1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
54 #include "exceptions.h"
56 #include "completer.h"
63 #include "gdb_string.h"
64 #include "gdb_assert.h"
65 #include <sys/types.h>
72 #define MAP_FAILED ((void *) -1)
76 typedef struct symbol
*symbolp
;
80 /* .debug_info header for a compilation unit
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct comp_unit_header
85 unsigned int length
; /* length of the .debug_info
87 unsigned short version
; /* version number -- 2 for DWARF
89 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
90 unsigned char addr_size
; /* byte size of an address -- 4 */
93 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
96 /* .debug_line statement program prologue
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct statement_prologue
101 unsigned int total_length
; /* byte length of the statement
103 unsigned short version
; /* version number -- 2 for DWARF
105 unsigned int prologue_length
; /* # bytes between prologue &
107 unsigned char minimum_instruction_length
; /* byte size of
109 unsigned char default_is_stmt
; /* initial value of is_stmt
112 unsigned char line_range
;
113 unsigned char opcode_base
; /* number assigned to first special
115 unsigned char *standard_opcode_lengths
;
119 /* When non-zero, dump DIEs after they are read in. */
120 static int dwarf2_die_debug
= 0;
124 /* When set, the file that we're processing is known to have debugging
125 info for C++ namespaces. GCC 3.3.x did not produce this information,
126 but later versions do. */
128 static int processing_has_namespace_info
;
130 static const struct objfile_data
*dwarf2_objfile_data_key
;
132 struct dwarf2_section_info
138 /* True if we have tried to read this section. */
142 /* All offsets in the index are of this type. It must be
143 architecture-independent. */
144 typedef uint32_t offset_type
;
146 DEF_VEC_I (offset_type
);
148 /* A description of the mapped index. The file format is described in
149 a comment by the code that writes the index. */
152 /* Index data format version. */
155 /* The total length of the buffer. */
158 /* A pointer to the address table data. */
159 const gdb_byte
*address_table
;
161 /* Size of the address table data in bytes. */
162 offset_type address_table_size
;
164 /* The symbol table, implemented as a hash table. */
165 const offset_type
*symbol_table
;
167 /* Size in slots, each slot is 2 offset_types. */
168 offset_type symbol_table_slots
;
170 /* A pointer to the constant pool. */
171 const char *constant_pool
;
174 struct dwarf2_per_objfile
176 struct dwarf2_section_info info
;
177 struct dwarf2_section_info abbrev
;
178 struct dwarf2_section_info line
;
179 struct dwarf2_section_info loc
;
180 struct dwarf2_section_info macinfo
;
181 struct dwarf2_section_info str
;
182 struct dwarf2_section_info ranges
;
183 struct dwarf2_section_info types
;
184 struct dwarf2_section_info frame
;
185 struct dwarf2_section_info eh_frame
;
186 struct dwarf2_section_info gdb_index
;
189 struct objfile
*objfile
;
191 /* A list of all the compilation units. This is used to locate
192 the target compilation unit of a particular reference. */
193 struct dwarf2_per_cu_data
**all_comp_units
;
195 /* The number of compilation units in ALL_COMP_UNITS. */
198 /* The number of .debug_types-related CUs. */
199 int n_type_comp_units
;
201 /* The .debug_types-related CUs. */
202 struct dwarf2_per_cu_data
**type_comp_units
;
204 /* A chain of compilation units that are currently read in, so that
205 they can be freed later. */
206 struct dwarf2_per_cu_data
*read_in_chain
;
208 /* A table mapping .debug_types signatures to its signatured_type entry.
209 This is NULL if the .debug_types section hasn't been read in yet. */
210 htab_t signatured_types
;
212 /* A flag indicating wether this objfile has a section loaded at a
214 int has_section_at_zero
;
216 /* True if we are using the mapped index,
217 or we are faking it for OBJF_READNOW's sake. */
218 unsigned char using_index
;
220 /* The mapped index, or NULL if .gdb_index is missing or not being used. */
221 struct mapped_index
*index_table
;
223 /* When using index_table, this keeps track of all quick_file_names entries.
224 TUs can share line table entries with CUs or other TUs, and there can be
225 a lot more TUs than unique line tables, so we maintain a separate table
226 of all line table entries to support the sharing. */
227 htab_t quick_file_names_table
;
229 /* Set during partial symbol reading, to prevent queueing of full
231 int reading_partial_symbols
;
233 /* Table mapping type .debug_info DIE offsets to types.
234 This is NULL if not allocated yet.
235 It (currently) makes sense to allocate debug_types_type_hash lazily.
236 To keep things simple we allocate both lazily. */
237 htab_t debug_info_type_hash
;
239 /* Table mapping type .debug_types DIE offsets to types.
240 This is NULL if not allocated yet. */
241 htab_t debug_types_type_hash
;
244 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
246 /* names of the debugging sections */
248 /* Note that if the debugging section has been compressed, it might
249 have a name like .zdebug_info. */
251 #define INFO_SECTION "debug_info"
252 #define ABBREV_SECTION "debug_abbrev"
253 #define LINE_SECTION "debug_line"
254 #define LOC_SECTION "debug_loc"
255 #define MACINFO_SECTION "debug_macinfo"
256 #define STR_SECTION "debug_str"
257 #define RANGES_SECTION "debug_ranges"
258 #define TYPES_SECTION "debug_types"
259 #define FRAME_SECTION "debug_frame"
260 #define EH_FRAME_SECTION "eh_frame"
261 #define GDB_INDEX_SECTION "gdb_index"
263 /* local data types */
265 /* We hold several abbreviation tables in memory at the same time. */
266 #ifndef ABBREV_HASH_SIZE
267 #define ABBREV_HASH_SIZE 121
270 /* The data in a compilation unit header, after target2host
271 translation, looks like this. */
272 struct comp_unit_head
276 unsigned char addr_size
;
277 unsigned char signed_addr_p
;
278 unsigned int abbrev_offset
;
280 /* Size of file offsets; either 4 or 8. */
281 unsigned int offset_size
;
283 /* Size of the length field; either 4 or 12. */
284 unsigned int initial_length_size
;
286 /* Offset to the first byte of this compilation unit header in the
287 .debug_info section, for resolving relative reference dies. */
290 /* Offset to first die in this cu from the start of the cu.
291 This will be the first byte following the compilation unit header. */
292 unsigned int first_die_offset
;
295 /* Type used for delaying computation of method physnames.
296 See comments for compute_delayed_physnames. */
297 struct delayed_method_info
299 /* The type to which the method is attached, i.e., its parent class. */
302 /* The index of the method in the type's function fieldlists. */
305 /* The index of the method in the fieldlist. */
308 /* The name of the DIE. */
311 /* The DIE associated with this method. */
312 struct die_info
*die
;
315 typedef struct delayed_method_info delayed_method_info
;
316 DEF_VEC_O (delayed_method_info
);
318 /* Internal state when decoding a particular compilation unit. */
321 /* The objfile containing this compilation unit. */
322 struct objfile
*objfile
;
324 /* The header of the compilation unit. */
325 struct comp_unit_head header
;
327 /* Base address of this compilation unit. */
328 CORE_ADDR base_address
;
330 /* Non-zero if base_address has been set. */
333 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
335 /* The language we are debugging. */
336 enum language language
;
337 const struct language_defn
*language_defn
;
339 const char *producer
;
341 /* The generic symbol table building routines have separate lists for
342 file scope symbols and all all other scopes (local scopes). So
343 we need to select the right one to pass to add_symbol_to_list().
344 We do it by keeping a pointer to the correct list in list_in_scope.
346 FIXME: The original dwarf code just treated the file scope as the
347 first local scope, and all other local scopes as nested local
348 scopes, and worked fine. Check to see if we really need to
349 distinguish these in buildsym.c. */
350 struct pending
**list_in_scope
;
352 /* DWARF abbreviation table associated with this compilation unit. */
353 struct abbrev_info
**dwarf2_abbrevs
;
355 /* Storage for the abbrev table. */
356 struct obstack abbrev_obstack
;
358 /* Hash table holding all the loaded partial DIEs. */
361 /* Storage for things with the same lifetime as this read-in compilation
362 unit, including partial DIEs. */
363 struct obstack comp_unit_obstack
;
365 /* When multiple dwarf2_cu structures are living in memory, this field
366 chains them all together, so that they can be released efficiently.
367 We will probably also want a generation counter so that most-recently-used
368 compilation units are cached... */
369 struct dwarf2_per_cu_data
*read_in_chain
;
371 /* Backchain to our per_cu entry if the tree has been built. */
372 struct dwarf2_per_cu_data
*per_cu
;
374 /* How many compilation units ago was this CU last referenced? */
377 /* A hash table of die offsets for following references. */
380 /* Full DIEs if read in. */
381 struct die_info
*dies
;
383 /* A set of pointers to dwarf2_per_cu_data objects for compilation
384 units referenced by this one. Only set during full symbol processing;
385 partial symbol tables do not have dependencies. */
388 /* Header data from the line table, during full symbol processing. */
389 struct line_header
*line_header
;
391 /* A list of methods which need to have physnames computed
392 after all type information has been read. */
393 VEC (delayed_method_info
) *method_list
;
395 /* Mark used when releasing cached dies. */
396 unsigned int mark
: 1;
398 /* This flag will be set if this compilation unit might include
399 inter-compilation-unit references. */
400 unsigned int has_form_ref_addr
: 1;
402 /* This flag will be set if this compilation unit includes any
403 DW_TAG_namespace DIEs. If we know that there are explicit
404 DIEs for namespaces, we don't need to try to infer them
405 from mangled names. */
406 unsigned int has_namespace_info
: 1;
409 /* Persistent data held for a compilation unit, even when not
410 processing it. We put a pointer to this structure in the
411 read_symtab_private field of the psymtab. If we encounter
412 inter-compilation-unit references, we also maintain a sorted
413 list of all compilation units. */
415 struct dwarf2_per_cu_data
417 /* The start offset and length of this compilation unit. 2**29-1
418 bytes should suffice to store the length of any compilation unit
419 - if it doesn't, GDB will fall over anyway.
420 NOTE: Unlike comp_unit_head.length, this length includes
421 initial_length_size. */
423 unsigned int length
: 29;
425 /* Flag indicating this compilation unit will be read in before
426 any of the current compilation units are processed. */
427 unsigned int queued
: 1;
429 /* This flag will be set if we need to load absolutely all DIEs
430 for this compilation unit, instead of just the ones we think
431 are interesting. It gets set if we look for a DIE in the
432 hash table and don't find it. */
433 unsigned int load_all_dies
: 1;
435 /* Non-zero if this CU is from .debug_types.
436 Otherwise it's from .debug_info. */
437 unsigned int from_debug_types
: 1;
439 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
440 of the CU cache it gets reset to NULL again. */
441 struct dwarf2_cu
*cu
;
443 /* The corresponding objfile. */
444 struct objfile
*objfile
;
446 /* When using partial symbol tables, the 'psymtab' field is active.
447 Otherwise the 'quick' field is active. */
450 /* The partial symbol table associated with this compilation unit,
451 or NULL for partial units (which do not have an associated
453 struct partial_symtab
*psymtab
;
455 /* Data needed by the "quick" functions. */
456 struct dwarf2_per_cu_quick_data
*quick
;
460 /* Entry in the signatured_types hash table. */
462 struct signatured_type
466 /* Offset in .debug_types of the TU (type_unit) for this type. */
469 /* Offset in .debug_types of the type defined by this TU. */
470 unsigned int type_offset
;
472 /* The CU(/TU) of this type. */
473 struct dwarf2_per_cu_data per_cu
;
476 /* Struct used to pass misc. parameters to read_die_and_children, et
477 al. which are used for both .debug_info and .debug_types dies.
478 All parameters here are unchanging for the life of the call. This
479 struct exists to abstract away the constant parameters of die
482 struct die_reader_specs
484 /* The bfd of this objfile. */
487 /* The CU of the DIE we are parsing. */
488 struct dwarf2_cu
*cu
;
490 /* Pointer to start of section buffer.
491 This is either the start of .debug_info or .debug_types. */
492 const gdb_byte
*buffer
;
495 /* The line number information for a compilation unit (found in the
496 .debug_line section) begins with a "statement program header",
497 which contains the following information. */
500 unsigned int total_length
;
501 unsigned short version
;
502 unsigned int header_length
;
503 unsigned char minimum_instruction_length
;
504 unsigned char maximum_ops_per_instruction
;
505 unsigned char default_is_stmt
;
507 unsigned char line_range
;
508 unsigned char opcode_base
;
510 /* standard_opcode_lengths[i] is the number of operands for the
511 standard opcode whose value is i. This means that
512 standard_opcode_lengths[0] is unused, and the last meaningful
513 element is standard_opcode_lengths[opcode_base - 1]. */
514 unsigned char *standard_opcode_lengths
;
516 /* The include_directories table. NOTE! These strings are not
517 allocated with xmalloc; instead, they are pointers into
518 debug_line_buffer. If you try to free them, `free' will get
520 unsigned int num_include_dirs
, include_dirs_size
;
523 /* The file_names table. NOTE! These strings are not allocated
524 with xmalloc; instead, they are pointers into debug_line_buffer.
525 Don't try to free them directly. */
526 unsigned int num_file_names
, file_names_size
;
530 unsigned int dir_index
;
531 unsigned int mod_time
;
533 int included_p
; /* Non-zero if referenced by the Line Number Program. */
534 struct symtab
*symtab
; /* The associated symbol table, if any. */
537 /* The start and end of the statement program following this
538 header. These point into dwarf2_per_objfile->line_buffer. */
539 gdb_byte
*statement_program_start
, *statement_program_end
;
542 /* When we construct a partial symbol table entry we only
543 need this much information. */
544 struct partial_die_info
546 /* Offset of this DIE. */
549 /* DWARF-2 tag for this DIE. */
550 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
552 /* Assorted flags describing the data found in this DIE. */
553 unsigned int has_children
: 1;
554 unsigned int is_external
: 1;
555 unsigned int is_declaration
: 1;
556 unsigned int has_type
: 1;
557 unsigned int has_specification
: 1;
558 unsigned int has_pc_info
: 1;
560 /* Flag set if the SCOPE field of this structure has been
562 unsigned int scope_set
: 1;
564 /* Flag set if the DIE has a byte_size attribute. */
565 unsigned int has_byte_size
: 1;
567 /* Flag set if any of the DIE's children are template arguments. */
568 unsigned int has_template_arguments
: 1;
570 /* Flag set if fixup_partial_die has been called on this die. */
571 unsigned int fixup_called
: 1;
573 /* The name of this DIE. Normally the value of DW_AT_name, but
574 sometimes a default name for unnamed DIEs. */
577 /* The linkage name, if present. */
578 const char *linkage_name
;
580 /* The scope to prepend to our children. This is generally
581 allocated on the comp_unit_obstack, so will disappear
582 when this compilation unit leaves the cache. */
585 /* The location description associated with this DIE, if any. */
586 struct dwarf_block
*locdesc
;
588 /* If HAS_PC_INFO, the PC range associated with this DIE. */
592 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
593 DW_AT_sibling, if any. */
594 /* NOTE: This member isn't strictly necessary, read_partial_die could
595 return DW_AT_sibling values to its caller load_partial_dies. */
598 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
599 DW_AT_specification (or DW_AT_abstract_origin or
601 unsigned int spec_offset
;
603 /* Pointers to this DIE's parent, first child, and next sibling,
605 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
608 /* This data structure holds the information of an abbrev. */
611 unsigned int number
; /* number identifying abbrev */
612 enum dwarf_tag tag
; /* dwarf tag */
613 unsigned short has_children
; /* boolean */
614 unsigned short num_attrs
; /* number of attributes */
615 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
616 struct abbrev_info
*next
; /* next in chain */
621 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
622 ENUM_BITFIELD(dwarf_form
) form
: 16;
625 /* Attributes have a name and a value. */
628 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
629 ENUM_BITFIELD(dwarf_form
) form
: 15;
631 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
632 field should be in u.str (existing only for DW_STRING) but it is kept
633 here for better struct attribute alignment. */
634 unsigned int string_is_canonical
: 1;
639 struct dwarf_block
*blk
;
643 struct signatured_type
*signatured_type
;
648 /* This data structure holds a complete die structure. */
651 /* DWARF-2 tag for this DIE. */
652 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
654 /* Number of attributes */
655 unsigned char num_attrs
;
657 /* True if we're presently building the full type name for the
658 type derived from this DIE. */
659 unsigned char building_fullname
: 1;
664 /* Offset in .debug_info or .debug_types section. */
667 /* The dies in a compilation unit form an n-ary tree. PARENT
668 points to this die's parent; CHILD points to the first child of
669 this node; and all the children of a given node are chained
670 together via their SIBLING fields. */
671 struct die_info
*child
; /* Its first child, if any. */
672 struct die_info
*sibling
; /* Its next sibling, if any. */
673 struct die_info
*parent
; /* Its parent, if any. */
675 /* An array of attributes, with NUM_ATTRS elements. There may be
676 zero, but it's not common and zero-sized arrays are not
677 sufficiently portable C. */
678 struct attribute attrs
[1];
681 struct function_range
684 CORE_ADDR lowpc
, highpc
;
686 struct function_range
*next
;
689 /* Get at parts of an attribute structure. */
691 #define DW_STRING(attr) ((attr)->u.str)
692 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
693 #define DW_UNSND(attr) ((attr)->u.unsnd)
694 #define DW_BLOCK(attr) ((attr)->u.blk)
695 #define DW_SND(attr) ((attr)->u.snd)
696 #define DW_ADDR(attr) ((attr)->u.addr)
697 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
699 /* Blocks are a bunch of untyped bytes. */
706 #ifndef ATTR_ALLOC_CHUNK
707 #define ATTR_ALLOC_CHUNK 4
710 /* Allocate fields for structs, unions and enums in this size. */
711 #ifndef DW_FIELD_ALLOC_CHUNK
712 #define DW_FIELD_ALLOC_CHUNK 4
715 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
716 but this would require a corresponding change in unpack_field_as_long
718 static int bits_per_byte
= 8;
720 /* The routines that read and process dies for a C struct or C++ class
721 pass lists of data member fields and lists of member function fields
722 in an instance of a field_info structure, as defined below. */
725 /* List of data member and baseclasses fields. */
728 struct nextfield
*next
;
733 *fields
, *baseclasses
;
735 /* Number of fields (including baseclasses). */
738 /* Number of baseclasses. */
741 /* Set if the accesibility of one of the fields is not public. */
742 int non_public_fields
;
744 /* Member function fields array, entries are allocated in the order they
745 are encountered in the object file. */
748 struct nextfnfield
*next
;
749 struct fn_field fnfield
;
753 /* Member function fieldlist array, contains name of possibly overloaded
754 member function, number of overloaded member functions and a pointer
755 to the head of the member function field chain. */
760 struct nextfnfield
*head
;
764 /* Number of entries in the fnfieldlists array. */
767 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
768 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
769 struct typedef_field_list
771 struct typedef_field field
;
772 struct typedef_field_list
*next
;
775 unsigned typedef_field_list_count
;
778 /* One item on the queue of compilation units to read in full symbols
780 struct dwarf2_queue_item
782 struct dwarf2_per_cu_data
*per_cu
;
783 struct dwarf2_queue_item
*next
;
786 /* The current queue. */
787 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
789 /* Loaded secondary compilation units are kept in memory until they
790 have not been referenced for the processing of this many
791 compilation units. Set this to zero to disable caching. Cache
792 sizes of up to at least twenty will improve startup time for
793 typical inter-CU-reference binaries, at an obvious memory cost. */
794 static int dwarf2_max_cache_age
= 5;
796 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
797 struct cmd_list_element
*c
, const char *value
)
799 fprintf_filtered (file
, _("The upper bound on the age of cached "
800 "dwarf2 compilation units is %s.\n"),
805 /* Various complaints about symbol reading that don't abort the process. */
808 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
810 complaint (&symfile_complaints
,
811 _("statement list doesn't fit in .debug_line section"));
815 dwarf2_debug_line_missing_file_complaint (void)
817 complaint (&symfile_complaints
,
818 _(".debug_line section has line data without a file"));
822 dwarf2_debug_line_missing_end_sequence_complaint (void)
824 complaint (&symfile_complaints
,
825 _(".debug_line section has line "
826 "program sequence without an end"));
830 dwarf2_complex_location_expr_complaint (void)
832 complaint (&symfile_complaints
, _("location expression too complex"));
836 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
839 complaint (&symfile_complaints
,
840 _("const value length mismatch for '%s', got %d, expected %d"),
845 dwarf2_macros_too_long_complaint (void)
847 complaint (&symfile_complaints
,
848 _("macro info runs off end of `.debug_macinfo' section"));
852 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
854 complaint (&symfile_complaints
,
855 _("macro debug info contains a "
856 "malformed macro definition:\n`%s'"),
861 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
863 complaint (&symfile_complaints
,
864 _("invalid attribute class or form for '%s' in '%s'"),
868 /* local function prototypes */
870 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
872 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
875 static void dwarf2_build_psymtabs_hard (struct objfile
*);
877 static void scan_partial_symbols (struct partial_die_info
*,
878 CORE_ADDR
*, CORE_ADDR
*,
879 int, struct dwarf2_cu
*);
881 static void add_partial_symbol (struct partial_die_info
*,
884 static void add_partial_namespace (struct partial_die_info
*pdi
,
885 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
886 int need_pc
, struct dwarf2_cu
*cu
);
888 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
889 CORE_ADDR
*highpc
, int need_pc
,
890 struct dwarf2_cu
*cu
);
892 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
893 struct dwarf2_cu
*cu
);
895 static void add_partial_subprogram (struct partial_die_info
*pdi
,
896 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
897 int need_pc
, struct dwarf2_cu
*cu
);
899 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
900 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
901 bfd
*abfd
, struct dwarf2_cu
*cu
);
903 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
905 static void psymtab_to_symtab_1 (struct partial_symtab
*);
907 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
909 static void dwarf2_free_abbrev_table (void *);
911 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
914 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
917 static struct partial_die_info
*load_partial_dies (bfd
*,
918 gdb_byte
*, gdb_byte
*,
919 int, struct dwarf2_cu
*);
921 static gdb_byte
*read_partial_die (struct partial_die_info
*,
922 struct abbrev_info
*abbrev
,
924 gdb_byte
*, gdb_byte
*,
927 static struct partial_die_info
*find_partial_die (unsigned int,
930 static void fixup_partial_die (struct partial_die_info
*,
933 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
934 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
936 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
937 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
939 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
941 static int read_1_signed_byte (bfd
*, gdb_byte
*);
943 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
945 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
947 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
949 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
952 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
954 static LONGEST read_checked_initial_length_and_offset
955 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
956 unsigned int *, unsigned int *);
958 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
961 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
963 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
965 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
967 static char *read_indirect_string (bfd
*, gdb_byte
*,
968 const struct comp_unit_head
*,
971 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
973 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
975 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
977 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
979 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
982 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
986 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
987 struct dwarf2_cu
*cu
);
989 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
991 static struct die_info
*die_specification (struct die_info
*die
,
992 struct dwarf2_cu
**);
994 static void free_line_header (struct line_header
*lh
);
996 static void add_file_name (struct line_header
*, char *, unsigned int,
997 unsigned int, unsigned int);
999 static struct line_header
*(dwarf_decode_line_header
1000 (unsigned int offset
,
1001 bfd
*abfd
, struct dwarf2_cu
*cu
));
1003 static void dwarf_decode_lines (struct line_header
*, const char *, bfd
*,
1004 struct dwarf2_cu
*, struct partial_symtab
*);
1006 static void dwarf2_start_subfile (char *, const char *, const char *);
1008 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1009 struct dwarf2_cu
*);
1011 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1012 struct dwarf2_cu
*, struct symbol
*);
1014 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1015 struct dwarf2_cu
*);
1017 static void dwarf2_const_value_attr (struct attribute
*attr
,
1020 struct obstack
*obstack
,
1021 struct dwarf2_cu
*cu
, long *value
,
1023 struct dwarf2_locexpr_baton
**baton
);
1025 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1027 static int need_gnat_info (struct dwarf2_cu
*);
1029 static struct type
*die_descriptive_type (struct die_info
*,
1030 struct dwarf2_cu
*);
1032 static void set_descriptive_type (struct type
*, struct die_info
*,
1033 struct dwarf2_cu
*);
1035 static struct type
*die_containing_type (struct die_info
*,
1036 struct dwarf2_cu
*);
1038 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1039 struct dwarf2_cu
*);
1041 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1043 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1045 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1047 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1048 const char *suffix
, int physname
,
1049 struct dwarf2_cu
*cu
);
1051 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1053 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1055 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1057 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1059 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1060 struct dwarf2_cu
*, struct partial_symtab
*);
1062 static int dwarf2_get_pc_bounds (struct die_info
*,
1063 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1064 struct partial_symtab
*);
1066 static void get_scope_pc_bounds (struct die_info
*,
1067 CORE_ADDR
*, CORE_ADDR
*,
1068 struct dwarf2_cu
*);
1070 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1071 CORE_ADDR
, struct dwarf2_cu
*);
1073 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1074 struct dwarf2_cu
*);
1076 static void dwarf2_attach_fields_to_type (struct field_info
*,
1077 struct type
*, struct dwarf2_cu
*);
1079 static void dwarf2_add_member_fn (struct field_info
*,
1080 struct die_info
*, struct type
*,
1081 struct dwarf2_cu
*);
1083 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1085 struct dwarf2_cu
*);
1087 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1089 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1091 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1093 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1095 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1097 static struct type
*read_module_type (struct die_info
*die
,
1098 struct dwarf2_cu
*cu
);
1100 static const char *namespace_name (struct die_info
*die
,
1101 int *is_anonymous
, struct dwarf2_cu
*);
1103 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1105 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1107 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1108 struct dwarf2_cu
*);
1110 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1112 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1114 gdb_byte
**new_info_ptr
,
1115 struct die_info
*parent
);
1117 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1119 gdb_byte
**new_info_ptr
,
1120 struct die_info
*parent
);
1122 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1124 gdb_byte
**new_info_ptr
,
1125 struct die_info
*parent
);
1127 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1128 struct die_info
**, gdb_byte
*,
1131 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1133 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1136 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1138 static const char *dwarf2_full_name (char *name
,
1139 struct die_info
*die
,
1140 struct dwarf2_cu
*cu
);
1142 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1143 struct dwarf2_cu
**);
1145 static char *dwarf_tag_name (unsigned int);
1147 static char *dwarf_attr_name (unsigned int);
1149 static char *dwarf_form_name (unsigned int);
1151 static char *dwarf_bool_name (unsigned int);
1153 static char *dwarf_type_encoding_name (unsigned int);
1156 static char *dwarf_cfi_name (unsigned int);
1159 static struct die_info
*sibling_die (struct die_info
*);
1161 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1163 static void dump_die_for_error (struct die_info
*);
1165 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1168 /*static*/ void dump_die (struct die_info
*, int max_level
);
1170 static void store_in_ref_table (struct die_info
*,
1171 struct dwarf2_cu
*);
1173 static int is_ref_attr (struct attribute
*);
1175 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1177 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1179 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1181 struct dwarf2_cu
**);
1183 static struct die_info
*follow_die_ref (struct die_info
*,
1185 struct dwarf2_cu
**);
1187 static struct die_info
*follow_die_sig (struct die_info
*,
1189 struct dwarf2_cu
**);
1191 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1192 unsigned int offset
);
1194 static void read_signatured_type (struct objfile
*,
1195 struct signatured_type
*type_sig
);
1197 /* memory allocation interface */
1199 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1201 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1203 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1205 static void initialize_cu_func_list (struct dwarf2_cu
*);
1207 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1208 struct dwarf2_cu
*);
1210 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1211 char *, bfd
*, struct dwarf2_cu
*);
1213 static int attr_form_is_block (struct attribute
*);
1215 static int attr_form_is_section_offset (struct attribute
*);
1217 static int attr_form_is_constant (struct attribute
*);
1219 static void fill_in_loclist_baton (struct dwarf2_cu
*cu
,
1220 struct dwarf2_loclist_baton
*baton
,
1221 struct attribute
*attr
);
1223 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1225 struct dwarf2_cu
*cu
);
1227 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1228 struct abbrev_info
*abbrev
,
1229 struct dwarf2_cu
*cu
);
1231 static void free_stack_comp_unit (void *);
1233 static hashval_t
partial_die_hash (const void *item
);
1235 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1237 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1238 (unsigned int offset
, struct objfile
*objfile
);
1240 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1241 (unsigned int offset
, struct objfile
*objfile
);
1243 static void init_one_comp_unit (struct dwarf2_cu
*cu
,
1244 struct objfile
*objfile
);
1246 static void prepare_one_comp_unit (struct dwarf2_cu
*cu
,
1247 struct die_info
*comp_unit_die
);
1249 static void free_one_comp_unit (void *);
1251 static void free_cached_comp_units (void *);
1253 static void age_cached_comp_units (void);
1255 static void free_one_cached_comp_unit (void *);
1257 static struct type
*set_die_type (struct die_info
*, struct type
*,
1258 struct dwarf2_cu
*);
1260 static void create_all_comp_units (struct objfile
*);
1262 static int create_debug_types_hash_table (struct objfile
*objfile
);
1264 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1267 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1269 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1270 struct dwarf2_per_cu_data
*);
1272 static void dwarf2_mark (struct dwarf2_cu
*);
1274 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1276 static struct type
*get_die_type_at_offset (unsigned int,
1277 struct dwarf2_per_cu_data
*per_cu
);
1279 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1281 static void dwarf2_release_queue (void *dummy
);
1283 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1284 struct objfile
*objfile
);
1286 static void process_queue (struct objfile
*objfile
);
1288 static void find_file_and_directory (struct die_info
*die
,
1289 struct dwarf2_cu
*cu
,
1290 char **name
, char **comp_dir
);
1292 static char *file_full_name (int file
, struct line_header
*lh
,
1293 const char *comp_dir
);
1295 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1298 unsigned int buffer_size
,
1301 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1302 struct dwarf2_cu
*cu
);
1304 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1308 /* Convert VALUE between big- and little-endian. */
1310 byte_swap (offset_type value
)
1314 result
= (value
& 0xff) << 24;
1315 result
|= (value
& 0xff00) << 8;
1316 result
|= (value
& 0xff0000) >> 8;
1317 result
|= (value
& 0xff000000) >> 24;
1321 #define MAYBE_SWAP(V) byte_swap (V)
1324 #define MAYBE_SWAP(V) (V)
1325 #endif /* WORDS_BIGENDIAN */
1327 /* The suffix for an index file. */
1328 #define INDEX_SUFFIX ".gdb-index"
1330 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1331 struct dwarf2_cu
*cu
);
1333 /* Try to locate the sections we need for DWARF 2 debugging
1334 information and return true if we have enough to do something. */
1337 dwarf2_has_info (struct objfile
*objfile
)
1339 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1340 if (!dwarf2_per_objfile
)
1342 /* Initialize per-objfile state. */
1343 struct dwarf2_per_objfile
*data
1344 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1346 memset (data
, 0, sizeof (*data
));
1347 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1348 dwarf2_per_objfile
= data
;
1350 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1351 dwarf2_per_objfile
->objfile
= objfile
;
1353 return (dwarf2_per_objfile
->info
.asection
!= NULL
1354 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1357 /* When loading sections, we can either look for ".<name>", or for
1358 * ".z<name>", which indicates a compressed section. */
1361 section_is_p (const char *section_name
, const char *name
)
1363 return (section_name
[0] == '.'
1364 && (strcmp (section_name
+ 1, name
) == 0
1365 || (section_name
[1] == 'z'
1366 && strcmp (section_name
+ 2, name
) == 0)));
1369 /* This function is mapped across the sections and remembers the
1370 offset and size of each of the debugging sections we are interested
1374 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1376 if (section_is_p (sectp
->name
, INFO_SECTION
))
1378 dwarf2_per_objfile
->info
.asection
= sectp
;
1379 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1381 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1383 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1384 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1386 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1388 dwarf2_per_objfile
->line
.asection
= sectp
;
1389 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1391 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1393 dwarf2_per_objfile
->loc
.asection
= sectp
;
1394 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1396 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1398 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1399 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1401 else if (section_is_p (sectp
->name
, STR_SECTION
))
1403 dwarf2_per_objfile
->str
.asection
= sectp
;
1404 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1406 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1408 dwarf2_per_objfile
->frame
.asection
= sectp
;
1409 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1411 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1413 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1415 if (aflag
& SEC_HAS_CONTENTS
)
1417 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1418 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1421 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1423 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1424 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1426 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1428 dwarf2_per_objfile
->types
.asection
= sectp
;
1429 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1431 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1433 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1434 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1437 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1438 && bfd_section_vma (abfd
, sectp
) == 0)
1439 dwarf2_per_objfile
->has_section_at_zero
= 1;
1442 /* Decompress a section that was compressed using zlib. Store the
1443 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1446 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1447 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1449 bfd
*abfd
= objfile
->obfd
;
1451 error (_("Support for zlib-compressed DWARF data (from '%s') "
1452 "is disabled in this copy of GDB"),
1453 bfd_get_filename (abfd
));
1455 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1456 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1457 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1458 bfd_size_type uncompressed_size
;
1459 gdb_byte
*uncompressed_buffer
;
1462 int header_size
= 12;
1464 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1465 || bfd_bread (compressed_buffer
,
1466 compressed_size
, abfd
) != compressed_size
)
1467 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1468 bfd_get_filename (abfd
));
1470 /* Read the zlib header. In this case, it should be "ZLIB" followed
1471 by the uncompressed section size, 8 bytes in big-endian order. */
1472 if (compressed_size
< header_size
1473 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1474 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1475 bfd_get_filename (abfd
));
1476 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1477 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1478 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1479 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1480 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1481 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1482 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1483 uncompressed_size
+= compressed_buffer
[11];
1485 /* It is possible the section consists of several compressed
1486 buffers concatenated together, so we uncompress in a loop. */
1490 strm
.avail_in
= compressed_size
- header_size
;
1491 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1492 strm
.avail_out
= uncompressed_size
;
1493 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1495 rc
= inflateInit (&strm
);
1496 while (strm
.avail_in
> 0)
1499 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1500 bfd_get_filename (abfd
), rc
);
1501 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1502 + (uncompressed_size
- strm
.avail_out
));
1503 rc
= inflate (&strm
, Z_FINISH
);
1504 if (rc
!= Z_STREAM_END
)
1505 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1506 bfd_get_filename (abfd
), rc
);
1507 rc
= inflateReset (&strm
);
1509 rc
= inflateEnd (&strm
);
1511 || strm
.avail_out
!= 0)
1512 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1513 bfd_get_filename (abfd
), rc
);
1515 do_cleanups (cleanup
);
1516 *outbuf
= uncompressed_buffer
;
1517 *outsize
= uncompressed_size
;
1521 /* A helper function that decides whether a section is empty. */
1524 dwarf2_section_empty_p (struct dwarf2_section_info
*info
)
1526 return info
->asection
== NULL
|| info
->size
== 0;
1529 /* Read the contents of the section SECTP from object file specified by
1530 OBJFILE, store info about the section into INFO.
1531 If the section is compressed, uncompress it before returning. */
1534 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1536 bfd
*abfd
= objfile
->obfd
;
1537 asection
*sectp
= info
->asection
;
1538 gdb_byte
*buf
, *retbuf
;
1539 unsigned char header
[4];
1543 info
->buffer
= NULL
;
1544 info
->was_mmapped
= 0;
1547 if (dwarf2_section_empty_p (info
))
1550 /* Check if the file has a 4-byte header indicating compression. */
1551 if (info
->size
> sizeof (header
)
1552 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1553 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1555 /* Upon decompression, update the buffer and its size. */
1556 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1558 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1566 pagesize
= getpagesize ();
1568 /* Only try to mmap sections which are large enough: we don't want to
1569 waste space due to fragmentation. Also, only try mmap for sections
1570 without relocations. */
1572 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1574 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1575 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1576 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1577 MAP_PRIVATE
, pg_offset
);
1579 if (retbuf
!= MAP_FAILED
)
1581 info
->was_mmapped
= 1;
1582 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1583 #if HAVE_POSIX_MADVISE
1584 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1591 /* If we get here, we are a normal, not-compressed section. */
1593 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1595 /* When debugging .o files, we may need to apply relocations; see
1596 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1597 We never compress sections in .o files, so we only need to
1598 try this when the section is not compressed. */
1599 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1602 info
->buffer
= retbuf
;
1606 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1607 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1608 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1609 bfd_get_filename (abfd
));
1612 /* A helper function that returns the size of a section in a safe way.
1613 If you are positive that the section has been read before using the
1614 size, then it is safe to refer to the dwarf2_section_info object's
1615 "size" field directly. In other cases, you must call this
1616 function, because for compressed sections the size field is not set
1617 correctly until the section has been read. */
1619 static bfd_size_type
1620 dwarf2_section_size (struct objfile
*objfile
,
1621 struct dwarf2_section_info
*info
)
1624 dwarf2_read_section (objfile
, info
);
1628 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1632 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1633 asection
**sectp
, gdb_byte
**bufp
,
1634 bfd_size_type
*sizep
)
1636 struct dwarf2_per_objfile
*data
1637 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1638 struct dwarf2_section_info
*info
;
1640 /* We may see an objfile without any DWARF, in which case we just
1649 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1650 info
= &data
->eh_frame
;
1651 else if (section_is_p (section_name
, FRAME_SECTION
))
1652 info
= &data
->frame
;
1654 gdb_assert_not_reached ("unexpected section");
1656 dwarf2_read_section (objfile
, info
);
1658 *sectp
= info
->asection
;
1659 *bufp
= info
->buffer
;
1660 *sizep
= info
->size
;
1664 /* DWARF quick_symbols_functions support. */
1666 /* TUs can share .debug_line entries, and there can be a lot more TUs than
1667 unique line tables, so we maintain a separate table of all .debug_line
1668 derived entries to support the sharing.
1669 All the quick functions need is the list of file names. We discard the
1670 line_header when we're done and don't need to record it here. */
1671 struct quick_file_names
1673 /* The offset in .debug_line of the line table. We hash on this. */
1674 unsigned int offset
;
1676 /* The number of entries in file_names, real_names. */
1677 unsigned int num_file_names
;
1679 /* The file names from the line table, after being run through
1681 const char **file_names
;
1683 /* The file names from the line table after being run through
1684 gdb_realpath. These are computed lazily. */
1685 const char **real_names
;
1688 /* When using the index (and thus not using psymtabs), each CU has an
1689 object of this type. This is used to hold information needed by
1690 the various "quick" methods. */
1691 struct dwarf2_per_cu_quick_data
1693 /* The file table. This can be NULL if there was no file table
1694 or it's currently not read in.
1695 NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */
1696 struct quick_file_names
*file_names
;
1698 /* The corresponding symbol table. This is NULL if symbols for this
1699 CU have not yet been read. */
1700 struct symtab
*symtab
;
1702 /* A temporary mark bit used when iterating over all CUs in
1703 expand_symtabs_matching. */
1704 unsigned int mark
: 1;
1706 /* True if we've tried to read the file table and found there isn't one.
1707 There will be no point in trying to read it again next time. */
1708 unsigned int no_file_data
: 1;
1711 /* Hash function for a quick_file_names. */
1714 hash_file_name_entry (const void *e
)
1716 const struct quick_file_names
*file_data
= e
;
1718 return file_data
->offset
;
1721 /* Equality function for a quick_file_names. */
1724 eq_file_name_entry (const void *a
, const void *b
)
1726 const struct quick_file_names
*ea
= a
;
1727 const struct quick_file_names
*eb
= b
;
1729 return ea
->offset
== eb
->offset
;
1732 /* Delete function for a quick_file_names. */
1735 delete_file_name_entry (void *e
)
1737 struct quick_file_names
*file_data
= e
;
1740 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
1742 xfree ((void*) file_data
->file_names
[i
]);
1743 if (file_data
->real_names
)
1744 xfree ((void*) file_data
->real_names
[i
]);
1747 /* The space for the struct itself lives on objfile_obstack,
1748 so we don't free it here. */
1751 /* Create a quick_file_names hash table. */
1754 create_quick_file_names_table (unsigned int nr_initial_entries
)
1756 return htab_create_alloc (nr_initial_entries
,
1757 hash_file_name_entry
, eq_file_name_entry
,
1758 delete_file_name_entry
, xcalloc
, xfree
);
1761 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1765 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1766 struct dwarf2_per_cu_data
*per_cu
)
1768 struct cleanup
*back_to
;
1770 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1772 queue_comp_unit (per_cu
, objfile
);
1774 if (per_cu
->from_debug_types
)
1775 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1777 load_full_comp_unit (per_cu
, objfile
);
1779 process_queue (objfile
);
1781 /* Age the cache, releasing compilation units that have not
1782 been used recently. */
1783 age_cached_comp_units ();
1785 do_cleanups (back_to
);
1788 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1789 the objfile from which this CU came. Returns the resulting symbol
1792 static struct symtab
*
1793 dw2_instantiate_symtab (struct objfile
*objfile
,
1794 struct dwarf2_per_cu_data
*per_cu
)
1796 if (!per_cu
->v
.quick
->symtab
)
1798 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1799 increment_reading_symtab ();
1800 dw2_do_instantiate_symtab (objfile
, per_cu
);
1801 do_cleanups (back_to
);
1803 return per_cu
->v
.quick
->symtab
;
1806 /* Return the CU given its index. */
1808 static struct dwarf2_per_cu_data
*
1809 dw2_get_cu (int index
)
1811 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1813 index
-= dwarf2_per_objfile
->n_comp_units
;
1814 return dwarf2_per_objfile
->type_comp_units
[index
];
1816 return dwarf2_per_objfile
->all_comp_units
[index
];
1819 /* A helper function that knows how to read a 64-bit value in a way
1820 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1824 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1826 if (sizeof (ULONGEST
) < 8)
1830 /* Ignore the upper 4 bytes if they are all zero. */
1831 for (i
= 0; i
< 4; ++i
)
1832 if (bytes
[i
+ 4] != 0)
1835 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1838 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1842 /* Read the CU list from the mapped index, and use it to create all
1843 the CU objects for this objfile. Return 0 if something went wrong,
1844 1 if everything went ok. */
1847 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1848 offset_type cu_list_elements
)
1852 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1853 dwarf2_per_objfile
->all_comp_units
1854 = obstack_alloc (&objfile
->objfile_obstack
,
1855 dwarf2_per_objfile
->n_comp_units
1856 * sizeof (struct dwarf2_per_cu_data
*));
1858 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1860 struct dwarf2_per_cu_data
*the_cu
;
1861 ULONGEST offset
, length
;
1863 if (!extract_cu_value (cu_list
, &offset
)
1864 || !extract_cu_value (cu_list
+ 8, &length
))
1868 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1869 struct dwarf2_per_cu_data
);
1870 the_cu
->offset
= offset
;
1871 the_cu
->length
= length
;
1872 the_cu
->objfile
= objfile
;
1873 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1874 struct dwarf2_per_cu_quick_data
);
1875 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1881 /* Create the signatured type hash table from the index. */
1884 create_signatured_type_table_from_index (struct objfile
*objfile
,
1885 const gdb_byte
*bytes
,
1886 offset_type elements
)
1889 htab_t sig_types_hash
;
1891 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1892 dwarf2_per_objfile
->type_comp_units
1893 = obstack_alloc (&objfile
->objfile_obstack
,
1894 dwarf2_per_objfile
->n_type_comp_units
1895 * sizeof (struct dwarf2_per_cu_data
*));
1897 sig_types_hash
= allocate_signatured_type_table (objfile
);
1899 for (i
= 0; i
< elements
; i
+= 3)
1901 struct signatured_type
*type_sig
;
1902 ULONGEST offset
, type_offset
, signature
;
1905 if (!extract_cu_value (bytes
, &offset
)
1906 || !extract_cu_value (bytes
+ 8, &type_offset
))
1908 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1911 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1912 struct signatured_type
);
1913 type_sig
->signature
= signature
;
1914 type_sig
->offset
= offset
;
1915 type_sig
->type_offset
= type_offset
;
1916 type_sig
->per_cu
.from_debug_types
= 1;
1917 type_sig
->per_cu
.offset
= offset
;
1918 type_sig
->per_cu
.objfile
= objfile
;
1919 type_sig
->per_cu
.v
.quick
1920 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1921 struct dwarf2_per_cu_quick_data
);
1923 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1926 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1929 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1934 /* Read the address map data from the mapped index, and use it to
1935 populate the objfile's psymtabs_addrmap. */
1938 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1940 const gdb_byte
*iter
, *end
;
1941 struct obstack temp_obstack
;
1942 struct addrmap
*mutable_map
;
1943 struct cleanup
*cleanup
;
1946 obstack_init (&temp_obstack
);
1947 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1948 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1950 iter
= index
->address_table
;
1951 end
= iter
+ index
->address_table_size
;
1953 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1957 ULONGEST hi
, lo
, cu_index
;
1958 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1960 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1962 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1965 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1966 dw2_get_cu (cu_index
));
1969 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1970 &objfile
->objfile_obstack
);
1971 do_cleanups (cleanup
);
1974 /* The hash function for strings in the mapped index. This is the same as
1975 SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the
1976 implementation. This is necessary because the hash function is tied to the
1977 format of the mapped index file. The hash values do not have to match with
1980 Use INT_MAX for INDEX_VERSION if you generate the current index format. */
1983 mapped_index_string_hash (int index_version
, const void *p
)
1985 const unsigned char *str
= (const unsigned char *) p
;
1989 while ((c
= *str
++) != 0)
1991 if (index_version
>= 5)
1993 r
= r
* 67 + c
- 113;
1999 /* Find a slot in the mapped index INDEX for the object named NAME.
2000 If NAME is found, set *VEC_OUT to point to the CU vector in the
2001 constant pool and return 1. If NAME cannot be found, return 0. */
2004 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
2005 offset_type
**vec_out
)
2007 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2009 offset_type slot
, step
;
2010 int (*cmp
) (const char *, const char *);
2012 if (current_language
->la_language
== language_cplus
2013 || current_language
->la_language
== language_java
2014 || current_language
->la_language
== language_fortran
)
2016 /* NAME is already canonical. Drop any qualifiers as .gdb_index does
2018 const char *paren
= strchr (name
, '(');
2024 dup
= xmalloc (paren
- name
+ 1);
2025 memcpy (dup
, name
, paren
- name
);
2026 dup
[paren
- name
] = 0;
2028 make_cleanup (xfree
, dup
);
2033 /* Index version 4 did not support case insensitive searches. But the
2034 indexes for case insensitive languages are built in lowercase, therefore
2035 simulate our NAME being searched is also lowercased. */
2036 hash
= mapped_index_string_hash ((index
->version
== 4
2037 && case_sensitivity
== case_sensitive_off
2038 ? 5 : index
->version
),
2041 slot
= hash
& (index
->symbol_table_slots
- 1);
2042 step
= ((hash
* 17) & (index
->symbol_table_slots
- 1)) | 1;
2043 cmp
= (case_sensitivity
== case_sensitive_on
? strcmp
: strcasecmp
);
2047 /* Convert a slot number to an offset into the table. */
2048 offset_type i
= 2 * slot
;
2050 if (index
->symbol_table
[i
] == 0 && index
->symbol_table
[i
+ 1] == 0)
2052 do_cleanups (back_to
);
2056 str
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[i
]);
2057 if (!cmp (name
, str
))
2059 *vec_out
= (offset_type
*) (index
->constant_pool
2060 + MAYBE_SWAP (index
->symbol_table
[i
+ 1]));
2061 do_cleanups (back_to
);
2065 slot
= (slot
+ step
) & (index
->symbol_table_slots
- 1);
2069 /* Read the index file. If everything went ok, initialize the "quick"
2070 elements of all the CUs and return 1. Otherwise, return 0. */
2073 dwarf2_read_index (struct objfile
*objfile
)
2076 struct mapped_index
*map
;
2077 offset_type
*metadata
;
2078 const gdb_byte
*cu_list
;
2079 const gdb_byte
*types_list
= NULL
;
2080 offset_type version
, cu_list_elements
;
2081 offset_type types_list_elements
= 0;
2084 if (dwarf2_section_empty_p (&dwarf2_per_objfile
->gdb_index
))
2087 /* Older elfutils strip versions could keep the section in the main
2088 executable while splitting it for the separate debug info file. */
2089 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
2090 & SEC_HAS_CONTENTS
) == 0)
2093 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
2095 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
2096 /* Version check. */
2097 version
= MAYBE_SWAP (*(offset_type
*) addr
);
2098 /* Versions earlier than 3 emitted every copy of a psymbol. This
2099 causes the index to behave very poorly for certain requests. Version 3
2100 contained incomplete addrmap. So, it seems better to just ignore such
2101 indices. Index version 4 uses a different hash function than index
2102 version 5 and later. */
2105 /* Indexes with higher version than the one supported by GDB may be no
2106 longer backward compatible. */
2110 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
2111 map
->version
= version
;
2112 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
2114 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
2117 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2118 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
2122 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
2123 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
2124 - MAYBE_SWAP (metadata
[i
]))
2128 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
2129 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
2130 - MAYBE_SWAP (metadata
[i
]));
2133 map
->symbol_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
2134 map
->symbol_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
2135 - MAYBE_SWAP (metadata
[i
]))
2136 / (2 * sizeof (offset_type
)));
2139 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
2141 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
2144 if (types_list_elements
2145 && !create_signatured_type_table_from_index (objfile
, types_list
,
2146 types_list_elements
))
2149 create_addrmap_from_index (objfile
, map
);
2151 dwarf2_per_objfile
->index_table
= map
;
2152 dwarf2_per_objfile
->using_index
= 1;
2153 dwarf2_per_objfile
->quick_file_names_table
=
2154 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2159 /* A helper for the "quick" functions which sets the global
2160 dwarf2_per_objfile according to OBJFILE. */
2163 dw2_setup (struct objfile
*objfile
)
2165 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
2166 gdb_assert (dwarf2_per_objfile
);
2169 /* A helper for the "quick" functions which attempts to read the line
2170 table for THIS_CU. */
2172 static struct quick_file_names
*
2173 dw2_get_file_names (struct objfile
*objfile
,
2174 struct dwarf2_per_cu_data
*this_cu
)
2176 bfd
*abfd
= objfile
->obfd
;
2177 struct line_header
*lh
;
2178 struct attribute
*attr
;
2179 struct cleanup
*cleanups
;
2180 struct die_info
*comp_unit_die
;
2181 struct dwarf2_section_info
* sec
;
2182 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2183 int has_children
, i
;
2184 struct dwarf2_cu cu
;
2185 unsigned int bytes_read
, buffer_size
;
2186 struct die_reader_specs reader_specs
;
2187 char *name
, *comp_dir
;
2189 struct quick_file_names
*qfn
;
2190 unsigned int line_offset
;
2192 if (this_cu
->v
.quick
->file_names
!= NULL
)
2193 return this_cu
->v
.quick
->file_names
;
2194 /* If we know there is no line data, no point in looking again. */
2195 if (this_cu
->v
.quick
->no_file_data
)
2198 init_one_comp_unit (&cu
, objfile
);
2199 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2201 if (this_cu
->from_debug_types
)
2202 sec
= &dwarf2_per_objfile
->types
;
2204 sec
= &dwarf2_per_objfile
->info
;
2205 dwarf2_read_section (objfile
, sec
);
2206 buffer_size
= sec
->size
;
2207 buffer
= sec
->buffer
;
2208 info_ptr
= buffer
+ this_cu
->offset
;
2209 beg_of_comp_unit
= info_ptr
;
2211 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2212 buffer
, buffer_size
,
2215 /* Complete the cu_header. */
2216 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2217 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2220 cu
.per_cu
= this_cu
;
2222 dwarf2_read_abbrevs (abfd
, &cu
);
2223 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2225 if (this_cu
->from_debug_types
)
2226 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2227 init_cu_die_reader (&reader_specs
, &cu
);
2228 read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2234 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2237 struct quick_file_names find_entry
;
2239 line_offset
= DW_UNSND (attr
);
2241 /* We may have already read in this line header (TU line header sharing).
2242 If we have we're done. */
2243 find_entry
.offset
= line_offset
;
2244 slot
= htab_find_slot (dwarf2_per_objfile
->quick_file_names_table
,
2245 &find_entry
, INSERT
);
2248 do_cleanups (cleanups
);
2249 this_cu
->v
.quick
->file_names
= *slot
;
2253 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2257 do_cleanups (cleanups
);
2258 this_cu
->v
.quick
->no_file_data
= 1;
2262 qfn
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*qfn
));
2263 qfn
->offset
= line_offset
;
2264 gdb_assert (slot
!= NULL
);
2267 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2269 qfn
->num_file_names
= lh
->num_file_names
;
2270 qfn
->file_names
= obstack_alloc (&objfile
->objfile_obstack
,
2271 lh
->num_file_names
* sizeof (char *));
2272 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2273 qfn
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2274 qfn
->real_names
= NULL
;
2276 free_line_header (lh
);
2277 do_cleanups (cleanups
);
2279 this_cu
->v
.quick
->file_names
= qfn
;
2283 /* A helper for the "quick" functions which computes and caches the
2284 real path for a given file name from the line table. */
2287 dw2_get_real_path (struct objfile
*objfile
,
2288 struct quick_file_names
*qfn
, int index
)
2290 if (qfn
->real_names
== NULL
)
2291 qfn
->real_names
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2292 qfn
->num_file_names
, sizeof (char *));
2294 if (qfn
->real_names
[index
] == NULL
)
2295 qfn
->real_names
[index
] = gdb_realpath (qfn
->file_names
[index
]);
2297 return qfn
->real_names
[index
];
2300 static struct symtab
*
2301 dw2_find_last_source_symtab (struct objfile
*objfile
)
2305 dw2_setup (objfile
);
2306 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2307 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2310 /* Traversal function for dw2_forget_cached_source_info. */
2313 dw2_free_cached_file_names (void **slot
, void *info
)
2315 struct quick_file_names
*file_data
= (struct quick_file_names
*) *slot
;
2317 if (file_data
->real_names
)
2321 for (i
= 0; i
< file_data
->num_file_names
; ++i
)
2323 xfree ((void*) file_data
->real_names
[i
]);
2324 file_data
->real_names
[i
] = NULL
;
2332 dw2_forget_cached_source_info (struct objfile
*objfile
)
2334 dw2_setup (objfile
);
2336 htab_traverse_noresize (dwarf2_per_objfile
->quick_file_names_table
,
2337 dw2_free_cached_file_names
, NULL
);
2341 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2342 const char *full_path
, const char *real_path
,
2343 struct symtab
**result
)
2346 int check_basename
= lbasename (name
) == name
;
2347 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2349 dw2_setup (objfile
);
2351 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2352 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2355 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2356 struct quick_file_names
*file_data
;
2358 if (per_cu
->v
.quick
->symtab
)
2361 file_data
= dw2_get_file_names (objfile
, per_cu
);
2362 if (file_data
== NULL
)
2365 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2367 const char *this_name
= file_data
->file_names
[j
];
2369 if (FILENAME_CMP (name
, this_name
) == 0)
2371 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2375 if (check_basename
&& ! base_cu
2376 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2379 if (full_path
!= NULL
)
2381 const char *this_real_name
= dw2_get_real_path (objfile
,
2384 if (this_real_name
!= NULL
2385 && FILENAME_CMP (full_path
, this_real_name
) == 0)
2387 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2392 if (real_path
!= NULL
)
2394 const char *this_real_name
= dw2_get_real_path (objfile
,
2397 if (this_real_name
!= NULL
2398 && FILENAME_CMP (real_path
, this_real_name
) == 0)
2400 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2409 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2416 static struct symtab
*
2417 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2418 const char *name
, domain_enum domain
)
2420 /* We do all the work in the pre_expand_symtabs_matching hook
2425 /* A helper function that expands all symtabs that hold an object
2429 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2431 dw2_setup (objfile
);
2433 /* index_table is NULL if OBJF_READNOW. */
2434 if (dwarf2_per_objfile
->index_table
)
2438 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2441 offset_type i
, len
= MAYBE_SWAP (*vec
);
2442 for (i
= 0; i
< len
; ++i
)
2444 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2445 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2447 dw2_instantiate_symtab (objfile
, per_cu
);
2454 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2455 enum block_enum block_kind
, const char *name
,
2458 dw2_do_expand_symtabs_matching (objfile
, name
);
2462 dw2_print_stats (struct objfile
*objfile
)
2466 dw2_setup (objfile
);
2468 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2469 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2471 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2473 if (!per_cu
->v
.quick
->symtab
)
2476 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2480 dw2_dump (struct objfile
*objfile
)
2482 /* Nothing worth printing. */
2486 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2487 struct section_offsets
*delta
)
2489 /* There's nothing to relocate here. */
2493 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2494 const char *func_name
)
2496 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2500 dw2_expand_all_symtabs (struct objfile
*objfile
)
2504 dw2_setup (objfile
);
2506 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2507 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2509 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2511 dw2_instantiate_symtab (objfile
, per_cu
);
2516 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2517 const char *filename
)
2521 dw2_setup (objfile
);
2523 /* We don't need to consider type units here.
2524 This is only called for examining code, e.g. expand_line_sal.
2525 There can be an order of magnitude (or more) more type units
2526 than comp units, and we avoid them if we can. */
2528 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2531 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2532 struct quick_file_names
*file_data
;
2534 if (per_cu
->v
.quick
->symtab
)
2537 file_data
= dw2_get_file_names (objfile
, per_cu
);
2538 if (file_data
== NULL
)
2541 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2543 const char *this_name
= file_data
->file_names
[j
];
2544 if (FILENAME_CMP (this_name
, filename
) == 0)
2546 dw2_instantiate_symtab (objfile
, per_cu
);
2554 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2556 struct dwarf2_per_cu_data
*per_cu
;
2558 struct quick_file_names
*file_data
;
2560 dw2_setup (objfile
);
2562 /* index_table is NULL if OBJF_READNOW. */
2563 if (!dwarf2_per_objfile
->index_table
)
2566 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2570 /* Note that this just looks at the very first one named NAME -- but
2571 actually we are looking for a function. find_main_filename
2572 should be rewritten so that it doesn't require a custom hook. It
2573 could just use the ordinary symbol tables. */
2574 /* vec[0] is the length, which must always be >0. */
2575 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2577 file_data
= dw2_get_file_names (objfile
, per_cu
);
2578 if (file_data
== NULL
)
2581 return file_data
->file_names
[file_data
->num_file_names
- 1];
2585 dw2_map_matching_symbols (const char * name
, domain_enum
namespace,
2586 struct objfile
*objfile
, int global
,
2587 int (*callback
) (struct block
*,
2588 struct symbol
*, void *),
2589 void *data
, symbol_compare_ftype
*match
,
2590 symbol_compare_ftype
*ordered_compare
)
2592 /* Currently unimplemented; used for Ada. The function can be called if the
2593 current language is Ada for a non-Ada objfile using GNU index. As Ada
2594 does not look for non-Ada symbols this function should just return. */
2598 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2599 int (*file_matcher
) (const char *, void *),
2600 int (*name_matcher
) (const char *, void *),
2601 enum search_domain kind
,
2606 struct mapped_index
*index
;
2608 dw2_setup (objfile
);
2610 /* index_table is NULL if OBJF_READNOW. */
2611 if (!dwarf2_per_objfile
->index_table
)
2613 index
= dwarf2_per_objfile
->index_table
;
2615 if (file_matcher
!= NULL
)
2616 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2617 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2620 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2621 struct quick_file_names
*file_data
;
2623 per_cu
->v
.quick
->mark
= 0;
2624 if (per_cu
->v
.quick
->symtab
)
2627 file_data
= dw2_get_file_names (objfile
, per_cu
);
2628 if (file_data
== NULL
)
2631 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2633 if (file_matcher (file_data
->file_names
[j
], data
))
2635 per_cu
->v
.quick
->mark
= 1;
2641 for (iter
= 0; iter
< index
->symbol_table_slots
; ++iter
)
2643 offset_type idx
= 2 * iter
;
2645 offset_type
*vec
, vec_len
, vec_idx
;
2647 if (index
->symbol_table
[idx
] == 0 && index
->symbol_table
[idx
+ 1] == 0)
2650 name
= index
->constant_pool
+ MAYBE_SWAP (index
->symbol_table
[idx
]);
2652 if (! (*name_matcher
) (name
, data
))
2655 /* The name was matched, now expand corresponding CUs that were
2657 vec
= (offset_type
*) (index
->constant_pool
2658 + MAYBE_SWAP (index
->symbol_table
[idx
+ 1]));
2659 vec_len
= MAYBE_SWAP (vec
[0]);
2660 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2662 struct dwarf2_per_cu_data
*per_cu
;
2664 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2665 if (file_matcher
== NULL
|| per_cu
->v
.quick
->mark
)
2666 dw2_instantiate_symtab (objfile
, per_cu
);
2671 static struct symtab
*
2672 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2673 struct minimal_symbol
*msymbol
,
2675 struct obj_section
*section
,
2678 struct dwarf2_per_cu_data
*data
;
2680 dw2_setup (objfile
);
2682 if (!objfile
->psymtabs_addrmap
)
2685 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2689 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2690 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2691 paddress (get_objfile_arch (objfile
), pc
));
2693 return dw2_instantiate_symtab (objfile
, data
);
2697 dw2_map_symbol_filenames (struct objfile
*objfile
,
2698 void (*fun
) (const char *, const char *, void *),
2703 dw2_setup (objfile
);
2705 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2706 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2709 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2710 struct quick_file_names
*file_data
;
2712 if (per_cu
->v
.quick
->symtab
)
2715 file_data
= dw2_get_file_names (objfile
, per_cu
);
2716 if (file_data
== NULL
)
2719 for (j
= 0; j
< file_data
->num_file_names
; ++j
)
2721 const char *this_real_name
= dw2_get_real_path (objfile
, file_data
,
2723 (*fun
) (file_data
->file_names
[j
], this_real_name
, data
);
2729 dw2_has_symbols (struct objfile
*objfile
)
2734 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2737 dw2_find_last_source_symtab
,
2738 dw2_forget_cached_source_info
,
2741 dw2_pre_expand_symtabs_matching
,
2745 dw2_expand_symtabs_for_function
,
2746 dw2_expand_all_symtabs
,
2747 dw2_expand_symtabs_with_filename
,
2748 dw2_find_symbol_file
,
2749 dw2_map_matching_symbols
,
2750 dw2_expand_symtabs_matching
,
2751 dw2_find_pc_sect_symtab
,
2752 dw2_map_symbol_filenames
2755 /* Initialize for reading DWARF for this objfile. Return 0 if this
2756 file will use psymtabs, or 1 if using the GNU index. */
2759 dwarf2_initialize_objfile (struct objfile
*objfile
)
2761 /* If we're about to read full symbols, don't bother with the
2762 indices. In this case we also don't care if some other debug
2763 format is making psymtabs, because they are all about to be
2765 if ((objfile
->flags
& OBJF_READNOW
))
2769 dwarf2_per_objfile
->using_index
= 1;
2770 create_all_comp_units (objfile
);
2771 create_debug_types_hash_table (objfile
);
2772 dwarf2_per_objfile
->quick_file_names_table
=
2773 create_quick_file_names_table (dwarf2_per_objfile
->n_comp_units
);
2775 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2776 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2778 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2780 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2781 struct dwarf2_per_cu_quick_data
);
2784 /* Return 1 so that gdb sees the "quick" functions. However,
2785 these functions will be no-ops because we will have expanded
2790 if (dwarf2_read_index (objfile
))
2798 /* Build a partial symbol table. */
2801 dwarf2_build_psymtabs (struct objfile
*objfile
)
2803 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2805 init_psymbol_list (objfile
, 1024);
2808 dwarf2_build_psymtabs_hard (objfile
);
2811 /* Return TRUE if OFFSET is within CU_HEADER. */
2814 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2816 unsigned int bottom
= cu_header
->offset
;
2817 unsigned int top
= (cu_header
->offset
2819 + cu_header
->initial_length_size
);
2821 return (offset
>= bottom
&& offset
< top
);
2824 /* Read in the comp unit header information from the debug_info at info_ptr.
2825 NOTE: This leaves members offset, first_die_offset to be filled in
2829 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2830 gdb_byte
*info_ptr
, bfd
*abfd
)
2833 unsigned int bytes_read
;
2835 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2836 cu_header
->initial_length_size
= bytes_read
;
2837 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2838 info_ptr
+= bytes_read
;
2839 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2841 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2843 info_ptr
+= bytes_read
;
2844 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2846 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2847 if (signed_addr
< 0)
2848 internal_error (__FILE__
, __LINE__
,
2849 _("read_comp_unit_head: dwarf from non elf file"));
2850 cu_header
->signed_addr_p
= signed_addr
;
2856 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2857 gdb_byte
*buffer
, unsigned int buffer_size
,
2860 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2862 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2864 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2865 error (_("Dwarf Error: wrong version in compilation unit header "
2866 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2867 bfd_get_filename (abfd
));
2869 if (header
->abbrev_offset
2870 >= dwarf2_section_size (dwarf2_per_objfile
->objfile
,
2871 &dwarf2_per_objfile
->abbrev
))
2872 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2873 "(offset 0x%lx + 6) [in module %s]"),
2874 (long) header
->abbrev_offset
,
2875 (long) (beg_of_comp_unit
- buffer
),
2876 bfd_get_filename (abfd
));
2878 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2879 > buffer
+ buffer_size
)
2880 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2881 "(offset 0x%lx + 0) [in module %s]"),
2882 (long) header
->length
,
2883 (long) (beg_of_comp_unit
- buffer
),
2884 bfd_get_filename (abfd
));
2889 /* Read in the types comp unit header information from .debug_types entry at
2890 types_ptr. The result is a pointer to one past the end of the header. */
2893 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2894 ULONGEST
*signature
,
2895 gdb_byte
*types_ptr
, bfd
*abfd
)
2897 gdb_byte
*initial_types_ptr
= types_ptr
;
2899 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2900 &dwarf2_per_objfile
->types
);
2901 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2903 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2905 *signature
= read_8_bytes (abfd
, types_ptr
);
2907 types_ptr
+= cu_header
->offset_size
;
2908 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2913 /* Allocate a new partial symtab for file named NAME and mark this new
2914 partial symtab as being an include of PST. */
2917 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2918 struct objfile
*objfile
)
2920 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2922 subpst
->section_offsets
= pst
->section_offsets
;
2923 subpst
->textlow
= 0;
2924 subpst
->texthigh
= 0;
2926 subpst
->dependencies
= (struct partial_symtab
**)
2927 obstack_alloc (&objfile
->objfile_obstack
,
2928 sizeof (struct partial_symtab
*));
2929 subpst
->dependencies
[0] = pst
;
2930 subpst
->number_of_dependencies
= 1;
2932 subpst
->globals_offset
= 0;
2933 subpst
->n_global_syms
= 0;
2934 subpst
->statics_offset
= 0;
2935 subpst
->n_static_syms
= 0;
2936 subpst
->symtab
= NULL
;
2937 subpst
->read_symtab
= pst
->read_symtab
;
2940 /* No private part is necessary for include psymtabs. This property
2941 can be used to differentiate between such include psymtabs and
2942 the regular ones. */
2943 subpst
->read_symtab_private
= NULL
;
2946 /* Read the Line Number Program data and extract the list of files
2947 included by the source file represented by PST. Build an include
2948 partial symtab for each of these included files. */
2951 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2952 struct die_info
*die
,
2953 struct partial_symtab
*pst
)
2955 struct objfile
*objfile
= cu
->objfile
;
2956 bfd
*abfd
= objfile
->obfd
;
2957 struct line_header
*lh
= NULL
;
2958 struct attribute
*attr
;
2960 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2963 unsigned int line_offset
= DW_UNSND (attr
);
2965 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2968 return; /* No linetable, so no includes. */
2970 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2971 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2973 free_line_header (lh
);
2977 hash_type_signature (const void *item
)
2979 const struct signatured_type
*type_sig
= item
;
2981 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2982 return type_sig
->signature
;
2986 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2988 const struct signatured_type
*lhs
= item_lhs
;
2989 const struct signatured_type
*rhs
= item_rhs
;
2991 return lhs
->signature
== rhs
->signature
;
2994 /* Allocate a hash table for signatured types. */
2997 allocate_signatured_type_table (struct objfile
*objfile
)
2999 return htab_create_alloc_ex (41,
3000 hash_type_signature
,
3003 &objfile
->objfile_obstack
,
3004 hashtab_obstack_allocate
,
3005 dummy_obstack_deallocate
);
3008 /* A helper function to add a signatured type CU to a list. */
3011 add_signatured_type_cu_to_list (void **slot
, void *datum
)
3013 struct signatured_type
*sigt
= *slot
;
3014 struct dwarf2_per_cu_data
***datap
= datum
;
3016 **datap
= &sigt
->per_cu
;
3022 /* Create the hash table of all entries in the .debug_types section.
3023 The result is zero if there is an error (e.g. missing .debug_types section),
3024 otherwise non-zero. */
3027 create_debug_types_hash_table (struct objfile
*objfile
)
3031 struct dwarf2_per_cu_data
**iter
;
3033 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
3034 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
3036 if (info_ptr
== NULL
)
3038 dwarf2_per_objfile
->signatured_types
= NULL
;
3042 types_htab
= allocate_signatured_type_table (objfile
);
3044 if (dwarf2_die_debug
)
3045 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
3047 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
3048 + dwarf2_per_objfile
->types
.size
)
3050 unsigned int offset
;
3051 unsigned int offset_size
;
3052 unsigned int type_offset
;
3053 unsigned int length
, initial_length_size
;
3054 unsigned short version
;
3056 struct signatured_type
*type_sig
;
3058 gdb_byte
*ptr
= info_ptr
;
3060 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
3062 /* We need to read the type's signature in order to build the hash
3063 table, but we don't need to read anything else just yet. */
3065 /* Sanity check to ensure entire cu is present. */
3066 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
3067 if (ptr
+ length
+ initial_length_size
3068 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
3070 complaint (&symfile_complaints
,
3071 _("debug type entry runs off end "
3072 "of `.debug_types' section, ignored"));
3076 offset_size
= initial_length_size
== 4 ? 4 : 8;
3077 ptr
+= initial_length_size
;
3078 version
= bfd_get_16 (objfile
->obfd
, ptr
);
3080 ptr
+= offset_size
; /* abbrev offset */
3081 ptr
+= 1; /* address size */
3082 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
3084 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
3086 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
3087 memset (type_sig
, 0, sizeof (*type_sig
));
3088 type_sig
->signature
= signature
;
3089 type_sig
->offset
= offset
;
3090 type_sig
->type_offset
= type_offset
;
3091 type_sig
->per_cu
.objfile
= objfile
;
3092 type_sig
->per_cu
.from_debug_types
= 1;
3094 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
3095 gdb_assert (slot
!= NULL
);
3098 if (dwarf2_die_debug
)
3099 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
3100 offset
, phex (signature
, sizeof (signature
)));
3102 info_ptr
= info_ptr
+ initial_length_size
+ length
;
3105 dwarf2_per_objfile
->signatured_types
= types_htab
;
3107 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
3108 dwarf2_per_objfile
->type_comp_units
3109 = obstack_alloc (&objfile
->objfile_obstack
,
3110 dwarf2_per_objfile
->n_type_comp_units
3111 * sizeof (struct dwarf2_per_cu_data
*));
3112 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
3113 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
3114 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
3115 == dwarf2_per_objfile
->n_type_comp_units
);
3120 /* Lookup a signature based type.
3121 Returns NULL if SIG is not present in the table. */
3123 static struct signatured_type
*
3124 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
3126 struct signatured_type find_entry
, *entry
;
3128 if (dwarf2_per_objfile
->signatured_types
== NULL
)
3130 complaint (&symfile_complaints
,
3131 _("missing `.debug_types' section for DW_FORM_ref_sig8 die"));
3135 find_entry
.signature
= sig
;
3136 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
3140 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
3143 init_cu_die_reader (struct die_reader_specs
*reader
,
3144 struct dwarf2_cu
*cu
)
3146 reader
->abfd
= cu
->objfile
->obfd
;
3148 if (cu
->per_cu
->from_debug_types
)
3150 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3151 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
3155 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3156 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
3160 /* Find the base address of the compilation unit for range lists and
3161 location lists. It will normally be specified by DW_AT_low_pc.
3162 In DWARF-3 draft 4, the base address could be overridden by
3163 DW_AT_entry_pc. It's been removed, but GCC still uses this for
3164 compilation units with discontinuous ranges. */
3167 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
3169 struct attribute
*attr
;
3172 cu
->base_address
= 0;
3174 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
3177 cu
->base_address
= DW_ADDR (attr
);
3182 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3185 cu
->base_address
= DW_ADDR (attr
);
3191 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
3192 to combine the common parts.
3193 Process a compilation unit for a psymtab.
3194 BUFFER is a pointer to the beginning of the dwarf section buffer,
3195 either .debug_info or debug_types.
3196 INFO_PTR is a pointer to the start of the CU.
3197 Returns a pointer to the next CU. */
3200 process_psymtab_comp_unit (struct objfile
*objfile
,
3201 struct dwarf2_per_cu_data
*this_cu
,
3202 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3203 unsigned int buffer_size
)
3205 bfd
*abfd
= objfile
->obfd
;
3206 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3207 struct die_info
*comp_unit_die
;
3208 struct partial_symtab
*pst
;
3210 struct cleanup
*back_to_inner
;
3211 struct dwarf2_cu cu
;
3212 int has_children
, has_pc_info
;
3213 struct attribute
*attr
;
3214 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3215 struct die_reader_specs reader_specs
;
3216 const char *filename
;
3218 init_one_comp_unit (&cu
, objfile
);
3219 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3221 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3222 buffer
, buffer_size
,
3225 /* Complete the cu_header. */
3226 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3227 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3229 cu
.list_in_scope
= &file_symbols
;
3231 /* If this compilation unit was already read in, free the
3232 cached copy in order to read it in again. This is
3233 necessary because we skipped some symbols when we first
3234 read in the compilation unit (see load_partial_dies).
3235 This problem could be avoided, but the benefit is
3237 if (this_cu
->cu
!= NULL
)
3238 free_one_cached_comp_unit (this_cu
->cu
);
3240 /* Note that this is a pointer to our stack frame, being
3241 added to a global data structure. It will be cleaned up
3242 in free_stack_comp_unit when we finish with this
3243 compilation unit. */
3245 cu
.per_cu
= this_cu
;
3247 /* Read the abbrevs for this compilation unit into a table. */
3248 dwarf2_read_abbrevs (abfd
, &cu
);
3249 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3251 /* Read the compilation unit die. */
3252 if (this_cu
->from_debug_types
)
3253 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3254 init_cu_die_reader (&reader_specs
, &cu
);
3255 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3258 if (this_cu
->from_debug_types
)
3260 /* offset,length haven't been set yet for type units. */
3261 this_cu
->offset
= cu
.header
.offset
;
3262 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3264 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3266 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3267 + cu
.header
.initial_length_size
);
3268 do_cleanups (back_to_inner
);
3272 prepare_one_comp_unit (&cu
, comp_unit_die
);
3274 /* Allocate a new partial symbol table structure. */
3275 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3276 if (attr
== NULL
|| !DW_STRING (attr
))
3279 filename
= DW_STRING (attr
);
3280 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3282 /* TEXTLOW and TEXTHIGH are set below. */
3284 objfile
->global_psymbols
.next
,
3285 objfile
->static_psymbols
.next
);
3287 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3289 pst
->dirname
= DW_STRING (attr
);
3291 pst
->read_symtab_private
= this_cu
;
3293 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3295 /* Store the function that reads in the rest of the symbol table. */
3296 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3298 this_cu
->v
.psymtab
= pst
;
3300 dwarf2_find_base_address (comp_unit_die
, &cu
);
3302 /* Possibly set the default values of LOWPC and HIGHPC from
3304 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3305 &best_highpc
, &cu
, pst
);
3306 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3307 /* Store the contiguous range if it is not empty; it can be empty for
3308 CUs with no code. */
3309 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3310 best_lowpc
+ baseaddr
,
3311 best_highpc
+ baseaddr
- 1, pst
);
3313 /* Check if comp unit has_children.
3314 If so, read the rest of the partial symbols from this comp unit.
3315 If not, there's no more debug_info for this comp unit. */
3318 struct partial_die_info
*first_die
;
3319 CORE_ADDR lowpc
, highpc
;
3321 lowpc
= ((CORE_ADDR
) -1);
3322 highpc
= ((CORE_ADDR
) 0);
3324 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3326 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3327 ! has_pc_info
, &cu
);
3329 /* If we didn't find a lowpc, set it to highpc to avoid
3330 complaints from `maint check'. */
3331 if (lowpc
== ((CORE_ADDR
) -1))
3334 /* If the compilation unit didn't have an explicit address range,
3335 then use the information extracted from its child dies. */
3339 best_highpc
= highpc
;
3342 pst
->textlow
= best_lowpc
+ baseaddr
;
3343 pst
->texthigh
= best_highpc
+ baseaddr
;
3345 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3346 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3347 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3348 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3349 sort_pst_symbols (pst
);
3351 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3352 + cu
.header
.initial_length_size
);
3354 if (this_cu
->from_debug_types
)
3356 /* It's not clear we want to do anything with stmt lists here.
3357 Waiting to see what gcc ultimately does. */
3361 /* Get the list of files included in the current compilation unit,
3362 and build a psymtab for each of them. */
3363 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3366 do_cleanups (back_to_inner
);
3371 /* Traversal function for htab_traverse_noresize.
3372 Process one .debug_types comp-unit. */
3375 process_type_comp_unit (void **slot
, void *info
)
3377 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3378 struct objfile
*objfile
= (struct objfile
*) info
;
3379 struct dwarf2_per_cu_data
*this_cu
;
3381 this_cu
= &entry
->per_cu
;
3383 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3384 process_psymtab_comp_unit (objfile
, this_cu
,
3385 dwarf2_per_objfile
->types
.buffer
,
3386 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3387 dwarf2_per_objfile
->types
.size
);
3392 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3393 Build partial symbol tables for the .debug_types comp-units. */
3396 build_type_psymtabs (struct objfile
*objfile
)
3398 if (! create_debug_types_hash_table (objfile
))
3401 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3402 process_type_comp_unit
, objfile
);
3405 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3408 psymtabs_addrmap_cleanup (void *o
)
3410 struct objfile
*objfile
= o
;
3412 objfile
->psymtabs_addrmap
= NULL
;
3415 /* Build the partial symbol table by doing a quick pass through the
3416 .debug_info and .debug_abbrev sections. */
3419 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3422 struct cleanup
*back_to
, *addrmap_cleanup
;
3423 struct obstack temp_obstack
;
3425 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3427 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3428 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3430 /* Any cached compilation units will be linked by the per-objfile
3431 read_in_chain. Make sure to free them when we're done. */
3432 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3434 build_type_psymtabs (objfile
);
3436 create_all_comp_units (objfile
);
3438 /* Create a temporary address map on a temporary obstack. We later
3439 copy this to the final obstack. */
3440 obstack_init (&temp_obstack
);
3441 make_cleanup_obstack_free (&temp_obstack
);
3442 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3443 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3445 /* Since the objects we're extracting from .debug_info vary in
3446 length, only the individual functions to extract them (like
3447 read_comp_unit_head and load_partial_die) can really know whether
3448 the buffer is large enough to hold another complete object.
3450 At the moment, they don't actually check that. If .debug_info
3451 holds just one extra byte after the last compilation unit's dies,
3452 then read_comp_unit_head will happily read off the end of the
3453 buffer. read_partial_die is similarly casual. Those functions
3456 For this loop condition, simply checking whether there's any data
3457 left at all should be sufficient. */
3459 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3460 + dwarf2_per_objfile
->info
.size
))
3462 struct dwarf2_per_cu_data
*this_cu
;
3464 this_cu
= dwarf2_find_comp_unit (info_ptr
3465 - dwarf2_per_objfile
->info
.buffer
,
3468 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3469 dwarf2_per_objfile
->info
.buffer
,
3471 dwarf2_per_objfile
->info
.size
);
3474 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3475 &objfile
->objfile_obstack
);
3476 discard_cleanups (addrmap_cleanup
);
3478 do_cleanups (back_to
);
3481 /* Load the partial DIEs for a secondary CU into memory. */
3484 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3485 struct objfile
*objfile
)
3487 bfd
*abfd
= objfile
->obfd
;
3488 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3489 struct die_info
*comp_unit_die
;
3490 struct dwarf2_cu
*cu
;
3491 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3493 struct die_reader_specs reader_specs
;
3496 gdb_assert (! this_cu
->from_debug_types
);
3498 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3499 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3500 beg_of_comp_unit
= info_ptr
;
3502 if (this_cu
->cu
== NULL
)
3504 cu
= xmalloc (sizeof (*cu
));
3505 init_one_comp_unit (cu
, objfile
);
3509 /* If an error occurs while loading, release our storage. */
3510 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3512 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3513 dwarf2_per_objfile
->info
.buffer
,
3514 dwarf2_per_objfile
->info
.size
,
3517 /* Complete the cu_header. */
3518 cu
->header
.offset
= this_cu
->offset
;
3519 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3521 /* Link this compilation unit into the compilation unit tree. */
3523 cu
->per_cu
= this_cu
;
3525 /* Link this CU into read_in_chain. */
3526 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3527 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3532 info_ptr
+= cu
->header
.first_die_offset
;
3535 /* Read the abbrevs for this compilation unit into a table. */
3536 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3537 dwarf2_read_abbrevs (abfd
, cu
);
3538 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3540 /* Read the compilation unit die. */
3541 init_cu_die_reader (&reader_specs
, cu
);
3542 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3545 prepare_one_comp_unit (cu
, comp_unit_die
);
3547 /* Check if comp unit has_children.
3548 If so, read the rest of the partial symbols from this comp unit.
3549 If not, there's no more debug_info for this comp unit. */
3551 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3553 do_cleanups (free_abbrevs_cleanup
);
3557 /* We've successfully allocated this compilation unit. Let our
3558 caller clean it up when finished with it. */
3559 discard_cleanups (free_cu_cleanup
);
3563 /* Create a list of all compilation units in OBJFILE. We do this only
3564 if an inter-comp-unit reference is found; presumably if there is one,
3565 there will be many, and one will occur early in the .debug_info section.
3566 So there's no point in building this list incrementally. */
3569 create_all_comp_units (struct objfile
*objfile
)
3573 struct dwarf2_per_cu_data
**all_comp_units
;
3576 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3577 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3581 all_comp_units
= xmalloc (n_allocated
3582 * sizeof (struct dwarf2_per_cu_data
*));
3584 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
3585 + dwarf2_per_objfile
->info
.size
)
3587 unsigned int length
, initial_length_size
;
3588 struct dwarf2_per_cu_data
*this_cu
;
3589 unsigned int offset
;
3591 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3593 /* Read just enough information to find out where the next
3594 compilation unit is. */
3595 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3596 &initial_length_size
);
3598 /* Save the compilation unit for later lookup. */
3599 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3600 sizeof (struct dwarf2_per_cu_data
));
3601 memset (this_cu
, 0, sizeof (*this_cu
));
3602 this_cu
->offset
= offset
;
3603 this_cu
->length
= length
+ initial_length_size
;
3604 this_cu
->objfile
= objfile
;
3606 if (n_comp_units
== n_allocated
)
3609 all_comp_units
= xrealloc (all_comp_units
,
3611 * sizeof (struct dwarf2_per_cu_data
*));
3613 all_comp_units
[n_comp_units
++] = this_cu
;
3615 info_ptr
= info_ptr
+ this_cu
->length
;
3618 dwarf2_per_objfile
->all_comp_units
3619 = obstack_alloc (&objfile
->objfile_obstack
,
3620 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3621 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3622 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3623 xfree (all_comp_units
);
3624 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3627 /* Process all loaded DIEs for compilation unit CU, starting at
3628 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3629 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3630 DW_AT_ranges). If NEED_PC is set, then this function will set
3631 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3632 and record the covered ranges in the addrmap. */
3635 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3636 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3638 struct partial_die_info
*pdi
;
3640 /* Now, march along the PDI's, descending into ones which have
3641 interesting children but skipping the children of the other ones,
3642 until we reach the end of the compilation unit. */
3648 fixup_partial_die (pdi
, cu
);
3650 /* Anonymous namespaces or modules have no name but have interesting
3651 children, so we need to look at them. Ditto for anonymous
3654 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3655 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3659 case DW_TAG_subprogram
:
3660 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3662 case DW_TAG_constant
:
3663 case DW_TAG_variable
:
3664 case DW_TAG_typedef
:
3665 case DW_TAG_union_type
:
3666 if (!pdi
->is_declaration
)
3668 add_partial_symbol (pdi
, cu
);
3671 case DW_TAG_class_type
:
3672 case DW_TAG_interface_type
:
3673 case DW_TAG_structure_type
:
3674 if (!pdi
->is_declaration
)
3676 add_partial_symbol (pdi
, cu
);
3679 case DW_TAG_enumeration_type
:
3680 if (!pdi
->is_declaration
)
3681 add_partial_enumeration (pdi
, cu
);
3683 case DW_TAG_base_type
:
3684 case DW_TAG_subrange_type
:
3685 /* File scope base type definitions are added to the partial
3687 add_partial_symbol (pdi
, cu
);
3689 case DW_TAG_namespace
:
3690 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3693 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3700 /* If the die has a sibling, skip to the sibling. */
3702 pdi
= pdi
->die_sibling
;
3706 /* Functions used to compute the fully scoped name of a partial DIE.
3708 Normally, this is simple. For C++, the parent DIE's fully scoped
3709 name is concatenated with "::" and the partial DIE's name. For
3710 Java, the same thing occurs except that "." is used instead of "::".
3711 Enumerators are an exception; they use the scope of their parent
3712 enumeration type, i.e. the name of the enumeration type is not
3713 prepended to the enumerator.
3715 There are two complexities. One is DW_AT_specification; in this
3716 case "parent" means the parent of the target of the specification,
3717 instead of the direct parent of the DIE. The other is compilers
3718 which do not emit DW_TAG_namespace; in this case we try to guess
3719 the fully qualified name of structure types from their members'
3720 linkage names. This must be done using the DIE's children rather
3721 than the children of any DW_AT_specification target. We only need
3722 to do this for structures at the top level, i.e. if the target of
3723 any DW_AT_specification (if any; otherwise the DIE itself) does not
3726 /* Compute the scope prefix associated with PDI's parent, in
3727 compilation unit CU. The result will be allocated on CU's
3728 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3729 field. NULL is returned if no prefix is necessary. */
3731 partial_die_parent_scope (struct partial_die_info
*pdi
,
3732 struct dwarf2_cu
*cu
)
3734 char *grandparent_scope
;
3735 struct partial_die_info
*parent
, *real_pdi
;
3737 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3738 then this means the parent of the specification DIE. */
3741 while (real_pdi
->has_specification
)
3742 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3744 parent
= real_pdi
->die_parent
;
3748 if (parent
->scope_set
)
3749 return parent
->scope
;
3751 fixup_partial_die (parent
, cu
);
3753 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3755 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3756 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3757 Work around this problem here. */
3758 if (cu
->language
== language_cplus
3759 && parent
->tag
== DW_TAG_namespace
3760 && strcmp (parent
->name
, "::") == 0
3761 && grandparent_scope
== NULL
)
3763 parent
->scope
= NULL
;
3764 parent
->scope_set
= 1;
3768 if (parent
->tag
== DW_TAG_namespace
3769 || parent
->tag
== DW_TAG_module
3770 || parent
->tag
== DW_TAG_structure_type
3771 || parent
->tag
== DW_TAG_class_type
3772 || parent
->tag
== DW_TAG_interface_type
3773 || parent
->tag
== DW_TAG_union_type
3774 || parent
->tag
== DW_TAG_enumeration_type
)
3776 if (grandparent_scope
== NULL
)
3777 parent
->scope
= parent
->name
;
3779 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
,
3781 parent
->name
, 0, cu
);
3783 else if (parent
->tag
== DW_TAG_enumerator
)
3784 /* Enumerators should not get the name of the enumeration as a prefix. */
3785 parent
->scope
= grandparent_scope
;
3788 /* FIXME drow/2004-04-01: What should we be doing with
3789 function-local names? For partial symbols, we should probably be
3791 complaint (&symfile_complaints
,
3792 _("unhandled containing DIE tag %d for DIE at %d"),
3793 parent
->tag
, pdi
->offset
);
3794 parent
->scope
= grandparent_scope
;
3797 parent
->scope_set
= 1;
3798 return parent
->scope
;
3801 /* Return the fully scoped name associated with PDI, from compilation unit
3802 CU. The result will be allocated with malloc. */
3804 partial_die_full_name (struct partial_die_info
*pdi
,
3805 struct dwarf2_cu
*cu
)
3809 /* If this is a template instantiation, we can not work out the
3810 template arguments from partial DIEs. So, unfortunately, we have
3811 to go through the full DIEs. At least any work we do building
3812 types here will be reused if full symbols are loaded later. */
3813 if (pdi
->has_template_arguments
)
3815 fixup_partial_die (pdi
, cu
);
3817 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3819 struct die_info
*die
;
3820 struct attribute attr
;
3821 struct dwarf2_cu
*ref_cu
= cu
;
3824 attr
.form
= DW_FORM_ref_addr
;
3825 attr
.u
.addr
= pdi
->offset
;
3826 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3828 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3832 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3833 if (parent_scope
== NULL
)
3836 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3840 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3842 struct objfile
*objfile
= cu
->objfile
;
3844 char *actual_name
= NULL
;
3845 const struct partial_symbol
*psym
= NULL
;
3847 int built_actual_name
= 0;
3849 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3851 actual_name
= partial_die_full_name (pdi
, cu
);
3853 built_actual_name
= 1;
3855 if (actual_name
== NULL
)
3856 actual_name
= pdi
->name
;
3860 case DW_TAG_subprogram
:
3861 if (pdi
->is_external
|| cu
->language
== language_ada
)
3863 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3864 of the global scope. But in Ada, we want to be able to access
3865 nested procedures globally. So all Ada subprograms are stored
3866 in the global scope. */
3867 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3868 mst_text, objfile); */
3869 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3871 VAR_DOMAIN
, LOC_BLOCK
,
3872 &objfile
->global_psymbols
,
3873 0, pdi
->lowpc
+ baseaddr
,
3874 cu
->language
, objfile
);
3878 /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3879 mst_file_text, objfile); */
3880 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3882 VAR_DOMAIN
, LOC_BLOCK
,
3883 &objfile
->static_psymbols
,
3884 0, pdi
->lowpc
+ baseaddr
,
3885 cu
->language
, objfile
);
3888 case DW_TAG_constant
:
3890 struct psymbol_allocation_list
*list
;
3892 if (pdi
->is_external
)
3893 list
= &objfile
->global_psymbols
;
3895 list
= &objfile
->static_psymbols
;
3896 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3897 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3898 list
, 0, 0, cu
->language
, objfile
);
3901 case DW_TAG_variable
:
3903 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3907 && !dwarf2_per_objfile
->has_section_at_zero
)
3909 /* A global or static variable may also have been stripped
3910 out by the linker if unused, in which case its address
3911 will be nullified; do not add such variables into partial
3912 symbol table then. */
3914 else if (pdi
->is_external
)
3917 Don't enter into the minimal symbol tables as there is
3918 a minimal symbol table entry from the ELF symbols already.
3919 Enter into partial symbol table if it has a location
3920 descriptor or a type.
3921 If the location descriptor is missing, new_symbol will create
3922 a LOC_UNRESOLVED symbol, the address of the variable will then
3923 be determined from the minimal symbol table whenever the variable
3925 The address for the partial symbol table entry is not
3926 used by GDB, but it comes in handy for debugging partial symbol
3929 if (pdi
->locdesc
|| pdi
->has_type
)
3930 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3932 VAR_DOMAIN
, LOC_STATIC
,
3933 &objfile
->global_psymbols
,
3935 cu
->language
, objfile
);
3939 /* Static Variable. Skip symbols without location descriptors. */
3940 if (pdi
->locdesc
== NULL
)
3942 if (built_actual_name
)
3943 xfree (actual_name
);
3946 /* prim_record_minimal_symbol (actual_name, addr + baseaddr,
3947 mst_file_data, objfile); */
3948 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3950 VAR_DOMAIN
, LOC_STATIC
,
3951 &objfile
->static_psymbols
,
3953 cu
->language
, objfile
);
3956 case DW_TAG_typedef
:
3957 case DW_TAG_base_type
:
3958 case DW_TAG_subrange_type
:
3959 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3961 VAR_DOMAIN
, LOC_TYPEDEF
,
3962 &objfile
->static_psymbols
,
3963 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3965 case DW_TAG_namespace
:
3966 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3968 VAR_DOMAIN
, LOC_TYPEDEF
,
3969 &objfile
->global_psymbols
,
3970 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3972 case DW_TAG_class_type
:
3973 case DW_TAG_interface_type
:
3974 case DW_TAG_structure_type
:
3975 case DW_TAG_union_type
:
3976 case DW_TAG_enumeration_type
:
3977 /* Skip external references. The DWARF standard says in the section
3978 about "Structure, Union, and Class Type Entries": "An incomplete
3979 structure, union or class type is represented by a structure,
3980 union or class entry that does not have a byte size attribute
3981 and that has a DW_AT_declaration attribute." */
3982 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3984 if (built_actual_name
)
3985 xfree (actual_name
);
3989 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3990 static vs. global. */
3991 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3993 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3994 (cu
->language
== language_cplus
3995 || cu
->language
== language_java
)
3996 ? &objfile
->global_psymbols
3997 : &objfile
->static_psymbols
,
3998 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4001 case DW_TAG_enumerator
:
4002 add_psymbol_to_list (actual_name
, strlen (actual_name
),
4004 VAR_DOMAIN
, LOC_CONST
,
4005 (cu
->language
== language_cplus
4006 || cu
->language
== language_java
)
4007 ? &objfile
->global_psymbols
4008 : &objfile
->static_psymbols
,
4009 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
4015 if (built_actual_name
)
4016 xfree (actual_name
);
4019 /* Read a partial die corresponding to a namespace; also, add a symbol
4020 corresponding to that namespace to the symbol table. NAMESPACE is
4021 the name of the enclosing namespace. */
4024 add_partial_namespace (struct partial_die_info
*pdi
,
4025 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4026 int need_pc
, struct dwarf2_cu
*cu
)
4028 /* Add a symbol for the namespace. */
4030 add_partial_symbol (pdi
, cu
);
4032 /* Now scan partial symbols in that namespace. */
4034 if (pdi
->has_children
)
4035 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4038 /* Read a partial die corresponding to a Fortran module. */
4041 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
4042 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
4044 /* Now scan partial symbols in that module. */
4046 if (pdi
->has_children
)
4047 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
4050 /* Read a partial die corresponding to a subprogram and create a partial
4051 symbol for that subprogram. When the CU language allows it, this
4052 routine also defines a partial symbol for each nested subprogram
4053 that this subprogram contains.
4055 DIE my also be a lexical block, in which case we simply search
4056 recursively for suprograms defined inside that lexical block.
4057 Again, this is only performed when the CU language allows this
4058 type of definitions. */
4061 add_partial_subprogram (struct partial_die_info
*pdi
,
4062 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4063 int need_pc
, struct dwarf2_cu
*cu
)
4065 if (pdi
->tag
== DW_TAG_subprogram
)
4067 if (pdi
->has_pc_info
)
4069 if (pdi
->lowpc
< *lowpc
)
4070 *lowpc
= pdi
->lowpc
;
4071 if (pdi
->highpc
> *highpc
)
4072 *highpc
= pdi
->highpc
;
4076 struct objfile
*objfile
= cu
->objfile
;
4078 baseaddr
= ANOFFSET (objfile
->section_offsets
,
4079 SECT_OFF_TEXT (objfile
));
4080 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4081 pdi
->lowpc
+ baseaddr
,
4082 pdi
->highpc
- 1 + baseaddr
,
4083 cu
->per_cu
->v
.psymtab
);
4085 if (!pdi
->is_declaration
)
4086 /* Ignore subprogram DIEs that do not have a name, they are
4087 illegal. Do not emit a complaint at this point, we will
4088 do so when we convert this psymtab into a symtab. */
4090 add_partial_symbol (pdi
, cu
);
4094 if (! pdi
->has_children
)
4097 if (cu
->language
== language_ada
)
4099 pdi
= pdi
->die_child
;
4102 fixup_partial_die (pdi
, cu
);
4103 if (pdi
->tag
== DW_TAG_subprogram
4104 || pdi
->tag
== DW_TAG_lexical_block
)
4105 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
4106 pdi
= pdi
->die_sibling
;
4111 /* Read a partial die corresponding to an enumeration type. */
4114 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
4115 struct dwarf2_cu
*cu
)
4117 struct partial_die_info
*pdi
;
4119 if (enum_pdi
->name
!= NULL
)
4120 add_partial_symbol (enum_pdi
, cu
);
4122 pdi
= enum_pdi
->die_child
;
4125 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
4126 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
4128 add_partial_symbol (pdi
, cu
);
4129 pdi
= pdi
->die_sibling
;
4133 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
4134 Return the corresponding abbrev, or NULL if the number is zero (indicating
4135 an empty DIE). In either case *BYTES_READ will be set to the length of
4136 the initial number. */
4138 static struct abbrev_info
*
4139 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
4140 struct dwarf2_cu
*cu
)
4142 bfd
*abfd
= cu
->objfile
->obfd
;
4143 unsigned int abbrev_number
;
4144 struct abbrev_info
*abbrev
;
4146 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
4148 if (abbrev_number
== 0)
4151 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
4154 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"),
4155 abbrev_number
, bfd_get_filename (abfd
));
4161 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4162 Returns a pointer to the end of a series of DIEs, terminated by an empty
4163 DIE. Any children of the skipped DIEs will also be skipped. */
4166 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4168 struct abbrev_info
*abbrev
;
4169 unsigned int bytes_read
;
4173 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4175 return info_ptr
+ bytes_read
;
4177 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4181 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4182 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4183 abbrev corresponding to that skipped uleb128 should be passed in
4184 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4188 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4189 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4191 unsigned int bytes_read
;
4192 struct attribute attr
;
4193 bfd
*abfd
= cu
->objfile
->obfd
;
4194 unsigned int form
, i
;
4196 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4198 /* The only abbrev we care about is DW_AT_sibling. */
4199 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4201 read_attribute (&attr
, &abbrev
->attrs
[i
],
4202 abfd
, info_ptr
, cu
);
4203 if (attr
.form
== DW_FORM_ref_addr
)
4204 complaint (&symfile_complaints
,
4205 _("ignoring absolute DW_AT_sibling"));
4207 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4210 /* If it isn't DW_AT_sibling, skip this attribute. */
4211 form
= abbrev
->attrs
[i
].form
;
4215 case DW_FORM_ref_addr
:
4216 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4217 and later it is offset sized. */
4218 if (cu
->header
.version
== 2)
4219 info_ptr
+= cu
->header
.addr_size
;
4221 info_ptr
+= cu
->header
.offset_size
;
4224 info_ptr
+= cu
->header
.addr_size
;
4231 case DW_FORM_flag_present
:
4243 case DW_FORM_ref_sig8
:
4246 case DW_FORM_string
:
4247 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4248 info_ptr
+= bytes_read
;
4250 case DW_FORM_sec_offset
:
4252 info_ptr
+= cu
->header
.offset_size
;
4254 case DW_FORM_exprloc
:
4256 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4257 info_ptr
+= bytes_read
;
4259 case DW_FORM_block1
:
4260 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4262 case DW_FORM_block2
:
4263 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4265 case DW_FORM_block4
:
4266 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4270 case DW_FORM_ref_udata
:
4271 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4273 case DW_FORM_indirect
:
4274 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4275 info_ptr
+= bytes_read
;
4276 /* We need to continue parsing from here, so just go back to
4278 goto skip_attribute
;
4281 error (_("Dwarf Error: Cannot handle %s "
4282 "in DWARF reader [in module %s]"),
4283 dwarf_form_name (form
),
4284 bfd_get_filename (abfd
));
4288 if (abbrev
->has_children
)
4289 return skip_children (buffer
, info_ptr
, cu
);
4294 /* Locate ORIG_PDI's sibling.
4295 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4299 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4300 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4301 bfd
*abfd
, struct dwarf2_cu
*cu
)
4303 /* Do we know the sibling already? */
4305 if (orig_pdi
->sibling
)
4306 return orig_pdi
->sibling
;
4308 /* Are there any children to deal with? */
4310 if (!orig_pdi
->has_children
)
4313 /* Skip the children the long way. */
4315 return skip_children (buffer
, info_ptr
, cu
);
4318 /* Expand this partial symbol table into a full symbol table. */
4321 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4327 warning (_("bug: psymtab for %s is already read in."),
4334 printf_filtered (_("Reading in symbols for %s..."),
4336 gdb_flush (gdb_stdout
);
4339 /* Restore our global data. */
4340 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4341 dwarf2_objfile_data_key
);
4343 /* If this psymtab is constructed from a debug-only objfile, the
4344 has_section_at_zero flag will not necessarily be correct. We
4345 can get the correct value for this flag by looking at the data
4346 associated with the (presumably stripped) associated objfile. */
4347 if (pst
->objfile
->separate_debug_objfile_backlink
)
4349 struct dwarf2_per_objfile
*dpo_backlink
4350 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4351 dwarf2_objfile_data_key
);
4353 dwarf2_per_objfile
->has_section_at_zero
4354 = dpo_backlink
->has_section_at_zero
;
4357 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4359 psymtab_to_symtab_1 (pst
);
4361 /* Finish up the debug error message. */
4363 printf_filtered (_("done.\n"));
4368 /* Add PER_CU to the queue. */
4371 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4373 struct dwarf2_queue_item
*item
;
4376 item
= xmalloc (sizeof (*item
));
4377 item
->per_cu
= per_cu
;
4380 if (dwarf2_queue
== NULL
)
4381 dwarf2_queue
= item
;
4383 dwarf2_queue_tail
->next
= item
;
4385 dwarf2_queue_tail
= item
;
4388 /* Process the queue. */
4391 process_queue (struct objfile
*objfile
)
4393 struct dwarf2_queue_item
*item
, *next_item
;
4395 /* The queue starts out with one item, but following a DIE reference
4396 may load a new CU, adding it to the end of the queue. */
4397 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4399 if (dwarf2_per_objfile
->using_index
4400 ? !item
->per_cu
->v
.quick
->symtab
4401 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4402 process_full_comp_unit (item
->per_cu
);
4404 item
->per_cu
->queued
= 0;
4405 next_item
= item
->next
;
4409 dwarf2_queue_tail
= NULL
;
4412 /* Free all allocated queue entries. This function only releases anything if
4413 an error was thrown; if the queue was processed then it would have been
4414 freed as we went along. */
4417 dwarf2_release_queue (void *dummy
)
4419 struct dwarf2_queue_item
*item
, *last
;
4421 item
= dwarf2_queue
;
4424 /* Anything still marked queued is likely to be in an
4425 inconsistent state, so discard it. */
4426 if (item
->per_cu
->queued
)
4428 if (item
->per_cu
->cu
!= NULL
)
4429 free_one_cached_comp_unit (item
->per_cu
->cu
);
4430 item
->per_cu
->queued
= 0;
4438 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4441 /* Read in full symbols for PST, and anything it depends on. */
4444 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4446 struct dwarf2_per_cu_data
*per_cu
;
4447 struct cleanup
*back_to
;
4450 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4451 if (!pst
->dependencies
[i
]->readin
)
4453 /* Inform about additional files that need to be read in. */
4456 /* FIXME: i18n: Need to make this a single string. */
4457 fputs_filtered (" ", gdb_stdout
);
4459 fputs_filtered ("and ", gdb_stdout
);
4461 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4462 wrap_here (""); /* Flush output. */
4463 gdb_flush (gdb_stdout
);
4465 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4468 per_cu
= pst
->read_symtab_private
;
4472 /* It's an include file, no symbols to read for it.
4473 Everything is in the parent symtab. */
4478 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4481 /* Load the DIEs associated with PER_CU into memory. */
4484 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
4485 struct objfile
*objfile
)
4487 bfd
*abfd
= objfile
->obfd
;
4488 struct dwarf2_cu
*cu
;
4489 unsigned int offset
;
4490 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4491 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4492 struct attribute
*attr
;
4495 gdb_assert (! per_cu
->from_debug_types
);
4497 /* Set local variables from the partial symbol table info. */
4498 offset
= per_cu
->offset
;
4500 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4501 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4502 beg_of_comp_unit
= info_ptr
;
4504 if (per_cu
->cu
== NULL
)
4506 cu
= xmalloc (sizeof (*cu
));
4507 init_one_comp_unit (cu
, objfile
);
4511 /* If an error occurs while loading, release our storage. */
4512 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4514 /* Read in the comp_unit header. */
4515 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4517 /* Complete the cu_header. */
4518 cu
->header
.offset
= offset
;
4519 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4521 /* Read the abbrevs for this compilation unit. */
4522 dwarf2_read_abbrevs (abfd
, cu
);
4523 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4525 /* Link this compilation unit into the compilation unit tree. */
4527 cu
->per_cu
= per_cu
;
4529 /* Link this CU into read_in_chain. */
4530 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4531 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4536 info_ptr
+= cu
->header
.first_die_offset
;
4539 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4541 /* We try not to read any attributes in this function, because not
4542 all objfiles needed for references have been loaded yet, and symbol
4543 table processing isn't initialized. But we have to set the CU language,
4544 or we won't be able to build types correctly. */
4545 prepare_one_comp_unit (cu
, cu
->dies
);
4547 /* Similarly, if we do not read the producer, we can not apply
4548 producer-specific interpretation. */
4549 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4551 cu
->producer
= DW_STRING (attr
);
4555 do_cleanups (free_abbrevs_cleanup
);
4557 /* We've successfully allocated this compilation unit. Let our
4558 caller clean it up when finished with it. */
4559 discard_cleanups (free_cu_cleanup
);
4563 /* Add a DIE to the delayed physname list. */
4566 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4567 const char *name
, struct die_info
*die
,
4568 struct dwarf2_cu
*cu
)
4570 struct delayed_method_info mi
;
4572 mi
.fnfield_index
= fnfield_index
;
4576 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4579 /* A cleanup for freeing the delayed method list. */
4582 free_delayed_list (void *ptr
)
4584 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4585 if (cu
->method_list
!= NULL
)
4587 VEC_free (delayed_method_info
, cu
->method_list
);
4588 cu
->method_list
= NULL
;
4592 /* Compute the physnames of any methods on the CU's method list.
4594 The computation of method physnames is delayed in order to avoid the
4595 (bad) condition that one of the method's formal parameters is of an as yet
4599 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4602 struct delayed_method_info
*mi
;
4603 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4606 struct fn_fieldlist
*fn_flp
4607 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4608 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4609 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4613 /* Generate full symbol information for PST and CU, whose DIEs have
4614 already been loaded into memory. */
4617 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4619 struct dwarf2_cu
*cu
= per_cu
->cu
;
4620 struct objfile
*objfile
= per_cu
->objfile
;
4621 CORE_ADDR lowpc
, highpc
;
4622 struct symtab
*symtab
;
4623 struct cleanup
*back_to
, *delayed_list_cleanup
;
4626 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4629 back_to
= make_cleanup (really_free_pendings
, NULL
);
4630 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4632 cu
->list_in_scope
= &file_symbols
;
4634 dwarf2_find_base_address (cu
->dies
, cu
);
4636 /* Do line number decoding in read_file_scope () */
4637 process_die (cu
->dies
, cu
);
4639 /* Now that we have processed all the DIEs in the CU, all the types
4640 should be complete, and it should now be safe to compute all of the
4642 compute_delayed_physnames (cu
);
4643 do_cleanups (delayed_list_cleanup
);
4645 /* Some compilers don't define a DW_AT_high_pc attribute for the
4646 compilation unit. If the DW_AT_high_pc is missing, synthesize
4647 it, by scanning the DIE's below the compilation unit. */
4648 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4650 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4652 /* Set symtab language to language from DW_AT_language.
4653 If the compilation is from a C file generated by language preprocessors,
4654 do not set the language if it was already deduced by start_subfile. */
4656 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4658 symtab
->language
= cu
->language
;
4661 if (dwarf2_per_objfile
->using_index
)
4662 per_cu
->v
.quick
->symtab
= symtab
;
4665 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4666 pst
->symtab
= symtab
;
4670 do_cleanups (back_to
);
4673 /* Process a die and its children. */
4676 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4680 case DW_TAG_padding
:
4682 case DW_TAG_compile_unit
:
4683 read_file_scope (die
, cu
);
4685 case DW_TAG_type_unit
:
4686 read_type_unit_scope (die
, cu
);
4688 case DW_TAG_subprogram
:
4689 case DW_TAG_inlined_subroutine
:
4690 read_func_scope (die
, cu
);
4692 case DW_TAG_lexical_block
:
4693 case DW_TAG_try_block
:
4694 case DW_TAG_catch_block
:
4695 read_lexical_block_scope (die
, cu
);
4697 case DW_TAG_class_type
:
4698 case DW_TAG_interface_type
:
4699 case DW_TAG_structure_type
:
4700 case DW_TAG_union_type
:
4701 process_structure_scope (die
, cu
);
4703 case DW_TAG_enumeration_type
:
4704 process_enumeration_scope (die
, cu
);
4707 /* These dies have a type, but processing them does not create
4708 a symbol or recurse to process the children. Therefore we can
4709 read them on-demand through read_type_die. */
4710 case DW_TAG_subroutine_type
:
4711 case DW_TAG_set_type
:
4712 case DW_TAG_array_type
:
4713 case DW_TAG_pointer_type
:
4714 case DW_TAG_ptr_to_member_type
:
4715 case DW_TAG_reference_type
:
4716 case DW_TAG_string_type
:
4719 case DW_TAG_base_type
:
4720 case DW_TAG_subrange_type
:
4721 case DW_TAG_typedef
:
4722 /* Add a typedef symbol for the type definition, if it has a
4724 new_symbol (die
, read_type_die (die
, cu
), cu
);
4726 case DW_TAG_common_block
:
4727 read_common_block (die
, cu
);
4729 case DW_TAG_common_inclusion
:
4731 case DW_TAG_namespace
:
4732 processing_has_namespace_info
= 1;
4733 read_namespace (die
, cu
);
4736 processing_has_namespace_info
= 1;
4737 read_module (die
, cu
);
4739 case DW_TAG_imported_declaration
:
4740 case DW_TAG_imported_module
:
4741 processing_has_namespace_info
= 1;
4742 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4743 || cu
->language
!= language_fortran
))
4744 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4745 dwarf_tag_name (die
->tag
));
4746 read_import_statement (die
, cu
);
4749 new_symbol (die
, NULL
, cu
);
4754 /* A helper function for dwarf2_compute_name which determines whether DIE
4755 needs to have the name of the scope prepended to the name listed in the
4759 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4761 struct attribute
*attr
;
4765 case DW_TAG_namespace
:
4766 case DW_TAG_typedef
:
4767 case DW_TAG_class_type
:
4768 case DW_TAG_interface_type
:
4769 case DW_TAG_structure_type
:
4770 case DW_TAG_union_type
:
4771 case DW_TAG_enumeration_type
:
4772 case DW_TAG_enumerator
:
4773 case DW_TAG_subprogram
:
4777 case DW_TAG_variable
:
4778 case DW_TAG_constant
:
4779 /* We only need to prefix "globally" visible variables. These include
4780 any variable marked with DW_AT_external or any variable that
4781 lives in a namespace. [Variables in anonymous namespaces
4782 require prefixing, but they are not DW_AT_external.] */
4784 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4786 struct dwarf2_cu
*spec_cu
= cu
;
4788 return die_needs_namespace (die_specification (die
, &spec_cu
),
4792 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4793 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4794 && die
->parent
->tag
!= DW_TAG_module
)
4796 /* A variable in a lexical block of some kind does not need a
4797 namespace, even though in C++ such variables may be external
4798 and have a mangled name. */
4799 if (die
->parent
->tag
== DW_TAG_lexical_block
4800 || die
->parent
->tag
== DW_TAG_try_block
4801 || die
->parent
->tag
== DW_TAG_catch_block
4802 || die
->parent
->tag
== DW_TAG_subprogram
)
4811 /* Retrieve the last character from a mem_file. */
4814 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4816 char *last_char_p
= (char *) object
;
4819 *last_char_p
= buffer
[length
- 1];
4822 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4823 compute the physname for the object, which include a method's
4824 formal parameters (C++/Java) and return type (Java).
4826 For Ada, return the DIE's linkage name rather than the fully qualified
4827 name. PHYSNAME is ignored..
4829 The result is allocated on the objfile_obstack and canonicalized. */
4832 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4836 name
= dwarf2_name (die
, cu
);
4838 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4839 compute it by typename_concat inside GDB. */
4840 if (cu
->language
== language_ada
4841 || (cu
->language
== language_fortran
&& physname
))
4843 /* For Ada unit, we prefer the linkage name over the name, as
4844 the former contains the exported name, which the user expects
4845 to be able to reference. Ideally, we want the user to be able
4846 to reference this entity using either natural or linkage name,
4847 but we haven't started looking at this enhancement yet. */
4848 struct attribute
*attr
;
4850 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4852 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4853 if (attr
&& DW_STRING (attr
))
4854 return DW_STRING (attr
);
4857 /* These are the only languages we know how to qualify names in. */
4859 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4860 || cu
->language
== language_fortran
))
4862 if (die_needs_namespace (die
, cu
))
4866 struct ui_file
*buf
;
4868 prefix
= determine_prefix (die
, cu
);
4869 buf
= mem_fileopen ();
4870 if (*prefix
!= '\0')
4872 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4875 fputs_unfiltered (prefixed_name
, buf
);
4876 xfree (prefixed_name
);
4879 fputs_unfiltered (name
, buf
);
4881 /* Template parameters may be specified in the DIE's DW_AT_name, or
4882 as children with DW_TAG_template_type_param or
4883 DW_TAG_value_type_param. If the latter, add them to the name
4884 here. If the name already has template parameters, then
4885 skip this step; some versions of GCC emit both, and
4886 it is more efficient to use the pre-computed name.
4888 Something to keep in mind about this process: it is very
4889 unlikely, or in some cases downright impossible, to produce
4890 something that will match the mangled name of a function.
4891 If the definition of the function has the same debug info,
4892 we should be able to match up with it anyway. But fallbacks
4893 using the minimal symbol, for instance to find a method
4894 implemented in a stripped copy of libstdc++, will not work.
4895 If we do not have debug info for the definition, we will have to
4896 match them up some other way.
4898 When we do name matching there is a related problem with function
4899 templates; two instantiated function templates are allowed to
4900 differ only by their return types, which we do not add here. */
4902 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4904 struct attribute
*attr
;
4905 struct die_info
*child
;
4908 die
->building_fullname
= 1;
4910 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4915 struct dwarf2_locexpr_baton
*baton
;
4918 if (child
->tag
!= DW_TAG_template_type_param
4919 && child
->tag
!= DW_TAG_template_value_param
)
4924 fputs_unfiltered ("<", buf
);
4928 fputs_unfiltered (", ", buf
);
4930 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4933 complaint (&symfile_complaints
,
4934 _("template parameter missing DW_AT_type"));
4935 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4938 type
= die_type (child
, cu
);
4940 if (child
->tag
== DW_TAG_template_type_param
)
4942 c_print_type (type
, "", buf
, -1, 0);
4946 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4949 complaint (&symfile_complaints
,
4950 _("template parameter missing "
4951 "DW_AT_const_value"));
4952 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4956 dwarf2_const_value_attr (attr
, type
, name
,
4957 &cu
->comp_unit_obstack
, cu
,
4958 &value
, &bytes
, &baton
);
4960 if (TYPE_NOSIGN (type
))
4961 /* GDB prints characters as NUMBER 'CHAR'. If that's
4962 changed, this can use value_print instead. */
4963 c_printchar (value
, type
, buf
);
4966 struct value_print_options opts
;
4969 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4973 else if (bytes
!= NULL
)
4975 v
= allocate_value (type
);
4976 memcpy (value_contents_writeable (v
), bytes
,
4977 TYPE_LENGTH (type
));
4980 v
= value_from_longest (type
, value
);
4982 /* Specify decimal so that we do not depend on
4984 get_formatted_print_options (&opts
, 'd');
4986 value_print (v
, buf
, &opts
);
4992 die
->building_fullname
= 0;
4996 /* Close the argument list, with a space if necessary
4997 (nested templates). */
4998 char last_char
= '\0';
4999 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
5000 if (last_char
== '>')
5001 fputs_unfiltered (" >", buf
);
5003 fputs_unfiltered (">", buf
);
5007 /* For Java and C++ methods, append formal parameter type
5008 information, if PHYSNAME. */
5010 if (physname
&& die
->tag
== DW_TAG_subprogram
5011 && (cu
->language
== language_cplus
5012 || cu
->language
== language_java
))
5014 struct type
*type
= read_type_die (die
, cu
);
5016 c_type_print_args (type
, buf
, 1, cu
->language
);
5018 if (cu
->language
== language_java
)
5020 /* For java, we must append the return type to method
5022 if (die
->tag
== DW_TAG_subprogram
)
5023 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
5026 else if (cu
->language
== language_cplus
)
5028 /* Assume that an artificial first parameter is
5029 "this", but do not crash if it is not. RealView
5030 marks unnamed (and thus unused) parameters as
5031 artificial; there is no way to differentiate
5033 if (TYPE_NFIELDS (type
) > 0
5034 && TYPE_FIELD_ARTIFICIAL (type
, 0)
5035 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
5036 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
,
5038 fputs_unfiltered (" const", buf
);
5042 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
5044 ui_file_delete (buf
);
5046 if (cu
->language
== language_cplus
)
5049 = dwarf2_canonicalize_name (name
, cu
,
5050 &cu
->objfile
->objfile_obstack
);
5061 /* Return the fully qualified name of DIE, based on its DW_AT_name.
5062 If scope qualifiers are appropriate they will be added. The result
5063 will be allocated on the objfile_obstack, or NULL if the DIE does
5064 not have a name. NAME may either be from a previous call to
5065 dwarf2_name or NULL.
5067 The output string will be canonicalized (if C++/Java). */
5070 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5072 return dwarf2_compute_name (name
, die
, cu
, 0);
5075 /* Construct a physname for the given DIE in CU. NAME may either be
5076 from a previous call to dwarf2_name or NULL. The result will be
5077 allocated on the objfile_objstack or NULL if the DIE does not have a
5080 The output string will be canonicalized (if C++/Java). */
5083 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
5085 return dwarf2_compute_name (name
, die
, cu
, 1);
5088 /* Read the import statement specified by the given die and record it. */
5091 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
5093 struct attribute
*import_attr
;
5094 struct die_info
*imported_die
;
5095 struct dwarf2_cu
*imported_cu
;
5096 const char *imported_name
;
5097 const char *imported_name_prefix
;
5098 const char *canonical_name
;
5099 const char *import_alias
;
5100 const char *imported_declaration
= NULL
;
5101 const char *import_prefix
;
5105 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
5106 if (import_attr
== NULL
)
5108 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
5109 dwarf_tag_name (die
->tag
));
5114 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
5115 imported_name
= dwarf2_name (imported_die
, imported_cu
);
5116 if (imported_name
== NULL
)
5118 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
5120 The import in the following code:
5134 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
5135 <52> DW_AT_decl_file : 1
5136 <53> DW_AT_decl_line : 6
5137 <54> DW_AT_import : <0x75>
5138 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
5140 <5b> DW_AT_decl_file : 1
5141 <5c> DW_AT_decl_line : 2
5142 <5d> DW_AT_type : <0x6e>
5144 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
5145 <76> DW_AT_byte_size : 4
5146 <77> DW_AT_encoding : 5 (signed)
5148 imports the wrong die ( 0x75 instead of 0x58 ).
5149 This case will be ignored until the gcc bug is fixed. */
5153 /* Figure out the local name after import. */
5154 import_alias
= dwarf2_name (die
, cu
);
5156 /* Figure out where the statement is being imported to. */
5157 import_prefix
= determine_prefix (die
, cu
);
5159 /* Figure out what the scope of the imported die is and prepend it
5160 to the name of the imported die. */
5161 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
5163 if (imported_die
->tag
!= DW_TAG_namespace
5164 && imported_die
->tag
!= DW_TAG_module
)
5166 imported_declaration
= imported_name
;
5167 canonical_name
= imported_name_prefix
;
5169 else if (strlen (imported_name_prefix
) > 0)
5171 temp
= alloca (strlen (imported_name_prefix
)
5172 + 2 + strlen (imported_name
) + 1);
5173 strcpy (temp
, imported_name_prefix
);
5174 strcat (temp
, "::");
5175 strcat (temp
, imported_name
);
5176 canonical_name
= temp
;
5179 canonical_name
= imported_name
;
5181 cp_add_using_directive (import_prefix
,
5184 imported_declaration
,
5185 &cu
->objfile
->objfile_obstack
);
5189 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5191 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5194 /* Cleanup function for read_file_scope. */
5197 free_cu_line_header (void *arg
)
5199 struct dwarf2_cu
*cu
= arg
;
5201 free_line_header (cu
->line_header
);
5202 cu
->line_header
= NULL
;
5206 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5207 char **name
, char **comp_dir
)
5209 struct attribute
*attr
;
5214 /* Find the filename. Do not use dwarf2_name here, since the filename
5215 is not a source language identifier. */
5216 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5219 *name
= DW_STRING (attr
);
5222 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5224 *comp_dir
= DW_STRING (attr
);
5225 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5227 *comp_dir
= ldirname (*name
);
5228 if (*comp_dir
!= NULL
)
5229 make_cleanup (xfree
, *comp_dir
);
5231 if (*comp_dir
!= NULL
)
5233 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5234 directory, get rid of it. */
5235 char *cp
= strchr (*comp_dir
, ':');
5237 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5242 *name
= "<unknown>";
5245 /* Process DW_TAG_compile_unit. */
5248 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5250 struct objfile
*objfile
= cu
->objfile
;
5251 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5252 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5253 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5254 struct attribute
*attr
;
5256 char *comp_dir
= NULL
;
5257 struct die_info
*child_die
;
5258 bfd
*abfd
= objfile
->obfd
;
5259 struct line_header
*line_header
= 0;
5262 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5264 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5266 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5267 from finish_block. */
5268 if (lowpc
== ((CORE_ADDR
) -1))
5273 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5275 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5278 set_cu_language (DW_UNSND (attr
), cu
);
5281 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5283 cu
->producer
= DW_STRING (attr
);
5285 /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not
5286 standardised yet. As a workaround for the language detection we fall
5287 back to the DW_AT_producer string. */
5288 if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL") != NULL
)
5289 cu
->language
= language_opencl
;
5291 /* We assume that we're processing GCC output. */
5292 processing_gcc_compilation
= 2;
5294 processing_has_namespace_info
= 0;
5296 start_symtab (name
, comp_dir
, lowpc
);
5297 record_debugformat ("DWARF 2");
5298 record_producer (cu
->producer
);
5300 initialize_cu_func_list (cu
);
5302 /* Decode line number information if present. We do this before
5303 processing child DIEs, so that the line header table is available
5304 for DW_AT_decl_file. */
5305 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5308 unsigned int line_offset
= DW_UNSND (attr
);
5309 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5312 cu
->line_header
= line_header
;
5313 make_cleanup (free_cu_line_header
, cu
);
5314 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5318 /* Process all dies in compilation unit. */
5319 if (die
->child
!= NULL
)
5321 child_die
= die
->child
;
5322 while (child_die
&& child_die
->tag
)
5324 process_die (child_die
, cu
);
5325 child_die
= sibling_die (child_die
);
5329 /* Decode macro information, if present. Dwarf 2 macro information
5330 refers to information in the line number info statement program
5331 header, so we can only read it if we've read the header
5333 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5334 if (attr
&& line_header
)
5336 unsigned int macro_offset
= DW_UNSND (attr
);
5338 dwarf_decode_macros (line_header
, macro_offset
,
5339 comp_dir
, abfd
, cu
);
5341 do_cleanups (back_to
);
5344 /* Process DW_TAG_type_unit.
5345 For TUs we want to skip the first top level sibling if it's not the
5346 actual type being defined by this TU. In this case the first top
5347 level sibling is there to provide context only. */
5350 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5352 struct objfile
*objfile
= cu
->objfile
;
5353 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5355 struct attribute
*attr
;
5357 char *comp_dir
= NULL
;
5358 struct die_info
*child_die
;
5359 bfd
*abfd
= objfile
->obfd
;
5361 /* start_symtab needs a low pc, but we don't really have one.
5362 Do what read_file_scope would do in the absence of such info. */
5363 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5365 /* Find the filename. Do not use dwarf2_name here, since the filename
5366 is not a source language identifier. */
5367 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5369 name
= DW_STRING (attr
);
5371 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5373 comp_dir
= DW_STRING (attr
);
5374 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5376 comp_dir
= ldirname (name
);
5377 if (comp_dir
!= NULL
)
5378 make_cleanup (xfree
, comp_dir
);
5384 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5386 set_cu_language (DW_UNSND (attr
), cu
);
5388 /* This isn't technically needed today. It is done for symmetry
5389 with read_file_scope. */
5390 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5392 cu
->producer
= DW_STRING (attr
);
5394 /* We assume that we're processing GCC output. */
5395 processing_gcc_compilation
= 2;
5397 processing_has_namespace_info
= 0;
5399 start_symtab (name
, comp_dir
, lowpc
);
5400 record_debugformat ("DWARF 2");
5401 record_producer (cu
->producer
);
5403 /* Process the dies in the type unit. */
5404 if (die
->child
== NULL
)
5406 dump_die_for_error (die
);
5407 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5408 bfd_get_filename (abfd
));
5411 child_die
= die
->child
;
5413 while (child_die
&& child_die
->tag
)
5415 process_die (child_die
, cu
);
5417 child_die
= sibling_die (child_die
);
5420 do_cleanups (back_to
);
5424 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5425 struct dwarf2_cu
*cu
)
5427 struct function_range
*thisfn
;
5429 thisfn
= (struct function_range
*)
5430 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5431 thisfn
->name
= name
;
5432 thisfn
->lowpc
= lowpc
;
5433 thisfn
->highpc
= highpc
;
5434 thisfn
->seen_line
= 0;
5435 thisfn
->next
= NULL
;
5437 if (cu
->last_fn
== NULL
)
5438 cu
->first_fn
= thisfn
;
5440 cu
->last_fn
->next
= thisfn
;
5442 cu
->last_fn
= thisfn
;
5445 /* qsort helper for inherit_abstract_dies. */
5448 unsigned_int_compar (const void *ap
, const void *bp
)
5450 unsigned int a
= *(unsigned int *) ap
;
5451 unsigned int b
= *(unsigned int *) bp
;
5453 return (a
> b
) - (b
> a
);
5456 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5457 Inherit only the children of the DW_AT_abstract_origin DIE not being
5458 already referenced by DW_AT_abstract_origin from the children of the
5462 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5464 struct die_info
*child_die
;
5465 unsigned die_children_count
;
5466 /* CU offsets which were referenced by children of the current DIE. */
5468 unsigned *offsets_end
, *offsetp
;
5469 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5470 struct die_info
*origin_die
;
5471 /* Iterator of the ORIGIN_DIE children. */
5472 struct die_info
*origin_child_die
;
5473 struct cleanup
*cleanups
;
5474 struct attribute
*attr
;
5475 struct dwarf2_cu
*origin_cu
;
5476 struct pending
**origin_previous_list_in_scope
;
5478 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5482 /* Note that following die references may follow to a die in a
5486 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5488 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5490 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5491 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5493 if (die
->tag
!= origin_die
->tag
5494 && !(die
->tag
== DW_TAG_inlined_subroutine
5495 && origin_die
->tag
== DW_TAG_subprogram
))
5496 complaint (&symfile_complaints
,
5497 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5498 die
->offset
, origin_die
->offset
);
5500 child_die
= die
->child
;
5501 die_children_count
= 0;
5502 while (child_die
&& child_die
->tag
)
5504 child_die
= sibling_die (child_die
);
5505 die_children_count
++;
5507 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5508 cleanups
= make_cleanup (xfree
, offsets
);
5510 offsets_end
= offsets
;
5511 child_die
= die
->child
;
5512 while (child_die
&& child_die
->tag
)
5514 /* For each CHILD_DIE, find the corresponding child of
5515 ORIGIN_DIE. If there is more than one layer of
5516 DW_AT_abstract_origin, follow them all; there shouldn't be,
5517 but GCC versions at least through 4.4 generate this (GCC PR
5519 struct die_info
*child_origin_die
= child_die
;
5520 struct dwarf2_cu
*child_origin_cu
= cu
;
5524 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5528 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5532 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5533 counterpart may exist. */
5534 if (child_origin_die
!= child_die
)
5536 if (child_die
->tag
!= child_origin_die
->tag
5537 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5538 && child_origin_die
->tag
== DW_TAG_subprogram
))
5539 complaint (&symfile_complaints
,
5540 _("Child DIE 0x%x and its abstract origin 0x%x have "
5541 "different tags"), child_die
->offset
,
5542 child_origin_die
->offset
);
5543 if (child_origin_die
->parent
!= origin_die
)
5544 complaint (&symfile_complaints
,
5545 _("Child DIE 0x%x and its abstract origin 0x%x have "
5546 "different parents"), child_die
->offset
,
5547 child_origin_die
->offset
);
5549 *offsets_end
++ = child_origin_die
->offset
;
5551 child_die
= sibling_die (child_die
);
5553 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5554 unsigned_int_compar
);
5555 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5556 if (offsetp
[-1] == *offsetp
)
5557 complaint (&symfile_complaints
,
5558 _("Multiple children of DIE 0x%x refer "
5559 "to DIE 0x%x as their abstract origin"),
5560 die
->offset
, *offsetp
);
5563 origin_child_die
= origin_die
->child
;
5564 while (origin_child_die
&& origin_child_die
->tag
)
5566 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5567 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5569 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5571 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5572 process_die (origin_child_die
, origin_cu
);
5574 origin_child_die
= sibling_die (origin_child_die
);
5576 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5578 do_cleanups (cleanups
);
5582 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5584 struct objfile
*objfile
= cu
->objfile
;
5585 struct context_stack
*new;
5588 struct die_info
*child_die
;
5589 struct attribute
*attr
, *call_line
, *call_file
;
5592 struct block
*block
;
5593 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5594 VEC (symbolp
) *template_args
= NULL
;
5595 struct template_symbol
*templ_func
= NULL
;
5599 /* If we do not have call site information, we can't show the
5600 caller of this inlined function. That's too confusing, so
5601 only use the scope for local variables. */
5602 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5603 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5604 if (call_line
== NULL
|| call_file
== NULL
)
5606 read_lexical_block_scope (die
, cu
);
5611 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5613 name
= dwarf2_name (die
, cu
);
5615 /* Ignore functions with missing or empty names. These are actually
5616 illegal according to the DWARF standard. */
5619 complaint (&symfile_complaints
,
5620 _("missing name for subprogram DIE at %d"), die
->offset
);
5624 /* Ignore functions with missing or invalid low and high pc attributes. */
5625 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5627 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5628 if (!attr
|| !DW_UNSND (attr
))
5629 complaint (&symfile_complaints
,
5630 _("cannot get low and high bounds "
5631 "for subprogram DIE at %d"),
5639 /* Record the function range for dwarf_decode_lines. */
5640 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5642 /* If we have any template arguments, then we must allocate a
5643 different sort of symbol. */
5644 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5646 if (child_die
->tag
== DW_TAG_template_type_param
5647 || child_die
->tag
== DW_TAG_template_value_param
)
5649 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5650 struct template_symbol
);
5651 templ_func
->base
.is_cplus_template_function
= 1;
5656 new = push_context (0, lowpc
);
5657 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5658 (struct symbol
*) templ_func
);
5660 /* If there is a location expression for DW_AT_frame_base, record
5662 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5664 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5665 expression is being recorded directly in the function's symbol
5666 and not in a separate frame-base object. I guess this hack is
5667 to avoid adding some sort of frame-base adjunct/annex to the
5668 function's symbol :-(. The problem with doing this is that it
5669 results in a function symbol with a location expression that
5670 has nothing to do with the location of the function, ouch! The
5671 relationship should be: a function's symbol has-a frame base; a
5672 frame-base has-a location expression. */
5673 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5675 cu
->list_in_scope
= &local_symbols
;
5677 if (die
->child
!= NULL
)
5679 child_die
= die
->child
;
5680 while (child_die
&& child_die
->tag
)
5682 if (child_die
->tag
== DW_TAG_template_type_param
5683 || child_die
->tag
== DW_TAG_template_value_param
)
5685 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5688 VEC_safe_push (symbolp
, template_args
, arg
);
5691 process_die (child_die
, cu
);
5692 child_die
= sibling_die (child_die
);
5696 inherit_abstract_dies (die
, cu
);
5698 /* If we have a DW_AT_specification, we might need to import using
5699 directives from the context of the specification DIE. See the
5700 comment in determine_prefix. */
5701 if (cu
->language
== language_cplus
5702 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5704 struct dwarf2_cu
*spec_cu
= cu
;
5705 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5709 child_die
= spec_die
->child
;
5710 while (child_die
&& child_die
->tag
)
5712 if (child_die
->tag
== DW_TAG_imported_module
)
5713 process_die (child_die
, spec_cu
);
5714 child_die
= sibling_die (child_die
);
5717 /* In some cases, GCC generates specification DIEs that
5718 themselves contain DW_AT_specification attributes. */
5719 spec_die
= die_specification (spec_die
, &spec_cu
);
5723 new = pop_context ();
5724 /* Make a block for the local symbols within. */
5725 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5726 lowpc
, highpc
, objfile
);
5728 /* For C++, set the block's scope. */
5729 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5730 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5731 determine_prefix (die
, cu
),
5732 processing_has_namespace_info
);
5734 /* If we have address ranges, record them. */
5735 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5737 /* Attach template arguments to function. */
5738 if (! VEC_empty (symbolp
, template_args
))
5740 gdb_assert (templ_func
!= NULL
);
5742 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5743 templ_func
->template_arguments
5744 = obstack_alloc (&objfile
->objfile_obstack
,
5745 (templ_func
->n_template_arguments
5746 * sizeof (struct symbol
*)));
5747 memcpy (templ_func
->template_arguments
,
5748 VEC_address (symbolp
, template_args
),
5749 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5750 VEC_free (symbolp
, template_args
);
5753 /* In C++, we can have functions nested inside functions (e.g., when
5754 a function declares a class that has methods). This means that
5755 when we finish processing a function scope, we may need to go
5756 back to building a containing block's symbol lists. */
5757 local_symbols
= new->locals
;
5758 param_symbols
= new->params
;
5759 using_directives
= new->using_directives
;
5761 /* If we've finished processing a top-level function, subsequent
5762 symbols go in the file symbol list. */
5763 if (outermost_context_p ())
5764 cu
->list_in_scope
= &file_symbols
;
5767 /* Process all the DIES contained within a lexical block scope. Start
5768 a new scope, process the dies, and then close the scope. */
5771 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5773 struct objfile
*objfile
= cu
->objfile
;
5774 struct context_stack
*new;
5775 CORE_ADDR lowpc
, highpc
;
5776 struct die_info
*child_die
;
5779 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5781 /* Ignore blocks with missing or invalid low and high pc attributes. */
5782 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5783 as multiple lexical blocks? Handling children in a sane way would
5784 be nasty. Might be easier to properly extend generic blocks to
5786 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5791 push_context (0, lowpc
);
5792 if (die
->child
!= NULL
)
5794 child_die
= die
->child
;
5795 while (child_die
&& child_die
->tag
)
5797 process_die (child_die
, cu
);
5798 child_die
= sibling_die (child_die
);
5801 new = pop_context ();
5803 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5806 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5809 /* Note that recording ranges after traversing children, as we
5810 do here, means that recording a parent's ranges entails
5811 walking across all its children's ranges as they appear in
5812 the address map, which is quadratic behavior.
5814 It would be nicer to record the parent's ranges before
5815 traversing its children, simply overriding whatever you find
5816 there. But since we don't even decide whether to create a
5817 block until after we've traversed its children, that's hard
5819 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5821 local_symbols
= new->locals
;
5822 using_directives
= new->using_directives
;
5825 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5826 Return 1 if the attributes are present and valid, otherwise, return 0.
5827 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5830 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5831 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5832 struct partial_symtab
*ranges_pst
)
5834 struct objfile
*objfile
= cu
->objfile
;
5835 struct comp_unit_head
*cu_header
= &cu
->header
;
5836 bfd
*obfd
= objfile
->obfd
;
5837 unsigned int addr_size
= cu_header
->addr_size
;
5838 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5839 /* Base address selection entry. */
5850 found_base
= cu
->base_known
;
5851 base
= cu
->base_address
;
5853 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5854 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5856 complaint (&symfile_complaints
,
5857 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5861 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5863 /* Read in the largest possible address. */
5864 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5865 if ((marker
& mask
) == mask
)
5867 /* If we found the largest possible address, then
5868 read the base address. */
5869 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5870 buffer
+= 2 * addr_size
;
5871 offset
+= 2 * addr_size
;
5877 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5881 CORE_ADDR range_beginning
, range_end
;
5883 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5884 buffer
+= addr_size
;
5885 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5886 buffer
+= addr_size
;
5887 offset
+= 2 * addr_size
;
5889 /* An end of list marker is a pair of zero addresses. */
5890 if (range_beginning
== 0 && range_end
== 0)
5891 /* Found the end of list entry. */
5894 /* Each base address selection entry is a pair of 2 values.
5895 The first is the largest possible address, the second is
5896 the base address. Check for a base address here. */
5897 if ((range_beginning
& mask
) == mask
)
5899 /* If we found the largest possible address, then
5900 read the base address. */
5901 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5908 /* We have no valid base address for the ranges
5910 complaint (&symfile_complaints
,
5911 _("Invalid .debug_ranges data (no base address)"));
5915 if (range_beginning
> range_end
)
5917 /* Inverted range entries are invalid. */
5918 complaint (&symfile_complaints
,
5919 _("Invalid .debug_ranges data (inverted range)"));
5923 /* Empty range entries have no effect. */
5924 if (range_beginning
== range_end
)
5927 range_beginning
+= base
;
5930 if (ranges_pst
!= NULL
)
5931 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5932 range_beginning
+ baseaddr
,
5933 range_end
- 1 + baseaddr
,
5936 /* FIXME: This is recording everything as a low-high
5937 segment of consecutive addresses. We should have a
5938 data structure for discontiguous block ranges
5942 low
= range_beginning
;
5948 if (range_beginning
< low
)
5949 low
= range_beginning
;
5950 if (range_end
> high
)
5956 /* If the first entry is an end-of-list marker, the range
5957 describes an empty scope, i.e. no instructions. */
5963 *high_return
= high
;
5967 /* Get low and high pc attributes from a die. Return 1 if the attributes
5968 are present and valid, otherwise, return 0. Return -1 if the range is
5969 discontinuous, i.e. derived from DW_AT_ranges information. */
5971 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5972 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5973 struct partial_symtab
*pst
)
5975 struct attribute
*attr
;
5980 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5983 high
= DW_ADDR (attr
);
5984 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5986 low
= DW_ADDR (attr
);
5988 /* Found high w/o low attribute. */
5991 /* Found consecutive range of addresses. */
5996 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5999 /* Value of the DW_AT_ranges attribute is the offset in the
6000 .debug_ranges section. */
6001 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
6003 /* Found discontinuous range of addresses. */
6008 /* read_partial_die has also the strict LOW < HIGH requirement. */
6012 /* When using the GNU linker, .gnu.linkonce. sections are used to
6013 eliminate duplicate copies of functions and vtables and such.
6014 The linker will arbitrarily choose one and discard the others.
6015 The AT_*_pc values for such functions refer to local labels in
6016 these sections. If the section from that file was discarded, the
6017 labels are not in the output, so the relocs get a value of 0.
6018 If this is a discarded function, mark the pc bounds as invalid,
6019 so that GDB will ignore it. */
6020 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
6028 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
6029 its low and high PC addresses. Do nothing if these addresses could not
6030 be determined. Otherwise, set LOWPC to the low address if it is smaller,
6031 and HIGHPC to the high address if greater than HIGHPC. */
6034 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
6035 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6036 struct dwarf2_cu
*cu
)
6038 CORE_ADDR low
, high
;
6039 struct die_info
*child
= die
->child
;
6041 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
6043 *lowpc
= min (*lowpc
, low
);
6044 *highpc
= max (*highpc
, high
);
6047 /* If the language does not allow nested subprograms (either inside
6048 subprograms or lexical blocks), we're done. */
6049 if (cu
->language
!= language_ada
)
6052 /* Check all the children of the given DIE. If it contains nested
6053 subprograms, then check their pc bounds. Likewise, we need to
6054 check lexical blocks as well, as they may also contain subprogram
6056 while (child
&& child
->tag
)
6058 if (child
->tag
== DW_TAG_subprogram
6059 || child
->tag
== DW_TAG_lexical_block
)
6060 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
6061 child
= sibling_die (child
);
6065 /* Get the low and high pc's represented by the scope DIE, and store
6066 them in *LOWPC and *HIGHPC. If the correct values can't be
6067 determined, set *LOWPC to -1 and *HIGHPC to 0. */
6070 get_scope_pc_bounds (struct die_info
*die
,
6071 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
6072 struct dwarf2_cu
*cu
)
6074 CORE_ADDR best_low
= (CORE_ADDR
) -1;
6075 CORE_ADDR best_high
= (CORE_ADDR
) 0;
6076 CORE_ADDR current_low
, current_high
;
6078 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
6080 best_low
= current_low
;
6081 best_high
= current_high
;
6085 struct die_info
*child
= die
->child
;
6087 while (child
&& child
->tag
)
6089 switch (child
->tag
) {
6090 case DW_TAG_subprogram
:
6091 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
6093 case DW_TAG_namespace
:
6095 /* FIXME: carlton/2004-01-16: Should we do this for
6096 DW_TAG_class_type/DW_TAG_structure_type, too? I think
6097 that current GCC's always emit the DIEs corresponding
6098 to definitions of methods of classes as children of a
6099 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
6100 the DIEs giving the declarations, which could be
6101 anywhere). But I don't see any reason why the
6102 standards says that they have to be there. */
6103 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
6105 if (current_low
!= ((CORE_ADDR
) -1))
6107 best_low
= min (best_low
, current_low
);
6108 best_high
= max (best_high
, current_high
);
6116 child
= sibling_die (child
);
6121 *highpc
= best_high
;
6124 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
6127 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
6128 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
6130 struct attribute
*attr
;
6132 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
6135 CORE_ADDR high
= DW_ADDR (attr
);
6137 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6140 CORE_ADDR low
= DW_ADDR (attr
);
6142 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
6146 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
6149 bfd
*obfd
= cu
->objfile
->obfd
;
6151 /* The value of the DW_AT_ranges attribute is the offset of the
6152 address range list in the .debug_ranges section. */
6153 unsigned long offset
= DW_UNSND (attr
);
6154 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
6156 /* For some target architectures, but not others, the
6157 read_address function sign-extends the addresses it returns.
6158 To recognize base address selection entries, we need a
6160 unsigned int addr_size
= cu
->header
.addr_size
;
6161 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
6163 /* The base address, to which the next pair is relative. Note
6164 that this 'base' is a DWARF concept: most entries in a range
6165 list are relative, to reduce the number of relocs against the
6166 debugging information. This is separate from this function's
6167 'baseaddr' argument, which GDB uses to relocate debugging
6168 information from a shared library based on the address at
6169 which the library was loaded. */
6170 CORE_ADDR base
= cu
->base_address
;
6171 int base_known
= cu
->base_known
;
6173 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
6174 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
6176 complaint (&symfile_complaints
,
6177 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
6184 unsigned int bytes_read
;
6185 CORE_ADDR start
, end
;
6187 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6188 buffer
+= bytes_read
;
6189 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
6190 buffer
+= bytes_read
;
6192 /* Did we find the end of the range list? */
6193 if (start
== 0 && end
== 0)
6196 /* Did we find a base address selection entry? */
6197 else if ((start
& base_select_mask
) == base_select_mask
)
6203 /* We found an ordinary address range. */
6208 complaint (&symfile_complaints
,
6209 _("Invalid .debug_ranges data "
6210 "(no base address)"));
6216 /* Inverted range entries are invalid. */
6217 complaint (&symfile_complaints
,
6218 _("Invalid .debug_ranges data "
6219 "(inverted range)"));
6223 /* Empty range entries have no effect. */
6227 record_block_range (block
,
6228 baseaddr
+ base
+ start
,
6229 baseaddr
+ base
+ end
- 1);
6235 /* Check for GCC PR debug/45124 fix which is not present in any G++ version up
6236 to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed
6237 during 4.6.0 experimental. */
6240 producer_is_gxx_lt_4_6 (struct dwarf2_cu
*cu
)
6243 int major
, minor
, release
;
6245 if (cu
->producer
== NULL
)
6247 /* For unknown compilers expect their behavior is DWARF version
6250 GCC started to support .debug_types sections by -gdwarf-4 since
6251 gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer
6252 for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4
6253 combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility
6254 interpreted incorrectly by GDB now - GCC PR debug/48229. */
6259 /* Skip any identifier after "GNU " - such as "C++" or "Java". */
6261 if (strncmp (cu
->producer
, "GNU ", strlen ("GNU ")) != 0)
6263 /* For non-GCC compilers expect their behavior is DWARF version
6268 cs
= &cu
->producer
[strlen ("GNU ")];
6269 while (*cs
&& !isdigit (*cs
))
6271 if (sscanf (cs
, "%d.%d.%d", &major
, &minor
, &release
) != 3)
6273 /* Not recognized as GCC. */
6278 return major
< 4 || (major
== 4 && minor
< 6);
6281 /* Return the default accessibility type if it is not overriden by
6282 DW_AT_accessibility. */
6284 static enum dwarf_access_attribute
6285 dwarf2_default_access_attribute (struct die_info
*die
, struct dwarf2_cu
*cu
)
6287 if (cu
->header
.version
< 3 || producer_is_gxx_lt_4_6 (cu
))
6289 /* The default DWARF 2 accessibility for members is public, the default
6290 accessibility for inheritance is private. */
6292 if (die
->tag
!= DW_TAG_inheritance
)
6293 return DW_ACCESS_public
;
6295 return DW_ACCESS_private
;
6299 /* DWARF 3+ defines the default accessibility a different way. The same
6300 rules apply now for DW_TAG_inheritance as for the members and it only
6301 depends on the container kind. */
6303 if (die
->parent
->tag
== DW_TAG_class_type
)
6304 return DW_ACCESS_private
;
6306 return DW_ACCESS_public
;
6310 /* Add an aggregate field to the field list. */
6313 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6314 struct dwarf2_cu
*cu
)
6316 struct objfile
*objfile
= cu
->objfile
;
6317 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6318 struct nextfield
*new_field
;
6319 struct attribute
*attr
;
6321 char *fieldname
= "";
6323 /* Allocate a new field list entry and link it in. */
6324 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6325 make_cleanup (xfree
, new_field
);
6326 memset (new_field
, 0, sizeof (struct nextfield
));
6328 if (die
->tag
== DW_TAG_inheritance
)
6330 new_field
->next
= fip
->baseclasses
;
6331 fip
->baseclasses
= new_field
;
6335 new_field
->next
= fip
->fields
;
6336 fip
->fields
= new_field
;
6340 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6342 new_field
->accessibility
= DW_UNSND (attr
);
6344 new_field
->accessibility
= dwarf2_default_access_attribute (die
, cu
);
6345 if (new_field
->accessibility
!= DW_ACCESS_public
)
6346 fip
->non_public_fields
= 1;
6348 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6350 new_field
->virtuality
= DW_UNSND (attr
);
6352 new_field
->virtuality
= DW_VIRTUALITY_none
;
6354 fp
= &new_field
->field
;
6356 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6358 /* Data member other than a C++ static data member. */
6360 /* Get type of field. */
6361 fp
->type
= die_type (die
, cu
);
6363 SET_FIELD_BITPOS (*fp
, 0);
6365 /* Get bit size of field (zero if none). */
6366 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6369 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6373 FIELD_BITSIZE (*fp
) = 0;
6376 /* Get bit offset of field. */
6377 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6380 int byte_offset
= 0;
6382 if (attr_form_is_section_offset (attr
))
6383 dwarf2_complex_location_expr_complaint ();
6384 else if (attr_form_is_constant (attr
))
6385 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6386 else if (attr_form_is_block (attr
))
6387 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6389 dwarf2_complex_location_expr_complaint ();
6391 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6393 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6396 if (gdbarch_bits_big_endian (gdbarch
))
6398 /* For big endian bits, the DW_AT_bit_offset gives the
6399 additional bit offset from the MSB of the containing
6400 anonymous object to the MSB of the field. We don't
6401 have to do anything special since we don't need to
6402 know the size of the anonymous object. */
6403 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6407 /* For little endian bits, compute the bit offset to the
6408 MSB of the anonymous object, subtract off the number of
6409 bits from the MSB of the field to the MSB of the
6410 object, and then subtract off the number of bits of
6411 the field itself. The result is the bit offset of
6412 the LSB of the field. */
6414 int bit_offset
= DW_UNSND (attr
);
6416 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6419 /* The size of the anonymous object containing
6420 the bit field is explicit, so use the
6421 indicated size (in bytes). */
6422 anonymous_size
= DW_UNSND (attr
);
6426 /* The size of the anonymous object containing
6427 the bit field must be inferred from the type
6428 attribute of the data member containing the
6430 anonymous_size
= TYPE_LENGTH (fp
->type
);
6432 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6433 - bit_offset
- FIELD_BITSIZE (*fp
);
6437 /* Get name of field. */
6438 fieldname
= dwarf2_name (die
, cu
);
6439 if (fieldname
== NULL
)
6442 /* The name is already allocated along with this objfile, so we don't
6443 need to duplicate it for the type. */
6444 fp
->name
= fieldname
;
6446 /* Change accessibility for artificial fields (e.g. virtual table
6447 pointer or virtual base class pointer) to private. */
6448 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6450 FIELD_ARTIFICIAL (*fp
) = 1;
6451 new_field
->accessibility
= DW_ACCESS_private
;
6452 fip
->non_public_fields
= 1;
6455 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6457 /* C++ static member. */
6459 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6460 is a declaration, but all versions of G++ as of this writing
6461 (so through at least 3.2.1) incorrectly generate
6462 DW_TAG_variable tags. */
6466 /* Get name of field. */
6467 fieldname
= dwarf2_name (die
, cu
);
6468 if (fieldname
== NULL
)
6471 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6473 /* Only create a symbol if this is an external value.
6474 new_symbol checks this and puts the value in the global symbol
6475 table, which we want. If it is not external, new_symbol
6476 will try to put the value in cu->list_in_scope which is wrong. */
6477 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6479 /* A static const member, not much different than an enum as far as
6480 we're concerned, except that we can support more types. */
6481 new_symbol (die
, NULL
, cu
);
6484 /* Get physical name. */
6485 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6487 /* The name is already allocated along with this objfile, so we don't
6488 need to duplicate it for the type. */
6489 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6490 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6491 FIELD_NAME (*fp
) = fieldname
;
6493 else if (die
->tag
== DW_TAG_inheritance
)
6495 /* C++ base class field. */
6496 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6499 int byte_offset
= 0;
6501 if (attr_form_is_section_offset (attr
))
6502 dwarf2_complex_location_expr_complaint ();
6503 else if (attr_form_is_constant (attr
))
6504 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6505 else if (attr_form_is_block (attr
))
6506 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6508 dwarf2_complex_location_expr_complaint ();
6510 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6512 FIELD_BITSIZE (*fp
) = 0;
6513 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6514 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6515 fip
->nbaseclasses
++;
6519 /* Add a typedef defined in the scope of the FIP's class. */
6522 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6523 struct dwarf2_cu
*cu
)
6525 struct objfile
*objfile
= cu
->objfile
;
6526 struct typedef_field_list
*new_field
;
6527 struct attribute
*attr
;
6528 struct typedef_field
*fp
;
6529 char *fieldname
= "";
6531 /* Allocate a new field list entry and link it in. */
6532 new_field
= xzalloc (sizeof (*new_field
));
6533 make_cleanup (xfree
, new_field
);
6535 gdb_assert (die
->tag
== DW_TAG_typedef
);
6537 fp
= &new_field
->field
;
6539 /* Get name of field. */
6540 fp
->name
= dwarf2_name (die
, cu
);
6541 if (fp
->name
== NULL
)
6544 fp
->type
= read_type_die (die
, cu
);
6546 new_field
->next
= fip
->typedef_field_list
;
6547 fip
->typedef_field_list
= new_field
;
6548 fip
->typedef_field_list_count
++;
6551 /* Create the vector of fields, and attach it to the type. */
6554 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6555 struct dwarf2_cu
*cu
)
6557 int nfields
= fip
->nfields
;
6559 /* Record the field count, allocate space for the array of fields,
6560 and create blank accessibility bitfields if necessary. */
6561 TYPE_NFIELDS (type
) = nfields
;
6562 TYPE_FIELDS (type
) = (struct field
*)
6563 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6564 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6566 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6568 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6570 TYPE_FIELD_PRIVATE_BITS (type
) =
6571 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6572 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6574 TYPE_FIELD_PROTECTED_BITS (type
) =
6575 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6576 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6578 TYPE_FIELD_IGNORE_BITS (type
) =
6579 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6580 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6583 /* If the type has baseclasses, allocate and clear a bit vector for
6584 TYPE_FIELD_VIRTUAL_BITS. */
6585 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6587 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6588 unsigned char *pointer
;
6590 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6591 pointer
= TYPE_ALLOC (type
, num_bytes
);
6592 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6593 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6594 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6597 /* Copy the saved-up fields into the field vector. Start from the head of
6598 the list, adding to the tail of the field array, so that they end up in
6599 the same order in the array in which they were added to the list. */
6600 while (nfields
-- > 0)
6602 struct nextfield
*fieldp
;
6606 fieldp
= fip
->fields
;
6607 fip
->fields
= fieldp
->next
;
6611 fieldp
= fip
->baseclasses
;
6612 fip
->baseclasses
= fieldp
->next
;
6615 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6616 switch (fieldp
->accessibility
)
6618 case DW_ACCESS_private
:
6619 if (cu
->language
!= language_ada
)
6620 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6623 case DW_ACCESS_protected
:
6624 if (cu
->language
!= language_ada
)
6625 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6628 case DW_ACCESS_public
:
6632 /* Unknown accessibility. Complain and treat it as public. */
6634 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6635 fieldp
->accessibility
);
6639 if (nfields
< fip
->nbaseclasses
)
6641 switch (fieldp
->virtuality
)
6643 case DW_VIRTUALITY_virtual
:
6644 case DW_VIRTUALITY_pure_virtual
:
6645 if (cu
->language
== language_ada
)
6646 error (_("unexpected virtuality in component of Ada type"));
6647 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6654 /* Add a member function to the proper fieldlist. */
6657 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6658 struct type
*type
, struct dwarf2_cu
*cu
)
6660 struct objfile
*objfile
= cu
->objfile
;
6661 struct attribute
*attr
;
6662 struct fnfieldlist
*flp
;
6664 struct fn_field
*fnp
;
6666 struct nextfnfield
*new_fnfield
;
6667 struct type
*this_type
;
6668 enum dwarf_access_attribute accessibility
;
6670 if (cu
->language
== language_ada
)
6671 error (_("unexpected member function in Ada type"));
6673 /* Get name of member function. */
6674 fieldname
= dwarf2_name (die
, cu
);
6675 if (fieldname
== NULL
)
6678 /* Look up member function name in fieldlist. */
6679 for (i
= 0; i
< fip
->nfnfields
; i
++)
6681 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6685 /* Create new list element if necessary. */
6686 if (i
< fip
->nfnfields
)
6687 flp
= &fip
->fnfieldlists
[i
];
6690 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6692 fip
->fnfieldlists
= (struct fnfieldlist
*)
6693 xrealloc (fip
->fnfieldlists
,
6694 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6695 * sizeof (struct fnfieldlist
));
6696 if (fip
->nfnfields
== 0)
6697 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6699 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6700 flp
->name
= fieldname
;
6703 i
= fip
->nfnfields
++;
6706 /* Create a new member function field and chain it to the field list
6708 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6709 make_cleanup (xfree
, new_fnfield
);
6710 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6711 new_fnfield
->next
= flp
->head
;
6712 flp
->head
= new_fnfield
;
6715 /* Fill in the member function field info. */
6716 fnp
= &new_fnfield
->fnfield
;
6718 /* Delay processing of the physname until later. */
6719 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6721 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6726 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6727 fnp
->physname
= physname
? physname
: "";
6730 fnp
->type
= alloc_type (objfile
);
6731 this_type
= read_type_die (die
, cu
);
6732 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6734 int nparams
= TYPE_NFIELDS (this_type
);
6736 /* TYPE is the domain of this method, and THIS_TYPE is the type
6737 of the method itself (TYPE_CODE_METHOD). */
6738 smash_to_method_type (fnp
->type
, type
,
6739 TYPE_TARGET_TYPE (this_type
),
6740 TYPE_FIELDS (this_type
),
6741 TYPE_NFIELDS (this_type
),
6742 TYPE_VARARGS (this_type
));
6744 /* Handle static member functions.
6745 Dwarf2 has no clean way to discern C++ static and non-static
6746 member functions. G++ helps GDB by marking the first
6747 parameter for non-static member functions (which is the this
6748 pointer) as artificial. We obtain this information from
6749 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6750 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6751 fnp
->voffset
= VOFFSET_STATIC
;
6754 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6755 dwarf2_full_name (fieldname
, die
, cu
));
6757 /* Get fcontext from DW_AT_containing_type if present. */
6758 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6759 fnp
->fcontext
= die_containing_type (die
, cu
);
6761 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and
6762 is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6764 /* Get accessibility. */
6765 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6767 accessibility
= DW_UNSND (attr
);
6769 accessibility
= dwarf2_default_access_attribute (die
, cu
);
6770 switch (accessibility
)
6772 case DW_ACCESS_private
:
6773 fnp
->is_private
= 1;
6775 case DW_ACCESS_protected
:
6776 fnp
->is_protected
= 1;
6780 /* Check for artificial methods. */
6781 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6782 if (attr
&& DW_UNSND (attr
) != 0)
6783 fnp
->is_artificial
= 1;
6785 /* Get index in virtual function table if it is a virtual member
6786 function. For older versions of GCC, this is an offset in the
6787 appropriate virtual table, as specified by DW_AT_containing_type.
6788 For everyone else, it is an expression to be evaluated relative
6789 to the object address. */
6791 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6794 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6796 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6798 /* Old-style GCC. */
6799 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6801 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6802 || (DW_BLOCK (attr
)->size
> 1
6803 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6804 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6806 struct dwarf_block blk
;
6809 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6811 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6812 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6813 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6814 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6815 dwarf2_complex_location_expr_complaint ();
6817 fnp
->voffset
/= cu
->header
.addr_size
;
6821 dwarf2_complex_location_expr_complaint ();
6824 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6826 else if (attr_form_is_section_offset (attr
))
6828 dwarf2_complex_location_expr_complaint ();
6832 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6838 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6839 if (attr
&& DW_UNSND (attr
))
6841 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6842 complaint (&symfile_complaints
,
6843 _("Member function \"%s\" (offset %d) is virtual "
6844 "but the vtable offset is not specified"),
6845 fieldname
, die
->offset
);
6846 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6847 TYPE_CPLUS_DYNAMIC (type
) = 1;
6852 /* Create the vector of member function fields, and attach it to the type. */
6855 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6856 struct dwarf2_cu
*cu
)
6858 struct fnfieldlist
*flp
;
6859 int total_length
= 0;
6862 if (cu
->language
== language_ada
)
6863 error (_("unexpected member functions in Ada type"));
6865 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6866 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6867 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6869 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6871 struct nextfnfield
*nfp
= flp
->head
;
6872 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6875 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6876 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6877 fn_flp
->fn_fields
= (struct fn_field
*)
6878 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6879 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6880 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6882 total_length
+= flp
->length
;
6885 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6886 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6889 /* Returns non-zero if NAME is the name of a vtable member in CU's
6890 language, zero otherwise. */
6892 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6894 static const char vptr
[] = "_vptr";
6895 static const char vtable
[] = "vtable";
6897 /* Look for the C++ and Java forms of the vtable. */
6898 if ((cu
->language
== language_java
6899 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6900 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6901 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6907 /* GCC outputs unnamed structures that are really pointers to member
6908 functions, with the ABI-specified layout. If TYPE describes
6909 such a structure, smash it into a member function type.
6911 GCC shouldn't do this; it should just output pointer to member DIEs.
6912 This is GCC PR debug/28767. */
6915 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6917 struct type
*pfn_type
, *domain_type
, *new_type
;
6919 /* Check for a structure with no name and two children. */
6920 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6923 /* Check for __pfn and __delta members. */
6924 if (TYPE_FIELD_NAME (type
, 0) == NULL
6925 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6926 || TYPE_FIELD_NAME (type
, 1) == NULL
6927 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6930 /* Find the type of the method. */
6931 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6932 if (pfn_type
== NULL
6933 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6934 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6937 /* Look for the "this" argument. */
6938 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6939 if (TYPE_NFIELDS (pfn_type
) == 0
6940 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6941 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6944 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6945 new_type
= alloc_type (objfile
);
6946 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6947 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6948 TYPE_VARARGS (pfn_type
));
6949 smash_to_methodptr_type (type
, new_type
);
6952 /* Called when we find the DIE that starts a structure or union scope
6953 (definition) to create a type for the structure or union. Fill in
6954 the type's name and general properties; the members will not be
6955 processed until process_structure_type.
6957 NOTE: we need to call these functions regardless of whether or not the
6958 DIE has a DW_AT_name attribute, since it might be an anonymous
6959 structure or union. This gets the type entered into our set of
6962 However, if the structure is incomplete (an opaque struct/union)
6963 then suppress creating a symbol table entry for it since gdb only
6964 wants to find the one with the complete definition. Note that if
6965 it is complete, we just call new_symbol, which does it's own
6966 checking about whether the struct/union is anonymous or not (and
6967 suppresses creating a symbol table entry itself). */
6969 static struct type
*
6970 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6972 struct objfile
*objfile
= cu
->objfile
;
6974 struct attribute
*attr
;
6977 /* If the definition of this type lives in .debug_types, read that type.
6978 Don't follow DW_AT_specification though, that will take us back up
6979 the chain and we want to go down. */
6980 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6983 struct dwarf2_cu
*type_cu
= cu
;
6984 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6986 /* We could just recurse on read_structure_type, but we need to call
6987 get_die_type to ensure only one type for this DIE is created.
6988 This is important, for example, because for c++ classes we need
6989 TYPE_NAME set which is only done by new_symbol. Blech. */
6990 type
= read_type_die (type_die
, type_cu
);
6992 /* TYPE_CU may not be the same as CU.
6993 Ensure TYPE is recorded in CU's type_hash table. */
6994 return set_die_type (die
, type
, cu
);
6997 type
= alloc_type (objfile
);
6998 INIT_CPLUS_SPECIFIC (type
);
7000 name
= dwarf2_name (die
, cu
);
7003 if (cu
->language
== language_cplus
7004 || cu
->language
== language_java
)
7006 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
7008 /* dwarf2_full_name might have already finished building the DIE's
7009 type. If so, there is no need to continue. */
7010 if (get_die_type (die
, cu
) != NULL
)
7011 return get_die_type (die
, cu
);
7013 TYPE_TAG_NAME (type
) = full_name
;
7014 if (die
->tag
== DW_TAG_structure_type
7015 || die
->tag
== DW_TAG_class_type
)
7016 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7020 /* The name is already allocated along with this objfile, so
7021 we don't need to duplicate it for the type. */
7022 TYPE_TAG_NAME (type
) = (char *) name
;
7023 if (die
->tag
== DW_TAG_class_type
)
7024 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
7028 if (die
->tag
== DW_TAG_structure_type
)
7030 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
7032 else if (die
->tag
== DW_TAG_union_type
)
7034 TYPE_CODE (type
) = TYPE_CODE_UNION
;
7038 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
7041 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
7042 TYPE_DECLARED_CLASS (type
) = 1;
7044 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7047 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7051 TYPE_LENGTH (type
) = 0;
7054 TYPE_STUB_SUPPORTED (type
) = 1;
7055 if (die_is_declaration (die
, cu
))
7056 TYPE_STUB (type
) = 1;
7057 else if (attr
== NULL
&& die
->child
== NULL
7058 && producer_is_realview (cu
->producer
))
7059 /* RealView does not output the required DW_AT_declaration
7060 on incomplete types. */
7061 TYPE_STUB (type
) = 1;
7063 /* We need to add the type field to the die immediately so we don't
7064 infinitely recurse when dealing with pointers to the structure
7065 type within the structure itself. */
7066 set_die_type (die
, type
, cu
);
7068 /* set_die_type should be already done. */
7069 set_descriptive_type (type
, die
, cu
);
7074 /* Finish creating a structure or union type, including filling in
7075 its members and creating a symbol for it. */
7078 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7080 struct objfile
*objfile
= cu
->objfile
;
7081 struct die_info
*child_die
= die
->child
;
7084 type
= get_die_type (die
, cu
);
7086 type
= read_structure_type (die
, cu
);
7088 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
7090 struct field_info fi
;
7091 struct die_info
*child_die
;
7092 VEC (symbolp
) *template_args
= NULL
;
7093 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
7095 memset (&fi
, 0, sizeof (struct field_info
));
7097 child_die
= die
->child
;
7099 while (child_die
&& child_die
->tag
)
7101 if (child_die
->tag
== DW_TAG_member
7102 || child_die
->tag
== DW_TAG_variable
)
7104 /* NOTE: carlton/2002-11-05: A C++ static data member
7105 should be a DW_TAG_member that is a declaration, but
7106 all versions of G++ as of this writing (so through at
7107 least 3.2.1) incorrectly generate DW_TAG_variable
7108 tags for them instead. */
7109 dwarf2_add_field (&fi
, child_die
, cu
);
7111 else if (child_die
->tag
== DW_TAG_subprogram
)
7113 /* C++ member function. */
7114 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
7116 else if (child_die
->tag
== DW_TAG_inheritance
)
7118 /* C++ base class field. */
7119 dwarf2_add_field (&fi
, child_die
, cu
);
7121 else if (child_die
->tag
== DW_TAG_typedef
)
7122 dwarf2_add_typedef (&fi
, child_die
, cu
);
7123 else if (child_die
->tag
== DW_TAG_template_type_param
7124 || child_die
->tag
== DW_TAG_template_value_param
)
7126 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
7129 VEC_safe_push (symbolp
, template_args
, arg
);
7132 child_die
= sibling_die (child_die
);
7135 /* Attach template arguments to type. */
7136 if (! VEC_empty (symbolp
, template_args
))
7138 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7139 TYPE_N_TEMPLATE_ARGUMENTS (type
)
7140 = VEC_length (symbolp
, template_args
);
7141 TYPE_TEMPLATE_ARGUMENTS (type
)
7142 = obstack_alloc (&objfile
->objfile_obstack
,
7143 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7144 * sizeof (struct symbol
*)));
7145 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
7146 VEC_address (symbolp
, template_args
),
7147 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
7148 * sizeof (struct symbol
*)));
7149 VEC_free (symbolp
, template_args
);
7152 /* Attach fields and member functions to the type. */
7154 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
7157 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
7159 /* Get the type which refers to the base class (possibly this
7160 class itself) which contains the vtable pointer for the current
7161 class from the DW_AT_containing_type attribute. This use of
7162 DW_AT_containing_type is a GNU extension. */
7164 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
7166 struct type
*t
= die_containing_type (die
, cu
);
7168 TYPE_VPTR_BASETYPE (type
) = t
;
7173 /* Our own class provides vtbl ptr. */
7174 for (i
= TYPE_NFIELDS (t
) - 1;
7175 i
>= TYPE_N_BASECLASSES (t
);
7178 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
7180 if (is_vtable_name (fieldname
, cu
))
7182 TYPE_VPTR_FIELDNO (type
) = i
;
7187 /* Complain if virtual function table field not found. */
7188 if (i
< TYPE_N_BASECLASSES (t
))
7189 complaint (&symfile_complaints
,
7190 _("virtual function table pointer "
7191 "not found when defining class '%s'"),
7192 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
7197 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
7200 else if (cu
->producer
7201 && strncmp (cu
->producer
,
7202 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
7204 /* The IBM XLC compiler does not provide direct indication
7205 of the containing type, but the vtable pointer is
7206 always named __vfp. */
7210 for (i
= TYPE_NFIELDS (type
) - 1;
7211 i
>= TYPE_N_BASECLASSES (type
);
7214 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
7216 TYPE_VPTR_FIELDNO (type
) = i
;
7217 TYPE_VPTR_BASETYPE (type
) = type
;
7224 /* Copy fi.typedef_field_list linked list elements content into the
7225 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
7226 if (fi
.typedef_field_list
)
7228 int i
= fi
.typedef_field_list_count
;
7230 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
7231 TYPE_TYPEDEF_FIELD_ARRAY (type
)
7232 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
7233 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
7235 /* Reverse the list order to keep the debug info elements order. */
7238 struct typedef_field
*dest
, *src
;
7240 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
7241 src
= &fi
.typedef_field_list
->field
;
7242 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
7247 do_cleanups (back_to
);
7250 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
7252 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
7253 snapshots) has been known to create a die giving a declaration
7254 for a class that has, as a child, a die giving a definition for a
7255 nested class. So we have to process our children even if the
7256 current die is a declaration. Normally, of course, a declaration
7257 won't have any children at all. */
7259 while (child_die
!= NULL
&& child_die
->tag
)
7261 if (child_die
->tag
== DW_TAG_member
7262 || child_die
->tag
== DW_TAG_variable
7263 || child_die
->tag
== DW_TAG_inheritance
7264 || child_die
->tag
== DW_TAG_template_value_param
7265 || child_die
->tag
== DW_TAG_template_type_param
)
7270 process_die (child_die
, cu
);
7272 child_die
= sibling_die (child_die
);
7275 /* Do not consider external references. According to the DWARF standard,
7276 these DIEs are identified by the fact that they have no byte_size
7277 attribute, and a declaration attribute. */
7278 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
7279 || !die_is_declaration (die
, cu
))
7280 new_symbol (die
, type
, cu
);
7283 /* Given a DW_AT_enumeration_type die, set its type. We do not
7284 complete the type's fields yet, or create any symbols. */
7286 static struct type
*
7287 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7289 struct objfile
*objfile
= cu
->objfile
;
7291 struct attribute
*attr
;
7294 /* If the definition of this type lives in .debug_types, read that type.
7295 Don't follow DW_AT_specification though, that will take us back up
7296 the chain and we want to go down. */
7297 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7300 struct dwarf2_cu
*type_cu
= cu
;
7301 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7303 type
= read_type_die (type_die
, type_cu
);
7305 /* TYPE_CU may not be the same as CU.
7306 Ensure TYPE is recorded in CU's type_hash table. */
7307 return set_die_type (die
, type
, cu
);
7310 type
= alloc_type (objfile
);
7312 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7313 name
= dwarf2_full_name (NULL
, die
, cu
);
7315 TYPE_TAG_NAME (type
) = (char *) name
;
7317 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7320 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7324 TYPE_LENGTH (type
) = 0;
7327 /* The enumeration DIE can be incomplete. In Ada, any type can be
7328 declared as private in the package spec, and then defined only
7329 inside the package body. Such types are known as Taft Amendment
7330 Types. When another package uses such a type, an incomplete DIE
7331 may be generated by the compiler. */
7332 if (die_is_declaration (die
, cu
))
7333 TYPE_STUB (type
) = 1;
7335 return set_die_type (die
, type
, cu
);
7338 /* Given a pointer to a die which begins an enumeration, process all
7339 the dies that define the members of the enumeration, and create the
7340 symbol for the enumeration type.
7342 NOTE: We reverse the order of the element list. */
7345 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7347 struct type
*this_type
;
7349 this_type
= get_die_type (die
, cu
);
7350 if (this_type
== NULL
)
7351 this_type
= read_enumeration_type (die
, cu
);
7353 if (die
->child
!= NULL
)
7355 struct die_info
*child_die
;
7357 struct field
*fields
= NULL
;
7359 int unsigned_enum
= 1;
7362 child_die
= die
->child
;
7363 while (child_die
&& child_die
->tag
)
7365 if (child_die
->tag
!= DW_TAG_enumerator
)
7367 process_die (child_die
, cu
);
7371 name
= dwarf2_name (child_die
, cu
);
7374 sym
= new_symbol (child_die
, this_type
, cu
);
7375 if (SYMBOL_VALUE (sym
) < 0)
7378 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7380 fields
= (struct field
*)
7382 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7383 * sizeof (struct field
));
7386 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7387 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7388 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7389 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7395 child_die
= sibling_die (child_die
);
7400 TYPE_NFIELDS (this_type
) = num_fields
;
7401 TYPE_FIELDS (this_type
) = (struct field
*)
7402 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7403 memcpy (TYPE_FIELDS (this_type
), fields
,
7404 sizeof (struct field
) * num_fields
);
7408 TYPE_UNSIGNED (this_type
) = 1;
7411 new_symbol (die
, this_type
, cu
);
7414 /* Extract all information from a DW_TAG_array_type DIE and put it in
7415 the DIE's type field. For now, this only handles one dimensional
7418 static struct type
*
7419 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7421 struct objfile
*objfile
= cu
->objfile
;
7422 struct die_info
*child_die
;
7424 struct type
*element_type
, *range_type
, *index_type
;
7425 struct type
**range_types
= NULL
;
7426 struct attribute
*attr
;
7428 struct cleanup
*back_to
;
7431 element_type
= die_type (die
, cu
);
7433 /* The die_type call above may have already set the type for this DIE. */
7434 type
= get_die_type (die
, cu
);
7438 /* Irix 6.2 native cc creates array types without children for
7439 arrays with unspecified length. */
7440 if (die
->child
== NULL
)
7442 index_type
= objfile_type (objfile
)->builtin_int
;
7443 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7444 type
= create_array_type (NULL
, element_type
, range_type
);
7445 return set_die_type (die
, type
, cu
);
7448 back_to
= make_cleanup (null_cleanup
, NULL
);
7449 child_die
= die
->child
;
7450 while (child_die
&& child_die
->tag
)
7452 if (child_die
->tag
== DW_TAG_subrange_type
)
7454 struct type
*child_type
= read_type_die (child_die
, cu
);
7456 if (child_type
!= NULL
)
7458 /* The range type was succesfully read. Save it for the
7459 array type creation. */
7460 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7462 range_types
= (struct type
**)
7463 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7464 * sizeof (struct type
*));
7466 make_cleanup (free_current_contents
, &range_types
);
7468 range_types
[ndim
++] = child_type
;
7471 child_die
= sibling_die (child_die
);
7474 /* Dwarf2 dimensions are output from left to right, create the
7475 necessary array types in backwards order. */
7477 type
= element_type
;
7479 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7484 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7489 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7492 /* Understand Dwarf2 support for vector types (like they occur on
7493 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7494 array type. This is not part of the Dwarf2/3 standard yet, but a
7495 custom vendor extension. The main difference between a regular
7496 array and the vector variant is that vectors are passed by value
7498 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7500 make_vector_type (type
);
7502 /* The DIE may have DW_AT_byte_size set. For example an OpenCL
7503 implementation may choose to implement triple vectors using this
7505 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7508 if (DW_UNSND (attr
) >= TYPE_LENGTH (type
))
7509 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7511 complaint (&symfile_complaints
,
7512 _("DW_AT_byte_size for array type smaller "
7513 "than the total size of elements"));
7516 name
= dwarf2_name (die
, cu
);
7518 TYPE_NAME (type
) = name
;
7520 /* Install the type in the die. */
7521 set_die_type (die
, type
, cu
);
7523 /* set_die_type should be already done. */
7524 set_descriptive_type (type
, die
, cu
);
7526 do_cleanups (back_to
);
7531 static enum dwarf_array_dim_ordering
7532 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7534 struct attribute
*attr
;
7536 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7538 if (attr
) return DW_SND (attr
);
7540 /* GNU F77 is a special case, as at 08/2004 array type info is the
7541 opposite order to the dwarf2 specification, but data is still
7542 laid out as per normal fortran.
7544 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7545 version checking. */
7547 if (cu
->language
== language_fortran
7548 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7550 return DW_ORD_row_major
;
7553 switch (cu
->language_defn
->la_array_ordering
)
7555 case array_column_major
:
7556 return DW_ORD_col_major
;
7557 case array_row_major
:
7559 return DW_ORD_row_major
;
7563 /* Extract all information from a DW_TAG_set_type DIE and put it in
7564 the DIE's type field. */
7566 static struct type
*
7567 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7569 struct type
*domain_type
, *set_type
;
7570 struct attribute
*attr
;
7572 domain_type
= die_type (die
, cu
);
7574 /* The die_type call above may have already set the type for this DIE. */
7575 set_type
= get_die_type (die
, cu
);
7579 set_type
= create_set_type (NULL
, domain_type
);
7581 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7583 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7585 return set_die_type (die
, set_type
, cu
);
7588 /* First cut: install each common block member as a global variable. */
7591 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7593 struct die_info
*child_die
;
7594 struct attribute
*attr
;
7596 CORE_ADDR base
= (CORE_ADDR
) 0;
7598 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7601 /* Support the .debug_loc offsets. */
7602 if (attr_form_is_block (attr
))
7604 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7606 else if (attr_form_is_section_offset (attr
))
7608 dwarf2_complex_location_expr_complaint ();
7612 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7613 "common block member");
7616 if (die
->child
!= NULL
)
7618 child_die
= die
->child
;
7619 while (child_die
&& child_die
->tag
)
7621 sym
= new_symbol (child_die
, NULL
, cu
);
7622 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7623 if (sym
!= NULL
&& attr
!= NULL
)
7625 CORE_ADDR byte_offset
= 0;
7627 if (attr_form_is_section_offset (attr
))
7628 dwarf2_complex_location_expr_complaint ();
7629 else if (attr_form_is_constant (attr
))
7630 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7631 else if (attr_form_is_block (attr
))
7632 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7634 dwarf2_complex_location_expr_complaint ();
7636 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7637 add_symbol_to_list (sym
, &global_symbols
);
7639 child_die
= sibling_die (child_die
);
7644 /* Create a type for a C++ namespace. */
7646 static struct type
*
7647 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7649 struct objfile
*objfile
= cu
->objfile
;
7650 const char *previous_prefix
, *name
;
7654 /* For extensions, reuse the type of the original namespace. */
7655 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7657 struct die_info
*ext_die
;
7658 struct dwarf2_cu
*ext_cu
= cu
;
7660 ext_die
= dwarf2_extension (die
, &ext_cu
);
7661 type
= read_type_die (ext_die
, ext_cu
);
7663 /* EXT_CU may not be the same as CU.
7664 Ensure TYPE is recorded in CU's type_hash table. */
7665 return set_die_type (die
, type
, cu
);
7668 name
= namespace_name (die
, &is_anonymous
, cu
);
7670 /* Now build the name of the current namespace. */
7672 previous_prefix
= determine_prefix (die
, cu
);
7673 if (previous_prefix
[0] != '\0')
7674 name
= typename_concat (&objfile
->objfile_obstack
,
7675 previous_prefix
, name
, 0, cu
);
7677 /* Create the type. */
7678 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7680 TYPE_NAME (type
) = (char *) name
;
7681 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7683 return set_die_type (die
, type
, cu
);
7686 /* Read a C++ namespace. */
7689 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7691 struct objfile
*objfile
= cu
->objfile
;
7694 /* Add a symbol associated to this if we haven't seen the namespace
7695 before. Also, add a using directive if it's an anonymous
7698 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7702 type
= read_type_die (die
, cu
);
7703 new_symbol (die
, type
, cu
);
7705 namespace_name (die
, &is_anonymous
, cu
);
7708 const char *previous_prefix
= determine_prefix (die
, cu
);
7710 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7711 NULL
, &objfile
->objfile_obstack
);
7715 if (die
->child
!= NULL
)
7717 struct die_info
*child_die
= die
->child
;
7719 while (child_die
&& child_die
->tag
)
7721 process_die (child_die
, cu
);
7722 child_die
= sibling_die (child_die
);
7727 /* Read a Fortran module as type. This DIE can be only a declaration used for
7728 imported module. Still we need that type as local Fortran "use ... only"
7729 declaration imports depend on the created type in determine_prefix. */
7731 static struct type
*
7732 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7734 struct objfile
*objfile
= cu
->objfile
;
7738 module_name
= dwarf2_name (die
, cu
);
7740 complaint (&symfile_complaints
,
7741 _("DW_TAG_module has no name, offset 0x%x"),
7743 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7745 /* determine_prefix uses TYPE_TAG_NAME. */
7746 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7748 return set_die_type (die
, type
, cu
);
7751 /* Read a Fortran module. */
7754 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7756 struct die_info
*child_die
= die
->child
;
7758 while (child_die
&& child_die
->tag
)
7760 process_die (child_die
, cu
);
7761 child_die
= sibling_die (child_die
);
7765 /* Return the name of the namespace represented by DIE. Set
7766 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7770 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7772 struct die_info
*current_die
;
7773 const char *name
= NULL
;
7775 /* Loop through the extensions until we find a name. */
7777 for (current_die
= die
;
7778 current_die
!= NULL
;
7779 current_die
= dwarf2_extension (die
, &cu
))
7781 name
= dwarf2_name (current_die
, cu
);
7786 /* Is it an anonymous namespace? */
7788 *is_anonymous
= (name
== NULL
);
7790 name
= "(anonymous namespace)";
7795 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7796 the user defined type vector. */
7798 static struct type
*
7799 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7801 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7802 struct comp_unit_head
*cu_header
= &cu
->header
;
7804 struct attribute
*attr_byte_size
;
7805 struct attribute
*attr_address_class
;
7806 int byte_size
, addr_class
;
7807 struct type
*target_type
;
7809 target_type
= die_type (die
, cu
);
7811 /* The die_type call above may have already set the type for this DIE. */
7812 type
= get_die_type (die
, cu
);
7816 type
= lookup_pointer_type (target_type
);
7818 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7820 byte_size
= DW_UNSND (attr_byte_size
);
7822 byte_size
= cu_header
->addr_size
;
7824 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7825 if (attr_address_class
)
7826 addr_class
= DW_UNSND (attr_address_class
);
7828 addr_class
= DW_ADDR_none
;
7830 /* If the pointer size or address class is different than the
7831 default, create a type variant marked as such and set the
7832 length accordingly. */
7833 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7835 if (gdbarch_address_class_type_flags_p (gdbarch
))
7839 type_flags
= gdbarch_address_class_type_flags
7840 (gdbarch
, byte_size
, addr_class
);
7841 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7843 type
= make_type_with_address_space (type
, type_flags
);
7845 else if (TYPE_LENGTH (type
) != byte_size
)
7847 complaint (&symfile_complaints
,
7848 _("invalid pointer size %d"), byte_size
);
7852 /* Should we also complain about unhandled address classes? */
7856 TYPE_LENGTH (type
) = byte_size
;
7857 return set_die_type (die
, type
, cu
);
7860 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7861 the user defined type vector. */
7863 static struct type
*
7864 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7867 struct type
*to_type
;
7868 struct type
*domain
;
7870 to_type
= die_type (die
, cu
);
7871 domain
= die_containing_type (die
, cu
);
7873 /* The calls above may have already set the type for this DIE. */
7874 type
= get_die_type (die
, cu
);
7878 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7879 type
= lookup_methodptr_type (to_type
);
7881 type
= lookup_memberptr_type (to_type
, domain
);
7883 return set_die_type (die
, type
, cu
);
7886 /* Extract all information from a DW_TAG_reference_type DIE and add to
7887 the user defined type vector. */
7889 static struct type
*
7890 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7892 struct comp_unit_head
*cu_header
= &cu
->header
;
7893 struct type
*type
, *target_type
;
7894 struct attribute
*attr
;
7896 target_type
= die_type (die
, cu
);
7898 /* The die_type call above may have already set the type for this DIE. */
7899 type
= get_die_type (die
, cu
);
7903 type
= lookup_reference_type (target_type
);
7904 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7907 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7911 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7913 return set_die_type (die
, type
, cu
);
7916 static struct type
*
7917 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7919 struct type
*base_type
, *cv_type
;
7921 base_type
= die_type (die
, cu
);
7923 /* The die_type call above may have already set the type for this DIE. */
7924 cv_type
= get_die_type (die
, cu
);
7928 /* In case the const qualifier is applied to an array type, the element type
7929 is so qualified, not the array type (section 6.7.3 of C99). */
7930 if (TYPE_CODE (base_type
) == TYPE_CODE_ARRAY
)
7932 struct type
*el_type
, *inner_array
;
7934 base_type
= copy_type (base_type
);
7935 inner_array
= base_type
;
7937 while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array
)) == TYPE_CODE_ARRAY
)
7939 TYPE_TARGET_TYPE (inner_array
) =
7940 copy_type (TYPE_TARGET_TYPE (inner_array
));
7941 inner_array
= TYPE_TARGET_TYPE (inner_array
);
7944 el_type
= TYPE_TARGET_TYPE (inner_array
);
7945 TYPE_TARGET_TYPE (inner_array
) =
7946 make_cv_type (1, TYPE_VOLATILE (el_type
), el_type
, NULL
);
7948 return set_die_type (die
, base_type
, cu
);
7951 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7952 return set_die_type (die
, cv_type
, cu
);
7955 static struct type
*
7956 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7958 struct type
*base_type
, *cv_type
;
7960 base_type
= die_type (die
, cu
);
7962 /* The die_type call above may have already set the type for this DIE. */
7963 cv_type
= get_die_type (die
, cu
);
7967 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7968 return set_die_type (die
, cv_type
, cu
);
7971 /* Extract all information from a DW_TAG_string_type DIE and add to
7972 the user defined type vector. It isn't really a user defined type,
7973 but it behaves like one, with other DIE's using an AT_user_def_type
7974 attribute to reference it. */
7976 static struct type
*
7977 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7979 struct objfile
*objfile
= cu
->objfile
;
7980 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7981 struct type
*type
, *range_type
, *index_type
, *char_type
;
7982 struct attribute
*attr
;
7983 unsigned int length
;
7985 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7988 length
= DW_UNSND (attr
);
7992 /* Check for the DW_AT_byte_size attribute. */
7993 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7996 length
= DW_UNSND (attr
);
8004 index_type
= objfile_type (objfile
)->builtin_int
;
8005 range_type
= create_range_type (NULL
, index_type
, 1, length
);
8006 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
8007 type
= create_string_type (NULL
, char_type
, range_type
);
8009 return set_die_type (die
, type
, cu
);
8012 /* Handle DIES due to C code like:
8016 int (*funcp)(int a, long l);
8020 ('funcp' generates a DW_TAG_subroutine_type DIE). */
8022 static struct type
*
8023 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8025 struct type
*type
; /* Type that this function returns. */
8026 struct type
*ftype
; /* Function that returns above type. */
8027 struct attribute
*attr
;
8029 type
= die_type (die
, cu
);
8031 /* The die_type call above may have already set the type for this DIE. */
8032 ftype
= get_die_type (die
, cu
);
8036 ftype
= lookup_function_type (type
);
8038 /* All functions in C++, Pascal and Java have prototypes. */
8039 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
8040 if ((attr
&& (DW_UNSND (attr
) != 0))
8041 || cu
->language
== language_cplus
8042 || cu
->language
== language_java
8043 || cu
->language
== language_pascal
)
8044 TYPE_PROTOTYPED (ftype
) = 1;
8045 else if (producer_is_realview (cu
->producer
))
8046 /* RealView does not emit DW_AT_prototyped. We can not
8047 distinguish prototyped and unprototyped functions; default to
8048 prototyped, since that is more common in modern code (and
8049 RealView warns about unprototyped functions). */
8050 TYPE_PROTOTYPED (ftype
) = 1;
8052 /* Store the calling convention in the type if it's available in
8053 the subroutine die. Otherwise set the calling convention to
8054 the default value DW_CC_normal. */
8055 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
8057 TYPE_CALLING_CONVENTION (ftype
) = DW_UNSND (attr
);
8058 else if (cu
->producer
&& strstr (cu
->producer
, "IBM XL C for OpenCL"))
8059 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_GDB_IBM_OpenCL
;
8061 TYPE_CALLING_CONVENTION (ftype
) = DW_CC_normal
;
8063 /* We need to add the subroutine type to the die immediately so
8064 we don't infinitely recurse when dealing with parameters
8065 declared as the same subroutine type. */
8066 set_die_type (die
, ftype
, cu
);
8068 if (die
->child
!= NULL
)
8070 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
8071 struct die_info
*child_die
;
8072 int nparams
, iparams
;
8074 /* Count the number of parameters.
8075 FIXME: GDB currently ignores vararg functions, but knows about
8076 vararg member functions. */
8078 child_die
= die
->child
;
8079 while (child_die
&& child_die
->tag
)
8081 if (child_die
->tag
== DW_TAG_formal_parameter
)
8083 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
8084 TYPE_VARARGS (ftype
) = 1;
8085 child_die
= sibling_die (child_die
);
8088 /* Allocate storage for parameters and fill them in. */
8089 TYPE_NFIELDS (ftype
) = nparams
;
8090 TYPE_FIELDS (ftype
) = (struct field
*)
8091 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
8093 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
8094 even if we error out during the parameters reading below. */
8095 for (iparams
= 0; iparams
< nparams
; iparams
++)
8096 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
8099 child_die
= die
->child
;
8100 while (child_die
&& child_die
->tag
)
8102 if (child_die
->tag
== DW_TAG_formal_parameter
)
8104 struct type
*arg_type
;
8106 /* DWARF version 2 has no clean way to discern C++
8107 static and non-static member functions. G++ helps
8108 GDB by marking the first parameter for non-static
8109 member functions (which is the this pointer) as
8110 artificial. We pass this information to
8111 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
8113 DWARF version 3 added DW_AT_object_pointer, which GCC
8114 4.5 does not yet generate. */
8115 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
8117 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
8120 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
8122 /* GCC/43521: In java, the formal parameter
8123 "this" is sometimes not marked with DW_AT_artificial. */
8124 if (cu
->language
== language_java
)
8126 const char *name
= dwarf2_name (child_die
, cu
);
8128 if (name
&& !strcmp (name
, "this"))
8129 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
8132 arg_type
= die_type (child_die
, cu
);
8134 /* RealView does not mark THIS as const, which the testsuite
8135 expects. GCC marks THIS as const in method definitions,
8136 but not in the class specifications (GCC PR 43053). */
8137 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
8138 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
8141 struct dwarf2_cu
*arg_cu
= cu
;
8142 const char *name
= dwarf2_name (child_die
, cu
);
8144 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
8147 /* If the compiler emits this, use it. */
8148 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
8151 else if (name
&& strcmp (name
, "this") == 0)
8152 /* Function definitions will have the argument names. */
8154 else if (name
== NULL
&& iparams
== 0)
8155 /* Declarations may not have the names, so like
8156 elsewhere in GDB, assume an artificial first
8157 argument is "this". */
8161 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
8165 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
8168 child_die
= sibling_die (child_die
);
8175 static struct type
*
8176 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
8178 struct objfile
*objfile
= cu
->objfile
;
8179 const char *name
= NULL
;
8180 struct type
*this_type
;
8182 name
= dwarf2_full_name (NULL
, die
, cu
);
8183 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
8184 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
8185 TYPE_NAME (this_type
) = (char *) name
;
8186 set_die_type (die
, this_type
, cu
);
8187 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
8191 /* Find a representation of a given base type and install
8192 it in the TYPE field of the die. */
8194 static struct type
*
8195 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8197 struct objfile
*objfile
= cu
->objfile
;
8199 struct attribute
*attr
;
8200 int encoding
= 0, size
= 0;
8202 enum type_code code
= TYPE_CODE_INT
;
8204 struct type
*target_type
= NULL
;
8206 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
8209 encoding
= DW_UNSND (attr
);
8211 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8214 size
= DW_UNSND (attr
);
8216 name
= dwarf2_name (die
, cu
);
8219 complaint (&symfile_complaints
,
8220 _("DW_AT_name missing from DW_TAG_base_type"));
8225 case DW_ATE_address
:
8226 /* Turn DW_ATE_address into a void * pointer. */
8227 code
= TYPE_CODE_PTR
;
8228 type_flags
|= TYPE_FLAG_UNSIGNED
;
8229 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
8231 case DW_ATE_boolean
:
8232 code
= TYPE_CODE_BOOL
;
8233 type_flags
|= TYPE_FLAG_UNSIGNED
;
8235 case DW_ATE_complex_float
:
8236 code
= TYPE_CODE_COMPLEX
;
8237 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
8239 case DW_ATE_decimal_float
:
8240 code
= TYPE_CODE_DECFLOAT
;
8243 code
= TYPE_CODE_FLT
;
8247 case DW_ATE_unsigned
:
8248 type_flags
|= TYPE_FLAG_UNSIGNED
;
8250 case DW_ATE_signed_char
:
8251 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8252 || cu
->language
== language_pascal
)
8253 code
= TYPE_CODE_CHAR
;
8255 case DW_ATE_unsigned_char
:
8256 if (cu
->language
== language_ada
|| cu
->language
== language_m2
8257 || cu
->language
== language_pascal
)
8258 code
= TYPE_CODE_CHAR
;
8259 type_flags
|= TYPE_FLAG_UNSIGNED
;
8262 /* We just treat this as an integer and then recognize the
8263 type by name elsewhere. */
8267 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
8268 dwarf_type_encoding_name (encoding
));
8272 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
8273 TYPE_NAME (type
) = name
;
8274 TYPE_TARGET_TYPE (type
) = target_type
;
8276 if (name
&& strcmp (name
, "char") == 0)
8277 TYPE_NOSIGN (type
) = 1;
8279 return set_die_type (die
, type
, cu
);
8282 /* Read the given DW_AT_subrange DIE. */
8284 static struct type
*
8285 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8287 struct type
*base_type
;
8288 struct type
*range_type
;
8289 struct attribute
*attr
;
8293 LONGEST negative_mask
;
8295 base_type
= die_type (die
, cu
);
8296 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
8297 check_typedef (base_type
);
8299 /* The die_type call above may have already set the type for this DIE. */
8300 range_type
= get_die_type (die
, cu
);
8304 if (cu
->language
== language_fortran
)
8306 /* FORTRAN implies a lower bound of 1, if not given. */
8310 /* FIXME: For variable sized arrays either of these could be
8311 a variable rather than a constant value. We'll allow it,
8312 but we don't know how to handle it. */
8313 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
8315 low
= dwarf2_get_attr_constant_value (attr
, 0);
8317 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8320 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8322 /* GCC encodes arrays with unspecified or dynamic length
8323 with a DW_FORM_block1 attribute or a reference attribute.
8324 FIXME: GDB does not yet know how to handle dynamic
8325 arrays properly, treat them as arrays with unspecified
8328 FIXME: jimb/2003-09-22: GDB does not really know
8329 how to handle arrays of unspecified length
8330 either; we just represent them as zero-length
8331 arrays. Choose an appropriate upper bound given
8332 the lower bound we've computed above. */
8336 high
= dwarf2_get_attr_constant_value (attr
, 1);
8340 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8343 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8344 high
= low
+ count
- 1;
8348 /* Unspecified array length. */
8353 /* Dwarf-2 specifications explicitly allows to create subrange types
8354 without specifying a base type.
8355 In that case, the base type must be set to the type of
8356 the lower bound, upper bound or count, in that order, if any of these
8357 three attributes references an object that has a type.
8358 If no base type is found, the Dwarf-2 specifications say that
8359 a signed integer type of size equal to the size of an address should
8361 For the following C code: `extern char gdb_int [];'
8362 GCC produces an empty range DIE.
8363 FIXME: muller/2010-05-28: Possible references to object for low bound,
8364 high bound or count are not yet handled by this code. */
8365 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8367 struct objfile
*objfile
= cu
->objfile
;
8368 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8369 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8370 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8372 /* Test "int", "long int", and "long long int" objfile types,
8373 and select the first one having a size above or equal to the
8374 architecture address size. */
8375 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8376 base_type
= int_type
;
8379 int_type
= objfile_type (objfile
)->builtin_long
;
8380 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8381 base_type
= int_type
;
8384 int_type
= objfile_type (objfile
)->builtin_long_long
;
8385 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8386 base_type
= int_type
;
8392 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8393 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8394 low
|= negative_mask
;
8395 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8396 high
|= negative_mask
;
8398 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8400 /* Mark arrays with dynamic length at least as an array of unspecified
8401 length. GDB could check the boundary but before it gets implemented at
8402 least allow accessing the array elements. */
8403 if (attr
&& attr
->form
== DW_FORM_block1
)
8404 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8406 /* Ada expects an empty array on no boundary attributes. */
8407 if (attr
== NULL
&& cu
->language
!= language_ada
)
8408 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8410 name
= dwarf2_name (die
, cu
);
8412 TYPE_NAME (range_type
) = name
;
8414 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8416 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8418 set_die_type (die
, range_type
, cu
);
8420 /* set_die_type should be already done. */
8421 set_descriptive_type (range_type
, die
, cu
);
8426 static struct type
*
8427 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8431 /* For now, we only support the C meaning of an unspecified type: void. */
8433 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8434 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8436 return set_die_type (die
, type
, cu
);
8439 /* Trivial hash function for die_info: the hash value of a DIE
8440 is its offset in .debug_info for this objfile. */
8443 die_hash (const void *item
)
8445 const struct die_info
*die
= item
;
8450 /* Trivial comparison function for die_info structures: two DIEs
8451 are equal if they have the same offset. */
8454 die_eq (const void *item_lhs
, const void *item_rhs
)
8456 const struct die_info
*die_lhs
= item_lhs
;
8457 const struct die_info
*die_rhs
= item_rhs
;
8459 return die_lhs
->offset
== die_rhs
->offset
;
8462 /* Read a whole compilation unit into a linked list of dies. */
8464 static struct die_info
*
8465 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8467 struct die_reader_specs reader_specs
;
8468 int read_abbrevs
= 0;
8469 struct cleanup
*back_to
= NULL
;
8470 struct die_info
*die
;
8472 if (cu
->dwarf2_abbrevs
== NULL
)
8474 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8475 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8479 gdb_assert (cu
->die_hash
== NULL
);
8481 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8485 &cu
->comp_unit_obstack
,
8486 hashtab_obstack_allocate
,
8487 dummy_obstack_deallocate
);
8489 init_cu_die_reader (&reader_specs
, cu
);
8491 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8494 do_cleanups (back_to
);
8499 /* Main entry point for reading a DIE and all children.
8500 Read the DIE and dump it if requested. */
8502 static struct die_info
*
8503 read_die_and_children (const struct die_reader_specs
*reader
,
8505 gdb_byte
**new_info_ptr
,
8506 struct die_info
*parent
)
8508 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8509 new_info_ptr
, parent
);
8511 if (dwarf2_die_debug
)
8513 fprintf_unfiltered (gdb_stdlog
,
8514 "\nRead die from %s of %s:\n",
8515 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8517 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8519 : "unknown section",
8520 reader
->abfd
->filename
);
8521 dump_die (result
, dwarf2_die_debug
);
8527 /* Read a single die and all its descendents. Set the die's sibling
8528 field to NULL; set other fields in the die correctly, and set all
8529 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8530 location of the info_ptr after reading all of those dies. PARENT
8531 is the parent of the die in question. */
8533 static struct die_info
*
8534 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8536 gdb_byte
**new_info_ptr
,
8537 struct die_info
*parent
)
8539 struct die_info
*die
;
8543 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8546 *new_info_ptr
= cur_ptr
;
8549 store_in_ref_table (die
, reader
->cu
);
8552 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8556 *new_info_ptr
= cur_ptr
;
8559 die
->sibling
= NULL
;
8560 die
->parent
= parent
;
8564 /* Read a die, all of its descendents, and all of its siblings; set
8565 all of the fields of all of the dies correctly. Arguments are as
8566 in read_die_and_children. */
8568 static struct die_info
*
8569 read_die_and_siblings (const struct die_reader_specs
*reader
,
8571 gdb_byte
**new_info_ptr
,
8572 struct die_info
*parent
)
8574 struct die_info
*first_die
, *last_sibling
;
8578 first_die
= last_sibling
= NULL
;
8582 struct die_info
*die
8583 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8587 *new_info_ptr
= cur_ptr
;
8594 last_sibling
->sibling
= die
;
8600 /* Read the die from the .debug_info section buffer. Set DIEP to
8601 point to a newly allocated die with its information, except for its
8602 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8603 whether the die has children or not. */
8606 read_full_die (const struct die_reader_specs
*reader
,
8607 struct die_info
**diep
, gdb_byte
*info_ptr
,
8610 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8611 struct abbrev_info
*abbrev
;
8612 struct die_info
*die
;
8613 struct dwarf2_cu
*cu
= reader
->cu
;
8614 bfd
*abfd
= reader
->abfd
;
8616 offset
= info_ptr
- reader
->buffer
;
8617 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8618 info_ptr
+= bytes_read
;
8626 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8628 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8630 bfd_get_filename (abfd
));
8632 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8633 die
->offset
= offset
;
8634 die
->tag
= abbrev
->tag
;
8635 die
->abbrev
= abbrev_number
;
8637 die
->num_attrs
= abbrev
->num_attrs
;
8639 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8640 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8641 abfd
, info_ptr
, cu
);
8644 *has_children
= abbrev
->has_children
;
8648 /* In DWARF version 2, the description of the debugging information is
8649 stored in a separate .debug_abbrev section. Before we read any
8650 dies from a section we read in all abbreviations and install them
8651 in a hash table. This function also sets flags in CU describing
8652 the data found in the abbrev table. */
8655 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8657 struct comp_unit_head
*cu_header
= &cu
->header
;
8658 gdb_byte
*abbrev_ptr
;
8659 struct abbrev_info
*cur_abbrev
;
8660 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8661 unsigned int abbrev_form
, hash_number
;
8662 struct attr_abbrev
*cur_attrs
;
8663 unsigned int allocated_attrs
;
8665 /* Initialize dwarf2 abbrevs. */
8666 obstack_init (&cu
->abbrev_obstack
);
8667 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8669 * sizeof (struct abbrev_info
*)));
8670 memset (cu
->dwarf2_abbrevs
, 0,
8671 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8673 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8674 &dwarf2_per_objfile
->abbrev
);
8675 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8676 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8677 abbrev_ptr
+= bytes_read
;
8679 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8680 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8682 /* Loop until we reach an abbrev number of 0. */
8683 while (abbrev_number
)
8685 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8687 /* read in abbrev header */
8688 cur_abbrev
->number
= abbrev_number
;
8689 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8690 abbrev_ptr
+= bytes_read
;
8691 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8694 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8695 cu
->has_namespace_info
= 1;
8697 /* now read in declarations */
8698 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8699 abbrev_ptr
+= bytes_read
;
8700 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8701 abbrev_ptr
+= bytes_read
;
8704 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8706 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8708 = xrealloc (cur_attrs
, (allocated_attrs
8709 * sizeof (struct attr_abbrev
)));
8712 /* Record whether this compilation unit might have
8713 inter-compilation-unit references. If we don't know what form
8714 this attribute will have, then it might potentially be a
8715 DW_FORM_ref_addr, so we conservatively expect inter-CU
8718 if (abbrev_form
== DW_FORM_ref_addr
8719 || abbrev_form
== DW_FORM_indirect
)
8720 cu
->has_form_ref_addr
= 1;
8722 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8723 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8724 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8725 abbrev_ptr
+= bytes_read
;
8726 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8727 abbrev_ptr
+= bytes_read
;
8730 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8731 (cur_abbrev
->num_attrs
8732 * sizeof (struct attr_abbrev
)));
8733 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8734 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8736 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8737 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8738 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8740 /* Get next abbreviation.
8741 Under Irix6 the abbreviations for a compilation unit are not
8742 always properly terminated with an abbrev number of 0.
8743 Exit loop if we encounter an abbreviation which we have
8744 already read (which means we are about to read the abbreviations
8745 for the next compile unit) or if the end of the abbreviation
8746 table is reached. */
8747 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8748 >= dwarf2_per_objfile
->abbrev
.size
)
8750 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8751 abbrev_ptr
+= bytes_read
;
8752 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8759 /* Release the memory used by the abbrev table for a compilation unit. */
8762 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8764 struct dwarf2_cu
*cu
= ptr_to_cu
;
8766 obstack_free (&cu
->abbrev_obstack
, NULL
);
8767 cu
->dwarf2_abbrevs
= NULL
;
8770 /* Lookup an abbrev_info structure in the abbrev hash table. */
8772 static struct abbrev_info
*
8773 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8775 unsigned int hash_number
;
8776 struct abbrev_info
*abbrev
;
8778 hash_number
= number
% ABBREV_HASH_SIZE
;
8779 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8783 if (abbrev
->number
== number
)
8786 abbrev
= abbrev
->next
;
8791 /* Returns nonzero if TAG represents a type that we might generate a partial
8795 is_type_tag_for_partial (int tag
)
8800 /* Some types that would be reasonable to generate partial symbols for,
8801 that we don't at present. */
8802 case DW_TAG_array_type
:
8803 case DW_TAG_file_type
:
8804 case DW_TAG_ptr_to_member_type
:
8805 case DW_TAG_set_type
:
8806 case DW_TAG_string_type
:
8807 case DW_TAG_subroutine_type
:
8809 case DW_TAG_base_type
:
8810 case DW_TAG_class_type
:
8811 case DW_TAG_interface_type
:
8812 case DW_TAG_enumeration_type
:
8813 case DW_TAG_structure_type
:
8814 case DW_TAG_subrange_type
:
8815 case DW_TAG_typedef
:
8816 case DW_TAG_union_type
:
8823 /* Load all DIEs that are interesting for partial symbols into memory. */
8825 static struct partial_die_info
*
8826 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8827 int building_psymtab
, struct dwarf2_cu
*cu
)
8829 struct partial_die_info
*part_die
;
8830 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8831 struct abbrev_info
*abbrev
;
8832 unsigned int bytes_read
;
8833 unsigned int load_all
= 0;
8835 int nesting_level
= 1;
8840 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8844 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8848 &cu
->comp_unit_obstack
,
8849 hashtab_obstack_allocate
,
8850 dummy_obstack_deallocate
);
8852 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8853 sizeof (struct partial_die_info
));
8857 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8859 /* A NULL abbrev means the end of a series of children. */
8862 if (--nesting_level
== 0)
8864 /* PART_DIE was probably the last thing allocated on the
8865 comp_unit_obstack, so we could call obstack_free
8866 here. We don't do that because the waste is small,
8867 and will be cleaned up when we're done with this
8868 compilation unit. This way, we're also more robust
8869 against other users of the comp_unit_obstack. */
8872 info_ptr
+= bytes_read
;
8873 last_die
= parent_die
;
8874 parent_die
= parent_die
->die_parent
;
8878 /* Check for template arguments. We never save these; if
8879 they're seen, we just mark the parent, and go on our way. */
8880 if (parent_die
!= NULL
8881 && cu
->language
== language_cplus
8882 && (abbrev
->tag
== DW_TAG_template_type_param
8883 || abbrev
->tag
== DW_TAG_template_value_param
))
8885 parent_die
->has_template_arguments
= 1;
8889 /* We don't need a partial DIE for the template argument. */
8890 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8896 /* We only recurse into subprograms looking for template arguments.
8897 Skip their other children. */
8899 && cu
->language
== language_cplus
8900 && parent_die
!= NULL
8901 && parent_die
->tag
== DW_TAG_subprogram
)
8903 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8907 /* Check whether this DIE is interesting enough to save. Normally
8908 we would not be interested in members here, but there may be
8909 later variables referencing them via DW_AT_specification (for
8912 && !is_type_tag_for_partial (abbrev
->tag
)
8913 && abbrev
->tag
!= DW_TAG_constant
8914 && abbrev
->tag
!= DW_TAG_enumerator
8915 && abbrev
->tag
!= DW_TAG_subprogram
8916 && abbrev
->tag
!= DW_TAG_lexical_block
8917 && abbrev
->tag
!= DW_TAG_variable
8918 && abbrev
->tag
!= DW_TAG_namespace
8919 && abbrev
->tag
!= DW_TAG_module
8920 && abbrev
->tag
!= DW_TAG_member
)
8922 /* Otherwise we skip to the next sibling, if any. */
8923 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8927 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8928 buffer
, info_ptr
, cu
);
8930 /* This two-pass algorithm for processing partial symbols has a
8931 high cost in cache pressure. Thus, handle some simple cases
8932 here which cover the majority of C partial symbols. DIEs
8933 which neither have specification tags in them, nor could have
8934 specification tags elsewhere pointing at them, can simply be
8935 processed and discarded.
8937 This segment is also optional; scan_partial_symbols and
8938 add_partial_symbol will handle these DIEs if we chain
8939 them in normally. When compilers which do not emit large
8940 quantities of duplicate debug information are more common,
8941 this code can probably be removed. */
8943 /* Any complete simple types at the top level (pretty much all
8944 of them, for a language without namespaces), can be processed
8946 if (parent_die
== NULL
8947 && part_die
->has_specification
== 0
8948 && part_die
->is_declaration
== 0
8949 && (part_die
->tag
== DW_TAG_typedef
8950 || part_die
->tag
== DW_TAG_base_type
8951 || part_die
->tag
== DW_TAG_subrange_type
))
8953 if (building_psymtab
&& part_die
->name
!= NULL
)
8954 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8955 VAR_DOMAIN
, LOC_TYPEDEF
,
8956 &cu
->objfile
->static_psymbols
,
8957 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8958 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8962 /* If we're at the second level, and we're an enumerator, and
8963 our parent has no specification (meaning possibly lives in a
8964 namespace elsewhere), then we can add the partial symbol now
8965 instead of queueing it. */
8966 if (part_die
->tag
== DW_TAG_enumerator
8967 && parent_die
!= NULL
8968 && parent_die
->die_parent
== NULL
8969 && parent_die
->tag
== DW_TAG_enumeration_type
8970 && parent_die
->has_specification
== 0)
8972 if (part_die
->name
== NULL
)
8973 complaint (&symfile_complaints
,
8974 _("malformed enumerator DIE ignored"));
8975 else if (building_psymtab
)
8976 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8977 VAR_DOMAIN
, LOC_CONST
,
8978 (cu
->language
== language_cplus
8979 || cu
->language
== language_java
)
8980 ? &cu
->objfile
->global_psymbols
8981 : &cu
->objfile
->static_psymbols
,
8982 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8984 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8988 /* We'll save this DIE so link it in. */
8989 part_die
->die_parent
= parent_die
;
8990 part_die
->die_sibling
= NULL
;
8991 part_die
->die_child
= NULL
;
8993 if (last_die
&& last_die
== parent_die
)
8994 last_die
->die_child
= part_die
;
8996 last_die
->die_sibling
= part_die
;
8998 last_die
= part_die
;
9000 if (first_die
== NULL
)
9001 first_die
= part_die
;
9003 /* Maybe add the DIE to the hash table. Not all DIEs that we
9004 find interesting need to be in the hash table, because we
9005 also have the parent/sibling/child chains; only those that we
9006 might refer to by offset later during partial symbol reading.
9008 For now this means things that might have be the target of a
9009 DW_AT_specification, DW_AT_abstract_origin, or
9010 DW_AT_extension. DW_AT_extension will refer only to
9011 namespaces; DW_AT_abstract_origin refers to functions (and
9012 many things under the function DIE, but we do not recurse
9013 into function DIEs during partial symbol reading) and
9014 possibly variables as well; DW_AT_specification refers to
9015 declarations. Declarations ought to have the DW_AT_declaration
9016 flag. It happens that GCC forgets to put it in sometimes, but
9017 only for functions, not for types.
9019 Adding more things than necessary to the hash table is harmless
9020 except for the performance cost. Adding too few will result in
9021 wasted time in find_partial_die, when we reread the compilation
9022 unit with load_all_dies set. */
9025 || abbrev
->tag
== DW_TAG_constant
9026 || abbrev
->tag
== DW_TAG_subprogram
9027 || abbrev
->tag
== DW_TAG_variable
9028 || abbrev
->tag
== DW_TAG_namespace
9029 || part_die
->is_declaration
)
9033 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
9034 part_die
->offset
, INSERT
);
9038 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
9039 sizeof (struct partial_die_info
));
9041 /* For some DIEs we want to follow their children (if any). For C
9042 we have no reason to follow the children of structures; for other
9043 languages we have to, so that we can get at method physnames
9044 to infer fully qualified class names, for DW_AT_specification,
9045 and for C++ template arguments. For C++, we also look one level
9046 inside functions to find template arguments (if the name of the
9047 function does not already contain the template arguments).
9049 For Ada, we need to scan the children of subprograms and lexical
9050 blocks as well because Ada allows the definition of nested
9051 entities that could be interesting for the debugger, such as
9052 nested subprograms for instance. */
9053 if (last_die
->has_children
9055 || last_die
->tag
== DW_TAG_namespace
9056 || last_die
->tag
== DW_TAG_module
9057 || last_die
->tag
== DW_TAG_enumeration_type
9058 || (cu
->language
== language_cplus
9059 && last_die
->tag
== DW_TAG_subprogram
9060 && (last_die
->name
== NULL
9061 || strchr (last_die
->name
, '<') == NULL
))
9062 || (cu
->language
!= language_c
9063 && (last_die
->tag
== DW_TAG_class_type
9064 || last_die
->tag
== DW_TAG_interface_type
9065 || last_die
->tag
== DW_TAG_structure_type
9066 || last_die
->tag
== DW_TAG_union_type
))
9067 || (cu
->language
== language_ada
9068 && (last_die
->tag
== DW_TAG_subprogram
9069 || last_die
->tag
== DW_TAG_lexical_block
))))
9072 parent_die
= last_die
;
9076 /* Otherwise we skip to the next sibling, if any. */
9077 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
9079 /* Back to the top, do it again. */
9083 /* Read a minimal amount of information into the minimal die structure. */
9086 read_partial_die (struct partial_die_info
*part_die
,
9087 struct abbrev_info
*abbrev
,
9088 unsigned int abbrev_len
, bfd
*abfd
,
9089 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
9090 struct dwarf2_cu
*cu
)
9093 struct attribute attr
;
9094 int has_low_pc_attr
= 0;
9095 int has_high_pc_attr
= 0;
9097 memset (part_die
, 0, sizeof (struct partial_die_info
));
9099 part_die
->offset
= info_ptr
- buffer
;
9101 info_ptr
+= abbrev_len
;
9106 part_die
->tag
= abbrev
->tag
;
9107 part_die
->has_children
= abbrev
->has_children
;
9109 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
9111 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
9113 /* Store the data if it is of an attribute we want to keep in a
9114 partial symbol table. */
9118 switch (part_die
->tag
)
9120 case DW_TAG_compile_unit
:
9121 case DW_TAG_type_unit
:
9122 /* Compilation units have a DW_AT_name that is a filename, not
9123 a source language identifier. */
9124 case DW_TAG_enumeration_type
:
9125 case DW_TAG_enumerator
:
9126 /* These tags always have simple identifiers already; no need
9127 to canonicalize them. */
9128 part_die
->name
= DW_STRING (&attr
);
9132 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
9133 &cu
->objfile
->objfile_obstack
);
9137 case DW_AT_linkage_name
:
9138 case DW_AT_MIPS_linkage_name
:
9139 /* Note that both forms of linkage name might appear. We
9140 assume they will be the same, and we only store the last
9142 if (cu
->language
== language_ada
)
9143 part_die
->name
= DW_STRING (&attr
);
9144 part_die
->linkage_name
= DW_STRING (&attr
);
9147 has_low_pc_attr
= 1;
9148 part_die
->lowpc
= DW_ADDR (&attr
);
9151 has_high_pc_attr
= 1;
9152 part_die
->highpc
= DW_ADDR (&attr
);
9154 case DW_AT_location
:
9155 /* Support the .debug_loc offsets. */
9156 if (attr_form_is_block (&attr
))
9158 part_die
->locdesc
= DW_BLOCK (&attr
);
9160 else if (attr_form_is_section_offset (&attr
))
9162 dwarf2_complex_location_expr_complaint ();
9166 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
9167 "partial symbol information");
9170 case DW_AT_external
:
9171 part_die
->is_external
= DW_UNSND (&attr
);
9173 case DW_AT_declaration
:
9174 part_die
->is_declaration
= DW_UNSND (&attr
);
9177 part_die
->has_type
= 1;
9179 case DW_AT_abstract_origin
:
9180 case DW_AT_specification
:
9181 case DW_AT_extension
:
9182 part_die
->has_specification
= 1;
9183 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
9186 /* Ignore absolute siblings, they might point outside of
9187 the current compile unit. */
9188 if (attr
.form
== DW_FORM_ref_addr
)
9189 complaint (&symfile_complaints
,
9190 _("ignoring absolute DW_AT_sibling"));
9192 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
9194 case DW_AT_byte_size
:
9195 part_die
->has_byte_size
= 1;
9197 case DW_AT_calling_convention
:
9198 /* DWARF doesn't provide a way to identify a program's source-level
9199 entry point. DW_AT_calling_convention attributes are only meant
9200 to describe functions' calling conventions.
9202 However, because it's a necessary piece of information in
9203 Fortran, and because DW_CC_program is the only piece of debugging
9204 information whose definition refers to a 'main program' at all,
9205 several compilers have begun marking Fortran main programs with
9206 DW_CC_program --- even when those functions use the standard
9207 calling conventions.
9209 So until DWARF specifies a way to provide this information and
9210 compilers pick up the new representation, we'll support this
9212 if (DW_UNSND (&attr
) == DW_CC_program
9213 && cu
->language
== language_fortran
)
9215 set_main_name (part_die
->name
);
9217 /* As this DIE has a static linkage the name would be difficult
9218 to look up later. */
9219 language_of_main
= language_fortran
;
9227 if (has_low_pc_attr
&& has_high_pc_attr
)
9229 /* When using the GNU linker, .gnu.linkonce. sections are used to
9230 eliminate duplicate copies of functions and vtables and such.
9231 The linker will arbitrarily choose one and discard the others.
9232 The AT_*_pc values for such functions refer to local labels in
9233 these sections. If the section from that file was discarded, the
9234 labels are not in the output, so the relocs get a value of 0.
9235 If this is a discarded function, mark the pc bounds as invalid,
9236 so that GDB will ignore it. */
9237 if (part_die
->lowpc
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
9239 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9241 complaint (&symfile_complaints
,
9242 _("DW_AT_low_pc %s is zero "
9243 "for DIE at 0x%x [in module %s]"),
9244 paddress (gdbarch
, part_die
->lowpc
),
9245 part_die
->offset
, cu
->objfile
->name
);
9247 /* dwarf2_get_pc_bounds has also the strict low < high requirement. */
9248 else if (part_die
->lowpc
>= part_die
->highpc
)
9250 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
9252 complaint (&symfile_complaints
,
9253 _("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
9254 "for DIE at 0x%x [in module %s]"),
9255 paddress (gdbarch
, part_die
->lowpc
),
9256 paddress (gdbarch
, part_die
->highpc
),
9257 part_die
->offset
, cu
->objfile
->name
);
9260 part_die
->has_pc_info
= 1;
9266 /* Find a cached partial DIE at OFFSET in CU. */
9268 static struct partial_die_info
*
9269 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
9271 struct partial_die_info
*lookup_die
= NULL
;
9272 struct partial_die_info part_die
;
9274 part_die
.offset
= offset
;
9275 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
9280 /* Find a partial DIE at OFFSET, which may or may not be in CU,
9281 except in the case of .debug_types DIEs which do not reference
9282 outside their CU (they do however referencing other types via
9283 DW_FORM_ref_sig8). */
9285 static struct partial_die_info
*
9286 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
9288 struct dwarf2_per_cu_data
*per_cu
= NULL
;
9289 struct partial_die_info
*pd
= NULL
;
9291 if (cu
->per_cu
->from_debug_types
)
9293 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9299 if (offset_in_cu_p (&cu
->header
, offset
))
9301 pd
= find_partial_die_in_comp_unit (offset
, cu
);
9306 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9308 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
9309 load_partial_comp_unit (per_cu
, cu
->objfile
);
9311 per_cu
->cu
->last_used
= 0;
9312 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9314 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
9316 struct cleanup
*back_to
;
9317 struct partial_die_info comp_unit_die
;
9318 struct abbrev_info
*abbrev
;
9319 unsigned int bytes_read
;
9322 per_cu
->load_all_dies
= 1;
9324 /* Re-read the DIEs. */
9325 back_to
= make_cleanup (null_cleanup
, 0);
9326 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
9328 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
9329 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
9331 info_ptr
= (dwarf2_per_objfile
->info
.buffer
9332 + per_cu
->cu
->header
.offset
9333 + per_cu
->cu
->header
.first_die_offset
);
9334 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
9335 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
9336 per_cu
->cu
->objfile
->obfd
,
9337 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9339 if (comp_unit_die
.has_children
)
9340 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
9341 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
9343 do_cleanups (back_to
);
9345 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
9351 internal_error (__FILE__
, __LINE__
,
9352 _("could not find partial DIE 0x%x "
9353 "in cache [from module %s]\n"),
9354 offset
, bfd_get_filename (cu
->objfile
->obfd
));
9358 /* See if we can figure out if the class lives in a namespace. We do
9359 this by looking for a member function; its demangled name will
9360 contain namespace info, if there is any. */
9363 guess_partial_die_structure_name (struct partial_die_info
*struct_pdi
,
9364 struct dwarf2_cu
*cu
)
9366 /* NOTE: carlton/2003-10-07: Getting the info this way changes
9367 what template types look like, because the demangler
9368 frequently doesn't give the same name as the debug info. We
9369 could fix this by only using the demangled name to get the
9370 prefix (but see comment in read_structure_type). */
9372 struct partial_die_info
*real_pdi
;
9373 struct partial_die_info
*child_pdi
;
9375 /* If this DIE (this DIE's specification, if any) has a parent, then
9376 we should not do this. We'll prepend the parent's fully qualified
9377 name when we create the partial symbol. */
9379 real_pdi
= struct_pdi
;
9380 while (real_pdi
->has_specification
)
9381 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
9383 if (real_pdi
->die_parent
!= NULL
)
9386 for (child_pdi
= struct_pdi
->die_child
;
9388 child_pdi
= child_pdi
->die_sibling
)
9390 if (child_pdi
->tag
== DW_TAG_subprogram
9391 && child_pdi
->linkage_name
!= NULL
)
9393 char *actual_class_name
9394 = language_class_name_from_physname (cu
->language_defn
,
9395 child_pdi
->linkage_name
);
9396 if (actual_class_name
!= NULL
)
9399 = obsavestring (actual_class_name
,
9400 strlen (actual_class_name
),
9401 &cu
->objfile
->objfile_obstack
);
9402 xfree (actual_class_name
);
9409 /* Adjust PART_DIE before generating a symbol for it. This function
9410 may set the is_external flag or change the DIE's name. */
9413 fixup_partial_die (struct partial_die_info
*part_die
,
9414 struct dwarf2_cu
*cu
)
9416 /* Once we've fixed up a die, there's no point in doing so again.
9417 This also avoids a memory leak if we were to call
9418 guess_partial_die_structure_name multiple times. */
9419 if (part_die
->fixup_called
)
9422 /* If we found a reference attribute and the DIE has no name, try
9423 to find a name in the referred to DIE. */
9425 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9427 struct partial_die_info
*spec_die
;
9429 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9431 fixup_partial_die (spec_die
, cu
);
9435 part_die
->name
= spec_die
->name
;
9437 /* Copy DW_AT_external attribute if it is set. */
9438 if (spec_die
->is_external
)
9439 part_die
->is_external
= spec_die
->is_external
;
9443 /* Set default names for some unnamed DIEs. */
9445 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9446 part_die
->name
= "(anonymous namespace)";
9448 /* If there is no parent die to provide a namespace, and there are
9449 children, see if we can determine the namespace from their linkage
9451 NOTE: We need to do this even if cu->has_namespace_info != 0.
9452 gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */
9453 if (cu
->language
== language_cplus
9454 && dwarf2_per_objfile
->types
.asection
!= NULL
9455 && part_die
->die_parent
== NULL
9456 && part_die
->has_children
9457 && (part_die
->tag
== DW_TAG_class_type
9458 || part_die
->tag
== DW_TAG_structure_type
9459 || part_die
->tag
== DW_TAG_union_type
))
9460 guess_partial_die_structure_name (part_die
, cu
);
9462 /* GCC might emit a nameless struct or union that has a linkage
9463 name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
9464 if (part_die
->name
== NULL
9465 && (part_die
->tag
== DW_TAG_structure_type
9466 || part_die
->tag
== DW_TAG_union_type
9467 || part_die
->tag
== DW_TAG_class_type
)
9468 && part_die
->linkage_name
!= NULL
)
9472 demangled
= cplus_demangle (part_die
->linkage_name
, DMGL_TYPES
);
9475 part_die
->name
= obsavestring (demangled
, strlen (demangled
),
9476 &cu
->objfile
->objfile_obstack
);
9481 part_die
->fixup_called
= 1;
9484 /* Read an attribute value described by an attribute form. */
9487 read_attribute_value (struct attribute
*attr
, unsigned form
,
9488 bfd
*abfd
, gdb_byte
*info_ptr
,
9489 struct dwarf2_cu
*cu
)
9491 struct comp_unit_head
*cu_header
= &cu
->header
;
9492 unsigned int bytes_read
;
9493 struct dwarf_block
*blk
;
9498 case DW_FORM_ref_addr
:
9499 if (cu
->header
.version
== 2)
9500 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9502 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
,
9503 &cu
->header
, &bytes_read
);
9504 info_ptr
+= bytes_read
;
9507 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9508 info_ptr
+= bytes_read
;
9510 case DW_FORM_block2
:
9511 blk
= dwarf_alloc_block (cu
);
9512 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9514 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9515 info_ptr
+= blk
->size
;
9516 DW_BLOCK (attr
) = blk
;
9518 case DW_FORM_block4
:
9519 blk
= dwarf_alloc_block (cu
);
9520 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9522 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9523 info_ptr
+= blk
->size
;
9524 DW_BLOCK (attr
) = blk
;
9527 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9531 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9535 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9538 case DW_FORM_sec_offset
:
9539 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9540 info_ptr
+= bytes_read
;
9542 case DW_FORM_string
:
9543 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9544 DW_STRING_IS_CANONICAL (attr
) = 0;
9545 info_ptr
+= bytes_read
;
9548 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9550 DW_STRING_IS_CANONICAL (attr
) = 0;
9551 info_ptr
+= bytes_read
;
9553 case DW_FORM_exprloc
:
9555 blk
= dwarf_alloc_block (cu
);
9556 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9557 info_ptr
+= bytes_read
;
9558 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9559 info_ptr
+= blk
->size
;
9560 DW_BLOCK (attr
) = blk
;
9562 case DW_FORM_block1
:
9563 blk
= dwarf_alloc_block (cu
);
9564 blk
->size
= read_1_byte (abfd
, info_ptr
);
9566 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9567 info_ptr
+= blk
->size
;
9568 DW_BLOCK (attr
) = blk
;
9571 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9575 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9578 case DW_FORM_flag_present
:
9579 DW_UNSND (attr
) = 1;
9582 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9583 info_ptr
+= bytes_read
;
9586 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9587 info_ptr
+= bytes_read
;
9590 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9594 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9598 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9602 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9605 case DW_FORM_ref_sig8
:
9606 /* Convert the signature to something we can record in DW_UNSND
9608 NOTE: This is NULL if the type wasn't found. */
9609 DW_SIGNATURED_TYPE (attr
) =
9610 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9613 case DW_FORM_ref_udata
:
9614 DW_ADDR (attr
) = (cu
->header
.offset
9615 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9616 info_ptr
+= bytes_read
;
9618 case DW_FORM_indirect
:
9619 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9620 info_ptr
+= bytes_read
;
9621 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9624 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9625 dwarf_form_name (form
),
9626 bfd_get_filename (abfd
));
9629 /* We have seen instances where the compiler tried to emit a byte
9630 size attribute of -1 which ended up being encoded as an unsigned
9631 0xffffffff. Although 0xffffffff is technically a valid size value,
9632 an object of this size seems pretty unlikely so we can relatively
9633 safely treat these cases as if the size attribute was invalid and
9634 treat them as zero by default. */
9635 if (attr
->name
== DW_AT_byte_size
9636 && form
== DW_FORM_data4
9637 && DW_UNSND (attr
) >= 0xffffffff)
9640 (&symfile_complaints
,
9641 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9642 hex_string (DW_UNSND (attr
)));
9643 DW_UNSND (attr
) = 0;
9649 /* Read an attribute described by an abbreviated attribute. */
9652 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9653 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9655 attr
->name
= abbrev
->name
;
9656 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9659 /* Read dwarf information from a buffer. */
9662 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9664 return bfd_get_8 (abfd
, buf
);
9668 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9670 return bfd_get_signed_8 (abfd
, buf
);
9674 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9676 return bfd_get_16 (abfd
, buf
);
9680 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9682 return bfd_get_signed_16 (abfd
, buf
);
9686 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9688 return bfd_get_32 (abfd
, buf
);
9692 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9694 return bfd_get_signed_32 (abfd
, buf
);
9698 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9700 return bfd_get_64 (abfd
, buf
);
9704 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9705 unsigned int *bytes_read
)
9707 struct comp_unit_head
*cu_header
= &cu
->header
;
9708 CORE_ADDR retval
= 0;
9710 if (cu_header
->signed_addr_p
)
9712 switch (cu_header
->addr_size
)
9715 retval
= bfd_get_signed_16 (abfd
, buf
);
9718 retval
= bfd_get_signed_32 (abfd
, buf
);
9721 retval
= bfd_get_signed_64 (abfd
, buf
);
9724 internal_error (__FILE__
, __LINE__
,
9725 _("read_address: bad switch, signed [in module %s]"),
9726 bfd_get_filename (abfd
));
9731 switch (cu_header
->addr_size
)
9734 retval
= bfd_get_16 (abfd
, buf
);
9737 retval
= bfd_get_32 (abfd
, buf
);
9740 retval
= bfd_get_64 (abfd
, buf
);
9743 internal_error (__FILE__
, __LINE__
,
9744 _("read_address: bad switch, "
9745 "unsigned [in module %s]"),
9746 bfd_get_filename (abfd
));
9750 *bytes_read
= cu_header
->addr_size
;
9754 /* Read the initial length from a section. The (draft) DWARF 3
9755 specification allows the initial length to take up either 4 bytes
9756 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9757 bytes describe the length and all offsets will be 8 bytes in length
9760 An older, non-standard 64-bit format is also handled by this
9761 function. The older format in question stores the initial length
9762 as an 8-byte quantity without an escape value. Lengths greater
9763 than 2^32 aren't very common which means that the initial 4 bytes
9764 is almost always zero. Since a length value of zero doesn't make
9765 sense for the 32-bit format, this initial zero can be considered to
9766 be an escape value which indicates the presence of the older 64-bit
9767 format. As written, the code can't detect (old format) lengths
9768 greater than 4GB. If it becomes necessary to handle lengths
9769 somewhat larger than 4GB, we could allow other small values (such
9770 as the non-sensical values of 1, 2, and 3) to also be used as
9771 escape values indicating the presence of the old format.
9773 The value returned via bytes_read should be used to increment the
9774 relevant pointer after calling read_initial_length().
9776 [ Note: read_initial_length() and read_offset() are based on the
9777 document entitled "DWARF Debugging Information Format", revision
9778 3, draft 8, dated November 19, 2001. This document was obtained
9781 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9783 This document is only a draft and is subject to change. (So beware.)
9785 Details regarding the older, non-standard 64-bit format were
9786 determined empirically by examining 64-bit ELF files produced by
9787 the SGI toolchain on an IRIX 6.5 machine.
9789 - Kevin, July 16, 2002
9793 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9795 LONGEST length
= bfd_get_32 (abfd
, buf
);
9797 if (length
== 0xffffffff)
9799 length
= bfd_get_64 (abfd
, buf
+ 4);
9802 else if (length
== 0)
9804 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9805 length
= bfd_get_64 (abfd
, buf
);
9816 /* Cover function for read_initial_length.
9817 Returns the length of the object at BUF, and stores the size of the
9818 initial length in *BYTES_READ and stores the size that offsets will be in
9820 If the initial length size is not equivalent to that specified in
9821 CU_HEADER then issue a complaint.
9822 This is useful when reading non-comp-unit headers. */
9825 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9826 const struct comp_unit_head
*cu_header
,
9827 unsigned int *bytes_read
,
9828 unsigned int *offset_size
)
9830 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9832 gdb_assert (cu_header
->initial_length_size
== 4
9833 || cu_header
->initial_length_size
== 8
9834 || cu_header
->initial_length_size
== 12);
9836 if (cu_header
->initial_length_size
!= *bytes_read
)
9837 complaint (&symfile_complaints
,
9838 _("intermixed 32-bit and 64-bit DWARF sections"));
9840 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9844 /* Read an offset from the data stream. The size of the offset is
9845 given by cu_header->offset_size. */
9848 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9849 unsigned int *bytes_read
)
9851 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9853 *bytes_read
= cu_header
->offset_size
;
9857 /* Read an offset from the data stream. */
9860 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9864 switch (offset_size
)
9867 retval
= bfd_get_32 (abfd
, buf
);
9870 retval
= bfd_get_64 (abfd
, buf
);
9873 internal_error (__FILE__
, __LINE__
,
9874 _("read_offset_1: bad switch [in module %s]"),
9875 bfd_get_filename (abfd
));
9882 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9884 /* If the size of a host char is 8 bits, we can return a pointer
9885 to the buffer, otherwise we have to copy the data to a buffer
9886 allocated on the temporary obstack. */
9887 gdb_assert (HOST_CHAR_BIT
== 8);
9892 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9894 /* If the size of a host char is 8 bits, we can return a pointer
9895 to the string, otherwise we have to copy the string to a buffer
9896 allocated on the temporary obstack. */
9897 gdb_assert (HOST_CHAR_BIT
== 8);
9900 *bytes_read_ptr
= 1;
9903 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9904 return (char *) buf
;
9908 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9909 const struct comp_unit_head
*cu_header
,
9910 unsigned int *bytes_read_ptr
)
9912 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9914 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9915 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9917 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9918 bfd_get_filename (abfd
));
9921 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9923 error (_("DW_FORM_strp pointing outside of "
9924 ".debug_str section [in module %s]"),
9925 bfd_get_filename (abfd
));
9928 gdb_assert (HOST_CHAR_BIT
== 8);
9929 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9931 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9934 static unsigned long
9935 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9937 unsigned long result
;
9938 unsigned int num_read
;
9948 byte
= bfd_get_8 (abfd
, buf
);
9951 result
|= ((unsigned long)(byte
& 127) << shift
);
9952 if ((byte
& 128) == 0)
9958 *bytes_read_ptr
= num_read
;
9963 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9966 int i
, shift
, num_read
;
9975 byte
= bfd_get_8 (abfd
, buf
);
9978 result
|= ((long)(byte
& 127) << shift
);
9980 if ((byte
& 128) == 0)
9985 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9986 result
|= -(((long)1) << shift
);
9987 *bytes_read_ptr
= num_read
;
9991 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9994 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
10000 byte
= bfd_get_8 (abfd
, buf
);
10002 if ((byte
& 128) == 0)
10008 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
10015 cu
->language
= language_c
;
10017 case DW_LANG_C_plus_plus
:
10018 cu
->language
= language_cplus
;
10021 cu
->language
= language_d
;
10023 case DW_LANG_Fortran77
:
10024 case DW_LANG_Fortran90
:
10025 case DW_LANG_Fortran95
:
10026 cu
->language
= language_fortran
;
10028 case DW_LANG_Mips_Assembler
:
10029 cu
->language
= language_asm
;
10032 cu
->language
= language_java
;
10034 case DW_LANG_Ada83
:
10035 case DW_LANG_Ada95
:
10036 cu
->language
= language_ada
;
10038 case DW_LANG_Modula2
:
10039 cu
->language
= language_m2
;
10041 case DW_LANG_Pascal83
:
10042 cu
->language
= language_pascal
;
10045 cu
->language
= language_objc
;
10047 case DW_LANG_Cobol74
:
10048 case DW_LANG_Cobol85
:
10050 cu
->language
= language_minimal
;
10053 cu
->language_defn
= language_def (cu
->language
);
10056 /* Return the named attribute or NULL if not there. */
10058 static struct attribute
*
10059 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
10062 struct attribute
*spec
= NULL
;
10064 for (i
= 0; i
< die
->num_attrs
; ++i
)
10066 if (die
->attrs
[i
].name
== name
)
10067 return &die
->attrs
[i
];
10068 if (die
->attrs
[i
].name
== DW_AT_specification
10069 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
10070 spec
= &die
->attrs
[i
];
10075 die
= follow_die_ref (die
, spec
, &cu
);
10076 return dwarf2_attr (die
, name
, cu
);
10082 /* Return the named attribute or NULL if not there,
10083 but do not follow DW_AT_specification, etc.
10084 This is for use in contexts where we're reading .debug_types dies.
10085 Following DW_AT_specification, DW_AT_abstract_origin will take us
10086 back up the chain, and we want to go down. */
10088 static struct attribute
*
10089 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
10090 struct dwarf2_cu
*cu
)
10094 for (i
= 0; i
< die
->num_attrs
; ++i
)
10095 if (die
->attrs
[i
].name
== name
)
10096 return &die
->attrs
[i
];
10101 /* Return non-zero iff the attribute NAME is defined for the given DIE,
10102 and holds a non-zero value. This function should only be used for
10103 DW_FORM_flag or DW_FORM_flag_present attributes. */
10106 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
10108 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
10110 return (attr
&& DW_UNSND (attr
));
10114 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
10116 /* A DIE is a declaration if it has a DW_AT_declaration attribute
10117 which value is non-zero. However, we have to be careful with
10118 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
10119 (via dwarf2_flag_true_p) follows this attribute. So we may
10120 end up accidently finding a declaration attribute that belongs
10121 to a different DIE referenced by the specification attribute,
10122 even though the given DIE does not have a declaration attribute. */
10123 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
10124 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
10127 /* Return the die giving the specification for DIE, if there is
10128 one. *SPEC_CU is the CU containing DIE on input, and the CU
10129 containing the return value on output. If there is no
10130 specification, but there is an abstract origin, that is
10133 static struct die_info
*
10134 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
10136 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
10139 if (spec_attr
== NULL
)
10140 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
10142 if (spec_attr
== NULL
)
10145 return follow_die_ref (die
, spec_attr
, spec_cu
);
10148 /* Free the line_header structure *LH, and any arrays and strings it
10150 NOTE: This is also used as a "cleanup" function. */
10153 free_line_header (struct line_header
*lh
)
10155 if (lh
->standard_opcode_lengths
)
10156 xfree (lh
->standard_opcode_lengths
);
10158 /* Remember that all the lh->file_names[i].name pointers are
10159 pointers into debug_line_buffer, and don't need to be freed. */
10160 if (lh
->file_names
)
10161 xfree (lh
->file_names
);
10163 /* Similarly for the include directory names. */
10164 if (lh
->include_dirs
)
10165 xfree (lh
->include_dirs
);
10170 /* Add an entry to LH's include directory table. */
10173 add_include_dir (struct line_header
*lh
, char *include_dir
)
10175 /* Grow the array if necessary. */
10176 if (lh
->include_dirs_size
== 0)
10178 lh
->include_dirs_size
= 1; /* for testing */
10179 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
10180 * sizeof (*lh
->include_dirs
));
10182 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
10184 lh
->include_dirs_size
*= 2;
10185 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
10186 (lh
->include_dirs_size
10187 * sizeof (*lh
->include_dirs
)));
10190 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
10193 /* Add an entry to LH's file name table. */
10196 add_file_name (struct line_header
*lh
,
10198 unsigned int dir_index
,
10199 unsigned int mod_time
,
10200 unsigned int length
)
10202 struct file_entry
*fe
;
10204 /* Grow the array if necessary. */
10205 if (lh
->file_names_size
== 0)
10207 lh
->file_names_size
= 1; /* for testing */
10208 lh
->file_names
= xmalloc (lh
->file_names_size
10209 * sizeof (*lh
->file_names
));
10211 else if (lh
->num_file_names
>= lh
->file_names_size
)
10213 lh
->file_names_size
*= 2;
10214 lh
->file_names
= xrealloc (lh
->file_names
,
10215 (lh
->file_names_size
10216 * sizeof (*lh
->file_names
)));
10219 fe
= &lh
->file_names
[lh
->num_file_names
++];
10221 fe
->dir_index
= dir_index
;
10222 fe
->mod_time
= mod_time
;
10223 fe
->length
= length
;
10224 fe
->included_p
= 0;
10228 /* Read the statement program header starting at OFFSET in
10229 .debug_line, according to the endianness of ABFD. Return a pointer
10230 to a struct line_header, allocated using xmalloc.
10232 NOTE: the strings in the include directory and file name tables of
10233 the returned object point into debug_line_buffer, and must not be
10236 static struct line_header
*
10237 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
10238 struct dwarf2_cu
*cu
)
10240 struct cleanup
*back_to
;
10241 struct line_header
*lh
;
10242 gdb_byte
*line_ptr
;
10243 unsigned int bytes_read
, offset_size
;
10245 char *cur_dir
, *cur_file
;
10247 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
10248 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
10250 complaint (&symfile_complaints
, _("missing .debug_line section"));
10254 /* Make sure that at least there's room for the total_length field.
10255 That could be 12 bytes long, but we're just going to fudge that. */
10256 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
10258 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10262 lh
= xmalloc (sizeof (*lh
));
10263 memset (lh
, 0, sizeof (*lh
));
10264 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
10267 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
10269 /* Read in the header. */
10271 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
10272 &bytes_read
, &offset_size
);
10273 line_ptr
+= bytes_read
;
10274 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
10275 + dwarf2_per_objfile
->line
.size
))
10277 dwarf2_statement_list_fits_in_line_number_section_complaint ();
10280 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
10281 lh
->version
= read_2_bytes (abfd
, line_ptr
);
10283 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
10284 line_ptr
+= offset_size
;
10285 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
10287 if (lh
->version
>= 4)
10289 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
10293 lh
->maximum_ops_per_instruction
= 1;
10295 if (lh
->maximum_ops_per_instruction
== 0)
10297 lh
->maximum_ops_per_instruction
= 1;
10298 complaint (&symfile_complaints
,
10299 _("invalid maximum_ops_per_instruction "
10300 "in `.debug_line' section"));
10303 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
10305 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
10307 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
10309 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
10311 lh
->standard_opcode_lengths
10312 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
10314 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
10315 for (i
= 1; i
< lh
->opcode_base
; ++i
)
10317 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
10321 /* Read directory table. */
10322 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10324 line_ptr
+= bytes_read
;
10325 add_include_dir (lh
, cur_dir
);
10327 line_ptr
+= bytes_read
;
10329 /* Read file name table. */
10330 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
10332 unsigned int dir_index
, mod_time
, length
;
10334 line_ptr
+= bytes_read
;
10335 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10336 line_ptr
+= bytes_read
;
10337 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10338 line_ptr
+= bytes_read
;
10339 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10340 line_ptr
+= bytes_read
;
10342 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10344 line_ptr
+= bytes_read
;
10345 lh
->statement_program_start
= line_ptr
;
10347 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
10348 + dwarf2_per_objfile
->line
.size
))
10349 complaint (&symfile_complaints
,
10350 _("line number info header doesn't "
10351 "fit in `.debug_line' section"));
10353 discard_cleanups (back_to
);
10357 /* This function exists to work around a bug in certain compilers
10358 (particularly GCC 2.95), in which the first line number marker of a
10359 function does not show up until after the prologue, right before
10360 the second line number marker. This function shifts ADDRESS down
10361 to the beginning of the function if necessary, and is called on
10362 addresses passed to record_line. */
10365 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
10367 struct function_range
*fn
;
10369 /* Find the function_range containing address. */
10373 if (!cu
->cached_fn
)
10374 cu
->cached_fn
= cu
->first_fn
;
10376 fn
= cu
->cached_fn
;
10378 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10384 while (fn
&& fn
!= cu
->cached_fn
)
10385 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
10395 if (address
!= fn
->lowpc
)
10396 complaint (&symfile_complaints
,
10397 _("misplaced first line number at 0x%lx for '%s'"),
10398 (unsigned long) address
, fn
->name
);
10403 /* Subroutine of dwarf_decode_lines to simplify it.
10404 Return the file name of the psymtab for included file FILE_INDEX
10405 in line header LH of PST.
10406 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10407 If space for the result is malloc'd, it will be freed by a cleanup.
10408 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
10411 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
10412 const struct partial_symtab
*pst
,
10413 const char *comp_dir
)
10415 const struct file_entry fe
= lh
->file_names
[file_index
];
10416 char *include_name
= fe
.name
;
10417 char *include_name_to_compare
= include_name
;
10418 char *dir_name
= NULL
;
10419 const char *pst_filename
;
10420 char *copied_name
= NULL
;
10424 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
10426 if (!IS_ABSOLUTE_PATH (include_name
)
10427 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
10429 /* Avoid creating a duplicate psymtab for PST.
10430 We do this by comparing INCLUDE_NAME and PST_FILENAME.
10431 Before we do the comparison, however, we need to account
10432 for DIR_NAME and COMP_DIR.
10433 First prepend dir_name (if non-NULL). If we still don't
10434 have an absolute path prepend comp_dir (if non-NULL).
10435 However, the directory we record in the include-file's
10436 psymtab does not contain COMP_DIR (to match the
10437 corresponding symtab(s)).
10442 bash$ gcc -g ./hello.c
10443 include_name = "hello.c"
10445 DW_AT_comp_dir = comp_dir = "/tmp"
10446 DW_AT_name = "./hello.c" */
10448 if (dir_name
!= NULL
)
10450 include_name
= concat (dir_name
, SLASH_STRING
,
10451 include_name
, (char *)NULL
);
10452 include_name_to_compare
= include_name
;
10453 make_cleanup (xfree
, include_name
);
10455 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10457 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10458 include_name
, (char *)NULL
);
10462 pst_filename
= pst
->filename
;
10463 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10465 copied_name
= concat (pst
->dirname
, SLASH_STRING
,
10466 pst_filename
, (char *)NULL
);
10467 pst_filename
= copied_name
;
10470 file_is_pst
= FILENAME_CMP (include_name_to_compare
, pst_filename
) == 0;
10472 if (include_name_to_compare
!= include_name
)
10473 xfree (include_name_to_compare
);
10474 if (copied_name
!= NULL
)
10475 xfree (copied_name
);
10479 return include_name
;
10482 /* Ignore this record_line request. */
10485 noop_record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10490 /* Decode the Line Number Program (LNP) for the given line_header
10491 structure and CU. The actual information extracted and the type
10492 of structures created from the LNP depends on the value of PST.
10494 1. If PST is NULL, then this procedure uses the data from the program
10495 to create all necessary symbol tables, and their linetables.
10497 2. If PST is not NULL, this procedure reads the program to determine
10498 the list of files included by the unit represented by PST, and
10499 builds all the associated partial symbol tables.
10501 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10502 It is used for relative paths in the line table.
10503 NOTE: When processing partial symtabs (pst != NULL),
10504 comp_dir == pst->dirname.
10506 NOTE: It is important that psymtabs have the same file name (via strcmp)
10507 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10508 symtab we don't use it in the name of the psymtabs we create.
10509 E.g. expand_line_sal requires this when finding psymtabs to expand.
10510 A good testcase for this is mb-inline.exp. */
10513 dwarf_decode_lines (struct line_header
*lh
, const char *comp_dir
, bfd
*abfd
,
10514 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10516 gdb_byte
*line_ptr
, *extended_end
;
10517 gdb_byte
*line_end
;
10518 unsigned int bytes_read
, extended_len
;
10519 unsigned char op_code
, extended_op
, adj_opcode
;
10520 CORE_ADDR baseaddr
;
10521 struct objfile
*objfile
= cu
->objfile
;
10522 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10523 const int decode_for_pst_p
= (pst
!= NULL
);
10524 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10525 void (*p_record_line
) (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
10528 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10530 line_ptr
= lh
->statement_program_start
;
10531 line_end
= lh
->statement_program_end
;
10533 /* Read the statement sequences until there's nothing left. */
10534 while (line_ptr
< line_end
)
10536 /* state machine registers */
10537 CORE_ADDR address
= 0;
10538 unsigned int file
= 1;
10539 unsigned int line
= 1;
10540 unsigned int column
= 0;
10541 int is_stmt
= lh
->default_is_stmt
;
10542 int basic_block
= 0;
10543 int end_sequence
= 0;
10545 unsigned char op_index
= 0;
10547 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10549 /* Start a subfile for the current file of the state machine. */
10550 /* lh->include_dirs and lh->file_names are 0-based, but the
10551 directory and file name numbers in the statement program
10553 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10557 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10559 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10562 /* Decode the table. */
10563 while (!end_sequence
)
10565 op_code
= read_1_byte (abfd
, line_ptr
);
10567 if (line_ptr
> line_end
)
10569 dwarf2_debug_line_missing_end_sequence_complaint ();
10573 if (op_code
>= lh
->opcode_base
)
10575 /* Special operand. */
10576 adj_opcode
= op_code
- lh
->opcode_base
;
10577 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10578 / lh
->maximum_ops_per_instruction
)
10579 * lh
->minimum_instruction_length
);
10580 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10581 % lh
->maximum_ops_per_instruction
);
10582 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10583 if (lh
->num_file_names
< file
|| file
== 0)
10584 dwarf2_debug_line_missing_file_complaint ();
10585 /* For now we ignore lines not starting on an
10586 instruction boundary. */
10587 else if (op_index
== 0)
10589 lh
->file_names
[file
- 1].included_p
= 1;
10590 if (!decode_for_pst_p
&& is_stmt
)
10592 if (last_subfile
!= current_subfile
)
10594 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10596 (*p_record_line
) (last_subfile
, 0, addr
);
10597 last_subfile
= current_subfile
;
10599 /* Append row to matrix using current values. */
10600 addr
= check_cu_functions (address
, cu
);
10601 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10602 (*p_record_line
) (current_subfile
, line
, addr
);
10607 else switch (op_code
)
10609 case DW_LNS_extended_op
:
10610 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
,
10612 line_ptr
+= bytes_read
;
10613 extended_end
= line_ptr
+ extended_len
;
10614 extended_op
= read_1_byte (abfd
, line_ptr
);
10616 switch (extended_op
)
10618 case DW_LNE_end_sequence
:
10619 p_record_line
= record_line
;
10622 case DW_LNE_set_address
:
10623 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10625 if (address
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
10627 /* This line table is for a function which has been
10628 GCd by the linker. Ignore it. PR gdb/12528 */
10631 = line_ptr
- dwarf2_per_objfile
->line
.buffer
;
10633 complaint (&symfile_complaints
,
10634 _(".debug_line address at offset 0x%lx is 0 "
10636 line_offset
, cu
->objfile
->name
);
10637 p_record_line
= noop_record_line
;
10641 line_ptr
+= bytes_read
;
10642 address
+= baseaddr
;
10644 case DW_LNE_define_file
:
10647 unsigned int dir_index
, mod_time
, length
;
10649 cur_file
= read_direct_string (abfd
, line_ptr
,
10651 line_ptr
+= bytes_read
;
10653 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10654 line_ptr
+= bytes_read
;
10656 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10657 line_ptr
+= bytes_read
;
10659 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10660 line_ptr
+= bytes_read
;
10661 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10664 case DW_LNE_set_discriminator
:
10665 /* The discriminator is not interesting to the debugger;
10667 line_ptr
= extended_end
;
10670 complaint (&symfile_complaints
,
10671 _("mangled .debug_line section"));
10674 /* Make sure that we parsed the extended op correctly. If e.g.
10675 we expected a different address size than the producer used,
10676 we may have read the wrong number of bytes. */
10677 if (line_ptr
!= extended_end
)
10679 complaint (&symfile_complaints
,
10680 _("mangled .debug_line section"));
10685 if (lh
->num_file_names
< file
|| file
== 0)
10686 dwarf2_debug_line_missing_file_complaint ();
10689 lh
->file_names
[file
- 1].included_p
= 1;
10690 if (!decode_for_pst_p
&& is_stmt
)
10692 if (last_subfile
!= current_subfile
)
10694 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10696 (*p_record_line
) (last_subfile
, 0, addr
);
10697 last_subfile
= current_subfile
;
10699 addr
= check_cu_functions (address
, cu
);
10700 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10701 (*p_record_line
) (current_subfile
, line
, addr
);
10706 case DW_LNS_advance_pc
:
10709 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10711 address
+= (((op_index
+ adjust
)
10712 / lh
->maximum_ops_per_instruction
)
10713 * lh
->minimum_instruction_length
);
10714 op_index
= ((op_index
+ adjust
)
10715 % lh
->maximum_ops_per_instruction
);
10716 line_ptr
+= bytes_read
;
10719 case DW_LNS_advance_line
:
10720 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10721 line_ptr
+= bytes_read
;
10723 case DW_LNS_set_file
:
10725 /* The arrays lh->include_dirs and lh->file_names are
10726 0-based, but the directory and file name numbers in
10727 the statement program are 1-based. */
10728 struct file_entry
*fe
;
10731 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10732 line_ptr
+= bytes_read
;
10733 if (lh
->num_file_names
< file
|| file
== 0)
10734 dwarf2_debug_line_missing_file_complaint ();
10737 fe
= &lh
->file_names
[file
- 1];
10739 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10740 if (!decode_for_pst_p
)
10742 last_subfile
= current_subfile
;
10743 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10748 case DW_LNS_set_column
:
10749 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10750 line_ptr
+= bytes_read
;
10752 case DW_LNS_negate_stmt
:
10753 is_stmt
= (!is_stmt
);
10755 case DW_LNS_set_basic_block
:
10758 /* Add to the address register of the state machine the
10759 address increment value corresponding to special opcode
10760 255. I.e., this value is scaled by the minimum
10761 instruction length since special opcode 255 would have
10762 scaled the increment. */
10763 case DW_LNS_const_add_pc
:
10765 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10767 address
+= (((op_index
+ adjust
)
10768 / lh
->maximum_ops_per_instruction
)
10769 * lh
->minimum_instruction_length
);
10770 op_index
= ((op_index
+ adjust
)
10771 % lh
->maximum_ops_per_instruction
);
10774 case DW_LNS_fixed_advance_pc
:
10775 address
+= read_2_bytes (abfd
, line_ptr
);
10781 /* Unknown standard opcode, ignore it. */
10784 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10786 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10787 line_ptr
+= bytes_read
;
10792 if (lh
->num_file_names
< file
|| file
== 0)
10793 dwarf2_debug_line_missing_file_complaint ();
10796 lh
->file_names
[file
- 1].included_p
= 1;
10797 if (!decode_for_pst_p
)
10799 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10800 (*p_record_line
) (current_subfile
, 0, addr
);
10805 if (decode_for_pst_p
)
10809 /* Now that we're done scanning the Line Header Program, we can
10810 create the psymtab of each included file. */
10811 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10812 if (lh
->file_names
[file_index
].included_p
== 1)
10814 char *include_name
=
10815 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10816 if (include_name
!= NULL
)
10817 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10822 /* Make sure a symtab is created for every file, even files
10823 which contain only variables (i.e. no code with associated
10827 struct file_entry
*fe
;
10829 for (i
= 0; i
< lh
->num_file_names
; i
++)
10833 fe
= &lh
->file_names
[i
];
10835 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10836 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10838 /* Skip the main file; we don't need it, and it must be
10839 allocated last, so that it will show up before the
10840 non-primary symtabs in the objfile's symtab list. */
10841 if (current_subfile
== first_subfile
)
10844 if (current_subfile
->symtab
== NULL
)
10845 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10847 fe
->symtab
= current_subfile
->symtab
;
10852 /* Start a subfile for DWARF. FILENAME is the name of the file and
10853 DIRNAME the name of the source directory which contains FILENAME
10854 or NULL if not known. COMP_DIR is the compilation directory for the
10855 linetable's compilation unit or NULL if not known.
10856 This routine tries to keep line numbers from identical absolute and
10857 relative file names in a common subfile.
10859 Using the `list' example from the GDB testsuite, which resides in
10860 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10861 of /srcdir/list0.c yields the following debugging information for list0.c:
10863 DW_AT_name: /srcdir/list0.c
10864 DW_AT_comp_dir: /compdir
10865 files.files[0].name: list0.h
10866 files.files[0].dir: /srcdir
10867 files.files[1].name: list0.c
10868 files.files[1].dir: /srcdir
10870 The line number information for list0.c has to end up in a single
10871 subfile, so that `break /srcdir/list0.c:1' works as expected.
10872 start_subfile will ensure that this happens provided that we pass the
10873 concatenation of files.files[1].dir and files.files[1].name as the
10877 dwarf2_start_subfile (char *filename
, const char *dirname
,
10878 const char *comp_dir
)
10882 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10883 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10884 second argument to start_subfile. To be consistent, we do the
10885 same here. In order not to lose the line information directory,
10886 we concatenate it to the filename when it makes sense.
10887 Note that the Dwarf3 standard says (speaking of filenames in line
10888 information): ``The directory index is ignored for file names
10889 that represent full path names''. Thus ignoring dirname in the
10890 `else' branch below isn't an issue. */
10892 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10893 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10895 fullname
= filename
;
10897 start_subfile (fullname
, comp_dir
);
10899 if (fullname
!= filename
)
10904 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10905 struct dwarf2_cu
*cu
)
10907 struct objfile
*objfile
= cu
->objfile
;
10908 struct comp_unit_head
*cu_header
= &cu
->header
;
10910 /* NOTE drow/2003-01-30: There used to be a comment and some special
10911 code here to turn a symbol with DW_AT_external and a
10912 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10913 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10914 with some versions of binutils) where shared libraries could have
10915 relocations against symbols in their debug information - the
10916 minimal symbol would have the right address, but the debug info
10917 would not. It's no longer necessary, because we will explicitly
10918 apply relocations when we read in the debug information now. */
10920 /* A DW_AT_location attribute with no contents indicates that a
10921 variable has been optimized away. */
10922 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10924 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10928 /* Handle one degenerate form of location expression specially, to
10929 preserve GDB's previous behavior when section offsets are
10930 specified. If this is just a DW_OP_addr then mark this symbol
10933 if (attr_form_is_block (attr
)
10934 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10935 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10937 unsigned int dummy
;
10939 SYMBOL_VALUE_ADDRESS (sym
) =
10940 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10941 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10942 fixup_symbol_section (sym
, objfile
);
10943 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10944 SYMBOL_SECTION (sym
));
10948 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10949 expression evaluator, and use LOC_COMPUTED only when necessary
10950 (i.e. when the value of a register or memory location is
10951 referenced, or a thread-local block, etc.). Then again, it might
10952 not be worthwhile. I'm assuming that it isn't unless performance
10953 or memory numbers show me otherwise. */
10955 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10956 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10959 /* Given a pointer to a DWARF information entry, figure out if we need
10960 to make a symbol table entry for it, and if so, create a new entry
10961 and return a pointer to it.
10962 If TYPE is NULL, determine symbol type from the die, otherwise
10963 used the passed type.
10964 If SPACE is not NULL, use it to hold the new symbol. If it is
10965 NULL, allocate a new symbol on the objfile's obstack. */
10967 static struct symbol
*
10968 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10969 struct symbol
*space
)
10971 struct objfile
*objfile
= cu
->objfile
;
10972 struct symbol
*sym
= NULL
;
10974 struct attribute
*attr
= NULL
;
10975 struct attribute
*attr2
= NULL
;
10976 CORE_ADDR baseaddr
;
10977 struct pending
**list_to_add
= NULL
;
10979 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10981 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10983 name
= dwarf2_name (die
, cu
);
10986 const char *linkagename
;
10987 int suppress_add
= 0;
10992 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10993 OBJSTAT (objfile
, n_syms
++);
10995 /* Cache this symbol's name and the name's demangled form (if any). */
10996 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10997 linkagename
= dwarf2_physname (name
, die
, cu
);
10998 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
11000 /* Fortran does not have mangling standard and the mangling does differ
11001 between gfortran, iFort etc. */
11002 if (cu
->language
== language_fortran
11003 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
11004 symbol_set_demangled_name (&(sym
->ginfo
),
11005 (char *) dwarf2_full_name (name
, die
, cu
),
11008 /* Default assumptions.
11009 Use the passed type or decode it from the die. */
11010 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11011 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
11013 SYMBOL_TYPE (sym
) = type
;
11015 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
11016 attr
= dwarf2_attr (die
,
11017 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
11021 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
11024 attr
= dwarf2_attr (die
,
11025 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
11029 int file_index
= DW_UNSND (attr
);
11031 if (cu
->line_header
== NULL
11032 || file_index
> cu
->line_header
->num_file_names
)
11033 complaint (&symfile_complaints
,
11034 _("file index out of range"));
11035 else if (file_index
> 0)
11037 struct file_entry
*fe
;
11039 fe
= &cu
->line_header
->file_names
[file_index
- 1];
11040 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
11047 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
11050 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
11052 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
11053 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
11054 SYMBOL_CLASS (sym
) = LOC_LABEL
;
11055 add_symbol_to_list (sym
, cu
->list_in_scope
);
11057 case DW_TAG_subprogram
:
11058 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11060 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11061 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11062 if ((attr2
&& (DW_UNSND (attr2
) != 0))
11063 || cu
->language
== language_ada
)
11065 /* Subprograms marked external are stored as a global symbol.
11066 Ada subprograms, whether marked external or not, are always
11067 stored as a global symbol, because we want to be able to
11068 access them globally. For instance, we want to be able
11069 to break on a nested subprogram without having to
11070 specify the context. */
11071 list_to_add
= &global_symbols
;
11075 list_to_add
= cu
->list_in_scope
;
11078 case DW_TAG_inlined_subroutine
:
11079 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
11081 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
11082 SYMBOL_INLINED (sym
) = 1;
11083 /* Do not add the symbol to any lists. It will be found via
11084 BLOCK_FUNCTION from the blockvector. */
11086 case DW_TAG_template_value_param
:
11088 /* Fall through. */
11089 case DW_TAG_constant
:
11090 case DW_TAG_variable
:
11091 case DW_TAG_member
:
11092 /* Compilation with minimal debug info may result in
11093 variables with missing type entries. Change the
11094 misleading `void' type to something sensible. */
11095 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
11097 = objfile_type (objfile
)->nodebug_data_symbol
;
11099 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11100 /* In the case of DW_TAG_member, we should only be called for
11101 static const members. */
11102 if (die
->tag
== DW_TAG_member
)
11104 /* dwarf2_add_field uses die_is_declaration,
11105 so we do the same. */
11106 gdb_assert (die_is_declaration (die
, cu
));
11111 dwarf2_const_value (attr
, sym
, cu
);
11112 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11115 if (attr2
&& (DW_UNSND (attr2
) != 0))
11116 list_to_add
= &global_symbols
;
11118 list_to_add
= cu
->list_in_scope
;
11122 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11125 var_decode_location (attr
, sym
, cu
);
11126 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11127 if (SYMBOL_CLASS (sym
) == LOC_STATIC
11128 && SYMBOL_VALUE_ADDRESS (sym
) == 0
11129 && !dwarf2_per_objfile
->has_section_at_zero
)
11131 /* When a static variable is eliminated by the linker,
11132 the corresponding debug information is not stripped
11133 out, but the variable address is set to null;
11134 do not add such variables into symbol table. */
11136 else if (attr2
&& (DW_UNSND (attr2
) != 0))
11138 /* Workaround gfortran PR debug/40040 - it uses
11139 DW_AT_location for variables in -fPIC libraries which may
11140 get overriden by other libraries/executable and get
11141 a different address. Resolve it by the minimal symbol
11142 which may come from inferior's executable using copy
11143 relocation. Make this workaround only for gfortran as for
11144 other compilers GDB cannot guess the minimal symbol
11145 Fortran mangling kind. */
11146 if (cu
->language
== language_fortran
&& die
->parent
11147 && die
->parent
->tag
== DW_TAG_module
11149 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
11150 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11152 /* A variable with DW_AT_external is never static,
11153 but it may be block-scoped. */
11154 list_to_add
= (cu
->list_in_scope
== &file_symbols
11155 ? &global_symbols
: cu
->list_in_scope
);
11158 list_to_add
= cu
->list_in_scope
;
11162 /* We do not know the address of this symbol.
11163 If it is an external symbol and we have type information
11164 for it, enter the symbol as a LOC_UNRESOLVED symbol.
11165 The address of the variable will then be determined from
11166 the minimal symbol table whenever the variable is
11168 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
11169 if (attr2
&& (DW_UNSND (attr2
) != 0)
11170 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
11172 /* A variable with DW_AT_external is never static, but it
11173 may be block-scoped. */
11174 list_to_add
= (cu
->list_in_scope
== &file_symbols
11175 ? &global_symbols
: cu
->list_in_scope
);
11177 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
11179 else if (!die_is_declaration (die
, cu
))
11181 /* Use the default LOC_OPTIMIZED_OUT class. */
11182 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
11184 list_to_add
= cu
->list_in_scope
;
11188 case DW_TAG_formal_parameter
:
11189 /* If we are inside a function, mark this as an argument. If
11190 not, we might be looking at an argument to an inlined function
11191 when we do not have enough information to show inlined frames;
11192 pretend it's a local variable in that case so that the user can
11194 if (context_stack_depth
> 0
11195 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
11196 SYMBOL_IS_ARGUMENT (sym
) = 1;
11197 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11200 var_decode_location (attr
, sym
, cu
);
11202 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11205 dwarf2_const_value (attr
, sym
, cu
);
11207 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
11208 if (attr
&& DW_UNSND (attr
))
11210 struct type
*ref_type
;
11212 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
11213 SYMBOL_TYPE (sym
) = ref_type
;
11216 list_to_add
= cu
->list_in_scope
;
11218 case DW_TAG_unspecified_parameters
:
11219 /* From varargs functions; gdb doesn't seem to have any
11220 interest in this information, so just ignore it for now.
11223 case DW_TAG_template_type_param
:
11225 /* Fall through. */
11226 case DW_TAG_class_type
:
11227 case DW_TAG_interface_type
:
11228 case DW_TAG_structure_type
:
11229 case DW_TAG_union_type
:
11230 case DW_TAG_set_type
:
11231 case DW_TAG_enumeration_type
:
11232 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11233 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
11236 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
11237 really ever be static objects: otherwise, if you try
11238 to, say, break of a class's method and you're in a file
11239 which doesn't mention that class, it won't work unless
11240 the check for all static symbols in lookup_symbol_aux
11241 saves you. See the OtherFileClass tests in
11242 gdb.c++/namespace.exp. */
11246 list_to_add
= (cu
->list_in_scope
== &file_symbols
11247 && (cu
->language
== language_cplus
11248 || cu
->language
== language_java
)
11249 ? &global_symbols
: cu
->list_in_scope
);
11251 /* The semantics of C++ state that "struct foo {
11252 ... }" also defines a typedef for "foo". A Java
11253 class declaration also defines a typedef for the
11255 if (cu
->language
== language_cplus
11256 || cu
->language
== language_java
11257 || cu
->language
== language_ada
)
11259 /* The symbol's name is already allocated along
11260 with this objfile, so we don't need to
11261 duplicate it for the type. */
11262 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
11263 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
11268 case DW_TAG_typedef
:
11269 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11270 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11271 list_to_add
= cu
->list_in_scope
;
11273 case DW_TAG_base_type
:
11274 case DW_TAG_subrange_type
:
11275 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11276 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
11277 list_to_add
= cu
->list_in_scope
;
11279 case DW_TAG_enumerator
:
11280 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
11283 dwarf2_const_value (attr
, sym
, cu
);
11286 /* NOTE: carlton/2003-11-10: See comment above in the
11287 DW_TAG_class_type, etc. block. */
11289 list_to_add
= (cu
->list_in_scope
== &file_symbols
11290 && (cu
->language
== language_cplus
11291 || cu
->language
== language_java
)
11292 ? &global_symbols
: cu
->list_in_scope
);
11295 case DW_TAG_namespace
:
11296 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
11297 list_to_add
= &global_symbols
;
11300 /* Not a tag we recognize. Hopefully we aren't processing
11301 trash data, but since we must specifically ignore things
11302 we don't recognize, there is nothing else we should do at
11304 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
11305 dwarf_tag_name (die
->tag
));
11311 sym
->hash_next
= objfile
->template_symbols
;
11312 objfile
->template_symbols
= sym
;
11313 list_to_add
= NULL
;
11316 if (list_to_add
!= NULL
)
11317 add_symbol_to_list (sym
, list_to_add
);
11319 /* For the benefit of old versions of GCC, check for anonymous
11320 namespaces based on the demangled name. */
11321 if (!processing_has_namespace_info
11322 && cu
->language
== language_cplus
)
11323 cp_scan_for_anonymous_namespaces (sym
);
11328 /* A wrapper for new_symbol_full that always allocates a new symbol. */
11330 static struct symbol
*
11331 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11333 return new_symbol_full (die
, type
, cu
, NULL
);
11336 /* Given an attr with a DW_FORM_dataN value in host byte order,
11337 zero-extend it as appropriate for the symbol's type. The DWARF
11338 standard (v4) is not entirely clear about the meaning of using
11339 DW_FORM_dataN for a constant with a signed type, where the type is
11340 wider than the data. The conclusion of a discussion on the DWARF
11341 list was that this is unspecified. We choose to always zero-extend
11342 because that is the interpretation long in use by GCC. */
11345 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
11346 const char *name
, struct obstack
*obstack
,
11347 struct dwarf2_cu
*cu
, long *value
, int bits
)
11349 struct objfile
*objfile
= cu
->objfile
;
11350 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
11351 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
11352 LONGEST l
= DW_UNSND (attr
);
11354 if (bits
< sizeof (*value
) * 8)
11356 l
&= ((LONGEST
) 1 << bits
) - 1;
11359 else if (bits
== sizeof (*value
) * 8)
11363 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
11364 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
11371 /* Read a constant value from an attribute. Either set *VALUE, or if
11372 the value does not fit in *VALUE, set *BYTES - either already
11373 allocated on the objfile obstack, or newly allocated on OBSTACK,
11374 or, set *BATON, if we translated the constant to a location
11378 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
11379 const char *name
, struct obstack
*obstack
,
11380 struct dwarf2_cu
*cu
,
11381 long *value
, gdb_byte
**bytes
,
11382 struct dwarf2_locexpr_baton
**baton
)
11384 struct objfile
*objfile
= cu
->objfile
;
11385 struct comp_unit_head
*cu_header
= &cu
->header
;
11386 struct dwarf_block
*blk
;
11387 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
11388 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
11394 switch (attr
->form
)
11400 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
11401 dwarf2_const_value_length_mismatch_complaint (name
,
11402 cu_header
->addr_size
,
11403 TYPE_LENGTH (type
));
11404 /* Symbols of this form are reasonably rare, so we just
11405 piggyback on the existing location code rather than writing
11406 a new implementation of symbol_computed_ops. */
11407 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
11408 sizeof (struct dwarf2_locexpr_baton
));
11409 (*baton
)->per_cu
= cu
->per_cu
;
11410 gdb_assert ((*baton
)->per_cu
);
11412 (*baton
)->size
= 2 + cu_header
->addr_size
;
11413 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
11414 (*baton
)->data
= data
;
11416 data
[0] = DW_OP_addr
;
11417 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
11418 byte_order
, DW_ADDR (attr
));
11419 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
11422 case DW_FORM_string
:
11424 /* DW_STRING is already allocated on the objfile obstack, point
11426 *bytes
= (gdb_byte
*) DW_STRING (attr
);
11428 case DW_FORM_block1
:
11429 case DW_FORM_block2
:
11430 case DW_FORM_block4
:
11431 case DW_FORM_block
:
11432 case DW_FORM_exprloc
:
11433 blk
= DW_BLOCK (attr
);
11434 if (TYPE_LENGTH (type
) != blk
->size
)
11435 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
11436 TYPE_LENGTH (type
));
11437 *bytes
= blk
->data
;
11440 /* The DW_AT_const_value attributes are supposed to carry the
11441 symbol's value "represented as it would be on the target
11442 architecture." By the time we get here, it's already been
11443 converted to host endianness, so we just need to sign- or
11444 zero-extend it as appropriate. */
11445 case DW_FORM_data1
:
11446 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11447 obstack
, cu
, value
, 8);
11449 case DW_FORM_data2
:
11450 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11451 obstack
, cu
, value
, 16);
11453 case DW_FORM_data4
:
11454 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11455 obstack
, cu
, value
, 32);
11457 case DW_FORM_data8
:
11458 *bytes
= dwarf2_const_value_data (attr
, type
, name
,
11459 obstack
, cu
, value
, 64);
11462 case DW_FORM_sdata
:
11463 *value
= DW_SND (attr
);
11466 case DW_FORM_udata
:
11467 *value
= DW_UNSND (attr
);
11471 complaint (&symfile_complaints
,
11472 _("unsupported const value attribute form: '%s'"),
11473 dwarf_form_name (attr
->form
));
11480 /* Copy constant value from an attribute to a symbol. */
11483 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
11484 struct dwarf2_cu
*cu
)
11486 struct objfile
*objfile
= cu
->objfile
;
11487 struct comp_unit_head
*cu_header
= &cu
->header
;
11490 struct dwarf2_locexpr_baton
*baton
;
11492 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11493 SYMBOL_PRINT_NAME (sym
),
11494 &objfile
->objfile_obstack
, cu
,
11495 &value
, &bytes
, &baton
);
11499 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11500 SYMBOL_LOCATION_BATON (sym
) = baton
;
11501 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11503 else if (bytes
!= NULL
)
11505 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11506 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11510 SYMBOL_VALUE (sym
) = value
;
11511 SYMBOL_CLASS (sym
) = LOC_CONST
;
11515 /* Return the type of the die in question using its DW_AT_type attribute. */
11517 static struct type
*
11518 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11520 struct attribute
*type_attr
;
11522 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11525 /* A missing DW_AT_type represents a void type. */
11526 return objfile_type (cu
->objfile
)->builtin_void
;
11529 return lookup_die_type (die
, type_attr
, cu
);
11532 /* True iff CU's producer generates GNAT Ada auxiliary information
11533 that allows to find parallel types through that information instead
11534 of having to do expensive parallel lookups by type name. */
11537 need_gnat_info (struct dwarf2_cu
*cu
)
11539 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11540 of GNAT produces this auxiliary information, without any indication
11541 that it is produced. Part of enhancing the FSF version of GNAT
11542 to produce that information will be to put in place an indicator
11543 that we can use in order to determine whether the descriptive type
11544 info is available or not. One suggestion that has been made is
11545 to use a new attribute, attached to the CU die. For now, assume
11546 that the descriptive type info is not available. */
11550 /* Return the auxiliary type of the die in question using its
11551 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11552 attribute is not present. */
11554 static struct type
*
11555 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11557 struct attribute
*type_attr
;
11559 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11563 return lookup_die_type (die
, type_attr
, cu
);
11566 /* If DIE has a descriptive_type attribute, then set the TYPE's
11567 descriptive type accordingly. */
11570 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11571 struct dwarf2_cu
*cu
)
11573 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11575 if (descriptive_type
)
11577 ALLOCATE_GNAT_AUX_TYPE (type
);
11578 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11582 /* Return the containing type of the die in question using its
11583 DW_AT_containing_type attribute. */
11585 static struct type
*
11586 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11588 struct attribute
*type_attr
;
11590 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11592 error (_("Dwarf Error: Problem turning containing type into gdb type "
11593 "[in module %s]"), cu
->objfile
->name
);
11595 return lookup_die_type (die
, type_attr
, cu
);
11598 /* Look up the type of DIE in CU using its type attribute ATTR.
11599 If there is no type substitute an error marker. */
11601 static struct type
*
11602 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11603 struct dwarf2_cu
*cu
)
11605 struct type
*this_type
;
11607 /* First see if we have it cached. */
11609 if (is_ref_attr (attr
))
11611 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11613 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11615 else if (attr
->form
== DW_FORM_ref_sig8
)
11617 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11618 struct dwarf2_cu
*sig_cu
;
11619 unsigned int offset
;
11621 /* sig_type will be NULL if the signatured type is missing from
11623 if (sig_type
== NULL
)
11624 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11625 "at 0x%x [in module %s]"),
11626 die
->offset
, cu
->objfile
->name
);
11628 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11629 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11630 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11634 dump_die_for_error (die
);
11635 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11636 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11639 /* If not cached we need to read it in. */
11641 if (this_type
== NULL
)
11643 struct die_info
*type_die
;
11644 struct dwarf2_cu
*type_cu
= cu
;
11646 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11647 /* If the type is cached, we should have found it above. */
11648 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11649 this_type
= read_type_die_1 (type_die
, type_cu
);
11652 /* If we still don't have a type use an error marker. */
11654 if (this_type
== NULL
)
11656 char *message
, *saved
;
11658 /* read_type_die already issued a complaint. */
11659 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11663 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11664 message
, strlen (message
));
11667 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11673 /* Return the type in DIE, CU.
11674 Returns NULL for invalid types.
11676 This first does a lookup in the appropriate type_hash table,
11677 and only reads the die in if necessary.
11679 NOTE: This can be called when reading in partial or full symbols. */
11681 static struct type
*
11682 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11684 struct type
*this_type
;
11686 this_type
= get_die_type (die
, cu
);
11690 return read_type_die_1 (die
, cu
);
11693 /* Read the type in DIE, CU.
11694 Returns NULL for invalid types. */
11696 static struct type
*
11697 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11699 struct type
*this_type
= NULL
;
11703 case DW_TAG_class_type
:
11704 case DW_TAG_interface_type
:
11705 case DW_TAG_structure_type
:
11706 case DW_TAG_union_type
:
11707 this_type
= read_structure_type (die
, cu
);
11709 case DW_TAG_enumeration_type
:
11710 this_type
= read_enumeration_type (die
, cu
);
11712 case DW_TAG_subprogram
:
11713 case DW_TAG_subroutine_type
:
11714 case DW_TAG_inlined_subroutine
:
11715 this_type
= read_subroutine_type (die
, cu
);
11717 case DW_TAG_array_type
:
11718 this_type
= read_array_type (die
, cu
);
11720 case DW_TAG_set_type
:
11721 this_type
= read_set_type (die
, cu
);
11723 case DW_TAG_pointer_type
:
11724 this_type
= read_tag_pointer_type (die
, cu
);
11726 case DW_TAG_ptr_to_member_type
:
11727 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11729 case DW_TAG_reference_type
:
11730 this_type
= read_tag_reference_type (die
, cu
);
11732 case DW_TAG_const_type
:
11733 this_type
= read_tag_const_type (die
, cu
);
11735 case DW_TAG_volatile_type
:
11736 this_type
= read_tag_volatile_type (die
, cu
);
11738 case DW_TAG_string_type
:
11739 this_type
= read_tag_string_type (die
, cu
);
11741 case DW_TAG_typedef
:
11742 this_type
= read_typedef (die
, cu
);
11744 case DW_TAG_subrange_type
:
11745 this_type
= read_subrange_type (die
, cu
);
11747 case DW_TAG_base_type
:
11748 this_type
= read_base_type (die
, cu
);
11750 case DW_TAG_unspecified_type
:
11751 this_type
= read_unspecified_type (die
, cu
);
11753 case DW_TAG_namespace
:
11754 this_type
= read_namespace_type (die
, cu
);
11756 case DW_TAG_module
:
11757 this_type
= read_module_type (die
, cu
);
11760 complaint (&symfile_complaints
,
11761 _("unexpected tag in read_type_die: '%s'"),
11762 dwarf_tag_name (die
->tag
));
11769 /* See if we can figure out if the class lives in a namespace. We do
11770 this by looking for a member function; its demangled name will
11771 contain namespace info, if there is any.
11772 Return the computed name or NULL.
11773 Space for the result is allocated on the objfile's obstack.
11774 This is the full-die version of guess_partial_die_structure_name.
11775 In this case we know DIE has no useful parent. */
11778 guess_full_die_structure_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11780 struct die_info
*spec_die
;
11781 struct dwarf2_cu
*spec_cu
;
11782 struct die_info
*child
;
11785 spec_die
= die_specification (die
, &spec_cu
);
11786 if (spec_die
!= NULL
)
11792 for (child
= die
->child
;
11794 child
= child
->sibling
)
11796 if (child
->tag
== DW_TAG_subprogram
)
11798 struct attribute
*attr
;
11800 attr
= dwarf2_attr (child
, DW_AT_linkage_name
, cu
);
11802 attr
= dwarf2_attr (child
, DW_AT_MIPS_linkage_name
, cu
);
11806 = language_class_name_from_physname (cu
->language_defn
,
11810 if (actual_name
!= NULL
)
11812 char *die_name
= dwarf2_name (die
, cu
);
11814 if (die_name
!= NULL
11815 && strcmp (die_name
, actual_name
) != 0)
11817 /* Strip off the class name from the full name.
11818 We want the prefix. */
11819 int die_name_len
= strlen (die_name
);
11820 int actual_name_len
= strlen (actual_name
);
11822 /* Test for '::' as a sanity check. */
11823 if (actual_name_len
> die_name_len
+ 2
11824 && actual_name
[actual_name_len
11825 - die_name_len
- 1] == ':')
11827 obsavestring (actual_name
,
11828 actual_name_len
- die_name_len
- 2,
11829 &cu
->objfile
->objfile_obstack
);
11832 xfree (actual_name
);
11841 /* Return the name of the namespace/class that DIE is defined within,
11842 or "" if we can't tell. The caller should not xfree the result.
11844 For example, if we're within the method foo() in the following
11854 then determine_prefix on foo's die will return "N::C". */
11857 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11859 struct die_info
*parent
, *spec_die
;
11860 struct dwarf2_cu
*spec_cu
;
11861 struct type
*parent_type
;
11863 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11864 && cu
->language
!= language_fortran
)
11867 /* We have to be careful in the presence of DW_AT_specification.
11868 For example, with GCC 3.4, given the code
11872 // Definition of N::foo.
11876 then we'll have a tree of DIEs like this:
11878 1: DW_TAG_compile_unit
11879 2: DW_TAG_namespace // N
11880 3: DW_TAG_subprogram // declaration of N::foo
11881 4: DW_TAG_subprogram // definition of N::foo
11882 DW_AT_specification // refers to die #3
11884 Thus, when processing die #4, we have to pretend that we're in
11885 the context of its DW_AT_specification, namely the contex of die
11888 spec_die
= die_specification (die
, &spec_cu
);
11889 if (spec_die
== NULL
)
11890 parent
= die
->parent
;
11893 parent
= spec_die
->parent
;
11897 if (parent
== NULL
)
11899 else if (parent
->building_fullname
)
11902 const char *parent_name
;
11904 /* It has been seen on RealView 2.2 built binaries,
11905 DW_TAG_template_type_param types actually _defined_ as
11906 children of the parent class:
11909 template class <class Enum> Class{};
11910 Class<enum E> class_e;
11912 1: DW_TAG_class_type (Class)
11913 2: DW_TAG_enumeration_type (E)
11914 3: DW_TAG_enumerator (enum1:0)
11915 3: DW_TAG_enumerator (enum2:1)
11917 2: DW_TAG_template_type_param
11918 DW_AT_type DW_FORM_ref_udata (E)
11920 Besides being broken debug info, it can put GDB into an
11921 infinite loop. Consider:
11923 When we're building the full name for Class<E>, we'll start
11924 at Class, and go look over its template type parameters,
11925 finding E. We'll then try to build the full name of E, and
11926 reach here. We're now trying to build the full name of E,
11927 and look over the parent DIE for containing scope. In the
11928 broken case, if we followed the parent DIE of E, we'd again
11929 find Class, and once again go look at its template type
11930 arguments, etc., etc. Simply don't consider such parent die
11931 as source-level parent of this die (it can't be, the language
11932 doesn't allow it), and break the loop here. */
11933 name
= dwarf2_name (die
, cu
);
11934 parent_name
= dwarf2_name (parent
, cu
);
11935 complaint (&symfile_complaints
,
11936 _("template param type '%s' defined within parent '%s'"),
11937 name
? name
: "<unknown>",
11938 parent_name
? parent_name
: "<unknown>");
11942 switch (parent
->tag
)
11944 case DW_TAG_namespace
:
11945 parent_type
= read_type_die (parent
, cu
);
11946 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11947 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11948 Work around this problem here. */
11949 if (cu
->language
== language_cplus
11950 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11952 /* We give a name to even anonymous namespaces. */
11953 return TYPE_TAG_NAME (parent_type
);
11954 case DW_TAG_class_type
:
11955 case DW_TAG_interface_type
:
11956 case DW_TAG_structure_type
:
11957 case DW_TAG_union_type
:
11958 case DW_TAG_module
:
11959 parent_type
= read_type_die (parent
, cu
);
11960 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11961 return TYPE_TAG_NAME (parent_type
);
11963 /* An anonymous structure is only allowed non-static data
11964 members; no typedefs, no member functions, et cetera.
11965 So it does not need a prefix. */
11967 case DW_TAG_compile_unit
:
11968 /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */
11969 if (cu
->language
== language_cplus
11970 && dwarf2_per_objfile
->types
.asection
!= NULL
11971 && die
->child
!= NULL
11972 && (die
->tag
== DW_TAG_class_type
11973 || die
->tag
== DW_TAG_structure_type
11974 || die
->tag
== DW_TAG_union_type
))
11976 char *name
= guess_full_die_structure_name (die
, cu
);
11982 return determine_prefix (parent
, cu
);
11986 /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX
11987 with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11988 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform
11989 an obconcat, otherwise allocate storage for the result. The CU argument is
11990 used to determine the language and hence, the appropriate separator. */
11992 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11995 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11996 int physname
, struct dwarf2_cu
*cu
)
11998 const char *lead
= "";
12001 if (suffix
== NULL
|| suffix
[0] == '\0'
12002 || prefix
== NULL
|| prefix
[0] == '\0')
12004 else if (cu
->language
== language_java
)
12006 else if (cu
->language
== language_fortran
&& physname
)
12008 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
12009 DW_AT_MIPS_linkage_name is preferred and used instead. */
12017 if (prefix
== NULL
)
12019 if (suffix
== NULL
)
12025 = xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
12027 strcpy (retval
, lead
);
12028 strcat (retval
, prefix
);
12029 strcat (retval
, sep
);
12030 strcat (retval
, suffix
);
12035 /* We have an obstack. */
12036 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
12040 /* Return sibling of die, NULL if no sibling. */
12042 static struct die_info
*
12043 sibling_die (struct die_info
*die
)
12045 return die
->sibling
;
12048 /* Get name of a die, return NULL if not found. */
12051 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
12052 struct obstack
*obstack
)
12054 if (name
&& cu
->language
== language_cplus
)
12056 char *canon_name
= cp_canonicalize_string (name
);
12058 if (canon_name
!= NULL
)
12060 if (strcmp (canon_name
, name
) != 0)
12061 name
= obsavestring (canon_name
, strlen (canon_name
),
12063 xfree (canon_name
);
12070 /* Get name of a die, return NULL if not found. */
12073 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
12075 struct attribute
*attr
;
12077 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
12078 if ((!attr
|| !DW_STRING (attr
))
12079 && die
->tag
!= DW_TAG_class_type
12080 && die
->tag
!= DW_TAG_interface_type
12081 && die
->tag
!= DW_TAG_structure_type
12082 && die
->tag
!= DW_TAG_union_type
)
12087 case DW_TAG_compile_unit
:
12088 /* Compilation units have a DW_AT_name that is a filename, not
12089 a source language identifier. */
12090 case DW_TAG_enumeration_type
:
12091 case DW_TAG_enumerator
:
12092 /* These tags always have simple identifiers already; no need
12093 to canonicalize them. */
12094 return DW_STRING (attr
);
12096 case DW_TAG_subprogram
:
12097 /* Java constructors will all be named "<init>", so return
12098 the class name when we see this special case. */
12099 if (cu
->language
== language_java
12100 && DW_STRING (attr
) != NULL
12101 && strcmp (DW_STRING (attr
), "<init>") == 0)
12103 struct dwarf2_cu
*spec_cu
= cu
;
12104 struct die_info
*spec_die
;
12106 /* GCJ will output '<init>' for Java constructor names.
12107 For this special case, return the name of the parent class. */
12109 /* GCJ may output suprogram DIEs with AT_specification set.
12110 If so, use the name of the specified DIE. */
12111 spec_die
= die_specification (die
, &spec_cu
);
12112 if (spec_die
!= NULL
)
12113 return dwarf2_name (spec_die
, spec_cu
);
12118 if (die
->tag
== DW_TAG_class_type
)
12119 return dwarf2_name (die
, cu
);
12121 while (die
->tag
!= DW_TAG_compile_unit
);
12125 case DW_TAG_class_type
:
12126 case DW_TAG_interface_type
:
12127 case DW_TAG_structure_type
:
12128 case DW_TAG_union_type
:
12129 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
12130 structures or unions. These were of the form "._%d" in GCC 4.1,
12131 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
12132 and GCC 4.4. We work around this problem by ignoring these. */
12133 if (attr
&& DW_STRING (attr
)
12134 && (strncmp (DW_STRING (attr
), "._", 2) == 0
12135 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0))
12138 /* GCC might emit a nameless typedef that has a linkage name. See
12139 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */
12140 if (!attr
|| DW_STRING (attr
) == NULL
)
12142 char *demangled
= NULL
;
12144 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
12146 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
12148 if (attr
== NULL
|| DW_STRING (attr
) == NULL
)
12151 /* Avoid demangling DW_STRING (attr) the second time on a second
12152 call for the same DIE. */
12153 if (!DW_STRING_IS_CANONICAL (attr
))
12154 demangled
= cplus_demangle (DW_STRING (attr
), DMGL_TYPES
);
12158 /* FIXME: we already did this for the partial symbol... */
12160 = obsavestring (demangled
, strlen (demangled
),
12161 &cu
->objfile
->objfile_obstack
);
12162 DW_STRING_IS_CANONICAL (attr
) = 1;
12172 if (!DW_STRING_IS_CANONICAL (attr
))
12175 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
12176 &cu
->objfile
->objfile_obstack
);
12177 DW_STRING_IS_CANONICAL (attr
) = 1;
12179 return DW_STRING (attr
);
12182 /* Return the die that this die in an extension of, or NULL if there
12183 is none. *EXT_CU is the CU containing DIE on input, and the CU
12184 containing the return value on output. */
12186 static struct die_info
*
12187 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
12189 struct attribute
*attr
;
12191 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
12195 return follow_die_ref (die
, attr
, ext_cu
);
12198 /* Convert a DIE tag into its string name. */
12201 dwarf_tag_name (unsigned tag
)
12205 case DW_TAG_padding
:
12206 return "DW_TAG_padding";
12207 case DW_TAG_array_type
:
12208 return "DW_TAG_array_type";
12209 case DW_TAG_class_type
:
12210 return "DW_TAG_class_type";
12211 case DW_TAG_entry_point
:
12212 return "DW_TAG_entry_point";
12213 case DW_TAG_enumeration_type
:
12214 return "DW_TAG_enumeration_type";
12215 case DW_TAG_formal_parameter
:
12216 return "DW_TAG_formal_parameter";
12217 case DW_TAG_imported_declaration
:
12218 return "DW_TAG_imported_declaration";
12220 return "DW_TAG_label";
12221 case DW_TAG_lexical_block
:
12222 return "DW_TAG_lexical_block";
12223 case DW_TAG_member
:
12224 return "DW_TAG_member";
12225 case DW_TAG_pointer_type
:
12226 return "DW_TAG_pointer_type";
12227 case DW_TAG_reference_type
:
12228 return "DW_TAG_reference_type";
12229 case DW_TAG_compile_unit
:
12230 return "DW_TAG_compile_unit";
12231 case DW_TAG_string_type
:
12232 return "DW_TAG_string_type";
12233 case DW_TAG_structure_type
:
12234 return "DW_TAG_structure_type";
12235 case DW_TAG_subroutine_type
:
12236 return "DW_TAG_subroutine_type";
12237 case DW_TAG_typedef
:
12238 return "DW_TAG_typedef";
12239 case DW_TAG_union_type
:
12240 return "DW_TAG_union_type";
12241 case DW_TAG_unspecified_parameters
:
12242 return "DW_TAG_unspecified_parameters";
12243 case DW_TAG_variant
:
12244 return "DW_TAG_variant";
12245 case DW_TAG_common_block
:
12246 return "DW_TAG_common_block";
12247 case DW_TAG_common_inclusion
:
12248 return "DW_TAG_common_inclusion";
12249 case DW_TAG_inheritance
:
12250 return "DW_TAG_inheritance";
12251 case DW_TAG_inlined_subroutine
:
12252 return "DW_TAG_inlined_subroutine";
12253 case DW_TAG_module
:
12254 return "DW_TAG_module";
12255 case DW_TAG_ptr_to_member_type
:
12256 return "DW_TAG_ptr_to_member_type";
12257 case DW_TAG_set_type
:
12258 return "DW_TAG_set_type";
12259 case DW_TAG_subrange_type
:
12260 return "DW_TAG_subrange_type";
12261 case DW_TAG_with_stmt
:
12262 return "DW_TAG_with_stmt";
12263 case DW_TAG_access_declaration
:
12264 return "DW_TAG_access_declaration";
12265 case DW_TAG_base_type
:
12266 return "DW_TAG_base_type";
12267 case DW_TAG_catch_block
:
12268 return "DW_TAG_catch_block";
12269 case DW_TAG_const_type
:
12270 return "DW_TAG_const_type";
12271 case DW_TAG_constant
:
12272 return "DW_TAG_constant";
12273 case DW_TAG_enumerator
:
12274 return "DW_TAG_enumerator";
12275 case DW_TAG_file_type
:
12276 return "DW_TAG_file_type";
12277 case DW_TAG_friend
:
12278 return "DW_TAG_friend";
12279 case DW_TAG_namelist
:
12280 return "DW_TAG_namelist";
12281 case DW_TAG_namelist_item
:
12282 return "DW_TAG_namelist_item";
12283 case DW_TAG_packed_type
:
12284 return "DW_TAG_packed_type";
12285 case DW_TAG_subprogram
:
12286 return "DW_TAG_subprogram";
12287 case DW_TAG_template_type_param
:
12288 return "DW_TAG_template_type_param";
12289 case DW_TAG_template_value_param
:
12290 return "DW_TAG_template_value_param";
12291 case DW_TAG_thrown_type
:
12292 return "DW_TAG_thrown_type";
12293 case DW_TAG_try_block
:
12294 return "DW_TAG_try_block";
12295 case DW_TAG_variant_part
:
12296 return "DW_TAG_variant_part";
12297 case DW_TAG_variable
:
12298 return "DW_TAG_variable";
12299 case DW_TAG_volatile_type
:
12300 return "DW_TAG_volatile_type";
12301 case DW_TAG_dwarf_procedure
:
12302 return "DW_TAG_dwarf_procedure";
12303 case DW_TAG_restrict_type
:
12304 return "DW_TAG_restrict_type";
12305 case DW_TAG_interface_type
:
12306 return "DW_TAG_interface_type";
12307 case DW_TAG_namespace
:
12308 return "DW_TAG_namespace";
12309 case DW_TAG_imported_module
:
12310 return "DW_TAG_imported_module";
12311 case DW_TAG_unspecified_type
:
12312 return "DW_TAG_unspecified_type";
12313 case DW_TAG_partial_unit
:
12314 return "DW_TAG_partial_unit";
12315 case DW_TAG_imported_unit
:
12316 return "DW_TAG_imported_unit";
12317 case DW_TAG_condition
:
12318 return "DW_TAG_condition";
12319 case DW_TAG_shared_type
:
12320 return "DW_TAG_shared_type";
12321 case DW_TAG_type_unit
:
12322 return "DW_TAG_type_unit";
12323 case DW_TAG_MIPS_loop
:
12324 return "DW_TAG_MIPS_loop";
12325 case DW_TAG_HP_array_descriptor
:
12326 return "DW_TAG_HP_array_descriptor";
12327 case DW_TAG_format_label
:
12328 return "DW_TAG_format_label";
12329 case DW_TAG_function_template
:
12330 return "DW_TAG_function_template";
12331 case DW_TAG_class_template
:
12332 return "DW_TAG_class_template";
12333 case DW_TAG_GNU_BINCL
:
12334 return "DW_TAG_GNU_BINCL";
12335 case DW_TAG_GNU_EINCL
:
12336 return "DW_TAG_GNU_EINCL";
12337 case DW_TAG_upc_shared_type
:
12338 return "DW_TAG_upc_shared_type";
12339 case DW_TAG_upc_strict_type
:
12340 return "DW_TAG_upc_strict_type";
12341 case DW_TAG_upc_relaxed_type
:
12342 return "DW_TAG_upc_relaxed_type";
12343 case DW_TAG_PGI_kanji_type
:
12344 return "DW_TAG_PGI_kanji_type";
12345 case DW_TAG_PGI_interface_block
:
12346 return "DW_TAG_PGI_interface_block";
12348 return "DW_TAG_<unknown>";
12352 /* Convert a DWARF attribute code into its string name. */
12355 dwarf_attr_name (unsigned attr
)
12359 case DW_AT_sibling
:
12360 return "DW_AT_sibling";
12361 case DW_AT_location
:
12362 return "DW_AT_location";
12364 return "DW_AT_name";
12365 case DW_AT_ordering
:
12366 return "DW_AT_ordering";
12367 case DW_AT_subscr_data
:
12368 return "DW_AT_subscr_data";
12369 case DW_AT_byte_size
:
12370 return "DW_AT_byte_size";
12371 case DW_AT_bit_offset
:
12372 return "DW_AT_bit_offset";
12373 case DW_AT_bit_size
:
12374 return "DW_AT_bit_size";
12375 case DW_AT_element_list
:
12376 return "DW_AT_element_list";
12377 case DW_AT_stmt_list
:
12378 return "DW_AT_stmt_list";
12380 return "DW_AT_low_pc";
12381 case DW_AT_high_pc
:
12382 return "DW_AT_high_pc";
12383 case DW_AT_language
:
12384 return "DW_AT_language";
12386 return "DW_AT_member";
12388 return "DW_AT_discr";
12389 case DW_AT_discr_value
:
12390 return "DW_AT_discr_value";
12391 case DW_AT_visibility
:
12392 return "DW_AT_visibility";
12394 return "DW_AT_import";
12395 case DW_AT_string_length
:
12396 return "DW_AT_string_length";
12397 case DW_AT_common_reference
:
12398 return "DW_AT_common_reference";
12399 case DW_AT_comp_dir
:
12400 return "DW_AT_comp_dir";
12401 case DW_AT_const_value
:
12402 return "DW_AT_const_value";
12403 case DW_AT_containing_type
:
12404 return "DW_AT_containing_type";
12405 case DW_AT_default_value
:
12406 return "DW_AT_default_value";
12408 return "DW_AT_inline";
12409 case DW_AT_is_optional
:
12410 return "DW_AT_is_optional";
12411 case DW_AT_lower_bound
:
12412 return "DW_AT_lower_bound";
12413 case DW_AT_producer
:
12414 return "DW_AT_producer";
12415 case DW_AT_prototyped
:
12416 return "DW_AT_prototyped";
12417 case DW_AT_return_addr
:
12418 return "DW_AT_return_addr";
12419 case DW_AT_start_scope
:
12420 return "DW_AT_start_scope";
12421 case DW_AT_bit_stride
:
12422 return "DW_AT_bit_stride";
12423 case DW_AT_upper_bound
:
12424 return "DW_AT_upper_bound";
12425 case DW_AT_abstract_origin
:
12426 return "DW_AT_abstract_origin";
12427 case DW_AT_accessibility
:
12428 return "DW_AT_accessibility";
12429 case DW_AT_address_class
:
12430 return "DW_AT_address_class";
12431 case DW_AT_artificial
:
12432 return "DW_AT_artificial";
12433 case DW_AT_base_types
:
12434 return "DW_AT_base_types";
12435 case DW_AT_calling_convention
:
12436 return "DW_AT_calling_convention";
12438 return "DW_AT_count";
12439 case DW_AT_data_member_location
:
12440 return "DW_AT_data_member_location";
12441 case DW_AT_decl_column
:
12442 return "DW_AT_decl_column";
12443 case DW_AT_decl_file
:
12444 return "DW_AT_decl_file";
12445 case DW_AT_decl_line
:
12446 return "DW_AT_decl_line";
12447 case DW_AT_declaration
:
12448 return "DW_AT_declaration";
12449 case DW_AT_discr_list
:
12450 return "DW_AT_discr_list";
12451 case DW_AT_encoding
:
12452 return "DW_AT_encoding";
12453 case DW_AT_external
:
12454 return "DW_AT_external";
12455 case DW_AT_frame_base
:
12456 return "DW_AT_frame_base";
12458 return "DW_AT_friend";
12459 case DW_AT_identifier_case
:
12460 return "DW_AT_identifier_case";
12461 case DW_AT_macro_info
:
12462 return "DW_AT_macro_info";
12463 case DW_AT_namelist_items
:
12464 return "DW_AT_namelist_items";
12465 case DW_AT_priority
:
12466 return "DW_AT_priority";
12467 case DW_AT_segment
:
12468 return "DW_AT_segment";
12469 case DW_AT_specification
:
12470 return "DW_AT_specification";
12471 case DW_AT_static_link
:
12472 return "DW_AT_static_link";
12474 return "DW_AT_type";
12475 case DW_AT_use_location
:
12476 return "DW_AT_use_location";
12477 case DW_AT_variable_parameter
:
12478 return "DW_AT_variable_parameter";
12479 case DW_AT_virtuality
:
12480 return "DW_AT_virtuality";
12481 case DW_AT_vtable_elem_location
:
12482 return "DW_AT_vtable_elem_location";
12483 /* DWARF 3 values. */
12484 case DW_AT_allocated
:
12485 return "DW_AT_allocated";
12486 case DW_AT_associated
:
12487 return "DW_AT_associated";
12488 case DW_AT_data_location
:
12489 return "DW_AT_data_location";
12490 case DW_AT_byte_stride
:
12491 return "DW_AT_byte_stride";
12492 case DW_AT_entry_pc
:
12493 return "DW_AT_entry_pc";
12494 case DW_AT_use_UTF8
:
12495 return "DW_AT_use_UTF8";
12496 case DW_AT_extension
:
12497 return "DW_AT_extension";
12499 return "DW_AT_ranges";
12500 case DW_AT_trampoline
:
12501 return "DW_AT_trampoline";
12502 case DW_AT_call_column
:
12503 return "DW_AT_call_column";
12504 case DW_AT_call_file
:
12505 return "DW_AT_call_file";
12506 case DW_AT_call_line
:
12507 return "DW_AT_call_line";
12508 case DW_AT_description
:
12509 return "DW_AT_description";
12510 case DW_AT_binary_scale
:
12511 return "DW_AT_binary_scale";
12512 case DW_AT_decimal_scale
:
12513 return "DW_AT_decimal_scale";
12515 return "DW_AT_small";
12516 case DW_AT_decimal_sign
:
12517 return "DW_AT_decimal_sign";
12518 case DW_AT_digit_count
:
12519 return "DW_AT_digit_count";
12520 case DW_AT_picture_string
:
12521 return "DW_AT_picture_string";
12522 case DW_AT_mutable
:
12523 return "DW_AT_mutable";
12524 case DW_AT_threads_scaled
:
12525 return "DW_AT_threads_scaled";
12526 case DW_AT_explicit
:
12527 return "DW_AT_explicit";
12528 case DW_AT_object_pointer
:
12529 return "DW_AT_object_pointer";
12530 case DW_AT_endianity
:
12531 return "DW_AT_endianity";
12532 case DW_AT_elemental
:
12533 return "DW_AT_elemental";
12535 return "DW_AT_pure";
12536 case DW_AT_recursive
:
12537 return "DW_AT_recursive";
12538 /* DWARF 4 values. */
12539 case DW_AT_signature
:
12540 return "DW_AT_signature";
12541 case DW_AT_linkage_name
:
12542 return "DW_AT_linkage_name";
12543 /* SGI/MIPS extensions. */
12544 #ifdef MIPS /* collides with DW_AT_HP_block_index */
12545 case DW_AT_MIPS_fde
:
12546 return "DW_AT_MIPS_fde";
12548 case DW_AT_MIPS_loop_begin
:
12549 return "DW_AT_MIPS_loop_begin";
12550 case DW_AT_MIPS_tail_loop_begin
:
12551 return "DW_AT_MIPS_tail_loop_begin";
12552 case DW_AT_MIPS_epilog_begin
:
12553 return "DW_AT_MIPS_epilog_begin";
12554 case DW_AT_MIPS_loop_unroll_factor
:
12555 return "DW_AT_MIPS_loop_unroll_factor";
12556 case DW_AT_MIPS_software_pipeline_depth
:
12557 return "DW_AT_MIPS_software_pipeline_depth";
12558 case DW_AT_MIPS_linkage_name
:
12559 return "DW_AT_MIPS_linkage_name";
12560 case DW_AT_MIPS_stride
:
12561 return "DW_AT_MIPS_stride";
12562 case DW_AT_MIPS_abstract_name
:
12563 return "DW_AT_MIPS_abstract_name";
12564 case DW_AT_MIPS_clone_origin
:
12565 return "DW_AT_MIPS_clone_origin";
12566 case DW_AT_MIPS_has_inlines
:
12567 return "DW_AT_MIPS_has_inlines";
12568 /* HP extensions. */
12569 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
12570 case DW_AT_HP_block_index
:
12571 return "DW_AT_HP_block_index";
12573 case DW_AT_HP_unmodifiable
:
12574 return "DW_AT_HP_unmodifiable";
12575 case DW_AT_HP_actuals_stmt_list
:
12576 return "DW_AT_HP_actuals_stmt_list";
12577 case DW_AT_HP_proc_per_section
:
12578 return "DW_AT_HP_proc_per_section";
12579 case DW_AT_HP_raw_data_ptr
:
12580 return "DW_AT_HP_raw_data_ptr";
12581 case DW_AT_HP_pass_by_reference
:
12582 return "DW_AT_HP_pass_by_reference";
12583 case DW_AT_HP_opt_level
:
12584 return "DW_AT_HP_opt_level";
12585 case DW_AT_HP_prof_version_id
:
12586 return "DW_AT_HP_prof_version_id";
12587 case DW_AT_HP_opt_flags
:
12588 return "DW_AT_HP_opt_flags";
12589 case DW_AT_HP_cold_region_low_pc
:
12590 return "DW_AT_HP_cold_region_low_pc";
12591 case DW_AT_HP_cold_region_high_pc
:
12592 return "DW_AT_HP_cold_region_high_pc";
12593 case DW_AT_HP_all_variables_modifiable
:
12594 return "DW_AT_HP_all_variables_modifiable";
12595 case DW_AT_HP_linkage_name
:
12596 return "DW_AT_HP_linkage_name";
12597 case DW_AT_HP_prof_flags
:
12598 return "DW_AT_HP_prof_flags";
12599 /* GNU extensions. */
12600 case DW_AT_sf_names
:
12601 return "DW_AT_sf_names";
12602 case DW_AT_src_info
:
12603 return "DW_AT_src_info";
12604 case DW_AT_mac_info
:
12605 return "DW_AT_mac_info";
12606 case DW_AT_src_coords
:
12607 return "DW_AT_src_coords";
12608 case DW_AT_body_begin
:
12609 return "DW_AT_body_begin";
12610 case DW_AT_body_end
:
12611 return "DW_AT_body_end";
12612 case DW_AT_GNU_vector
:
12613 return "DW_AT_GNU_vector";
12614 case DW_AT_GNU_odr_signature
:
12615 return "DW_AT_GNU_odr_signature";
12616 /* VMS extensions. */
12617 case DW_AT_VMS_rtnbeg_pd_address
:
12618 return "DW_AT_VMS_rtnbeg_pd_address";
12619 /* UPC extension. */
12620 case DW_AT_upc_threads_scaled
:
12621 return "DW_AT_upc_threads_scaled";
12622 /* PGI (STMicroelectronics) extensions. */
12623 case DW_AT_PGI_lbase
:
12624 return "DW_AT_PGI_lbase";
12625 case DW_AT_PGI_soffset
:
12626 return "DW_AT_PGI_soffset";
12627 case DW_AT_PGI_lstride
:
12628 return "DW_AT_PGI_lstride";
12630 return "DW_AT_<unknown>";
12634 /* Convert a DWARF value form code into its string name. */
12637 dwarf_form_name (unsigned form
)
12642 return "DW_FORM_addr";
12643 case DW_FORM_block2
:
12644 return "DW_FORM_block2";
12645 case DW_FORM_block4
:
12646 return "DW_FORM_block4";
12647 case DW_FORM_data2
:
12648 return "DW_FORM_data2";
12649 case DW_FORM_data4
:
12650 return "DW_FORM_data4";
12651 case DW_FORM_data8
:
12652 return "DW_FORM_data8";
12653 case DW_FORM_string
:
12654 return "DW_FORM_string";
12655 case DW_FORM_block
:
12656 return "DW_FORM_block";
12657 case DW_FORM_block1
:
12658 return "DW_FORM_block1";
12659 case DW_FORM_data1
:
12660 return "DW_FORM_data1";
12662 return "DW_FORM_flag";
12663 case DW_FORM_sdata
:
12664 return "DW_FORM_sdata";
12666 return "DW_FORM_strp";
12667 case DW_FORM_udata
:
12668 return "DW_FORM_udata";
12669 case DW_FORM_ref_addr
:
12670 return "DW_FORM_ref_addr";
12672 return "DW_FORM_ref1";
12674 return "DW_FORM_ref2";
12676 return "DW_FORM_ref4";
12678 return "DW_FORM_ref8";
12679 case DW_FORM_ref_udata
:
12680 return "DW_FORM_ref_udata";
12681 case DW_FORM_indirect
:
12682 return "DW_FORM_indirect";
12683 case DW_FORM_sec_offset
:
12684 return "DW_FORM_sec_offset";
12685 case DW_FORM_exprloc
:
12686 return "DW_FORM_exprloc";
12687 case DW_FORM_flag_present
:
12688 return "DW_FORM_flag_present";
12689 case DW_FORM_ref_sig8
:
12690 return "DW_FORM_ref_sig8";
12692 return "DW_FORM_<unknown>";
12696 /* Convert a DWARF stack opcode into its string name. */
12699 dwarf_stack_op_name (unsigned op
)
12704 return "DW_OP_addr";
12706 return "DW_OP_deref";
12707 case DW_OP_const1u
:
12708 return "DW_OP_const1u";
12709 case DW_OP_const1s
:
12710 return "DW_OP_const1s";
12711 case DW_OP_const2u
:
12712 return "DW_OP_const2u";
12713 case DW_OP_const2s
:
12714 return "DW_OP_const2s";
12715 case DW_OP_const4u
:
12716 return "DW_OP_const4u";
12717 case DW_OP_const4s
:
12718 return "DW_OP_const4s";
12719 case DW_OP_const8u
:
12720 return "DW_OP_const8u";
12721 case DW_OP_const8s
:
12722 return "DW_OP_const8s";
12724 return "DW_OP_constu";
12726 return "DW_OP_consts";
12728 return "DW_OP_dup";
12730 return "DW_OP_drop";
12732 return "DW_OP_over";
12734 return "DW_OP_pick";
12736 return "DW_OP_swap";
12738 return "DW_OP_rot";
12740 return "DW_OP_xderef";
12742 return "DW_OP_abs";
12744 return "DW_OP_and";
12746 return "DW_OP_div";
12748 return "DW_OP_minus";
12750 return "DW_OP_mod";
12752 return "DW_OP_mul";
12754 return "DW_OP_neg";
12756 return "DW_OP_not";
12760 return "DW_OP_plus";
12761 case DW_OP_plus_uconst
:
12762 return "DW_OP_plus_uconst";
12764 return "DW_OP_shl";
12766 return "DW_OP_shr";
12768 return "DW_OP_shra";
12770 return "DW_OP_xor";
12772 return "DW_OP_bra";
12786 return "DW_OP_skip";
12788 return "DW_OP_lit0";
12790 return "DW_OP_lit1";
12792 return "DW_OP_lit2";
12794 return "DW_OP_lit3";
12796 return "DW_OP_lit4";
12798 return "DW_OP_lit5";
12800 return "DW_OP_lit6";
12802 return "DW_OP_lit7";
12804 return "DW_OP_lit8";
12806 return "DW_OP_lit9";
12808 return "DW_OP_lit10";
12810 return "DW_OP_lit11";
12812 return "DW_OP_lit12";
12814 return "DW_OP_lit13";
12816 return "DW_OP_lit14";
12818 return "DW_OP_lit15";
12820 return "DW_OP_lit16";
12822 return "DW_OP_lit17";
12824 return "DW_OP_lit18";
12826 return "DW_OP_lit19";
12828 return "DW_OP_lit20";
12830 return "DW_OP_lit21";
12832 return "DW_OP_lit22";
12834 return "DW_OP_lit23";
12836 return "DW_OP_lit24";
12838 return "DW_OP_lit25";
12840 return "DW_OP_lit26";
12842 return "DW_OP_lit27";
12844 return "DW_OP_lit28";
12846 return "DW_OP_lit29";
12848 return "DW_OP_lit30";
12850 return "DW_OP_lit31";
12852 return "DW_OP_reg0";
12854 return "DW_OP_reg1";
12856 return "DW_OP_reg2";
12858 return "DW_OP_reg3";
12860 return "DW_OP_reg4";
12862 return "DW_OP_reg5";
12864 return "DW_OP_reg6";
12866 return "DW_OP_reg7";
12868 return "DW_OP_reg8";
12870 return "DW_OP_reg9";
12872 return "DW_OP_reg10";
12874 return "DW_OP_reg11";
12876 return "DW_OP_reg12";
12878 return "DW_OP_reg13";
12880 return "DW_OP_reg14";
12882 return "DW_OP_reg15";
12884 return "DW_OP_reg16";
12886 return "DW_OP_reg17";
12888 return "DW_OP_reg18";
12890 return "DW_OP_reg19";
12892 return "DW_OP_reg20";
12894 return "DW_OP_reg21";
12896 return "DW_OP_reg22";
12898 return "DW_OP_reg23";
12900 return "DW_OP_reg24";
12902 return "DW_OP_reg25";
12904 return "DW_OP_reg26";
12906 return "DW_OP_reg27";
12908 return "DW_OP_reg28";
12910 return "DW_OP_reg29";
12912 return "DW_OP_reg30";
12914 return "DW_OP_reg31";
12916 return "DW_OP_breg0";
12918 return "DW_OP_breg1";
12920 return "DW_OP_breg2";
12922 return "DW_OP_breg3";
12924 return "DW_OP_breg4";
12926 return "DW_OP_breg5";
12928 return "DW_OP_breg6";
12930 return "DW_OP_breg7";
12932 return "DW_OP_breg8";
12934 return "DW_OP_breg9";
12936 return "DW_OP_breg10";
12938 return "DW_OP_breg11";
12940 return "DW_OP_breg12";
12942 return "DW_OP_breg13";
12944 return "DW_OP_breg14";
12946 return "DW_OP_breg15";
12948 return "DW_OP_breg16";
12950 return "DW_OP_breg17";
12952 return "DW_OP_breg18";
12954 return "DW_OP_breg19";
12956 return "DW_OP_breg20";
12958 return "DW_OP_breg21";
12960 return "DW_OP_breg22";
12962 return "DW_OP_breg23";
12964 return "DW_OP_breg24";
12966 return "DW_OP_breg25";
12968 return "DW_OP_breg26";
12970 return "DW_OP_breg27";
12972 return "DW_OP_breg28";
12974 return "DW_OP_breg29";
12976 return "DW_OP_breg30";
12978 return "DW_OP_breg31";
12980 return "DW_OP_regx";
12982 return "DW_OP_fbreg";
12984 return "DW_OP_bregx";
12986 return "DW_OP_piece";
12987 case DW_OP_deref_size
:
12988 return "DW_OP_deref_size";
12989 case DW_OP_xderef_size
:
12990 return "DW_OP_xderef_size";
12992 return "DW_OP_nop";
12993 /* DWARF 3 extensions. */
12994 case DW_OP_push_object_address
:
12995 return "DW_OP_push_object_address";
12997 return "DW_OP_call2";
12999 return "DW_OP_call4";
13000 case DW_OP_call_ref
:
13001 return "DW_OP_call_ref";
13002 case DW_OP_form_tls_address
:
13003 return "DW_OP_form_tls_address";
13004 case DW_OP_call_frame_cfa
:
13005 return "DW_OP_call_frame_cfa";
13006 case DW_OP_bit_piece
:
13007 return "DW_OP_bit_piece";
13008 /* DWARF 4 extensions. */
13009 case DW_OP_implicit_value
:
13010 return "DW_OP_implicit_value";
13011 case DW_OP_stack_value
:
13012 return "DW_OP_stack_value";
13013 /* GNU extensions. */
13014 case DW_OP_GNU_push_tls_address
:
13015 return "DW_OP_GNU_push_tls_address";
13016 case DW_OP_GNU_uninit
:
13017 return "DW_OP_GNU_uninit";
13018 case DW_OP_GNU_implicit_pointer
:
13019 return "DW_OP_GNU_implicit_pointer";
13026 dwarf_bool_name (unsigned mybool
)
13034 /* Convert a DWARF type code into its string name. */
13037 dwarf_type_encoding_name (unsigned enc
)
13042 return "DW_ATE_void";
13043 case DW_ATE_address
:
13044 return "DW_ATE_address";
13045 case DW_ATE_boolean
:
13046 return "DW_ATE_boolean";
13047 case DW_ATE_complex_float
:
13048 return "DW_ATE_complex_float";
13050 return "DW_ATE_float";
13051 case DW_ATE_signed
:
13052 return "DW_ATE_signed";
13053 case DW_ATE_signed_char
:
13054 return "DW_ATE_signed_char";
13055 case DW_ATE_unsigned
:
13056 return "DW_ATE_unsigned";
13057 case DW_ATE_unsigned_char
:
13058 return "DW_ATE_unsigned_char";
13060 case DW_ATE_imaginary_float
:
13061 return "DW_ATE_imaginary_float";
13062 case DW_ATE_packed_decimal
:
13063 return "DW_ATE_packed_decimal";
13064 case DW_ATE_numeric_string
:
13065 return "DW_ATE_numeric_string";
13066 case DW_ATE_edited
:
13067 return "DW_ATE_edited";
13068 case DW_ATE_signed_fixed
:
13069 return "DW_ATE_signed_fixed";
13070 case DW_ATE_unsigned_fixed
:
13071 return "DW_ATE_unsigned_fixed";
13072 case DW_ATE_decimal_float
:
13073 return "DW_ATE_decimal_float";
13076 return "DW_ATE_UTF";
13077 /* HP extensions. */
13078 case DW_ATE_HP_float80
:
13079 return "DW_ATE_HP_float80";
13080 case DW_ATE_HP_complex_float80
:
13081 return "DW_ATE_HP_complex_float80";
13082 case DW_ATE_HP_float128
:
13083 return "DW_ATE_HP_float128";
13084 case DW_ATE_HP_complex_float128
:
13085 return "DW_ATE_HP_complex_float128";
13086 case DW_ATE_HP_floathpintel
:
13087 return "DW_ATE_HP_floathpintel";
13088 case DW_ATE_HP_imaginary_float80
:
13089 return "DW_ATE_HP_imaginary_float80";
13090 case DW_ATE_HP_imaginary_float128
:
13091 return "DW_ATE_HP_imaginary_float128";
13093 return "DW_ATE_<unknown>";
13097 /* Convert a DWARF call frame info operation to its string name. */
13101 dwarf_cfi_name (unsigned cfi_opc
)
13105 case DW_CFA_advance_loc
:
13106 return "DW_CFA_advance_loc";
13107 case DW_CFA_offset
:
13108 return "DW_CFA_offset";
13109 case DW_CFA_restore
:
13110 return "DW_CFA_restore";
13112 return "DW_CFA_nop";
13113 case DW_CFA_set_loc
:
13114 return "DW_CFA_set_loc";
13115 case DW_CFA_advance_loc1
:
13116 return "DW_CFA_advance_loc1";
13117 case DW_CFA_advance_loc2
:
13118 return "DW_CFA_advance_loc2";
13119 case DW_CFA_advance_loc4
:
13120 return "DW_CFA_advance_loc4";
13121 case DW_CFA_offset_extended
:
13122 return "DW_CFA_offset_extended";
13123 case DW_CFA_restore_extended
:
13124 return "DW_CFA_restore_extended";
13125 case DW_CFA_undefined
:
13126 return "DW_CFA_undefined";
13127 case DW_CFA_same_value
:
13128 return "DW_CFA_same_value";
13129 case DW_CFA_register
:
13130 return "DW_CFA_register";
13131 case DW_CFA_remember_state
:
13132 return "DW_CFA_remember_state";
13133 case DW_CFA_restore_state
:
13134 return "DW_CFA_restore_state";
13135 case DW_CFA_def_cfa
:
13136 return "DW_CFA_def_cfa";
13137 case DW_CFA_def_cfa_register
:
13138 return "DW_CFA_def_cfa_register";
13139 case DW_CFA_def_cfa_offset
:
13140 return "DW_CFA_def_cfa_offset";
13142 case DW_CFA_def_cfa_expression
:
13143 return "DW_CFA_def_cfa_expression";
13144 case DW_CFA_expression
:
13145 return "DW_CFA_expression";
13146 case DW_CFA_offset_extended_sf
:
13147 return "DW_CFA_offset_extended_sf";
13148 case DW_CFA_def_cfa_sf
:
13149 return "DW_CFA_def_cfa_sf";
13150 case DW_CFA_def_cfa_offset_sf
:
13151 return "DW_CFA_def_cfa_offset_sf";
13152 case DW_CFA_val_offset
:
13153 return "DW_CFA_val_offset";
13154 case DW_CFA_val_offset_sf
:
13155 return "DW_CFA_val_offset_sf";
13156 case DW_CFA_val_expression
:
13157 return "DW_CFA_val_expression";
13158 /* SGI/MIPS specific. */
13159 case DW_CFA_MIPS_advance_loc8
:
13160 return "DW_CFA_MIPS_advance_loc8";
13161 /* GNU extensions. */
13162 case DW_CFA_GNU_window_save
:
13163 return "DW_CFA_GNU_window_save";
13164 case DW_CFA_GNU_args_size
:
13165 return "DW_CFA_GNU_args_size";
13166 case DW_CFA_GNU_negative_offset_extended
:
13167 return "DW_CFA_GNU_negative_offset_extended";
13169 return "DW_CFA_<unknown>";
13175 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
13179 print_spaces (indent
, f
);
13180 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
13181 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
13183 if (die
->parent
!= NULL
)
13185 print_spaces (indent
, f
);
13186 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
13187 die
->parent
->offset
);
13190 print_spaces (indent
, f
);
13191 fprintf_unfiltered (f
, " has children: %s\n",
13192 dwarf_bool_name (die
->child
!= NULL
));
13194 print_spaces (indent
, f
);
13195 fprintf_unfiltered (f
, " attributes:\n");
13197 for (i
= 0; i
< die
->num_attrs
; ++i
)
13199 print_spaces (indent
, f
);
13200 fprintf_unfiltered (f
, " %s (%s) ",
13201 dwarf_attr_name (die
->attrs
[i
].name
),
13202 dwarf_form_name (die
->attrs
[i
].form
));
13204 switch (die
->attrs
[i
].form
)
13206 case DW_FORM_ref_addr
:
13208 fprintf_unfiltered (f
, "address: ");
13209 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
13211 case DW_FORM_block2
:
13212 case DW_FORM_block4
:
13213 case DW_FORM_block
:
13214 case DW_FORM_block1
:
13215 fprintf_unfiltered (f
, "block: size %d",
13216 DW_BLOCK (&die
->attrs
[i
])->size
);
13218 case DW_FORM_exprloc
:
13219 fprintf_unfiltered (f
, "expression: size %u",
13220 DW_BLOCK (&die
->attrs
[i
])->size
);
13225 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
13226 (long) (DW_ADDR (&die
->attrs
[i
])));
13228 case DW_FORM_data1
:
13229 case DW_FORM_data2
:
13230 case DW_FORM_data4
:
13231 case DW_FORM_data8
:
13232 case DW_FORM_udata
:
13233 case DW_FORM_sdata
:
13234 fprintf_unfiltered (f
, "constant: %s",
13235 pulongest (DW_UNSND (&die
->attrs
[i
])));
13237 case DW_FORM_sec_offset
:
13238 fprintf_unfiltered (f
, "section offset: %s",
13239 pulongest (DW_UNSND (&die
->attrs
[i
])));
13241 case DW_FORM_ref_sig8
:
13242 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
13243 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
13244 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
13246 fprintf_unfiltered (f
, "signatured type, offset: unknown");
13248 case DW_FORM_string
:
13250 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
13251 DW_STRING (&die
->attrs
[i
])
13252 ? DW_STRING (&die
->attrs
[i
]) : "",
13253 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
13256 if (DW_UNSND (&die
->attrs
[i
]))
13257 fprintf_unfiltered (f
, "flag: TRUE");
13259 fprintf_unfiltered (f
, "flag: FALSE");
13261 case DW_FORM_flag_present
:
13262 fprintf_unfiltered (f
, "flag: TRUE");
13264 case DW_FORM_indirect
:
13265 /* The reader will have reduced the indirect form to
13266 the "base form" so this form should not occur. */
13267 fprintf_unfiltered (f
,
13268 "unexpected attribute form: DW_FORM_indirect");
13271 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
13272 die
->attrs
[i
].form
);
13275 fprintf_unfiltered (f
, "\n");
13280 dump_die_for_error (struct die_info
*die
)
13282 dump_die_shallow (gdb_stderr
, 0, die
);
13286 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
13288 int indent
= level
* 4;
13290 gdb_assert (die
!= NULL
);
13292 if (level
>= max_level
)
13295 dump_die_shallow (f
, indent
, die
);
13297 if (die
->child
!= NULL
)
13299 print_spaces (indent
, f
);
13300 fprintf_unfiltered (f
, " Children:");
13301 if (level
+ 1 < max_level
)
13303 fprintf_unfiltered (f
, "\n");
13304 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
13308 fprintf_unfiltered (f
,
13309 " [not printed, max nesting level reached]\n");
13313 if (die
->sibling
!= NULL
&& level
> 0)
13315 dump_die_1 (f
, level
, max_level
, die
->sibling
);
13319 /* This is called from the pdie macro in gdbinit.in.
13320 It's not static so gcc will keep a copy callable from gdb. */
13323 dump_die (struct die_info
*die
, int max_level
)
13325 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
13329 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
13333 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
13339 is_ref_attr (struct attribute
*attr
)
13341 switch (attr
->form
)
13343 case DW_FORM_ref_addr
:
13348 case DW_FORM_ref_udata
:
13355 static unsigned int
13356 dwarf2_get_ref_die_offset (struct attribute
*attr
)
13358 if (is_ref_attr (attr
))
13359 return DW_ADDR (attr
);
13361 complaint (&symfile_complaints
,
13362 _("unsupported die ref attribute form: '%s'"),
13363 dwarf_form_name (attr
->form
));
13367 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
13368 * the value held by the attribute is not constant. */
13371 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
13373 if (attr
->form
== DW_FORM_sdata
)
13374 return DW_SND (attr
);
13375 else if (attr
->form
== DW_FORM_udata
13376 || attr
->form
== DW_FORM_data1
13377 || attr
->form
== DW_FORM_data2
13378 || attr
->form
== DW_FORM_data4
13379 || attr
->form
== DW_FORM_data8
)
13380 return DW_UNSND (attr
);
13383 complaint (&symfile_complaints
,
13384 _("Attribute value is not a constant (%s)"),
13385 dwarf_form_name (attr
->form
));
13386 return default_value
;
13390 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
13391 unit and add it to our queue.
13392 The result is non-zero if PER_CU was queued, otherwise the result is zero
13393 meaning either PER_CU is already queued or it is already loaded. */
13396 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
13397 struct dwarf2_per_cu_data
*per_cu
)
13399 /* We may arrive here during partial symbol reading, if we need full
13400 DIEs to process an unusual case (e.g. template arguments). Do
13401 not queue PER_CU, just tell our caller to load its DIEs. */
13402 if (dwarf2_per_objfile
->reading_partial_symbols
)
13404 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
13409 /* Mark the dependence relation so that we don't flush PER_CU
13411 dwarf2_add_dependence (this_cu
, per_cu
);
13413 /* If it's already on the queue, we have nothing to do. */
13414 if (per_cu
->queued
)
13417 /* If the compilation unit is already loaded, just mark it as
13419 if (per_cu
->cu
!= NULL
)
13421 per_cu
->cu
->last_used
= 0;
13425 /* Add it to the queue. */
13426 queue_comp_unit (per_cu
, this_cu
->objfile
);
13431 /* Follow reference or signature attribute ATTR of SRC_DIE.
13432 On entry *REF_CU is the CU of SRC_DIE.
13433 On exit *REF_CU is the CU of the result. */
13435 static struct die_info
*
13436 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
13437 struct dwarf2_cu
**ref_cu
)
13439 struct die_info
*die
;
13441 if (is_ref_attr (attr
))
13442 die
= follow_die_ref (src_die
, attr
, ref_cu
);
13443 else if (attr
->form
== DW_FORM_ref_sig8
)
13444 die
= follow_die_sig (src_die
, attr
, ref_cu
);
13447 dump_die_for_error (src_die
);
13448 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
13449 (*ref_cu
)->objfile
->name
);
13455 /* Follow reference OFFSET.
13456 On entry *REF_CU is the CU of the source die referencing OFFSET.
13457 On exit *REF_CU is the CU of the result.
13458 Returns NULL if OFFSET is invalid. */
13460 static struct die_info
*
13461 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
13463 struct die_info temp_die
;
13464 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
13466 gdb_assert (cu
->per_cu
!= NULL
);
13470 if (cu
->per_cu
->from_debug_types
)
13472 /* .debug_types CUs cannot reference anything outside their CU.
13473 If they need to, they have to reference a signatured type via
13474 DW_FORM_ref_sig8. */
13475 if (! offset_in_cu_p (&cu
->header
, offset
))
13478 else if (! offset_in_cu_p (&cu
->header
, offset
))
13480 struct dwarf2_per_cu_data
*per_cu
;
13482 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
13484 /* If necessary, add it to the queue and load its DIEs. */
13485 if (maybe_queue_comp_unit (cu
, per_cu
))
13486 load_full_comp_unit (per_cu
, cu
->objfile
);
13488 target_cu
= per_cu
->cu
;
13490 else if (cu
->dies
== NULL
)
13492 /* We're loading full DIEs during partial symbol reading. */
13493 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
13494 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
13497 *ref_cu
= target_cu
;
13498 temp_die
.offset
= offset
;
13499 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
13502 /* Follow reference attribute ATTR of SRC_DIE.
13503 On entry *REF_CU is the CU of SRC_DIE.
13504 On exit *REF_CU is the CU of the result. */
13506 static struct die_info
*
13507 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
13508 struct dwarf2_cu
**ref_cu
)
13510 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
13511 struct dwarf2_cu
*cu
= *ref_cu
;
13512 struct die_info
*die
;
13514 die
= follow_die_offset (offset
, ref_cu
);
13516 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
13517 "at 0x%x [in module %s]"),
13518 offset
, src_die
->offset
, cu
->objfile
->name
);
13523 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
13524 value is intended for DW_OP_call*. */
13526 struct dwarf2_locexpr_baton
13527 dwarf2_fetch_die_location_block (unsigned int offset
,
13528 struct dwarf2_per_cu_data
*per_cu
,
13529 CORE_ADDR (*get_frame_pc
) (void *baton
),
13532 struct dwarf2_cu
*cu
= per_cu
->cu
;
13533 struct die_info
*die
;
13534 struct attribute
*attr
;
13535 struct dwarf2_locexpr_baton retval
;
13537 dw2_setup (per_cu
->objfile
);
13539 die
= follow_die_offset (offset
, &cu
);
13541 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
13542 offset
, per_cu
->cu
->objfile
->name
);
13544 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
13547 /* DWARF: "If there is no such attribute, then there is no effect.". */
13549 retval
.data
= NULL
;
13552 else if (attr_form_is_section_offset (attr
))
13554 struct dwarf2_loclist_baton loclist_baton
;
13555 CORE_ADDR pc
= (*get_frame_pc
) (baton
);
13558 fill_in_loclist_baton (cu
, &loclist_baton
, attr
);
13560 retval
.data
= dwarf2_find_location_expression (&loclist_baton
,
13562 retval
.size
= size
;
13566 if (!attr_form_is_block (attr
))
13567 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
13568 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
13569 offset
, per_cu
->cu
->objfile
->name
);
13571 retval
.data
= DW_BLOCK (attr
)->data
;
13572 retval
.size
= DW_BLOCK (attr
)->size
;
13574 retval
.per_cu
= cu
->per_cu
;
13578 /* Follow the signature attribute ATTR in SRC_DIE.
13579 On entry *REF_CU is the CU of SRC_DIE.
13580 On exit *REF_CU is the CU of the result. */
13582 static struct die_info
*
13583 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
13584 struct dwarf2_cu
**ref_cu
)
13586 struct objfile
*objfile
= (*ref_cu
)->objfile
;
13587 struct die_info temp_die
;
13588 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
13589 struct dwarf2_cu
*sig_cu
;
13590 struct die_info
*die
;
13592 /* sig_type will be NULL if the signatured type is missing from
13594 if (sig_type
== NULL
)
13595 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
13596 "at 0x%x [in module %s]"),
13597 src_die
->offset
, objfile
->name
);
13599 /* If necessary, add it to the queue and load its DIEs. */
13601 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
13602 read_signatured_type (objfile
, sig_type
);
13604 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
13606 sig_cu
= sig_type
->per_cu
.cu
;
13607 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
13608 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
13615 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced "
13616 "from DIE at 0x%x [in module %s]"),
13617 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
13620 /* Given an offset of a signatured type, return its signatured_type. */
13622 static struct signatured_type
*
13623 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
13625 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
13626 unsigned int length
, initial_length_size
;
13627 unsigned int sig_offset
;
13628 struct signatured_type find_entry
, *type_sig
;
13630 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
13631 sig_offset
= (initial_length_size
13633 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13634 + 1 /*address_size*/);
13635 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13636 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13638 /* This is only used to lookup previously recorded types.
13639 If we didn't find it, it's our bug. */
13640 gdb_assert (type_sig
!= NULL
);
13641 gdb_assert (offset
== type_sig
->offset
);
13646 /* Read in signatured type at OFFSET and build its CU and die(s). */
13649 read_signatured_type_at_offset (struct objfile
*objfile
,
13650 unsigned int offset
)
13652 struct signatured_type
*type_sig
;
13654 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13656 /* We have the section offset, but we need the signature to do the
13657 hash table lookup. */
13658 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13660 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13662 read_signatured_type (objfile
, type_sig
);
13664 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13667 /* Read in a signatured type and build its CU and DIEs. */
13670 read_signatured_type (struct objfile
*objfile
,
13671 struct signatured_type
*type_sig
)
13673 gdb_byte
*types_ptr
;
13674 struct die_reader_specs reader_specs
;
13675 struct dwarf2_cu
*cu
;
13676 ULONGEST signature
;
13677 struct cleanup
*back_to
, *free_cu_cleanup
;
13679 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13680 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13682 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13684 cu
= xmalloc (sizeof (*cu
));
13685 init_one_comp_unit (cu
, objfile
);
13687 type_sig
->per_cu
.cu
= cu
;
13688 cu
->per_cu
= &type_sig
->per_cu
;
13690 /* If an error occurs while loading, release our storage. */
13691 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13693 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13694 types_ptr
, objfile
->obfd
);
13695 gdb_assert (signature
== type_sig
->signature
);
13698 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13702 &cu
->comp_unit_obstack
,
13703 hashtab_obstack_allocate
,
13704 dummy_obstack_deallocate
);
13706 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13707 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13709 init_cu_die_reader (&reader_specs
, cu
);
13711 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13714 /* We try not to read any attributes in this function, because not
13715 all objfiles needed for references have been loaded yet, and symbol
13716 table processing isn't initialized. But we have to set the CU language,
13717 or we won't be able to build types correctly. */
13718 prepare_one_comp_unit (cu
, cu
->dies
);
13720 do_cleanups (back_to
);
13722 /* We've successfully allocated this compilation unit. Let our caller
13723 clean it up when finished with it. */
13724 discard_cleanups (free_cu_cleanup
);
13726 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13727 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13730 /* Decode simple location descriptions.
13731 Given a pointer to a dwarf block that defines a location, compute
13732 the location and return the value.
13734 NOTE drow/2003-11-18: This function is called in two situations
13735 now: for the address of static or global variables (partial symbols
13736 only) and for offsets into structures which are expected to be
13737 (more or less) constant. The partial symbol case should go away,
13738 and only the constant case should remain. That will let this
13739 function complain more accurately. A few special modes are allowed
13740 without complaint for global variables (for instance, global
13741 register values and thread-local values).
13743 A location description containing no operations indicates that the
13744 object is optimized out. The return value is 0 for that case.
13745 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13746 callers will only want a very basic result and this can become a
13749 Note that stack[0] is unused except as a default error return. */
13752 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13754 struct objfile
*objfile
= cu
->objfile
;
13756 int size
= blk
->size
;
13757 gdb_byte
*data
= blk
->data
;
13758 CORE_ADDR stack
[64];
13760 unsigned int bytes_read
, unsnd
;
13766 stack
[++stacki
] = 0;
13805 stack
[++stacki
] = op
- DW_OP_lit0
;
13840 stack
[++stacki
] = op
- DW_OP_reg0
;
13842 dwarf2_complex_location_expr_complaint ();
13846 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13848 stack
[++stacki
] = unsnd
;
13850 dwarf2_complex_location_expr_complaint ();
13854 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13859 case DW_OP_const1u
:
13860 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13864 case DW_OP_const1s
:
13865 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13869 case DW_OP_const2u
:
13870 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13874 case DW_OP_const2s
:
13875 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13879 case DW_OP_const4u
:
13880 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13884 case DW_OP_const4s
:
13885 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13890 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13896 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13901 stack
[stacki
+ 1] = stack
[stacki
];
13906 stack
[stacki
- 1] += stack
[stacki
];
13910 case DW_OP_plus_uconst
:
13911 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
),
13917 stack
[stacki
- 1] -= stack
[stacki
];
13922 /* If we're not the last op, then we definitely can't encode
13923 this using GDB's address_class enum. This is valid for partial
13924 global symbols, although the variable's address will be bogus
13927 dwarf2_complex_location_expr_complaint ();
13930 case DW_OP_GNU_push_tls_address
:
13931 /* The top of the stack has the offset from the beginning
13932 of the thread control block at which the variable is located. */
13933 /* Nothing should follow this operator, so the top of stack would
13935 /* This is valid for partial global symbols, but the variable's
13936 address will be bogus in the psymtab. */
13938 dwarf2_complex_location_expr_complaint ();
13941 case DW_OP_GNU_uninit
:
13946 const char *name
= dwarf_stack_op_name (op
);
13949 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13952 complaint (&symfile_complaints
, _("unsupported stack op: '%02x'"),
13956 return (stack
[stacki
]);
13959 /* Enforce maximum stack depth of SIZE-1 to avoid writing
13960 outside of the allocated space. Also enforce minimum>0. */
13961 if (stacki
>= ARRAY_SIZE (stack
) - 1)
13963 complaint (&symfile_complaints
,
13964 _("location description stack overflow"));
13970 complaint (&symfile_complaints
,
13971 _("location description stack underflow"));
13975 return (stack
[stacki
]);
13978 /* memory allocation interface */
13980 static struct dwarf_block
*
13981 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13983 struct dwarf_block
*blk
;
13985 blk
= (struct dwarf_block
*)
13986 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13990 static struct abbrev_info
*
13991 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13993 struct abbrev_info
*abbrev
;
13995 abbrev
= (struct abbrev_info
*)
13996 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13997 memset (abbrev
, 0, sizeof (struct abbrev_info
));
14001 static struct die_info
*
14002 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
14004 struct die_info
*die
;
14005 size_t size
= sizeof (struct die_info
);
14008 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
14010 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
14011 memset (die
, 0, sizeof (struct die_info
));
14016 /* Macro support. */
14018 /* Return the full name of file number I in *LH's file name table.
14019 Use COMP_DIR as the name of the current directory of the
14020 compilation. The result is allocated using xmalloc; the caller is
14021 responsible for freeing it. */
14023 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
14025 /* Is the file number a valid index into the line header's file name
14026 table? Remember that file numbers start with one, not zero. */
14027 if (1 <= file
&& file
<= lh
->num_file_names
)
14029 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
14031 if (IS_ABSOLUTE_PATH (fe
->name
))
14032 return xstrdup (fe
->name
);
14040 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
14046 dir_len
= strlen (dir
);
14047 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
14048 strcpy (full_name
, dir
);
14049 full_name
[dir_len
] = '/';
14050 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
14054 return xstrdup (fe
->name
);
14059 /* The compiler produced a bogus file number. We can at least
14060 record the macro definitions made in the file, even if we
14061 won't be able to find the file by name. */
14062 char fake_name
[80];
14064 sprintf (fake_name
, "<bad macro file number %d>", file
);
14066 complaint (&symfile_complaints
,
14067 _("bad file number in macro information (%d)"),
14070 return xstrdup (fake_name
);
14075 static struct macro_source_file
*
14076 macro_start_file (int file
, int line
,
14077 struct macro_source_file
*current_file
,
14078 const char *comp_dir
,
14079 struct line_header
*lh
, struct objfile
*objfile
)
14081 /* The full name of this source file. */
14082 char *full_name
= file_full_name (file
, lh
, comp_dir
);
14084 /* We don't create a macro table for this compilation unit
14085 at all until we actually get a filename. */
14086 if (! pending_macros
)
14087 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
14088 objfile
->macro_cache
);
14090 if (! current_file
)
14091 /* If we have no current file, then this must be the start_file
14092 directive for the compilation unit's main source file. */
14093 current_file
= macro_set_main (pending_macros
, full_name
);
14095 current_file
= macro_include (current_file
, line
, full_name
);
14099 return current_file
;
14103 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
14104 followed by a null byte. */
14106 copy_string (const char *buf
, int len
)
14108 char *s
= xmalloc (len
+ 1);
14110 memcpy (s
, buf
, len
);
14116 static const char *
14117 consume_improper_spaces (const char *p
, const char *body
)
14121 complaint (&symfile_complaints
,
14122 _("macro definition contains spaces "
14123 "in formal argument list:\n`%s'"),
14135 parse_macro_definition (struct macro_source_file
*file
, int line
,
14140 /* The body string takes one of two forms. For object-like macro
14141 definitions, it should be:
14143 <macro name> " " <definition>
14145 For function-like macro definitions, it should be:
14147 <macro name> "() " <definition>
14149 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
14151 Spaces may appear only where explicitly indicated, and in the
14154 The Dwarf 2 spec says that an object-like macro's name is always
14155 followed by a space, but versions of GCC around March 2002 omit
14156 the space when the macro's definition is the empty string.
14158 The Dwarf 2 spec says that there should be no spaces between the
14159 formal arguments in a function-like macro's formal argument list,
14160 but versions of GCC around March 2002 include spaces after the
14164 /* Find the extent of the macro name. The macro name is terminated
14165 by either a space or null character (for an object-like macro) or
14166 an opening paren (for a function-like macro). */
14167 for (p
= body
; *p
; p
++)
14168 if (*p
== ' ' || *p
== '(')
14171 if (*p
== ' ' || *p
== '\0')
14173 /* It's an object-like macro. */
14174 int name_len
= p
- body
;
14175 char *name
= copy_string (body
, name_len
);
14176 const char *replacement
;
14179 replacement
= body
+ name_len
+ 1;
14182 dwarf2_macro_malformed_definition_complaint (body
);
14183 replacement
= body
+ name_len
;
14186 macro_define_object (file
, line
, name
, replacement
);
14190 else if (*p
== '(')
14192 /* It's a function-like macro. */
14193 char *name
= copy_string (body
, p
- body
);
14196 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
14200 p
= consume_improper_spaces (p
, body
);
14202 /* Parse the formal argument list. */
14203 while (*p
&& *p
!= ')')
14205 /* Find the extent of the current argument name. */
14206 const char *arg_start
= p
;
14208 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
14211 if (! *p
|| p
== arg_start
)
14212 dwarf2_macro_malformed_definition_complaint (body
);
14215 /* Make sure argv has room for the new argument. */
14216 if (argc
>= argv_size
)
14219 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
14222 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
14225 p
= consume_improper_spaces (p
, body
);
14227 /* Consume the comma, if present. */
14232 p
= consume_improper_spaces (p
, body
);
14241 /* Perfectly formed definition, no complaints. */
14242 macro_define_function (file
, line
, name
,
14243 argc
, (const char **) argv
,
14245 else if (*p
== '\0')
14247 /* Complain, but do define it. */
14248 dwarf2_macro_malformed_definition_complaint (body
);
14249 macro_define_function (file
, line
, name
,
14250 argc
, (const char **) argv
,
14254 /* Just complain. */
14255 dwarf2_macro_malformed_definition_complaint (body
);
14258 /* Just complain. */
14259 dwarf2_macro_malformed_definition_complaint (body
);
14265 for (i
= 0; i
< argc
; i
++)
14271 dwarf2_macro_malformed_definition_complaint (body
);
14276 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
14277 char *comp_dir
, bfd
*abfd
,
14278 struct dwarf2_cu
*cu
)
14280 gdb_byte
*mac_ptr
, *mac_end
;
14281 struct macro_source_file
*current_file
= 0;
14282 enum dwarf_macinfo_record_type macinfo_type
;
14283 int at_commandline
;
14285 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14286 &dwarf2_per_objfile
->macinfo
);
14287 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
14289 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
14293 /* First pass: Find the name of the base filename.
14294 This filename is needed in order to process all macros whose definition
14295 (or undefinition) comes from the command line. These macros are defined
14296 before the first DW_MACINFO_start_file entry, and yet still need to be
14297 associated to the base file.
14299 To determine the base file name, we scan the macro definitions until we
14300 reach the first DW_MACINFO_start_file entry. We then initialize
14301 CURRENT_FILE accordingly so that any macro definition found before the
14302 first DW_MACINFO_start_file can still be associated to the base file. */
14304 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14305 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
14306 + dwarf2_per_objfile
->macinfo
.size
;
14310 /* Do we at least have room for a macinfo type byte? */
14311 if (mac_ptr
>= mac_end
)
14313 /* Complaint is printed during the second pass as GDB will probably
14314 stop the first pass earlier upon finding
14315 DW_MACINFO_start_file. */
14319 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14322 switch (macinfo_type
)
14324 /* A zero macinfo type indicates the end of the macro
14329 case DW_MACINFO_define
:
14330 case DW_MACINFO_undef
:
14331 /* Only skip the data by MAC_PTR. */
14333 unsigned int bytes_read
;
14335 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14336 mac_ptr
+= bytes_read
;
14337 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14338 mac_ptr
+= bytes_read
;
14342 case DW_MACINFO_start_file
:
14344 unsigned int bytes_read
;
14347 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14348 mac_ptr
+= bytes_read
;
14349 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14350 mac_ptr
+= bytes_read
;
14352 current_file
= macro_start_file (file
, line
, current_file
,
14353 comp_dir
, lh
, cu
->objfile
);
14357 case DW_MACINFO_end_file
:
14358 /* No data to skip by MAC_PTR. */
14361 case DW_MACINFO_vendor_ext
:
14362 /* Only skip the data by MAC_PTR. */
14364 unsigned int bytes_read
;
14366 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14367 mac_ptr
+= bytes_read
;
14368 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14369 mac_ptr
+= bytes_read
;
14376 } while (macinfo_type
!= 0 && current_file
== NULL
);
14378 /* Second pass: Process all entries.
14380 Use the AT_COMMAND_LINE flag to determine whether we are still processing
14381 command-line macro definitions/undefinitions. This flag is unset when we
14382 reach the first DW_MACINFO_start_file entry. */
14384 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
14386 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
14387 GDB is still reading the definitions from command line. First
14388 DW_MACINFO_start_file will need to be ignored as it was already executed
14389 to create CURRENT_FILE for the main source holding also the command line
14390 definitions. On first met DW_MACINFO_start_file this flag is reset to
14391 normally execute all the remaining DW_MACINFO_start_file macinfos. */
14393 at_commandline
= 1;
14397 /* Do we at least have room for a macinfo type byte? */
14398 if (mac_ptr
>= mac_end
)
14400 dwarf2_macros_too_long_complaint ();
14404 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
14407 switch (macinfo_type
)
14409 /* A zero macinfo type indicates the end of the macro
14414 case DW_MACINFO_define
:
14415 case DW_MACINFO_undef
:
14417 unsigned int bytes_read
;
14421 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14422 mac_ptr
+= bytes_read
;
14423 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14424 mac_ptr
+= bytes_read
;
14426 if (! current_file
)
14428 /* DWARF violation as no main source is present. */
14429 complaint (&symfile_complaints
,
14430 _("debug info with no main source gives macro %s "
14432 macinfo_type
== DW_MACINFO_define
?
14434 macinfo_type
== DW_MACINFO_undef
?
14435 _("undefinition") :
14436 _("something-or-other"), line
, body
);
14439 if ((line
== 0 && !at_commandline
)
14440 || (line
!= 0 && at_commandline
))
14441 complaint (&symfile_complaints
,
14442 _("debug info gives %s macro %s with %s line %d: %s"),
14443 at_commandline
? _("command-line") : _("in-file"),
14444 macinfo_type
== DW_MACINFO_define
?
14446 macinfo_type
== DW_MACINFO_undef
?
14447 _("undefinition") :
14448 _("something-or-other"),
14449 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
14451 if (macinfo_type
== DW_MACINFO_define
)
14452 parse_macro_definition (current_file
, line
, body
);
14453 else if (macinfo_type
== DW_MACINFO_undef
)
14454 macro_undef (current_file
, line
, body
);
14458 case DW_MACINFO_start_file
:
14460 unsigned int bytes_read
;
14463 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14464 mac_ptr
+= bytes_read
;
14465 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14466 mac_ptr
+= bytes_read
;
14468 if ((line
== 0 && !at_commandline
)
14469 || (line
!= 0 && at_commandline
))
14470 complaint (&symfile_complaints
,
14471 _("debug info gives source %d included "
14472 "from %s at %s line %d"),
14473 file
, at_commandline
? _("command-line") : _("file"),
14474 line
== 0 ? _("zero") : _("non-zero"), line
);
14476 if (at_commandline
)
14478 /* This DW_MACINFO_start_file was executed in the pass one. */
14479 at_commandline
= 0;
14482 current_file
= macro_start_file (file
, line
,
14483 current_file
, comp_dir
,
14488 case DW_MACINFO_end_file
:
14489 if (! current_file
)
14490 complaint (&symfile_complaints
,
14491 _("macro debug info has an unmatched "
14492 "`close_file' directive"));
14495 current_file
= current_file
->included_by
;
14496 if (! current_file
)
14498 enum dwarf_macinfo_record_type next_type
;
14500 /* GCC circa March 2002 doesn't produce the zero
14501 type byte marking the end of the compilation
14502 unit. Complain if it's not there, but exit no
14505 /* Do we at least have room for a macinfo type byte? */
14506 if (mac_ptr
>= mac_end
)
14508 dwarf2_macros_too_long_complaint ();
14512 /* We don't increment mac_ptr here, so this is just
14514 next_type
= read_1_byte (abfd
, mac_ptr
);
14515 if (next_type
!= 0)
14516 complaint (&symfile_complaints
,
14517 _("no terminating 0-type entry for "
14518 "macros in `.debug_macinfo' section"));
14525 case DW_MACINFO_vendor_ext
:
14527 unsigned int bytes_read
;
14530 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
14531 mac_ptr
+= bytes_read
;
14532 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
14533 mac_ptr
+= bytes_read
;
14535 /* We don't recognize any vendor extensions. */
14539 } while (macinfo_type
!= 0);
14542 /* Check if the attribute's form is a DW_FORM_block*
14543 if so return true else false. */
14545 attr_form_is_block (struct attribute
*attr
)
14547 return (attr
== NULL
? 0 :
14548 attr
->form
== DW_FORM_block1
14549 || attr
->form
== DW_FORM_block2
14550 || attr
->form
== DW_FORM_block4
14551 || attr
->form
== DW_FORM_block
14552 || attr
->form
== DW_FORM_exprloc
);
14555 /* Return non-zero if ATTR's value is a section offset --- classes
14556 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
14557 You may use DW_UNSND (attr) to retrieve such offsets.
14559 Section 7.5.4, "Attribute Encodings", explains that no attribute
14560 may have a value that belongs to more than one of these classes; it
14561 would be ambiguous if we did, because we use the same forms for all
14564 attr_form_is_section_offset (struct attribute
*attr
)
14566 return (attr
->form
== DW_FORM_data4
14567 || attr
->form
== DW_FORM_data8
14568 || attr
->form
== DW_FORM_sec_offset
);
14572 /* Return non-zero if ATTR's value falls in the 'constant' class, or
14573 zero otherwise. When this function returns true, you can apply
14574 dwarf2_get_attr_constant_value to it.
14576 However, note that for some attributes you must check
14577 attr_form_is_section_offset before using this test. DW_FORM_data4
14578 and DW_FORM_data8 are members of both the constant class, and of
14579 the classes that contain offsets into other debug sections
14580 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
14581 that, if an attribute's can be either a constant or one of the
14582 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
14583 taken as section offsets, not constants. */
14585 attr_form_is_constant (struct attribute
*attr
)
14587 switch (attr
->form
)
14589 case DW_FORM_sdata
:
14590 case DW_FORM_udata
:
14591 case DW_FORM_data1
:
14592 case DW_FORM_data2
:
14593 case DW_FORM_data4
:
14594 case DW_FORM_data8
:
14601 /* A helper function that fills in a dwarf2_loclist_baton. */
14604 fill_in_loclist_baton (struct dwarf2_cu
*cu
,
14605 struct dwarf2_loclist_baton
*baton
,
14606 struct attribute
*attr
)
14608 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
14609 &dwarf2_per_objfile
->loc
);
14611 baton
->per_cu
= cu
->per_cu
;
14612 gdb_assert (baton
->per_cu
);
14613 /* We don't know how long the location list is, but make sure we
14614 don't run off the edge of the section. */
14615 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
14616 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
14617 baton
->base_address
= cu
->base_address
;
14621 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
14622 struct dwarf2_cu
*cu
)
14624 if (attr_form_is_section_offset (attr
)
14625 /* ".debug_loc" may not exist at all, or the offset may be outside
14626 the section. If so, fall through to the complaint in the
14628 && DW_UNSND (attr
) < dwarf2_section_size (dwarf2_per_objfile
->objfile
,
14629 &dwarf2_per_objfile
->loc
))
14631 struct dwarf2_loclist_baton
*baton
;
14633 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14634 sizeof (struct dwarf2_loclist_baton
));
14636 fill_in_loclist_baton (cu
, baton
, attr
);
14638 if (cu
->base_known
== 0)
14639 complaint (&symfile_complaints
,
14640 _("Location list used without "
14641 "specifying the CU base address."));
14643 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
14644 SYMBOL_LOCATION_BATON (sym
) = baton
;
14648 struct dwarf2_locexpr_baton
*baton
;
14650 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
14651 sizeof (struct dwarf2_locexpr_baton
));
14652 baton
->per_cu
= cu
->per_cu
;
14653 gdb_assert (baton
->per_cu
);
14655 if (attr_form_is_block (attr
))
14657 /* Note that we're just copying the block's data pointer
14658 here, not the actual data. We're still pointing into the
14659 info_buffer for SYM's objfile; right now we never release
14660 that buffer, but when we do clean up properly this may
14662 baton
->size
= DW_BLOCK (attr
)->size
;
14663 baton
->data
= DW_BLOCK (attr
)->data
;
14667 dwarf2_invalid_attrib_class_complaint ("location description",
14668 SYMBOL_NATURAL_NAME (sym
));
14670 baton
->data
= NULL
;
14673 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14674 SYMBOL_LOCATION_BATON (sym
) = baton
;
14678 /* Return the OBJFILE associated with the compilation unit CU. If CU
14679 came from a separate debuginfo file, then the master objfile is
14683 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14685 struct objfile
*objfile
= per_cu
->objfile
;
14687 /* Return the master objfile, so that we can report and look up the
14688 correct file containing this variable. */
14689 if (objfile
->separate_debug_objfile_backlink
)
14690 objfile
= objfile
->separate_debug_objfile_backlink
;
14695 /* Return the address size given in the compilation unit header for CU. */
14698 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14701 return per_cu
->cu
->header
.addr_size
;
14704 /* If the CU is not currently read in, we re-read its header. */
14705 struct objfile
*objfile
= per_cu
->objfile
;
14706 struct dwarf2_per_objfile
*per_objfile
14707 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14708 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14709 struct comp_unit_head cu_header
;
14711 memset (&cu_header
, 0, sizeof cu_header
);
14712 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14713 return cu_header
.addr_size
;
14717 /* Return the offset size given in the compilation unit header for CU. */
14720 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14723 return per_cu
->cu
->header
.offset_size
;
14726 /* If the CU is not currently read in, we re-read its header. */
14727 struct objfile
*objfile
= per_cu
->objfile
;
14728 struct dwarf2_per_objfile
*per_objfile
14729 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14730 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14731 struct comp_unit_head cu_header
;
14733 memset (&cu_header
, 0, sizeof cu_header
);
14734 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14735 return cu_header
.offset_size
;
14739 /* Return the text offset of the CU. The returned offset comes from
14740 this CU's objfile. If this objfile came from a separate debuginfo
14741 file, then the offset may be different from the corresponding
14742 offset in the parent objfile. */
14745 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14747 struct objfile
*objfile
= per_cu
->objfile
;
14749 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14752 /* Locate the .debug_info compilation unit from CU's objfile which contains
14753 the DIE at OFFSET. Raises an error on failure. */
14755 static struct dwarf2_per_cu_data
*
14756 dwarf2_find_containing_comp_unit (unsigned int offset
,
14757 struct objfile
*objfile
)
14759 struct dwarf2_per_cu_data
*this_cu
;
14763 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14766 int mid
= low
+ (high
- low
) / 2;
14768 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14773 gdb_assert (low
== high
);
14774 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14777 error (_("Dwarf Error: could not find partial DIE containing "
14778 "offset 0x%lx [in module %s]"),
14779 (long) offset
, bfd_get_filename (objfile
->obfd
));
14781 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14782 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14786 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14787 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14788 && offset
>= this_cu
->offset
+ this_cu
->length
)
14789 error (_("invalid dwarf2 offset %u"), offset
);
14790 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14795 /* Locate the compilation unit from OBJFILE which is located at exactly
14796 OFFSET. Raises an error on failure. */
14798 static struct dwarf2_per_cu_data
*
14799 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14801 struct dwarf2_per_cu_data
*this_cu
;
14803 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14804 if (this_cu
->offset
!= offset
)
14805 error (_("no compilation unit with offset %u."), offset
);
14809 /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */
14812 init_one_comp_unit (struct dwarf2_cu
*cu
, struct objfile
*objfile
)
14814 memset (cu
, 0, sizeof (*cu
));
14815 cu
->objfile
= objfile
;
14816 obstack_init (&cu
->comp_unit_obstack
);
14819 /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */
14822 prepare_one_comp_unit (struct dwarf2_cu
*cu
, struct die_info
*comp_unit_die
)
14824 struct attribute
*attr
;
14826 /* Set the language we're debugging. */
14827 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
14829 set_cu_language (DW_UNSND (attr
), cu
);
14832 cu
->language
= language_minimal
;
14833 cu
->language_defn
= language_def (cu
->language
);
14837 /* Release one cached compilation unit, CU. We unlink it from the tree
14838 of compilation units, but we don't remove it from the read_in_chain;
14839 the caller is responsible for that.
14840 NOTE: DATA is a void * because this function is also used as a
14841 cleanup routine. */
14844 free_one_comp_unit (void *data
)
14846 struct dwarf2_cu
*cu
= data
;
14848 if (cu
->per_cu
!= NULL
)
14849 cu
->per_cu
->cu
= NULL
;
14852 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14857 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14858 when we're finished with it. We can't free the pointer itself, but be
14859 sure to unlink it from the cache. Also release any associated storage
14860 and perform cache maintenance.
14862 Only used during partial symbol parsing. */
14865 free_stack_comp_unit (void *data
)
14867 struct dwarf2_cu
*cu
= data
;
14869 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14870 cu
->partial_dies
= NULL
;
14872 if (cu
->per_cu
!= NULL
)
14874 /* This compilation unit is on the stack in our caller, so we
14875 should not xfree it. Just unlink it. */
14876 cu
->per_cu
->cu
= NULL
;
14879 /* If we had a per-cu pointer, then we may have other compilation
14880 units loaded, so age them now. */
14881 age_cached_comp_units ();
14885 /* Free all cached compilation units. */
14888 free_cached_comp_units (void *data
)
14890 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14892 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14893 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14894 while (per_cu
!= NULL
)
14896 struct dwarf2_per_cu_data
*next_cu
;
14898 next_cu
= per_cu
->cu
->read_in_chain
;
14900 free_one_comp_unit (per_cu
->cu
);
14901 *last_chain
= next_cu
;
14907 /* Increase the age counter on each cached compilation unit, and free
14908 any that are too old. */
14911 age_cached_comp_units (void)
14913 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14915 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14916 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14917 while (per_cu
!= NULL
)
14919 per_cu
->cu
->last_used
++;
14920 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14921 dwarf2_mark (per_cu
->cu
);
14922 per_cu
= per_cu
->cu
->read_in_chain
;
14925 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14926 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14927 while (per_cu
!= NULL
)
14929 struct dwarf2_per_cu_data
*next_cu
;
14931 next_cu
= per_cu
->cu
->read_in_chain
;
14933 if (!per_cu
->cu
->mark
)
14935 free_one_comp_unit (per_cu
->cu
);
14936 *last_chain
= next_cu
;
14939 last_chain
= &per_cu
->cu
->read_in_chain
;
14945 /* Remove a single compilation unit from the cache. */
14948 free_one_cached_comp_unit (void *target_cu
)
14950 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14952 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14953 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14954 while (per_cu
!= NULL
)
14956 struct dwarf2_per_cu_data
*next_cu
;
14958 next_cu
= per_cu
->cu
->read_in_chain
;
14960 if (per_cu
->cu
== target_cu
)
14962 free_one_comp_unit (per_cu
->cu
);
14963 *last_chain
= next_cu
;
14967 last_chain
= &per_cu
->cu
->read_in_chain
;
14973 /* Release all extra memory associated with OBJFILE. */
14976 dwarf2_free_objfile (struct objfile
*objfile
)
14978 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14980 if (dwarf2_per_objfile
== NULL
)
14983 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14984 free_cached_comp_units (NULL
);
14986 if (dwarf2_per_objfile
->quick_file_names_table
)
14987 htab_delete (dwarf2_per_objfile
->quick_file_names_table
);
14989 /* Everything else should be on the objfile obstack. */
14992 /* A pair of DIE offset and GDB type pointer. We store these
14993 in a hash table separate from the DIEs, and preserve them
14994 when the DIEs are flushed out of cache. */
14996 struct dwarf2_offset_and_type
14998 unsigned int offset
;
15002 /* Hash function for a dwarf2_offset_and_type. */
15005 offset_and_type_hash (const void *item
)
15007 const struct dwarf2_offset_and_type
*ofs
= item
;
15009 return ofs
->offset
;
15012 /* Equality function for a dwarf2_offset_and_type. */
15015 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
15017 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
15018 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
15020 return ofs_lhs
->offset
== ofs_rhs
->offset
;
15023 /* Set the type associated with DIE to TYPE. Save it in CU's hash
15024 table if necessary. For convenience, return TYPE.
15026 The DIEs reading must have careful ordering to:
15027 * Not cause infite loops trying to read in DIEs as a prerequisite for
15028 reading current DIE.
15029 * Not trying to dereference contents of still incompletely read in types
15030 while reading in other DIEs.
15031 * Enable referencing still incompletely read in types just by a pointer to
15032 the type without accessing its fields.
15034 Therefore caller should follow these rules:
15035 * Try to fetch any prerequisite types we may need to build this DIE type
15036 before building the type and calling set_die_type.
15037 * After building type call set_die_type for current DIE as soon as
15038 possible before fetching more types to complete the current type.
15039 * Make the type as complete as possible before fetching more types. */
15041 static struct type
*
15042 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
15044 struct dwarf2_offset_and_type
**slot
, ofs
;
15045 struct objfile
*objfile
= cu
->objfile
;
15046 htab_t
*type_hash_ptr
;
15048 /* For Ada types, make sure that the gnat-specific data is always
15049 initialized (if not already set). There are a few types where
15050 we should not be doing so, because the type-specific area is
15051 already used to hold some other piece of info (eg: TYPE_CODE_FLT
15052 where the type-specific area is used to store the floatformat).
15053 But this is not a problem, because the gnat-specific information
15054 is actually not needed for these types. */
15055 if (need_gnat_info (cu
)
15056 && TYPE_CODE (type
) != TYPE_CODE_FUNC
15057 && TYPE_CODE (type
) != TYPE_CODE_FLT
15058 && !HAVE_GNAT_AUX_INFO (type
))
15059 INIT_GNAT_SPECIFIC (type
);
15061 if (cu
->per_cu
->from_debug_types
)
15062 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
15064 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
15066 if (*type_hash_ptr
== NULL
)
15069 = htab_create_alloc_ex (127,
15070 offset_and_type_hash
,
15071 offset_and_type_eq
,
15073 &objfile
->objfile_obstack
,
15074 hashtab_obstack_allocate
,
15075 dummy_obstack_deallocate
);
15078 ofs
.offset
= die
->offset
;
15080 slot
= (struct dwarf2_offset_and_type
**)
15081 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
15083 complaint (&symfile_complaints
,
15084 _("A problem internal to GDB: DIE 0x%x has type already set"),
15086 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
15091 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
15092 table, or return NULL if the die does not have a saved type. */
15094 static struct type
*
15095 get_die_type_at_offset (unsigned int offset
,
15096 struct dwarf2_per_cu_data
*per_cu
)
15098 struct dwarf2_offset_and_type
*slot
, ofs
;
15101 if (per_cu
->from_debug_types
)
15102 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
15104 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
15105 if (type_hash
== NULL
)
15108 ofs
.offset
= offset
;
15109 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
15116 /* Look up the type for DIE in the appropriate type_hash table,
15117 or return NULL if DIE does not have a saved type. */
15119 static struct type
*
15120 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
15122 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
15125 /* Add a dependence relationship from CU to REF_PER_CU. */
15128 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
15129 struct dwarf2_per_cu_data
*ref_per_cu
)
15133 if (cu
->dependencies
== NULL
)
15135 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
15136 NULL
, &cu
->comp_unit_obstack
,
15137 hashtab_obstack_allocate
,
15138 dummy_obstack_deallocate
);
15140 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
15142 *slot
= ref_per_cu
;
15145 /* Subroutine of dwarf2_mark to pass to htab_traverse.
15146 Set the mark field in every compilation unit in the
15147 cache that we must keep because we are keeping CU. */
15150 dwarf2_mark_helper (void **slot
, void *data
)
15152 struct dwarf2_per_cu_data
*per_cu
;
15154 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
15155 if (per_cu
->cu
->mark
)
15157 per_cu
->cu
->mark
= 1;
15159 if (per_cu
->cu
->dependencies
!= NULL
)
15160 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15165 /* Set the mark field in CU and in every other compilation unit in the
15166 cache that we must keep because we are keeping CU. */
15169 dwarf2_mark (struct dwarf2_cu
*cu
)
15174 if (cu
->dependencies
!= NULL
)
15175 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
15179 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
15183 per_cu
->cu
->mark
= 0;
15184 per_cu
= per_cu
->cu
->read_in_chain
;
15188 /* Trivial hash function for partial_die_info: the hash value of a DIE
15189 is its offset in .debug_info for this objfile. */
15192 partial_die_hash (const void *item
)
15194 const struct partial_die_info
*part_die
= item
;
15196 return part_die
->offset
;
15199 /* Trivial comparison function for partial_die_info structures: two DIEs
15200 are equal if they have the same offset. */
15203 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
15205 const struct partial_die_info
*part_die_lhs
= item_lhs
;
15206 const struct partial_die_info
*part_die_rhs
= item_rhs
;
15208 return part_die_lhs
->offset
== part_die_rhs
->offset
;
15211 static struct cmd_list_element
*set_dwarf2_cmdlist
;
15212 static struct cmd_list_element
*show_dwarf2_cmdlist
;
15215 set_dwarf2_cmd (char *args
, int from_tty
)
15217 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
15221 show_dwarf2_cmd (char *args
, int from_tty
)
15223 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
15226 /* If section described by INFO was mmapped, munmap it now. */
15229 munmap_section_buffer (struct dwarf2_section_info
*info
)
15231 if (info
->was_mmapped
)
15234 intptr_t begin
= (intptr_t) info
->buffer
;
15235 intptr_t map_begin
= begin
& ~(pagesize
- 1);
15236 size_t map_length
= info
->size
+ begin
- map_begin
;
15238 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
15240 /* Without HAVE_MMAP, we should never be here to begin with. */
15241 gdb_assert_not_reached ("no mmap support");
15246 /* munmap debug sections for OBJFILE, if necessary. */
15249 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
15251 struct dwarf2_per_objfile
*data
= d
;
15253 /* This is sorted according to the order they're defined in to make it easier
15254 to keep in sync. */
15255 munmap_section_buffer (&data
->info
);
15256 munmap_section_buffer (&data
->abbrev
);
15257 munmap_section_buffer (&data
->line
);
15258 munmap_section_buffer (&data
->loc
);
15259 munmap_section_buffer (&data
->macinfo
);
15260 munmap_section_buffer (&data
->str
);
15261 munmap_section_buffer (&data
->ranges
);
15262 munmap_section_buffer (&data
->types
);
15263 munmap_section_buffer (&data
->frame
);
15264 munmap_section_buffer (&data
->eh_frame
);
15265 munmap_section_buffer (&data
->gdb_index
);
15269 /* The "save gdb-index" command. */
15271 /* The contents of the hash table we create when building the string
15273 struct strtab_entry
15275 offset_type offset
;
15279 /* Hash function for a strtab_entry.
15281 Function is used only during write_hash_table so no index format backward
15282 compatibility is needed. */
15285 hash_strtab_entry (const void *e
)
15287 const struct strtab_entry
*entry
= e
;
15288 return mapped_index_string_hash (INT_MAX
, entry
->str
);
15291 /* Equality function for a strtab_entry. */
15294 eq_strtab_entry (const void *a
, const void *b
)
15296 const struct strtab_entry
*ea
= a
;
15297 const struct strtab_entry
*eb
= b
;
15298 return !strcmp (ea
->str
, eb
->str
);
15301 /* Create a strtab_entry hash table. */
15304 create_strtab (void)
15306 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
15307 xfree
, xcalloc
, xfree
);
15310 /* Add a string to the constant pool. Return the string's offset in
15314 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
15317 struct strtab_entry entry
;
15318 struct strtab_entry
*result
;
15321 slot
= htab_find_slot (table
, &entry
, INSERT
);
15326 result
= XNEW (struct strtab_entry
);
15327 result
->offset
= obstack_object_size (cpool
);
15329 obstack_grow_str0 (cpool
, str
);
15332 return result
->offset
;
15335 /* An entry in the symbol table. */
15336 struct symtab_index_entry
15338 /* The name of the symbol. */
15340 /* The offset of the name in the constant pool. */
15341 offset_type index_offset
;
15342 /* A sorted vector of the indices of all the CUs that hold an object
15344 VEC (offset_type
) *cu_indices
;
15347 /* The symbol table. This is a power-of-2-sized hash table. */
15348 struct mapped_symtab
15350 offset_type n_elements
;
15352 struct symtab_index_entry
**data
;
15355 /* Hash function for a symtab_index_entry. */
15358 hash_symtab_entry (const void *e
)
15360 const struct symtab_index_entry
*entry
= e
;
15361 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
15362 sizeof (offset_type
) * VEC_length (offset_type
,
15363 entry
->cu_indices
),
15367 /* Equality function for a symtab_index_entry. */
15370 eq_symtab_entry (const void *a
, const void *b
)
15372 const struct symtab_index_entry
*ea
= a
;
15373 const struct symtab_index_entry
*eb
= b
;
15374 int len
= VEC_length (offset_type
, ea
->cu_indices
);
15375 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
15377 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
15378 VEC_address (offset_type
, eb
->cu_indices
),
15379 sizeof (offset_type
) * len
);
15382 /* Destroy a symtab_index_entry. */
15385 delete_symtab_entry (void *p
)
15387 struct symtab_index_entry
*entry
= p
;
15388 VEC_free (offset_type
, entry
->cu_indices
);
15392 /* Create a hash table holding symtab_index_entry objects. */
15395 create_symbol_hash_table (void)
15397 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
15398 delete_symtab_entry
, xcalloc
, xfree
);
15401 /* Create a new mapped symtab object. */
15403 static struct mapped_symtab
*
15404 create_mapped_symtab (void)
15406 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
15407 symtab
->n_elements
= 0;
15408 symtab
->size
= 1024;
15409 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15413 /* Destroy a mapped_symtab. */
15416 cleanup_mapped_symtab (void *p
)
15418 struct mapped_symtab
*symtab
= p
;
15419 /* The contents of the array are freed when the other hash table is
15421 xfree (symtab
->data
);
15425 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
15428 Function is used only during write_hash_table so no index format backward
15429 compatibility is needed. */
15431 static struct symtab_index_entry
**
15432 find_slot (struct mapped_symtab
*symtab
, const char *name
)
15434 offset_type index
, step
, hash
= mapped_index_string_hash (INT_MAX
, name
);
15436 index
= hash
& (symtab
->size
- 1);
15437 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
15441 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
15442 return &symtab
->data
[index
];
15443 index
= (index
+ step
) & (symtab
->size
- 1);
15447 /* Expand SYMTAB's hash table. */
15450 hash_expand (struct mapped_symtab
*symtab
)
15452 offset_type old_size
= symtab
->size
;
15454 struct symtab_index_entry
**old_entries
= symtab
->data
;
15457 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
15459 for (i
= 0; i
< old_size
; ++i
)
15461 if (old_entries
[i
])
15463 struct symtab_index_entry
**slot
= find_slot (symtab
,
15464 old_entries
[i
]->name
);
15465 *slot
= old_entries
[i
];
15469 xfree (old_entries
);
15472 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
15473 is the index of the CU in which the symbol appears. */
15476 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
15477 offset_type cu_index
)
15479 struct symtab_index_entry
**slot
;
15481 ++symtab
->n_elements
;
15482 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
15483 hash_expand (symtab
);
15485 slot
= find_slot (symtab
, name
);
15488 *slot
= XNEW (struct symtab_index_entry
);
15489 (*slot
)->name
= name
;
15490 (*slot
)->cu_indices
= NULL
;
15492 /* Don't push an index twice. Due to how we add entries we only
15493 have to check the last one. */
15494 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
15495 || VEC_last (offset_type
, (*slot
)->cu_indices
) != cu_index
)
15496 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
15499 /* Add a vector of indices to the constant pool. */
15502 add_indices_to_cpool (htab_t symbol_hash_table
, struct obstack
*cpool
,
15503 struct symtab_index_entry
*entry
)
15507 slot
= htab_find_slot (symbol_hash_table
, entry
, INSERT
);
15510 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
15511 offset_type val
= MAYBE_SWAP (len
);
15516 entry
->index_offset
= obstack_object_size (cpool
);
15518 obstack_grow (cpool
, &val
, sizeof (val
));
15520 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
15523 val
= MAYBE_SWAP (iter
);
15524 obstack_grow (cpool
, &val
, sizeof (val
));
15529 struct symtab_index_entry
*old_entry
= *slot
;
15530 entry
->index_offset
= old_entry
->index_offset
;
15533 return entry
->index_offset
;
15536 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
15537 constant pool entries going into the obstack CPOOL. */
15540 write_hash_table (struct mapped_symtab
*symtab
,
15541 struct obstack
*output
, struct obstack
*cpool
)
15544 htab_t symbol_hash_table
;
15547 symbol_hash_table
= create_symbol_hash_table ();
15548 str_table
= create_strtab ();
15550 /* We add all the index vectors to the constant pool first, to
15551 ensure alignment is ok. */
15552 for (i
= 0; i
< symtab
->size
; ++i
)
15554 if (symtab
->data
[i
])
15555 add_indices_to_cpool (symbol_hash_table
, cpool
, symtab
->data
[i
]);
15558 /* Now write out the hash table. */
15559 for (i
= 0; i
< symtab
->size
; ++i
)
15561 offset_type str_off
, vec_off
;
15563 if (symtab
->data
[i
])
15565 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
15566 vec_off
= symtab
->data
[i
]->index_offset
;
15570 /* While 0 is a valid constant pool index, it is not valid
15571 to have 0 for both offsets. */
15576 str_off
= MAYBE_SWAP (str_off
);
15577 vec_off
= MAYBE_SWAP (vec_off
);
15579 obstack_grow (output
, &str_off
, sizeof (str_off
));
15580 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
15583 htab_delete (str_table
);
15584 htab_delete (symbol_hash_table
);
15587 /* Struct to map psymtab to CU index in the index file. */
15588 struct psymtab_cu_index_map
15590 struct partial_symtab
*psymtab
;
15591 unsigned int cu_index
;
15595 hash_psymtab_cu_index (const void *item
)
15597 const struct psymtab_cu_index_map
*map
= item
;
15599 return htab_hash_pointer (map
->psymtab
);
15603 eq_psymtab_cu_index (const void *item_lhs
, const void *item_rhs
)
15605 const struct psymtab_cu_index_map
*lhs
= item_lhs
;
15606 const struct psymtab_cu_index_map
*rhs
= item_rhs
;
15608 return lhs
->psymtab
== rhs
->psymtab
;
15611 /* Helper struct for building the address table. */
15612 struct addrmap_index_data
15614 struct objfile
*objfile
;
15615 struct obstack
*addr_obstack
;
15616 htab_t cu_index_htab
;
15618 /* Non-zero if the previous_* fields are valid.
15619 We can't write an entry until we see the next entry (since it is only then
15620 that we know the end of the entry). */
15621 int previous_valid
;
15622 /* Index of the CU in the table of all CUs in the index file. */
15623 unsigned int previous_cu_index
;
15624 /* Start address of the CU. */
15625 CORE_ADDR previous_cu_start
;
15628 /* Write an address entry to OBSTACK. */
15631 add_address_entry (struct objfile
*objfile
, struct obstack
*obstack
,
15632 CORE_ADDR start
, CORE_ADDR end
, unsigned int cu_index
)
15634 offset_type cu_index_to_write
;
15636 CORE_ADDR baseaddr
;
15638 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
15640 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, start
- baseaddr
);
15641 obstack_grow (obstack
, addr
, 8);
15642 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, end
- baseaddr
);
15643 obstack_grow (obstack
, addr
, 8);
15644 cu_index_to_write
= MAYBE_SWAP (cu_index
);
15645 obstack_grow (obstack
, &cu_index_to_write
, sizeof (offset_type
));
15648 /* Worker function for traversing an addrmap to build the address table. */
15651 add_address_entry_worker (void *datap
, CORE_ADDR start_addr
, void *obj
)
15653 struct addrmap_index_data
*data
= datap
;
15654 struct partial_symtab
*pst
= obj
;
15655 offset_type cu_index
;
15658 if (data
->previous_valid
)
15659 add_address_entry (data
->objfile
, data
->addr_obstack
,
15660 data
->previous_cu_start
, start_addr
,
15661 data
->previous_cu_index
);
15663 data
->previous_cu_start
= start_addr
;
15666 struct psymtab_cu_index_map find_map
, *map
;
15667 find_map
.psymtab
= pst
;
15668 map
= htab_find (data
->cu_index_htab
, &find_map
);
15669 gdb_assert (map
!= NULL
);
15670 data
->previous_cu_index
= map
->cu_index
;
15671 data
->previous_valid
= 1;
15674 data
->previous_valid
= 0;
15679 /* Write OBJFILE's address map to OBSTACK.
15680 CU_INDEX_HTAB is used to map addrmap entries to their CU indices
15681 in the index file. */
15684 write_address_map (struct objfile
*objfile
, struct obstack
*obstack
,
15685 htab_t cu_index_htab
)
15687 struct addrmap_index_data addrmap_index_data
;
15689 /* When writing the address table, we have to cope with the fact that
15690 the addrmap iterator only provides the start of a region; we have to
15691 wait until the next invocation to get the start of the next region. */
15693 addrmap_index_data
.objfile
= objfile
;
15694 addrmap_index_data
.addr_obstack
= obstack
;
15695 addrmap_index_data
.cu_index_htab
= cu_index_htab
;
15696 addrmap_index_data
.previous_valid
= 0;
15698 addrmap_foreach (objfile
->psymtabs_addrmap
, add_address_entry_worker
,
15699 &addrmap_index_data
);
15701 /* It's highly unlikely the last entry (end address = 0xff...ff)
15702 is valid, but we should still handle it.
15703 The end address is recorded as the start of the next region, but that
15704 doesn't work here. To cope we pass 0xff...ff, this is a rare situation
15706 if (addrmap_index_data
.previous_valid
)
15707 add_address_entry (objfile
, obstack
,
15708 addrmap_index_data
.previous_cu_start
, (CORE_ADDR
) -1,
15709 addrmap_index_data
.previous_cu_index
);
15712 /* Add a list of partial symbols to SYMTAB. */
15715 write_psymbols (struct mapped_symtab
*symtab
,
15717 struct partial_symbol
**psymp
,
15719 offset_type cu_index
,
15722 for (; count
-- > 0; ++psymp
)
15724 void **slot
, *lookup
;
15726 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
15727 error (_("Ada is not currently supported by the index"));
15729 /* We only want to add a given psymbol once. However, we also
15730 want to account for whether it is global or static. So, we
15731 may add it twice, using slightly different values. */
15734 uintptr_t val
= 1 | (uintptr_t) *psymp
;
15736 lookup
= (void *) val
;
15741 /* Only add a given psymbol once. */
15742 slot
= htab_find_slot (psyms_seen
, lookup
, INSERT
);
15746 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
15751 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
15752 exception if there is an error. */
15755 write_obstack (FILE *file
, struct obstack
*obstack
)
15757 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
15759 != obstack_object_size (obstack
))
15760 error (_("couldn't data write to file"));
15763 /* Unlink a file if the argument is not NULL. */
15766 unlink_if_set (void *p
)
15768 char **filename
= p
;
15770 unlink (*filename
);
15773 /* A helper struct used when iterating over debug_types. */
15774 struct signatured_type_index_data
15776 struct objfile
*objfile
;
15777 struct mapped_symtab
*symtab
;
15778 struct obstack
*types_list
;
15783 /* A helper function that writes a single signatured_type to an
15787 write_one_signatured_type (void **slot
, void *d
)
15789 struct signatured_type_index_data
*info
= d
;
15790 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
15791 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
15792 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15795 write_psymbols (info
->symtab
,
15797 info
->objfile
->global_psymbols
.list
15798 + psymtab
->globals_offset
,
15799 psymtab
->n_global_syms
, info
->cu_index
,
15801 write_psymbols (info
->symtab
,
15803 info
->objfile
->static_psymbols
.list
15804 + psymtab
->statics_offset
,
15805 psymtab
->n_static_syms
, info
->cu_index
,
15808 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
15809 obstack_grow (info
->types_list
, val
, 8);
15810 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
15811 obstack_grow (info
->types_list
, val
, 8);
15812 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
15813 obstack_grow (info
->types_list
, val
, 8);
15820 /* A cleanup function for an htab_t. */
15823 cleanup_htab (void *arg
)
15828 /* Create an index file for OBJFILE in the directory DIR. */
15831 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15833 struct cleanup
*cleanup
;
15834 char *filename
, *cleanup_filename
;
15835 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15836 struct obstack cu_list
, types_cu_list
;
15839 struct mapped_symtab
*symtab
;
15840 offset_type val
, size_of_contents
, total_len
;
15844 htab_t cu_index_htab
;
15845 struct psymtab_cu_index_map
*psymtab_cu_index_map
;
15847 if (!objfile
->psymtabs
|| !objfile
->psymtabs_addrmap
)
15850 if (dwarf2_per_objfile
->using_index
)
15851 error (_("Cannot use an index to create the index"));
15853 if (stat (objfile
->name
, &st
) < 0)
15854 perror_with_name (objfile
->name
);
15856 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15857 INDEX_SUFFIX
, (char *) NULL
);
15858 cleanup
= make_cleanup (xfree
, filename
);
15860 out_file
= fopen (filename
, "wb");
15862 error (_("Can't open `%s' for writing"), filename
);
15864 cleanup_filename
= filename
;
15865 make_cleanup (unlink_if_set
, &cleanup_filename
);
15867 symtab
= create_mapped_symtab ();
15868 make_cleanup (cleanup_mapped_symtab
, symtab
);
15870 obstack_init (&addr_obstack
);
15871 make_cleanup_obstack_free (&addr_obstack
);
15873 obstack_init (&cu_list
);
15874 make_cleanup_obstack_free (&cu_list
);
15876 obstack_init (&types_cu_list
);
15877 make_cleanup_obstack_free (&types_cu_list
);
15879 psyms_seen
= htab_create_alloc (100, htab_hash_pointer
, htab_eq_pointer
,
15880 NULL
, xcalloc
, xfree
);
15881 make_cleanup (cleanup_htab
, psyms_seen
);
15883 /* While we're scanning CU's create a table that maps a psymtab pointer
15884 (which is what addrmap records) to its index (which is what is recorded
15885 in the index file). This will later be needed to write the address
15887 cu_index_htab
= htab_create_alloc (100,
15888 hash_psymtab_cu_index
,
15889 eq_psymtab_cu_index
,
15890 NULL
, xcalloc
, xfree
);
15891 make_cleanup (cleanup_htab
, cu_index_htab
);
15892 psymtab_cu_index_map
= (struct psymtab_cu_index_map
*)
15893 xmalloc (sizeof (struct psymtab_cu_index_map
)
15894 * dwarf2_per_objfile
->n_comp_units
);
15895 make_cleanup (xfree
, psymtab_cu_index_map
);
15897 /* The CU list is already sorted, so we don't need to do additional
15898 work here. Also, the debug_types entries do not appear in
15899 all_comp_units, but only in their own hash table. */
15900 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15902 struct dwarf2_per_cu_data
*per_cu
15903 = dwarf2_per_objfile
->all_comp_units
[i
];
15904 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15906 struct psymtab_cu_index_map
*map
;
15909 write_psymbols (symtab
,
15911 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15912 psymtab
->n_global_syms
, i
,
15914 write_psymbols (symtab
,
15916 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15917 psymtab
->n_static_syms
, i
,
15920 map
= &psymtab_cu_index_map
[i
];
15921 map
->psymtab
= psymtab
;
15923 slot
= htab_find_slot (cu_index_htab
, map
, INSERT
);
15924 gdb_assert (slot
!= NULL
);
15925 gdb_assert (*slot
== NULL
);
15928 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15929 obstack_grow (&cu_list
, val
, 8);
15930 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15931 obstack_grow (&cu_list
, val
, 8);
15934 /* Dump the address map. */
15935 write_address_map (objfile
, &addr_obstack
, cu_index_htab
);
15937 /* Write out the .debug_type entries, if any. */
15938 if (dwarf2_per_objfile
->signatured_types
)
15940 struct signatured_type_index_data sig_data
;
15942 sig_data
.objfile
= objfile
;
15943 sig_data
.symtab
= symtab
;
15944 sig_data
.types_list
= &types_cu_list
;
15945 sig_data
.psyms_seen
= psyms_seen
;
15946 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15947 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15948 write_one_signatured_type
, &sig_data
);
15951 obstack_init (&constant_pool
);
15952 make_cleanup_obstack_free (&constant_pool
);
15953 obstack_init (&symtab_obstack
);
15954 make_cleanup_obstack_free (&symtab_obstack
);
15955 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15957 obstack_init (&contents
);
15958 make_cleanup_obstack_free (&contents
);
15959 size_of_contents
= 6 * sizeof (offset_type
);
15960 total_len
= size_of_contents
;
15962 /* The version number. */
15963 val
= MAYBE_SWAP (5);
15964 obstack_grow (&contents
, &val
, sizeof (val
));
15966 /* The offset of the CU list from the start of the file. */
15967 val
= MAYBE_SWAP (total_len
);
15968 obstack_grow (&contents
, &val
, sizeof (val
));
15969 total_len
+= obstack_object_size (&cu_list
);
15971 /* The offset of the types CU list from the start of the file. */
15972 val
= MAYBE_SWAP (total_len
);
15973 obstack_grow (&contents
, &val
, sizeof (val
));
15974 total_len
+= obstack_object_size (&types_cu_list
);
15976 /* The offset of the address table from the start of the file. */
15977 val
= MAYBE_SWAP (total_len
);
15978 obstack_grow (&contents
, &val
, sizeof (val
));
15979 total_len
+= obstack_object_size (&addr_obstack
);
15981 /* The offset of the symbol table from the start of the file. */
15982 val
= MAYBE_SWAP (total_len
);
15983 obstack_grow (&contents
, &val
, sizeof (val
));
15984 total_len
+= obstack_object_size (&symtab_obstack
);
15986 /* The offset of the constant pool from the start of the file. */
15987 val
= MAYBE_SWAP (total_len
);
15988 obstack_grow (&contents
, &val
, sizeof (val
));
15989 total_len
+= obstack_object_size (&constant_pool
);
15991 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15993 write_obstack (out_file
, &contents
);
15994 write_obstack (out_file
, &cu_list
);
15995 write_obstack (out_file
, &types_cu_list
);
15996 write_obstack (out_file
, &addr_obstack
);
15997 write_obstack (out_file
, &symtab_obstack
);
15998 write_obstack (out_file
, &constant_pool
);
16002 /* We want to keep the file, so we set cleanup_filename to NULL
16003 here. See unlink_if_set. */
16004 cleanup_filename
= NULL
;
16006 do_cleanups (cleanup
);
16009 /* Implementation of the `save gdb-index' command.
16011 Note that the file format used by this command is documented in the
16012 GDB manual. Any changes here must be documented there. */
16015 save_gdb_index_command (char *arg
, int from_tty
)
16017 struct objfile
*objfile
;
16020 error (_("usage: save gdb-index DIRECTORY"));
16022 ALL_OBJFILES (objfile
)
16026 /* If the objfile does not correspond to an actual file, skip it. */
16027 if (stat (objfile
->name
, &st
) < 0)
16030 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
16031 if (dwarf2_per_objfile
)
16033 volatile struct gdb_exception except
;
16035 TRY_CATCH (except
, RETURN_MASK_ERROR
)
16037 write_psymtabs_to_index (objfile
, arg
);
16039 if (except
.reason
< 0)
16040 exception_fprintf (gdb_stderr
, except
,
16041 _("Error while writing index for `%s': "),
16049 int dwarf2_always_disassemble
;
16052 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
16053 struct cmd_list_element
*c
, const char *value
)
16055 fprintf_filtered (file
,
16056 _("Whether to always disassemble "
16057 "DWARF expressions is %s.\n"),
16061 void _initialize_dwarf2_read (void);
16064 _initialize_dwarf2_read (void)
16066 struct cmd_list_element
*c
;
16068 dwarf2_objfile_data_key
16069 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
16071 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
16072 Set DWARF 2 specific variables.\n\
16073 Configure DWARF 2 variables such as the cache size"),
16074 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
16075 0/*allow-unknown*/, &maintenance_set_cmdlist
);
16077 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
16078 Show DWARF 2 specific variables\n\
16079 Show DWARF 2 variables such as the cache size"),
16080 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
16081 0/*allow-unknown*/, &maintenance_show_cmdlist
);
16083 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
16084 &dwarf2_max_cache_age
, _("\
16085 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
16086 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
16087 A higher limit means that cached compilation units will be stored\n\
16088 in memory longer, and more total memory will be used. Zero disables\n\
16089 caching, which can slow down startup."),
16091 show_dwarf2_max_cache_age
,
16092 &set_dwarf2_cmdlist
,
16093 &show_dwarf2_cmdlist
);
16095 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
16096 &dwarf2_always_disassemble
, _("\
16097 Set whether `info address' always disassembles DWARF expressions."), _("\
16098 Show whether `info address' always disassembles DWARF expressions."), _("\
16099 When enabled, DWARF expressions are always printed in an assembly-like\n\
16100 syntax. When disabled, expressions will be printed in a more\n\
16101 conversational style, when possible."),
16103 show_dwarf2_always_disassemble
,
16104 &set_dwarf2_cmdlist
,
16105 &show_dwarf2_cmdlist
);
16107 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
16108 Set debugging of the dwarf2 DIE reader."), _("\
16109 Show debugging of the dwarf2 DIE reader."), _("\
16110 When enabled (non-zero), DIEs are dumped after they are read in.\n\
16111 The value is the maximum depth to print."),
16114 &setdebuglist
, &showdebuglist
);
16116 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
16118 Save a gdb-index file.\n\
16119 Usage: save gdb-index DIRECTORY"),
16121 set_cmd_completer (c
, filename_completer
);