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
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"
62 #include "gdb_string.h"
63 #include "gdb_assert.h"
64 #include <sys/types.h>
71 #define MAP_FAILED ((void *) -1)
75 typedef struct symbol
*symbolp
;
79 /* .debug_info header for a compilation unit
80 Because of alignment constraints, this structure has padding and cannot
81 be mapped directly onto the beginning of the .debug_info section. */
82 typedef struct comp_unit_header
84 unsigned int length
; /* length of the .debug_info
86 unsigned short version
; /* version number -- 2 for DWARF
88 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
89 unsigned char addr_size
; /* byte size of an address -- 4 */
92 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
95 /* .debug_line statement program prologue
96 Because of alignment constraints, this structure has padding and cannot
97 be mapped directly onto the beginning of the .debug_info section. */
98 typedef struct statement_prologue
100 unsigned int total_length
; /* byte length of the statement
102 unsigned short version
; /* version number -- 2 for DWARF
104 unsigned int prologue_length
; /* # bytes between prologue &
106 unsigned char minimum_instruction_length
; /* byte size of
108 unsigned char default_is_stmt
; /* initial value of is_stmt
111 unsigned char line_range
;
112 unsigned char opcode_base
; /* number assigned to first special
114 unsigned char *standard_opcode_lengths
;
118 /* When non-zero, dump DIEs after they are read in. */
119 static int dwarf2_die_debug
= 0;
123 /* When set, the file that we're processing is known to have debugging
124 info for C++ namespaces. GCC 3.3.x did not produce this information,
125 but later versions do. */
127 static int processing_has_namespace_info
;
129 static const struct objfile_data
*dwarf2_objfile_data_key
;
131 struct dwarf2_section_info
137 /* True if we have tried to read this section. */
141 /* All offsets in the index are of this type. It must be
142 architecture-independent. */
143 typedef uint32_t offset_type
;
145 DEF_VEC_I (offset_type
);
147 /* A description of the mapped index. The file format is described in
148 a comment by the code that writes the index. */
151 /* The total length of the buffer. */
153 /* A pointer to the address table data. */
154 const gdb_byte
*address_table
;
155 /* Size of the address table data in bytes. */
156 offset_type address_table_size
;
157 /* The hash table. */
158 const offset_type
*index_table
;
159 /* Size in slots, each slot is 2 offset_types. */
160 offset_type index_table_slots
;
161 /* A pointer to the constant pool. */
162 const char *constant_pool
;
165 struct dwarf2_per_objfile
167 struct dwarf2_section_info info
;
168 struct dwarf2_section_info abbrev
;
169 struct dwarf2_section_info line
;
170 struct dwarf2_section_info loc
;
171 struct dwarf2_section_info macinfo
;
172 struct dwarf2_section_info str
;
173 struct dwarf2_section_info ranges
;
174 struct dwarf2_section_info types
;
175 struct dwarf2_section_info frame
;
176 struct dwarf2_section_info eh_frame
;
177 struct dwarf2_section_info gdb_index
;
180 struct objfile
*objfile
;
182 /* A list of all the compilation units. This is used to locate
183 the target compilation unit of a particular reference. */
184 struct dwarf2_per_cu_data
**all_comp_units
;
186 /* The number of compilation units in ALL_COMP_UNITS. */
189 /* The number of .debug_types-related CUs. */
190 int n_type_comp_units
;
192 /* The .debug_types-related CUs. */
193 struct dwarf2_per_cu_data
**type_comp_units
;
195 /* A chain of compilation units that are currently read in, so that
196 they can be freed later. */
197 struct dwarf2_per_cu_data
*read_in_chain
;
199 /* A table mapping .debug_types signatures to its signatured_type entry.
200 This is NULL if the .debug_types section hasn't been read in yet. */
201 htab_t signatured_types
;
203 /* A flag indicating wether this objfile has a section loaded at a
205 int has_section_at_zero
;
207 /* True if we are using the mapped index. */
208 unsigned char using_index
;
210 /* The mapped index. */
211 struct mapped_index
*index_table
;
213 /* Set during partial symbol reading, to prevent queueing of full
215 int reading_partial_symbols
;
217 /* Table mapping type .debug_info DIE offsets to types.
218 This is NULL if not allocated yet.
219 It (currently) makes sense to allocate debug_types_type_hash lazily.
220 To keep things simple we allocate both lazily. */
221 htab_t debug_info_type_hash
;
223 /* Table mapping type .debug_types DIE offsets to types.
224 This is NULL if not allocated yet. */
225 htab_t debug_types_type_hash
;
228 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
230 /* names of the debugging sections */
232 /* Note that if the debugging section has been compressed, it might
233 have a name like .zdebug_info. */
235 #define INFO_SECTION "debug_info"
236 #define ABBREV_SECTION "debug_abbrev"
237 #define LINE_SECTION "debug_line"
238 #define LOC_SECTION "debug_loc"
239 #define MACINFO_SECTION "debug_macinfo"
240 #define STR_SECTION "debug_str"
241 #define RANGES_SECTION "debug_ranges"
242 #define TYPES_SECTION "debug_types"
243 #define FRAME_SECTION "debug_frame"
244 #define EH_FRAME_SECTION "eh_frame"
245 #define GDB_INDEX_SECTION "gdb_index"
247 /* local data types */
249 /* We hold several abbreviation tables in memory at the same time. */
250 #ifndef ABBREV_HASH_SIZE
251 #define ABBREV_HASH_SIZE 121
254 /* The data in a compilation unit header, after target2host
255 translation, looks like this. */
256 struct comp_unit_head
260 unsigned char addr_size
;
261 unsigned char signed_addr_p
;
262 unsigned int abbrev_offset
;
264 /* Size of file offsets; either 4 or 8. */
265 unsigned int offset_size
;
267 /* Size of the length field; either 4 or 12. */
268 unsigned int initial_length_size
;
270 /* Offset to the first byte of this compilation unit header in the
271 .debug_info section, for resolving relative reference dies. */
274 /* Offset to first die in this cu from the start of the cu.
275 This will be the first byte following the compilation unit header. */
276 unsigned int first_die_offset
;
279 /* Type used for delaying computation of method physnames.
280 See comments for compute_delayed_physnames. */
281 struct delayed_method_info
283 /* The type to which the method is attached, i.e., its parent class. */
286 /* The index of the method in the type's function fieldlists. */
289 /* The index of the method in the fieldlist. */
292 /* The name of the DIE. */
295 /* The DIE associated with this method. */
296 struct die_info
*die
;
299 typedef struct delayed_method_info delayed_method_info
;
300 DEF_VEC_O (delayed_method_info
);
302 /* Internal state when decoding a particular compilation unit. */
305 /* The objfile containing this compilation unit. */
306 struct objfile
*objfile
;
308 /* The header of the compilation unit. */
309 struct comp_unit_head header
;
311 /* Base address of this compilation unit. */
312 CORE_ADDR base_address
;
314 /* Non-zero if base_address has been set. */
317 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
319 /* The language we are debugging. */
320 enum language language
;
321 const struct language_defn
*language_defn
;
323 const char *producer
;
325 /* The generic symbol table building routines have separate lists for
326 file scope symbols and all all other scopes (local scopes). So
327 we need to select the right one to pass to add_symbol_to_list().
328 We do it by keeping a pointer to the correct list in list_in_scope.
330 FIXME: The original dwarf code just treated the file scope as the
331 first local scope, and all other local scopes as nested local
332 scopes, and worked fine. Check to see if we really need to
333 distinguish these in buildsym.c. */
334 struct pending
**list_in_scope
;
336 /* DWARF abbreviation table associated with this compilation unit. */
337 struct abbrev_info
**dwarf2_abbrevs
;
339 /* Storage for the abbrev table. */
340 struct obstack abbrev_obstack
;
342 /* Hash table holding all the loaded partial DIEs. */
345 /* Storage for things with the same lifetime as this read-in compilation
346 unit, including partial DIEs. */
347 struct obstack comp_unit_obstack
;
349 /* When multiple dwarf2_cu structures are living in memory, this field
350 chains them all together, so that they can be released efficiently.
351 We will probably also want a generation counter so that most-recently-used
352 compilation units are cached... */
353 struct dwarf2_per_cu_data
*read_in_chain
;
355 /* Backchain to our per_cu entry if the tree has been built. */
356 struct dwarf2_per_cu_data
*per_cu
;
358 /* How many compilation units ago was this CU last referenced? */
361 /* A hash table of die offsets for following references. */
364 /* Full DIEs if read in. */
365 struct die_info
*dies
;
367 /* A set of pointers to dwarf2_per_cu_data objects for compilation
368 units referenced by this one. Only set during full symbol processing;
369 partial symbol tables do not have dependencies. */
372 /* Header data from the line table, during full symbol processing. */
373 struct line_header
*line_header
;
375 /* A list of methods which need to have physnames computed
376 after all type information has been read. */
377 VEC (delayed_method_info
) *method_list
;
379 /* Mark used when releasing cached dies. */
380 unsigned int mark
: 1;
382 /* This flag will be set if this compilation unit might include
383 inter-compilation-unit references. */
384 unsigned int has_form_ref_addr
: 1;
386 /* This flag will be set if this compilation unit includes any
387 DW_TAG_namespace DIEs. If we know that there are explicit
388 DIEs for namespaces, we don't need to try to infer them
389 from mangled names. */
390 unsigned int has_namespace_info
: 1;
393 /* When using the index (and thus not using psymtabs), each CU has an
394 object of this type. This is used to hold information needed by
395 the various "quick" methods. */
396 struct dwarf2_per_cu_quick_data
398 /* The line table. This can be NULL if there was no line table. */
399 struct line_header
*lines
;
401 /* The file names from the line table. */
402 const char **file_names
;
403 /* The file names from the line table after being run through
405 const char **full_names
;
407 /* The corresponding symbol table. This is NULL if symbols for this
408 CU have not yet been read. */
409 struct symtab
*symtab
;
411 /* A temporary mark bit used when iterating over all CUs in
412 expand_symtabs_matching. */
413 unsigned int mark
: 1;
415 /* True if we've tried to read the line table. */
416 unsigned int read_lines
: 1;
419 /* Persistent data held for a compilation unit, even when not
420 processing it. We put a pointer to this structure in the
421 read_symtab_private field of the psymtab. If we encounter
422 inter-compilation-unit references, we also maintain a sorted
423 list of all compilation units. */
425 struct dwarf2_per_cu_data
427 /* The start offset and length of this compilation unit. 2**29-1
428 bytes should suffice to store the length of any compilation unit
429 - if it doesn't, GDB will fall over anyway.
430 NOTE: Unlike comp_unit_head.length, this length includes
431 initial_length_size. */
433 unsigned int length
: 29;
435 /* Flag indicating this compilation unit will be read in before
436 any of the current compilation units are processed. */
437 unsigned int queued
: 1;
439 /* This flag will be set if we need to load absolutely all DIEs
440 for this compilation unit, instead of just the ones we think
441 are interesting. It gets set if we look for a DIE in the
442 hash table and don't find it. */
443 unsigned int load_all_dies
: 1;
445 /* Non-zero if this CU is from .debug_types.
446 Otherwise it's from .debug_info. */
447 unsigned int from_debug_types
: 1;
449 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
450 of the CU cache it gets reset to NULL again. */
451 struct dwarf2_cu
*cu
;
453 /* The corresponding objfile. */
454 struct objfile
*objfile
;
456 /* When using partial symbol tables, the 'psymtab' field is active.
457 Otherwise the 'quick' field is active. */
460 /* The partial symbol table associated with this compilation unit,
461 or NULL for partial units (which do not have an associated
463 struct partial_symtab
*psymtab
;
465 /* Data needed by the "quick" functions. */
466 struct dwarf2_per_cu_quick_data
*quick
;
470 /* Entry in the signatured_types hash table. */
472 struct signatured_type
476 /* Offset in .debug_types of the TU (type_unit) for this type. */
479 /* Offset in .debug_types of the type defined by this TU. */
480 unsigned int type_offset
;
482 /* The CU(/TU) of this type. */
483 struct dwarf2_per_cu_data per_cu
;
486 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
487 which are used for both .debug_info and .debug_types dies.
488 All parameters here are unchanging for the life of the call.
489 This struct exists to abstract away the constant parameters of
492 struct die_reader_specs
494 /* The bfd of this objfile. */
497 /* The CU of the DIE we are parsing. */
498 struct dwarf2_cu
*cu
;
500 /* Pointer to start of section buffer.
501 This is either the start of .debug_info or .debug_types. */
502 const gdb_byte
*buffer
;
505 /* The line number information for a compilation unit (found in the
506 .debug_line section) begins with a "statement program header",
507 which contains the following information. */
510 unsigned int total_length
;
511 unsigned short version
;
512 unsigned int header_length
;
513 unsigned char minimum_instruction_length
;
514 unsigned char maximum_ops_per_instruction
;
515 unsigned char default_is_stmt
;
517 unsigned char line_range
;
518 unsigned char opcode_base
;
520 /* standard_opcode_lengths[i] is the number of operands for the
521 standard opcode whose value is i. This means that
522 standard_opcode_lengths[0] is unused, and the last meaningful
523 element is standard_opcode_lengths[opcode_base - 1]. */
524 unsigned char *standard_opcode_lengths
;
526 /* The include_directories table. NOTE! These strings are not
527 allocated with xmalloc; instead, they are pointers into
528 debug_line_buffer. If you try to free them, `free' will get
530 unsigned int num_include_dirs
, include_dirs_size
;
533 /* The file_names table. NOTE! These strings are not allocated
534 with xmalloc; instead, they are pointers into debug_line_buffer.
535 Don't try to free them directly. */
536 unsigned int num_file_names
, file_names_size
;
540 unsigned int dir_index
;
541 unsigned int mod_time
;
543 int included_p
; /* Non-zero if referenced by the Line Number Program. */
544 struct symtab
*symtab
; /* The associated symbol table, if any. */
547 /* The start and end of the statement program following this
548 header. These point into dwarf2_per_objfile->line_buffer. */
549 gdb_byte
*statement_program_start
, *statement_program_end
;
552 /* When we construct a partial symbol table entry we only
553 need this much information. */
554 struct partial_die_info
556 /* Offset of this DIE. */
559 /* DWARF-2 tag for this DIE. */
560 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
562 /* Assorted flags describing the data found in this DIE. */
563 unsigned int has_children
: 1;
564 unsigned int is_external
: 1;
565 unsigned int is_declaration
: 1;
566 unsigned int has_type
: 1;
567 unsigned int has_specification
: 1;
568 unsigned int has_pc_info
: 1;
570 /* Flag set if the SCOPE field of this structure has been
572 unsigned int scope_set
: 1;
574 /* Flag set if the DIE has a byte_size attribute. */
575 unsigned int has_byte_size
: 1;
577 /* Flag set if any of the DIE's children are template arguments. */
578 unsigned int has_template_arguments
: 1;
580 /* The name of this DIE. Normally the value of DW_AT_name, but
581 sometimes a default name for unnamed DIEs. */
584 /* The scope to prepend to our children. This is generally
585 allocated on the comp_unit_obstack, so will disappear
586 when this compilation unit leaves the cache. */
589 /* The location description associated with this DIE, if any. */
590 struct dwarf_block
*locdesc
;
592 /* If HAS_PC_INFO, the PC range associated with this DIE. */
596 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
597 DW_AT_sibling, if any. */
600 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
601 DW_AT_specification (or DW_AT_abstract_origin or
603 unsigned int spec_offset
;
605 /* Pointers to this DIE's parent, first child, and next sibling,
607 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
610 /* This data structure holds the information of an abbrev. */
613 unsigned int number
; /* number identifying abbrev */
614 enum dwarf_tag tag
; /* dwarf tag */
615 unsigned short has_children
; /* boolean */
616 unsigned short num_attrs
; /* number of attributes */
617 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
618 struct abbrev_info
*next
; /* next in chain */
623 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
624 ENUM_BITFIELD(dwarf_form
) form
: 16;
627 /* Attributes have a name and a value */
630 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
631 ENUM_BITFIELD(dwarf_form
) form
: 15;
633 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
634 field should be in u.str (existing only for DW_STRING) but it is kept
635 here for better struct attribute alignment. */
636 unsigned int string_is_canonical
: 1;
641 struct dwarf_block
*blk
;
645 struct signatured_type
*signatured_type
;
650 /* This data structure holds a complete die structure. */
653 /* DWARF-2 tag for this DIE. */
654 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
656 /* Number of attributes */
657 unsigned char num_attrs
;
659 /* True if we're presently building the full type name for the
660 type derived from this DIE. */
661 unsigned char building_fullname
: 1;
666 /* Offset in .debug_info or .debug_types section. */
669 /* The dies in a compilation unit form an n-ary tree. PARENT
670 points to this die's parent; CHILD points to the first child of
671 this node; and all the children of a given node are chained
672 together via their SIBLING fields, terminated by a die whose
674 struct die_info
*child
; /* Its first child, if any. */
675 struct die_info
*sibling
; /* Its next sibling, if any. */
676 struct die_info
*parent
; /* Its parent, if any. */
678 /* An array of attributes, with NUM_ATTRS elements. There may be
679 zero, but it's not common and zero-sized arrays are not
680 sufficiently portable C. */
681 struct attribute attrs
[1];
684 struct function_range
687 CORE_ADDR lowpc
, highpc
;
689 struct function_range
*next
;
692 /* Get at parts of an attribute structure */
694 #define DW_STRING(attr) ((attr)->u.str)
695 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
696 #define DW_UNSND(attr) ((attr)->u.unsnd)
697 #define DW_BLOCK(attr) ((attr)->u.blk)
698 #define DW_SND(attr) ((attr)->u.snd)
699 #define DW_ADDR(attr) ((attr)->u.addr)
700 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
702 /* Blocks are a bunch of untyped bytes. */
709 #ifndef ATTR_ALLOC_CHUNK
710 #define ATTR_ALLOC_CHUNK 4
713 /* Allocate fields for structs, unions and enums in this size. */
714 #ifndef DW_FIELD_ALLOC_CHUNK
715 #define DW_FIELD_ALLOC_CHUNK 4
718 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
719 but this would require a corresponding change in unpack_field_as_long
721 static int bits_per_byte
= 8;
723 /* The routines that read and process dies for a C struct or C++ class
724 pass lists of data member fields and lists of member function fields
725 in an instance of a field_info structure, as defined below. */
728 /* List of data member and baseclasses fields. */
731 struct nextfield
*next
;
736 *fields
, *baseclasses
;
738 /* Number of fields (including baseclasses). */
741 /* Number of baseclasses. */
744 /* Set if the accesibility of one of the fields is not public. */
745 int non_public_fields
;
747 /* Member function fields array, entries are allocated in the order they
748 are encountered in the object file. */
751 struct nextfnfield
*next
;
752 struct fn_field fnfield
;
756 /* Member function fieldlist array, contains name of possibly overloaded
757 member function, number of overloaded member functions and a pointer
758 to the head of the member function field chain. */
763 struct nextfnfield
*head
;
767 /* Number of entries in the fnfieldlists array. */
770 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
771 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
772 struct typedef_field_list
774 struct typedef_field field
;
775 struct typedef_field_list
*next
;
778 unsigned typedef_field_list_count
;
781 /* One item on the queue of compilation units to read in full symbols
783 struct dwarf2_queue_item
785 struct dwarf2_per_cu_data
*per_cu
;
786 struct dwarf2_queue_item
*next
;
789 /* The current queue. */
790 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
792 /* Loaded secondary compilation units are kept in memory until they
793 have not been referenced for the processing of this many
794 compilation units. Set this to zero to disable caching. Cache
795 sizes of up to at least twenty will improve startup time for
796 typical inter-CU-reference binaries, at an obvious memory cost. */
797 static int dwarf2_max_cache_age
= 5;
799 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
800 struct cmd_list_element
*c
, const char *value
)
802 fprintf_filtered (file
, _("\
803 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
808 /* Various complaints about symbol reading that don't abort the process */
811 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
813 complaint (&symfile_complaints
,
814 _("statement list doesn't fit in .debug_line section"));
818 dwarf2_debug_line_missing_file_complaint (void)
820 complaint (&symfile_complaints
,
821 _(".debug_line section has line data without a file"));
825 dwarf2_debug_line_missing_end_sequence_complaint (void)
827 complaint (&symfile_complaints
,
828 _(".debug_line section has line program sequence without an end"));
832 dwarf2_complex_location_expr_complaint (void)
834 complaint (&symfile_complaints
, _("location expression too complex"));
838 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
841 complaint (&symfile_complaints
,
842 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
847 dwarf2_macros_too_long_complaint (void)
849 complaint (&symfile_complaints
,
850 _("macro info runs off end of `.debug_macinfo' section"));
854 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
856 complaint (&symfile_complaints
,
857 _("macro debug info contains a malformed macro definition:\n`%s'"),
862 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
864 complaint (&symfile_complaints
,
865 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
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
*, char *, bfd
*,
1004 struct dwarf2_cu
*, struct partial_symtab
*);
1006 static void dwarf2_start_subfile (char *, char *, 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
*, struct dwarf2_cu
*);
1031 static void set_descriptive_type (struct type
*, struct die_info
*,
1032 struct dwarf2_cu
*);
1034 static struct type
*die_containing_type (struct die_info
*,
1035 struct dwarf2_cu
*);
1037 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1038 struct dwarf2_cu
*);
1040 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1042 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1044 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1046 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1047 const char *suffix
, int physname
,
1048 struct dwarf2_cu
*cu
);
1050 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1052 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1054 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1056 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1058 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1059 struct dwarf2_cu
*, struct partial_symtab
*);
1061 static int dwarf2_get_pc_bounds (struct die_info
*,
1062 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1063 struct partial_symtab
*);
1065 static void get_scope_pc_bounds (struct die_info
*,
1066 CORE_ADDR
*, CORE_ADDR
*,
1067 struct dwarf2_cu
*);
1069 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1070 CORE_ADDR
, struct dwarf2_cu
*);
1072 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1073 struct dwarf2_cu
*);
1075 static void dwarf2_attach_fields_to_type (struct field_info
*,
1076 struct type
*, struct dwarf2_cu
*);
1078 static void dwarf2_add_member_fn (struct field_info
*,
1079 struct die_info
*, struct type
*,
1080 struct dwarf2_cu
*);
1082 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1083 struct type
*, struct dwarf2_cu
*);
1085 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1087 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1089 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1091 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1093 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1095 static struct type
*read_module_type (struct die_info
*die
,
1096 struct dwarf2_cu
*cu
);
1098 static const char *namespace_name (struct die_info
*die
,
1099 int *is_anonymous
, struct dwarf2_cu
*);
1101 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1103 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1105 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1106 struct dwarf2_cu
*);
1108 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1110 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1112 gdb_byte
**new_info_ptr
,
1113 struct die_info
*parent
);
1115 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1117 gdb_byte
**new_info_ptr
,
1118 struct die_info
*parent
);
1120 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1122 gdb_byte
**new_info_ptr
,
1123 struct die_info
*parent
);
1125 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1126 struct die_info
**, gdb_byte
*,
1129 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1131 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1134 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1136 static const char *dwarf2_full_name (char *name
,
1137 struct die_info
*die
,
1138 struct dwarf2_cu
*cu
);
1140 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1141 struct dwarf2_cu
**);
1143 static char *dwarf_tag_name (unsigned int);
1145 static char *dwarf_attr_name (unsigned int);
1147 static char *dwarf_form_name (unsigned int);
1149 static char *dwarf_bool_name (unsigned int);
1151 static char *dwarf_type_encoding_name (unsigned int);
1154 static char *dwarf_cfi_name (unsigned int);
1157 static struct die_info
*sibling_die (struct die_info
*);
1159 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1161 static void dump_die_for_error (struct die_info
*);
1163 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1166 /*static*/ void dump_die (struct die_info
*, int max_level
);
1168 static void store_in_ref_table (struct die_info
*,
1169 struct dwarf2_cu
*);
1171 static int is_ref_attr (struct attribute
*);
1173 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1175 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1177 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1179 struct dwarf2_cu
**);
1181 static struct die_info
*follow_die_ref (struct die_info
*,
1183 struct dwarf2_cu
**);
1185 static struct die_info
*follow_die_sig (struct die_info
*,
1187 struct dwarf2_cu
**);
1189 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1190 unsigned int offset
);
1192 static void read_signatured_type (struct objfile
*,
1193 struct signatured_type
*type_sig
);
1195 /* memory allocation interface */
1197 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1199 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1201 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1203 static void initialize_cu_func_list (struct dwarf2_cu
*);
1205 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1206 struct dwarf2_cu
*);
1208 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1209 char *, bfd
*, struct dwarf2_cu
*);
1211 static int attr_form_is_block (struct attribute
*);
1213 static int attr_form_is_section_offset (struct attribute
*);
1215 static int attr_form_is_constant (struct attribute
*);
1217 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1219 struct dwarf2_cu
*cu
);
1221 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1222 struct abbrev_info
*abbrev
,
1223 struct dwarf2_cu
*cu
);
1225 static void free_stack_comp_unit (void *);
1227 static hashval_t
partial_die_hash (const void *item
);
1229 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1231 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1232 (unsigned int offset
, struct objfile
*objfile
);
1234 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1235 (unsigned int offset
, struct objfile
*objfile
);
1237 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1239 static void free_one_comp_unit (void *);
1241 static void free_cached_comp_units (void *);
1243 static void age_cached_comp_units (void);
1245 static void free_one_cached_comp_unit (void *);
1247 static struct type
*set_die_type (struct die_info
*, struct type
*,
1248 struct dwarf2_cu
*);
1250 static void create_all_comp_units (struct objfile
*);
1252 static int create_debug_types_hash_table (struct objfile
*objfile
);
1254 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1257 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1259 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1260 struct dwarf2_per_cu_data
*);
1262 static void dwarf2_mark (struct dwarf2_cu
*);
1264 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1266 static struct type
*get_die_type_at_offset (unsigned int,
1267 struct dwarf2_per_cu_data
*per_cu
);
1269 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1271 static void dwarf2_release_queue (void *dummy
);
1273 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1274 struct objfile
*objfile
);
1276 static void process_queue (struct objfile
*objfile
);
1278 static void find_file_and_directory (struct die_info
*die
,
1279 struct dwarf2_cu
*cu
,
1280 char **name
, char **comp_dir
);
1282 static char *file_full_name (int file
, struct line_header
*lh
,
1283 const char *comp_dir
);
1285 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1288 unsigned int buffer_size
,
1291 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1292 struct dwarf2_cu
*cu
);
1294 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1298 /* Convert VALUE between big- and little-endian. */
1300 byte_swap (offset_type value
)
1304 result
= (value
& 0xff) << 24;
1305 result
|= (value
& 0xff00) << 8;
1306 result
|= (value
& 0xff0000) >> 8;
1307 result
|= (value
& 0xff000000) >> 24;
1311 #define MAYBE_SWAP(V) byte_swap (V)
1314 #define MAYBE_SWAP(V) (V)
1315 #endif /* WORDS_BIGENDIAN */
1317 /* The suffix for an index file. */
1318 #define INDEX_SUFFIX ".gdb-index"
1320 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1321 struct dwarf2_cu
*cu
);
1323 /* Try to locate the sections we need for DWARF 2 debugging
1324 information and return true if we have enough to do something. */
1327 dwarf2_has_info (struct objfile
*objfile
)
1329 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1330 if (!dwarf2_per_objfile
)
1332 /* Initialize per-objfile state. */
1333 struct dwarf2_per_objfile
*data
1334 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1336 memset (data
, 0, sizeof (*data
));
1337 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1338 dwarf2_per_objfile
= data
;
1340 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1341 dwarf2_per_objfile
->objfile
= objfile
;
1343 return (dwarf2_per_objfile
->info
.asection
!= NULL
1344 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1347 /* When loading sections, we can either look for ".<name>", or for
1348 * ".z<name>", which indicates a compressed section. */
1351 section_is_p (const char *section_name
, const char *name
)
1353 return (section_name
[0] == '.'
1354 && (strcmp (section_name
+ 1, name
) == 0
1355 || (section_name
[1] == 'z'
1356 && strcmp (section_name
+ 2, name
) == 0)));
1359 /* This function is mapped across the sections and remembers the
1360 offset and size of each of the debugging sections we are interested
1364 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1366 if (section_is_p (sectp
->name
, INFO_SECTION
))
1368 dwarf2_per_objfile
->info
.asection
= sectp
;
1369 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1371 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1373 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1374 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1376 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1378 dwarf2_per_objfile
->line
.asection
= sectp
;
1379 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1381 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1383 dwarf2_per_objfile
->loc
.asection
= sectp
;
1384 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1386 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1388 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1389 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1391 else if (section_is_p (sectp
->name
, STR_SECTION
))
1393 dwarf2_per_objfile
->str
.asection
= sectp
;
1394 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1396 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1398 dwarf2_per_objfile
->frame
.asection
= sectp
;
1399 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1401 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1403 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1405 if (aflag
& SEC_HAS_CONTENTS
)
1407 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1408 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1411 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1413 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1414 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1416 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1418 dwarf2_per_objfile
->types
.asection
= sectp
;
1419 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1421 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1423 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1424 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1427 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1428 && bfd_section_vma (abfd
, sectp
) == 0)
1429 dwarf2_per_objfile
->has_section_at_zero
= 1;
1432 /* Decompress a section that was compressed using zlib. Store the
1433 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1436 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1437 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1439 bfd
*abfd
= objfile
->obfd
;
1441 error (_("Support for zlib-compressed DWARF data (from '%s') "
1442 "is disabled in this copy of GDB"),
1443 bfd_get_filename (abfd
));
1445 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1446 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1447 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1448 bfd_size_type uncompressed_size
;
1449 gdb_byte
*uncompressed_buffer
;
1452 int header_size
= 12;
1454 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1455 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1456 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1457 bfd_get_filename (abfd
));
1459 /* Read the zlib header. In this case, it should be "ZLIB" followed
1460 by the uncompressed section size, 8 bytes in big-endian order. */
1461 if (compressed_size
< header_size
1462 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1463 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1464 bfd_get_filename (abfd
));
1465 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1466 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1467 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1468 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1469 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1470 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1471 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1472 uncompressed_size
+= compressed_buffer
[11];
1474 /* It is possible the section consists of several compressed
1475 buffers concatenated together, so we uncompress in a loop. */
1479 strm
.avail_in
= compressed_size
- header_size
;
1480 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1481 strm
.avail_out
= uncompressed_size
;
1482 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1484 rc
= inflateInit (&strm
);
1485 while (strm
.avail_in
> 0)
1488 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1489 bfd_get_filename (abfd
), rc
);
1490 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1491 + (uncompressed_size
- strm
.avail_out
));
1492 rc
= inflate (&strm
, Z_FINISH
);
1493 if (rc
!= Z_STREAM_END
)
1494 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1495 bfd_get_filename (abfd
), rc
);
1496 rc
= inflateReset (&strm
);
1498 rc
= inflateEnd (&strm
);
1500 || strm
.avail_out
!= 0)
1501 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1502 bfd_get_filename (abfd
), rc
);
1504 do_cleanups (cleanup
);
1505 *outbuf
= uncompressed_buffer
;
1506 *outsize
= uncompressed_size
;
1510 /* Read the contents of the section SECTP from object file specified by
1511 OBJFILE, store info about the section into INFO.
1512 If the section is compressed, uncompress it before returning. */
1515 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1517 bfd
*abfd
= objfile
->obfd
;
1518 asection
*sectp
= info
->asection
;
1519 gdb_byte
*buf
, *retbuf
;
1520 unsigned char header
[4];
1524 info
->buffer
= NULL
;
1525 info
->was_mmapped
= 0;
1528 if (info
->asection
== NULL
|| info
->size
== 0)
1531 /* Check if the file has a 4-byte header indicating compression. */
1532 if (info
->size
> sizeof (header
)
1533 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1534 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1536 /* Upon decompression, update the buffer and its size. */
1537 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1539 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1547 pagesize
= getpagesize ();
1549 /* Only try to mmap sections which are large enough: we don't want to
1550 waste space due to fragmentation. Also, only try mmap for sections
1551 without relocations. */
1553 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1555 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1556 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1557 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1558 MAP_PRIVATE
, pg_offset
);
1560 if (retbuf
!= MAP_FAILED
)
1562 info
->was_mmapped
= 1;
1563 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1564 #if HAVE_POSIX_MADVISE
1565 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1572 /* If we get here, we are a normal, not-compressed section. */
1574 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1576 /* When debugging .o files, we may need to apply relocations; see
1577 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1578 We never compress sections in .o files, so we only need to
1579 try this when the section is not compressed. */
1580 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1583 info
->buffer
= retbuf
;
1587 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1588 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1589 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1590 bfd_get_filename (abfd
));
1593 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1597 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1598 asection
**sectp
, gdb_byte
**bufp
,
1599 bfd_size_type
*sizep
)
1601 struct dwarf2_per_objfile
*data
1602 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1603 struct dwarf2_section_info
*info
;
1605 /* We may see an objfile without any DWARF, in which case we just
1614 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1615 info
= &data
->eh_frame
;
1616 else if (section_is_p (section_name
, FRAME_SECTION
))
1617 info
= &data
->frame
;
1619 gdb_assert_not_reached ("unexpected section");
1621 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1622 /* We haven't read this section in yet. Do it now. */
1623 dwarf2_read_section (objfile
, info
);
1625 *sectp
= info
->asection
;
1626 *bufp
= info
->buffer
;
1627 *sizep
= info
->size
;
1632 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1635 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1636 struct dwarf2_per_cu_data
*per_cu
)
1638 struct cleanup
*back_to
;
1640 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1642 queue_comp_unit (per_cu
, objfile
);
1644 if (per_cu
->from_debug_types
)
1645 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1647 load_full_comp_unit (per_cu
, objfile
);
1649 process_queue (objfile
);
1651 /* Age the cache, releasing compilation units that have not
1652 been used recently. */
1653 age_cached_comp_units ();
1655 do_cleanups (back_to
);
1658 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1659 the objfile from which this CU came. Returns the resulting symbol
1661 static struct symtab
*
1662 dw2_instantiate_symtab (struct objfile
*objfile
,
1663 struct dwarf2_per_cu_data
*per_cu
)
1665 if (!per_cu
->v
.quick
->symtab
)
1667 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1668 increment_reading_symtab ();
1669 dw2_do_instantiate_symtab (objfile
, per_cu
);
1670 do_cleanups (back_to
);
1672 return per_cu
->v
.quick
->symtab
;
1675 /* Return the CU given its index. */
1676 static struct dwarf2_per_cu_data
*
1677 dw2_get_cu (int index
)
1679 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1681 index
-= dwarf2_per_objfile
->n_comp_units
;
1682 return dwarf2_per_objfile
->type_comp_units
[index
];
1684 return dwarf2_per_objfile
->all_comp_units
[index
];
1687 /* A helper function that knows how to read a 64-bit value in a way
1688 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1691 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1693 if (sizeof (ULONGEST
) < 8)
1697 /* Ignore the upper 4 bytes if they are all zero. */
1698 for (i
= 0; i
< 4; ++i
)
1699 if (bytes
[i
+ 4] != 0)
1702 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1705 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1709 /* Read the CU list from the mapped index, and use it to create all
1710 the CU objects for this objfile. Return 0 if something went wrong,
1711 1 if everything went ok. */
1713 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1714 offset_type cu_list_elements
)
1718 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1719 dwarf2_per_objfile
->all_comp_units
1720 = obstack_alloc (&objfile
->objfile_obstack
,
1721 dwarf2_per_objfile
->n_comp_units
1722 * sizeof (struct dwarf2_per_cu_data
*));
1724 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1726 struct dwarf2_per_cu_data
*the_cu
;
1727 ULONGEST offset
, length
;
1729 if (!extract_cu_value (cu_list
, &offset
)
1730 || !extract_cu_value (cu_list
+ 8, &length
))
1734 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1735 struct dwarf2_per_cu_data
);
1736 the_cu
->offset
= offset
;
1737 the_cu
->length
= length
;
1738 the_cu
->objfile
= objfile
;
1739 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1740 struct dwarf2_per_cu_quick_data
);
1741 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1747 /* Create the signatured type hash table from the index. */
1750 create_signatured_type_table_from_index (struct objfile
*objfile
,
1751 const gdb_byte
*bytes
,
1752 offset_type elements
)
1755 htab_t sig_types_hash
;
1757 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1758 dwarf2_per_objfile
->type_comp_units
1759 = obstack_alloc (&objfile
->objfile_obstack
,
1760 dwarf2_per_objfile
->n_type_comp_units
1761 * sizeof (struct dwarf2_per_cu_data
*));
1763 sig_types_hash
= allocate_signatured_type_table (objfile
);
1765 for (i
= 0; i
< elements
; i
+= 3)
1767 struct signatured_type
*type_sig
;
1768 ULONGEST offset
, type_offset
, signature
;
1771 if (!extract_cu_value (bytes
, &offset
)
1772 || !extract_cu_value (bytes
+ 8, &type_offset
))
1774 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1777 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1778 struct signatured_type
);
1779 type_sig
->signature
= signature
;
1780 type_sig
->offset
= offset
;
1781 type_sig
->type_offset
= type_offset
;
1782 type_sig
->per_cu
.from_debug_types
= 1;
1783 type_sig
->per_cu
.offset
= offset
;
1784 type_sig
->per_cu
.objfile
= objfile
;
1785 type_sig
->per_cu
.v
.quick
1786 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1787 struct dwarf2_per_cu_quick_data
);
1789 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1792 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1795 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1800 /* Read the address map data from the mapped index, and use it to
1801 populate the objfile's psymtabs_addrmap. */
1803 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1805 const gdb_byte
*iter
, *end
;
1806 struct obstack temp_obstack
;
1807 struct addrmap
*mutable_map
;
1808 struct cleanup
*cleanup
;
1811 obstack_init (&temp_obstack
);
1812 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1813 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1815 iter
= index
->address_table
;
1816 end
= iter
+ index
->address_table_size
;
1818 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1822 ULONGEST hi
, lo
, cu_index
;
1823 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1825 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1827 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1830 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1831 dw2_get_cu (cu_index
));
1834 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1835 &objfile
->objfile_obstack
);
1836 do_cleanups (cleanup
);
1839 /* The hash function for strings in the mapped index. This is the
1840 same as the hashtab.c hash function, but we keep a separate copy to
1841 maintain control over the implementation. This is necessary
1842 because the hash function is tied to the format of the mapped index
1845 mapped_index_string_hash (const void *p
)
1847 const unsigned char *str
= (const unsigned char *) p
;
1851 while ((c
= *str
++) != 0)
1852 r
= r
* 67 + c
- 113;
1857 /* Find a slot in the mapped index INDEX for the object named NAME.
1858 If NAME is found, set *VEC_OUT to point to the CU vector in the
1859 constant pool and return 1. If NAME cannot be found, return 0. */
1861 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1862 offset_type
**vec_out
)
1864 offset_type hash
= mapped_index_string_hash (name
);
1865 offset_type slot
, step
;
1867 slot
= hash
& (index
->index_table_slots
- 1);
1868 step
= ((hash
* 17) & (index
->index_table_slots
- 1)) | 1;
1872 /* Convert a slot number to an offset into the table. */
1873 offset_type i
= 2 * slot
;
1875 if (index
->index_table
[i
] == 0 && index
->index_table
[i
+ 1] == 0)
1878 str
= index
->constant_pool
+ MAYBE_SWAP (index
->index_table
[i
]);
1879 if (!strcmp (name
, str
))
1881 *vec_out
= (offset_type
*) (index
->constant_pool
1882 + MAYBE_SWAP (index
->index_table
[i
+ 1]));
1886 slot
= (slot
+ step
) & (index
->index_table_slots
- 1);
1890 /* Read the index file. If everything went ok, initialize the "quick"
1891 elements of all the CUs and return 1. Otherwise, return 0. */
1893 dwarf2_read_index (struct objfile
*objfile
)
1896 struct mapped_index
*map
;
1897 offset_type
*metadata
;
1898 const gdb_byte
*cu_list
;
1899 const gdb_byte
*types_list
= NULL
;
1900 offset_type version
, cu_list_elements
;
1901 offset_type types_list_elements
= 0;
1904 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1905 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1908 /* Older elfutils strip versions could keep the section in the main
1909 executable while splitting it for the separate debug info file. */
1910 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
1911 & SEC_HAS_CONTENTS
) == 0)
1914 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1916 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1917 /* Version check. */
1918 version
= MAYBE_SWAP (*(offset_type
*) addr
);
1921 /* Index version 1 neglected to account for .debug_types. So,
1922 if we see .debug_types, we cannot use this index. */
1923 if (dwarf2_per_objfile
->types
.asection
!= NULL
1924 && dwarf2_per_objfile
->types
.size
!= 0)
1927 else if (version
!= 2)
1930 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1931 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
1933 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1936 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1937 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
1943 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1944 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
1945 - MAYBE_SWAP (metadata
[i
]))
1950 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
1951 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
1952 - MAYBE_SWAP (metadata
[i
]));
1955 map
->index_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
1956 map
->index_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
1957 - MAYBE_SWAP (metadata
[i
]))
1958 / (2 * sizeof (offset_type
)));
1961 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
1963 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
1967 && types_list_elements
1968 && !create_signatured_type_table_from_index (objfile
, types_list
,
1969 types_list_elements
))
1972 create_addrmap_from_index (objfile
, map
);
1974 dwarf2_per_objfile
->index_table
= map
;
1975 dwarf2_per_objfile
->using_index
= 1;
1980 /* A helper for the "quick" functions which sets the global
1981 dwarf2_per_objfile according to OBJFILE. */
1983 dw2_setup (struct objfile
*objfile
)
1985 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1986 gdb_assert (dwarf2_per_objfile
);
1989 /* A helper for the "quick" functions which attempts to read the line
1990 table for THIS_CU. */
1992 dw2_require_line_header (struct objfile
*objfile
,
1993 struct dwarf2_per_cu_data
*this_cu
)
1995 bfd
*abfd
= objfile
->obfd
;
1996 struct line_header
*lh
= NULL
;
1997 struct attribute
*attr
;
1998 struct cleanup
*cleanups
;
1999 struct die_info
*comp_unit_die
;
2000 struct dwarf2_section_info
* sec
;
2001 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2002 int has_children
, i
;
2003 struct dwarf2_cu cu
;
2004 unsigned int bytes_read
, buffer_size
;
2005 struct die_reader_specs reader_specs
;
2006 char *name
, *comp_dir
;
2008 if (this_cu
->v
.quick
->read_lines
)
2010 this_cu
->v
.quick
->read_lines
= 1;
2012 memset (&cu
, 0, sizeof (cu
));
2013 cu
.objfile
= objfile
;
2014 obstack_init (&cu
.comp_unit_obstack
);
2016 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2018 if (this_cu
->from_debug_types
)
2019 sec
= &dwarf2_per_objfile
->types
;
2021 sec
= &dwarf2_per_objfile
->info
;
2022 dwarf2_read_section (objfile
, sec
);
2023 buffer_size
= sec
->size
;
2024 buffer
= sec
->buffer
;
2025 info_ptr
= buffer
+ this_cu
->offset
;
2026 beg_of_comp_unit
= info_ptr
;
2028 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2029 buffer
, buffer_size
,
2032 /* Complete the cu_header. */
2033 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2034 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2037 cu
.per_cu
= this_cu
;
2039 dwarf2_read_abbrevs (abfd
, &cu
);
2040 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2042 if (this_cu
->from_debug_types
)
2043 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2044 init_cu_die_reader (&reader_specs
, &cu
);
2045 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2048 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2051 unsigned int line_offset
= DW_UNSND (attr
);
2052 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2056 do_cleanups (cleanups
);
2060 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2062 this_cu
->v
.quick
->lines
= lh
;
2064 this_cu
->v
.quick
->file_names
2065 = obstack_alloc (&objfile
->objfile_obstack
,
2066 lh
->num_file_names
* sizeof (char *));
2067 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2068 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2070 do_cleanups (cleanups
);
2073 /* A helper for the "quick" functions which computes and caches the
2074 real path for a given file name from the line table.
2075 dw2_require_line_header must have been called before this is
2078 dw2_require_full_path (struct objfile
*objfile
,
2079 struct dwarf2_per_cu_data
*per_cu
,
2082 if (!per_cu
->v
.quick
->full_names
)
2083 per_cu
->v
.quick
->full_names
2084 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2085 per_cu
->v
.quick
->lines
->num_file_names
,
2088 if (!per_cu
->v
.quick
->full_names
[index
])
2089 per_cu
->v
.quick
->full_names
[index
]
2090 = gdb_realpath (per_cu
->v
.quick
->file_names
[index
]);
2092 return per_cu
->v
.quick
->full_names
[index
];
2095 static struct symtab
*
2096 dw2_find_last_source_symtab (struct objfile
*objfile
)
2099 dw2_setup (objfile
);
2100 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2101 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2105 dw2_forget_cached_source_info (struct objfile
*objfile
)
2109 dw2_setup (objfile
);
2110 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2111 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2113 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2115 if (per_cu
->v
.quick
->full_names
)
2119 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2120 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
2126 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2127 const char *full_path
, const char *real_path
,
2128 struct symtab
**result
)
2131 int check_basename
= lbasename (name
) == name
;
2132 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2134 dw2_setup (objfile
);
2135 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2136 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2139 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2141 if (per_cu
->v
.quick
->symtab
)
2144 dw2_require_line_header (objfile
, per_cu
);
2145 if (!per_cu
->v
.quick
->lines
)
2148 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2150 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2152 if (FILENAME_CMP (name
, this_name
) == 0)
2154 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2158 if (check_basename
&& ! base_cu
2159 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2162 if (full_path
!= NULL
)
2164 const char *this_full_name
= dw2_require_full_path (objfile
,
2168 && FILENAME_CMP (full_path
, this_full_name
) == 0)
2170 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2175 if (real_path
!= NULL
)
2177 const char *this_full_name
= dw2_require_full_path (objfile
,
2180 if (this_full_name
!= NULL
)
2182 char *rp
= gdb_realpath (this_full_name
);
2183 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
2186 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2197 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2204 static struct symtab
*
2205 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2206 const char *name
, domain_enum domain
)
2208 /* We do all the work in the pre_expand_symtabs_matching hook
2213 /* A helper function that expands all symtabs that hold an object
2216 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2218 dw2_setup (objfile
);
2220 if (dwarf2_per_objfile
->index_table
)
2224 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2227 offset_type i
, len
= MAYBE_SWAP (*vec
);
2228 for (i
= 0; i
< len
; ++i
)
2230 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2231 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2233 dw2_instantiate_symtab (objfile
, per_cu
);
2240 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2241 int kind
, const char *name
,
2244 dw2_do_expand_symtabs_matching (objfile
, name
);
2248 dw2_print_stats (struct objfile
*objfile
)
2252 dw2_setup (objfile
);
2254 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2255 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2257 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2259 if (!per_cu
->v
.quick
->symtab
)
2262 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2266 dw2_dump (struct objfile
*objfile
)
2268 /* Nothing worth printing. */
2272 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2273 struct section_offsets
*delta
)
2275 /* There's nothing to relocate here. */
2279 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2280 const char *func_name
)
2282 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2286 dw2_expand_all_symtabs (struct objfile
*objfile
)
2290 dw2_setup (objfile
);
2292 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2293 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2295 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2297 dw2_instantiate_symtab (objfile
, per_cu
);
2302 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2303 const char *filename
)
2307 dw2_setup (objfile
);
2308 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2309 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2312 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2314 if (per_cu
->v
.quick
->symtab
)
2317 dw2_require_line_header (objfile
, per_cu
);
2318 if (!per_cu
->v
.quick
->lines
)
2321 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2323 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2324 if (strcmp (this_name
, filename
) == 0)
2326 dw2_instantiate_symtab (objfile
, per_cu
);
2334 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2336 struct dwarf2_per_cu_data
*per_cu
;
2339 dw2_setup (objfile
);
2341 if (!dwarf2_per_objfile
->index_table
)
2344 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2348 /* Note that this just looks at the very first one named NAME -- but
2349 actually we are looking for a function. find_main_filename
2350 should be rewritten so that it doesn't require a custom hook. It
2351 could just use the ordinary symbol tables. */
2352 /* vec[0] is the length, which must always be >0. */
2353 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2355 dw2_require_line_header (objfile
, per_cu
);
2356 if (!per_cu
->v
.quick
->lines
)
2359 return per_cu
->v
.quick
->file_names
[per_cu
->v
.quick
->lines
->num_file_names
- 1];
2363 dw2_map_ada_symtabs (struct objfile
*objfile
,
2364 int (*wild_match
) (const char *, int, const char *),
2365 int (*is_name_suffix
) (const char *),
2366 void (*callback
) (struct objfile
*,
2367 struct symtab
*, void *),
2368 const char *name
, int global
,
2369 domain_enum
namespace, int wild
,
2372 /* For now, we don't support Ada, so this function can't be
2374 internal_error (__FILE__
, __LINE__
,
2375 _("map_ada_symtabs called via index method"));
2379 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2380 int (*file_matcher
) (const char *, void *),
2381 int (*name_matcher
) (const char *, void *),
2388 dw2_setup (objfile
);
2389 if (!dwarf2_per_objfile
->index_table
)
2392 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2393 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2396 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2398 per_cu
->v
.quick
->mark
= 0;
2399 if (per_cu
->v
.quick
->symtab
)
2402 dw2_require_line_header (objfile
, per_cu
);
2403 if (!per_cu
->v
.quick
->lines
)
2406 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2408 if (file_matcher (per_cu
->v
.quick
->file_names
[j
], data
))
2410 per_cu
->v
.quick
->mark
= 1;
2417 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2420 offset_type idx
= 2 * iter
;
2422 offset_type
*vec
, vec_len
, vec_idx
;
2424 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2425 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2428 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2429 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2431 if (! (*name_matcher
) (name
, data
))
2434 /* The name was matched, now expand corresponding CUs that were
2436 vec
= (offset_type
*) (dwarf2_per_objfile
->index_table
->constant_pool
2437 + dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1]);
2438 vec_len
= MAYBE_SWAP (vec
[0]);
2439 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2441 struct dwarf2_per_cu_data
*per_cu
;
2443 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2444 if (per_cu
->v
.quick
->mark
)
2445 dw2_instantiate_symtab (objfile
, per_cu
);
2450 static struct symtab
*
2451 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2452 struct minimal_symbol
*msymbol
,
2454 struct obj_section
*section
,
2457 struct dwarf2_per_cu_data
*data
;
2459 dw2_setup (objfile
);
2461 if (!objfile
->psymtabs_addrmap
)
2464 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2468 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2469 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2470 paddress (get_objfile_arch (objfile
), pc
));
2472 return dw2_instantiate_symtab (objfile
, data
);
2476 dw2_map_symbol_names (struct objfile
*objfile
,
2477 void (*fun
) (const char *, void *),
2481 dw2_setup (objfile
);
2483 if (!dwarf2_per_objfile
->index_table
)
2487 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2490 offset_type idx
= 2 * iter
;
2492 offset_type
*vec
, vec_len
, vec_idx
;
2494 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2495 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2498 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2499 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2501 (*fun
) (name
, data
);
2506 dw2_map_symbol_filenames (struct objfile
*objfile
,
2507 void (*fun
) (const char *, const char *, void *),
2512 dw2_setup (objfile
);
2513 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2514 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2517 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2519 if (per_cu
->v
.quick
->symtab
)
2522 dw2_require_line_header (objfile
, per_cu
);
2523 if (!per_cu
->v
.quick
->lines
)
2526 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2528 const char *this_full_name
= dw2_require_full_path (objfile
, per_cu
,
2530 (*fun
) (per_cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2536 dw2_has_symbols (struct objfile
*objfile
)
2541 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2544 dw2_find_last_source_symtab
,
2545 dw2_forget_cached_source_info
,
2548 dw2_pre_expand_symtabs_matching
,
2552 dw2_expand_symtabs_for_function
,
2553 dw2_expand_all_symtabs
,
2554 dw2_expand_symtabs_with_filename
,
2555 dw2_find_symbol_file
,
2556 dw2_map_ada_symtabs
,
2557 dw2_expand_symtabs_matching
,
2558 dw2_find_pc_sect_symtab
,
2559 dw2_map_symbol_names
,
2560 dw2_map_symbol_filenames
2563 /* Initialize for reading DWARF for this objfile. Return 0 if this
2564 file will use psymtabs, or 1 if using the GNU index. */
2567 dwarf2_initialize_objfile (struct objfile
*objfile
)
2569 /* If we're about to read full symbols, don't bother with the
2570 indices. In this case we also don't care if some other debug
2571 format is making psymtabs, because they are all about to be
2573 if ((objfile
->flags
& OBJF_READNOW
))
2577 dwarf2_per_objfile
->using_index
= 1;
2578 create_all_comp_units (objfile
);
2579 create_debug_types_hash_table (objfile
);
2581 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2582 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2584 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2586 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2587 struct dwarf2_per_cu_quick_data
);
2590 /* Return 1 so that gdb sees the "quick" functions. However,
2591 these functions will be no-ops because we will have expanded
2596 if (dwarf2_read_index (objfile
))
2599 dwarf2_build_psymtabs (objfile
);
2605 /* Build a partial symbol table. */
2608 dwarf2_build_psymtabs (struct objfile
*objfile
)
2610 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2612 init_psymbol_list (objfile
, 1024);
2615 dwarf2_build_psymtabs_hard (objfile
);
2618 /* Return TRUE if OFFSET is within CU_HEADER. */
2621 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2623 unsigned int bottom
= cu_header
->offset
;
2624 unsigned int top
= (cu_header
->offset
2626 + cu_header
->initial_length_size
);
2628 return (offset
>= bottom
&& offset
< top
);
2631 /* Read in the comp unit header information from the debug_info at info_ptr.
2632 NOTE: This leaves members offset, first_die_offset to be filled in
2636 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2637 gdb_byte
*info_ptr
, bfd
*abfd
)
2640 unsigned int bytes_read
;
2642 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2643 cu_header
->initial_length_size
= bytes_read
;
2644 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2645 info_ptr
+= bytes_read
;
2646 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2648 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2650 info_ptr
+= bytes_read
;
2651 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2653 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2654 if (signed_addr
< 0)
2655 internal_error (__FILE__
, __LINE__
,
2656 _("read_comp_unit_head: dwarf from non elf file"));
2657 cu_header
->signed_addr_p
= signed_addr
;
2663 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2664 gdb_byte
*buffer
, unsigned int buffer_size
,
2667 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2669 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2671 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2672 error (_("Dwarf Error: wrong version in compilation unit header "
2673 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2674 bfd_get_filename (abfd
));
2676 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2677 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2678 "(offset 0x%lx + 6) [in module %s]"),
2679 (long) header
->abbrev_offset
,
2680 (long) (beg_of_comp_unit
- buffer
),
2681 bfd_get_filename (abfd
));
2683 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2684 > buffer
+ buffer_size
)
2685 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2686 "(offset 0x%lx + 0) [in module %s]"),
2687 (long) header
->length
,
2688 (long) (beg_of_comp_unit
- buffer
),
2689 bfd_get_filename (abfd
));
2694 /* Read in the types comp unit header information from .debug_types entry at
2695 types_ptr. The result is a pointer to one past the end of the header. */
2698 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2699 ULONGEST
*signature
,
2700 gdb_byte
*types_ptr
, bfd
*abfd
)
2702 gdb_byte
*initial_types_ptr
= types_ptr
;
2704 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2705 &dwarf2_per_objfile
->types
);
2706 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2708 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2710 *signature
= read_8_bytes (abfd
, types_ptr
);
2712 types_ptr
+= cu_header
->offset_size
;
2713 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2718 /* Allocate a new partial symtab for file named NAME and mark this new
2719 partial symtab as being an include of PST. */
2722 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2723 struct objfile
*objfile
)
2725 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2727 subpst
->section_offsets
= pst
->section_offsets
;
2728 subpst
->textlow
= 0;
2729 subpst
->texthigh
= 0;
2731 subpst
->dependencies
= (struct partial_symtab
**)
2732 obstack_alloc (&objfile
->objfile_obstack
,
2733 sizeof (struct partial_symtab
*));
2734 subpst
->dependencies
[0] = pst
;
2735 subpst
->number_of_dependencies
= 1;
2737 subpst
->globals_offset
= 0;
2738 subpst
->n_global_syms
= 0;
2739 subpst
->statics_offset
= 0;
2740 subpst
->n_static_syms
= 0;
2741 subpst
->symtab
= NULL
;
2742 subpst
->read_symtab
= pst
->read_symtab
;
2745 /* No private part is necessary for include psymtabs. This property
2746 can be used to differentiate between such include psymtabs and
2747 the regular ones. */
2748 subpst
->read_symtab_private
= NULL
;
2751 /* Read the Line Number Program data and extract the list of files
2752 included by the source file represented by PST. Build an include
2753 partial symtab for each of these included files. */
2756 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2757 struct die_info
*die
,
2758 struct partial_symtab
*pst
)
2760 struct objfile
*objfile
= cu
->objfile
;
2761 bfd
*abfd
= objfile
->obfd
;
2762 struct line_header
*lh
= NULL
;
2763 struct attribute
*attr
;
2765 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2768 unsigned int line_offset
= DW_UNSND (attr
);
2770 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2773 return; /* No linetable, so no includes. */
2775 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2776 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2778 free_line_header (lh
);
2782 hash_type_signature (const void *item
)
2784 const struct signatured_type
*type_sig
= item
;
2786 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2787 return type_sig
->signature
;
2791 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2793 const struct signatured_type
*lhs
= item_lhs
;
2794 const struct signatured_type
*rhs
= item_rhs
;
2796 return lhs
->signature
== rhs
->signature
;
2799 /* Allocate a hash table for signatured types. */
2802 allocate_signatured_type_table (struct objfile
*objfile
)
2804 return htab_create_alloc_ex (41,
2805 hash_type_signature
,
2808 &objfile
->objfile_obstack
,
2809 hashtab_obstack_allocate
,
2810 dummy_obstack_deallocate
);
2813 /* A helper function to add a signatured type CU to a list. */
2816 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2818 struct signatured_type
*sigt
= *slot
;
2819 struct dwarf2_per_cu_data
***datap
= datum
;
2821 **datap
= &sigt
->per_cu
;
2827 /* Create the hash table of all entries in the .debug_types section.
2828 The result is zero if there is an error (e.g. missing .debug_types section),
2829 otherwise non-zero. */
2832 create_debug_types_hash_table (struct objfile
*objfile
)
2836 struct dwarf2_per_cu_data
**iter
;
2838 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2839 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2841 if (info_ptr
== NULL
)
2843 dwarf2_per_objfile
->signatured_types
= NULL
;
2847 types_htab
= allocate_signatured_type_table (objfile
);
2849 if (dwarf2_die_debug
)
2850 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2852 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2854 unsigned int offset
;
2855 unsigned int offset_size
;
2856 unsigned int type_offset
;
2857 unsigned int length
, initial_length_size
;
2858 unsigned short version
;
2860 struct signatured_type
*type_sig
;
2862 gdb_byte
*ptr
= info_ptr
;
2864 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2866 /* We need to read the type's signature in order to build the hash
2867 table, but we don't need to read anything else just yet. */
2869 /* Sanity check to ensure entire cu is present. */
2870 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2871 if (ptr
+ length
+ initial_length_size
2872 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2874 complaint (&symfile_complaints
,
2875 _("debug type entry runs off end of `.debug_types' section, ignored"));
2879 offset_size
= initial_length_size
== 4 ? 4 : 8;
2880 ptr
+= initial_length_size
;
2881 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2883 ptr
+= offset_size
; /* abbrev offset */
2884 ptr
+= 1; /* address size */
2885 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2887 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2889 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2890 memset (type_sig
, 0, sizeof (*type_sig
));
2891 type_sig
->signature
= signature
;
2892 type_sig
->offset
= offset
;
2893 type_sig
->type_offset
= type_offset
;
2894 type_sig
->per_cu
.objfile
= objfile
;
2895 type_sig
->per_cu
.from_debug_types
= 1;
2897 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2898 gdb_assert (slot
!= NULL
);
2901 if (dwarf2_die_debug
)
2902 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2903 offset
, phex (signature
, sizeof (signature
)));
2905 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2908 dwarf2_per_objfile
->signatured_types
= types_htab
;
2910 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
2911 dwarf2_per_objfile
->type_comp_units
2912 = obstack_alloc (&objfile
->objfile_obstack
,
2913 dwarf2_per_objfile
->n_type_comp_units
2914 * sizeof (struct dwarf2_per_cu_data
*));
2915 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
2916 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
2917 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
2918 == dwarf2_per_objfile
->n_type_comp_units
);
2923 /* Lookup a signature based type.
2924 Returns NULL if SIG is not present in the table. */
2926 static struct signatured_type
*
2927 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2929 struct signatured_type find_entry
, *entry
;
2931 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2933 complaint (&symfile_complaints
,
2934 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2938 find_entry
.signature
= sig
;
2939 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2943 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2946 init_cu_die_reader (struct die_reader_specs
*reader
,
2947 struct dwarf2_cu
*cu
)
2949 reader
->abfd
= cu
->objfile
->obfd
;
2951 if (cu
->per_cu
->from_debug_types
)
2953 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2954 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2958 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2959 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2963 /* Find the base address of the compilation unit for range lists and
2964 location lists. It will normally be specified by DW_AT_low_pc.
2965 In DWARF-3 draft 4, the base address could be overridden by
2966 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2967 compilation units with discontinuous ranges. */
2970 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2972 struct attribute
*attr
;
2975 cu
->base_address
= 0;
2977 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
2980 cu
->base_address
= DW_ADDR (attr
);
2985 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2988 cu
->base_address
= DW_ADDR (attr
);
2994 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2995 to combine the common parts.
2996 Process a compilation unit for a psymtab.
2997 BUFFER is a pointer to the beginning of the dwarf section buffer,
2998 either .debug_info or debug_types.
2999 INFO_PTR is a pointer to the start of the CU.
3000 Returns a pointer to the next CU. */
3003 process_psymtab_comp_unit (struct objfile
*objfile
,
3004 struct dwarf2_per_cu_data
*this_cu
,
3005 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3006 unsigned int buffer_size
)
3008 bfd
*abfd
= objfile
->obfd
;
3009 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3010 struct die_info
*comp_unit_die
;
3011 struct partial_symtab
*pst
;
3013 struct cleanup
*back_to_inner
;
3014 struct dwarf2_cu cu
;
3015 int has_children
, has_pc_info
;
3016 struct attribute
*attr
;
3017 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3018 struct die_reader_specs reader_specs
;
3020 memset (&cu
, 0, sizeof (cu
));
3021 cu
.objfile
= objfile
;
3022 obstack_init (&cu
.comp_unit_obstack
);
3024 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3026 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3027 buffer
, buffer_size
,
3030 /* Complete the cu_header. */
3031 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3032 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3034 cu
.list_in_scope
= &file_symbols
;
3036 /* If this compilation unit was already read in, free the
3037 cached copy in order to read it in again. This is
3038 necessary because we skipped some symbols when we first
3039 read in the compilation unit (see load_partial_dies).
3040 This problem could be avoided, but the benefit is
3042 if (this_cu
->cu
!= NULL
)
3043 free_one_cached_comp_unit (this_cu
->cu
);
3045 /* Note that this is a pointer to our stack frame, being
3046 added to a global data structure. It will be cleaned up
3047 in free_stack_comp_unit when we finish with this
3048 compilation unit. */
3050 cu
.per_cu
= this_cu
;
3052 /* Read the abbrevs for this compilation unit into a table. */
3053 dwarf2_read_abbrevs (abfd
, &cu
);
3054 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3056 /* Read the compilation unit die. */
3057 if (this_cu
->from_debug_types
)
3058 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3059 init_cu_die_reader (&reader_specs
, &cu
);
3060 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3063 if (this_cu
->from_debug_types
)
3065 /* offset,length haven't been set yet for type units. */
3066 this_cu
->offset
= cu
.header
.offset
;
3067 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3069 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3071 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3072 + cu
.header
.initial_length_size
);
3073 do_cleanups (back_to_inner
);
3077 /* Set the language we're debugging. */
3078 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
3080 set_cu_language (DW_UNSND (attr
), &cu
);
3082 set_cu_language (language_minimal
, &cu
);
3084 /* Allocate a new partial symbol table structure. */
3085 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3086 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3087 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3088 /* TEXTLOW and TEXTHIGH are set below. */
3090 objfile
->global_psymbols
.next
,
3091 objfile
->static_psymbols
.next
);
3093 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3095 pst
->dirname
= DW_STRING (attr
);
3097 pst
->read_symtab_private
= this_cu
;
3099 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3101 /* Store the function that reads in the rest of the symbol table */
3102 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3104 this_cu
->v
.psymtab
= pst
;
3106 dwarf2_find_base_address (comp_unit_die
, &cu
);
3108 /* Possibly set the default values of LOWPC and HIGHPC from
3110 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3111 &best_highpc
, &cu
, pst
);
3112 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3113 /* Store the contiguous range if it is not empty; it can be empty for
3114 CUs with no code. */
3115 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3116 best_lowpc
+ baseaddr
,
3117 best_highpc
+ baseaddr
- 1, pst
);
3119 /* Check if comp unit has_children.
3120 If so, read the rest of the partial symbols from this comp unit.
3121 If not, there's no more debug_info for this comp unit. */
3124 struct partial_die_info
*first_die
;
3125 CORE_ADDR lowpc
, highpc
;
3127 lowpc
= ((CORE_ADDR
) -1);
3128 highpc
= ((CORE_ADDR
) 0);
3130 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3132 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3133 ! has_pc_info
, &cu
);
3135 /* If we didn't find a lowpc, set it to highpc to avoid
3136 complaints from `maint check'. */
3137 if (lowpc
== ((CORE_ADDR
) -1))
3140 /* If the compilation unit didn't have an explicit address range,
3141 then use the information extracted from its child dies. */
3145 best_highpc
= highpc
;
3148 pst
->textlow
= best_lowpc
+ baseaddr
;
3149 pst
->texthigh
= best_highpc
+ baseaddr
;
3151 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3152 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3153 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3154 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3155 sort_pst_symbols (pst
);
3157 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3158 + cu
.header
.initial_length_size
);
3160 if (this_cu
->from_debug_types
)
3162 /* It's not clear we want to do anything with stmt lists here.
3163 Waiting to see what gcc ultimately does. */
3167 /* Get the list of files included in the current compilation unit,
3168 and build a psymtab for each of them. */
3169 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3172 do_cleanups (back_to_inner
);
3177 /* Traversal function for htab_traverse_noresize.
3178 Process one .debug_types comp-unit. */
3181 process_type_comp_unit (void **slot
, void *info
)
3183 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3184 struct objfile
*objfile
= (struct objfile
*) info
;
3185 struct dwarf2_per_cu_data
*this_cu
;
3187 this_cu
= &entry
->per_cu
;
3189 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3190 process_psymtab_comp_unit (objfile
, this_cu
,
3191 dwarf2_per_objfile
->types
.buffer
,
3192 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3193 dwarf2_per_objfile
->types
.size
);
3198 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3199 Build partial symbol tables for the .debug_types comp-units. */
3202 build_type_psymtabs (struct objfile
*objfile
)
3204 if (! create_debug_types_hash_table (objfile
))
3207 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3208 process_type_comp_unit
, objfile
);
3211 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3214 psymtabs_addrmap_cleanup (void *o
)
3216 struct objfile
*objfile
= o
;
3218 objfile
->psymtabs_addrmap
= NULL
;
3221 /* Build the partial symbol table by doing a quick pass through the
3222 .debug_info and .debug_abbrev sections. */
3225 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3228 struct cleanup
*back_to
, *addrmap_cleanup
;
3229 struct obstack temp_obstack
;
3231 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3233 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3234 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3236 /* Any cached compilation units will be linked by the per-objfile
3237 read_in_chain. Make sure to free them when we're done. */
3238 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3240 build_type_psymtabs (objfile
);
3242 create_all_comp_units (objfile
);
3244 /* Create a temporary address map on a temporary obstack. We later
3245 copy this to the final obstack. */
3246 obstack_init (&temp_obstack
);
3247 make_cleanup_obstack_free (&temp_obstack
);
3248 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3249 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3251 /* Since the objects we're extracting from .debug_info vary in
3252 length, only the individual functions to extract them (like
3253 read_comp_unit_head and load_partial_die) can really know whether
3254 the buffer is large enough to hold another complete object.
3256 At the moment, they don't actually check that. If .debug_info
3257 holds just one extra byte after the last compilation unit's dies,
3258 then read_comp_unit_head will happily read off the end of the
3259 buffer. read_partial_die is similarly casual. Those functions
3262 For this loop condition, simply checking whether there's any data
3263 left at all should be sufficient. */
3265 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3266 + dwarf2_per_objfile
->info
.size
))
3268 struct dwarf2_per_cu_data
*this_cu
;
3270 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3273 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3274 dwarf2_per_objfile
->info
.buffer
,
3276 dwarf2_per_objfile
->info
.size
);
3279 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3280 &objfile
->objfile_obstack
);
3281 discard_cleanups (addrmap_cleanup
);
3283 do_cleanups (back_to
);
3286 /* Load the partial DIEs for a secondary CU into memory. */
3289 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3290 struct objfile
*objfile
)
3292 bfd
*abfd
= objfile
->obfd
;
3293 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3294 struct die_info
*comp_unit_die
;
3295 struct dwarf2_cu
*cu
;
3296 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3297 struct attribute
*attr
;
3299 struct die_reader_specs reader_specs
;
3302 gdb_assert (! this_cu
->from_debug_types
);
3304 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3305 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3306 beg_of_comp_unit
= info_ptr
;
3308 if (this_cu
->cu
== NULL
)
3310 cu
= alloc_one_comp_unit (objfile
);
3314 /* If an error occurs while loading, release our storage. */
3315 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3317 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3318 dwarf2_per_objfile
->info
.buffer
,
3319 dwarf2_per_objfile
->info
.size
,
3322 /* Complete the cu_header. */
3323 cu
->header
.offset
= this_cu
->offset
;
3324 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3326 /* Link this compilation unit into the compilation unit tree. */
3328 cu
->per_cu
= this_cu
;
3330 /* Link this CU into read_in_chain. */
3331 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3332 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3337 info_ptr
+= cu
->header
.first_die_offset
;
3340 /* Read the abbrevs for this compilation unit into a table. */
3341 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3342 dwarf2_read_abbrevs (abfd
, cu
);
3343 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3345 /* Read the compilation unit die. */
3346 init_cu_die_reader (&reader_specs
, cu
);
3347 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3350 /* Set the language we're debugging. */
3351 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
3353 set_cu_language (DW_UNSND (attr
), cu
);
3355 set_cu_language (language_minimal
, cu
);
3357 /* Check if comp unit has_children.
3358 If so, read the rest of the partial symbols from this comp unit.
3359 If not, there's no more debug_info for this comp unit. */
3361 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3363 do_cleanups (free_abbrevs_cleanup
);
3367 /* We've successfully allocated this compilation unit. Let our
3368 caller clean it up when finished with it. */
3369 discard_cleanups (free_cu_cleanup
);
3373 /* Create a list of all compilation units in OBJFILE. We do this only
3374 if an inter-comp-unit reference is found; presumably if there is one,
3375 there will be many, and one will occur early in the .debug_info section.
3376 So there's no point in building this list incrementally. */
3379 create_all_comp_units (struct objfile
*objfile
)
3383 struct dwarf2_per_cu_data
**all_comp_units
;
3386 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3387 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3391 all_comp_units
= xmalloc (n_allocated
3392 * sizeof (struct dwarf2_per_cu_data
*));
3394 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3396 unsigned int length
, initial_length_size
;
3397 struct dwarf2_per_cu_data
*this_cu
;
3398 unsigned int offset
;
3400 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3402 /* Read just enough information to find out where the next
3403 compilation unit is. */
3404 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3405 &initial_length_size
);
3407 /* Save the compilation unit for later lookup. */
3408 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3409 sizeof (struct dwarf2_per_cu_data
));
3410 memset (this_cu
, 0, sizeof (*this_cu
));
3411 this_cu
->offset
= offset
;
3412 this_cu
->length
= length
+ initial_length_size
;
3413 this_cu
->objfile
= objfile
;
3415 if (n_comp_units
== n_allocated
)
3418 all_comp_units
= xrealloc (all_comp_units
,
3420 * sizeof (struct dwarf2_per_cu_data
*));
3422 all_comp_units
[n_comp_units
++] = this_cu
;
3424 info_ptr
= info_ptr
+ this_cu
->length
;
3427 dwarf2_per_objfile
->all_comp_units
3428 = obstack_alloc (&objfile
->objfile_obstack
,
3429 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3430 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3431 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3432 xfree (all_comp_units
);
3433 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3436 /* Process all loaded DIEs for compilation unit CU, starting at
3437 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3438 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3439 DW_AT_ranges). If NEED_PC is set, then this function will set
3440 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3441 and record the covered ranges in the addrmap. */
3444 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3445 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3447 struct partial_die_info
*pdi
;
3449 /* Now, march along the PDI's, descending into ones which have
3450 interesting children but skipping the children of the other ones,
3451 until we reach the end of the compilation unit. */
3457 fixup_partial_die (pdi
, cu
);
3459 /* Anonymous namespaces or modules have no name but have interesting
3460 children, so we need to look at them. Ditto for anonymous
3463 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3464 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3468 case DW_TAG_subprogram
:
3469 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3471 case DW_TAG_variable
:
3472 case DW_TAG_typedef
:
3473 case DW_TAG_union_type
:
3474 if (!pdi
->is_declaration
)
3476 add_partial_symbol (pdi
, cu
);
3479 case DW_TAG_class_type
:
3480 case DW_TAG_interface_type
:
3481 case DW_TAG_structure_type
:
3482 if (!pdi
->is_declaration
)
3484 add_partial_symbol (pdi
, cu
);
3487 case DW_TAG_enumeration_type
:
3488 if (!pdi
->is_declaration
)
3489 add_partial_enumeration (pdi
, cu
);
3491 case DW_TAG_base_type
:
3492 case DW_TAG_subrange_type
:
3493 /* File scope base type definitions are added to the partial
3495 add_partial_symbol (pdi
, cu
);
3497 case DW_TAG_namespace
:
3498 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3501 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3508 /* If the die has a sibling, skip to the sibling. */
3510 pdi
= pdi
->die_sibling
;
3514 /* Functions used to compute the fully scoped name of a partial DIE.
3516 Normally, this is simple. For C++, the parent DIE's fully scoped
3517 name is concatenated with "::" and the partial DIE's name. For
3518 Java, the same thing occurs except that "." is used instead of "::".
3519 Enumerators are an exception; they use the scope of their parent
3520 enumeration type, i.e. the name of the enumeration type is not
3521 prepended to the enumerator.
3523 There are two complexities. One is DW_AT_specification; in this
3524 case "parent" means the parent of the target of the specification,
3525 instead of the direct parent of the DIE. The other is compilers
3526 which do not emit DW_TAG_namespace; in this case we try to guess
3527 the fully qualified name of structure types from their members'
3528 linkage names. This must be done using the DIE's children rather
3529 than the children of any DW_AT_specification target. We only need
3530 to do this for structures at the top level, i.e. if the target of
3531 any DW_AT_specification (if any; otherwise the DIE itself) does not
3534 /* Compute the scope prefix associated with PDI's parent, in
3535 compilation unit CU. The result will be allocated on CU's
3536 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3537 field. NULL is returned if no prefix is necessary. */
3539 partial_die_parent_scope (struct partial_die_info
*pdi
,
3540 struct dwarf2_cu
*cu
)
3542 char *grandparent_scope
;
3543 struct partial_die_info
*parent
, *real_pdi
;
3545 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3546 then this means the parent of the specification DIE. */
3549 while (real_pdi
->has_specification
)
3550 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3552 parent
= real_pdi
->die_parent
;
3556 if (parent
->scope_set
)
3557 return parent
->scope
;
3559 fixup_partial_die (parent
, cu
);
3561 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3563 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3564 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3565 Work around this problem here. */
3566 if (cu
->language
== language_cplus
3567 && parent
->tag
== DW_TAG_namespace
3568 && strcmp (parent
->name
, "::") == 0
3569 && grandparent_scope
== NULL
)
3571 parent
->scope
= NULL
;
3572 parent
->scope_set
= 1;
3576 if (parent
->tag
== DW_TAG_namespace
3577 || parent
->tag
== DW_TAG_module
3578 || parent
->tag
== DW_TAG_structure_type
3579 || parent
->tag
== DW_TAG_class_type
3580 || parent
->tag
== DW_TAG_interface_type
3581 || parent
->tag
== DW_TAG_union_type
3582 || parent
->tag
== DW_TAG_enumeration_type
)
3584 if (grandparent_scope
== NULL
)
3585 parent
->scope
= parent
->name
;
3587 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3588 parent
->name
, 0, cu
);
3590 else if (parent
->tag
== DW_TAG_enumerator
)
3591 /* Enumerators should not get the name of the enumeration as a prefix. */
3592 parent
->scope
= grandparent_scope
;
3595 /* FIXME drow/2004-04-01: What should we be doing with
3596 function-local names? For partial symbols, we should probably be
3598 complaint (&symfile_complaints
,
3599 _("unhandled containing DIE tag %d for DIE at %d"),
3600 parent
->tag
, pdi
->offset
);
3601 parent
->scope
= grandparent_scope
;
3604 parent
->scope_set
= 1;
3605 return parent
->scope
;
3608 /* Return the fully scoped name associated with PDI, from compilation unit
3609 CU. The result will be allocated with malloc. */
3611 partial_die_full_name (struct partial_die_info
*pdi
,
3612 struct dwarf2_cu
*cu
)
3616 /* If this is a template instantiation, we can not work out the
3617 template arguments from partial DIEs. So, unfortunately, we have
3618 to go through the full DIEs. At least any work we do building
3619 types here will be reused if full symbols are loaded later. */
3620 if (pdi
->has_template_arguments
)
3622 fixup_partial_die (pdi
, cu
);
3624 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3626 struct die_info
*die
;
3627 struct attribute attr
;
3628 struct dwarf2_cu
*ref_cu
= cu
;
3631 attr
.form
= DW_FORM_ref_addr
;
3632 attr
.u
.addr
= pdi
->offset
;
3633 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3635 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3639 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3640 if (parent_scope
== NULL
)
3643 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3647 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3649 struct objfile
*objfile
= cu
->objfile
;
3651 char *actual_name
= NULL
;
3652 const struct partial_symbol
*psym
= NULL
;
3654 int built_actual_name
= 0;
3656 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3658 actual_name
= partial_die_full_name (pdi
, cu
);
3660 built_actual_name
= 1;
3662 if (actual_name
== NULL
)
3663 actual_name
= pdi
->name
;
3667 case DW_TAG_subprogram
:
3668 if (pdi
->is_external
|| cu
->language
== language_ada
)
3670 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3671 of the global scope. But in Ada, we want to be able to access
3672 nested procedures globally. So all Ada subprograms are stored
3673 in the global scope. */
3674 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3675 mst_text, objfile); */
3676 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3678 VAR_DOMAIN
, LOC_BLOCK
,
3679 &objfile
->global_psymbols
,
3680 0, pdi
->lowpc
+ baseaddr
,
3681 cu
->language
, objfile
);
3685 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3686 mst_file_text, objfile); */
3687 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3689 VAR_DOMAIN
, LOC_BLOCK
,
3690 &objfile
->static_psymbols
,
3691 0, pdi
->lowpc
+ baseaddr
,
3692 cu
->language
, objfile
);
3695 case DW_TAG_variable
:
3697 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3701 && !dwarf2_per_objfile
->has_section_at_zero
)
3703 /* A global or static variable may also have been stripped
3704 out by the linker if unused, in which case its address
3705 will be nullified; do not add such variables into partial
3706 symbol table then. */
3708 else if (pdi
->is_external
)
3711 Don't enter into the minimal symbol tables as there is
3712 a minimal symbol table entry from the ELF symbols already.
3713 Enter into partial symbol table if it has a location
3714 descriptor or a type.
3715 If the location descriptor is missing, new_symbol will create
3716 a LOC_UNRESOLVED symbol, the address of the variable will then
3717 be determined from the minimal symbol table whenever the variable
3719 The address for the partial symbol table entry is not
3720 used by GDB, but it comes in handy for debugging partial symbol
3723 if (pdi
->locdesc
|| pdi
->has_type
)
3724 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3726 VAR_DOMAIN
, LOC_STATIC
,
3727 &objfile
->global_psymbols
,
3729 cu
->language
, objfile
);
3733 /* Static Variable. Skip symbols without location descriptors. */
3734 if (pdi
->locdesc
== NULL
)
3736 if (built_actual_name
)
3737 xfree (actual_name
);
3740 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3741 mst_file_data, objfile); */
3742 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3744 VAR_DOMAIN
, LOC_STATIC
,
3745 &objfile
->static_psymbols
,
3747 cu
->language
, objfile
);
3750 case DW_TAG_typedef
:
3751 case DW_TAG_base_type
:
3752 case DW_TAG_subrange_type
:
3753 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3755 VAR_DOMAIN
, LOC_TYPEDEF
,
3756 &objfile
->static_psymbols
,
3757 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3759 case DW_TAG_namespace
:
3760 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3762 VAR_DOMAIN
, LOC_TYPEDEF
,
3763 &objfile
->global_psymbols
,
3764 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3766 case DW_TAG_class_type
:
3767 case DW_TAG_interface_type
:
3768 case DW_TAG_structure_type
:
3769 case DW_TAG_union_type
:
3770 case DW_TAG_enumeration_type
:
3771 /* Skip external references. The DWARF standard says in the section
3772 about "Structure, Union, and Class Type Entries": "An incomplete
3773 structure, union or class type is represented by a structure,
3774 union or class entry that does not have a byte size attribute
3775 and that has a DW_AT_declaration attribute." */
3776 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3778 if (built_actual_name
)
3779 xfree (actual_name
);
3783 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3784 static vs. global. */
3785 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3787 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3788 (cu
->language
== language_cplus
3789 || cu
->language
== language_java
)
3790 ? &objfile
->global_psymbols
3791 : &objfile
->static_psymbols
,
3792 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3795 case DW_TAG_enumerator
:
3796 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3798 VAR_DOMAIN
, LOC_CONST
,
3799 (cu
->language
== language_cplus
3800 || cu
->language
== language_java
)
3801 ? &objfile
->global_psymbols
3802 : &objfile
->static_psymbols
,
3803 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3809 if (built_actual_name
)
3810 xfree (actual_name
);
3813 /* Read a partial die corresponding to a namespace; also, add a symbol
3814 corresponding to that namespace to the symbol table. NAMESPACE is
3815 the name of the enclosing namespace. */
3818 add_partial_namespace (struct partial_die_info
*pdi
,
3819 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3820 int need_pc
, struct dwarf2_cu
*cu
)
3822 /* Add a symbol for the namespace. */
3824 add_partial_symbol (pdi
, cu
);
3826 /* Now scan partial symbols in that namespace. */
3828 if (pdi
->has_children
)
3829 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3832 /* Read a partial die corresponding to a Fortran module. */
3835 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3836 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3838 /* Now scan partial symbols in that module. */
3840 if (pdi
->has_children
)
3841 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3844 /* Read a partial die corresponding to a subprogram and create a partial
3845 symbol for that subprogram. When the CU language allows it, this
3846 routine also defines a partial symbol for each nested subprogram
3847 that this subprogram contains.
3849 DIE my also be a lexical block, in which case we simply search
3850 recursively for suprograms defined inside that lexical block.
3851 Again, this is only performed when the CU language allows this
3852 type of definitions. */
3855 add_partial_subprogram (struct partial_die_info
*pdi
,
3856 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3857 int need_pc
, struct dwarf2_cu
*cu
)
3859 if (pdi
->tag
== DW_TAG_subprogram
)
3861 if (pdi
->has_pc_info
)
3863 if (pdi
->lowpc
< *lowpc
)
3864 *lowpc
= pdi
->lowpc
;
3865 if (pdi
->highpc
> *highpc
)
3866 *highpc
= pdi
->highpc
;
3870 struct objfile
*objfile
= cu
->objfile
;
3872 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3873 SECT_OFF_TEXT (objfile
));
3874 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3875 pdi
->lowpc
+ baseaddr
,
3876 pdi
->highpc
- 1 + baseaddr
,
3877 cu
->per_cu
->v
.psymtab
);
3879 if (!pdi
->is_declaration
)
3880 /* Ignore subprogram DIEs that do not have a name, they are
3881 illegal. Do not emit a complaint at this point, we will
3882 do so when we convert this psymtab into a symtab. */
3884 add_partial_symbol (pdi
, cu
);
3888 if (! pdi
->has_children
)
3891 if (cu
->language
== language_ada
)
3893 pdi
= pdi
->die_child
;
3896 fixup_partial_die (pdi
, cu
);
3897 if (pdi
->tag
== DW_TAG_subprogram
3898 || pdi
->tag
== DW_TAG_lexical_block
)
3899 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3900 pdi
= pdi
->die_sibling
;
3905 /* See if we can figure out if the class lives in a namespace. We do
3906 this by looking for a member function; its demangled name will
3907 contain namespace info, if there is any. */
3910 guess_structure_name (struct partial_die_info
*struct_pdi
,
3911 struct dwarf2_cu
*cu
)
3913 if ((cu
->language
== language_cplus
3914 || cu
->language
== language_java
)
3915 && cu
->has_namespace_info
== 0
3916 && struct_pdi
->has_children
)
3918 /* NOTE: carlton/2003-10-07: Getting the info this way changes
3919 what template types look like, because the demangler
3920 frequently doesn't give the same name as the debug info. We
3921 could fix this by only using the demangled name to get the
3922 prefix (but see comment in read_structure_type). */
3924 struct partial_die_info
*real_pdi
;
3926 /* If this DIE (this DIE's specification, if any) has a parent, then
3927 we should not do this. We'll prepend the parent's fully qualified
3928 name when we create the partial symbol. */
3930 real_pdi
= struct_pdi
;
3931 while (real_pdi
->has_specification
)
3932 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3934 if (real_pdi
->die_parent
!= NULL
)
3939 /* Read a partial die corresponding to an enumeration type. */
3942 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3943 struct dwarf2_cu
*cu
)
3945 struct partial_die_info
*pdi
;
3947 if (enum_pdi
->name
!= NULL
)
3948 add_partial_symbol (enum_pdi
, cu
);
3950 pdi
= enum_pdi
->die_child
;
3953 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3954 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3956 add_partial_symbol (pdi
, cu
);
3957 pdi
= pdi
->die_sibling
;
3961 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3962 Return the corresponding abbrev, or NULL if the number is zero (indicating
3963 an empty DIE). In either case *BYTES_READ will be set to the length of
3964 the initial number. */
3966 static struct abbrev_info
*
3967 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3968 struct dwarf2_cu
*cu
)
3970 bfd
*abfd
= cu
->objfile
->obfd
;
3971 unsigned int abbrev_number
;
3972 struct abbrev_info
*abbrev
;
3974 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3976 if (abbrev_number
== 0)
3979 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3982 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3983 bfd_get_filename (abfd
));
3989 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3990 Returns a pointer to the end of a series of DIEs, terminated by an empty
3991 DIE. Any children of the skipped DIEs will also be skipped. */
3994 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
3996 struct abbrev_info
*abbrev
;
3997 unsigned int bytes_read
;
4001 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4003 return info_ptr
+ bytes_read
;
4005 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4009 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4010 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4011 abbrev corresponding to that skipped uleb128 should be passed in
4012 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4016 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4017 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4019 unsigned int bytes_read
;
4020 struct attribute attr
;
4021 bfd
*abfd
= cu
->objfile
->obfd
;
4022 unsigned int form
, i
;
4024 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4026 /* The only abbrev we care about is DW_AT_sibling. */
4027 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4029 read_attribute (&attr
, &abbrev
->attrs
[i
],
4030 abfd
, info_ptr
, cu
);
4031 if (attr
.form
== DW_FORM_ref_addr
)
4032 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
4034 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4037 /* If it isn't DW_AT_sibling, skip this attribute. */
4038 form
= abbrev
->attrs
[i
].form
;
4042 case DW_FORM_ref_addr
:
4043 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4044 and later it is offset sized. */
4045 if (cu
->header
.version
== 2)
4046 info_ptr
+= cu
->header
.addr_size
;
4048 info_ptr
+= cu
->header
.offset_size
;
4051 info_ptr
+= cu
->header
.addr_size
;
4058 case DW_FORM_flag_present
:
4073 case DW_FORM_string
:
4074 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4075 info_ptr
+= bytes_read
;
4077 case DW_FORM_sec_offset
:
4079 info_ptr
+= cu
->header
.offset_size
;
4081 case DW_FORM_exprloc
:
4083 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4084 info_ptr
+= bytes_read
;
4086 case DW_FORM_block1
:
4087 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4089 case DW_FORM_block2
:
4090 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4092 case DW_FORM_block4
:
4093 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4097 case DW_FORM_ref_udata
:
4098 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4100 case DW_FORM_indirect
:
4101 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4102 info_ptr
+= bytes_read
;
4103 /* We need to continue parsing from here, so just go back to
4105 goto skip_attribute
;
4108 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4109 dwarf_form_name (form
),
4110 bfd_get_filename (abfd
));
4114 if (abbrev
->has_children
)
4115 return skip_children (buffer
, info_ptr
, cu
);
4120 /* Locate ORIG_PDI's sibling.
4121 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4125 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4126 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4127 bfd
*abfd
, struct dwarf2_cu
*cu
)
4129 /* Do we know the sibling already? */
4131 if (orig_pdi
->sibling
)
4132 return orig_pdi
->sibling
;
4134 /* Are there any children to deal with? */
4136 if (!orig_pdi
->has_children
)
4139 /* Skip the children the long way. */
4141 return skip_children (buffer
, info_ptr
, cu
);
4144 /* Expand this partial symbol table into a full symbol table. */
4147 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4153 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
4159 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
4160 gdb_flush (gdb_stdout
);
4163 /* Restore our global data. */
4164 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4165 dwarf2_objfile_data_key
);
4167 /* If this psymtab is constructed from a debug-only objfile, the
4168 has_section_at_zero flag will not necessarily be correct. We
4169 can get the correct value for this flag by looking at the data
4170 associated with the (presumably stripped) associated objfile. */
4171 if (pst
->objfile
->separate_debug_objfile_backlink
)
4173 struct dwarf2_per_objfile
*dpo_backlink
4174 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4175 dwarf2_objfile_data_key
);
4177 dwarf2_per_objfile
->has_section_at_zero
4178 = dpo_backlink
->has_section_at_zero
;
4181 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4183 psymtab_to_symtab_1 (pst
);
4185 /* Finish up the debug error message. */
4187 printf_filtered (_("done.\n"));
4192 /* Add PER_CU to the queue. */
4195 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4197 struct dwarf2_queue_item
*item
;
4200 item
= xmalloc (sizeof (*item
));
4201 item
->per_cu
= per_cu
;
4204 if (dwarf2_queue
== NULL
)
4205 dwarf2_queue
= item
;
4207 dwarf2_queue_tail
->next
= item
;
4209 dwarf2_queue_tail
= item
;
4212 /* Process the queue. */
4215 process_queue (struct objfile
*objfile
)
4217 struct dwarf2_queue_item
*item
, *next_item
;
4219 /* The queue starts out with one item, but following a DIE reference
4220 may load a new CU, adding it to the end of the queue. */
4221 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4223 if (dwarf2_per_objfile
->using_index
4224 ? !item
->per_cu
->v
.quick
->symtab
4225 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4226 process_full_comp_unit (item
->per_cu
);
4228 item
->per_cu
->queued
= 0;
4229 next_item
= item
->next
;
4233 dwarf2_queue_tail
= NULL
;
4236 /* Free all allocated queue entries. This function only releases anything if
4237 an error was thrown; if the queue was processed then it would have been
4238 freed as we went along. */
4241 dwarf2_release_queue (void *dummy
)
4243 struct dwarf2_queue_item
*item
, *last
;
4245 item
= dwarf2_queue
;
4248 /* Anything still marked queued is likely to be in an
4249 inconsistent state, so discard it. */
4250 if (item
->per_cu
->queued
)
4252 if (item
->per_cu
->cu
!= NULL
)
4253 free_one_cached_comp_unit (item
->per_cu
->cu
);
4254 item
->per_cu
->queued
= 0;
4262 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4265 /* Read in full symbols for PST, and anything it depends on. */
4268 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4270 struct dwarf2_per_cu_data
*per_cu
;
4271 struct cleanup
*back_to
;
4274 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4275 if (!pst
->dependencies
[i
]->readin
)
4277 /* Inform about additional files that need to be read in. */
4280 /* FIXME: i18n: Need to make this a single string. */
4281 fputs_filtered (" ", gdb_stdout
);
4283 fputs_filtered ("and ", gdb_stdout
);
4285 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4286 wrap_here (""); /* Flush output */
4287 gdb_flush (gdb_stdout
);
4289 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4292 per_cu
= pst
->read_symtab_private
;
4296 /* It's an include file, no symbols to read for it.
4297 Everything is in the parent symtab. */
4302 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4305 /* Load the DIEs associated with PER_CU into memory. */
4308 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4310 bfd
*abfd
= objfile
->obfd
;
4311 struct dwarf2_cu
*cu
;
4312 unsigned int offset
;
4313 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4314 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4315 struct attribute
*attr
;
4318 gdb_assert (! per_cu
->from_debug_types
);
4320 /* Set local variables from the partial symbol table info. */
4321 offset
= per_cu
->offset
;
4323 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4324 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4325 beg_of_comp_unit
= info_ptr
;
4327 if (per_cu
->cu
== NULL
)
4329 cu
= alloc_one_comp_unit (objfile
);
4333 /* If an error occurs while loading, release our storage. */
4334 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4336 /* Read in the comp_unit header. */
4337 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4339 /* Complete the cu_header. */
4340 cu
->header
.offset
= offset
;
4341 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4343 /* Read the abbrevs for this compilation unit. */
4344 dwarf2_read_abbrevs (abfd
, cu
);
4345 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4347 /* Link this compilation unit into the compilation unit tree. */
4349 cu
->per_cu
= per_cu
;
4351 /* Link this CU into read_in_chain. */
4352 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4353 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4358 info_ptr
+= cu
->header
.first_die_offset
;
4361 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4363 /* We try not to read any attributes in this function, because not
4364 all objfiles needed for references have been loaded yet, and symbol
4365 table processing isn't initialized. But we have to set the CU language,
4366 or we won't be able to build types correctly. */
4367 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
4369 set_cu_language (DW_UNSND (attr
), cu
);
4371 set_cu_language (language_minimal
, cu
);
4373 /* Similarly, if we do not read the producer, we can not apply
4374 producer-specific interpretation. */
4375 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4377 cu
->producer
= DW_STRING (attr
);
4381 do_cleanups (free_abbrevs_cleanup
);
4383 /* We've successfully allocated this compilation unit. Let our
4384 caller clean it up when finished with it. */
4385 discard_cleanups (free_cu_cleanup
);
4389 /* Add a DIE to the delayed physname list. */
4392 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4393 const char *name
, struct die_info
*die
,
4394 struct dwarf2_cu
*cu
)
4396 struct delayed_method_info mi
;
4398 mi
.fnfield_index
= fnfield_index
;
4402 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4405 /* A cleanup for freeing the delayed method list. */
4408 free_delayed_list (void *ptr
)
4410 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4411 if (cu
->method_list
!= NULL
)
4413 VEC_free (delayed_method_info
, cu
->method_list
);
4414 cu
->method_list
= NULL
;
4418 /* Compute the physnames of any methods on the CU's method list.
4420 The computation of method physnames is delayed in order to avoid the
4421 (bad) condition that one of the method's formal parameters is of an as yet
4425 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4428 struct delayed_method_info
*mi
;
4429 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4432 struct fn_fieldlist
*fn_flp
4433 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4434 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4435 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4439 /* Generate full symbol information for PST and CU, whose DIEs have
4440 already been loaded into memory. */
4443 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4445 struct dwarf2_cu
*cu
= per_cu
->cu
;
4446 struct objfile
*objfile
= per_cu
->objfile
;
4447 CORE_ADDR lowpc
, highpc
;
4448 struct symtab
*symtab
;
4449 struct cleanup
*back_to
, *delayed_list_cleanup
;
4452 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4455 back_to
= make_cleanup (really_free_pendings
, NULL
);
4456 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4458 cu
->list_in_scope
= &file_symbols
;
4460 dwarf2_find_base_address (cu
->dies
, cu
);
4462 /* Do line number decoding in read_file_scope () */
4463 process_die (cu
->dies
, cu
);
4465 /* Now that we have processed all the DIEs in the CU, all the types
4466 should be complete, and it should now be safe to compute all of the
4468 compute_delayed_physnames (cu
);
4469 do_cleanups (delayed_list_cleanup
);
4471 /* Some compilers don't define a DW_AT_high_pc attribute for the
4472 compilation unit. If the DW_AT_high_pc is missing, synthesize
4473 it, by scanning the DIE's below the compilation unit. */
4474 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4476 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4478 /* Set symtab language to language from DW_AT_language.
4479 If the compilation is from a C file generated by language preprocessors,
4480 do not set the language if it was already deduced by start_subfile. */
4482 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4484 symtab
->language
= cu
->language
;
4487 if (dwarf2_per_objfile
->using_index
)
4488 per_cu
->v
.quick
->symtab
= symtab
;
4491 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4492 pst
->symtab
= symtab
;
4496 do_cleanups (back_to
);
4499 /* Process a die and its children. */
4502 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4506 case DW_TAG_padding
:
4508 case DW_TAG_compile_unit
:
4509 read_file_scope (die
, cu
);
4511 case DW_TAG_type_unit
:
4512 read_type_unit_scope (die
, cu
);
4514 case DW_TAG_subprogram
:
4515 case DW_TAG_inlined_subroutine
:
4516 read_func_scope (die
, cu
);
4518 case DW_TAG_lexical_block
:
4519 case DW_TAG_try_block
:
4520 case DW_TAG_catch_block
:
4521 read_lexical_block_scope (die
, cu
);
4523 case DW_TAG_class_type
:
4524 case DW_TAG_interface_type
:
4525 case DW_TAG_structure_type
:
4526 case DW_TAG_union_type
:
4527 process_structure_scope (die
, cu
);
4529 case DW_TAG_enumeration_type
:
4530 process_enumeration_scope (die
, cu
);
4533 /* These dies have a type, but processing them does not create
4534 a symbol or recurse to process the children. Therefore we can
4535 read them on-demand through read_type_die. */
4536 case DW_TAG_subroutine_type
:
4537 case DW_TAG_set_type
:
4538 case DW_TAG_array_type
:
4539 case DW_TAG_pointer_type
:
4540 case DW_TAG_ptr_to_member_type
:
4541 case DW_TAG_reference_type
:
4542 case DW_TAG_string_type
:
4545 case DW_TAG_base_type
:
4546 case DW_TAG_subrange_type
:
4547 case DW_TAG_typedef
:
4548 /* Add a typedef symbol for the type definition, if it has a
4550 new_symbol (die
, read_type_die (die
, cu
), cu
);
4552 case DW_TAG_common_block
:
4553 read_common_block (die
, cu
);
4555 case DW_TAG_common_inclusion
:
4557 case DW_TAG_namespace
:
4558 processing_has_namespace_info
= 1;
4559 read_namespace (die
, cu
);
4562 processing_has_namespace_info
= 1;
4563 read_module (die
, cu
);
4565 case DW_TAG_imported_declaration
:
4566 case DW_TAG_imported_module
:
4567 processing_has_namespace_info
= 1;
4568 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4569 || cu
->language
!= language_fortran
))
4570 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4571 dwarf_tag_name (die
->tag
));
4572 read_import_statement (die
, cu
);
4575 new_symbol (die
, NULL
, cu
);
4580 /* A helper function for dwarf2_compute_name which determines whether DIE
4581 needs to have the name of the scope prepended to the name listed in the
4585 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4587 struct attribute
*attr
;
4591 case DW_TAG_namespace
:
4592 case DW_TAG_typedef
:
4593 case DW_TAG_class_type
:
4594 case DW_TAG_interface_type
:
4595 case DW_TAG_structure_type
:
4596 case DW_TAG_union_type
:
4597 case DW_TAG_enumeration_type
:
4598 case DW_TAG_enumerator
:
4599 case DW_TAG_subprogram
:
4603 case DW_TAG_variable
:
4604 /* We only need to prefix "globally" visible variables. These include
4605 any variable marked with DW_AT_external or any variable that
4606 lives in a namespace. [Variables in anonymous namespaces
4607 require prefixing, but they are not DW_AT_external.] */
4609 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4611 struct dwarf2_cu
*spec_cu
= cu
;
4613 return die_needs_namespace (die_specification (die
, &spec_cu
),
4617 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4618 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4619 && die
->parent
->tag
!= DW_TAG_module
)
4621 /* A variable in a lexical block of some kind does not need a
4622 namespace, even though in C++ such variables may be external
4623 and have a mangled name. */
4624 if (die
->parent
->tag
== DW_TAG_lexical_block
4625 || die
->parent
->tag
== DW_TAG_try_block
4626 || die
->parent
->tag
== DW_TAG_catch_block
4627 || die
->parent
->tag
== DW_TAG_subprogram
)
4636 /* Retrieve the last character from a mem_file. */
4639 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4641 char *last_char_p
= (char *) object
;
4644 *last_char_p
= buffer
[length
- 1];
4647 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4648 compute the physname for the object, which include a method's
4649 formal parameters (C++/Java) and return type (Java).
4651 For Ada, return the DIE's linkage name rather than the fully qualified
4652 name. PHYSNAME is ignored..
4654 The result is allocated on the objfile_obstack and canonicalized. */
4657 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4661 name
= dwarf2_name (die
, cu
);
4663 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4664 compute it by typename_concat inside GDB. */
4665 if (cu
->language
== language_ada
4666 || (cu
->language
== language_fortran
&& physname
))
4668 /* For Ada unit, we prefer the linkage name over the name, as
4669 the former contains the exported name, which the user expects
4670 to be able to reference. Ideally, we want the user to be able
4671 to reference this entity using either natural or linkage name,
4672 but we haven't started looking at this enhancement yet. */
4673 struct attribute
*attr
;
4675 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4677 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4678 if (attr
&& DW_STRING (attr
))
4679 return DW_STRING (attr
);
4682 /* These are the only languages we know how to qualify names in. */
4684 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4685 || cu
->language
== language_fortran
))
4687 if (die_needs_namespace (die
, cu
))
4691 struct ui_file
*buf
;
4693 prefix
= determine_prefix (die
, cu
);
4694 buf
= mem_fileopen ();
4695 if (*prefix
!= '\0')
4697 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4700 fputs_unfiltered (prefixed_name
, buf
);
4701 xfree (prefixed_name
);
4704 fputs_unfiltered (name
? name
: "", buf
);
4706 /* Template parameters may be specified in the DIE's DW_AT_name, or
4707 as children with DW_TAG_template_type_param or
4708 DW_TAG_value_type_param. If the latter, add them to the name
4709 here. If the name already has template parameters, then
4710 skip this step; some versions of GCC emit both, and
4711 it is more efficient to use the pre-computed name.
4713 Something to keep in mind about this process: it is very
4714 unlikely, or in some cases downright impossible, to produce
4715 something that will match the mangled name of a function.
4716 If the definition of the function has the same debug info,
4717 we should be able to match up with it anyway. But fallbacks
4718 using the minimal symbol, for instance to find a method
4719 implemented in a stripped copy of libstdc++, will not work.
4720 If we do not have debug info for the definition, we will have to
4721 match them up some other way.
4723 When we do name matching there is a related problem with function
4724 templates; two instantiated function templates are allowed to
4725 differ only by their return types, which we do not add here. */
4727 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4729 struct attribute
*attr
;
4730 struct die_info
*child
;
4733 die
->building_fullname
= 1;
4735 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4740 struct dwarf2_locexpr_baton
*baton
;
4743 if (child
->tag
!= DW_TAG_template_type_param
4744 && child
->tag
!= DW_TAG_template_value_param
)
4749 fputs_unfiltered ("<", buf
);
4753 fputs_unfiltered (", ", buf
);
4755 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4758 complaint (&symfile_complaints
,
4759 _("template parameter missing DW_AT_type"));
4760 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4763 type
= die_type (child
, cu
);
4765 if (child
->tag
== DW_TAG_template_type_param
)
4767 c_print_type (type
, "", buf
, -1, 0);
4771 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4774 complaint (&symfile_complaints
,
4775 _("template parameter missing DW_AT_const_value"));
4776 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4780 dwarf2_const_value_attr (attr
, type
, name
,
4781 &cu
->comp_unit_obstack
, cu
,
4782 &value
, &bytes
, &baton
);
4784 if (TYPE_NOSIGN (type
))
4785 /* GDB prints characters as NUMBER 'CHAR'. If that's
4786 changed, this can use value_print instead. */
4787 c_printchar (value
, type
, buf
);
4790 struct value_print_options opts
;
4793 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4797 else if (bytes
!= NULL
)
4799 v
= allocate_value (type
);
4800 memcpy (value_contents_writeable (v
), bytes
,
4801 TYPE_LENGTH (type
));
4804 v
= value_from_longest (type
, value
);
4806 /* Specify decimal so that we do not depend on the radix. */
4807 get_formatted_print_options (&opts
, 'd');
4809 value_print (v
, buf
, &opts
);
4815 die
->building_fullname
= 0;
4819 /* Close the argument list, with a space if necessary
4820 (nested templates). */
4821 char last_char
= '\0';
4822 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4823 if (last_char
== '>')
4824 fputs_unfiltered (" >", buf
);
4826 fputs_unfiltered (">", buf
);
4830 /* For Java and C++ methods, append formal parameter type
4831 information, if PHYSNAME. */
4833 if (physname
&& die
->tag
== DW_TAG_subprogram
4834 && (cu
->language
== language_cplus
4835 || cu
->language
== language_java
))
4837 struct type
*type
= read_type_die (die
, cu
);
4839 c_type_print_args (type
, buf
, 0, cu
->language
);
4841 if (cu
->language
== language_java
)
4843 /* For java, we must append the return type to method
4845 if (die
->tag
== DW_TAG_subprogram
)
4846 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4849 else if (cu
->language
== language_cplus
)
4851 /* Assume that an artificial first parameter is
4852 "this", but do not crash if it is not. RealView
4853 marks unnamed (and thus unused) parameters as
4854 artificial; there is no way to differentiate
4856 if (TYPE_NFIELDS (type
) > 0
4857 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4858 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
4859 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4860 fputs_unfiltered (" const", buf
);
4864 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4866 ui_file_delete (buf
);
4868 if (cu
->language
== language_cplus
)
4871 = dwarf2_canonicalize_name (name
, cu
,
4872 &cu
->objfile
->objfile_obstack
);
4883 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4884 If scope qualifiers are appropriate they will be added. The result
4885 will be allocated on the objfile_obstack, or NULL if the DIE does
4886 not have a name. NAME may either be from a previous call to
4887 dwarf2_name or NULL.
4889 The output string will be canonicalized (if C++/Java). */
4892 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4894 return dwarf2_compute_name (name
, die
, cu
, 0);
4897 /* Construct a physname for the given DIE in CU. NAME may either be
4898 from a previous call to dwarf2_name or NULL. The result will be
4899 allocated on the objfile_objstack or NULL if the DIE does not have a
4902 The output string will be canonicalized (if C++/Java). */
4905 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4907 return dwarf2_compute_name (name
, die
, cu
, 1);
4910 /* Read the import statement specified by the given die and record it. */
4913 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4915 struct attribute
*import_attr
;
4916 struct die_info
*imported_die
;
4917 struct dwarf2_cu
*imported_cu
;
4918 const char *imported_name
;
4919 const char *imported_name_prefix
;
4920 const char *canonical_name
;
4921 const char *import_alias
;
4922 const char *imported_declaration
= NULL
;
4923 const char *import_prefix
;
4927 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4928 if (import_attr
== NULL
)
4930 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4931 dwarf_tag_name (die
->tag
));
4936 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4937 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4938 if (imported_name
== NULL
)
4940 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4942 The import in the following code:
4956 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4957 <52> DW_AT_decl_file : 1
4958 <53> DW_AT_decl_line : 6
4959 <54> DW_AT_import : <0x75>
4960 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4962 <5b> DW_AT_decl_file : 1
4963 <5c> DW_AT_decl_line : 2
4964 <5d> DW_AT_type : <0x6e>
4966 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4967 <76> DW_AT_byte_size : 4
4968 <77> DW_AT_encoding : 5 (signed)
4970 imports the wrong die ( 0x75 instead of 0x58 ).
4971 This case will be ignored until the gcc bug is fixed. */
4975 /* Figure out the local name after import. */
4976 import_alias
= dwarf2_name (die
, cu
);
4978 /* Figure out where the statement is being imported to. */
4979 import_prefix
= determine_prefix (die
, cu
);
4981 /* Figure out what the scope of the imported die is and prepend it
4982 to the name of the imported die. */
4983 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4985 if (imported_die
->tag
!= DW_TAG_namespace
4986 && imported_die
->tag
!= DW_TAG_module
)
4988 imported_declaration
= imported_name
;
4989 canonical_name
= imported_name_prefix
;
4991 else if (strlen (imported_name_prefix
) > 0)
4993 temp
= alloca (strlen (imported_name_prefix
)
4994 + 2 + strlen (imported_name
) + 1);
4995 strcpy (temp
, imported_name_prefix
);
4996 strcat (temp
, "::");
4997 strcat (temp
, imported_name
);
4998 canonical_name
= temp
;
5001 canonical_name
= imported_name
;
5003 cp_add_using_directive (import_prefix
,
5006 imported_declaration
,
5007 &cu
->objfile
->objfile_obstack
);
5011 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5013 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5017 free_cu_line_header (void *arg
)
5019 struct dwarf2_cu
*cu
= arg
;
5021 free_line_header (cu
->line_header
);
5022 cu
->line_header
= NULL
;
5026 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5027 char **name
, char **comp_dir
)
5029 struct attribute
*attr
;
5034 /* Find the filename. Do not use dwarf2_name here, since the filename
5035 is not a source language identifier. */
5036 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5039 *name
= DW_STRING (attr
);
5042 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5044 *comp_dir
= DW_STRING (attr
);
5045 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5047 *comp_dir
= ldirname (*name
);
5048 if (*comp_dir
!= NULL
)
5049 make_cleanup (xfree
, *comp_dir
);
5051 if (*comp_dir
!= NULL
)
5053 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5054 directory, get rid of it. */
5055 char *cp
= strchr (*comp_dir
, ':');
5057 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5062 *name
= "<unknown>";
5066 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5068 struct objfile
*objfile
= cu
->objfile
;
5069 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5070 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5071 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5072 struct attribute
*attr
;
5074 char *comp_dir
= NULL
;
5075 struct die_info
*child_die
;
5076 bfd
*abfd
= objfile
->obfd
;
5077 struct line_header
*line_header
= 0;
5080 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5082 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5084 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5085 from finish_block. */
5086 if (lowpc
== ((CORE_ADDR
) -1))
5091 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5093 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5096 set_cu_language (DW_UNSND (attr
), cu
);
5099 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5101 cu
->producer
= DW_STRING (attr
);
5103 /* We assume that we're processing GCC output. */
5104 processing_gcc_compilation
= 2;
5106 processing_has_namespace_info
= 0;
5108 start_symtab (name
, comp_dir
, lowpc
);
5109 record_debugformat ("DWARF 2");
5110 record_producer (cu
->producer
);
5112 initialize_cu_func_list (cu
);
5114 /* Decode line number information if present. We do this before
5115 processing child DIEs, so that the line header table is available
5116 for DW_AT_decl_file. */
5117 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5120 unsigned int line_offset
= DW_UNSND (attr
);
5121 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5124 cu
->line_header
= line_header
;
5125 make_cleanup (free_cu_line_header
, cu
);
5126 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5130 /* Process all dies in compilation unit. */
5131 if (die
->child
!= NULL
)
5133 child_die
= die
->child
;
5134 while (child_die
&& child_die
->tag
)
5136 process_die (child_die
, cu
);
5137 child_die
= sibling_die (child_die
);
5141 /* Decode macro information, if present. Dwarf 2 macro information
5142 refers to information in the line number info statement program
5143 header, so we can only read it if we've read the header
5145 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5146 if (attr
&& line_header
)
5148 unsigned int macro_offset
= DW_UNSND (attr
);
5150 dwarf_decode_macros (line_header
, macro_offset
,
5151 comp_dir
, abfd
, cu
);
5153 do_cleanups (back_to
);
5156 /* For TUs we want to skip the first top level sibling if it's not the
5157 actual type being defined by this TU. In this case the first top
5158 level sibling is there to provide context only. */
5161 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5163 struct objfile
*objfile
= cu
->objfile
;
5164 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5166 struct attribute
*attr
;
5168 char *comp_dir
= NULL
;
5169 struct die_info
*child_die
;
5170 bfd
*abfd
= objfile
->obfd
;
5172 /* start_symtab needs a low pc, but we don't really have one.
5173 Do what read_file_scope would do in the absence of such info. */
5174 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5176 /* Find the filename. Do not use dwarf2_name here, since the filename
5177 is not a source language identifier. */
5178 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5180 name
= DW_STRING (attr
);
5182 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5184 comp_dir
= DW_STRING (attr
);
5185 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5187 comp_dir
= ldirname (name
);
5188 if (comp_dir
!= NULL
)
5189 make_cleanup (xfree
, comp_dir
);
5195 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5197 set_cu_language (DW_UNSND (attr
), cu
);
5199 /* This isn't technically needed today. It is done for symmetry
5200 with read_file_scope. */
5201 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5203 cu
->producer
= DW_STRING (attr
);
5205 /* We assume that we're processing GCC output. */
5206 processing_gcc_compilation
= 2;
5208 processing_has_namespace_info
= 0;
5210 start_symtab (name
, comp_dir
, lowpc
);
5211 record_debugformat ("DWARF 2");
5212 record_producer (cu
->producer
);
5214 /* Process the dies in the type unit. */
5215 if (die
->child
== NULL
)
5217 dump_die_for_error (die
);
5218 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5219 bfd_get_filename (abfd
));
5222 child_die
= die
->child
;
5224 while (child_die
&& child_die
->tag
)
5226 process_die (child_die
, cu
);
5228 child_die
= sibling_die (child_die
);
5231 do_cleanups (back_to
);
5235 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5236 struct dwarf2_cu
*cu
)
5238 struct function_range
*thisfn
;
5240 thisfn
= (struct function_range
*)
5241 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5242 thisfn
->name
= name
;
5243 thisfn
->lowpc
= lowpc
;
5244 thisfn
->highpc
= highpc
;
5245 thisfn
->seen_line
= 0;
5246 thisfn
->next
= NULL
;
5248 if (cu
->last_fn
== NULL
)
5249 cu
->first_fn
= thisfn
;
5251 cu
->last_fn
->next
= thisfn
;
5253 cu
->last_fn
= thisfn
;
5256 /* qsort helper for inherit_abstract_dies. */
5259 unsigned_int_compar (const void *ap
, const void *bp
)
5261 unsigned int a
= *(unsigned int *) ap
;
5262 unsigned int b
= *(unsigned int *) bp
;
5264 return (a
> b
) - (b
> a
);
5267 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5268 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5269 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5272 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5274 struct die_info
*child_die
;
5275 unsigned die_children_count
;
5276 /* CU offsets which were referenced by children of the current DIE. */
5278 unsigned *offsets_end
, *offsetp
;
5279 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5280 struct die_info
*origin_die
;
5281 /* Iterator of the ORIGIN_DIE children. */
5282 struct die_info
*origin_child_die
;
5283 struct cleanup
*cleanups
;
5284 struct attribute
*attr
;
5285 struct dwarf2_cu
*origin_cu
;
5286 struct pending
**origin_previous_list_in_scope
;
5288 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5292 /* Note that following die references may follow to a die in a
5296 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5298 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5300 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5301 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5303 if (die
->tag
!= origin_die
->tag
5304 && !(die
->tag
== DW_TAG_inlined_subroutine
5305 && origin_die
->tag
== DW_TAG_subprogram
))
5306 complaint (&symfile_complaints
,
5307 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5308 die
->offset
, origin_die
->offset
);
5310 child_die
= die
->child
;
5311 die_children_count
= 0;
5312 while (child_die
&& child_die
->tag
)
5314 child_die
= sibling_die (child_die
);
5315 die_children_count
++;
5317 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5318 cleanups
= make_cleanup (xfree
, offsets
);
5320 offsets_end
= offsets
;
5321 child_die
= die
->child
;
5322 while (child_die
&& child_die
->tag
)
5324 /* For each CHILD_DIE, find the corresponding child of
5325 ORIGIN_DIE. If there is more than one layer of
5326 DW_AT_abstract_origin, follow them all; there shouldn't be,
5327 but GCC versions at least through 4.4 generate this (GCC PR
5329 struct die_info
*child_origin_die
= child_die
;
5330 struct dwarf2_cu
*child_origin_cu
= cu
;
5334 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5338 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5342 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5343 counterpart may exist. */
5344 if (child_origin_die
!= child_die
)
5346 if (child_die
->tag
!= child_origin_die
->tag
5347 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5348 && child_origin_die
->tag
== DW_TAG_subprogram
))
5349 complaint (&symfile_complaints
,
5350 _("Child DIE 0x%x and its abstract origin 0x%x have "
5351 "different tags"), child_die
->offset
,
5352 child_origin_die
->offset
);
5353 if (child_origin_die
->parent
!= origin_die
)
5354 complaint (&symfile_complaints
,
5355 _("Child DIE 0x%x and its abstract origin 0x%x have "
5356 "different parents"), child_die
->offset
,
5357 child_origin_die
->offset
);
5359 *offsets_end
++ = child_origin_die
->offset
;
5361 child_die
= sibling_die (child_die
);
5363 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5364 unsigned_int_compar
);
5365 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5366 if (offsetp
[-1] == *offsetp
)
5367 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
5368 "to DIE 0x%x as their abstract origin"),
5369 die
->offset
, *offsetp
);
5372 origin_child_die
= origin_die
->child
;
5373 while (origin_child_die
&& origin_child_die
->tag
)
5375 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5376 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5378 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5380 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5381 process_die (origin_child_die
, origin_cu
);
5383 origin_child_die
= sibling_die (origin_child_die
);
5385 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5387 do_cleanups (cleanups
);
5391 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5393 struct objfile
*objfile
= cu
->objfile
;
5394 struct context_stack
*new;
5397 struct die_info
*child_die
;
5398 struct attribute
*attr
, *call_line
, *call_file
;
5401 struct block
*block
;
5402 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5403 VEC (symbolp
) *template_args
= NULL
;
5404 struct template_symbol
*templ_func
= NULL
;
5408 /* If we do not have call site information, we can't show the
5409 caller of this inlined function. That's too confusing, so
5410 only use the scope for local variables. */
5411 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5412 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5413 if (call_line
== NULL
|| call_file
== NULL
)
5415 read_lexical_block_scope (die
, cu
);
5420 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5422 name
= dwarf2_name (die
, cu
);
5424 /* Ignore functions with missing or empty names. These are actually
5425 illegal according to the DWARF standard. */
5428 complaint (&symfile_complaints
,
5429 _("missing name for subprogram DIE at %d"), die
->offset
);
5433 /* Ignore functions with missing or invalid low and high pc attributes. */
5434 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5436 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5437 if (!attr
|| !DW_UNSND (attr
))
5438 complaint (&symfile_complaints
,
5439 _("cannot get low and high bounds for subprogram DIE at %d"),
5447 /* Record the function range for dwarf_decode_lines. */
5448 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5450 /* If we have any template arguments, then we must allocate a
5451 different sort of symbol. */
5452 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5454 if (child_die
->tag
== DW_TAG_template_type_param
5455 || child_die
->tag
== DW_TAG_template_value_param
)
5457 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5458 struct template_symbol
);
5459 templ_func
->base
.is_cplus_template_function
= 1;
5464 new = push_context (0, lowpc
);
5465 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5466 (struct symbol
*) templ_func
);
5468 /* If there is a location expression for DW_AT_frame_base, record
5470 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5472 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5473 expression is being recorded directly in the function's symbol
5474 and not in a separate frame-base object. I guess this hack is
5475 to avoid adding some sort of frame-base adjunct/annex to the
5476 function's symbol :-(. The problem with doing this is that it
5477 results in a function symbol with a location expression that
5478 has nothing to do with the location of the function, ouch! The
5479 relationship should be: a function's symbol has-a frame base; a
5480 frame-base has-a location expression. */
5481 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5483 cu
->list_in_scope
= &local_symbols
;
5485 if (die
->child
!= NULL
)
5487 child_die
= die
->child
;
5488 while (child_die
&& child_die
->tag
)
5490 if (child_die
->tag
== DW_TAG_template_type_param
5491 || child_die
->tag
== DW_TAG_template_value_param
)
5493 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5496 VEC_safe_push (symbolp
, template_args
, arg
);
5499 process_die (child_die
, cu
);
5500 child_die
= sibling_die (child_die
);
5504 inherit_abstract_dies (die
, cu
);
5506 /* If we have a DW_AT_specification, we might need to import using
5507 directives from the context of the specification DIE. See the
5508 comment in determine_prefix. */
5509 if (cu
->language
== language_cplus
5510 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5512 struct dwarf2_cu
*spec_cu
= cu
;
5513 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5517 child_die
= spec_die
->child
;
5518 while (child_die
&& child_die
->tag
)
5520 if (child_die
->tag
== DW_TAG_imported_module
)
5521 process_die (child_die
, spec_cu
);
5522 child_die
= sibling_die (child_die
);
5525 /* In some cases, GCC generates specification DIEs that
5526 themselves contain DW_AT_specification attributes. */
5527 spec_die
= die_specification (spec_die
, &spec_cu
);
5531 new = pop_context ();
5532 /* Make a block for the local symbols within. */
5533 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5534 lowpc
, highpc
, objfile
);
5536 /* For C++, set the block's scope. */
5537 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5538 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5539 determine_prefix (die
, cu
),
5540 processing_has_namespace_info
);
5542 /* If we have address ranges, record them. */
5543 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5545 /* Attach template arguments to function. */
5546 if (! VEC_empty (symbolp
, template_args
))
5548 gdb_assert (templ_func
!= NULL
);
5550 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5551 templ_func
->template_arguments
5552 = obstack_alloc (&objfile
->objfile_obstack
,
5553 (templ_func
->n_template_arguments
5554 * sizeof (struct symbol
*)));
5555 memcpy (templ_func
->template_arguments
,
5556 VEC_address (symbolp
, template_args
),
5557 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5558 VEC_free (symbolp
, template_args
);
5561 /* In C++, we can have functions nested inside functions (e.g., when
5562 a function declares a class that has methods). This means that
5563 when we finish processing a function scope, we may need to go
5564 back to building a containing block's symbol lists. */
5565 local_symbols
= new->locals
;
5566 param_symbols
= new->params
;
5567 using_directives
= new->using_directives
;
5569 /* If we've finished processing a top-level function, subsequent
5570 symbols go in the file symbol list. */
5571 if (outermost_context_p ())
5572 cu
->list_in_scope
= &file_symbols
;
5575 /* Process all the DIES contained within a lexical block scope. Start
5576 a new scope, process the dies, and then close the scope. */
5579 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5581 struct objfile
*objfile
= cu
->objfile
;
5582 struct context_stack
*new;
5583 CORE_ADDR lowpc
, highpc
;
5584 struct die_info
*child_die
;
5587 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5589 /* Ignore blocks with missing or invalid low and high pc attributes. */
5590 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5591 as multiple lexical blocks? Handling children in a sane way would
5592 be nasty. Might be easier to properly extend generic blocks to
5594 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5599 push_context (0, lowpc
);
5600 if (die
->child
!= NULL
)
5602 child_die
= die
->child
;
5603 while (child_die
&& child_die
->tag
)
5605 process_die (child_die
, cu
);
5606 child_die
= sibling_die (child_die
);
5609 new = pop_context ();
5611 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5614 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5617 /* Note that recording ranges after traversing children, as we
5618 do here, means that recording a parent's ranges entails
5619 walking across all its children's ranges as they appear in
5620 the address map, which is quadratic behavior.
5622 It would be nicer to record the parent's ranges before
5623 traversing its children, simply overriding whatever you find
5624 there. But since we don't even decide whether to create a
5625 block until after we've traversed its children, that's hard
5627 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5629 local_symbols
= new->locals
;
5630 using_directives
= new->using_directives
;
5633 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5634 Return 1 if the attributes are present and valid, otherwise, return 0.
5635 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5638 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5639 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5640 struct partial_symtab
*ranges_pst
)
5642 struct objfile
*objfile
= cu
->objfile
;
5643 struct comp_unit_head
*cu_header
= &cu
->header
;
5644 bfd
*obfd
= objfile
->obfd
;
5645 unsigned int addr_size
= cu_header
->addr_size
;
5646 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5647 /* Base address selection entry. */
5658 found_base
= cu
->base_known
;
5659 base
= cu
->base_address
;
5661 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5662 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5664 complaint (&symfile_complaints
,
5665 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5669 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5671 /* Read in the largest possible address. */
5672 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5673 if ((marker
& mask
) == mask
)
5675 /* If we found the largest possible address, then
5676 read the base address. */
5677 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5678 buffer
+= 2 * addr_size
;
5679 offset
+= 2 * addr_size
;
5685 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5689 CORE_ADDR range_beginning
, range_end
;
5691 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5692 buffer
+= addr_size
;
5693 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5694 buffer
+= addr_size
;
5695 offset
+= 2 * addr_size
;
5697 /* An end of list marker is a pair of zero addresses. */
5698 if (range_beginning
== 0 && range_end
== 0)
5699 /* Found the end of list entry. */
5702 /* Each base address selection entry is a pair of 2 values.
5703 The first is the largest possible address, the second is
5704 the base address. Check for a base address here. */
5705 if ((range_beginning
& mask
) == mask
)
5707 /* If we found the largest possible address, then
5708 read the base address. */
5709 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5716 /* We have no valid base address for the ranges
5718 complaint (&symfile_complaints
,
5719 _("Invalid .debug_ranges data (no base address)"));
5723 range_beginning
+= base
;
5726 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5727 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5728 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5731 /* FIXME: This is recording everything as a low-high
5732 segment of consecutive addresses. We should have a
5733 data structure for discontiguous block ranges
5737 low
= range_beginning
;
5743 if (range_beginning
< low
)
5744 low
= range_beginning
;
5745 if (range_end
> high
)
5751 /* If the first entry is an end-of-list marker, the range
5752 describes an empty scope, i.e. no instructions. */
5758 *high_return
= high
;
5762 /* Get low and high pc attributes from a die. Return 1 if the attributes
5763 are present and valid, otherwise, return 0. Return -1 if the range is
5764 discontinuous, i.e. derived from DW_AT_ranges information. */
5766 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5767 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5768 struct partial_symtab
*pst
)
5770 struct attribute
*attr
;
5775 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5778 high
= DW_ADDR (attr
);
5779 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5781 low
= DW_ADDR (attr
);
5783 /* Found high w/o low attribute. */
5786 /* Found consecutive range of addresses. */
5791 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5794 /* Value of the DW_AT_ranges attribute is the offset in the
5795 .debug_ranges section. */
5796 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5798 /* Found discontinuous range of addresses. */
5806 /* When using the GNU linker, .gnu.linkonce. sections are used to
5807 eliminate duplicate copies of functions and vtables and such.
5808 The linker will arbitrarily choose one and discard the others.
5809 The AT_*_pc values for such functions refer to local labels in
5810 these sections. If the section from that file was discarded, the
5811 labels are not in the output, so the relocs get a value of 0.
5812 If this is a discarded function, mark the pc bounds as invalid,
5813 so that GDB will ignore it. */
5814 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5822 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5823 its low and high PC addresses. Do nothing if these addresses could not
5824 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5825 and HIGHPC to the high address if greater than HIGHPC. */
5828 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5829 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5830 struct dwarf2_cu
*cu
)
5832 CORE_ADDR low
, high
;
5833 struct die_info
*child
= die
->child
;
5835 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5837 *lowpc
= min (*lowpc
, low
);
5838 *highpc
= max (*highpc
, high
);
5841 /* If the language does not allow nested subprograms (either inside
5842 subprograms or lexical blocks), we're done. */
5843 if (cu
->language
!= language_ada
)
5846 /* Check all the children of the given DIE. If it contains nested
5847 subprograms, then check their pc bounds. Likewise, we need to
5848 check lexical blocks as well, as they may also contain subprogram
5850 while (child
&& child
->tag
)
5852 if (child
->tag
== DW_TAG_subprogram
5853 || child
->tag
== DW_TAG_lexical_block
)
5854 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5855 child
= sibling_die (child
);
5859 /* Get the low and high pc's represented by the scope DIE, and store
5860 them in *LOWPC and *HIGHPC. If the correct values can't be
5861 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5864 get_scope_pc_bounds (struct die_info
*die
,
5865 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5866 struct dwarf2_cu
*cu
)
5868 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5869 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5870 CORE_ADDR current_low
, current_high
;
5872 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5874 best_low
= current_low
;
5875 best_high
= current_high
;
5879 struct die_info
*child
= die
->child
;
5881 while (child
&& child
->tag
)
5883 switch (child
->tag
) {
5884 case DW_TAG_subprogram
:
5885 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5887 case DW_TAG_namespace
:
5889 /* FIXME: carlton/2004-01-16: Should we do this for
5890 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5891 that current GCC's always emit the DIEs corresponding
5892 to definitions of methods of classes as children of a
5893 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5894 the DIEs giving the declarations, which could be
5895 anywhere). But I don't see any reason why the
5896 standards says that they have to be there. */
5897 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5899 if (current_low
!= ((CORE_ADDR
) -1))
5901 best_low
= min (best_low
, current_low
);
5902 best_high
= max (best_high
, current_high
);
5910 child
= sibling_die (child
);
5915 *highpc
= best_high
;
5918 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5921 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5922 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5924 struct attribute
*attr
;
5926 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5929 CORE_ADDR high
= DW_ADDR (attr
);
5931 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5934 CORE_ADDR low
= DW_ADDR (attr
);
5936 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5940 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5943 bfd
*obfd
= cu
->objfile
->obfd
;
5945 /* The value of the DW_AT_ranges attribute is the offset of the
5946 address range list in the .debug_ranges section. */
5947 unsigned long offset
= DW_UNSND (attr
);
5948 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5950 /* For some target architectures, but not others, the
5951 read_address function sign-extends the addresses it returns.
5952 To recognize base address selection entries, we need a
5954 unsigned int addr_size
= cu
->header
.addr_size
;
5955 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5957 /* The base address, to which the next pair is relative. Note
5958 that this 'base' is a DWARF concept: most entries in a range
5959 list are relative, to reduce the number of relocs against the
5960 debugging information. This is separate from this function's
5961 'baseaddr' argument, which GDB uses to relocate debugging
5962 information from a shared library based on the address at
5963 which the library was loaded. */
5964 CORE_ADDR base
= cu
->base_address
;
5965 int base_known
= cu
->base_known
;
5967 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5968 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5970 complaint (&symfile_complaints
,
5971 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5978 unsigned int bytes_read
;
5979 CORE_ADDR start
, end
;
5981 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5982 buffer
+= bytes_read
;
5983 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5984 buffer
+= bytes_read
;
5986 /* Did we find the end of the range list? */
5987 if (start
== 0 && end
== 0)
5990 /* Did we find a base address selection entry? */
5991 else if ((start
& base_select_mask
) == base_select_mask
)
5997 /* We found an ordinary address range. */
6002 complaint (&symfile_complaints
,
6003 _("Invalid .debug_ranges data (no base address)"));
6007 record_block_range (block
,
6008 baseaddr
+ base
+ start
,
6009 baseaddr
+ base
+ end
- 1);
6015 /* Add an aggregate field to the field list. */
6018 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6019 struct dwarf2_cu
*cu
)
6021 struct objfile
*objfile
= cu
->objfile
;
6022 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6023 struct nextfield
*new_field
;
6024 struct attribute
*attr
;
6026 char *fieldname
= "";
6028 /* Allocate a new field list entry and link it in. */
6029 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6030 make_cleanup (xfree
, new_field
);
6031 memset (new_field
, 0, sizeof (struct nextfield
));
6033 if (die
->tag
== DW_TAG_inheritance
)
6035 new_field
->next
= fip
->baseclasses
;
6036 fip
->baseclasses
= new_field
;
6040 new_field
->next
= fip
->fields
;
6041 fip
->fields
= new_field
;
6045 /* Handle accessibility and virtuality of field.
6046 The default accessibility for members is public, the default
6047 accessibility for inheritance is private. */
6048 if (die
->tag
!= DW_TAG_inheritance
)
6049 new_field
->accessibility
= DW_ACCESS_public
;
6051 new_field
->accessibility
= DW_ACCESS_private
;
6052 new_field
->virtuality
= DW_VIRTUALITY_none
;
6054 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6056 new_field
->accessibility
= DW_UNSND (attr
);
6057 if (new_field
->accessibility
!= DW_ACCESS_public
)
6058 fip
->non_public_fields
= 1;
6059 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6061 new_field
->virtuality
= DW_UNSND (attr
);
6063 fp
= &new_field
->field
;
6065 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6067 /* Data member other than a C++ static data member. */
6069 /* Get type of field. */
6070 fp
->type
= die_type (die
, cu
);
6072 SET_FIELD_BITPOS (*fp
, 0);
6074 /* Get bit size of field (zero if none). */
6075 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6078 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6082 FIELD_BITSIZE (*fp
) = 0;
6085 /* Get bit offset of field. */
6086 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6089 int byte_offset
= 0;
6091 if (attr_form_is_section_offset (attr
))
6092 dwarf2_complex_location_expr_complaint ();
6093 else if (attr_form_is_constant (attr
))
6094 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6095 else if (attr_form_is_block (attr
))
6096 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6098 dwarf2_complex_location_expr_complaint ();
6100 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6102 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6105 if (gdbarch_bits_big_endian (gdbarch
))
6107 /* For big endian bits, the DW_AT_bit_offset gives the
6108 additional bit offset from the MSB of the containing
6109 anonymous object to the MSB of the field. We don't
6110 have to do anything special since we don't need to
6111 know the size of the anonymous object. */
6112 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6116 /* For little endian bits, compute the bit offset to the
6117 MSB of the anonymous object, subtract off the number of
6118 bits from the MSB of the field to the MSB of the
6119 object, and then subtract off the number of bits of
6120 the field itself. The result is the bit offset of
6121 the LSB of the field. */
6123 int bit_offset
= DW_UNSND (attr
);
6125 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6128 /* The size of the anonymous object containing
6129 the bit field is explicit, so use the
6130 indicated size (in bytes). */
6131 anonymous_size
= DW_UNSND (attr
);
6135 /* The size of the anonymous object containing
6136 the bit field must be inferred from the type
6137 attribute of the data member containing the
6139 anonymous_size
= TYPE_LENGTH (fp
->type
);
6141 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6142 - bit_offset
- FIELD_BITSIZE (*fp
);
6146 /* Get name of field. */
6147 fieldname
= dwarf2_name (die
, cu
);
6148 if (fieldname
== NULL
)
6151 /* The name is already allocated along with this objfile, so we don't
6152 need to duplicate it for the type. */
6153 fp
->name
= fieldname
;
6155 /* Change accessibility for artificial fields (e.g. virtual table
6156 pointer or virtual base class pointer) to private. */
6157 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6159 FIELD_ARTIFICIAL (*fp
) = 1;
6160 new_field
->accessibility
= DW_ACCESS_private
;
6161 fip
->non_public_fields
= 1;
6164 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6166 /* C++ static member. */
6168 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6169 is a declaration, but all versions of G++ as of this writing
6170 (so through at least 3.2.1) incorrectly generate
6171 DW_TAG_variable tags. */
6175 /* Get name of field. */
6176 fieldname
= dwarf2_name (die
, cu
);
6177 if (fieldname
== NULL
)
6180 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6182 /* Only create a symbol if this is an external value.
6183 new_symbol checks this and puts the value in the global symbol
6184 table, which we want. If it is not external, new_symbol
6185 will try to put the value in cu->list_in_scope which is wrong. */
6186 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6188 /* A static const member, not much different than an enum as far as
6189 we're concerned, except that we can support more types. */
6190 new_symbol (die
, NULL
, cu
);
6193 /* Get physical name. */
6194 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6196 /* The name is already allocated along with this objfile, so we don't
6197 need to duplicate it for the type. */
6198 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6199 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6200 FIELD_NAME (*fp
) = fieldname
;
6202 else if (die
->tag
== DW_TAG_inheritance
)
6204 /* C++ base class field. */
6205 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6208 int byte_offset
= 0;
6210 if (attr_form_is_section_offset (attr
))
6211 dwarf2_complex_location_expr_complaint ();
6212 else if (attr_form_is_constant (attr
))
6213 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6214 else if (attr_form_is_block (attr
))
6215 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6217 dwarf2_complex_location_expr_complaint ();
6219 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6221 FIELD_BITSIZE (*fp
) = 0;
6222 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6223 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6224 fip
->nbaseclasses
++;
6228 /* Add a typedef defined in the scope of the FIP's class. */
6231 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6232 struct dwarf2_cu
*cu
)
6234 struct objfile
*objfile
= cu
->objfile
;
6235 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6236 struct typedef_field_list
*new_field
;
6237 struct attribute
*attr
;
6238 struct typedef_field
*fp
;
6239 char *fieldname
= "";
6241 /* Allocate a new field list entry and link it in. */
6242 new_field
= xzalloc (sizeof (*new_field
));
6243 make_cleanup (xfree
, new_field
);
6245 gdb_assert (die
->tag
== DW_TAG_typedef
);
6247 fp
= &new_field
->field
;
6249 /* Get name of field. */
6250 fp
->name
= dwarf2_name (die
, cu
);
6251 if (fp
->name
== NULL
)
6254 fp
->type
= read_type_die (die
, cu
);
6256 new_field
->next
= fip
->typedef_field_list
;
6257 fip
->typedef_field_list
= new_field
;
6258 fip
->typedef_field_list_count
++;
6261 /* Create the vector of fields, and attach it to the type. */
6264 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6265 struct dwarf2_cu
*cu
)
6267 int nfields
= fip
->nfields
;
6269 /* Record the field count, allocate space for the array of fields,
6270 and create blank accessibility bitfields if necessary. */
6271 TYPE_NFIELDS (type
) = nfields
;
6272 TYPE_FIELDS (type
) = (struct field
*)
6273 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6274 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6276 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6278 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6280 TYPE_FIELD_PRIVATE_BITS (type
) =
6281 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6282 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6284 TYPE_FIELD_PROTECTED_BITS (type
) =
6285 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6286 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6288 TYPE_FIELD_IGNORE_BITS (type
) =
6289 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6290 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6293 /* If the type has baseclasses, allocate and clear a bit vector for
6294 TYPE_FIELD_VIRTUAL_BITS. */
6295 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6297 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6298 unsigned char *pointer
;
6300 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6301 pointer
= TYPE_ALLOC (type
, num_bytes
);
6302 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6303 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6304 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6307 /* Copy the saved-up fields into the field vector. Start from the head
6308 of the list, adding to the tail of the field array, so that they end
6309 up in the same order in the array in which they were added to the list. */
6310 while (nfields
-- > 0)
6312 struct nextfield
*fieldp
;
6316 fieldp
= fip
->fields
;
6317 fip
->fields
= fieldp
->next
;
6321 fieldp
= fip
->baseclasses
;
6322 fip
->baseclasses
= fieldp
->next
;
6325 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6326 switch (fieldp
->accessibility
)
6328 case DW_ACCESS_private
:
6329 if (cu
->language
!= language_ada
)
6330 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6333 case DW_ACCESS_protected
:
6334 if (cu
->language
!= language_ada
)
6335 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6338 case DW_ACCESS_public
:
6342 /* Unknown accessibility. Complain and treat it as public. */
6344 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6345 fieldp
->accessibility
);
6349 if (nfields
< fip
->nbaseclasses
)
6351 switch (fieldp
->virtuality
)
6353 case DW_VIRTUALITY_virtual
:
6354 case DW_VIRTUALITY_pure_virtual
:
6355 if (cu
->language
== language_ada
)
6356 error ("unexpected virtuality in component of Ada type");
6357 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6364 /* Add a member function to the proper fieldlist. */
6367 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6368 struct type
*type
, struct dwarf2_cu
*cu
)
6370 struct objfile
*objfile
= cu
->objfile
;
6371 struct attribute
*attr
;
6372 struct fnfieldlist
*flp
;
6374 struct fn_field
*fnp
;
6376 struct nextfnfield
*new_fnfield
;
6377 struct type
*this_type
;
6379 if (cu
->language
== language_ada
)
6380 error ("unexpected member function in Ada type");
6382 /* Get name of member function. */
6383 fieldname
= dwarf2_name (die
, cu
);
6384 if (fieldname
== NULL
)
6387 /* Look up member function name in fieldlist. */
6388 for (i
= 0; i
< fip
->nfnfields
; i
++)
6390 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6394 /* Create new list element if necessary. */
6395 if (i
< fip
->nfnfields
)
6396 flp
= &fip
->fnfieldlists
[i
];
6399 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6401 fip
->fnfieldlists
= (struct fnfieldlist
*)
6402 xrealloc (fip
->fnfieldlists
,
6403 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6404 * sizeof (struct fnfieldlist
));
6405 if (fip
->nfnfields
== 0)
6406 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6408 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6409 flp
->name
= fieldname
;
6412 i
= fip
->nfnfields
++;
6415 /* Create a new member function field and chain it to the field list
6417 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6418 make_cleanup (xfree
, new_fnfield
);
6419 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6420 new_fnfield
->next
= flp
->head
;
6421 flp
->head
= new_fnfield
;
6424 /* Fill in the member function field info. */
6425 fnp
= &new_fnfield
->fnfield
;
6427 /* Delay processing of the physname until later. */
6428 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6430 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6435 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6436 fnp
->physname
= physname
? physname
: "";
6439 fnp
->type
= alloc_type (objfile
);
6440 this_type
= read_type_die (die
, cu
);
6441 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6443 int nparams
= TYPE_NFIELDS (this_type
);
6445 /* TYPE is the domain of this method, and THIS_TYPE is the type
6446 of the method itself (TYPE_CODE_METHOD). */
6447 smash_to_method_type (fnp
->type
, type
,
6448 TYPE_TARGET_TYPE (this_type
),
6449 TYPE_FIELDS (this_type
),
6450 TYPE_NFIELDS (this_type
),
6451 TYPE_VARARGS (this_type
));
6453 /* Handle static member functions.
6454 Dwarf2 has no clean way to discern C++ static and non-static
6455 member functions. G++ helps GDB by marking the first
6456 parameter for non-static member functions (which is the
6457 this pointer) as artificial. We obtain this information
6458 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6459 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6460 fnp
->voffset
= VOFFSET_STATIC
;
6463 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6464 dwarf2_full_name (fieldname
, die
, cu
));
6466 /* Get fcontext from DW_AT_containing_type if present. */
6467 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6468 fnp
->fcontext
= die_containing_type (die
, cu
);
6470 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6471 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6473 /* Get accessibility. */
6474 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6477 switch (DW_UNSND (attr
))
6479 case DW_ACCESS_private
:
6480 fnp
->is_private
= 1;
6482 case DW_ACCESS_protected
:
6483 fnp
->is_protected
= 1;
6488 /* Check for artificial methods. */
6489 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6490 if (attr
&& DW_UNSND (attr
) != 0)
6491 fnp
->is_artificial
= 1;
6493 /* Get index in virtual function table if it is a virtual member
6494 function. For older versions of GCC, this is an offset in the
6495 appropriate virtual table, as specified by DW_AT_containing_type.
6496 For everyone else, it is an expression to be evaluated relative
6497 to the object address. */
6499 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6502 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6504 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6506 /* Old-style GCC. */
6507 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6509 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6510 || (DW_BLOCK (attr
)->size
> 1
6511 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6512 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6514 struct dwarf_block blk
;
6517 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6519 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6520 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6521 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6522 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6523 dwarf2_complex_location_expr_complaint ();
6525 fnp
->voffset
/= cu
->header
.addr_size
;
6529 dwarf2_complex_location_expr_complaint ();
6532 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6534 else if (attr_form_is_section_offset (attr
))
6536 dwarf2_complex_location_expr_complaint ();
6540 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6546 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6547 if (attr
&& DW_UNSND (attr
))
6549 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6550 complaint (&symfile_complaints
,
6551 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6552 fieldname
, die
->offset
);
6553 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6554 TYPE_CPLUS_DYNAMIC (type
) = 1;
6559 /* Create the vector of member function fields, and attach it to the type. */
6562 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6563 struct dwarf2_cu
*cu
)
6565 struct fnfieldlist
*flp
;
6566 int total_length
= 0;
6569 if (cu
->language
== language_ada
)
6570 error ("unexpected member functions in Ada type");
6572 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6573 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6574 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6576 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6578 struct nextfnfield
*nfp
= flp
->head
;
6579 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6582 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6583 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6584 fn_flp
->fn_fields
= (struct fn_field
*)
6585 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6586 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6587 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6589 total_length
+= flp
->length
;
6592 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6593 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6596 /* Returns non-zero if NAME is the name of a vtable member in CU's
6597 language, zero otherwise. */
6599 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6601 static const char vptr
[] = "_vptr";
6602 static const char vtable
[] = "vtable";
6604 /* Look for the C++ and Java forms of the vtable. */
6605 if ((cu
->language
== language_java
6606 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6607 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6608 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6614 /* GCC outputs unnamed structures that are really pointers to member
6615 functions, with the ABI-specified layout. If TYPE describes
6616 such a structure, smash it into a member function type.
6618 GCC shouldn't do this; it should just output pointer to member DIEs.
6619 This is GCC PR debug/28767. */
6622 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6624 struct type
*pfn_type
, *domain_type
, *new_type
;
6626 /* Check for a structure with no name and two children. */
6627 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6630 /* Check for __pfn and __delta members. */
6631 if (TYPE_FIELD_NAME (type
, 0) == NULL
6632 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6633 || TYPE_FIELD_NAME (type
, 1) == NULL
6634 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6637 /* Find the type of the method. */
6638 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6639 if (pfn_type
== NULL
6640 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6641 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6644 /* Look for the "this" argument. */
6645 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6646 if (TYPE_NFIELDS (pfn_type
) == 0
6647 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6648 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6651 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6652 new_type
= alloc_type (objfile
);
6653 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6654 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6655 TYPE_VARARGS (pfn_type
));
6656 smash_to_methodptr_type (type
, new_type
);
6659 /* Called when we find the DIE that starts a structure or union scope
6660 (definition) to create a type for the structure or union. Fill in
6661 the type's name and general properties; the members will not be
6662 processed until process_structure_type.
6664 NOTE: we need to call these functions regardless of whether or not the
6665 DIE has a DW_AT_name attribute, since it might be an anonymous
6666 structure or union. This gets the type entered into our set of
6669 However, if the structure is incomplete (an opaque struct/union)
6670 then suppress creating a symbol table entry for it since gdb only
6671 wants to find the one with the complete definition. Note that if
6672 it is complete, we just call new_symbol, which does it's own
6673 checking about whether the struct/union is anonymous or not (and
6674 suppresses creating a symbol table entry itself). */
6676 static struct type
*
6677 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6679 struct objfile
*objfile
= cu
->objfile
;
6681 struct attribute
*attr
;
6684 /* If the definition of this type lives in .debug_types, read that type.
6685 Don't follow DW_AT_specification though, that will take us back up
6686 the chain and we want to go down. */
6687 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6690 struct dwarf2_cu
*type_cu
= cu
;
6691 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6693 /* We could just recurse on read_structure_type, but we need to call
6694 get_die_type to ensure only one type for this DIE is created.
6695 This is important, for example, because for c++ classes we need
6696 TYPE_NAME set which is only done by new_symbol. Blech. */
6697 type
= read_type_die (type_die
, type_cu
);
6699 /* TYPE_CU may not be the same as CU.
6700 Ensure TYPE is recorded in CU's type_hash table. */
6701 return set_die_type (die
, type
, cu
);
6704 type
= alloc_type (objfile
);
6705 INIT_CPLUS_SPECIFIC (type
);
6707 name
= dwarf2_name (die
, cu
);
6710 if (cu
->language
== language_cplus
6711 || cu
->language
== language_java
)
6713 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6715 /* dwarf2_full_name might have already finished building the DIE's
6716 type. If so, there is no need to continue. */
6717 if (get_die_type (die
, cu
) != NULL
)
6718 return get_die_type (die
, cu
);
6720 TYPE_TAG_NAME (type
) = full_name
;
6721 if (die
->tag
== DW_TAG_structure_type
6722 || die
->tag
== DW_TAG_class_type
)
6723 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6727 /* The name is already allocated along with this objfile, so
6728 we don't need to duplicate it for the type. */
6729 TYPE_TAG_NAME (type
) = (char *) name
;
6730 if (die
->tag
== DW_TAG_class_type
)
6731 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6735 if (die
->tag
== DW_TAG_structure_type
)
6737 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6739 else if (die
->tag
== DW_TAG_union_type
)
6741 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6745 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6748 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6749 TYPE_DECLARED_CLASS (type
) = 1;
6751 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6754 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6758 TYPE_LENGTH (type
) = 0;
6761 TYPE_STUB_SUPPORTED (type
) = 1;
6762 if (die_is_declaration (die
, cu
))
6763 TYPE_STUB (type
) = 1;
6764 else if (attr
== NULL
&& die
->child
== NULL
6765 && producer_is_realview (cu
->producer
))
6766 /* RealView does not output the required DW_AT_declaration
6767 on incomplete types. */
6768 TYPE_STUB (type
) = 1;
6770 /* We need to add the type field to the die immediately so we don't
6771 infinitely recurse when dealing with pointers to the structure
6772 type within the structure itself. */
6773 set_die_type (die
, type
, cu
);
6775 /* set_die_type should be already done. */
6776 set_descriptive_type (type
, die
, cu
);
6781 /* Finish creating a structure or union type, including filling in
6782 its members and creating a symbol for it. */
6785 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6787 struct objfile
*objfile
= cu
->objfile
;
6788 struct die_info
*child_die
= die
->child
;
6791 type
= get_die_type (die
, cu
);
6793 type
= read_structure_type (die
, cu
);
6795 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6797 struct field_info fi
;
6798 struct die_info
*child_die
;
6799 VEC (symbolp
) *template_args
= NULL
;
6800 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6802 memset (&fi
, 0, sizeof (struct field_info
));
6804 child_die
= die
->child
;
6806 while (child_die
&& child_die
->tag
)
6808 if (child_die
->tag
== DW_TAG_member
6809 || child_die
->tag
== DW_TAG_variable
)
6811 /* NOTE: carlton/2002-11-05: A C++ static data member
6812 should be a DW_TAG_member that is a declaration, but
6813 all versions of G++ as of this writing (so through at
6814 least 3.2.1) incorrectly generate DW_TAG_variable
6815 tags for them instead. */
6816 dwarf2_add_field (&fi
, child_die
, cu
);
6818 else if (child_die
->tag
== DW_TAG_subprogram
)
6820 /* C++ member function. */
6821 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6823 else if (child_die
->tag
== DW_TAG_inheritance
)
6825 /* C++ base class field. */
6826 dwarf2_add_field (&fi
, child_die
, cu
);
6828 else if (child_die
->tag
== DW_TAG_typedef
)
6829 dwarf2_add_typedef (&fi
, child_die
, cu
);
6830 else if (child_die
->tag
== DW_TAG_template_type_param
6831 || child_die
->tag
== DW_TAG_template_value_param
)
6833 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6836 VEC_safe_push (symbolp
, template_args
, arg
);
6839 child_die
= sibling_die (child_die
);
6842 /* Attach template arguments to type. */
6843 if (! VEC_empty (symbolp
, template_args
))
6845 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6846 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6847 = VEC_length (symbolp
, template_args
);
6848 TYPE_TEMPLATE_ARGUMENTS (type
)
6849 = obstack_alloc (&objfile
->objfile_obstack
,
6850 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6851 * sizeof (struct symbol
*)));
6852 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6853 VEC_address (symbolp
, template_args
),
6854 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6855 * sizeof (struct symbol
*)));
6856 VEC_free (symbolp
, template_args
);
6859 /* Attach fields and member functions to the type. */
6861 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6864 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6866 /* Get the type which refers to the base class (possibly this
6867 class itself) which contains the vtable pointer for the current
6868 class from the DW_AT_containing_type attribute. This use of
6869 DW_AT_containing_type is a GNU extension. */
6871 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6873 struct type
*t
= die_containing_type (die
, cu
);
6875 TYPE_VPTR_BASETYPE (type
) = t
;
6880 /* Our own class provides vtbl ptr. */
6881 for (i
= TYPE_NFIELDS (t
) - 1;
6882 i
>= TYPE_N_BASECLASSES (t
);
6885 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6887 if (is_vtable_name (fieldname
, cu
))
6889 TYPE_VPTR_FIELDNO (type
) = i
;
6894 /* Complain if virtual function table field not found. */
6895 if (i
< TYPE_N_BASECLASSES (t
))
6896 complaint (&symfile_complaints
,
6897 _("virtual function table pointer not found when defining class '%s'"),
6898 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6903 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6906 else if (cu
->producer
6907 && strncmp (cu
->producer
,
6908 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6910 /* The IBM XLC compiler does not provide direct indication
6911 of the containing type, but the vtable pointer is
6912 always named __vfp. */
6916 for (i
= TYPE_NFIELDS (type
) - 1;
6917 i
>= TYPE_N_BASECLASSES (type
);
6920 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6922 TYPE_VPTR_FIELDNO (type
) = i
;
6923 TYPE_VPTR_BASETYPE (type
) = type
;
6930 /* Copy fi.typedef_field_list linked list elements content into the
6931 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6932 if (fi
.typedef_field_list
)
6934 int i
= fi
.typedef_field_list_count
;
6936 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6937 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6938 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6939 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6941 /* Reverse the list order to keep the debug info elements order. */
6944 struct typedef_field
*dest
, *src
;
6946 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6947 src
= &fi
.typedef_field_list
->field
;
6948 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6953 do_cleanups (back_to
);
6956 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6958 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6959 snapshots) has been known to create a die giving a declaration
6960 for a class that has, as a child, a die giving a definition for a
6961 nested class. So we have to process our children even if the
6962 current die is a declaration. Normally, of course, a declaration
6963 won't have any children at all. */
6965 while (child_die
!= NULL
&& child_die
->tag
)
6967 if (child_die
->tag
== DW_TAG_member
6968 || child_die
->tag
== DW_TAG_variable
6969 || child_die
->tag
== DW_TAG_inheritance
6970 || child_die
->tag
== DW_TAG_template_value_param
6971 || child_die
->tag
== DW_TAG_template_type_param
)
6976 process_die (child_die
, cu
);
6978 child_die
= sibling_die (child_die
);
6981 /* Do not consider external references. According to the DWARF standard,
6982 these DIEs are identified by the fact that they have no byte_size
6983 attribute, and a declaration attribute. */
6984 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6985 || !die_is_declaration (die
, cu
))
6986 new_symbol (die
, type
, cu
);
6989 /* Given a DW_AT_enumeration_type die, set its type. We do not
6990 complete the type's fields yet, or create any symbols. */
6992 static struct type
*
6993 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6995 struct objfile
*objfile
= cu
->objfile
;
6997 struct attribute
*attr
;
7000 /* If the definition of this type lives in .debug_types, read that type.
7001 Don't follow DW_AT_specification though, that will take us back up
7002 the chain and we want to go down. */
7003 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7006 struct dwarf2_cu
*type_cu
= cu
;
7007 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7009 type
= read_type_die (type_die
, type_cu
);
7011 /* TYPE_CU may not be the same as CU.
7012 Ensure TYPE is recorded in CU's type_hash table. */
7013 return set_die_type (die
, type
, cu
);
7016 type
= alloc_type (objfile
);
7018 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7019 name
= dwarf2_full_name (NULL
, die
, cu
);
7021 TYPE_TAG_NAME (type
) = (char *) name
;
7023 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7026 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7030 TYPE_LENGTH (type
) = 0;
7033 /* The enumeration DIE can be incomplete. In Ada, any type can be
7034 declared as private in the package spec, and then defined only
7035 inside the package body. Such types are known as Taft Amendment
7036 Types. When another package uses such a type, an incomplete DIE
7037 may be generated by the compiler. */
7038 if (die_is_declaration (die
, cu
))
7039 TYPE_STUB (type
) = 1;
7041 return set_die_type (die
, type
, cu
);
7044 /* Given a pointer to a die which begins an enumeration, process all
7045 the dies that define the members of the enumeration, and create the
7046 symbol for the enumeration type.
7048 NOTE: We reverse the order of the element list. */
7051 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7053 struct type
*this_type
;
7055 this_type
= get_die_type (die
, cu
);
7056 if (this_type
== NULL
)
7057 this_type
= read_enumeration_type (die
, cu
);
7059 if (die
->child
!= NULL
)
7061 struct die_info
*child_die
;
7063 struct field
*fields
= NULL
;
7065 int unsigned_enum
= 1;
7068 child_die
= die
->child
;
7069 while (child_die
&& child_die
->tag
)
7071 if (child_die
->tag
!= DW_TAG_enumerator
)
7073 process_die (child_die
, cu
);
7077 name
= dwarf2_name (child_die
, cu
);
7080 sym
= new_symbol (child_die
, this_type
, cu
);
7081 if (SYMBOL_VALUE (sym
) < 0)
7084 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7086 fields
= (struct field
*)
7088 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7089 * sizeof (struct field
));
7092 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7093 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7094 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7095 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7101 child_die
= sibling_die (child_die
);
7106 TYPE_NFIELDS (this_type
) = num_fields
;
7107 TYPE_FIELDS (this_type
) = (struct field
*)
7108 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7109 memcpy (TYPE_FIELDS (this_type
), fields
,
7110 sizeof (struct field
) * num_fields
);
7114 TYPE_UNSIGNED (this_type
) = 1;
7117 new_symbol (die
, this_type
, cu
);
7120 /* Extract all information from a DW_TAG_array_type DIE and put it in
7121 the DIE's type field. For now, this only handles one dimensional
7124 static struct type
*
7125 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7127 struct objfile
*objfile
= cu
->objfile
;
7128 struct die_info
*child_die
;
7130 struct type
*element_type
, *range_type
, *index_type
;
7131 struct type
**range_types
= NULL
;
7132 struct attribute
*attr
;
7134 struct cleanup
*back_to
;
7137 element_type
= die_type (die
, cu
);
7139 /* The die_type call above may have already set the type for this DIE. */
7140 type
= get_die_type (die
, cu
);
7144 /* Irix 6.2 native cc creates array types without children for
7145 arrays with unspecified length. */
7146 if (die
->child
== NULL
)
7148 index_type
= objfile_type (objfile
)->builtin_int
;
7149 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7150 type
= create_array_type (NULL
, element_type
, range_type
);
7151 return set_die_type (die
, type
, cu
);
7154 back_to
= make_cleanup (null_cleanup
, NULL
);
7155 child_die
= die
->child
;
7156 while (child_die
&& child_die
->tag
)
7158 if (child_die
->tag
== DW_TAG_subrange_type
)
7160 struct type
*child_type
= read_type_die (child_die
, cu
);
7162 if (child_type
!= NULL
)
7164 /* The range type was succesfully read. Save it for
7165 the array type creation. */
7166 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7168 range_types
= (struct type
**)
7169 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7170 * sizeof (struct type
*));
7172 make_cleanup (free_current_contents
, &range_types
);
7174 range_types
[ndim
++] = child_type
;
7177 child_die
= sibling_die (child_die
);
7180 /* Dwarf2 dimensions are output from left to right, create the
7181 necessary array types in backwards order. */
7183 type
= element_type
;
7185 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7190 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7195 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7198 /* Understand Dwarf2 support for vector types (like they occur on
7199 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7200 array type. This is not part of the Dwarf2/3 standard yet, but a
7201 custom vendor extension. The main difference between a regular
7202 array and the vector variant is that vectors are passed by value
7204 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7206 make_vector_type (type
);
7208 name
= dwarf2_name (die
, cu
);
7210 TYPE_NAME (type
) = name
;
7212 /* Install the type in the die. */
7213 set_die_type (die
, type
, cu
);
7215 /* set_die_type should be already done. */
7216 set_descriptive_type (type
, die
, cu
);
7218 do_cleanups (back_to
);
7223 static enum dwarf_array_dim_ordering
7224 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7226 struct attribute
*attr
;
7228 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7230 if (attr
) return DW_SND (attr
);
7233 GNU F77 is a special case, as at 08/2004 array type info is the
7234 opposite order to the dwarf2 specification, but data is still
7235 laid out as per normal fortran.
7237 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7241 if (cu
->language
== language_fortran
7242 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7244 return DW_ORD_row_major
;
7247 switch (cu
->language_defn
->la_array_ordering
)
7249 case array_column_major
:
7250 return DW_ORD_col_major
;
7251 case array_row_major
:
7253 return DW_ORD_row_major
;
7257 /* Extract all information from a DW_TAG_set_type DIE and put it in
7258 the DIE's type field. */
7260 static struct type
*
7261 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7263 struct type
*domain_type
, *set_type
;
7264 struct attribute
*attr
;
7266 domain_type
= die_type (die
, cu
);
7268 /* The die_type call above may have already set the type for this DIE. */
7269 set_type
= get_die_type (die
, cu
);
7273 set_type
= create_set_type (NULL
, domain_type
);
7275 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7277 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7279 return set_die_type (die
, set_type
, cu
);
7282 /* First cut: install each common block member as a global variable. */
7285 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7287 struct die_info
*child_die
;
7288 struct attribute
*attr
;
7290 CORE_ADDR base
= (CORE_ADDR
) 0;
7292 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7295 /* Support the .debug_loc offsets */
7296 if (attr_form_is_block (attr
))
7298 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7300 else if (attr_form_is_section_offset (attr
))
7302 dwarf2_complex_location_expr_complaint ();
7306 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7307 "common block member");
7310 if (die
->child
!= NULL
)
7312 child_die
= die
->child
;
7313 while (child_die
&& child_die
->tag
)
7315 sym
= new_symbol (child_die
, NULL
, cu
);
7316 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7317 if (sym
!= NULL
&& attr
!= NULL
)
7319 CORE_ADDR byte_offset
= 0;
7321 if (attr_form_is_section_offset (attr
))
7322 dwarf2_complex_location_expr_complaint ();
7323 else if (attr_form_is_constant (attr
))
7324 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7325 else if (attr_form_is_block (attr
))
7326 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7328 dwarf2_complex_location_expr_complaint ();
7330 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7331 add_symbol_to_list (sym
, &global_symbols
);
7333 child_die
= sibling_die (child_die
);
7338 /* Create a type for a C++ namespace. */
7340 static struct type
*
7341 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7343 struct objfile
*objfile
= cu
->objfile
;
7344 const char *previous_prefix
, *name
;
7348 /* For extensions, reuse the type of the original namespace. */
7349 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7351 struct die_info
*ext_die
;
7352 struct dwarf2_cu
*ext_cu
= cu
;
7354 ext_die
= dwarf2_extension (die
, &ext_cu
);
7355 type
= read_type_die (ext_die
, ext_cu
);
7357 /* EXT_CU may not be the same as CU.
7358 Ensure TYPE is recorded in CU's type_hash table. */
7359 return set_die_type (die
, type
, cu
);
7362 name
= namespace_name (die
, &is_anonymous
, cu
);
7364 /* Now build the name of the current namespace. */
7366 previous_prefix
= determine_prefix (die
, cu
);
7367 if (previous_prefix
[0] != '\0')
7368 name
= typename_concat (&objfile
->objfile_obstack
,
7369 previous_prefix
, name
, 0, cu
);
7371 /* Create the type. */
7372 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7374 TYPE_NAME (type
) = (char *) name
;
7375 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7377 return set_die_type (die
, type
, cu
);
7380 /* Read a C++ namespace. */
7383 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7385 struct objfile
*objfile
= cu
->objfile
;
7389 /* Add a symbol associated to this if we haven't seen the namespace
7390 before. Also, add a using directive if it's an anonymous
7393 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7397 type
= read_type_die (die
, cu
);
7398 new_symbol (die
, type
, cu
);
7400 name
= namespace_name (die
, &is_anonymous
, cu
);
7403 const char *previous_prefix
= determine_prefix (die
, cu
);
7405 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7406 NULL
, &objfile
->objfile_obstack
);
7410 if (die
->child
!= NULL
)
7412 struct die_info
*child_die
= die
->child
;
7414 while (child_die
&& child_die
->tag
)
7416 process_die (child_die
, cu
);
7417 child_die
= sibling_die (child_die
);
7422 /* Read a Fortran module as type. This DIE can be only a declaration used for
7423 imported module. Still we need that type as local Fortran "use ... only"
7424 declaration imports depend on the created type in determine_prefix. */
7426 static struct type
*
7427 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7429 struct objfile
*objfile
= cu
->objfile
;
7433 module_name
= dwarf2_name (die
, cu
);
7435 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
7437 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7439 /* determine_prefix uses TYPE_TAG_NAME. */
7440 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7442 return set_die_type (die
, type
, cu
);
7445 /* Read a Fortran module. */
7448 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7450 struct die_info
*child_die
= die
->child
;
7452 while (child_die
&& child_die
->tag
)
7454 process_die (child_die
, cu
);
7455 child_die
= sibling_die (child_die
);
7459 /* Return the name of the namespace represented by DIE. Set
7460 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7464 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7466 struct die_info
*current_die
;
7467 const char *name
= NULL
;
7469 /* Loop through the extensions until we find a name. */
7471 for (current_die
= die
;
7472 current_die
!= NULL
;
7473 current_die
= dwarf2_extension (die
, &cu
))
7475 name
= dwarf2_name (current_die
, cu
);
7480 /* Is it an anonymous namespace? */
7482 *is_anonymous
= (name
== NULL
);
7484 name
= "(anonymous namespace)";
7489 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7490 the user defined type vector. */
7492 static struct type
*
7493 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7495 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7496 struct comp_unit_head
*cu_header
= &cu
->header
;
7498 struct attribute
*attr_byte_size
;
7499 struct attribute
*attr_address_class
;
7500 int byte_size
, addr_class
;
7501 struct type
*target_type
;
7503 target_type
= die_type (die
, cu
);
7505 /* The die_type call above may have already set the type for this DIE. */
7506 type
= get_die_type (die
, cu
);
7510 type
= lookup_pointer_type (target_type
);
7512 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7514 byte_size
= DW_UNSND (attr_byte_size
);
7516 byte_size
= cu_header
->addr_size
;
7518 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7519 if (attr_address_class
)
7520 addr_class
= DW_UNSND (attr_address_class
);
7522 addr_class
= DW_ADDR_none
;
7524 /* If the pointer size or address class is different than the
7525 default, create a type variant marked as such and set the
7526 length accordingly. */
7527 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7529 if (gdbarch_address_class_type_flags_p (gdbarch
))
7533 type_flags
= gdbarch_address_class_type_flags
7534 (gdbarch
, byte_size
, addr_class
);
7535 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7537 type
= make_type_with_address_space (type
, type_flags
);
7539 else if (TYPE_LENGTH (type
) != byte_size
)
7541 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
7545 /* Should we also complain about unhandled address classes? */
7549 TYPE_LENGTH (type
) = byte_size
;
7550 return set_die_type (die
, type
, cu
);
7553 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7554 the user defined type vector. */
7556 static struct type
*
7557 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7560 struct type
*to_type
;
7561 struct type
*domain
;
7563 to_type
= die_type (die
, cu
);
7564 domain
= die_containing_type (die
, cu
);
7566 /* The calls above may have already set the type for this DIE. */
7567 type
= get_die_type (die
, cu
);
7571 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7572 type
= lookup_methodptr_type (to_type
);
7574 type
= lookup_memberptr_type (to_type
, domain
);
7576 return set_die_type (die
, type
, cu
);
7579 /* Extract all information from a DW_TAG_reference_type DIE and add to
7580 the user defined type vector. */
7582 static struct type
*
7583 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7585 struct comp_unit_head
*cu_header
= &cu
->header
;
7586 struct type
*type
, *target_type
;
7587 struct attribute
*attr
;
7589 target_type
= die_type (die
, cu
);
7591 /* The die_type call above may have already set the type for this DIE. */
7592 type
= get_die_type (die
, cu
);
7596 type
= lookup_reference_type (target_type
);
7597 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7600 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7604 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7606 return set_die_type (die
, type
, cu
);
7609 static struct type
*
7610 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7612 struct type
*base_type
, *cv_type
;
7614 base_type
= die_type (die
, cu
);
7616 /* The die_type call above may have already set the type for this DIE. */
7617 cv_type
= get_die_type (die
, cu
);
7621 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7622 return set_die_type (die
, cv_type
, cu
);
7625 static struct type
*
7626 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7628 struct type
*base_type
, *cv_type
;
7630 base_type
= die_type (die
, cu
);
7632 /* The die_type call above may have already set the type for this DIE. */
7633 cv_type
= get_die_type (die
, cu
);
7637 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7638 return set_die_type (die
, cv_type
, cu
);
7641 /* Extract all information from a DW_TAG_string_type DIE and add to
7642 the user defined type vector. It isn't really a user defined type,
7643 but it behaves like one, with other DIE's using an AT_user_def_type
7644 attribute to reference it. */
7646 static struct type
*
7647 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7649 struct objfile
*objfile
= cu
->objfile
;
7650 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7651 struct type
*type
, *range_type
, *index_type
, *char_type
;
7652 struct attribute
*attr
;
7653 unsigned int length
;
7655 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7658 length
= DW_UNSND (attr
);
7662 /* check for the DW_AT_byte_size attribute */
7663 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7666 length
= DW_UNSND (attr
);
7674 index_type
= objfile_type (objfile
)->builtin_int
;
7675 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7676 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7677 type
= create_string_type (NULL
, char_type
, range_type
);
7679 return set_die_type (die
, type
, cu
);
7682 /* Handle DIES due to C code like:
7686 int (*funcp)(int a, long l);
7690 ('funcp' generates a DW_TAG_subroutine_type DIE)
7693 static struct type
*
7694 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7696 struct type
*type
; /* Type that this function returns */
7697 struct type
*ftype
; /* Function that returns above type */
7698 struct attribute
*attr
;
7700 type
= die_type (die
, cu
);
7702 /* The die_type call above may have already set the type for this DIE. */
7703 ftype
= get_die_type (die
, cu
);
7707 ftype
= lookup_function_type (type
);
7709 /* All functions in C++, Pascal and Java have prototypes. */
7710 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7711 if ((attr
&& (DW_UNSND (attr
) != 0))
7712 || cu
->language
== language_cplus
7713 || cu
->language
== language_java
7714 || cu
->language
== language_pascal
)
7715 TYPE_PROTOTYPED (ftype
) = 1;
7716 else if (producer_is_realview (cu
->producer
))
7717 /* RealView does not emit DW_AT_prototyped. We can not
7718 distinguish prototyped and unprototyped functions; default to
7719 prototyped, since that is more common in modern code (and
7720 RealView warns about unprototyped functions). */
7721 TYPE_PROTOTYPED (ftype
) = 1;
7723 /* Store the calling convention in the type if it's available in
7724 the subroutine die. Otherwise set the calling convention to
7725 the default value DW_CC_normal. */
7726 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7727 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7729 /* We need to add the subroutine type to the die immediately so
7730 we don't infinitely recurse when dealing with parameters
7731 declared as the same subroutine type. */
7732 set_die_type (die
, ftype
, cu
);
7734 if (die
->child
!= NULL
)
7736 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7737 struct die_info
*child_die
;
7738 int nparams
, iparams
;
7740 /* Count the number of parameters.
7741 FIXME: GDB currently ignores vararg functions, but knows about
7742 vararg member functions. */
7744 child_die
= die
->child
;
7745 while (child_die
&& child_die
->tag
)
7747 if (child_die
->tag
== DW_TAG_formal_parameter
)
7749 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7750 TYPE_VARARGS (ftype
) = 1;
7751 child_die
= sibling_die (child_die
);
7754 /* Allocate storage for parameters and fill them in. */
7755 TYPE_NFIELDS (ftype
) = nparams
;
7756 TYPE_FIELDS (ftype
) = (struct field
*)
7757 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7759 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7760 even if we error out during the parameters reading below. */
7761 for (iparams
= 0; iparams
< nparams
; iparams
++)
7762 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7765 child_die
= die
->child
;
7766 while (child_die
&& child_die
->tag
)
7768 if (child_die
->tag
== DW_TAG_formal_parameter
)
7770 struct type
*arg_type
;
7772 /* DWARF version 2 has no clean way to discern C++
7773 static and non-static member functions. G++ helps
7774 GDB by marking the first parameter for non-static
7775 member functions (which is the this pointer) as
7776 artificial. We pass this information to
7777 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7779 DWARF version 3 added DW_AT_object_pointer, which GCC
7780 4.5 does not yet generate. */
7781 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7783 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7786 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7788 /* GCC/43521: In java, the formal parameter
7789 "this" is sometimes not marked with DW_AT_artificial. */
7790 if (cu
->language
== language_java
)
7792 const char *name
= dwarf2_name (child_die
, cu
);
7794 if (name
&& !strcmp (name
, "this"))
7795 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7798 arg_type
= die_type (child_die
, cu
);
7800 /* RealView does not mark THIS as const, which the testsuite
7801 expects. GCC marks THIS as const in method definitions,
7802 but not in the class specifications (GCC PR 43053). */
7803 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7804 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7807 struct dwarf2_cu
*arg_cu
= cu
;
7808 const char *name
= dwarf2_name (child_die
, cu
);
7810 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7813 /* If the compiler emits this, use it. */
7814 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
7817 else if (name
&& strcmp (name
, "this") == 0)
7818 /* Function definitions will have the argument names. */
7820 else if (name
== NULL
&& iparams
== 0)
7821 /* Declarations may not have the names, so like
7822 elsewhere in GDB, assume an artificial first
7823 argument is "this". */
7827 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
7831 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
7834 child_die
= sibling_die (child_die
);
7841 static struct type
*
7842 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7844 struct objfile
*objfile
= cu
->objfile
;
7845 const char *name
= NULL
;
7846 struct type
*this_type
;
7848 name
= dwarf2_full_name (NULL
, die
, cu
);
7849 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7850 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7851 TYPE_NAME (this_type
) = (char *) name
;
7852 set_die_type (die
, this_type
, cu
);
7853 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7857 /* Find a representation of a given base type and install
7858 it in the TYPE field of the die. */
7860 static struct type
*
7861 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7863 struct objfile
*objfile
= cu
->objfile
;
7865 struct attribute
*attr
;
7866 int encoding
= 0, size
= 0;
7868 enum type_code code
= TYPE_CODE_INT
;
7870 struct type
*target_type
= NULL
;
7872 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7875 encoding
= DW_UNSND (attr
);
7877 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7880 size
= DW_UNSND (attr
);
7882 name
= dwarf2_name (die
, cu
);
7885 complaint (&symfile_complaints
,
7886 _("DW_AT_name missing from DW_TAG_base_type"));
7891 case DW_ATE_address
:
7892 /* Turn DW_ATE_address into a void * pointer. */
7893 code
= TYPE_CODE_PTR
;
7894 type_flags
|= TYPE_FLAG_UNSIGNED
;
7895 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7897 case DW_ATE_boolean
:
7898 code
= TYPE_CODE_BOOL
;
7899 type_flags
|= TYPE_FLAG_UNSIGNED
;
7901 case DW_ATE_complex_float
:
7902 code
= TYPE_CODE_COMPLEX
;
7903 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7905 case DW_ATE_decimal_float
:
7906 code
= TYPE_CODE_DECFLOAT
;
7909 code
= TYPE_CODE_FLT
;
7913 case DW_ATE_unsigned
:
7914 type_flags
|= TYPE_FLAG_UNSIGNED
;
7916 case DW_ATE_signed_char
:
7917 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7918 || cu
->language
== language_pascal
)
7919 code
= TYPE_CODE_CHAR
;
7921 case DW_ATE_unsigned_char
:
7922 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7923 || cu
->language
== language_pascal
)
7924 code
= TYPE_CODE_CHAR
;
7925 type_flags
|= TYPE_FLAG_UNSIGNED
;
7928 /* We just treat this as an integer and then recognize the
7929 type by name elsewhere. */
7933 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7934 dwarf_type_encoding_name (encoding
));
7938 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7939 TYPE_NAME (type
) = name
;
7940 TYPE_TARGET_TYPE (type
) = target_type
;
7942 if (name
&& strcmp (name
, "char") == 0)
7943 TYPE_NOSIGN (type
) = 1;
7945 return set_die_type (die
, type
, cu
);
7948 /* Read the given DW_AT_subrange DIE. */
7950 static struct type
*
7951 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7953 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7954 struct type
*base_type
;
7955 struct type
*range_type
;
7956 struct attribute
*attr
;
7960 LONGEST negative_mask
;
7962 base_type
= die_type (die
, cu
);
7963 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7964 check_typedef (base_type
);
7966 /* The die_type call above may have already set the type for this DIE. */
7967 range_type
= get_die_type (die
, cu
);
7971 if (cu
->language
== language_fortran
)
7973 /* FORTRAN implies a lower bound of 1, if not given. */
7977 /* FIXME: For variable sized arrays either of these could be
7978 a variable rather than a constant value. We'll allow it,
7979 but we don't know how to handle it. */
7980 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
7982 low
= dwarf2_get_attr_constant_value (attr
, 0);
7984 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
7987 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
7989 /* GCC encodes arrays with unspecified or dynamic length
7990 with a DW_FORM_block1 attribute or a reference attribute.
7991 FIXME: GDB does not yet know how to handle dynamic
7992 arrays properly, treat them as arrays with unspecified
7995 FIXME: jimb/2003-09-22: GDB does not really know
7996 how to handle arrays of unspecified length
7997 either; we just represent them as zero-length
7998 arrays. Choose an appropriate upper bound given
7999 the lower bound we've computed above. */
8003 high
= dwarf2_get_attr_constant_value (attr
, 1);
8007 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8010 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8011 high
= low
+ count
- 1;
8015 /* Dwarf-2 specifications explicitly allows to create subrange types
8016 without specifying a base type.
8017 In that case, the base type must be set to the type of
8018 the lower bound, upper bound or count, in that order, if any of these
8019 three attributes references an object that has a type.
8020 If no base type is found, the Dwarf-2 specifications say that
8021 a signed integer type of size equal to the size of an address should
8023 For the following C code: `extern char gdb_int [];'
8024 GCC produces an empty range DIE.
8025 FIXME: muller/2010-05-28: Possible references to object for low bound,
8026 high bound or count are not yet handled by this code.
8028 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8030 struct objfile
*objfile
= cu
->objfile
;
8031 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8032 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8033 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8035 /* Test "int", "long int", and "long long int" objfile types,
8036 and select the first one having a size above or equal to the
8037 architecture address size. */
8038 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8039 base_type
= int_type
;
8042 int_type
= objfile_type (objfile
)->builtin_long
;
8043 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8044 base_type
= int_type
;
8047 int_type
= objfile_type (objfile
)->builtin_long_long
;
8048 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8049 base_type
= int_type
;
8055 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8056 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8057 low
|= negative_mask
;
8058 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8059 high
|= negative_mask
;
8061 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8063 /* Mark arrays with dynamic length at least as an array of unspecified
8064 length. GDB could check the boundary but before it gets implemented at
8065 least allow accessing the array elements. */
8066 if (attr
&& attr
->form
== DW_FORM_block1
)
8067 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8069 name
= dwarf2_name (die
, cu
);
8071 TYPE_NAME (range_type
) = name
;
8073 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8075 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8077 set_die_type (die
, range_type
, cu
);
8079 /* set_die_type should be already done. */
8080 set_descriptive_type (range_type
, die
, cu
);
8085 static struct type
*
8086 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8090 /* For now, we only support the C meaning of an unspecified type: void. */
8092 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8093 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8095 return set_die_type (die
, type
, cu
);
8098 /* Trivial hash function for die_info: the hash value of a DIE
8099 is its offset in .debug_info for this objfile. */
8102 die_hash (const void *item
)
8104 const struct die_info
*die
= item
;
8109 /* Trivial comparison function for die_info structures: two DIEs
8110 are equal if they have the same offset. */
8113 die_eq (const void *item_lhs
, const void *item_rhs
)
8115 const struct die_info
*die_lhs
= item_lhs
;
8116 const struct die_info
*die_rhs
= item_rhs
;
8118 return die_lhs
->offset
== die_rhs
->offset
;
8121 /* Read a whole compilation unit into a linked list of dies. */
8123 static struct die_info
*
8124 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8126 struct die_reader_specs reader_specs
;
8127 int read_abbrevs
= 0;
8128 struct cleanup
*back_to
= NULL
;
8129 struct die_info
*die
;
8131 if (cu
->dwarf2_abbrevs
== NULL
)
8133 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8134 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8138 gdb_assert (cu
->die_hash
== NULL
);
8140 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8144 &cu
->comp_unit_obstack
,
8145 hashtab_obstack_allocate
,
8146 dummy_obstack_deallocate
);
8148 init_cu_die_reader (&reader_specs
, cu
);
8150 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8153 do_cleanups (back_to
);
8158 /* Main entry point for reading a DIE and all children.
8159 Read the DIE and dump it if requested. */
8161 static struct die_info
*
8162 read_die_and_children (const struct die_reader_specs
*reader
,
8164 gdb_byte
**new_info_ptr
,
8165 struct die_info
*parent
)
8167 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8168 new_info_ptr
, parent
);
8170 if (dwarf2_die_debug
)
8172 fprintf_unfiltered (gdb_stdlog
,
8173 "\nRead die from %s of %s:\n",
8174 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8176 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8178 : "unknown section",
8179 reader
->abfd
->filename
);
8180 dump_die (result
, dwarf2_die_debug
);
8186 /* Read a single die and all its descendents. Set the die's sibling
8187 field to NULL; set other fields in the die correctly, and set all
8188 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8189 location of the info_ptr after reading all of those dies. PARENT
8190 is the parent of the die in question. */
8192 static struct die_info
*
8193 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8195 gdb_byte
**new_info_ptr
,
8196 struct die_info
*parent
)
8198 struct die_info
*die
;
8202 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8205 *new_info_ptr
= cur_ptr
;
8208 store_in_ref_table (die
, reader
->cu
);
8211 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8215 *new_info_ptr
= cur_ptr
;
8218 die
->sibling
= NULL
;
8219 die
->parent
= parent
;
8223 /* Read a die, all of its descendents, and all of its siblings; set
8224 all of the fields of all of the dies correctly. Arguments are as
8225 in read_die_and_children. */
8227 static struct die_info
*
8228 read_die_and_siblings (const struct die_reader_specs
*reader
,
8230 gdb_byte
**new_info_ptr
,
8231 struct die_info
*parent
)
8233 struct die_info
*first_die
, *last_sibling
;
8237 first_die
= last_sibling
= NULL
;
8241 struct die_info
*die
8242 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8246 *new_info_ptr
= cur_ptr
;
8253 last_sibling
->sibling
= die
;
8259 /* Read the die from the .debug_info section buffer. Set DIEP to
8260 point to a newly allocated die with its information, except for its
8261 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8262 whether the die has children or not. */
8265 read_full_die (const struct die_reader_specs
*reader
,
8266 struct die_info
**diep
, gdb_byte
*info_ptr
,
8269 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8270 struct abbrev_info
*abbrev
;
8271 struct die_info
*die
;
8272 struct dwarf2_cu
*cu
= reader
->cu
;
8273 bfd
*abfd
= reader
->abfd
;
8275 offset
= info_ptr
- reader
->buffer
;
8276 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8277 info_ptr
+= bytes_read
;
8285 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8287 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8289 bfd_get_filename (abfd
));
8291 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8292 die
->offset
= offset
;
8293 die
->tag
= abbrev
->tag
;
8294 die
->abbrev
= abbrev_number
;
8296 die
->num_attrs
= abbrev
->num_attrs
;
8298 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8299 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8300 abfd
, info_ptr
, cu
);
8303 *has_children
= abbrev
->has_children
;
8307 /* In DWARF version 2, the description of the debugging information is
8308 stored in a separate .debug_abbrev section. Before we read any
8309 dies from a section we read in all abbreviations and install them
8310 in a hash table. This function also sets flags in CU describing
8311 the data found in the abbrev table. */
8314 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8316 struct comp_unit_head
*cu_header
= &cu
->header
;
8317 gdb_byte
*abbrev_ptr
;
8318 struct abbrev_info
*cur_abbrev
;
8319 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8320 unsigned int abbrev_form
, hash_number
;
8321 struct attr_abbrev
*cur_attrs
;
8322 unsigned int allocated_attrs
;
8324 /* Initialize dwarf2 abbrevs */
8325 obstack_init (&cu
->abbrev_obstack
);
8326 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8328 * sizeof (struct abbrev_info
*)));
8329 memset (cu
->dwarf2_abbrevs
, 0,
8330 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8332 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8333 &dwarf2_per_objfile
->abbrev
);
8334 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8335 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8336 abbrev_ptr
+= bytes_read
;
8338 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8339 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8341 /* loop until we reach an abbrev number of 0 */
8342 while (abbrev_number
)
8344 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8346 /* read in abbrev header */
8347 cur_abbrev
->number
= abbrev_number
;
8348 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8349 abbrev_ptr
+= bytes_read
;
8350 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8353 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8354 cu
->has_namespace_info
= 1;
8356 /* now read in declarations */
8357 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8358 abbrev_ptr
+= bytes_read
;
8359 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8360 abbrev_ptr
+= bytes_read
;
8363 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8365 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8367 = xrealloc (cur_attrs
, (allocated_attrs
8368 * sizeof (struct attr_abbrev
)));
8371 /* Record whether this compilation unit might have
8372 inter-compilation-unit references. If we don't know what form
8373 this attribute will have, then it might potentially be a
8374 DW_FORM_ref_addr, so we conservatively expect inter-CU
8377 if (abbrev_form
== DW_FORM_ref_addr
8378 || abbrev_form
== DW_FORM_indirect
)
8379 cu
->has_form_ref_addr
= 1;
8381 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8382 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8383 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8384 abbrev_ptr
+= bytes_read
;
8385 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8386 abbrev_ptr
+= bytes_read
;
8389 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8390 (cur_abbrev
->num_attrs
8391 * sizeof (struct attr_abbrev
)));
8392 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8393 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8395 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8396 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8397 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8399 /* Get next abbreviation.
8400 Under Irix6 the abbreviations for a compilation unit are not
8401 always properly terminated with an abbrev number of 0.
8402 Exit loop if we encounter an abbreviation which we have
8403 already read (which means we are about to read the abbreviations
8404 for the next compile unit) or if the end of the abbreviation
8405 table is reached. */
8406 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8407 >= dwarf2_per_objfile
->abbrev
.size
)
8409 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8410 abbrev_ptr
+= bytes_read
;
8411 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8418 /* Release the memory used by the abbrev table for a compilation unit. */
8421 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8423 struct dwarf2_cu
*cu
= ptr_to_cu
;
8425 obstack_free (&cu
->abbrev_obstack
, NULL
);
8426 cu
->dwarf2_abbrevs
= NULL
;
8429 /* Lookup an abbrev_info structure in the abbrev hash table. */
8431 static struct abbrev_info
*
8432 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8434 unsigned int hash_number
;
8435 struct abbrev_info
*abbrev
;
8437 hash_number
= number
% ABBREV_HASH_SIZE
;
8438 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8442 if (abbrev
->number
== number
)
8445 abbrev
= abbrev
->next
;
8450 /* Returns nonzero if TAG represents a type that we might generate a partial
8454 is_type_tag_for_partial (int tag
)
8459 /* Some types that would be reasonable to generate partial symbols for,
8460 that we don't at present. */
8461 case DW_TAG_array_type
:
8462 case DW_TAG_file_type
:
8463 case DW_TAG_ptr_to_member_type
:
8464 case DW_TAG_set_type
:
8465 case DW_TAG_string_type
:
8466 case DW_TAG_subroutine_type
:
8468 case DW_TAG_base_type
:
8469 case DW_TAG_class_type
:
8470 case DW_TAG_interface_type
:
8471 case DW_TAG_enumeration_type
:
8472 case DW_TAG_structure_type
:
8473 case DW_TAG_subrange_type
:
8474 case DW_TAG_typedef
:
8475 case DW_TAG_union_type
:
8482 /* Load all DIEs that are interesting for partial symbols into memory. */
8484 static struct partial_die_info
*
8485 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8486 int building_psymtab
, struct dwarf2_cu
*cu
)
8488 struct partial_die_info
*part_die
;
8489 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8490 struct abbrev_info
*abbrev
;
8491 unsigned int bytes_read
;
8492 unsigned int load_all
= 0;
8494 int nesting_level
= 1;
8499 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8503 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8507 &cu
->comp_unit_obstack
,
8508 hashtab_obstack_allocate
,
8509 dummy_obstack_deallocate
);
8511 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8512 sizeof (struct partial_die_info
));
8516 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8518 /* A NULL abbrev means the end of a series of children. */
8521 if (--nesting_level
== 0)
8523 /* PART_DIE was probably the last thing allocated on the
8524 comp_unit_obstack, so we could call obstack_free
8525 here. We don't do that because the waste is small,
8526 and will be cleaned up when we're done with this
8527 compilation unit. This way, we're also more robust
8528 against other users of the comp_unit_obstack. */
8531 info_ptr
+= bytes_read
;
8532 last_die
= parent_die
;
8533 parent_die
= parent_die
->die_parent
;
8537 /* Check for template arguments. We never save these; if
8538 they're seen, we just mark the parent, and go on our way. */
8539 if (parent_die
!= NULL
8540 && cu
->language
== language_cplus
8541 && (abbrev
->tag
== DW_TAG_template_type_param
8542 || abbrev
->tag
== DW_TAG_template_value_param
))
8544 parent_die
->has_template_arguments
= 1;
8548 /* We don't need a partial DIE for the template argument. */
8549 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8555 /* We only recurse into subprograms looking for template arguments.
8556 Skip their other children. */
8558 && cu
->language
== language_cplus
8559 && parent_die
!= NULL
8560 && parent_die
->tag
== DW_TAG_subprogram
)
8562 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8566 /* Check whether this DIE is interesting enough to save. Normally
8567 we would not be interested in members here, but there may be
8568 later variables referencing them via DW_AT_specification (for
8571 && !is_type_tag_for_partial (abbrev
->tag
)
8572 && abbrev
->tag
!= DW_TAG_enumerator
8573 && abbrev
->tag
!= DW_TAG_subprogram
8574 && abbrev
->tag
!= DW_TAG_lexical_block
8575 && abbrev
->tag
!= DW_TAG_variable
8576 && abbrev
->tag
!= DW_TAG_namespace
8577 && abbrev
->tag
!= DW_TAG_module
8578 && abbrev
->tag
!= DW_TAG_member
)
8580 /* Otherwise we skip to the next sibling, if any. */
8581 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8585 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8586 buffer
, info_ptr
, cu
);
8588 /* This two-pass algorithm for processing partial symbols has a
8589 high cost in cache pressure. Thus, handle some simple cases
8590 here which cover the majority of C partial symbols. DIEs
8591 which neither have specification tags in them, nor could have
8592 specification tags elsewhere pointing at them, can simply be
8593 processed and discarded.
8595 This segment is also optional; scan_partial_symbols and
8596 add_partial_symbol will handle these DIEs if we chain
8597 them in normally. When compilers which do not emit large
8598 quantities of duplicate debug information are more common,
8599 this code can probably be removed. */
8601 /* Any complete simple types at the top level (pretty much all
8602 of them, for a language without namespaces), can be processed
8604 if (parent_die
== NULL
8605 && part_die
->has_specification
== 0
8606 && part_die
->is_declaration
== 0
8607 && (part_die
->tag
== DW_TAG_typedef
8608 || part_die
->tag
== DW_TAG_base_type
8609 || part_die
->tag
== DW_TAG_subrange_type
))
8611 if (building_psymtab
&& part_die
->name
!= NULL
)
8612 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8613 VAR_DOMAIN
, LOC_TYPEDEF
,
8614 &cu
->objfile
->static_psymbols
,
8615 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8616 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8620 /* If we're at the second level, and we're an enumerator, and
8621 our parent has no specification (meaning possibly lives in a
8622 namespace elsewhere), then we can add the partial symbol now
8623 instead of queueing it. */
8624 if (part_die
->tag
== DW_TAG_enumerator
8625 && parent_die
!= NULL
8626 && parent_die
->die_parent
== NULL
8627 && parent_die
->tag
== DW_TAG_enumeration_type
8628 && parent_die
->has_specification
== 0)
8630 if (part_die
->name
== NULL
)
8631 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8632 else if (building_psymtab
)
8633 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8634 VAR_DOMAIN
, LOC_CONST
,
8635 (cu
->language
== language_cplus
8636 || cu
->language
== language_java
)
8637 ? &cu
->objfile
->global_psymbols
8638 : &cu
->objfile
->static_psymbols
,
8639 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8641 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8645 /* We'll save this DIE so link it in. */
8646 part_die
->die_parent
= parent_die
;
8647 part_die
->die_sibling
= NULL
;
8648 part_die
->die_child
= NULL
;
8650 if (last_die
&& last_die
== parent_die
)
8651 last_die
->die_child
= part_die
;
8653 last_die
->die_sibling
= part_die
;
8655 last_die
= part_die
;
8657 if (first_die
== NULL
)
8658 first_die
= part_die
;
8660 /* Maybe add the DIE to the hash table. Not all DIEs that we
8661 find interesting need to be in the hash table, because we
8662 also have the parent/sibling/child chains; only those that we
8663 might refer to by offset later during partial symbol reading.
8665 For now this means things that might have be the target of a
8666 DW_AT_specification, DW_AT_abstract_origin, or
8667 DW_AT_extension. DW_AT_extension will refer only to
8668 namespaces; DW_AT_abstract_origin refers to functions (and
8669 many things under the function DIE, but we do not recurse
8670 into function DIEs during partial symbol reading) and
8671 possibly variables as well; DW_AT_specification refers to
8672 declarations. Declarations ought to have the DW_AT_declaration
8673 flag. It happens that GCC forgets to put it in sometimes, but
8674 only for functions, not for types.
8676 Adding more things than necessary to the hash table is harmless
8677 except for the performance cost. Adding too few will result in
8678 wasted time in find_partial_die, when we reread the compilation
8679 unit with load_all_dies set. */
8682 || abbrev
->tag
== DW_TAG_subprogram
8683 || abbrev
->tag
== DW_TAG_variable
8684 || abbrev
->tag
== DW_TAG_namespace
8685 || part_die
->is_declaration
)
8689 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8690 part_die
->offset
, INSERT
);
8694 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8695 sizeof (struct partial_die_info
));
8697 /* For some DIEs we want to follow their children (if any). For C
8698 we have no reason to follow the children of structures; for other
8699 languages we have to, so that we can get at method physnames
8700 to infer fully qualified class names, for DW_AT_specification,
8701 and for C++ template arguments. For C++, we also look one level
8702 inside functions to find template arguments (if the name of the
8703 function does not already contain the template arguments).
8705 For Ada, we need to scan the children of subprograms and lexical
8706 blocks as well because Ada allows the definition of nested
8707 entities that could be interesting for the debugger, such as
8708 nested subprograms for instance. */
8709 if (last_die
->has_children
8711 || last_die
->tag
== DW_TAG_namespace
8712 || last_die
->tag
== DW_TAG_module
8713 || last_die
->tag
== DW_TAG_enumeration_type
8714 || (cu
->language
== language_cplus
8715 && last_die
->tag
== DW_TAG_subprogram
8716 && (last_die
->name
== NULL
8717 || strchr (last_die
->name
, '<') == NULL
))
8718 || (cu
->language
!= language_c
8719 && (last_die
->tag
== DW_TAG_class_type
8720 || last_die
->tag
== DW_TAG_interface_type
8721 || last_die
->tag
== DW_TAG_structure_type
8722 || last_die
->tag
== DW_TAG_union_type
))
8723 || (cu
->language
== language_ada
8724 && (last_die
->tag
== DW_TAG_subprogram
8725 || last_die
->tag
== DW_TAG_lexical_block
))))
8728 parent_die
= last_die
;
8732 /* Otherwise we skip to the next sibling, if any. */
8733 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8735 /* Back to the top, do it again. */
8739 /* Read a minimal amount of information into the minimal die structure. */
8742 read_partial_die (struct partial_die_info
*part_die
,
8743 struct abbrev_info
*abbrev
,
8744 unsigned int abbrev_len
, bfd
*abfd
,
8745 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8746 struct dwarf2_cu
*cu
)
8749 struct attribute attr
;
8750 int has_low_pc_attr
= 0;
8751 int has_high_pc_attr
= 0;
8753 memset (part_die
, 0, sizeof (struct partial_die_info
));
8755 part_die
->offset
= info_ptr
- buffer
;
8757 info_ptr
+= abbrev_len
;
8762 part_die
->tag
= abbrev
->tag
;
8763 part_die
->has_children
= abbrev
->has_children
;
8765 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8767 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8769 /* Store the data if it is of an attribute we want to keep in a
8770 partial symbol table. */
8774 switch (part_die
->tag
)
8776 case DW_TAG_compile_unit
:
8777 case DW_TAG_type_unit
:
8778 /* Compilation units have a DW_AT_name that is a filename, not
8779 a source language identifier. */
8780 case DW_TAG_enumeration_type
:
8781 case DW_TAG_enumerator
:
8782 /* These tags always have simple identifiers already; no need
8783 to canonicalize them. */
8784 part_die
->name
= DW_STRING (&attr
);
8788 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8789 &cu
->objfile
->objfile_obstack
);
8793 case DW_AT_linkage_name
:
8794 case DW_AT_MIPS_linkage_name
:
8795 /* Note that both forms of linkage name might appear. We
8796 assume they will be the same, and we only store the last
8798 if (cu
->language
== language_ada
)
8799 part_die
->name
= DW_STRING (&attr
);
8802 has_low_pc_attr
= 1;
8803 part_die
->lowpc
= DW_ADDR (&attr
);
8806 has_high_pc_attr
= 1;
8807 part_die
->highpc
= DW_ADDR (&attr
);
8809 case DW_AT_location
:
8810 /* Support the .debug_loc offsets */
8811 if (attr_form_is_block (&attr
))
8813 part_die
->locdesc
= DW_BLOCK (&attr
);
8815 else if (attr_form_is_section_offset (&attr
))
8817 dwarf2_complex_location_expr_complaint ();
8821 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8822 "partial symbol information");
8825 case DW_AT_external
:
8826 part_die
->is_external
= DW_UNSND (&attr
);
8828 case DW_AT_declaration
:
8829 part_die
->is_declaration
= DW_UNSND (&attr
);
8832 part_die
->has_type
= 1;
8834 case DW_AT_abstract_origin
:
8835 case DW_AT_specification
:
8836 case DW_AT_extension
:
8837 part_die
->has_specification
= 1;
8838 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8841 /* Ignore absolute siblings, they might point outside of
8842 the current compile unit. */
8843 if (attr
.form
== DW_FORM_ref_addr
)
8844 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8846 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8848 case DW_AT_byte_size
:
8849 part_die
->has_byte_size
= 1;
8851 case DW_AT_calling_convention
:
8852 /* DWARF doesn't provide a way to identify a program's source-level
8853 entry point. DW_AT_calling_convention attributes are only meant
8854 to describe functions' calling conventions.
8856 However, because it's a necessary piece of information in
8857 Fortran, and because DW_CC_program is the only piece of debugging
8858 information whose definition refers to a 'main program' at all,
8859 several compilers have begun marking Fortran main programs with
8860 DW_CC_program --- even when those functions use the standard
8861 calling conventions.
8863 So until DWARF specifies a way to provide this information and
8864 compilers pick up the new representation, we'll support this
8866 if (DW_UNSND (&attr
) == DW_CC_program
8867 && cu
->language
== language_fortran
)
8868 set_main_name (part_die
->name
);
8875 /* When using the GNU linker, .gnu.linkonce. sections are used to
8876 eliminate duplicate copies of functions and vtables and such.
8877 The linker will arbitrarily choose one and discard the others.
8878 The AT_*_pc values for such functions refer to local labels in
8879 these sections. If the section from that file was discarded, the
8880 labels are not in the output, so the relocs get a value of 0.
8881 If this is a discarded function, mark the pc bounds as invalid,
8882 so that GDB will ignore it. */
8883 if (has_low_pc_attr
&& has_high_pc_attr
8884 && part_die
->lowpc
< part_die
->highpc
8885 && (part_die
->lowpc
!= 0
8886 || dwarf2_per_objfile
->has_section_at_zero
))
8887 part_die
->has_pc_info
= 1;
8892 /* Find a cached partial DIE at OFFSET in CU. */
8894 static struct partial_die_info
*
8895 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8897 struct partial_die_info
*lookup_die
= NULL
;
8898 struct partial_die_info part_die
;
8900 part_die
.offset
= offset
;
8901 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8906 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8907 except in the case of .debug_types DIEs which do not reference
8908 outside their CU (they do however referencing other types via
8911 static struct partial_die_info
*
8912 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8914 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8915 struct partial_die_info
*pd
= NULL
;
8917 if (cu
->per_cu
->from_debug_types
)
8919 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8925 if (offset_in_cu_p (&cu
->header
, offset
))
8927 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8932 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8934 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
8935 load_partial_comp_unit (per_cu
, cu
->objfile
);
8937 per_cu
->cu
->last_used
= 0;
8938 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8940 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8942 struct cleanup
*back_to
;
8943 struct partial_die_info comp_unit_die
;
8944 struct abbrev_info
*abbrev
;
8945 unsigned int bytes_read
;
8948 per_cu
->load_all_dies
= 1;
8950 /* Re-read the DIEs. */
8951 back_to
= make_cleanup (null_cleanup
, 0);
8952 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8954 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8955 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8957 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8958 + per_cu
->cu
->header
.offset
8959 + per_cu
->cu
->header
.first_die_offset
);
8960 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8961 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8962 per_cu
->cu
->objfile
->obfd
,
8963 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8965 if (comp_unit_die
.has_children
)
8966 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8967 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8969 do_cleanups (back_to
);
8971 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8977 internal_error (__FILE__
, __LINE__
,
8978 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8979 offset
, bfd_get_filename (cu
->objfile
->obfd
));
8983 /* Adjust PART_DIE before generating a symbol for it. This function
8984 may set the is_external flag or change the DIE's name. */
8987 fixup_partial_die (struct partial_die_info
*part_die
,
8988 struct dwarf2_cu
*cu
)
8990 /* If we found a reference attribute and the DIE has no name, try
8991 to find a name in the referred to DIE. */
8993 if (part_die
->name
== NULL
&& part_die
->has_specification
)
8995 struct partial_die_info
*spec_die
;
8997 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
8999 fixup_partial_die (spec_die
, cu
);
9003 part_die
->name
= spec_die
->name
;
9005 /* Copy DW_AT_external attribute if it is set. */
9006 if (spec_die
->is_external
)
9007 part_die
->is_external
= spec_die
->is_external
;
9011 /* Set default names for some unnamed DIEs. */
9012 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
9013 || part_die
->tag
== DW_TAG_class_type
))
9014 part_die
->name
= "(anonymous class)";
9016 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9017 part_die
->name
= "(anonymous namespace)";
9019 if (part_die
->tag
== DW_TAG_structure_type
9020 || part_die
->tag
== DW_TAG_class_type
9021 || part_die
->tag
== DW_TAG_union_type
)
9022 guess_structure_name (part_die
, cu
);
9025 /* Read an attribute value described by an attribute form. */
9028 read_attribute_value (struct attribute
*attr
, unsigned form
,
9029 bfd
*abfd
, gdb_byte
*info_ptr
,
9030 struct dwarf2_cu
*cu
)
9032 struct comp_unit_head
*cu_header
= &cu
->header
;
9033 unsigned int bytes_read
;
9034 struct dwarf_block
*blk
;
9039 case DW_FORM_ref_addr
:
9040 if (cu
->header
.version
== 2)
9041 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9043 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9044 info_ptr
+= bytes_read
;
9047 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9048 info_ptr
+= bytes_read
;
9050 case DW_FORM_block2
:
9051 blk
= dwarf_alloc_block (cu
);
9052 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9054 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9055 info_ptr
+= blk
->size
;
9056 DW_BLOCK (attr
) = blk
;
9058 case DW_FORM_block4
:
9059 blk
= dwarf_alloc_block (cu
);
9060 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9062 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9063 info_ptr
+= blk
->size
;
9064 DW_BLOCK (attr
) = blk
;
9067 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9071 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9075 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9078 case DW_FORM_sec_offset
:
9079 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9080 info_ptr
+= bytes_read
;
9082 case DW_FORM_string
:
9083 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9084 DW_STRING_IS_CANONICAL (attr
) = 0;
9085 info_ptr
+= bytes_read
;
9088 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9090 DW_STRING_IS_CANONICAL (attr
) = 0;
9091 info_ptr
+= bytes_read
;
9093 case DW_FORM_exprloc
:
9095 blk
= dwarf_alloc_block (cu
);
9096 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9097 info_ptr
+= bytes_read
;
9098 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9099 info_ptr
+= blk
->size
;
9100 DW_BLOCK (attr
) = blk
;
9102 case DW_FORM_block1
:
9103 blk
= dwarf_alloc_block (cu
);
9104 blk
->size
= read_1_byte (abfd
, info_ptr
);
9106 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9107 info_ptr
+= blk
->size
;
9108 DW_BLOCK (attr
) = blk
;
9111 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9115 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9118 case DW_FORM_flag_present
:
9119 DW_UNSND (attr
) = 1;
9122 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9123 info_ptr
+= bytes_read
;
9126 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9127 info_ptr
+= bytes_read
;
9130 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9134 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9138 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9142 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9146 /* Convert the signature to something we can record in DW_UNSND
9148 NOTE: This is NULL if the type wasn't found. */
9149 DW_SIGNATURED_TYPE (attr
) =
9150 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9153 case DW_FORM_ref_udata
:
9154 DW_ADDR (attr
) = (cu
->header
.offset
9155 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9156 info_ptr
+= bytes_read
;
9158 case DW_FORM_indirect
:
9159 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9160 info_ptr
+= bytes_read
;
9161 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9164 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9165 dwarf_form_name (form
),
9166 bfd_get_filename (abfd
));
9169 /* We have seen instances where the compiler tried to emit a byte
9170 size attribute of -1 which ended up being encoded as an unsigned
9171 0xffffffff. Although 0xffffffff is technically a valid size value,
9172 an object of this size seems pretty unlikely so we can relatively
9173 safely treat these cases as if the size attribute was invalid and
9174 treat them as zero by default. */
9175 if (attr
->name
== DW_AT_byte_size
9176 && form
== DW_FORM_data4
9177 && DW_UNSND (attr
) >= 0xffffffff)
9180 (&symfile_complaints
,
9181 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9182 hex_string (DW_UNSND (attr
)));
9183 DW_UNSND (attr
) = 0;
9189 /* Read an attribute described by an abbreviated attribute. */
9192 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9193 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9195 attr
->name
= abbrev
->name
;
9196 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9199 /* read dwarf information from a buffer */
9202 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9204 return bfd_get_8 (abfd
, buf
);
9208 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9210 return bfd_get_signed_8 (abfd
, buf
);
9214 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9216 return bfd_get_16 (abfd
, buf
);
9220 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9222 return bfd_get_signed_16 (abfd
, buf
);
9226 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9228 return bfd_get_32 (abfd
, buf
);
9232 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9234 return bfd_get_signed_32 (abfd
, buf
);
9238 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9240 return bfd_get_64 (abfd
, buf
);
9244 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9245 unsigned int *bytes_read
)
9247 struct comp_unit_head
*cu_header
= &cu
->header
;
9248 CORE_ADDR retval
= 0;
9250 if (cu_header
->signed_addr_p
)
9252 switch (cu_header
->addr_size
)
9255 retval
= bfd_get_signed_16 (abfd
, buf
);
9258 retval
= bfd_get_signed_32 (abfd
, buf
);
9261 retval
= bfd_get_signed_64 (abfd
, buf
);
9264 internal_error (__FILE__
, __LINE__
,
9265 _("read_address: bad switch, signed [in module %s]"),
9266 bfd_get_filename (abfd
));
9271 switch (cu_header
->addr_size
)
9274 retval
= bfd_get_16 (abfd
, buf
);
9277 retval
= bfd_get_32 (abfd
, buf
);
9280 retval
= bfd_get_64 (abfd
, buf
);
9283 internal_error (__FILE__
, __LINE__
,
9284 _("read_address: bad switch, unsigned [in module %s]"),
9285 bfd_get_filename (abfd
));
9289 *bytes_read
= cu_header
->addr_size
;
9293 /* Read the initial length from a section. The (draft) DWARF 3
9294 specification allows the initial length to take up either 4 bytes
9295 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9296 bytes describe the length and all offsets will be 8 bytes in length
9299 An older, non-standard 64-bit format is also handled by this
9300 function. The older format in question stores the initial length
9301 as an 8-byte quantity without an escape value. Lengths greater
9302 than 2^32 aren't very common which means that the initial 4 bytes
9303 is almost always zero. Since a length value of zero doesn't make
9304 sense for the 32-bit format, this initial zero can be considered to
9305 be an escape value which indicates the presence of the older 64-bit
9306 format. As written, the code can't detect (old format) lengths
9307 greater than 4GB. If it becomes necessary to handle lengths
9308 somewhat larger than 4GB, we could allow other small values (such
9309 as the non-sensical values of 1, 2, and 3) to also be used as
9310 escape values indicating the presence of the old format.
9312 The value returned via bytes_read should be used to increment the
9313 relevant pointer after calling read_initial_length().
9315 [ Note: read_initial_length() and read_offset() are based on the
9316 document entitled "DWARF Debugging Information Format", revision
9317 3, draft 8, dated November 19, 2001. This document was obtained
9320 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9322 This document is only a draft and is subject to change. (So beware.)
9324 Details regarding the older, non-standard 64-bit format were
9325 determined empirically by examining 64-bit ELF files produced by
9326 the SGI toolchain on an IRIX 6.5 machine.
9328 - Kevin, July 16, 2002
9332 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9334 LONGEST length
= bfd_get_32 (abfd
, buf
);
9336 if (length
== 0xffffffff)
9338 length
= bfd_get_64 (abfd
, buf
+ 4);
9341 else if (length
== 0)
9343 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9344 length
= bfd_get_64 (abfd
, buf
);
9355 /* Cover function for read_initial_length.
9356 Returns the length of the object at BUF, and stores the size of the
9357 initial length in *BYTES_READ and stores the size that offsets will be in
9359 If the initial length size is not equivalent to that specified in
9360 CU_HEADER then issue a complaint.
9361 This is useful when reading non-comp-unit headers. */
9364 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9365 const struct comp_unit_head
*cu_header
,
9366 unsigned int *bytes_read
,
9367 unsigned int *offset_size
)
9369 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9371 gdb_assert (cu_header
->initial_length_size
== 4
9372 || cu_header
->initial_length_size
== 8
9373 || cu_header
->initial_length_size
== 12);
9375 if (cu_header
->initial_length_size
!= *bytes_read
)
9376 complaint (&symfile_complaints
,
9377 _("intermixed 32-bit and 64-bit DWARF sections"));
9379 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9383 /* Read an offset from the data stream. The size of the offset is
9384 given by cu_header->offset_size. */
9387 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9388 unsigned int *bytes_read
)
9390 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9392 *bytes_read
= cu_header
->offset_size
;
9396 /* Read an offset from the data stream. */
9399 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9403 switch (offset_size
)
9406 retval
= bfd_get_32 (abfd
, buf
);
9409 retval
= bfd_get_64 (abfd
, buf
);
9412 internal_error (__FILE__
, __LINE__
,
9413 _("read_offset_1: bad switch [in module %s]"),
9414 bfd_get_filename (abfd
));
9421 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9423 /* If the size of a host char is 8 bits, we can return a pointer
9424 to the buffer, otherwise we have to copy the data to a buffer
9425 allocated on the temporary obstack. */
9426 gdb_assert (HOST_CHAR_BIT
== 8);
9431 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9433 /* If the size of a host char is 8 bits, we can return a pointer
9434 to the string, otherwise we have to copy the string to a buffer
9435 allocated on the temporary obstack. */
9436 gdb_assert (HOST_CHAR_BIT
== 8);
9439 *bytes_read_ptr
= 1;
9442 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9443 return (char *) buf
;
9447 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9448 const struct comp_unit_head
*cu_header
,
9449 unsigned int *bytes_read_ptr
)
9451 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9453 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9454 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9456 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9457 bfd_get_filename (abfd
));
9460 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9462 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9463 bfd_get_filename (abfd
));
9466 gdb_assert (HOST_CHAR_BIT
== 8);
9467 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9469 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9472 static unsigned long
9473 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9475 unsigned long result
;
9476 unsigned int num_read
;
9486 byte
= bfd_get_8 (abfd
, buf
);
9489 result
|= ((unsigned long)(byte
& 127) << shift
);
9490 if ((byte
& 128) == 0)
9496 *bytes_read_ptr
= num_read
;
9501 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9504 int i
, shift
, num_read
;
9513 byte
= bfd_get_8 (abfd
, buf
);
9516 result
|= ((long)(byte
& 127) << shift
);
9518 if ((byte
& 128) == 0)
9523 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9524 result
|= -(((long)1) << shift
);
9525 *bytes_read_ptr
= num_read
;
9529 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9532 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9538 byte
= bfd_get_8 (abfd
, buf
);
9540 if ((byte
& 128) == 0)
9546 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9553 cu
->language
= language_c
;
9555 case DW_LANG_C_plus_plus
:
9556 cu
->language
= language_cplus
;
9559 cu
->language
= language_d
;
9561 case DW_LANG_Fortran77
:
9562 case DW_LANG_Fortran90
:
9563 case DW_LANG_Fortran95
:
9564 cu
->language
= language_fortran
;
9566 case DW_LANG_Mips_Assembler
:
9567 cu
->language
= language_asm
;
9570 cu
->language
= language_java
;
9574 cu
->language
= language_ada
;
9576 case DW_LANG_Modula2
:
9577 cu
->language
= language_m2
;
9579 case DW_LANG_Pascal83
:
9580 cu
->language
= language_pascal
;
9583 cu
->language
= language_objc
;
9585 case DW_LANG_Cobol74
:
9586 case DW_LANG_Cobol85
:
9588 cu
->language
= language_minimal
;
9591 cu
->language_defn
= language_def (cu
->language
);
9594 /* Return the named attribute or NULL if not there. */
9596 static struct attribute
*
9597 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9600 struct attribute
*spec
= NULL
;
9602 for (i
= 0; i
< die
->num_attrs
; ++i
)
9604 if (die
->attrs
[i
].name
== name
)
9605 return &die
->attrs
[i
];
9606 if (die
->attrs
[i
].name
== DW_AT_specification
9607 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9608 spec
= &die
->attrs
[i
];
9613 die
= follow_die_ref (die
, spec
, &cu
);
9614 return dwarf2_attr (die
, name
, cu
);
9620 /* Return the named attribute or NULL if not there,
9621 but do not follow DW_AT_specification, etc.
9622 This is for use in contexts where we're reading .debug_types dies.
9623 Following DW_AT_specification, DW_AT_abstract_origin will take us
9624 back up the chain, and we want to go down. */
9626 static struct attribute
*
9627 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9628 struct dwarf2_cu
*cu
)
9632 for (i
= 0; i
< die
->num_attrs
; ++i
)
9633 if (die
->attrs
[i
].name
== name
)
9634 return &die
->attrs
[i
];
9639 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9640 and holds a non-zero value. This function should only be used for
9641 DW_FORM_flag or DW_FORM_flag_present attributes. */
9644 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9646 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9648 return (attr
&& DW_UNSND (attr
));
9652 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9654 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9655 which value is non-zero. However, we have to be careful with
9656 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9657 (via dwarf2_flag_true_p) follows this attribute. So we may
9658 end up accidently finding a declaration attribute that belongs
9659 to a different DIE referenced by the specification attribute,
9660 even though the given DIE does not have a declaration attribute. */
9661 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9662 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9665 /* Return the die giving the specification for DIE, if there is
9666 one. *SPEC_CU is the CU containing DIE on input, and the CU
9667 containing the return value on output. If there is no
9668 specification, but there is an abstract origin, that is
9671 static struct die_info
*
9672 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9674 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9677 if (spec_attr
== NULL
)
9678 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9680 if (spec_attr
== NULL
)
9683 return follow_die_ref (die
, spec_attr
, spec_cu
);
9686 /* Free the line_header structure *LH, and any arrays and strings it
9689 free_line_header (struct line_header
*lh
)
9691 if (lh
->standard_opcode_lengths
)
9692 xfree (lh
->standard_opcode_lengths
);
9694 /* Remember that all the lh->file_names[i].name pointers are
9695 pointers into debug_line_buffer, and don't need to be freed. */
9697 xfree (lh
->file_names
);
9699 /* Similarly for the include directory names. */
9700 if (lh
->include_dirs
)
9701 xfree (lh
->include_dirs
);
9707 /* Add an entry to LH's include directory table. */
9709 add_include_dir (struct line_header
*lh
, char *include_dir
)
9711 /* Grow the array if necessary. */
9712 if (lh
->include_dirs_size
== 0)
9714 lh
->include_dirs_size
= 1; /* for testing */
9715 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9716 * sizeof (*lh
->include_dirs
));
9718 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9720 lh
->include_dirs_size
*= 2;
9721 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9722 (lh
->include_dirs_size
9723 * sizeof (*lh
->include_dirs
)));
9726 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9730 /* Add an entry to LH's file name table. */
9732 add_file_name (struct line_header
*lh
,
9734 unsigned int dir_index
,
9735 unsigned int mod_time
,
9736 unsigned int length
)
9738 struct file_entry
*fe
;
9740 /* Grow the array if necessary. */
9741 if (lh
->file_names_size
== 0)
9743 lh
->file_names_size
= 1; /* for testing */
9744 lh
->file_names
= xmalloc (lh
->file_names_size
9745 * sizeof (*lh
->file_names
));
9747 else if (lh
->num_file_names
>= lh
->file_names_size
)
9749 lh
->file_names_size
*= 2;
9750 lh
->file_names
= xrealloc (lh
->file_names
,
9751 (lh
->file_names_size
9752 * sizeof (*lh
->file_names
)));
9755 fe
= &lh
->file_names
[lh
->num_file_names
++];
9757 fe
->dir_index
= dir_index
;
9758 fe
->mod_time
= mod_time
;
9759 fe
->length
= length
;
9765 /* Read the statement program header starting at OFFSET in
9766 .debug_line, according to the endianness of ABFD. Return a pointer
9767 to a struct line_header, allocated using xmalloc.
9769 NOTE: the strings in the include directory and file name tables of
9770 the returned object point into debug_line_buffer, and must not be
9772 static struct line_header
*
9773 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9774 struct dwarf2_cu
*cu
)
9776 struct cleanup
*back_to
;
9777 struct line_header
*lh
;
9779 unsigned int bytes_read
, offset_size
;
9781 char *cur_dir
, *cur_file
;
9783 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9784 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9786 complaint (&symfile_complaints
, _("missing .debug_line section"));
9790 /* Make sure that at least there's room for the total_length field.
9791 That could be 12 bytes long, but we're just going to fudge that. */
9792 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9794 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9798 lh
= xmalloc (sizeof (*lh
));
9799 memset (lh
, 0, sizeof (*lh
));
9800 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9803 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9805 /* Read in the header. */
9807 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9808 &bytes_read
, &offset_size
);
9809 line_ptr
+= bytes_read
;
9810 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9811 + dwarf2_per_objfile
->line
.size
))
9813 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9816 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9817 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9819 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9820 line_ptr
+= offset_size
;
9821 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9823 if (lh
->version
>= 4)
9825 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9829 lh
->maximum_ops_per_instruction
= 1;
9831 if (lh
->maximum_ops_per_instruction
== 0)
9833 lh
->maximum_ops_per_instruction
= 1;
9834 complaint (&symfile_complaints
,
9835 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9838 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9840 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9842 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9844 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9846 lh
->standard_opcode_lengths
9847 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9849 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9850 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9852 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9856 /* Read directory table. */
9857 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9859 line_ptr
+= bytes_read
;
9860 add_include_dir (lh
, cur_dir
);
9862 line_ptr
+= bytes_read
;
9864 /* Read file name table. */
9865 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9867 unsigned int dir_index
, mod_time
, length
;
9869 line_ptr
+= bytes_read
;
9870 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9871 line_ptr
+= bytes_read
;
9872 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9873 line_ptr
+= bytes_read
;
9874 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9875 line_ptr
+= bytes_read
;
9877 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9879 line_ptr
+= bytes_read
;
9880 lh
->statement_program_start
= line_ptr
;
9882 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9883 + dwarf2_per_objfile
->line
.size
))
9884 complaint (&symfile_complaints
,
9885 _("line number info header doesn't fit in `.debug_line' section"));
9887 discard_cleanups (back_to
);
9891 /* This function exists to work around a bug in certain compilers
9892 (particularly GCC 2.95), in which the first line number marker of a
9893 function does not show up until after the prologue, right before
9894 the second line number marker. This function shifts ADDRESS down
9895 to the beginning of the function if necessary, and is called on
9896 addresses passed to record_line. */
9899 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9901 struct function_range
*fn
;
9903 /* Find the function_range containing address. */
9908 cu
->cached_fn
= cu
->first_fn
;
9912 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9918 while (fn
&& fn
!= cu
->cached_fn
)
9919 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9929 if (address
!= fn
->lowpc
)
9930 complaint (&symfile_complaints
,
9931 _("misplaced first line number at 0x%lx for '%s'"),
9932 (unsigned long) address
, fn
->name
);
9937 /* Subroutine of dwarf_decode_lines to simplify it.
9938 Return the file name of the psymtab for included file FILE_INDEX
9939 in line header LH of PST.
9940 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
9941 If space for the result is malloc'd, it will be freed by a cleanup.
9942 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
9945 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
9946 const struct partial_symtab
*pst
,
9947 const char *comp_dir
)
9949 const struct file_entry fe
= lh
->file_names
[file_index
];
9950 char *include_name
= fe
.name
;
9951 char *include_name_to_compare
= include_name
;
9952 char *dir_name
= NULL
;
9957 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
9959 if (!IS_ABSOLUTE_PATH (include_name
)
9960 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
9962 /* Avoid creating a duplicate psymtab for PST.
9963 We do this by comparing INCLUDE_NAME and PST_FILENAME.
9964 Before we do the comparison, however, we need to account
9965 for DIR_NAME and COMP_DIR.
9966 First prepend dir_name (if non-NULL). If we still don't
9967 have an absolute path prepend comp_dir (if non-NULL).
9968 However, the directory we record in the include-file's
9969 psymtab does not contain COMP_DIR (to match the
9970 corresponding symtab(s)).
9975 bash$ gcc -g ./hello.c
9976 include_name = "hello.c"
9978 DW_AT_comp_dir = comp_dir = "/tmp"
9979 DW_AT_name = "./hello.c" */
9981 if (dir_name
!= NULL
)
9983 include_name
= concat (dir_name
, SLASH_STRING
,
9984 include_name
, (char *)NULL
);
9985 include_name_to_compare
= include_name
;
9986 make_cleanup (xfree
, include_name
);
9988 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
9990 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
9991 include_name
, (char *)NULL
);
9995 pst_filename
= pst
->filename
;
9996 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
9998 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
9999 pst_filename
, (char *)NULL
);
10002 file_is_pst
= strcmp (include_name_to_compare
, pst_filename
) == 0;
10004 if (include_name_to_compare
!= include_name
)
10005 xfree (include_name_to_compare
);
10006 if (pst_filename
!= pst
->filename
)
10007 xfree (pst_filename
);
10011 return include_name
;
10014 /* Decode the Line Number Program (LNP) for the given line_header
10015 structure and CU. The actual information extracted and the type
10016 of structures created from the LNP depends on the value of PST.
10018 1. If PST is NULL, then this procedure uses the data from the program
10019 to create all necessary symbol tables, and their linetables.
10021 2. If PST is not NULL, this procedure reads the program to determine
10022 the list of files included by the unit represented by PST, and
10023 builds all the associated partial symbol tables.
10025 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10026 It is used for relative paths in the line table.
10027 NOTE: When processing partial symtabs (pst != NULL),
10028 comp_dir == pst->dirname.
10030 NOTE: It is important that psymtabs have the same file name (via strcmp)
10031 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10032 symtab we don't use it in the name of the psymtabs we create.
10033 E.g. expand_line_sal requires this when finding psymtabs to expand.
10034 A good testcase for this is mb-inline.exp. */
10037 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
10038 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10040 gdb_byte
*line_ptr
, *extended_end
;
10041 gdb_byte
*line_end
;
10042 unsigned int bytes_read
, extended_len
;
10043 unsigned char op_code
, extended_op
, adj_opcode
;
10044 CORE_ADDR baseaddr
;
10045 struct objfile
*objfile
= cu
->objfile
;
10046 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10047 const int decode_for_pst_p
= (pst
!= NULL
);
10048 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10050 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10052 line_ptr
= lh
->statement_program_start
;
10053 line_end
= lh
->statement_program_end
;
10055 /* Read the statement sequences until there's nothing left. */
10056 while (line_ptr
< line_end
)
10058 /* state machine registers */
10059 CORE_ADDR address
= 0;
10060 unsigned int file
= 1;
10061 unsigned int line
= 1;
10062 unsigned int column
= 0;
10063 int is_stmt
= lh
->default_is_stmt
;
10064 int basic_block
= 0;
10065 int end_sequence
= 0;
10067 unsigned char op_index
= 0;
10069 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10071 /* Start a subfile for the current file of the state machine. */
10072 /* lh->include_dirs and lh->file_names are 0-based, but the
10073 directory and file name numbers in the statement program
10075 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10079 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10081 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10084 /* Decode the table. */
10085 while (!end_sequence
)
10087 op_code
= read_1_byte (abfd
, line_ptr
);
10089 if (line_ptr
> line_end
)
10091 dwarf2_debug_line_missing_end_sequence_complaint ();
10095 if (op_code
>= lh
->opcode_base
)
10097 /* Special operand. */
10098 adj_opcode
= op_code
- lh
->opcode_base
;
10099 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10100 / lh
->maximum_ops_per_instruction
)
10101 * lh
->minimum_instruction_length
);
10102 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10103 % lh
->maximum_ops_per_instruction
);
10104 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10105 if (lh
->num_file_names
< file
|| file
== 0)
10106 dwarf2_debug_line_missing_file_complaint ();
10107 /* For now we ignore lines not starting on an
10108 instruction boundary. */
10109 else if (op_index
== 0)
10111 lh
->file_names
[file
- 1].included_p
= 1;
10112 if (!decode_for_pst_p
&& is_stmt
)
10114 if (last_subfile
!= current_subfile
)
10116 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10118 record_line (last_subfile
, 0, addr
);
10119 last_subfile
= current_subfile
;
10121 /* Append row to matrix using current values. */
10122 addr
= check_cu_functions (address
, cu
);
10123 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10124 record_line (current_subfile
, line
, addr
);
10129 else switch (op_code
)
10131 case DW_LNS_extended_op
:
10132 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10133 line_ptr
+= bytes_read
;
10134 extended_end
= line_ptr
+ extended_len
;
10135 extended_op
= read_1_byte (abfd
, line_ptr
);
10137 switch (extended_op
)
10139 case DW_LNE_end_sequence
:
10142 case DW_LNE_set_address
:
10143 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10145 line_ptr
+= bytes_read
;
10146 address
+= baseaddr
;
10148 case DW_LNE_define_file
:
10151 unsigned int dir_index
, mod_time
, length
;
10153 cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
);
10154 line_ptr
+= bytes_read
;
10156 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10157 line_ptr
+= bytes_read
;
10159 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10160 line_ptr
+= bytes_read
;
10162 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10163 line_ptr
+= bytes_read
;
10164 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10167 case DW_LNE_set_discriminator
:
10168 /* The discriminator is not interesting to the debugger;
10170 line_ptr
= extended_end
;
10173 complaint (&symfile_complaints
,
10174 _("mangled .debug_line section"));
10177 /* Make sure that we parsed the extended op correctly. If e.g.
10178 we expected a different address size than the producer used,
10179 we may have read the wrong number of bytes. */
10180 if (line_ptr
!= extended_end
)
10182 complaint (&symfile_complaints
,
10183 _("mangled .debug_line section"));
10188 if (lh
->num_file_names
< file
|| file
== 0)
10189 dwarf2_debug_line_missing_file_complaint ();
10192 lh
->file_names
[file
- 1].included_p
= 1;
10193 if (!decode_for_pst_p
&& is_stmt
)
10195 if (last_subfile
!= current_subfile
)
10197 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10199 record_line (last_subfile
, 0, addr
);
10200 last_subfile
= current_subfile
;
10202 addr
= check_cu_functions (address
, cu
);
10203 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10204 record_line (current_subfile
, line
, addr
);
10209 case DW_LNS_advance_pc
:
10212 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10214 address
+= (((op_index
+ adjust
)
10215 / lh
->maximum_ops_per_instruction
)
10216 * lh
->minimum_instruction_length
);
10217 op_index
= ((op_index
+ adjust
)
10218 % lh
->maximum_ops_per_instruction
);
10219 line_ptr
+= bytes_read
;
10222 case DW_LNS_advance_line
:
10223 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10224 line_ptr
+= bytes_read
;
10226 case DW_LNS_set_file
:
10228 /* The arrays lh->include_dirs and lh->file_names are
10229 0-based, but the directory and file name numbers in
10230 the statement program are 1-based. */
10231 struct file_entry
*fe
;
10234 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10235 line_ptr
+= bytes_read
;
10236 if (lh
->num_file_names
< file
|| file
== 0)
10237 dwarf2_debug_line_missing_file_complaint ();
10240 fe
= &lh
->file_names
[file
- 1];
10242 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10243 if (!decode_for_pst_p
)
10245 last_subfile
= current_subfile
;
10246 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10251 case DW_LNS_set_column
:
10252 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10253 line_ptr
+= bytes_read
;
10255 case DW_LNS_negate_stmt
:
10256 is_stmt
= (!is_stmt
);
10258 case DW_LNS_set_basic_block
:
10261 /* Add to the address register of the state machine the
10262 address increment value corresponding to special opcode
10263 255. I.e., this value is scaled by the minimum
10264 instruction length since special opcode 255 would have
10265 scaled the the increment. */
10266 case DW_LNS_const_add_pc
:
10268 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10270 address
+= (((op_index
+ adjust
)
10271 / lh
->maximum_ops_per_instruction
)
10272 * lh
->minimum_instruction_length
);
10273 op_index
= ((op_index
+ adjust
)
10274 % lh
->maximum_ops_per_instruction
);
10277 case DW_LNS_fixed_advance_pc
:
10278 address
+= read_2_bytes (abfd
, line_ptr
);
10284 /* Unknown standard opcode, ignore it. */
10287 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10289 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10290 line_ptr
+= bytes_read
;
10295 if (lh
->num_file_names
< file
|| file
== 0)
10296 dwarf2_debug_line_missing_file_complaint ();
10299 lh
->file_names
[file
- 1].included_p
= 1;
10300 if (!decode_for_pst_p
)
10302 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10303 record_line (current_subfile
, 0, addr
);
10308 if (decode_for_pst_p
)
10312 /* Now that we're done scanning the Line Header Program, we can
10313 create the psymtab of each included file. */
10314 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10315 if (lh
->file_names
[file_index
].included_p
== 1)
10317 char *include_name
=
10318 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10319 if (include_name
!= NULL
)
10320 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10325 /* Make sure a symtab is created for every file, even files
10326 which contain only variables (i.e. no code with associated
10330 struct file_entry
*fe
;
10332 for (i
= 0; i
< lh
->num_file_names
; i
++)
10336 fe
= &lh
->file_names
[i
];
10338 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10339 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10341 /* Skip the main file; we don't need it, and it must be
10342 allocated last, so that it will show up before the
10343 non-primary symtabs in the objfile's symtab list. */
10344 if (current_subfile
== first_subfile
)
10347 if (current_subfile
->symtab
== NULL
)
10348 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10350 fe
->symtab
= current_subfile
->symtab
;
10355 /* Start a subfile for DWARF. FILENAME is the name of the file and
10356 DIRNAME the name of the source directory which contains FILENAME
10357 or NULL if not known. COMP_DIR is the compilation directory for the
10358 linetable's compilation unit or NULL if not known.
10359 This routine tries to keep line numbers from identical absolute and
10360 relative file names in a common subfile.
10362 Using the `list' example from the GDB testsuite, which resides in
10363 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10364 of /srcdir/list0.c yields the following debugging information for list0.c:
10366 DW_AT_name: /srcdir/list0.c
10367 DW_AT_comp_dir: /compdir
10368 files.files[0].name: list0.h
10369 files.files[0].dir: /srcdir
10370 files.files[1].name: list0.c
10371 files.files[1].dir: /srcdir
10373 The line number information for list0.c has to end up in a single
10374 subfile, so that `break /srcdir/list0.c:1' works as expected.
10375 start_subfile will ensure that this happens provided that we pass the
10376 concatenation of files.files[1].dir and files.files[1].name as the
10380 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
10384 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10385 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10386 second argument to start_subfile. To be consistent, we do the
10387 same here. In order not to lose the line information directory,
10388 we concatenate it to the filename when it makes sense.
10389 Note that the Dwarf3 standard says (speaking of filenames in line
10390 information): ``The directory index is ignored for file names
10391 that represent full path names''. Thus ignoring dirname in the
10392 `else' branch below isn't an issue. */
10394 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10395 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10397 fullname
= filename
;
10399 start_subfile (fullname
, comp_dir
);
10401 if (fullname
!= filename
)
10406 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10407 struct dwarf2_cu
*cu
)
10409 struct objfile
*objfile
= cu
->objfile
;
10410 struct comp_unit_head
*cu_header
= &cu
->header
;
10412 /* NOTE drow/2003-01-30: There used to be a comment and some special
10413 code here to turn a symbol with DW_AT_external and a
10414 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10415 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10416 with some versions of binutils) where shared libraries could have
10417 relocations against symbols in their debug information - the
10418 minimal symbol would have the right address, but the debug info
10419 would not. It's no longer necessary, because we will explicitly
10420 apply relocations when we read in the debug information now. */
10422 /* A DW_AT_location attribute with no contents indicates that a
10423 variable has been optimized away. */
10424 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10426 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10430 /* Handle one degenerate form of location expression specially, to
10431 preserve GDB's previous behavior when section offsets are
10432 specified. If this is just a DW_OP_addr then mark this symbol
10435 if (attr_form_is_block (attr
)
10436 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10437 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10439 unsigned int dummy
;
10441 SYMBOL_VALUE_ADDRESS (sym
) =
10442 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10443 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10444 fixup_symbol_section (sym
, objfile
);
10445 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10446 SYMBOL_SECTION (sym
));
10450 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10451 expression evaluator, and use LOC_COMPUTED only when necessary
10452 (i.e. when the value of a register or memory location is
10453 referenced, or a thread-local block, etc.). Then again, it might
10454 not be worthwhile. I'm assuming that it isn't unless performance
10455 or memory numbers show me otherwise. */
10457 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10458 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10461 /* Given a pointer to a DWARF information entry, figure out if we need
10462 to make a symbol table entry for it, and if so, create a new entry
10463 and return a pointer to it.
10464 If TYPE is NULL, determine symbol type from the die, otherwise
10465 used the passed type.
10466 If SPACE is not NULL, use it to hold the new symbol. If it is
10467 NULL, allocate a new symbol on the objfile's obstack. */
10469 static struct symbol
*
10470 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10471 struct symbol
*space
)
10473 struct objfile
*objfile
= cu
->objfile
;
10474 struct symbol
*sym
= NULL
;
10476 struct attribute
*attr
= NULL
;
10477 struct attribute
*attr2
= NULL
;
10478 CORE_ADDR baseaddr
;
10479 struct pending
**list_to_add
= NULL
;
10481 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10483 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10485 name
= dwarf2_name (die
, cu
);
10488 const char *linkagename
;
10489 int suppress_add
= 0;
10494 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10495 OBJSTAT (objfile
, n_syms
++);
10497 /* Cache this symbol's name and the name's demangled form (if any). */
10498 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10499 linkagename
= dwarf2_physname (name
, die
, cu
);
10500 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10502 /* Fortran does not have mangling standard and the mangling does differ
10503 between gfortran, iFort etc. */
10504 if (cu
->language
== language_fortran
10505 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10506 symbol_set_demangled_name (&(sym
->ginfo
),
10507 (char *) dwarf2_full_name (name
, die
, cu
),
10510 /* Default assumptions.
10511 Use the passed type or decode it from the die. */
10512 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10513 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10515 SYMBOL_TYPE (sym
) = type
;
10517 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10518 attr
= dwarf2_attr (die
,
10519 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10523 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10526 attr
= dwarf2_attr (die
,
10527 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10531 int file_index
= DW_UNSND (attr
);
10533 if (cu
->line_header
== NULL
10534 || file_index
> cu
->line_header
->num_file_names
)
10535 complaint (&symfile_complaints
,
10536 _("file index out of range"));
10537 else if (file_index
> 0)
10539 struct file_entry
*fe
;
10541 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10542 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10549 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10552 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10554 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10555 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10556 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10557 add_symbol_to_list (sym
, cu
->list_in_scope
);
10559 case DW_TAG_subprogram
:
10560 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10562 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10563 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10564 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10565 || cu
->language
== language_ada
)
10567 /* Subprograms marked external are stored as a global symbol.
10568 Ada subprograms, whether marked external or not, are always
10569 stored as a global symbol, because we want to be able to
10570 access them globally. For instance, we want to be able
10571 to break on a nested subprogram without having to
10572 specify the context. */
10573 list_to_add
= &global_symbols
;
10577 list_to_add
= cu
->list_in_scope
;
10580 case DW_TAG_inlined_subroutine
:
10581 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10583 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10584 SYMBOL_INLINED (sym
) = 1;
10585 /* Do not add the symbol to any lists. It will be found via
10586 BLOCK_FUNCTION from the blockvector. */
10588 case DW_TAG_template_value_param
:
10590 /* Fall through. */
10591 case DW_TAG_variable
:
10592 case DW_TAG_member
:
10593 /* Compilation with minimal debug info may result in variables
10594 with missing type entries. Change the misleading `void' type
10595 to something sensible. */
10596 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10598 = objfile_type (objfile
)->nodebug_data_symbol
;
10600 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10601 /* In the case of DW_TAG_member, we should only be called for
10602 static const members. */
10603 if (die
->tag
== DW_TAG_member
)
10605 /* dwarf2_add_field uses die_is_declaration,
10606 so we do the same. */
10607 gdb_assert (die_is_declaration (die
, cu
));
10612 dwarf2_const_value (attr
, sym
, cu
);
10613 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10616 if (attr2
&& (DW_UNSND (attr2
) != 0))
10617 list_to_add
= &global_symbols
;
10619 list_to_add
= cu
->list_in_scope
;
10623 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10626 var_decode_location (attr
, sym
, cu
);
10627 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10628 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10629 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10630 && !dwarf2_per_objfile
->has_section_at_zero
)
10632 /* When a static variable is eliminated by the linker,
10633 the corresponding debug information is not stripped
10634 out, but the variable address is set to null;
10635 do not add such variables into symbol table. */
10637 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10639 /* Workaround gfortran PR debug/40040 - it uses
10640 DW_AT_location for variables in -fPIC libraries which may
10641 get overriden by other libraries/executable and get
10642 a different address. Resolve it by the minimal symbol
10643 which may come from inferior's executable using copy
10644 relocation. Make this workaround only for gfortran as for
10645 other compilers GDB cannot guess the minimal symbol
10646 Fortran mangling kind. */
10647 if (cu
->language
== language_fortran
&& die
->parent
10648 && die
->parent
->tag
== DW_TAG_module
10650 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10651 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10653 /* A variable with DW_AT_external is never static,
10654 but it may be block-scoped. */
10655 list_to_add
= (cu
->list_in_scope
== &file_symbols
10656 ? &global_symbols
: cu
->list_in_scope
);
10659 list_to_add
= cu
->list_in_scope
;
10663 /* We do not know the address of this symbol.
10664 If it is an external symbol and we have type information
10665 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10666 The address of the variable will then be determined from
10667 the minimal symbol table whenever the variable is
10669 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10670 if (attr2
&& (DW_UNSND (attr2
) != 0)
10671 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10673 /* A variable with DW_AT_external is never static, but it
10674 may be block-scoped. */
10675 list_to_add
= (cu
->list_in_scope
== &file_symbols
10676 ? &global_symbols
: cu
->list_in_scope
);
10678 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10680 else if (!die_is_declaration (die
, cu
))
10682 /* Use the default LOC_OPTIMIZED_OUT class. */
10683 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10685 list_to_add
= cu
->list_in_scope
;
10689 case DW_TAG_formal_parameter
:
10690 /* If we are inside a function, mark this as an argument. If
10691 not, we might be looking at an argument to an inlined function
10692 when we do not have enough information to show inlined frames;
10693 pretend it's a local variable in that case so that the user can
10695 if (context_stack_depth
> 0
10696 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10697 SYMBOL_IS_ARGUMENT (sym
) = 1;
10698 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10701 var_decode_location (attr
, sym
, cu
);
10703 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10706 dwarf2_const_value (attr
, sym
, cu
);
10708 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10709 if (attr
&& DW_UNSND (attr
))
10711 struct type
*ref_type
;
10713 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10714 SYMBOL_TYPE (sym
) = ref_type
;
10717 list_to_add
= cu
->list_in_scope
;
10719 case DW_TAG_unspecified_parameters
:
10720 /* From varargs functions; gdb doesn't seem to have any
10721 interest in this information, so just ignore it for now.
10724 case DW_TAG_template_type_param
:
10726 /* Fall through. */
10727 case DW_TAG_class_type
:
10728 case DW_TAG_interface_type
:
10729 case DW_TAG_structure_type
:
10730 case DW_TAG_union_type
:
10731 case DW_TAG_set_type
:
10732 case DW_TAG_enumeration_type
:
10733 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10734 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10737 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10738 really ever be static objects: otherwise, if you try
10739 to, say, break of a class's method and you're in a file
10740 which doesn't mention that class, it won't work unless
10741 the check for all static symbols in lookup_symbol_aux
10742 saves you. See the OtherFileClass tests in
10743 gdb.c++/namespace.exp. */
10747 list_to_add
= (cu
->list_in_scope
== &file_symbols
10748 && (cu
->language
== language_cplus
10749 || cu
->language
== language_java
)
10750 ? &global_symbols
: cu
->list_in_scope
);
10752 /* The semantics of C++ state that "struct foo {
10753 ... }" also defines a typedef for "foo". A Java
10754 class declaration also defines a typedef for the
10756 if (cu
->language
== language_cplus
10757 || cu
->language
== language_java
10758 || cu
->language
== language_ada
)
10760 /* The symbol's name is already allocated along
10761 with this objfile, so we don't need to
10762 duplicate it for the type. */
10763 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
10764 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
10769 case DW_TAG_typedef
:
10770 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10771 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10772 list_to_add
= cu
->list_in_scope
;
10774 case DW_TAG_base_type
:
10775 case DW_TAG_subrange_type
:
10776 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10777 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10778 list_to_add
= cu
->list_in_scope
;
10780 case DW_TAG_enumerator
:
10781 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10784 dwarf2_const_value (attr
, sym
, cu
);
10787 /* NOTE: carlton/2003-11-10: See comment above in the
10788 DW_TAG_class_type, etc. block. */
10790 list_to_add
= (cu
->list_in_scope
== &file_symbols
10791 && (cu
->language
== language_cplus
10792 || cu
->language
== language_java
)
10793 ? &global_symbols
: cu
->list_in_scope
);
10796 case DW_TAG_namespace
:
10797 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10798 list_to_add
= &global_symbols
;
10801 /* Not a tag we recognize. Hopefully we aren't processing
10802 trash data, but since we must specifically ignore things
10803 we don't recognize, there is nothing else we should do at
10805 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10806 dwarf_tag_name (die
->tag
));
10812 sym
->hash_next
= objfile
->template_symbols
;
10813 objfile
->template_symbols
= sym
;
10814 list_to_add
= NULL
;
10817 if (list_to_add
!= NULL
)
10818 add_symbol_to_list (sym
, list_to_add
);
10820 /* For the benefit of old versions of GCC, check for anonymous
10821 namespaces based on the demangled name. */
10822 if (!processing_has_namespace_info
10823 && cu
->language
== language_cplus
)
10824 cp_scan_for_anonymous_namespaces (sym
);
10829 /* A wrapper for new_symbol_full that always allocates a new symbol. */
10831 static struct symbol
*
10832 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10834 return new_symbol_full (die
, type
, cu
, NULL
);
10837 /* Given an attr with a DW_FORM_dataN value in host byte order,
10838 zero-extend it as appropriate for the symbol's type. The DWARF
10839 standard (v4) is not entirely clear about the meaning of using
10840 DW_FORM_dataN for a constant with a signed type, where the type is
10841 wider than the data. The conclusion of a discussion on the DWARF
10842 list was that this is unspecified. We choose to always zero-extend
10843 because that is the interpretation long in use by GCC. */
10846 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
10847 const char *name
, struct obstack
*obstack
,
10848 struct dwarf2_cu
*cu
, long *value
, int bits
)
10850 struct objfile
*objfile
= cu
->objfile
;
10851 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10852 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10853 LONGEST l
= DW_UNSND (attr
);
10855 if (bits
< sizeof (*value
) * 8)
10857 l
&= ((LONGEST
) 1 << bits
) - 1;
10860 else if (bits
== sizeof (*value
) * 8)
10864 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
10865 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
10872 /* Read a constant value from an attribute. Either set *VALUE, or if
10873 the value does not fit in *VALUE, set *BYTES - either already
10874 allocated on the objfile obstack, or newly allocated on OBSTACK,
10875 or, set *BATON, if we translated the constant to a location
10879 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
10880 const char *name
, struct obstack
*obstack
,
10881 struct dwarf2_cu
*cu
,
10882 long *value
, gdb_byte
**bytes
,
10883 struct dwarf2_locexpr_baton
**baton
)
10885 struct objfile
*objfile
= cu
->objfile
;
10886 struct comp_unit_head
*cu_header
= &cu
->header
;
10887 struct dwarf_block
*blk
;
10888 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
10889 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
10895 switch (attr
->form
)
10901 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
10902 dwarf2_const_value_length_mismatch_complaint (name
,
10903 cu_header
->addr_size
,
10904 TYPE_LENGTH (type
));
10905 /* Symbols of this form are reasonably rare, so we just
10906 piggyback on the existing location code rather than writing
10907 a new implementation of symbol_computed_ops. */
10908 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
10909 sizeof (struct dwarf2_locexpr_baton
));
10910 (*baton
)->per_cu
= cu
->per_cu
;
10911 gdb_assert ((*baton
)->per_cu
);
10913 (*baton
)->size
= 2 + cu_header
->addr_size
;
10914 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
10915 (*baton
)->data
= data
;
10917 data
[0] = DW_OP_addr
;
10918 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
10919 byte_order
, DW_ADDR (attr
));
10920 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
10923 case DW_FORM_string
:
10925 /* DW_STRING is already allocated on the objfile obstack, point
10927 *bytes
= (gdb_byte
*) DW_STRING (attr
);
10929 case DW_FORM_block1
:
10930 case DW_FORM_block2
:
10931 case DW_FORM_block4
:
10932 case DW_FORM_block
:
10933 case DW_FORM_exprloc
:
10934 blk
= DW_BLOCK (attr
);
10935 if (TYPE_LENGTH (type
) != blk
->size
)
10936 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
10937 TYPE_LENGTH (type
));
10938 *bytes
= blk
->data
;
10941 /* The DW_AT_const_value attributes are supposed to carry the
10942 symbol's value "represented as it would be on the target
10943 architecture." By the time we get here, it's already been
10944 converted to host endianness, so we just need to sign- or
10945 zero-extend it as appropriate. */
10946 case DW_FORM_data1
:
10947 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 8);
10949 case DW_FORM_data2
:
10950 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 16);
10952 case DW_FORM_data4
:
10953 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 32);
10955 case DW_FORM_data8
:
10956 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 64);
10959 case DW_FORM_sdata
:
10960 *value
= DW_SND (attr
);
10963 case DW_FORM_udata
:
10964 *value
= DW_UNSND (attr
);
10968 complaint (&symfile_complaints
,
10969 _("unsupported const value attribute form: '%s'"),
10970 dwarf_form_name (attr
->form
));
10977 /* Copy constant value from an attribute to a symbol. */
10980 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
10981 struct dwarf2_cu
*cu
)
10983 struct objfile
*objfile
= cu
->objfile
;
10984 struct comp_unit_head
*cu_header
= &cu
->header
;
10987 struct dwarf2_locexpr_baton
*baton
;
10989 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
10990 SYMBOL_PRINT_NAME (sym
),
10991 &objfile
->objfile_obstack
, cu
,
10992 &value
, &bytes
, &baton
);
10996 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10997 SYMBOL_LOCATION_BATON (sym
) = baton
;
10998 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11000 else if (bytes
!= NULL
)
11002 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11003 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11007 SYMBOL_VALUE (sym
) = value
;
11008 SYMBOL_CLASS (sym
) = LOC_CONST
;
11012 /* Return the type of the die in question using its DW_AT_type attribute. */
11014 static struct type
*
11015 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11017 struct attribute
*type_attr
;
11019 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11022 /* A missing DW_AT_type represents a void type. */
11023 return objfile_type (cu
->objfile
)->builtin_void
;
11026 return lookup_die_type (die
, type_attr
, cu
);
11029 /* True iff CU's producer generates GNAT Ada auxiliary information
11030 that allows to find parallel types through that information instead
11031 of having to do expensive parallel lookups by type name. */
11034 need_gnat_info (struct dwarf2_cu
*cu
)
11036 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11037 of GNAT produces this auxiliary information, without any indication
11038 that it is produced. Part of enhancing the FSF version of GNAT
11039 to produce that information will be to put in place an indicator
11040 that we can use in order to determine whether the descriptive type
11041 info is available or not. One suggestion that has been made is
11042 to use a new attribute, attached to the CU die. For now, assume
11043 that the descriptive type info is not available. */
11047 /* Return the auxiliary type of the die in question using its
11048 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11049 attribute is not present. */
11051 static struct type
*
11052 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11054 struct attribute
*type_attr
;
11056 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11060 return lookup_die_type (die
, type_attr
, cu
);
11063 /* If DIE has a descriptive_type attribute, then set the TYPE's
11064 descriptive type accordingly. */
11067 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11068 struct dwarf2_cu
*cu
)
11070 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11072 if (descriptive_type
)
11074 ALLOCATE_GNAT_AUX_TYPE (type
);
11075 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11079 /* Return the containing type of the die in question using its
11080 DW_AT_containing_type attribute. */
11082 static struct type
*
11083 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11085 struct attribute
*type_attr
;
11087 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11089 error (_("Dwarf Error: Problem turning containing type into gdb type "
11090 "[in module %s]"), cu
->objfile
->name
);
11092 return lookup_die_type (die
, type_attr
, cu
);
11095 /* Look up the type of DIE in CU using its type attribute ATTR.
11096 If there is no type substitute an error marker. */
11098 static struct type
*
11099 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11100 struct dwarf2_cu
*cu
)
11102 struct type
*this_type
;
11104 /* First see if we have it cached. */
11106 if (is_ref_attr (attr
))
11108 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11110 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11112 else if (attr
->form
== DW_FORM_sig8
)
11114 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11115 struct dwarf2_cu
*sig_cu
;
11116 unsigned int offset
;
11118 /* sig_type will be NULL if the signatured type is missing from
11120 if (sig_type
== NULL
)
11121 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11122 "at 0x%x [in module %s]"),
11123 die
->offset
, cu
->objfile
->name
);
11125 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11126 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11127 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11131 dump_die_for_error (die
);
11132 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11133 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11136 /* If not cached we need to read it in. */
11138 if (this_type
== NULL
)
11140 struct die_info
*type_die
;
11141 struct dwarf2_cu
*type_cu
= cu
;
11143 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11144 /* If the type is cached, we should have found it above. */
11145 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11146 this_type
= read_type_die_1 (type_die
, type_cu
);
11149 /* If we still don't have a type use an error marker. */
11151 if (this_type
== NULL
)
11153 char *message
, *saved
;
11155 /* read_type_die already issued a complaint. */
11156 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11160 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11161 message
, strlen (message
));
11164 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11170 /* Return the type in DIE, CU.
11171 Returns NULL for invalid types.
11173 This first does a lookup in the appropriate type_hash table,
11174 and only reads the die in if necessary.
11176 NOTE: This can be called when reading in partial or full symbols. */
11178 static struct type
*
11179 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11181 struct type
*this_type
;
11183 this_type
= get_die_type (die
, cu
);
11187 return read_type_die_1 (die
, cu
);
11190 /* Read the type in DIE, CU.
11191 Returns NULL for invalid types. */
11193 static struct type
*
11194 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11196 struct type
*this_type
= NULL
;
11200 case DW_TAG_class_type
:
11201 case DW_TAG_interface_type
:
11202 case DW_TAG_structure_type
:
11203 case DW_TAG_union_type
:
11204 this_type
= read_structure_type (die
, cu
);
11206 case DW_TAG_enumeration_type
:
11207 this_type
= read_enumeration_type (die
, cu
);
11209 case DW_TAG_subprogram
:
11210 case DW_TAG_subroutine_type
:
11211 case DW_TAG_inlined_subroutine
:
11212 this_type
= read_subroutine_type (die
, cu
);
11214 case DW_TAG_array_type
:
11215 this_type
= read_array_type (die
, cu
);
11217 case DW_TAG_set_type
:
11218 this_type
= read_set_type (die
, cu
);
11220 case DW_TAG_pointer_type
:
11221 this_type
= read_tag_pointer_type (die
, cu
);
11223 case DW_TAG_ptr_to_member_type
:
11224 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11226 case DW_TAG_reference_type
:
11227 this_type
= read_tag_reference_type (die
, cu
);
11229 case DW_TAG_const_type
:
11230 this_type
= read_tag_const_type (die
, cu
);
11232 case DW_TAG_volatile_type
:
11233 this_type
= read_tag_volatile_type (die
, cu
);
11235 case DW_TAG_string_type
:
11236 this_type
= read_tag_string_type (die
, cu
);
11238 case DW_TAG_typedef
:
11239 this_type
= read_typedef (die
, cu
);
11241 case DW_TAG_subrange_type
:
11242 this_type
= read_subrange_type (die
, cu
);
11244 case DW_TAG_base_type
:
11245 this_type
= read_base_type (die
, cu
);
11247 case DW_TAG_unspecified_type
:
11248 this_type
= read_unspecified_type (die
, cu
);
11250 case DW_TAG_namespace
:
11251 this_type
= read_namespace_type (die
, cu
);
11253 case DW_TAG_module
:
11254 this_type
= read_module_type (die
, cu
);
11257 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
11258 dwarf_tag_name (die
->tag
));
11265 /* Return the name of the namespace/class that DIE is defined within,
11266 or "" if we can't tell. The caller should not xfree the result.
11268 For example, if we're within the method foo() in the following
11278 then determine_prefix on foo's die will return "N::C". */
11281 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11283 struct die_info
*parent
, *spec_die
;
11284 struct dwarf2_cu
*spec_cu
;
11285 struct type
*parent_type
;
11287 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11288 && cu
->language
!= language_fortran
)
11291 /* We have to be careful in the presence of DW_AT_specification.
11292 For example, with GCC 3.4, given the code
11296 // Definition of N::foo.
11300 then we'll have a tree of DIEs like this:
11302 1: DW_TAG_compile_unit
11303 2: DW_TAG_namespace // N
11304 3: DW_TAG_subprogram // declaration of N::foo
11305 4: DW_TAG_subprogram // definition of N::foo
11306 DW_AT_specification // refers to die #3
11308 Thus, when processing die #4, we have to pretend that we're in
11309 the context of its DW_AT_specification, namely the contex of die
11312 spec_die
= die_specification (die
, &spec_cu
);
11313 if (spec_die
== NULL
)
11314 parent
= die
->parent
;
11317 parent
= spec_die
->parent
;
11321 if (parent
== NULL
)
11323 else if (parent
->building_fullname
)
11326 const char *parent_name
;
11328 /* It has been seen on RealView 2.2 built binaries,
11329 DW_TAG_template_type_param types actually _defined_ as
11330 children of the parent class:
11333 template class <class Enum> Class{};
11334 Class<enum E> class_e;
11336 1: DW_TAG_class_type (Class)
11337 2: DW_TAG_enumeration_type (E)
11338 3: DW_TAG_enumerator (enum1:0)
11339 3: DW_TAG_enumerator (enum2:1)
11341 2: DW_TAG_template_type_param
11342 DW_AT_type DW_FORM_ref_udata (E)
11344 Besides being broken debug info, it can put GDB into an
11345 infinite loop. Consider:
11347 When we're building the full name for Class<E>, we'll start
11348 at Class, and go look over its template type parameters,
11349 finding E. We'll then try to build the full name of E, and
11350 reach here. We're now trying to build the full name of E,
11351 and look over the parent DIE for containing scope. In the
11352 broken case, if we followed the parent DIE of E, we'd again
11353 find Class, and once again go look at its template type
11354 arguments, etc., etc. Simply don't consider such parent die
11355 as source-level parent of this die (it can't be, the language
11356 doesn't allow it), and break the loop here. */
11357 name
= dwarf2_name (die
, cu
);
11358 parent_name
= dwarf2_name (parent
, cu
);
11359 complaint (&symfile_complaints
,
11360 _("template param type '%s' defined within parent '%s'"),
11361 name
? name
: "<unknown>",
11362 parent_name
? parent_name
: "<unknown>");
11366 switch (parent
->tag
)
11368 case DW_TAG_namespace
:
11369 parent_type
= read_type_die (parent
, cu
);
11370 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11371 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11372 Work around this problem here. */
11373 if (cu
->language
== language_cplus
11374 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11376 /* We give a name to even anonymous namespaces. */
11377 return TYPE_TAG_NAME (parent_type
);
11378 case DW_TAG_class_type
:
11379 case DW_TAG_interface_type
:
11380 case DW_TAG_structure_type
:
11381 case DW_TAG_union_type
:
11382 case DW_TAG_module
:
11383 parent_type
= read_type_die (parent
, cu
);
11384 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11385 return TYPE_TAG_NAME (parent_type
);
11387 /* An anonymous structure is only allowed non-static data
11388 members; no typedefs, no member functions, et cetera.
11389 So it does not need a prefix. */
11392 return determine_prefix (parent
, cu
);
11396 /* Return a newly-allocated string formed by concatenating PREFIX and
11397 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11398 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11399 perform an obconcat, otherwise allocate storage for the result. The CU argument
11400 is used to determine the language and hence, the appropriate separator. */
11402 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11405 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11406 int physname
, struct dwarf2_cu
*cu
)
11408 const char *lead
= "";
11411 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
11413 else if (cu
->language
== language_java
)
11415 else if (cu
->language
== language_fortran
&& physname
)
11417 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11418 DW_AT_MIPS_linkage_name is preferred and used instead. */
11426 if (prefix
== NULL
)
11428 if (suffix
== NULL
)
11433 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11435 strcpy (retval
, lead
);
11436 strcat (retval
, prefix
);
11437 strcat (retval
, sep
);
11438 strcat (retval
, suffix
);
11443 /* We have an obstack. */
11444 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11448 /* Return sibling of die, NULL if no sibling. */
11450 static struct die_info
*
11451 sibling_die (struct die_info
*die
)
11453 return die
->sibling
;
11456 /* Get name of a die, return NULL if not found. */
11459 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11460 struct obstack
*obstack
)
11462 if (name
&& cu
->language
== language_cplus
)
11464 char *canon_name
= cp_canonicalize_string (name
);
11466 if (canon_name
!= NULL
)
11468 if (strcmp (canon_name
, name
) != 0)
11469 name
= obsavestring (canon_name
, strlen (canon_name
),
11471 xfree (canon_name
);
11478 /* Get name of a die, return NULL if not found. */
11481 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11483 struct attribute
*attr
;
11485 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11486 if (!attr
|| !DW_STRING (attr
))
11491 case DW_TAG_compile_unit
:
11492 /* Compilation units have a DW_AT_name that is a filename, not
11493 a source language identifier. */
11494 case DW_TAG_enumeration_type
:
11495 case DW_TAG_enumerator
:
11496 /* These tags always have simple identifiers already; no need
11497 to canonicalize them. */
11498 return DW_STRING (attr
);
11500 case DW_TAG_subprogram
:
11501 /* Java constructors will all be named "<init>", so return
11502 the class name when we see this special case. */
11503 if (cu
->language
== language_java
11504 && DW_STRING (attr
) != NULL
11505 && strcmp (DW_STRING (attr
), "<init>") == 0)
11507 struct dwarf2_cu
*spec_cu
= cu
;
11508 struct die_info
*spec_die
;
11510 /* GCJ will output '<init>' for Java constructor names.
11511 For this special case, return the name of the parent class. */
11513 /* GCJ may output suprogram DIEs with AT_specification set.
11514 If so, use the name of the specified DIE. */
11515 spec_die
= die_specification (die
, &spec_cu
);
11516 if (spec_die
!= NULL
)
11517 return dwarf2_name (spec_die
, spec_cu
);
11522 if (die
->tag
== DW_TAG_class_type
)
11523 return dwarf2_name (die
, cu
);
11525 while (die
->tag
!= DW_TAG_compile_unit
);
11529 case DW_TAG_class_type
:
11530 case DW_TAG_interface_type
:
11531 case DW_TAG_structure_type
:
11532 case DW_TAG_union_type
:
11533 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11534 structures or unions. These were of the form "._%d" in GCC 4.1,
11535 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11536 and GCC 4.4. We work around this problem by ignoring these. */
11537 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11538 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11546 if (!DW_STRING_IS_CANONICAL (attr
))
11549 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11550 &cu
->objfile
->objfile_obstack
);
11551 DW_STRING_IS_CANONICAL (attr
) = 1;
11553 return DW_STRING (attr
);
11556 /* Return the die that this die in an extension of, or NULL if there
11557 is none. *EXT_CU is the CU containing DIE on input, and the CU
11558 containing the return value on output. */
11560 static struct die_info
*
11561 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11563 struct attribute
*attr
;
11565 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11569 return follow_die_ref (die
, attr
, ext_cu
);
11572 /* Convert a DIE tag into its string name. */
11575 dwarf_tag_name (unsigned tag
)
11579 case DW_TAG_padding
:
11580 return "DW_TAG_padding";
11581 case DW_TAG_array_type
:
11582 return "DW_TAG_array_type";
11583 case DW_TAG_class_type
:
11584 return "DW_TAG_class_type";
11585 case DW_TAG_entry_point
:
11586 return "DW_TAG_entry_point";
11587 case DW_TAG_enumeration_type
:
11588 return "DW_TAG_enumeration_type";
11589 case DW_TAG_formal_parameter
:
11590 return "DW_TAG_formal_parameter";
11591 case DW_TAG_imported_declaration
:
11592 return "DW_TAG_imported_declaration";
11594 return "DW_TAG_label";
11595 case DW_TAG_lexical_block
:
11596 return "DW_TAG_lexical_block";
11597 case DW_TAG_member
:
11598 return "DW_TAG_member";
11599 case DW_TAG_pointer_type
:
11600 return "DW_TAG_pointer_type";
11601 case DW_TAG_reference_type
:
11602 return "DW_TAG_reference_type";
11603 case DW_TAG_compile_unit
:
11604 return "DW_TAG_compile_unit";
11605 case DW_TAG_string_type
:
11606 return "DW_TAG_string_type";
11607 case DW_TAG_structure_type
:
11608 return "DW_TAG_structure_type";
11609 case DW_TAG_subroutine_type
:
11610 return "DW_TAG_subroutine_type";
11611 case DW_TAG_typedef
:
11612 return "DW_TAG_typedef";
11613 case DW_TAG_union_type
:
11614 return "DW_TAG_union_type";
11615 case DW_TAG_unspecified_parameters
:
11616 return "DW_TAG_unspecified_parameters";
11617 case DW_TAG_variant
:
11618 return "DW_TAG_variant";
11619 case DW_TAG_common_block
:
11620 return "DW_TAG_common_block";
11621 case DW_TAG_common_inclusion
:
11622 return "DW_TAG_common_inclusion";
11623 case DW_TAG_inheritance
:
11624 return "DW_TAG_inheritance";
11625 case DW_TAG_inlined_subroutine
:
11626 return "DW_TAG_inlined_subroutine";
11627 case DW_TAG_module
:
11628 return "DW_TAG_module";
11629 case DW_TAG_ptr_to_member_type
:
11630 return "DW_TAG_ptr_to_member_type";
11631 case DW_TAG_set_type
:
11632 return "DW_TAG_set_type";
11633 case DW_TAG_subrange_type
:
11634 return "DW_TAG_subrange_type";
11635 case DW_TAG_with_stmt
:
11636 return "DW_TAG_with_stmt";
11637 case DW_TAG_access_declaration
:
11638 return "DW_TAG_access_declaration";
11639 case DW_TAG_base_type
:
11640 return "DW_TAG_base_type";
11641 case DW_TAG_catch_block
:
11642 return "DW_TAG_catch_block";
11643 case DW_TAG_const_type
:
11644 return "DW_TAG_const_type";
11645 case DW_TAG_constant
:
11646 return "DW_TAG_constant";
11647 case DW_TAG_enumerator
:
11648 return "DW_TAG_enumerator";
11649 case DW_TAG_file_type
:
11650 return "DW_TAG_file_type";
11651 case DW_TAG_friend
:
11652 return "DW_TAG_friend";
11653 case DW_TAG_namelist
:
11654 return "DW_TAG_namelist";
11655 case DW_TAG_namelist_item
:
11656 return "DW_TAG_namelist_item";
11657 case DW_TAG_packed_type
:
11658 return "DW_TAG_packed_type";
11659 case DW_TAG_subprogram
:
11660 return "DW_TAG_subprogram";
11661 case DW_TAG_template_type_param
:
11662 return "DW_TAG_template_type_param";
11663 case DW_TAG_template_value_param
:
11664 return "DW_TAG_template_value_param";
11665 case DW_TAG_thrown_type
:
11666 return "DW_TAG_thrown_type";
11667 case DW_TAG_try_block
:
11668 return "DW_TAG_try_block";
11669 case DW_TAG_variant_part
:
11670 return "DW_TAG_variant_part";
11671 case DW_TAG_variable
:
11672 return "DW_TAG_variable";
11673 case DW_TAG_volatile_type
:
11674 return "DW_TAG_volatile_type";
11675 case DW_TAG_dwarf_procedure
:
11676 return "DW_TAG_dwarf_procedure";
11677 case DW_TAG_restrict_type
:
11678 return "DW_TAG_restrict_type";
11679 case DW_TAG_interface_type
:
11680 return "DW_TAG_interface_type";
11681 case DW_TAG_namespace
:
11682 return "DW_TAG_namespace";
11683 case DW_TAG_imported_module
:
11684 return "DW_TAG_imported_module";
11685 case DW_TAG_unspecified_type
:
11686 return "DW_TAG_unspecified_type";
11687 case DW_TAG_partial_unit
:
11688 return "DW_TAG_partial_unit";
11689 case DW_TAG_imported_unit
:
11690 return "DW_TAG_imported_unit";
11691 case DW_TAG_condition
:
11692 return "DW_TAG_condition";
11693 case DW_TAG_shared_type
:
11694 return "DW_TAG_shared_type";
11695 case DW_TAG_type_unit
:
11696 return "DW_TAG_type_unit";
11697 case DW_TAG_MIPS_loop
:
11698 return "DW_TAG_MIPS_loop";
11699 case DW_TAG_HP_array_descriptor
:
11700 return "DW_TAG_HP_array_descriptor";
11701 case DW_TAG_format_label
:
11702 return "DW_TAG_format_label";
11703 case DW_TAG_function_template
:
11704 return "DW_TAG_function_template";
11705 case DW_TAG_class_template
:
11706 return "DW_TAG_class_template";
11707 case DW_TAG_GNU_BINCL
:
11708 return "DW_TAG_GNU_BINCL";
11709 case DW_TAG_GNU_EINCL
:
11710 return "DW_TAG_GNU_EINCL";
11711 case DW_TAG_upc_shared_type
:
11712 return "DW_TAG_upc_shared_type";
11713 case DW_TAG_upc_strict_type
:
11714 return "DW_TAG_upc_strict_type";
11715 case DW_TAG_upc_relaxed_type
:
11716 return "DW_TAG_upc_relaxed_type";
11717 case DW_TAG_PGI_kanji_type
:
11718 return "DW_TAG_PGI_kanji_type";
11719 case DW_TAG_PGI_interface_block
:
11720 return "DW_TAG_PGI_interface_block";
11722 return "DW_TAG_<unknown>";
11726 /* Convert a DWARF attribute code into its string name. */
11729 dwarf_attr_name (unsigned attr
)
11733 case DW_AT_sibling
:
11734 return "DW_AT_sibling";
11735 case DW_AT_location
:
11736 return "DW_AT_location";
11738 return "DW_AT_name";
11739 case DW_AT_ordering
:
11740 return "DW_AT_ordering";
11741 case DW_AT_subscr_data
:
11742 return "DW_AT_subscr_data";
11743 case DW_AT_byte_size
:
11744 return "DW_AT_byte_size";
11745 case DW_AT_bit_offset
:
11746 return "DW_AT_bit_offset";
11747 case DW_AT_bit_size
:
11748 return "DW_AT_bit_size";
11749 case DW_AT_element_list
:
11750 return "DW_AT_element_list";
11751 case DW_AT_stmt_list
:
11752 return "DW_AT_stmt_list";
11754 return "DW_AT_low_pc";
11755 case DW_AT_high_pc
:
11756 return "DW_AT_high_pc";
11757 case DW_AT_language
:
11758 return "DW_AT_language";
11760 return "DW_AT_member";
11762 return "DW_AT_discr";
11763 case DW_AT_discr_value
:
11764 return "DW_AT_discr_value";
11765 case DW_AT_visibility
:
11766 return "DW_AT_visibility";
11768 return "DW_AT_import";
11769 case DW_AT_string_length
:
11770 return "DW_AT_string_length";
11771 case DW_AT_common_reference
:
11772 return "DW_AT_common_reference";
11773 case DW_AT_comp_dir
:
11774 return "DW_AT_comp_dir";
11775 case DW_AT_const_value
:
11776 return "DW_AT_const_value";
11777 case DW_AT_containing_type
:
11778 return "DW_AT_containing_type";
11779 case DW_AT_default_value
:
11780 return "DW_AT_default_value";
11782 return "DW_AT_inline";
11783 case DW_AT_is_optional
:
11784 return "DW_AT_is_optional";
11785 case DW_AT_lower_bound
:
11786 return "DW_AT_lower_bound";
11787 case DW_AT_producer
:
11788 return "DW_AT_producer";
11789 case DW_AT_prototyped
:
11790 return "DW_AT_prototyped";
11791 case DW_AT_return_addr
:
11792 return "DW_AT_return_addr";
11793 case DW_AT_start_scope
:
11794 return "DW_AT_start_scope";
11795 case DW_AT_bit_stride
:
11796 return "DW_AT_bit_stride";
11797 case DW_AT_upper_bound
:
11798 return "DW_AT_upper_bound";
11799 case DW_AT_abstract_origin
:
11800 return "DW_AT_abstract_origin";
11801 case DW_AT_accessibility
:
11802 return "DW_AT_accessibility";
11803 case DW_AT_address_class
:
11804 return "DW_AT_address_class";
11805 case DW_AT_artificial
:
11806 return "DW_AT_artificial";
11807 case DW_AT_base_types
:
11808 return "DW_AT_base_types";
11809 case DW_AT_calling_convention
:
11810 return "DW_AT_calling_convention";
11812 return "DW_AT_count";
11813 case DW_AT_data_member_location
:
11814 return "DW_AT_data_member_location";
11815 case DW_AT_decl_column
:
11816 return "DW_AT_decl_column";
11817 case DW_AT_decl_file
:
11818 return "DW_AT_decl_file";
11819 case DW_AT_decl_line
:
11820 return "DW_AT_decl_line";
11821 case DW_AT_declaration
:
11822 return "DW_AT_declaration";
11823 case DW_AT_discr_list
:
11824 return "DW_AT_discr_list";
11825 case DW_AT_encoding
:
11826 return "DW_AT_encoding";
11827 case DW_AT_external
:
11828 return "DW_AT_external";
11829 case DW_AT_frame_base
:
11830 return "DW_AT_frame_base";
11832 return "DW_AT_friend";
11833 case DW_AT_identifier_case
:
11834 return "DW_AT_identifier_case";
11835 case DW_AT_macro_info
:
11836 return "DW_AT_macro_info";
11837 case DW_AT_namelist_items
:
11838 return "DW_AT_namelist_items";
11839 case DW_AT_priority
:
11840 return "DW_AT_priority";
11841 case DW_AT_segment
:
11842 return "DW_AT_segment";
11843 case DW_AT_specification
:
11844 return "DW_AT_specification";
11845 case DW_AT_static_link
:
11846 return "DW_AT_static_link";
11848 return "DW_AT_type";
11849 case DW_AT_use_location
:
11850 return "DW_AT_use_location";
11851 case DW_AT_variable_parameter
:
11852 return "DW_AT_variable_parameter";
11853 case DW_AT_virtuality
:
11854 return "DW_AT_virtuality";
11855 case DW_AT_vtable_elem_location
:
11856 return "DW_AT_vtable_elem_location";
11857 /* DWARF 3 values. */
11858 case DW_AT_allocated
:
11859 return "DW_AT_allocated";
11860 case DW_AT_associated
:
11861 return "DW_AT_associated";
11862 case DW_AT_data_location
:
11863 return "DW_AT_data_location";
11864 case DW_AT_byte_stride
:
11865 return "DW_AT_byte_stride";
11866 case DW_AT_entry_pc
:
11867 return "DW_AT_entry_pc";
11868 case DW_AT_use_UTF8
:
11869 return "DW_AT_use_UTF8";
11870 case DW_AT_extension
:
11871 return "DW_AT_extension";
11873 return "DW_AT_ranges";
11874 case DW_AT_trampoline
:
11875 return "DW_AT_trampoline";
11876 case DW_AT_call_column
:
11877 return "DW_AT_call_column";
11878 case DW_AT_call_file
:
11879 return "DW_AT_call_file";
11880 case DW_AT_call_line
:
11881 return "DW_AT_call_line";
11882 case DW_AT_description
:
11883 return "DW_AT_description";
11884 case DW_AT_binary_scale
:
11885 return "DW_AT_binary_scale";
11886 case DW_AT_decimal_scale
:
11887 return "DW_AT_decimal_scale";
11889 return "DW_AT_small";
11890 case DW_AT_decimal_sign
:
11891 return "DW_AT_decimal_sign";
11892 case DW_AT_digit_count
:
11893 return "DW_AT_digit_count";
11894 case DW_AT_picture_string
:
11895 return "DW_AT_picture_string";
11896 case DW_AT_mutable
:
11897 return "DW_AT_mutable";
11898 case DW_AT_threads_scaled
:
11899 return "DW_AT_threads_scaled";
11900 case DW_AT_explicit
:
11901 return "DW_AT_explicit";
11902 case DW_AT_object_pointer
:
11903 return "DW_AT_object_pointer";
11904 case DW_AT_endianity
:
11905 return "DW_AT_endianity";
11906 case DW_AT_elemental
:
11907 return "DW_AT_elemental";
11909 return "DW_AT_pure";
11910 case DW_AT_recursive
:
11911 return "DW_AT_recursive";
11912 /* DWARF 4 values. */
11913 case DW_AT_signature
:
11914 return "DW_AT_signature";
11915 case DW_AT_linkage_name
:
11916 return "DW_AT_linkage_name";
11917 /* SGI/MIPS extensions. */
11918 #ifdef MIPS /* collides with DW_AT_HP_block_index */
11919 case DW_AT_MIPS_fde
:
11920 return "DW_AT_MIPS_fde";
11922 case DW_AT_MIPS_loop_begin
:
11923 return "DW_AT_MIPS_loop_begin";
11924 case DW_AT_MIPS_tail_loop_begin
:
11925 return "DW_AT_MIPS_tail_loop_begin";
11926 case DW_AT_MIPS_epilog_begin
:
11927 return "DW_AT_MIPS_epilog_begin";
11928 case DW_AT_MIPS_loop_unroll_factor
:
11929 return "DW_AT_MIPS_loop_unroll_factor";
11930 case DW_AT_MIPS_software_pipeline_depth
:
11931 return "DW_AT_MIPS_software_pipeline_depth";
11932 case DW_AT_MIPS_linkage_name
:
11933 return "DW_AT_MIPS_linkage_name";
11934 case DW_AT_MIPS_stride
:
11935 return "DW_AT_MIPS_stride";
11936 case DW_AT_MIPS_abstract_name
:
11937 return "DW_AT_MIPS_abstract_name";
11938 case DW_AT_MIPS_clone_origin
:
11939 return "DW_AT_MIPS_clone_origin";
11940 case DW_AT_MIPS_has_inlines
:
11941 return "DW_AT_MIPS_has_inlines";
11942 /* HP extensions. */
11943 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11944 case DW_AT_HP_block_index
:
11945 return "DW_AT_HP_block_index";
11947 case DW_AT_HP_unmodifiable
:
11948 return "DW_AT_HP_unmodifiable";
11949 case DW_AT_HP_actuals_stmt_list
:
11950 return "DW_AT_HP_actuals_stmt_list";
11951 case DW_AT_HP_proc_per_section
:
11952 return "DW_AT_HP_proc_per_section";
11953 case DW_AT_HP_raw_data_ptr
:
11954 return "DW_AT_HP_raw_data_ptr";
11955 case DW_AT_HP_pass_by_reference
:
11956 return "DW_AT_HP_pass_by_reference";
11957 case DW_AT_HP_opt_level
:
11958 return "DW_AT_HP_opt_level";
11959 case DW_AT_HP_prof_version_id
:
11960 return "DW_AT_HP_prof_version_id";
11961 case DW_AT_HP_opt_flags
:
11962 return "DW_AT_HP_opt_flags";
11963 case DW_AT_HP_cold_region_low_pc
:
11964 return "DW_AT_HP_cold_region_low_pc";
11965 case DW_AT_HP_cold_region_high_pc
:
11966 return "DW_AT_HP_cold_region_high_pc";
11967 case DW_AT_HP_all_variables_modifiable
:
11968 return "DW_AT_HP_all_variables_modifiable";
11969 case DW_AT_HP_linkage_name
:
11970 return "DW_AT_HP_linkage_name";
11971 case DW_AT_HP_prof_flags
:
11972 return "DW_AT_HP_prof_flags";
11973 /* GNU extensions. */
11974 case DW_AT_sf_names
:
11975 return "DW_AT_sf_names";
11976 case DW_AT_src_info
:
11977 return "DW_AT_src_info";
11978 case DW_AT_mac_info
:
11979 return "DW_AT_mac_info";
11980 case DW_AT_src_coords
:
11981 return "DW_AT_src_coords";
11982 case DW_AT_body_begin
:
11983 return "DW_AT_body_begin";
11984 case DW_AT_body_end
:
11985 return "DW_AT_body_end";
11986 case DW_AT_GNU_vector
:
11987 return "DW_AT_GNU_vector";
11988 case DW_AT_GNU_odr_signature
:
11989 return "DW_AT_GNU_odr_signature";
11990 /* VMS extensions. */
11991 case DW_AT_VMS_rtnbeg_pd_address
:
11992 return "DW_AT_VMS_rtnbeg_pd_address";
11993 /* UPC extension. */
11994 case DW_AT_upc_threads_scaled
:
11995 return "DW_AT_upc_threads_scaled";
11996 /* PGI (STMicroelectronics) extensions. */
11997 case DW_AT_PGI_lbase
:
11998 return "DW_AT_PGI_lbase";
11999 case DW_AT_PGI_soffset
:
12000 return "DW_AT_PGI_soffset";
12001 case DW_AT_PGI_lstride
:
12002 return "DW_AT_PGI_lstride";
12004 return "DW_AT_<unknown>";
12008 /* Convert a DWARF value form code into its string name. */
12011 dwarf_form_name (unsigned form
)
12016 return "DW_FORM_addr";
12017 case DW_FORM_block2
:
12018 return "DW_FORM_block2";
12019 case DW_FORM_block4
:
12020 return "DW_FORM_block4";
12021 case DW_FORM_data2
:
12022 return "DW_FORM_data2";
12023 case DW_FORM_data4
:
12024 return "DW_FORM_data4";
12025 case DW_FORM_data8
:
12026 return "DW_FORM_data8";
12027 case DW_FORM_string
:
12028 return "DW_FORM_string";
12029 case DW_FORM_block
:
12030 return "DW_FORM_block";
12031 case DW_FORM_block1
:
12032 return "DW_FORM_block1";
12033 case DW_FORM_data1
:
12034 return "DW_FORM_data1";
12036 return "DW_FORM_flag";
12037 case DW_FORM_sdata
:
12038 return "DW_FORM_sdata";
12040 return "DW_FORM_strp";
12041 case DW_FORM_udata
:
12042 return "DW_FORM_udata";
12043 case DW_FORM_ref_addr
:
12044 return "DW_FORM_ref_addr";
12046 return "DW_FORM_ref1";
12048 return "DW_FORM_ref2";
12050 return "DW_FORM_ref4";
12052 return "DW_FORM_ref8";
12053 case DW_FORM_ref_udata
:
12054 return "DW_FORM_ref_udata";
12055 case DW_FORM_indirect
:
12056 return "DW_FORM_indirect";
12057 case DW_FORM_sec_offset
:
12058 return "DW_FORM_sec_offset";
12059 case DW_FORM_exprloc
:
12060 return "DW_FORM_exprloc";
12061 case DW_FORM_flag_present
:
12062 return "DW_FORM_flag_present";
12064 return "DW_FORM_sig8";
12066 return "DW_FORM_<unknown>";
12070 /* Convert a DWARF stack opcode into its string name. */
12073 dwarf_stack_op_name (unsigned op
, int def
)
12078 return "DW_OP_addr";
12080 return "DW_OP_deref";
12081 case DW_OP_const1u
:
12082 return "DW_OP_const1u";
12083 case DW_OP_const1s
:
12084 return "DW_OP_const1s";
12085 case DW_OP_const2u
:
12086 return "DW_OP_const2u";
12087 case DW_OP_const2s
:
12088 return "DW_OP_const2s";
12089 case DW_OP_const4u
:
12090 return "DW_OP_const4u";
12091 case DW_OP_const4s
:
12092 return "DW_OP_const4s";
12093 case DW_OP_const8u
:
12094 return "DW_OP_const8u";
12095 case DW_OP_const8s
:
12096 return "DW_OP_const8s";
12098 return "DW_OP_constu";
12100 return "DW_OP_consts";
12102 return "DW_OP_dup";
12104 return "DW_OP_drop";
12106 return "DW_OP_over";
12108 return "DW_OP_pick";
12110 return "DW_OP_swap";
12112 return "DW_OP_rot";
12114 return "DW_OP_xderef";
12116 return "DW_OP_abs";
12118 return "DW_OP_and";
12120 return "DW_OP_div";
12122 return "DW_OP_minus";
12124 return "DW_OP_mod";
12126 return "DW_OP_mul";
12128 return "DW_OP_neg";
12130 return "DW_OP_not";
12134 return "DW_OP_plus";
12135 case DW_OP_plus_uconst
:
12136 return "DW_OP_plus_uconst";
12138 return "DW_OP_shl";
12140 return "DW_OP_shr";
12142 return "DW_OP_shra";
12144 return "DW_OP_xor";
12146 return "DW_OP_bra";
12160 return "DW_OP_skip";
12162 return "DW_OP_lit0";
12164 return "DW_OP_lit1";
12166 return "DW_OP_lit2";
12168 return "DW_OP_lit3";
12170 return "DW_OP_lit4";
12172 return "DW_OP_lit5";
12174 return "DW_OP_lit6";
12176 return "DW_OP_lit7";
12178 return "DW_OP_lit8";
12180 return "DW_OP_lit9";
12182 return "DW_OP_lit10";
12184 return "DW_OP_lit11";
12186 return "DW_OP_lit12";
12188 return "DW_OP_lit13";
12190 return "DW_OP_lit14";
12192 return "DW_OP_lit15";
12194 return "DW_OP_lit16";
12196 return "DW_OP_lit17";
12198 return "DW_OP_lit18";
12200 return "DW_OP_lit19";
12202 return "DW_OP_lit20";
12204 return "DW_OP_lit21";
12206 return "DW_OP_lit22";
12208 return "DW_OP_lit23";
12210 return "DW_OP_lit24";
12212 return "DW_OP_lit25";
12214 return "DW_OP_lit26";
12216 return "DW_OP_lit27";
12218 return "DW_OP_lit28";
12220 return "DW_OP_lit29";
12222 return "DW_OP_lit30";
12224 return "DW_OP_lit31";
12226 return "DW_OP_reg0";
12228 return "DW_OP_reg1";
12230 return "DW_OP_reg2";
12232 return "DW_OP_reg3";
12234 return "DW_OP_reg4";
12236 return "DW_OP_reg5";
12238 return "DW_OP_reg6";
12240 return "DW_OP_reg7";
12242 return "DW_OP_reg8";
12244 return "DW_OP_reg9";
12246 return "DW_OP_reg10";
12248 return "DW_OP_reg11";
12250 return "DW_OP_reg12";
12252 return "DW_OP_reg13";
12254 return "DW_OP_reg14";
12256 return "DW_OP_reg15";
12258 return "DW_OP_reg16";
12260 return "DW_OP_reg17";
12262 return "DW_OP_reg18";
12264 return "DW_OP_reg19";
12266 return "DW_OP_reg20";
12268 return "DW_OP_reg21";
12270 return "DW_OP_reg22";
12272 return "DW_OP_reg23";
12274 return "DW_OP_reg24";
12276 return "DW_OP_reg25";
12278 return "DW_OP_reg26";
12280 return "DW_OP_reg27";
12282 return "DW_OP_reg28";
12284 return "DW_OP_reg29";
12286 return "DW_OP_reg30";
12288 return "DW_OP_reg31";
12290 return "DW_OP_breg0";
12292 return "DW_OP_breg1";
12294 return "DW_OP_breg2";
12296 return "DW_OP_breg3";
12298 return "DW_OP_breg4";
12300 return "DW_OP_breg5";
12302 return "DW_OP_breg6";
12304 return "DW_OP_breg7";
12306 return "DW_OP_breg8";
12308 return "DW_OP_breg9";
12310 return "DW_OP_breg10";
12312 return "DW_OP_breg11";
12314 return "DW_OP_breg12";
12316 return "DW_OP_breg13";
12318 return "DW_OP_breg14";
12320 return "DW_OP_breg15";
12322 return "DW_OP_breg16";
12324 return "DW_OP_breg17";
12326 return "DW_OP_breg18";
12328 return "DW_OP_breg19";
12330 return "DW_OP_breg20";
12332 return "DW_OP_breg21";
12334 return "DW_OP_breg22";
12336 return "DW_OP_breg23";
12338 return "DW_OP_breg24";
12340 return "DW_OP_breg25";
12342 return "DW_OP_breg26";
12344 return "DW_OP_breg27";
12346 return "DW_OP_breg28";
12348 return "DW_OP_breg29";
12350 return "DW_OP_breg30";
12352 return "DW_OP_breg31";
12354 return "DW_OP_regx";
12356 return "DW_OP_fbreg";
12358 return "DW_OP_bregx";
12360 return "DW_OP_piece";
12361 case DW_OP_deref_size
:
12362 return "DW_OP_deref_size";
12363 case DW_OP_xderef_size
:
12364 return "DW_OP_xderef_size";
12366 return "DW_OP_nop";
12367 /* DWARF 3 extensions. */
12368 case DW_OP_push_object_address
:
12369 return "DW_OP_push_object_address";
12371 return "DW_OP_call2";
12373 return "DW_OP_call4";
12374 case DW_OP_call_ref
:
12375 return "DW_OP_call_ref";
12376 case DW_OP_form_tls_address
:
12377 return "DW_OP_form_tls_address";
12378 case DW_OP_call_frame_cfa
:
12379 return "DW_OP_call_frame_cfa";
12380 case DW_OP_bit_piece
:
12381 return "DW_OP_bit_piece";
12382 /* DWARF 4 extensions. */
12383 case DW_OP_implicit_value
:
12384 return "DW_OP_implicit_value";
12385 case DW_OP_stack_value
:
12386 return "DW_OP_stack_value";
12387 /* GNU extensions. */
12388 case DW_OP_GNU_push_tls_address
:
12389 return "DW_OP_GNU_push_tls_address";
12390 case DW_OP_GNU_uninit
:
12391 return "DW_OP_GNU_uninit";
12393 return def
? "OP_<unknown>" : NULL
;
12398 dwarf_bool_name (unsigned mybool
)
12406 /* Convert a DWARF type code into its string name. */
12409 dwarf_type_encoding_name (unsigned enc
)
12414 return "DW_ATE_void";
12415 case DW_ATE_address
:
12416 return "DW_ATE_address";
12417 case DW_ATE_boolean
:
12418 return "DW_ATE_boolean";
12419 case DW_ATE_complex_float
:
12420 return "DW_ATE_complex_float";
12422 return "DW_ATE_float";
12423 case DW_ATE_signed
:
12424 return "DW_ATE_signed";
12425 case DW_ATE_signed_char
:
12426 return "DW_ATE_signed_char";
12427 case DW_ATE_unsigned
:
12428 return "DW_ATE_unsigned";
12429 case DW_ATE_unsigned_char
:
12430 return "DW_ATE_unsigned_char";
12432 case DW_ATE_imaginary_float
:
12433 return "DW_ATE_imaginary_float";
12434 case DW_ATE_packed_decimal
:
12435 return "DW_ATE_packed_decimal";
12436 case DW_ATE_numeric_string
:
12437 return "DW_ATE_numeric_string";
12438 case DW_ATE_edited
:
12439 return "DW_ATE_edited";
12440 case DW_ATE_signed_fixed
:
12441 return "DW_ATE_signed_fixed";
12442 case DW_ATE_unsigned_fixed
:
12443 return "DW_ATE_unsigned_fixed";
12444 case DW_ATE_decimal_float
:
12445 return "DW_ATE_decimal_float";
12448 return "DW_ATE_UTF";
12449 /* HP extensions. */
12450 case DW_ATE_HP_float80
:
12451 return "DW_ATE_HP_float80";
12452 case DW_ATE_HP_complex_float80
:
12453 return "DW_ATE_HP_complex_float80";
12454 case DW_ATE_HP_float128
:
12455 return "DW_ATE_HP_float128";
12456 case DW_ATE_HP_complex_float128
:
12457 return "DW_ATE_HP_complex_float128";
12458 case DW_ATE_HP_floathpintel
:
12459 return "DW_ATE_HP_floathpintel";
12460 case DW_ATE_HP_imaginary_float80
:
12461 return "DW_ATE_HP_imaginary_float80";
12462 case DW_ATE_HP_imaginary_float128
:
12463 return "DW_ATE_HP_imaginary_float128";
12465 return "DW_ATE_<unknown>";
12469 /* Convert a DWARF call frame info operation to its string name. */
12473 dwarf_cfi_name (unsigned cfi_opc
)
12477 case DW_CFA_advance_loc
:
12478 return "DW_CFA_advance_loc";
12479 case DW_CFA_offset
:
12480 return "DW_CFA_offset";
12481 case DW_CFA_restore
:
12482 return "DW_CFA_restore";
12484 return "DW_CFA_nop";
12485 case DW_CFA_set_loc
:
12486 return "DW_CFA_set_loc";
12487 case DW_CFA_advance_loc1
:
12488 return "DW_CFA_advance_loc1";
12489 case DW_CFA_advance_loc2
:
12490 return "DW_CFA_advance_loc2";
12491 case DW_CFA_advance_loc4
:
12492 return "DW_CFA_advance_loc4";
12493 case DW_CFA_offset_extended
:
12494 return "DW_CFA_offset_extended";
12495 case DW_CFA_restore_extended
:
12496 return "DW_CFA_restore_extended";
12497 case DW_CFA_undefined
:
12498 return "DW_CFA_undefined";
12499 case DW_CFA_same_value
:
12500 return "DW_CFA_same_value";
12501 case DW_CFA_register
:
12502 return "DW_CFA_register";
12503 case DW_CFA_remember_state
:
12504 return "DW_CFA_remember_state";
12505 case DW_CFA_restore_state
:
12506 return "DW_CFA_restore_state";
12507 case DW_CFA_def_cfa
:
12508 return "DW_CFA_def_cfa";
12509 case DW_CFA_def_cfa_register
:
12510 return "DW_CFA_def_cfa_register";
12511 case DW_CFA_def_cfa_offset
:
12512 return "DW_CFA_def_cfa_offset";
12514 case DW_CFA_def_cfa_expression
:
12515 return "DW_CFA_def_cfa_expression";
12516 case DW_CFA_expression
:
12517 return "DW_CFA_expression";
12518 case DW_CFA_offset_extended_sf
:
12519 return "DW_CFA_offset_extended_sf";
12520 case DW_CFA_def_cfa_sf
:
12521 return "DW_CFA_def_cfa_sf";
12522 case DW_CFA_def_cfa_offset_sf
:
12523 return "DW_CFA_def_cfa_offset_sf";
12524 case DW_CFA_val_offset
:
12525 return "DW_CFA_val_offset";
12526 case DW_CFA_val_offset_sf
:
12527 return "DW_CFA_val_offset_sf";
12528 case DW_CFA_val_expression
:
12529 return "DW_CFA_val_expression";
12530 /* SGI/MIPS specific. */
12531 case DW_CFA_MIPS_advance_loc8
:
12532 return "DW_CFA_MIPS_advance_loc8";
12533 /* GNU extensions. */
12534 case DW_CFA_GNU_window_save
:
12535 return "DW_CFA_GNU_window_save";
12536 case DW_CFA_GNU_args_size
:
12537 return "DW_CFA_GNU_args_size";
12538 case DW_CFA_GNU_negative_offset_extended
:
12539 return "DW_CFA_GNU_negative_offset_extended";
12541 return "DW_CFA_<unknown>";
12547 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12551 print_spaces (indent
, f
);
12552 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12553 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12555 if (die
->parent
!= NULL
)
12557 print_spaces (indent
, f
);
12558 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12559 die
->parent
->offset
);
12562 print_spaces (indent
, f
);
12563 fprintf_unfiltered (f
, " has children: %s\n",
12564 dwarf_bool_name (die
->child
!= NULL
));
12566 print_spaces (indent
, f
);
12567 fprintf_unfiltered (f
, " attributes:\n");
12569 for (i
= 0; i
< die
->num_attrs
; ++i
)
12571 print_spaces (indent
, f
);
12572 fprintf_unfiltered (f
, " %s (%s) ",
12573 dwarf_attr_name (die
->attrs
[i
].name
),
12574 dwarf_form_name (die
->attrs
[i
].form
));
12576 switch (die
->attrs
[i
].form
)
12578 case DW_FORM_ref_addr
:
12580 fprintf_unfiltered (f
, "address: ");
12581 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12583 case DW_FORM_block2
:
12584 case DW_FORM_block4
:
12585 case DW_FORM_block
:
12586 case DW_FORM_block1
:
12587 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
12589 case DW_FORM_exprloc
:
12590 fprintf_unfiltered (f
, "expression: size %u",
12591 DW_BLOCK (&die
->attrs
[i
])->size
);
12596 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12597 (long) (DW_ADDR (&die
->attrs
[i
])));
12599 case DW_FORM_data1
:
12600 case DW_FORM_data2
:
12601 case DW_FORM_data4
:
12602 case DW_FORM_data8
:
12603 case DW_FORM_udata
:
12604 case DW_FORM_sdata
:
12605 fprintf_unfiltered (f
, "constant: %s",
12606 pulongest (DW_UNSND (&die
->attrs
[i
])));
12608 case DW_FORM_sec_offset
:
12609 fprintf_unfiltered (f
, "section offset: %s",
12610 pulongest (DW_UNSND (&die
->attrs
[i
])));
12613 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12614 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12615 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12617 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12619 case DW_FORM_string
:
12621 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12622 DW_STRING (&die
->attrs
[i
])
12623 ? DW_STRING (&die
->attrs
[i
]) : "",
12624 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12627 if (DW_UNSND (&die
->attrs
[i
]))
12628 fprintf_unfiltered (f
, "flag: TRUE");
12630 fprintf_unfiltered (f
, "flag: FALSE");
12632 case DW_FORM_flag_present
:
12633 fprintf_unfiltered (f
, "flag: TRUE");
12635 case DW_FORM_indirect
:
12636 /* the reader will have reduced the indirect form to
12637 the "base form" so this form should not occur */
12638 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
12641 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
12642 die
->attrs
[i
].form
);
12645 fprintf_unfiltered (f
, "\n");
12650 dump_die_for_error (struct die_info
*die
)
12652 dump_die_shallow (gdb_stderr
, 0, die
);
12656 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
12658 int indent
= level
* 4;
12660 gdb_assert (die
!= NULL
);
12662 if (level
>= max_level
)
12665 dump_die_shallow (f
, indent
, die
);
12667 if (die
->child
!= NULL
)
12669 print_spaces (indent
, f
);
12670 fprintf_unfiltered (f
, " Children:");
12671 if (level
+ 1 < max_level
)
12673 fprintf_unfiltered (f
, "\n");
12674 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
12678 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
12682 if (die
->sibling
!= NULL
&& level
> 0)
12684 dump_die_1 (f
, level
, max_level
, die
->sibling
);
12688 /* This is called from the pdie macro in gdbinit.in.
12689 It's not static so gcc will keep a copy callable from gdb. */
12692 dump_die (struct die_info
*die
, int max_level
)
12694 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
12698 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
12702 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
12708 is_ref_attr (struct attribute
*attr
)
12710 switch (attr
->form
)
12712 case DW_FORM_ref_addr
:
12717 case DW_FORM_ref_udata
:
12724 static unsigned int
12725 dwarf2_get_ref_die_offset (struct attribute
*attr
)
12727 if (is_ref_attr (attr
))
12728 return DW_ADDR (attr
);
12730 complaint (&symfile_complaints
,
12731 _("unsupported die ref attribute form: '%s'"),
12732 dwarf_form_name (attr
->form
));
12736 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
12737 * the value held by the attribute is not constant. */
12740 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
12742 if (attr
->form
== DW_FORM_sdata
)
12743 return DW_SND (attr
);
12744 else if (attr
->form
== DW_FORM_udata
12745 || attr
->form
== DW_FORM_data1
12746 || attr
->form
== DW_FORM_data2
12747 || attr
->form
== DW_FORM_data4
12748 || attr
->form
== DW_FORM_data8
)
12749 return DW_UNSND (attr
);
12752 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
12753 dwarf_form_name (attr
->form
));
12754 return default_value
;
12758 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
12759 unit and add it to our queue.
12760 The result is non-zero if PER_CU was queued, otherwise the result is zero
12761 meaning either PER_CU is already queued or it is already loaded. */
12764 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
12765 struct dwarf2_per_cu_data
*per_cu
)
12767 /* We may arrive here during partial symbol reading, if we need full
12768 DIEs to process an unusual case (e.g. template arguments). Do
12769 not queue PER_CU, just tell our caller to load its DIEs. */
12770 if (dwarf2_per_objfile
->reading_partial_symbols
)
12772 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
12777 /* Mark the dependence relation so that we don't flush PER_CU
12779 dwarf2_add_dependence (this_cu
, per_cu
);
12781 /* If it's already on the queue, we have nothing to do. */
12782 if (per_cu
->queued
)
12785 /* If the compilation unit is already loaded, just mark it as
12787 if (per_cu
->cu
!= NULL
)
12789 per_cu
->cu
->last_used
= 0;
12793 /* Add it to the queue. */
12794 queue_comp_unit (per_cu
, this_cu
->objfile
);
12799 /* Follow reference or signature attribute ATTR of SRC_DIE.
12800 On entry *REF_CU is the CU of SRC_DIE.
12801 On exit *REF_CU is the CU of the result. */
12803 static struct die_info
*
12804 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
12805 struct dwarf2_cu
**ref_cu
)
12807 struct die_info
*die
;
12809 if (is_ref_attr (attr
))
12810 die
= follow_die_ref (src_die
, attr
, ref_cu
);
12811 else if (attr
->form
== DW_FORM_sig8
)
12812 die
= follow_die_sig (src_die
, attr
, ref_cu
);
12815 dump_die_for_error (src_die
);
12816 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
12817 (*ref_cu
)->objfile
->name
);
12823 /* Follow reference OFFSET.
12824 On entry *REF_CU is the CU of the source die referencing OFFSET.
12825 On exit *REF_CU is the CU of the result.
12826 Returns NULL if OFFSET is invalid. */
12828 static struct die_info
*
12829 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
12831 struct die_info temp_die
;
12832 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
12834 gdb_assert (cu
->per_cu
!= NULL
);
12838 if (cu
->per_cu
->from_debug_types
)
12840 /* .debug_types CUs cannot reference anything outside their CU.
12841 If they need to, they have to reference a signatured type via
12843 if (! offset_in_cu_p (&cu
->header
, offset
))
12846 else if (! offset_in_cu_p (&cu
->header
, offset
))
12848 struct dwarf2_per_cu_data
*per_cu
;
12850 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
12852 /* If necessary, add it to the queue and load its DIEs. */
12853 if (maybe_queue_comp_unit (cu
, per_cu
))
12854 load_full_comp_unit (per_cu
, cu
->objfile
);
12856 target_cu
= per_cu
->cu
;
12858 else if (cu
->dies
== NULL
)
12860 /* We're loading full DIEs during partial symbol reading. */
12861 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
12862 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
12865 *ref_cu
= target_cu
;
12866 temp_die
.offset
= offset
;
12867 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
12870 /* Follow reference attribute ATTR of SRC_DIE.
12871 On entry *REF_CU is the CU of SRC_DIE.
12872 On exit *REF_CU is the CU of the result. */
12874 static struct die_info
*
12875 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
12876 struct dwarf2_cu
**ref_cu
)
12878 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12879 struct dwarf2_cu
*cu
= *ref_cu
;
12880 struct die_info
*die
;
12882 die
= follow_die_offset (offset
, ref_cu
);
12884 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
12885 "at 0x%x [in module %s]"),
12886 offset
, src_die
->offset
, cu
->objfile
->name
);
12891 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
12892 value is intended for DW_OP_call*. */
12894 struct dwarf2_locexpr_baton
12895 dwarf2_fetch_die_location_block (unsigned int offset
,
12896 struct dwarf2_per_cu_data
*per_cu
)
12898 struct dwarf2_cu
*cu
= per_cu
->cu
;
12899 struct die_info
*die
;
12900 struct attribute
*attr
;
12901 struct dwarf2_locexpr_baton retval
;
12903 die
= follow_die_offset (offset
, &cu
);
12905 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
12906 offset
, per_cu
->cu
->objfile
->name
);
12908 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12911 /* DWARF: "If there is no such attribute, then there is no effect.". */
12913 retval
.data
= NULL
;
12918 if (!attr_form_is_block (attr
))
12919 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
12920 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
12921 offset
, per_cu
->cu
->objfile
->name
);
12923 retval
.data
= DW_BLOCK (attr
)->data
;
12924 retval
.size
= DW_BLOCK (attr
)->size
;
12926 retval
.per_cu
= cu
->per_cu
;
12930 /* Follow the signature attribute ATTR in SRC_DIE.
12931 On entry *REF_CU is the CU of SRC_DIE.
12932 On exit *REF_CU is the CU of the result. */
12934 static struct die_info
*
12935 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
12936 struct dwarf2_cu
**ref_cu
)
12938 struct objfile
*objfile
= (*ref_cu
)->objfile
;
12939 struct die_info temp_die
;
12940 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12941 struct dwarf2_cu
*sig_cu
;
12942 struct die_info
*die
;
12944 /* sig_type will be NULL if the signatured type is missing from
12946 if (sig_type
== NULL
)
12947 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12948 "at 0x%x [in module %s]"),
12949 src_die
->offset
, objfile
->name
);
12951 /* If necessary, add it to the queue and load its DIEs. */
12953 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
12954 read_signatured_type (objfile
, sig_type
);
12956 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
12958 sig_cu
= sig_type
->per_cu
.cu
;
12959 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
12960 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
12967 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12968 "at 0x%x [in module %s]"),
12969 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
12972 /* Given an offset of a signatured type, return its signatured_type. */
12974 static struct signatured_type
*
12975 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
12977 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
12978 unsigned int length
, initial_length_size
;
12979 unsigned int sig_offset
;
12980 struct signatured_type find_entry
, *type_sig
;
12982 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
12983 sig_offset
= (initial_length_size
12985 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
12986 + 1 /*address_size*/);
12987 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
12988 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
12990 /* This is only used to lookup previously recorded types.
12991 If we didn't find it, it's our bug. */
12992 gdb_assert (type_sig
!= NULL
);
12993 gdb_assert (offset
== type_sig
->offset
);
12998 /* Read in signatured type at OFFSET and build its CU and die(s). */
13001 read_signatured_type_at_offset (struct objfile
*objfile
,
13002 unsigned int offset
)
13004 struct signatured_type
*type_sig
;
13006 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13008 /* We have the section offset, but we need the signature to do the
13009 hash table lookup. */
13010 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13012 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13014 read_signatured_type (objfile
, type_sig
);
13016 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13019 /* Read in a signatured type and build its CU and DIEs. */
13022 read_signatured_type (struct objfile
*objfile
,
13023 struct signatured_type
*type_sig
)
13025 gdb_byte
*types_ptr
;
13026 struct die_reader_specs reader_specs
;
13027 struct dwarf2_cu
*cu
;
13028 ULONGEST signature
;
13029 struct cleanup
*back_to
, *free_cu_cleanup
;
13030 struct attribute
*attr
;
13032 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13033 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13035 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13037 cu
= xmalloc (sizeof (struct dwarf2_cu
));
13038 memset (cu
, 0, sizeof (struct dwarf2_cu
));
13039 obstack_init (&cu
->comp_unit_obstack
);
13040 cu
->objfile
= objfile
;
13041 type_sig
->per_cu
.cu
= cu
;
13042 cu
->per_cu
= &type_sig
->per_cu
;
13044 /* If an error occurs while loading, release our storage. */
13045 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13047 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13048 types_ptr
, objfile
->obfd
);
13049 gdb_assert (signature
== type_sig
->signature
);
13052 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13056 &cu
->comp_unit_obstack
,
13057 hashtab_obstack_allocate
,
13058 dummy_obstack_deallocate
);
13060 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13061 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13063 init_cu_die_reader (&reader_specs
, cu
);
13065 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13068 /* We try not to read any attributes in this function, because not
13069 all objfiles needed for references have been loaded yet, and symbol
13070 table processing isn't initialized. But we have to set the CU language,
13071 or we won't be able to build types correctly. */
13072 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
13074 set_cu_language (DW_UNSND (attr
), cu
);
13076 set_cu_language (language_minimal
, cu
);
13078 do_cleanups (back_to
);
13080 /* We've successfully allocated this compilation unit. Let our caller
13081 clean it up when finished with it. */
13082 discard_cleanups (free_cu_cleanup
);
13084 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13085 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13088 /* Decode simple location descriptions.
13089 Given a pointer to a dwarf block that defines a location, compute
13090 the location and return the value.
13092 NOTE drow/2003-11-18: This function is called in two situations
13093 now: for the address of static or global variables (partial symbols
13094 only) and for offsets into structures which are expected to be
13095 (more or less) constant. The partial symbol case should go away,
13096 and only the constant case should remain. That will let this
13097 function complain more accurately. A few special modes are allowed
13098 without complaint for global variables (for instance, global
13099 register values and thread-local values).
13101 A location description containing no operations indicates that the
13102 object is optimized out. The return value is 0 for that case.
13103 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13104 callers will only want a very basic result and this can become a
13107 Note that stack[0] is unused except as a default error return.
13108 Note that stack overflow is not yet handled. */
13111 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13113 struct objfile
*objfile
= cu
->objfile
;
13115 int size
= blk
->size
;
13116 gdb_byte
*data
= blk
->data
;
13117 CORE_ADDR stack
[64];
13119 unsigned int bytes_read
, unsnd
;
13163 stack
[++stacki
] = op
- DW_OP_lit0
;
13198 stack
[++stacki
] = op
- DW_OP_reg0
;
13200 dwarf2_complex_location_expr_complaint ();
13204 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13206 stack
[++stacki
] = unsnd
;
13208 dwarf2_complex_location_expr_complaint ();
13212 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13217 case DW_OP_const1u
:
13218 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13222 case DW_OP_const1s
:
13223 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13227 case DW_OP_const2u
:
13228 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13232 case DW_OP_const2s
:
13233 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13237 case DW_OP_const4u
:
13238 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13242 case DW_OP_const4s
:
13243 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13248 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13254 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13259 stack
[stacki
+ 1] = stack
[stacki
];
13264 stack
[stacki
- 1] += stack
[stacki
];
13268 case DW_OP_plus_uconst
:
13269 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13274 stack
[stacki
- 1] -= stack
[stacki
];
13279 /* If we're not the last op, then we definitely can't encode
13280 this using GDB's address_class enum. This is valid for partial
13281 global symbols, although the variable's address will be bogus
13284 dwarf2_complex_location_expr_complaint ();
13287 case DW_OP_GNU_push_tls_address
:
13288 /* The top of the stack has the offset from the beginning
13289 of the thread control block at which the variable is located. */
13290 /* Nothing should follow this operator, so the top of stack would
13292 /* This is valid for partial global symbols, but the variable's
13293 address will be bogus in the psymtab. */
13295 dwarf2_complex_location_expr_complaint ();
13298 case DW_OP_GNU_uninit
:
13302 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13303 dwarf_stack_op_name (op
, 1));
13304 return (stack
[stacki
]);
13307 return (stack
[stacki
]);
13310 /* memory allocation interface */
13312 static struct dwarf_block
*
13313 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13315 struct dwarf_block
*blk
;
13317 blk
= (struct dwarf_block
*)
13318 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13322 static struct abbrev_info
*
13323 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13325 struct abbrev_info
*abbrev
;
13327 abbrev
= (struct abbrev_info
*)
13328 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13329 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13333 static struct die_info
*
13334 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13336 struct die_info
*die
;
13337 size_t size
= sizeof (struct die_info
);
13340 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13342 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13343 memset (die
, 0, sizeof (struct die_info
));
13348 /* Macro support. */
13351 /* Return the full name of file number I in *LH's file name table.
13352 Use COMP_DIR as the name of the current directory of the
13353 compilation. The result is allocated using xmalloc; the caller is
13354 responsible for freeing it. */
13356 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13358 /* Is the file number a valid index into the line header's file name
13359 table? Remember that file numbers start with one, not zero. */
13360 if (1 <= file
&& file
<= lh
->num_file_names
)
13362 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13364 if (IS_ABSOLUTE_PATH (fe
->name
))
13365 return xstrdup (fe
->name
);
13373 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13379 dir_len
= strlen (dir
);
13380 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13381 strcpy (full_name
, dir
);
13382 full_name
[dir_len
] = '/';
13383 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13387 return xstrdup (fe
->name
);
13392 /* The compiler produced a bogus file number. We can at least
13393 record the macro definitions made in the file, even if we
13394 won't be able to find the file by name. */
13395 char fake_name
[80];
13397 sprintf (fake_name
, "<bad macro file number %d>", file
);
13399 complaint (&symfile_complaints
,
13400 _("bad file number in macro information (%d)"),
13403 return xstrdup (fake_name
);
13408 static struct macro_source_file
*
13409 macro_start_file (int file
, int line
,
13410 struct macro_source_file
*current_file
,
13411 const char *comp_dir
,
13412 struct line_header
*lh
, struct objfile
*objfile
)
13414 /* The full name of this source file. */
13415 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13417 /* We don't create a macro table for this compilation unit
13418 at all until we actually get a filename. */
13419 if (! pending_macros
)
13420 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13421 objfile
->macro_cache
);
13423 if (! current_file
)
13424 /* If we have no current file, then this must be the start_file
13425 directive for the compilation unit's main source file. */
13426 current_file
= macro_set_main (pending_macros
, full_name
);
13428 current_file
= macro_include (current_file
, line
, full_name
);
13432 return current_file
;
13436 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13437 followed by a null byte. */
13439 copy_string (const char *buf
, int len
)
13441 char *s
= xmalloc (len
+ 1);
13443 memcpy (s
, buf
, len
);
13449 static const char *
13450 consume_improper_spaces (const char *p
, const char *body
)
13454 complaint (&symfile_complaints
,
13455 _("macro definition contains spaces in formal argument list:\n`%s'"),
13467 parse_macro_definition (struct macro_source_file
*file
, int line
,
13472 /* The body string takes one of two forms. For object-like macro
13473 definitions, it should be:
13475 <macro name> " " <definition>
13477 For function-like macro definitions, it should be:
13479 <macro name> "() " <definition>
13481 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13483 Spaces may appear only where explicitly indicated, and in the
13486 The Dwarf 2 spec says that an object-like macro's name is always
13487 followed by a space, but versions of GCC around March 2002 omit
13488 the space when the macro's definition is the empty string.
13490 The Dwarf 2 spec says that there should be no spaces between the
13491 formal arguments in a function-like macro's formal argument list,
13492 but versions of GCC around March 2002 include spaces after the
13496 /* Find the extent of the macro name. The macro name is terminated
13497 by either a space or null character (for an object-like macro) or
13498 an opening paren (for a function-like macro). */
13499 for (p
= body
; *p
; p
++)
13500 if (*p
== ' ' || *p
== '(')
13503 if (*p
== ' ' || *p
== '\0')
13505 /* It's an object-like macro. */
13506 int name_len
= p
- body
;
13507 char *name
= copy_string (body
, name_len
);
13508 const char *replacement
;
13511 replacement
= body
+ name_len
+ 1;
13514 dwarf2_macro_malformed_definition_complaint (body
);
13515 replacement
= body
+ name_len
;
13518 macro_define_object (file
, line
, name
, replacement
);
13522 else if (*p
== '(')
13524 /* It's a function-like macro. */
13525 char *name
= copy_string (body
, p
- body
);
13528 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13532 p
= consume_improper_spaces (p
, body
);
13534 /* Parse the formal argument list. */
13535 while (*p
&& *p
!= ')')
13537 /* Find the extent of the current argument name. */
13538 const char *arg_start
= p
;
13540 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13543 if (! *p
|| p
== arg_start
)
13544 dwarf2_macro_malformed_definition_complaint (body
);
13547 /* Make sure argv has room for the new argument. */
13548 if (argc
>= argv_size
)
13551 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13554 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13557 p
= consume_improper_spaces (p
, body
);
13559 /* Consume the comma, if present. */
13564 p
= consume_improper_spaces (p
, body
);
13573 /* Perfectly formed definition, no complaints. */
13574 macro_define_function (file
, line
, name
,
13575 argc
, (const char **) argv
,
13577 else if (*p
== '\0')
13579 /* Complain, but do define it. */
13580 dwarf2_macro_malformed_definition_complaint (body
);
13581 macro_define_function (file
, line
, name
,
13582 argc
, (const char **) argv
,
13586 /* Just complain. */
13587 dwarf2_macro_malformed_definition_complaint (body
);
13590 /* Just complain. */
13591 dwarf2_macro_malformed_definition_complaint (body
);
13597 for (i
= 0; i
< argc
; i
++)
13603 dwarf2_macro_malformed_definition_complaint (body
);
13608 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
13609 char *comp_dir
, bfd
*abfd
,
13610 struct dwarf2_cu
*cu
)
13612 gdb_byte
*mac_ptr
, *mac_end
;
13613 struct macro_source_file
*current_file
= 0;
13614 enum dwarf_macinfo_record_type macinfo_type
;
13615 int at_commandline
;
13617 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13618 &dwarf2_per_objfile
->macinfo
);
13619 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
13621 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
13625 /* First pass: Find the name of the base filename.
13626 This filename is needed in order to process all macros whose definition
13627 (or undefinition) comes from the command line. These macros are defined
13628 before the first DW_MACINFO_start_file entry, and yet still need to be
13629 associated to the base file.
13631 To determine the base file name, we scan the macro definitions until we
13632 reach the first DW_MACINFO_start_file entry. We then initialize
13633 CURRENT_FILE accordingly so that any macro definition found before the
13634 first DW_MACINFO_start_file can still be associated to the base file. */
13636 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13637 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
13638 + dwarf2_per_objfile
->macinfo
.size
;
13642 /* Do we at least have room for a macinfo type byte? */
13643 if (mac_ptr
>= mac_end
)
13645 /* Complaint is printed during the second pass as GDB will probably
13646 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13650 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13653 switch (macinfo_type
)
13655 /* A zero macinfo type indicates the end of the macro
13660 case DW_MACINFO_define
:
13661 case DW_MACINFO_undef
:
13662 /* Only skip the data by MAC_PTR. */
13664 unsigned int bytes_read
;
13666 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13667 mac_ptr
+= bytes_read
;
13668 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13669 mac_ptr
+= bytes_read
;
13673 case DW_MACINFO_start_file
:
13675 unsigned int bytes_read
;
13678 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13679 mac_ptr
+= bytes_read
;
13680 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13681 mac_ptr
+= bytes_read
;
13683 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
13688 case DW_MACINFO_end_file
:
13689 /* No data to skip by MAC_PTR. */
13692 case DW_MACINFO_vendor_ext
:
13693 /* Only skip the data by MAC_PTR. */
13695 unsigned int bytes_read
;
13697 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13698 mac_ptr
+= bytes_read
;
13699 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13700 mac_ptr
+= bytes_read
;
13707 } while (macinfo_type
!= 0 && current_file
== NULL
);
13709 /* Second pass: Process all entries.
13711 Use the AT_COMMAND_LINE flag to determine whether we are still processing
13712 command-line macro definitions/undefinitions. This flag is unset when we
13713 reach the first DW_MACINFO_start_file entry. */
13715 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13717 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
13718 GDB is still reading the definitions from command line. First
13719 DW_MACINFO_start_file will need to be ignored as it was already executed
13720 to create CURRENT_FILE for the main source holding also the command line
13721 definitions. On first met DW_MACINFO_start_file this flag is reset to
13722 normally execute all the remaining DW_MACINFO_start_file macinfos. */
13724 at_commandline
= 1;
13728 /* Do we at least have room for a macinfo type byte? */
13729 if (mac_ptr
>= mac_end
)
13731 dwarf2_macros_too_long_complaint ();
13735 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13738 switch (macinfo_type
)
13740 /* A zero macinfo type indicates the end of the macro
13745 case DW_MACINFO_define
:
13746 case DW_MACINFO_undef
:
13748 unsigned int bytes_read
;
13752 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13753 mac_ptr
+= bytes_read
;
13754 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13755 mac_ptr
+= bytes_read
;
13757 if (! current_file
)
13759 /* DWARF violation as no main source is present. */
13760 complaint (&symfile_complaints
,
13761 _("debug info with no main source gives macro %s "
13763 macinfo_type
== DW_MACINFO_define
?
13765 macinfo_type
== DW_MACINFO_undef
?
13766 _("undefinition") :
13767 _("something-or-other"), line
, body
);
13770 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13771 complaint (&symfile_complaints
,
13772 _("debug info gives %s macro %s with %s line %d: %s"),
13773 at_commandline
? _("command-line") : _("in-file"),
13774 macinfo_type
== DW_MACINFO_define
?
13776 macinfo_type
== DW_MACINFO_undef
?
13777 _("undefinition") :
13778 _("something-or-other"),
13779 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
13781 if (macinfo_type
== DW_MACINFO_define
)
13782 parse_macro_definition (current_file
, line
, body
);
13783 else if (macinfo_type
== DW_MACINFO_undef
)
13784 macro_undef (current_file
, line
, body
);
13788 case DW_MACINFO_start_file
:
13790 unsigned int bytes_read
;
13793 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13794 mac_ptr
+= bytes_read
;
13795 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13796 mac_ptr
+= bytes_read
;
13798 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13799 complaint (&symfile_complaints
,
13800 _("debug info gives source %d included "
13801 "from %s at %s line %d"),
13802 file
, at_commandline
? _("command-line") : _("file"),
13803 line
== 0 ? _("zero") : _("non-zero"), line
);
13805 if (at_commandline
)
13807 /* This DW_MACINFO_start_file was executed in the pass one. */
13808 at_commandline
= 0;
13811 current_file
= macro_start_file (file
, line
,
13812 current_file
, comp_dir
,
13817 case DW_MACINFO_end_file
:
13818 if (! current_file
)
13819 complaint (&symfile_complaints
,
13820 _("macro debug info has an unmatched `close_file' directive"));
13823 current_file
= current_file
->included_by
;
13824 if (! current_file
)
13826 enum dwarf_macinfo_record_type next_type
;
13828 /* GCC circa March 2002 doesn't produce the zero
13829 type byte marking the end of the compilation
13830 unit. Complain if it's not there, but exit no
13833 /* Do we at least have room for a macinfo type byte? */
13834 if (mac_ptr
>= mac_end
)
13836 dwarf2_macros_too_long_complaint ();
13840 /* We don't increment mac_ptr here, so this is just
13842 next_type
= read_1_byte (abfd
, mac_ptr
);
13843 if (next_type
!= 0)
13844 complaint (&symfile_complaints
,
13845 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
13852 case DW_MACINFO_vendor_ext
:
13854 unsigned int bytes_read
;
13858 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13859 mac_ptr
+= bytes_read
;
13860 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13861 mac_ptr
+= bytes_read
;
13863 /* We don't recognize any vendor extensions. */
13867 } while (macinfo_type
!= 0);
13870 /* Check if the attribute's form is a DW_FORM_block*
13871 if so return true else false. */
13873 attr_form_is_block (struct attribute
*attr
)
13875 return (attr
== NULL
? 0 :
13876 attr
->form
== DW_FORM_block1
13877 || attr
->form
== DW_FORM_block2
13878 || attr
->form
== DW_FORM_block4
13879 || attr
->form
== DW_FORM_block
13880 || attr
->form
== DW_FORM_exprloc
);
13883 /* Return non-zero if ATTR's value is a section offset --- classes
13884 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
13885 You may use DW_UNSND (attr) to retrieve such offsets.
13887 Section 7.5.4, "Attribute Encodings", explains that no attribute
13888 may have a value that belongs to more than one of these classes; it
13889 would be ambiguous if we did, because we use the same forms for all
13892 attr_form_is_section_offset (struct attribute
*attr
)
13894 return (attr
->form
== DW_FORM_data4
13895 || attr
->form
== DW_FORM_data8
13896 || attr
->form
== DW_FORM_sec_offset
);
13900 /* Return non-zero if ATTR's value falls in the 'constant' class, or
13901 zero otherwise. When this function returns true, you can apply
13902 dwarf2_get_attr_constant_value to it.
13904 However, note that for some attributes you must check
13905 attr_form_is_section_offset before using this test. DW_FORM_data4
13906 and DW_FORM_data8 are members of both the constant class, and of
13907 the classes that contain offsets into other debug sections
13908 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
13909 that, if an attribute's can be either a constant or one of the
13910 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
13911 taken as section offsets, not constants. */
13913 attr_form_is_constant (struct attribute
*attr
)
13915 switch (attr
->form
)
13917 case DW_FORM_sdata
:
13918 case DW_FORM_udata
:
13919 case DW_FORM_data1
:
13920 case DW_FORM_data2
:
13921 case DW_FORM_data4
:
13922 case DW_FORM_data8
:
13930 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
13931 struct dwarf2_cu
*cu
)
13933 if (attr_form_is_section_offset (attr
)
13934 /* ".debug_loc" may not exist at all, or the offset may be outside
13935 the section. If so, fall through to the complaint in the
13937 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
13939 struct dwarf2_loclist_baton
*baton
;
13941 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13942 sizeof (struct dwarf2_loclist_baton
));
13943 baton
->per_cu
= cu
->per_cu
;
13944 gdb_assert (baton
->per_cu
);
13946 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13947 &dwarf2_per_objfile
->loc
);
13949 /* We don't know how long the location list is, but make sure we
13950 don't run off the edge of the section. */
13951 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
13952 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
13953 baton
->base_address
= cu
->base_address
;
13954 if (cu
->base_known
== 0)
13955 complaint (&symfile_complaints
,
13956 _("Location list used without specifying the CU base address."));
13958 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
13959 SYMBOL_LOCATION_BATON (sym
) = baton
;
13963 struct dwarf2_locexpr_baton
*baton
;
13965 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13966 sizeof (struct dwarf2_locexpr_baton
));
13967 baton
->per_cu
= cu
->per_cu
;
13968 gdb_assert (baton
->per_cu
);
13970 if (attr_form_is_block (attr
))
13972 /* Note that we're just copying the block's data pointer
13973 here, not the actual data. We're still pointing into the
13974 info_buffer for SYM's objfile; right now we never release
13975 that buffer, but when we do clean up properly this may
13977 baton
->size
= DW_BLOCK (attr
)->size
;
13978 baton
->data
= DW_BLOCK (attr
)->data
;
13982 dwarf2_invalid_attrib_class_complaint ("location description",
13983 SYMBOL_NATURAL_NAME (sym
));
13985 baton
->data
= NULL
;
13988 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13989 SYMBOL_LOCATION_BATON (sym
) = baton
;
13993 /* Return the OBJFILE associated with the compilation unit CU. If CU
13994 came from a separate debuginfo file, then the master objfile is
13998 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14000 struct objfile
*objfile
= per_cu
->objfile
;
14002 /* Return the master objfile, so that we can report and look up the
14003 correct file containing this variable. */
14004 if (objfile
->separate_debug_objfile_backlink
)
14005 objfile
= objfile
->separate_debug_objfile_backlink
;
14010 /* Return the address size given in the compilation unit header for CU. */
14013 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14016 return per_cu
->cu
->header
.addr_size
;
14019 /* If the CU is not currently read in, we re-read its header. */
14020 struct objfile
*objfile
= per_cu
->objfile
;
14021 struct dwarf2_per_objfile
*per_objfile
14022 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14023 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14024 struct comp_unit_head cu_header
;
14026 memset (&cu_header
, 0, sizeof cu_header
);
14027 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14028 return cu_header
.addr_size
;
14032 /* Return the offset size given in the compilation unit header for CU. */
14035 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14038 return per_cu
->cu
->header
.offset_size
;
14041 /* If the CU is not currently read in, we re-read its header. */
14042 struct objfile
*objfile
= per_cu
->objfile
;
14043 struct dwarf2_per_objfile
*per_objfile
14044 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14045 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14046 struct comp_unit_head cu_header
;
14048 memset (&cu_header
, 0, sizeof cu_header
);
14049 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14050 return cu_header
.offset_size
;
14054 /* Return the text offset of the CU. The returned offset comes from
14055 this CU's objfile. If this objfile came from a separate debuginfo
14056 file, then the offset may be different from the corresponding
14057 offset in the parent objfile. */
14060 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14062 struct objfile
*objfile
= per_cu
->objfile
;
14064 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14067 /* Locate the .debug_info compilation unit from CU's objfile which contains
14068 the DIE at OFFSET. Raises an error on failure. */
14070 static struct dwarf2_per_cu_data
*
14071 dwarf2_find_containing_comp_unit (unsigned int offset
,
14072 struct objfile
*objfile
)
14074 struct dwarf2_per_cu_data
*this_cu
;
14078 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14081 int mid
= low
+ (high
- low
) / 2;
14083 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14088 gdb_assert (low
== high
);
14089 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14092 error (_("Dwarf Error: could not find partial DIE containing "
14093 "offset 0x%lx [in module %s]"),
14094 (long) offset
, bfd_get_filename (objfile
->obfd
));
14096 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14097 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14101 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14102 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14103 && offset
>= this_cu
->offset
+ this_cu
->length
)
14104 error (_("invalid dwarf2 offset %u"), offset
);
14105 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14110 /* Locate the compilation unit from OBJFILE which is located at exactly
14111 OFFSET. Raises an error on failure. */
14113 static struct dwarf2_per_cu_data
*
14114 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14116 struct dwarf2_per_cu_data
*this_cu
;
14118 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14119 if (this_cu
->offset
!= offset
)
14120 error (_("no compilation unit with offset %u."), offset
);
14124 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
14126 static struct dwarf2_cu
*
14127 alloc_one_comp_unit (struct objfile
*objfile
)
14129 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
14130 cu
->objfile
= objfile
;
14131 obstack_init (&cu
->comp_unit_obstack
);
14135 /* Release one cached compilation unit, CU. We unlink it from the tree
14136 of compilation units, but we don't remove it from the read_in_chain;
14137 the caller is responsible for that.
14138 NOTE: DATA is a void * because this function is also used as a
14139 cleanup routine. */
14142 free_one_comp_unit (void *data
)
14144 struct dwarf2_cu
*cu
= data
;
14146 if (cu
->per_cu
!= NULL
)
14147 cu
->per_cu
->cu
= NULL
;
14150 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14155 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14156 when we're finished with it. We can't free the pointer itself, but be
14157 sure to unlink it from the cache. Also release any associated storage
14158 and perform cache maintenance.
14160 Only used during partial symbol parsing. */
14163 free_stack_comp_unit (void *data
)
14165 struct dwarf2_cu
*cu
= data
;
14167 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14168 cu
->partial_dies
= NULL
;
14170 if (cu
->per_cu
!= NULL
)
14172 /* This compilation unit is on the stack in our caller, so we
14173 should not xfree it. Just unlink it. */
14174 cu
->per_cu
->cu
= NULL
;
14177 /* If we had a per-cu pointer, then we may have other compilation
14178 units loaded, so age them now. */
14179 age_cached_comp_units ();
14183 /* Free all cached compilation units. */
14186 free_cached_comp_units (void *data
)
14188 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14190 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14191 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14192 while (per_cu
!= NULL
)
14194 struct dwarf2_per_cu_data
*next_cu
;
14196 next_cu
= per_cu
->cu
->read_in_chain
;
14198 free_one_comp_unit (per_cu
->cu
);
14199 *last_chain
= next_cu
;
14205 /* Increase the age counter on each cached compilation unit, and free
14206 any that are too old. */
14209 age_cached_comp_units (void)
14211 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14213 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14214 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14215 while (per_cu
!= NULL
)
14217 per_cu
->cu
->last_used
++;
14218 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14219 dwarf2_mark (per_cu
->cu
);
14220 per_cu
= per_cu
->cu
->read_in_chain
;
14223 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14224 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14225 while (per_cu
!= NULL
)
14227 struct dwarf2_per_cu_data
*next_cu
;
14229 next_cu
= per_cu
->cu
->read_in_chain
;
14231 if (!per_cu
->cu
->mark
)
14233 free_one_comp_unit (per_cu
->cu
);
14234 *last_chain
= next_cu
;
14237 last_chain
= &per_cu
->cu
->read_in_chain
;
14243 /* Remove a single compilation unit from the cache. */
14246 free_one_cached_comp_unit (void *target_cu
)
14248 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14250 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14251 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14252 while (per_cu
!= NULL
)
14254 struct dwarf2_per_cu_data
*next_cu
;
14256 next_cu
= per_cu
->cu
->read_in_chain
;
14258 if (per_cu
->cu
== target_cu
)
14260 free_one_comp_unit (per_cu
->cu
);
14261 *last_chain
= next_cu
;
14265 last_chain
= &per_cu
->cu
->read_in_chain
;
14271 /* Release all extra memory associated with OBJFILE. */
14274 dwarf2_free_objfile (struct objfile
*objfile
)
14276 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14278 if (dwarf2_per_objfile
== NULL
)
14281 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14282 free_cached_comp_units (NULL
);
14284 if (dwarf2_per_objfile
->using_index
)
14288 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14291 struct dwarf2_per_cu_data
*per_cu
=
14292 dwarf2_per_objfile
->all_comp_units
[i
];
14294 if (!per_cu
->v
.quick
->lines
)
14297 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
14299 if (per_cu
->v
.quick
->file_names
)
14300 xfree ((void *) per_cu
->v
.quick
->file_names
[j
]);
14301 if (per_cu
->v
.quick
->full_names
)
14302 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
14305 free_line_header (per_cu
->v
.quick
->lines
);
14309 /* Everything else should be on the objfile obstack. */
14312 /* A pair of DIE offset and GDB type pointer. We store these
14313 in a hash table separate from the DIEs, and preserve them
14314 when the DIEs are flushed out of cache. */
14316 struct dwarf2_offset_and_type
14318 unsigned int offset
;
14322 /* Hash function for a dwarf2_offset_and_type. */
14325 offset_and_type_hash (const void *item
)
14327 const struct dwarf2_offset_and_type
*ofs
= item
;
14329 return ofs
->offset
;
14332 /* Equality function for a dwarf2_offset_and_type. */
14335 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14337 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14338 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14340 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14343 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14344 table if necessary. For convenience, return TYPE.
14346 The DIEs reading must have careful ordering to:
14347 * Not cause infite loops trying to read in DIEs as a prerequisite for
14348 reading current DIE.
14349 * Not trying to dereference contents of still incompletely read in types
14350 while reading in other DIEs.
14351 * Enable referencing still incompletely read in types just by a pointer to
14352 the type without accessing its fields.
14354 Therefore caller should follow these rules:
14355 * Try to fetch any prerequisite types we may need to build this DIE type
14356 before building the type and calling set_die_type.
14357 * After building type call set_die_type for current DIE as soon as
14358 possible before fetching more types to complete the current type.
14359 * Make the type as complete as possible before fetching more types. */
14361 static struct type
*
14362 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14364 struct dwarf2_offset_and_type
**slot
, ofs
;
14365 struct objfile
*objfile
= cu
->objfile
;
14366 htab_t
*type_hash_ptr
;
14368 /* For Ada types, make sure that the gnat-specific data is always
14369 initialized (if not already set). There are a few types where
14370 we should not be doing so, because the type-specific area is
14371 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14372 where the type-specific area is used to store the floatformat).
14373 But this is not a problem, because the gnat-specific information
14374 is actually not needed for these types. */
14375 if (need_gnat_info (cu
)
14376 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14377 && TYPE_CODE (type
) != TYPE_CODE_FLT
14378 && !HAVE_GNAT_AUX_INFO (type
))
14379 INIT_GNAT_SPECIFIC (type
);
14381 if (cu
->per_cu
->from_debug_types
)
14382 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14384 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14386 if (*type_hash_ptr
== NULL
)
14389 = htab_create_alloc_ex (127,
14390 offset_and_type_hash
,
14391 offset_and_type_eq
,
14393 &objfile
->objfile_obstack
,
14394 hashtab_obstack_allocate
,
14395 dummy_obstack_deallocate
);
14398 ofs
.offset
= die
->offset
;
14400 slot
= (struct dwarf2_offset_and_type
**)
14401 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14403 complaint (&symfile_complaints
,
14404 _("A problem internal to GDB: DIE 0x%x has type already set"),
14406 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14411 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14412 table, or return NULL if the die does not have a saved type. */
14414 static struct type
*
14415 get_die_type_at_offset (unsigned int offset
,
14416 struct dwarf2_per_cu_data
*per_cu
)
14418 struct dwarf2_offset_and_type
*slot
, ofs
;
14421 if (per_cu
->from_debug_types
)
14422 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
14424 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
14425 if (type_hash
== NULL
)
14428 ofs
.offset
= offset
;
14429 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14436 /* Look up the type for DIE in the appropriate type_hash table,
14437 or return NULL if DIE does not have a saved type. */
14439 static struct type
*
14440 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14442 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
14445 /* Add a dependence relationship from CU to REF_PER_CU. */
14448 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14449 struct dwarf2_per_cu_data
*ref_per_cu
)
14453 if (cu
->dependencies
== NULL
)
14455 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14456 NULL
, &cu
->comp_unit_obstack
,
14457 hashtab_obstack_allocate
,
14458 dummy_obstack_deallocate
);
14460 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14462 *slot
= ref_per_cu
;
14465 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14466 Set the mark field in every compilation unit in the
14467 cache that we must keep because we are keeping CU. */
14470 dwarf2_mark_helper (void **slot
, void *data
)
14472 struct dwarf2_per_cu_data
*per_cu
;
14474 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14475 if (per_cu
->cu
->mark
)
14477 per_cu
->cu
->mark
= 1;
14479 if (per_cu
->cu
->dependencies
!= NULL
)
14480 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14485 /* Set the mark field in CU and in every other compilation unit in the
14486 cache that we must keep because we are keeping CU. */
14489 dwarf2_mark (struct dwarf2_cu
*cu
)
14494 if (cu
->dependencies
!= NULL
)
14495 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14499 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14503 per_cu
->cu
->mark
= 0;
14504 per_cu
= per_cu
->cu
->read_in_chain
;
14508 /* Trivial hash function for partial_die_info: the hash value of a DIE
14509 is its offset in .debug_info for this objfile. */
14512 partial_die_hash (const void *item
)
14514 const struct partial_die_info
*part_die
= item
;
14516 return part_die
->offset
;
14519 /* Trivial comparison function for partial_die_info structures: two DIEs
14520 are equal if they have the same offset. */
14523 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14525 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14526 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14528 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14531 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14532 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14535 set_dwarf2_cmd (char *args
, int from_tty
)
14537 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14541 show_dwarf2_cmd (char *args
, int from_tty
)
14543 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14546 /* If section described by INFO was mmapped, munmap it now. */
14549 munmap_section_buffer (struct dwarf2_section_info
*info
)
14551 if (info
->was_mmapped
)
14554 intptr_t begin
= (intptr_t) info
->buffer
;
14555 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14556 size_t map_length
= info
->size
+ begin
- map_begin
;
14558 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14560 /* Without HAVE_MMAP, we should never be here to begin with. */
14561 gdb_assert_not_reached ("no mmap support");
14566 /* munmap debug sections for OBJFILE, if necessary. */
14569 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14571 struct dwarf2_per_objfile
*data
= d
;
14573 /* This is sorted according to the order they're defined in to make it easier
14574 to keep in sync. */
14575 munmap_section_buffer (&data
->info
);
14576 munmap_section_buffer (&data
->abbrev
);
14577 munmap_section_buffer (&data
->line
);
14578 munmap_section_buffer (&data
->loc
);
14579 munmap_section_buffer (&data
->macinfo
);
14580 munmap_section_buffer (&data
->str
);
14581 munmap_section_buffer (&data
->ranges
);
14582 munmap_section_buffer (&data
->types
);
14583 munmap_section_buffer (&data
->frame
);
14584 munmap_section_buffer (&data
->eh_frame
);
14585 munmap_section_buffer (&data
->gdb_index
);
14590 /* The contents of the hash table we create when building the string
14592 struct strtab_entry
14594 offset_type offset
;
14598 /* Hash function for a strtab_entry. */
14600 hash_strtab_entry (const void *e
)
14602 const struct strtab_entry
*entry
= e
;
14603 return mapped_index_string_hash (entry
->str
);
14606 /* Equality function for a strtab_entry. */
14608 eq_strtab_entry (const void *a
, const void *b
)
14610 const struct strtab_entry
*ea
= a
;
14611 const struct strtab_entry
*eb
= b
;
14612 return !strcmp (ea
->str
, eb
->str
);
14615 /* Create a strtab_entry hash table. */
14617 create_strtab (void)
14619 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
14620 xfree
, xcalloc
, xfree
);
14623 /* Add a string to the constant pool. Return the string's offset in
14626 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
14629 struct strtab_entry entry
;
14630 struct strtab_entry
*result
;
14633 slot
= htab_find_slot (table
, &entry
, INSERT
);
14638 result
= XNEW (struct strtab_entry
);
14639 result
->offset
= obstack_object_size (cpool
);
14641 obstack_grow_str0 (cpool
, str
);
14644 return result
->offset
;
14647 /* An entry in the symbol table. */
14648 struct symtab_index_entry
14650 /* The name of the symbol. */
14652 /* The offset of the name in the constant pool. */
14653 offset_type index_offset
;
14654 /* A sorted vector of the indices of all the CUs that hold an object
14656 VEC (offset_type
) *cu_indices
;
14659 /* The symbol table. This is a power-of-2-sized hash table. */
14660 struct mapped_symtab
14662 offset_type n_elements
;
14664 struct symtab_index_entry
**data
;
14667 /* Hash function for a symtab_index_entry. */
14669 hash_symtab_entry (const void *e
)
14671 const struct symtab_index_entry
*entry
= e
;
14672 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
14673 sizeof (offset_type
) * VEC_length (offset_type
,
14674 entry
->cu_indices
),
14678 /* Equality function for a symtab_index_entry. */
14680 eq_symtab_entry (const void *a
, const void *b
)
14682 const struct symtab_index_entry
*ea
= a
;
14683 const struct symtab_index_entry
*eb
= b
;
14684 int len
= VEC_length (offset_type
, ea
->cu_indices
);
14685 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
14687 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
14688 VEC_address (offset_type
, eb
->cu_indices
),
14689 sizeof (offset_type
) * len
);
14692 /* Destroy a symtab_index_entry. */
14694 delete_symtab_entry (void *p
)
14696 struct symtab_index_entry
*entry
= p
;
14697 VEC_free (offset_type
, entry
->cu_indices
);
14701 /* Create a hash table holding symtab_index_entry objects. */
14703 create_index_table (void)
14705 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
14706 delete_symtab_entry
, xcalloc
, xfree
);
14709 /* Create a new mapped symtab object. */
14710 static struct mapped_symtab
*
14711 create_mapped_symtab (void)
14713 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
14714 symtab
->n_elements
= 0;
14715 symtab
->size
= 1024;
14716 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14720 /* Destroy a mapped_symtab. */
14722 cleanup_mapped_symtab (void *p
)
14724 struct mapped_symtab
*symtab
= p
;
14725 /* The contents of the array are freed when the other hash table is
14727 xfree (symtab
->data
);
14731 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
14733 static struct symtab_index_entry
**
14734 find_slot (struct mapped_symtab
*symtab
, const char *name
)
14736 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
14738 index
= hash
& (symtab
->size
- 1);
14739 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
14743 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
14744 return &symtab
->data
[index
];
14745 index
= (index
+ step
) & (symtab
->size
- 1);
14749 /* Expand SYMTAB's hash table. */
14751 hash_expand (struct mapped_symtab
*symtab
)
14753 offset_type old_size
= symtab
->size
;
14755 struct symtab_index_entry
**old_entries
= symtab
->data
;
14758 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14760 for (i
= 0; i
< old_size
; ++i
)
14762 if (old_entries
[i
])
14764 struct symtab_index_entry
**slot
= find_slot (symtab
,
14765 old_entries
[i
]->name
);
14766 *slot
= old_entries
[i
];
14770 xfree (old_entries
);
14773 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
14774 is the index of the CU in which the symbol appears. */
14776 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
14777 offset_type cu_index
)
14779 struct symtab_index_entry
**slot
;
14781 ++symtab
->n_elements
;
14782 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
14783 hash_expand (symtab
);
14785 slot
= find_slot (symtab
, name
);
14788 *slot
= XNEW (struct symtab_index_entry
);
14789 (*slot
)->name
= name
;
14790 (*slot
)->cu_indices
= NULL
;
14792 /* Don't push an index twice. Due to how we add entries we only
14793 have to check the last one. */
14794 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
14795 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
14796 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
14799 /* Add a vector of indices to the constant pool. */
14801 add_indices_to_cpool (htab_t index_table
, struct obstack
*cpool
,
14802 struct symtab_index_entry
*entry
)
14806 slot
= htab_find_slot (index_table
, entry
, INSERT
);
14809 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
14810 offset_type val
= MAYBE_SWAP (len
);
14815 entry
->index_offset
= obstack_object_size (cpool
);
14817 obstack_grow (cpool
, &val
, sizeof (val
));
14819 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
14822 val
= MAYBE_SWAP (iter
);
14823 obstack_grow (cpool
, &val
, sizeof (val
));
14828 struct symtab_index_entry
*old_entry
= *slot
;
14829 entry
->index_offset
= old_entry
->index_offset
;
14832 return entry
->index_offset
;
14835 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
14836 constant pool entries going into the obstack CPOOL. */
14838 write_hash_table (struct mapped_symtab
*symtab
,
14839 struct obstack
*output
, struct obstack
*cpool
)
14842 htab_t index_table
;
14845 index_table
= create_index_table ();
14846 str_table
= create_strtab ();
14847 /* We add all the index vectors to the constant pool first, to
14848 ensure alignment is ok. */
14849 for (i
= 0; i
< symtab
->size
; ++i
)
14851 if (symtab
->data
[i
])
14852 add_indices_to_cpool (index_table
, cpool
, symtab
->data
[i
]);
14855 /* Now write out the hash table. */
14856 for (i
= 0; i
< symtab
->size
; ++i
)
14858 offset_type str_off
, vec_off
;
14860 if (symtab
->data
[i
])
14862 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
14863 vec_off
= symtab
->data
[i
]->index_offset
;
14867 /* While 0 is a valid constant pool index, it is not valid
14868 to have 0 for both offsets. */
14873 str_off
= MAYBE_SWAP (str_off
);
14874 vec_off
= MAYBE_SWAP (vec_off
);
14876 obstack_grow (output
, &str_off
, sizeof (str_off
));
14877 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
14880 htab_delete (str_table
);
14881 htab_delete (index_table
);
14884 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
14885 from PST; CU_INDEX is the index of the CU in the vector of all
14888 add_address_entry (struct objfile
*objfile
,
14889 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
14890 unsigned int cu_index
)
14892 offset_type offset
;
14894 CORE_ADDR baseaddr
;
14896 /* Don't bother recording empty ranges. */
14897 if (pst
->textlow
== pst
->texthigh
)
14900 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14902 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
14903 obstack_grow (addr_obstack
, addr
, 8);
14904 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
14905 obstack_grow (addr_obstack
, addr
, 8);
14906 offset
= MAYBE_SWAP (cu_index
);
14907 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
14910 /* Add a list of partial symbols to SYMTAB. */
14912 write_psymbols (struct mapped_symtab
*symtab
,
14913 struct partial_symbol
**psymp
,
14915 offset_type cu_index
)
14917 for (; count
-- > 0; ++psymp
)
14919 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
14920 error (_("Ada is not currently supported by the index"));
14921 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
14925 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
14926 exception if there is an error. */
14928 write_obstack (FILE *file
, struct obstack
*obstack
)
14930 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
14932 != obstack_object_size (obstack
))
14933 error (_("couldn't data write to file"));
14936 /* Unlink a file if the argument is not NULL. */
14938 unlink_if_set (void *p
)
14940 char **filename
= p
;
14942 unlink (*filename
);
14945 /* A helper struct used when iterating over debug_types. */
14946 struct signatured_type_index_data
14948 struct objfile
*objfile
;
14949 struct mapped_symtab
*symtab
;
14950 struct obstack
*types_list
;
14954 /* A helper function that writes a single signatured_type to an
14957 write_one_signatured_type (void **slot
, void *d
)
14959 struct signatured_type_index_data
*info
= d
;
14960 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
14961 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
14962 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
14965 write_psymbols (info
->symtab
,
14966 info
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
14967 psymtab
->n_global_syms
, info
->cu_index
);
14968 write_psymbols (info
->symtab
,
14969 info
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
14970 psymtab
->n_static_syms
, info
->cu_index
);
14972 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
14973 obstack_grow (info
->types_list
, val
, 8);
14974 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
14975 obstack_grow (info
->types_list
, val
, 8);
14976 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
14977 obstack_grow (info
->types_list
, val
, 8);
14984 /* Create an index file for OBJFILE in the directory DIR. */
14986 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
14988 struct cleanup
*cleanup
;
14989 char *filename
, *cleanup_filename
;
14990 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
14991 struct obstack cu_list
, types_cu_list
;
14994 struct mapped_symtab
*symtab
;
14995 offset_type val
, size_of_contents
, total_len
;
14999 if (!objfile
->psymtabs
)
15001 if (dwarf2_per_objfile
->using_index
)
15002 error (_("Cannot use an index to create the index"));
15004 if (stat (objfile
->name
, &st
) < 0)
15005 perror_with_name (_("Could not stat"));
15007 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15008 INDEX_SUFFIX
, (char *) NULL
);
15009 cleanup
= make_cleanup (xfree
, filename
);
15011 out_file
= fopen (filename
, "wb");
15013 error (_("Can't open `%s' for writing"), filename
);
15015 cleanup_filename
= filename
;
15016 make_cleanup (unlink_if_set
, &cleanup_filename
);
15018 symtab
= create_mapped_symtab ();
15019 make_cleanup (cleanup_mapped_symtab
, symtab
);
15021 obstack_init (&addr_obstack
);
15022 make_cleanup_obstack_free (&addr_obstack
);
15024 obstack_init (&cu_list
);
15025 make_cleanup_obstack_free (&cu_list
);
15027 obstack_init (&types_cu_list
);
15028 make_cleanup_obstack_free (&types_cu_list
);
15030 /* The list is already sorted, so we don't need to do additional
15031 work here. Also, the debug_types entries do not appear in
15032 all_comp_units, but only in their own hash table. */
15033 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15035 struct dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
15036 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15039 write_psymbols (symtab
,
15040 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15041 psymtab
->n_global_syms
, i
);
15042 write_psymbols (symtab
,
15043 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15044 psymtab
->n_static_syms
, i
);
15046 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
15048 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15049 obstack_grow (&cu_list
, val
, 8);
15050 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15051 obstack_grow (&cu_list
, val
, 8);
15054 /* Write out the .debug_type entries, if any. */
15055 if (dwarf2_per_objfile
->signatured_types
)
15057 struct signatured_type_index_data sig_data
;
15059 sig_data
.objfile
= objfile
;
15060 sig_data
.symtab
= symtab
;
15061 sig_data
.types_list
= &types_cu_list
;
15062 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15063 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15064 write_one_signatured_type
, &sig_data
);
15067 obstack_init (&constant_pool
);
15068 make_cleanup_obstack_free (&constant_pool
);
15069 obstack_init (&symtab_obstack
);
15070 make_cleanup_obstack_free (&symtab_obstack
);
15071 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15073 obstack_init (&contents
);
15074 make_cleanup_obstack_free (&contents
);
15075 size_of_contents
= 6 * sizeof (offset_type
);
15076 total_len
= size_of_contents
;
15078 /* The version number. */
15079 val
= MAYBE_SWAP (2);
15080 obstack_grow (&contents
, &val
, sizeof (val
));
15082 /* The offset of the CU list from the start of the file. */
15083 val
= MAYBE_SWAP (total_len
);
15084 obstack_grow (&contents
, &val
, sizeof (val
));
15085 total_len
+= obstack_object_size (&cu_list
);
15087 /* The offset of the types CU list from the start of the file. */
15088 val
= MAYBE_SWAP (total_len
);
15089 obstack_grow (&contents
, &val
, sizeof (val
));
15090 total_len
+= obstack_object_size (&types_cu_list
);
15092 /* The offset of the address table from the start of the file. */
15093 val
= MAYBE_SWAP (total_len
);
15094 obstack_grow (&contents
, &val
, sizeof (val
));
15095 total_len
+= obstack_object_size (&addr_obstack
);
15097 /* The offset of the symbol table from the start of the file. */
15098 val
= MAYBE_SWAP (total_len
);
15099 obstack_grow (&contents
, &val
, sizeof (val
));
15100 total_len
+= obstack_object_size (&symtab_obstack
);
15102 /* The offset of the constant pool from the start of the file. */
15103 val
= MAYBE_SWAP (total_len
);
15104 obstack_grow (&contents
, &val
, sizeof (val
));
15105 total_len
+= obstack_object_size (&constant_pool
);
15107 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15109 write_obstack (out_file
, &contents
);
15110 write_obstack (out_file
, &cu_list
);
15111 write_obstack (out_file
, &types_cu_list
);
15112 write_obstack (out_file
, &addr_obstack
);
15113 write_obstack (out_file
, &symtab_obstack
);
15114 write_obstack (out_file
, &constant_pool
);
15118 /* We want to keep the file, so we set cleanup_filename to NULL
15119 here. See unlink_if_set. */
15120 cleanup_filename
= NULL
;
15122 do_cleanups (cleanup
);
15125 /* The mapped index file format is designed to be directly mmap()able
15126 on any architecture. In most cases, a datum is represented using a
15127 little-endian 32-bit integer value, called an offset_type. Big
15128 endian machines must byte-swap the values before using them.
15129 Exceptions to this rule are noted. The data is laid out such that
15130 alignment is always respected.
15132 A mapped index consists of several sections.
15134 1. The file header. This is a sequence of values, of offset_type
15135 unless otherwise noted:
15136 [0] The version number. Currently 1 or 2. The differences are
15137 noted below. Version 1 did not account for .debug_types sections;
15138 the presence of a .debug_types section invalidates any version 1
15139 index that may exist.
15140 [1] The offset, from the start of the file, of the CU list.
15141 [1.5] In version 2, the offset, from the start of the file, of the
15142 types CU list. This offset does not appear in version 1. Note
15143 that this can be empty, in which case this offset will be equal to
15145 [2] The offset, from the start of the file, of the address section.
15146 [3] The offset, from the start of the file, of the symbol table.
15147 [4] The offset, from the start of the file, of the constant pool.
15149 2. The CU list. This is a sequence of pairs of 64-bit
15150 little-endian values, sorted by the CU offset. The first element
15151 in each pair is the offset of a CU in the .debug_info section. The
15152 second element in each pair is the length of that CU. References
15153 to a CU elsewhere in the map are done using a CU index, which is
15154 just the 0-based index into this table. Note that if there are
15155 type CUs, then conceptually CUs and type CUs form a single list for
15156 the purposes of CU indices.
15158 2.5 The types CU list. This does not appear in a version 1 index.
15159 This is a sequence of triplets of 64-bit little-endian values. In
15160 a triplet, the first value is the CU offset, the second value is
15161 the type offset in the CU, and the third value is the type
15162 signature. The types CU list is not sorted.
15164 3. The address section. The address section consists of a sequence
15165 of address entries. Each address entry has three elements.
15166 [0] The low address. This is a 64-bit little-endian value.
15167 [1] The high address. This is a 64-bit little-endian value.
15168 [2] The CU index. This is an offset_type value.
15170 4. The symbol table. This is a hash table. The size of the hash
15171 table is always a power of 2. The initial hash and the step are
15172 currently defined by the `find_slot' function.
15174 Each slot in the hash table consists of a pair of offset_type
15175 values. The first value is the offset of the symbol's name in the
15176 constant pool. The second value is the offset of the CU vector in
15179 If both values are 0, then this slot in the hash table is empty.
15180 This is ok because while 0 is a valid constant pool index, it
15181 cannot be a valid index for both a string and a CU vector.
15183 A string in the constant pool is stored as a \0-terminated string,
15186 A CU vector in the constant pool is a sequence of offset_type
15187 values. The first value is the number of CU indices in the vector.
15188 Each subsequent value is the index of a CU in the CU list. This
15189 element in the hash table is used to indicate which CUs define the
15192 5. The constant pool. This is simply a bunch of bytes. It is
15193 organized so that alignment is correct: CU vectors are stored
15194 first, followed by strings. */
15196 save_gdb_index_command (char *arg
, int from_tty
)
15198 struct objfile
*objfile
;
15201 error (_("usage: save gdb-index DIRECTORY"));
15203 ALL_OBJFILES (objfile
)
15207 /* If the objfile does not correspond to an actual file, skip it. */
15208 if (stat (objfile
->name
, &st
) < 0)
15211 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15212 if (dwarf2_per_objfile
)
15214 volatile struct gdb_exception except
;
15216 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15218 write_psymtabs_to_index (objfile
, arg
);
15220 if (except
.reason
< 0)
15221 exception_fprintf (gdb_stderr
, except
,
15222 _("Error while writing index for `%s': "),
15230 int dwarf2_always_disassemble
;
15233 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15234 struct cmd_list_element
*c
, const char *value
)
15236 fprintf_filtered (file
, _("\
15237 Whether to always disassemble DWARF expressions is %s.\n"),
15241 void _initialize_dwarf2_read (void);
15244 _initialize_dwarf2_read (void)
15246 struct cmd_list_element
*c
;
15248 dwarf2_objfile_data_key
15249 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15251 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15252 Set DWARF 2 specific variables.\n\
15253 Configure DWARF 2 variables such as the cache size"),
15254 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15255 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15257 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15258 Show DWARF 2 specific variables\n\
15259 Show DWARF 2 variables such as the cache size"),
15260 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15261 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15263 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15264 &dwarf2_max_cache_age
, _("\
15265 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15266 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15267 A higher limit means that cached compilation units will be stored\n\
15268 in memory longer, and more total memory will be used. Zero disables\n\
15269 caching, which can slow down startup."),
15271 show_dwarf2_max_cache_age
,
15272 &set_dwarf2_cmdlist
,
15273 &show_dwarf2_cmdlist
);
15275 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15276 &dwarf2_always_disassemble
, _("\
15277 Set whether `info address' always disassembles DWARF expressions."), _("\
15278 Show whether `info address' always disassembles DWARF expressions."), _("\
15279 When enabled, DWARF expressions are always printed in an assembly-like\n\
15280 syntax. When disabled, expressions will be printed in a more\n\
15281 conversational style, when possible."),
15283 show_dwarf2_always_disassemble
,
15284 &set_dwarf2_cmdlist
,
15285 &show_dwarf2_cmdlist
);
15287 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15288 Set debugging of the dwarf2 DIE reader."), _("\
15289 Show debugging of the dwarf2 DIE reader."), _("\
15290 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15291 The value is the maximum depth to print."),
15294 &setdebuglist
, &showdebuglist
);
15296 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15297 _("Save a .gdb-index file"),
15299 set_cmd_completer (c
, filename_completer
);