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. */
673 struct die_info
*child
; /* Its first child, if any. */
674 struct die_info
*sibling
; /* Its next sibling, if any. */
675 struct die_info
*parent
; /* Its parent, if any. */
677 /* An array of attributes, with NUM_ATTRS elements. There may be
678 zero, but it's not common and zero-sized arrays are not
679 sufficiently portable C. */
680 struct attribute attrs
[1];
683 struct function_range
686 CORE_ADDR lowpc
, highpc
;
688 struct function_range
*next
;
691 /* Get at parts of an attribute structure */
693 #define DW_STRING(attr) ((attr)->u.str)
694 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
695 #define DW_UNSND(attr) ((attr)->u.unsnd)
696 #define DW_BLOCK(attr) ((attr)->u.blk)
697 #define DW_SND(attr) ((attr)->u.snd)
698 #define DW_ADDR(attr) ((attr)->u.addr)
699 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
701 /* Blocks are a bunch of untyped bytes. */
708 #ifndef ATTR_ALLOC_CHUNK
709 #define ATTR_ALLOC_CHUNK 4
712 /* Allocate fields for structs, unions and enums in this size. */
713 #ifndef DW_FIELD_ALLOC_CHUNK
714 #define DW_FIELD_ALLOC_CHUNK 4
717 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
718 but this would require a corresponding change in unpack_field_as_long
720 static int bits_per_byte
= 8;
722 /* The routines that read and process dies for a C struct or C++ class
723 pass lists of data member fields and lists of member function fields
724 in an instance of a field_info structure, as defined below. */
727 /* List of data member and baseclasses fields. */
730 struct nextfield
*next
;
735 *fields
, *baseclasses
;
737 /* Number of fields (including baseclasses). */
740 /* Number of baseclasses. */
743 /* Set if the accesibility of one of the fields is not public. */
744 int non_public_fields
;
746 /* Member function fields array, entries are allocated in the order they
747 are encountered in the object file. */
750 struct nextfnfield
*next
;
751 struct fn_field fnfield
;
755 /* Member function fieldlist array, contains name of possibly overloaded
756 member function, number of overloaded member functions and a pointer
757 to the head of the member function field chain. */
762 struct nextfnfield
*head
;
766 /* Number of entries in the fnfieldlists array. */
769 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
770 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
771 struct typedef_field_list
773 struct typedef_field field
;
774 struct typedef_field_list
*next
;
777 unsigned typedef_field_list_count
;
780 /* One item on the queue of compilation units to read in full symbols
782 struct dwarf2_queue_item
784 struct dwarf2_per_cu_data
*per_cu
;
785 struct dwarf2_queue_item
*next
;
788 /* The current queue. */
789 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
791 /* Loaded secondary compilation units are kept in memory until they
792 have not been referenced for the processing of this many
793 compilation units. Set this to zero to disable caching. Cache
794 sizes of up to at least twenty will improve startup time for
795 typical inter-CU-reference binaries, at an obvious memory cost. */
796 static int dwarf2_max_cache_age
= 5;
798 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
799 struct cmd_list_element
*c
, const char *value
)
801 fprintf_filtered (file
, _("\
802 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
807 /* Various complaints about symbol reading that don't abort the process */
810 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
812 complaint (&symfile_complaints
,
813 _("statement list doesn't fit in .debug_line section"));
817 dwarf2_debug_line_missing_file_complaint (void)
819 complaint (&symfile_complaints
,
820 _(".debug_line section has line data without a file"));
824 dwarf2_debug_line_missing_end_sequence_complaint (void)
826 complaint (&symfile_complaints
,
827 _(".debug_line section has line program sequence without an end"));
831 dwarf2_complex_location_expr_complaint (void)
833 complaint (&symfile_complaints
, _("location expression too complex"));
837 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
840 complaint (&symfile_complaints
,
841 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
846 dwarf2_macros_too_long_complaint (void)
848 complaint (&symfile_complaints
,
849 _("macro info runs off end of `.debug_macinfo' section"));
853 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
855 complaint (&symfile_complaints
,
856 _("macro debug info contains a malformed macro definition:\n`%s'"),
861 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
863 complaint (&symfile_complaints
,
864 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
867 /* local function prototypes */
869 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
871 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
874 static void dwarf2_build_psymtabs_hard (struct objfile
*);
876 static void scan_partial_symbols (struct partial_die_info
*,
877 CORE_ADDR
*, CORE_ADDR
*,
878 int, struct dwarf2_cu
*);
880 static void add_partial_symbol (struct partial_die_info
*,
883 static void add_partial_namespace (struct partial_die_info
*pdi
,
884 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
885 int need_pc
, struct dwarf2_cu
*cu
);
887 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
888 CORE_ADDR
*highpc
, int need_pc
,
889 struct dwarf2_cu
*cu
);
891 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
892 struct dwarf2_cu
*cu
);
894 static void add_partial_subprogram (struct partial_die_info
*pdi
,
895 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
896 int need_pc
, struct dwarf2_cu
*cu
);
898 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
899 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
900 bfd
*abfd
, struct dwarf2_cu
*cu
);
902 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
904 static void psymtab_to_symtab_1 (struct partial_symtab
*);
906 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
908 static void dwarf2_free_abbrev_table (void *);
910 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
913 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
916 static struct partial_die_info
*load_partial_dies (bfd
*,
917 gdb_byte
*, gdb_byte
*,
918 int, struct dwarf2_cu
*);
920 static gdb_byte
*read_partial_die (struct partial_die_info
*,
921 struct abbrev_info
*abbrev
,
923 gdb_byte
*, gdb_byte
*,
926 static struct partial_die_info
*find_partial_die (unsigned int,
929 static void fixup_partial_die (struct partial_die_info
*,
932 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
933 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
935 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
936 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
938 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
940 static int read_1_signed_byte (bfd
*, gdb_byte
*);
942 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
944 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
946 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
948 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
951 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
953 static LONGEST read_checked_initial_length_and_offset
954 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
955 unsigned int *, unsigned int *);
957 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
960 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
962 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
964 static char *read_direct_string (bfd
*, gdb_byte
*, unsigned int *);
966 static char *read_indirect_string (bfd
*, gdb_byte
*,
967 const struct comp_unit_head
*,
970 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
972 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
974 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
976 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
978 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
981 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
985 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
986 struct dwarf2_cu
*cu
);
988 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
990 static struct die_info
*die_specification (struct die_info
*die
,
991 struct dwarf2_cu
**);
993 static void free_line_header (struct line_header
*lh
);
995 static void add_file_name (struct line_header
*, char *, unsigned int,
996 unsigned int, unsigned int);
998 static struct line_header
*(dwarf_decode_line_header
999 (unsigned int offset
,
1000 bfd
*abfd
, struct dwarf2_cu
*cu
));
1002 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
1003 struct dwarf2_cu
*, struct partial_symtab
*);
1005 static void dwarf2_start_subfile (char *, char *, char *);
1007 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
1008 struct dwarf2_cu
*);
1010 static struct symbol
*new_symbol_full (struct die_info
*, struct type
*,
1011 struct dwarf2_cu
*, struct symbol
*);
1013 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
1014 struct dwarf2_cu
*);
1016 static void dwarf2_const_value_attr (struct attribute
*attr
,
1019 struct obstack
*obstack
,
1020 struct dwarf2_cu
*cu
, long *value
,
1022 struct dwarf2_locexpr_baton
**baton
);
1024 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
1026 static int need_gnat_info (struct dwarf2_cu
*);
1028 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
1030 static void set_descriptive_type (struct type
*, struct die_info
*,
1031 struct dwarf2_cu
*);
1033 static struct type
*die_containing_type (struct die_info
*,
1034 struct dwarf2_cu
*);
1036 static struct type
*lookup_die_type (struct die_info
*, struct attribute
*,
1037 struct dwarf2_cu
*);
1039 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
1041 static struct type
*read_type_die_1 (struct die_info
*, struct dwarf2_cu
*);
1043 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
1045 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
1046 const char *suffix
, int physname
,
1047 struct dwarf2_cu
*cu
);
1049 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
1051 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1053 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1055 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1057 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1058 struct dwarf2_cu
*, struct partial_symtab
*);
1060 static int dwarf2_get_pc_bounds (struct die_info
*,
1061 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1062 struct partial_symtab
*);
1064 static void get_scope_pc_bounds (struct die_info
*,
1065 CORE_ADDR
*, CORE_ADDR
*,
1066 struct dwarf2_cu
*);
1068 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1069 CORE_ADDR
, struct dwarf2_cu
*);
1071 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1072 struct dwarf2_cu
*);
1074 static void dwarf2_attach_fields_to_type (struct field_info
*,
1075 struct type
*, struct dwarf2_cu
*);
1077 static void dwarf2_add_member_fn (struct field_info
*,
1078 struct die_info
*, struct type
*,
1079 struct dwarf2_cu
*);
1081 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1082 struct type
*, struct dwarf2_cu
*);
1084 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1086 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1088 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1090 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1092 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1094 static struct type
*read_module_type (struct die_info
*die
,
1095 struct dwarf2_cu
*cu
);
1097 static const char *namespace_name (struct die_info
*die
,
1098 int *is_anonymous
, struct dwarf2_cu
*);
1100 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1102 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1104 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1105 struct dwarf2_cu
*);
1107 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1109 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1111 gdb_byte
**new_info_ptr
,
1112 struct die_info
*parent
);
1114 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1116 gdb_byte
**new_info_ptr
,
1117 struct die_info
*parent
);
1119 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1121 gdb_byte
**new_info_ptr
,
1122 struct die_info
*parent
);
1124 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1125 struct die_info
**, gdb_byte
*,
1128 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1130 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1133 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1135 static const char *dwarf2_full_name (char *name
,
1136 struct die_info
*die
,
1137 struct dwarf2_cu
*cu
);
1139 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1140 struct dwarf2_cu
**);
1142 static char *dwarf_tag_name (unsigned int);
1144 static char *dwarf_attr_name (unsigned int);
1146 static char *dwarf_form_name (unsigned int);
1148 static char *dwarf_bool_name (unsigned int);
1150 static char *dwarf_type_encoding_name (unsigned int);
1153 static char *dwarf_cfi_name (unsigned int);
1156 static struct die_info
*sibling_die (struct die_info
*);
1158 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1160 static void dump_die_for_error (struct die_info
*);
1162 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1165 /*static*/ void dump_die (struct die_info
*, int max_level
);
1167 static void store_in_ref_table (struct die_info
*,
1168 struct dwarf2_cu
*);
1170 static int is_ref_attr (struct attribute
*);
1172 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1174 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1176 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1178 struct dwarf2_cu
**);
1180 static struct die_info
*follow_die_ref (struct die_info
*,
1182 struct dwarf2_cu
**);
1184 static struct die_info
*follow_die_sig (struct die_info
*,
1186 struct dwarf2_cu
**);
1188 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1189 unsigned int offset
);
1191 static void read_signatured_type (struct objfile
*,
1192 struct signatured_type
*type_sig
);
1194 /* memory allocation interface */
1196 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1198 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1200 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1202 static void initialize_cu_func_list (struct dwarf2_cu
*);
1204 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1205 struct dwarf2_cu
*);
1207 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1208 char *, bfd
*, struct dwarf2_cu
*);
1210 static int attr_form_is_block (struct attribute
*);
1212 static int attr_form_is_section_offset (struct attribute
*);
1214 static int attr_form_is_constant (struct attribute
*);
1216 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1218 struct dwarf2_cu
*cu
);
1220 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1221 struct abbrev_info
*abbrev
,
1222 struct dwarf2_cu
*cu
);
1224 static void free_stack_comp_unit (void *);
1226 static hashval_t
partial_die_hash (const void *item
);
1228 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1230 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1231 (unsigned int offset
, struct objfile
*objfile
);
1233 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1234 (unsigned int offset
, struct objfile
*objfile
);
1236 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1238 static void free_one_comp_unit (void *);
1240 static void free_cached_comp_units (void *);
1242 static void age_cached_comp_units (void);
1244 static void free_one_cached_comp_unit (void *);
1246 static struct type
*set_die_type (struct die_info
*, struct type
*,
1247 struct dwarf2_cu
*);
1249 static void create_all_comp_units (struct objfile
*);
1251 static int create_debug_types_hash_table (struct objfile
*objfile
);
1253 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1256 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1258 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1259 struct dwarf2_per_cu_data
*);
1261 static void dwarf2_mark (struct dwarf2_cu
*);
1263 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1265 static struct type
*get_die_type_at_offset (unsigned int,
1266 struct dwarf2_per_cu_data
*per_cu
);
1268 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1270 static void dwarf2_release_queue (void *dummy
);
1272 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1273 struct objfile
*objfile
);
1275 static void process_queue (struct objfile
*objfile
);
1277 static void find_file_and_directory (struct die_info
*die
,
1278 struct dwarf2_cu
*cu
,
1279 char **name
, char **comp_dir
);
1281 static char *file_full_name (int file
, struct line_header
*lh
,
1282 const char *comp_dir
);
1284 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1287 unsigned int buffer_size
,
1290 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1291 struct dwarf2_cu
*cu
);
1293 static htab_t
allocate_signatured_type_table (struct objfile
*objfile
);
1297 /* Convert VALUE between big- and little-endian. */
1299 byte_swap (offset_type value
)
1303 result
= (value
& 0xff) << 24;
1304 result
|= (value
& 0xff00) << 8;
1305 result
|= (value
& 0xff0000) >> 8;
1306 result
|= (value
& 0xff000000) >> 24;
1310 #define MAYBE_SWAP(V) byte_swap (V)
1313 #define MAYBE_SWAP(V) (V)
1314 #endif /* WORDS_BIGENDIAN */
1316 /* The suffix for an index file. */
1317 #define INDEX_SUFFIX ".gdb-index"
1319 static const char *dwarf2_physname (char *name
, struct die_info
*die
,
1320 struct dwarf2_cu
*cu
);
1322 /* Try to locate the sections we need for DWARF 2 debugging
1323 information and return true if we have enough to do something. */
1326 dwarf2_has_info (struct objfile
*objfile
)
1328 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1329 if (!dwarf2_per_objfile
)
1331 /* Initialize per-objfile state. */
1332 struct dwarf2_per_objfile
*data
1333 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1335 memset (data
, 0, sizeof (*data
));
1336 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1337 dwarf2_per_objfile
= data
;
1339 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1340 dwarf2_per_objfile
->objfile
= objfile
;
1342 return (dwarf2_per_objfile
->info
.asection
!= NULL
1343 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1346 /* When loading sections, we can either look for ".<name>", or for
1347 * ".z<name>", which indicates a compressed section. */
1350 section_is_p (const char *section_name
, const char *name
)
1352 return (section_name
[0] == '.'
1353 && (strcmp (section_name
+ 1, name
) == 0
1354 || (section_name
[1] == 'z'
1355 && strcmp (section_name
+ 2, name
) == 0)));
1358 /* This function is mapped across the sections and remembers the
1359 offset and size of each of the debugging sections we are interested
1363 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1365 if (section_is_p (sectp
->name
, INFO_SECTION
))
1367 dwarf2_per_objfile
->info
.asection
= sectp
;
1368 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1370 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1372 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1373 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1375 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1377 dwarf2_per_objfile
->line
.asection
= sectp
;
1378 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1380 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1382 dwarf2_per_objfile
->loc
.asection
= sectp
;
1383 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1385 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1387 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1388 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1390 else if (section_is_p (sectp
->name
, STR_SECTION
))
1392 dwarf2_per_objfile
->str
.asection
= sectp
;
1393 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1395 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1397 dwarf2_per_objfile
->frame
.asection
= sectp
;
1398 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1400 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1402 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1404 if (aflag
& SEC_HAS_CONTENTS
)
1406 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1407 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1410 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1412 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1413 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1415 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1417 dwarf2_per_objfile
->types
.asection
= sectp
;
1418 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1420 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1422 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1423 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1426 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1427 && bfd_section_vma (abfd
, sectp
) == 0)
1428 dwarf2_per_objfile
->has_section_at_zero
= 1;
1431 /* Decompress a section that was compressed using zlib. Store the
1432 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1435 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1436 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1438 bfd
*abfd
= objfile
->obfd
;
1440 error (_("Support for zlib-compressed DWARF data (from '%s') "
1441 "is disabled in this copy of GDB"),
1442 bfd_get_filename (abfd
));
1444 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1445 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1446 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1447 bfd_size_type uncompressed_size
;
1448 gdb_byte
*uncompressed_buffer
;
1451 int header_size
= 12;
1453 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1454 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1455 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1456 bfd_get_filename (abfd
));
1458 /* Read the zlib header. In this case, it should be "ZLIB" followed
1459 by the uncompressed section size, 8 bytes in big-endian order. */
1460 if (compressed_size
< header_size
1461 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1462 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1463 bfd_get_filename (abfd
));
1464 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1465 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1466 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1467 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1468 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1469 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1470 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1471 uncompressed_size
+= compressed_buffer
[11];
1473 /* It is possible the section consists of several compressed
1474 buffers concatenated together, so we uncompress in a loop. */
1478 strm
.avail_in
= compressed_size
- header_size
;
1479 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1480 strm
.avail_out
= uncompressed_size
;
1481 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1483 rc
= inflateInit (&strm
);
1484 while (strm
.avail_in
> 0)
1487 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1488 bfd_get_filename (abfd
), rc
);
1489 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1490 + (uncompressed_size
- strm
.avail_out
));
1491 rc
= inflate (&strm
, Z_FINISH
);
1492 if (rc
!= Z_STREAM_END
)
1493 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1494 bfd_get_filename (abfd
), rc
);
1495 rc
= inflateReset (&strm
);
1497 rc
= inflateEnd (&strm
);
1499 || strm
.avail_out
!= 0)
1500 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1501 bfd_get_filename (abfd
), rc
);
1503 do_cleanups (cleanup
);
1504 *outbuf
= uncompressed_buffer
;
1505 *outsize
= uncompressed_size
;
1509 /* Read the contents of the section SECTP from object file specified by
1510 OBJFILE, store info about the section into INFO.
1511 If the section is compressed, uncompress it before returning. */
1514 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1516 bfd
*abfd
= objfile
->obfd
;
1517 asection
*sectp
= info
->asection
;
1518 gdb_byte
*buf
, *retbuf
;
1519 unsigned char header
[4];
1523 info
->buffer
= NULL
;
1524 info
->was_mmapped
= 0;
1527 if (info
->asection
== NULL
|| info
->size
== 0)
1530 /* Check if the file has a 4-byte header indicating compression. */
1531 if (info
->size
> sizeof (header
)
1532 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1533 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1535 /* Upon decompression, update the buffer and its size. */
1536 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1538 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1546 pagesize
= getpagesize ();
1548 /* Only try to mmap sections which are large enough: we don't want to
1549 waste space due to fragmentation. Also, only try mmap for sections
1550 without relocations. */
1552 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1554 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1555 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1556 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1557 MAP_PRIVATE
, pg_offset
);
1559 if (retbuf
!= MAP_FAILED
)
1561 info
->was_mmapped
= 1;
1562 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1563 #if HAVE_POSIX_MADVISE
1564 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1571 /* If we get here, we are a normal, not-compressed section. */
1573 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1575 /* When debugging .o files, we may need to apply relocations; see
1576 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1577 We never compress sections in .o files, so we only need to
1578 try this when the section is not compressed. */
1579 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1582 info
->buffer
= retbuf
;
1586 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1587 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1588 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1589 bfd_get_filename (abfd
));
1592 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1596 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1597 asection
**sectp
, gdb_byte
**bufp
,
1598 bfd_size_type
*sizep
)
1600 struct dwarf2_per_objfile
*data
1601 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1602 struct dwarf2_section_info
*info
;
1604 /* We may see an objfile without any DWARF, in which case we just
1613 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1614 info
= &data
->eh_frame
;
1615 else if (section_is_p (section_name
, FRAME_SECTION
))
1616 info
= &data
->frame
;
1618 gdb_assert_not_reached ("unexpected section");
1620 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1621 /* We haven't read this section in yet. Do it now. */
1622 dwarf2_read_section (objfile
, info
);
1624 *sectp
= info
->asection
;
1625 *bufp
= info
->buffer
;
1626 *sizep
= info
->size
;
1631 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1634 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1635 struct dwarf2_per_cu_data
*per_cu
)
1637 struct cleanup
*back_to
;
1639 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1641 queue_comp_unit (per_cu
, objfile
);
1643 if (per_cu
->from_debug_types
)
1644 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1646 load_full_comp_unit (per_cu
, objfile
);
1648 process_queue (objfile
);
1650 /* Age the cache, releasing compilation units that have not
1651 been used recently. */
1652 age_cached_comp_units ();
1654 do_cleanups (back_to
);
1657 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1658 the objfile from which this CU came. Returns the resulting symbol
1660 static struct symtab
*
1661 dw2_instantiate_symtab (struct objfile
*objfile
,
1662 struct dwarf2_per_cu_data
*per_cu
)
1664 if (!per_cu
->v
.quick
->symtab
)
1666 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1667 increment_reading_symtab ();
1668 dw2_do_instantiate_symtab (objfile
, per_cu
);
1669 do_cleanups (back_to
);
1671 return per_cu
->v
.quick
->symtab
;
1674 /* Return the CU given its index. */
1675 static struct dwarf2_per_cu_data
*
1676 dw2_get_cu (int index
)
1678 if (index
>= dwarf2_per_objfile
->n_comp_units
)
1680 index
-= dwarf2_per_objfile
->n_comp_units
;
1681 return dwarf2_per_objfile
->type_comp_units
[index
];
1683 return dwarf2_per_objfile
->all_comp_units
[index
];
1686 /* A helper function that knows how to read a 64-bit value in a way
1687 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1690 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1692 if (sizeof (ULONGEST
) < 8)
1696 /* Ignore the upper 4 bytes if they are all zero. */
1697 for (i
= 0; i
< 4; ++i
)
1698 if (bytes
[i
+ 4] != 0)
1701 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1704 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1708 /* Read the CU list from the mapped index, and use it to create all
1709 the CU objects for this objfile. Return 0 if something went wrong,
1710 1 if everything went ok. */
1712 create_cus_from_index (struct objfile
*objfile
, const gdb_byte
*cu_list
,
1713 offset_type cu_list_elements
)
1717 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1718 dwarf2_per_objfile
->all_comp_units
1719 = obstack_alloc (&objfile
->objfile_obstack
,
1720 dwarf2_per_objfile
->n_comp_units
1721 * sizeof (struct dwarf2_per_cu_data
*));
1723 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1725 struct dwarf2_per_cu_data
*the_cu
;
1726 ULONGEST offset
, length
;
1728 if (!extract_cu_value (cu_list
, &offset
)
1729 || !extract_cu_value (cu_list
+ 8, &length
))
1733 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1734 struct dwarf2_per_cu_data
);
1735 the_cu
->offset
= offset
;
1736 the_cu
->length
= length
;
1737 the_cu
->objfile
= objfile
;
1738 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1739 struct dwarf2_per_cu_quick_data
);
1740 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1746 /* Create the signatured type hash table from the index. */
1749 create_signatured_type_table_from_index (struct objfile
*objfile
,
1750 const gdb_byte
*bytes
,
1751 offset_type elements
)
1754 htab_t sig_types_hash
;
1756 dwarf2_per_objfile
->n_type_comp_units
= elements
/ 3;
1757 dwarf2_per_objfile
->type_comp_units
1758 = obstack_alloc (&objfile
->objfile_obstack
,
1759 dwarf2_per_objfile
->n_type_comp_units
1760 * sizeof (struct dwarf2_per_cu_data
*));
1762 sig_types_hash
= allocate_signatured_type_table (objfile
);
1764 for (i
= 0; i
< elements
; i
+= 3)
1766 struct signatured_type
*type_sig
;
1767 ULONGEST offset
, type_offset
, signature
;
1770 if (!extract_cu_value (bytes
, &offset
)
1771 || !extract_cu_value (bytes
+ 8, &type_offset
))
1773 signature
= extract_unsigned_integer (bytes
+ 16, 8, BFD_ENDIAN_LITTLE
);
1776 type_sig
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1777 struct signatured_type
);
1778 type_sig
->signature
= signature
;
1779 type_sig
->offset
= offset
;
1780 type_sig
->type_offset
= type_offset
;
1781 type_sig
->per_cu
.from_debug_types
= 1;
1782 type_sig
->per_cu
.offset
= offset
;
1783 type_sig
->per_cu
.objfile
= objfile
;
1784 type_sig
->per_cu
.v
.quick
1785 = OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1786 struct dwarf2_per_cu_quick_data
);
1788 slot
= htab_find_slot (sig_types_hash
, type_sig
, INSERT
);
1791 dwarf2_per_objfile
->type_comp_units
[i
/ 3] = &type_sig
->per_cu
;
1794 dwarf2_per_objfile
->signatured_types
= sig_types_hash
;
1799 /* Read the address map data from the mapped index, and use it to
1800 populate the objfile's psymtabs_addrmap. */
1802 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1804 const gdb_byte
*iter
, *end
;
1805 struct obstack temp_obstack
;
1806 struct addrmap
*mutable_map
;
1807 struct cleanup
*cleanup
;
1810 obstack_init (&temp_obstack
);
1811 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1812 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1814 iter
= index
->address_table
;
1815 end
= iter
+ index
->address_table_size
;
1817 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1821 ULONGEST hi
, lo
, cu_index
;
1822 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1824 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1826 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1829 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1830 dw2_get_cu (cu_index
));
1833 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1834 &objfile
->objfile_obstack
);
1835 do_cleanups (cleanup
);
1838 /* The hash function for strings in the mapped index. This is the
1839 same as the hashtab.c hash function, but we keep a separate copy to
1840 maintain control over the implementation. This is necessary
1841 because the hash function is tied to the format of the mapped index
1844 mapped_index_string_hash (const void *p
)
1846 const unsigned char *str
= (const unsigned char *) p
;
1850 while ((c
= *str
++) != 0)
1851 r
= r
* 67 + c
- 113;
1856 /* Find a slot in the mapped index INDEX for the object named NAME.
1857 If NAME is found, set *VEC_OUT to point to the CU vector in the
1858 constant pool and return 1. If NAME cannot be found, return 0. */
1860 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1861 offset_type
**vec_out
)
1863 offset_type hash
= mapped_index_string_hash (name
);
1864 offset_type slot
, step
;
1866 slot
= hash
& (index
->index_table_slots
- 1);
1867 step
= ((hash
* 17) & (index
->index_table_slots
- 1)) | 1;
1871 /* Convert a slot number to an offset into the table. */
1872 offset_type i
= 2 * slot
;
1874 if (index
->index_table
[i
] == 0 && index
->index_table
[i
+ 1] == 0)
1877 str
= index
->constant_pool
+ MAYBE_SWAP (index
->index_table
[i
]);
1878 if (!strcmp (name
, str
))
1880 *vec_out
= (offset_type
*) (index
->constant_pool
1881 + MAYBE_SWAP (index
->index_table
[i
+ 1]));
1885 slot
= (slot
+ step
) & (index
->index_table_slots
- 1);
1889 /* Read the index file. If everything went ok, initialize the "quick"
1890 elements of all the CUs and return 1. Otherwise, return 0. */
1892 dwarf2_read_index (struct objfile
*objfile
)
1895 struct mapped_index
*map
;
1896 offset_type
*metadata
;
1897 const gdb_byte
*cu_list
;
1898 const gdb_byte
*types_list
= NULL
;
1899 offset_type version
, cu_list_elements
;
1900 offset_type types_list_elements
= 0;
1903 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1904 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1907 /* Older elfutils strip versions could keep the section in the main
1908 executable while splitting it for the separate debug info file. */
1909 if ((bfd_get_file_flags (dwarf2_per_objfile
->gdb_index
.asection
)
1910 & SEC_HAS_CONTENTS
) == 0)
1913 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1915 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1916 /* Version check. */
1917 version
= MAYBE_SWAP (*(offset_type
*) addr
);
1920 /* Index version 1 neglected to account for .debug_types. So,
1921 if we see .debug_types, we cannot use this index. */
1922 if (dwarf2_per_objfile
->types
.asection
!= NULL
1923 && dwarf2_per_objfile
->types
.size
!= 0)
1926 else if (version
!= 2)
1929 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1930 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
1932 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1935 cu_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1936 cu_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1]) - MAYBE_SWAP (metadata
[i
]))
1942 types_list
= addr
+ MAYBE_SWAP (metadata
[i
]);
1943 types_list_elements
= ((MAYBE_SWAP (metadata
[i
+ 1])
1944 - MAYBE_SWAP (metadata
[i
]))
1949 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[i
]);
1950 map
->address_table_size
= (MAYBE_SWAP (metadata
[i
+ 1])
1951 - MAYBE_SWAP (metadata
[i
]));
1954 map
->index_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[i
]));
1955 map
->index_table_slots
= ((MAYBE_SWAP (metadata
[i
+ 1])
1956 - MAYBE_SWAP (metadata
[i
]))
1957 / (2 * sizeof (offset_type
)));
1960 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[i
]);
1962 if (!create_cus_from_index (objfile
, cu_list
, cu_list_elements
))
1966 && types_list_elements
1967 && !create_signatured_type_table_from_index (objfile
, types_list
,
1968 types_list_elements
))
1971 create_addrmap_from_index (objfile
, map
);
1973 dwarf2_per_objfile
->index_table
= map
;
1974 dwarf2_per_objfile
->using_index
= 1;
1979 /* A helper for the "quick" functions which sets the global
1980 dwarf2_per_objfile according to OBJFILE. */
1982 dw2_setup (struct objfile
*objfile
)
1984 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1985 gdb_assert (dwarf2_per_objfile
);
1988 /* A helper for the "quick" functions which attempts to read the line
1989 table for THIS_CU. */
1991 dw2_require_line_header (struct objfile
*objfile
,
1992 struct dwarf2_per_cu_data
*this_cu
)
1994 bfd
*abfd
= objfile
->obfd
;
1995 struct line_header
*lh
= NULL
;
1996 struct attribute
*attr
;
1997 struct cleanup
*cleanups
;
1998 struct die_info
*comp_unit_die
;
1999 struct dwarf2_section_info
* sec
;
2000 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
2001 int has_children
, i
;
2002 struct dwarf2_cu cu
;
2003 unsigned int bytes_read
, buffer_size
;
2004 struct die_reader_specs reader_specs
;
2005 char *name
, *comp_dir
;
2007 if (this_cu
->v
.quick
->read_lines
)
2009 this_cu
->v
.quick
->read_lines
= 1;
2011 memset (&cu
, 0, sizeof (cu
));
2012 cu
.objfile
= objfile
;
2013 obstack_init (&cu
.comp_unit_obstack
);
2015 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
2017 if (this_cu
->from_debug_types
)
2018 sec
= &dwarf2_per_objfile
->types
;
2020 sec
= &dwarf2_per_objfile
->info
;
2021 dwarf2_read_section (objfile
, sec
);
2022 buffer_size
= sec
->size
;
2023 buffer
= sec
->buffer
;
2024 info_ptr
= buffer
+ this_cu
->offset
;
2025 beg_of_comp_unit
= info_ptr
;
2027 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2028 buffer
, buffer_size
,
2031 /* Complete the cu_header. */
2032 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2033 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2036 cu
.per_cu
= this_cu
;
2038 dwarf2_read_abbrevs (abfd
, &cu
);
2039 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2041 if (this_cu
->from_debug_types
)
2042 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2043 init_cu_die_reader (&reader_specs
, &cu
);
2044 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2047 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
2050 unsigned int line_offset
= DW_UNSND (attr
);
2051 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
2055 do_cleanups (cleanups
);
2059 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
2061 this_cu
->v
.quick
->lines
= lh
;
2063 this_cu
->v
.quick
->file_names
2064 = obstack_alloc (&objfile
->objfile_obstack
,
2065 lh
->num_file_names
* sizeof (char *));
2066 for (i
= 0; i
< lh
->num_file_names
; ++i
)
2067 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
2069 do_cleanups (cleanups
);
2072 /* A helper for the "quick" functions which computes and caches the
2073 real path for a given file name from the line table.
2074 dw2_require_line_header must have been called before this is
2077 dw2_require_full_path (struct objfile
*objfile
,
2078 struct dwarf2_per_cu_data
*per_cu
,
2081 if (!per_cu
->v
.quick
->full_names
)
2082 per_cu
->v
.quick
->full_names
2083 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2084 per_cu
->v
.quick
->lines
->num_file_names
,
2087 if (!per_cu
->v
.quick
->full_names
[index
])
2088 per_cu
->v
.quick
->full_names
[index
]
2089 = gdb_realpath (per_cu
->v
.quick
->file_names
[index
]);
2091 return per_cu
->v
.quick
->full_names
[index
];
2094 static struct symtab
*
2095 dw2_find_last_source_symtab (struct objfile
*objfile
)
2098 dw2_setup (objfile
);
2099 index
= dwarf2_per_objfile
->n_comp_units
- 1;
2100 return dw2_instantiate_symtab (objfile
, dw2_get_cu (index
));
2104 dw2_forget_cached_source_info (struct objfile
*objfile
)
2108 dw2_setup (objfile
);
2109 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2110 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2112 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2114 if (per_cu
->v
.quick
->full_names
)
2118 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2119 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
2125 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
2126 const char *full_path
, const char *real_path
,
2127 struct symtab
**result
)
2130 int check_basename
= lbasename (name
) == name
;
2131 struct dwarf2_per_cu_data
*base_cu
= NULL
;
2133 dw2_setup (objfile
);
2134 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2135 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2138 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2140 if (per_cu
->v
.quick
->symtab
)
2143 dw2_require_line_header (objfile
, per_cu
);
2144 if (!per_cu
->v
.quick
->lines
)
2147 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2149 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2151 if (FILENAME_CMP (name
, this_name
) == 0)
2153 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2157 if (check_basename
&& ! base_cu
2158 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
2161 if (full_path
!= NULL
)
2163 const char *this_full_name
= dw2_require_full_path (objfile
,
2167 && FILENAME_CMP (full_path
, this_full_name
) == 0)
2169 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2174 if (real_path
!= NULL
)
2176 const char *this_full_name
= dw2_require_full_path (objfile
,
2179 if (this_full_name
!= NULL
)
2181 char *rp
= gdb_realpath (this_full_name
);
2182 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
2185 *result
= dw2_instantiate_symtab (objfile
, per_cu
);
2196 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2203 static struct symtab
*
2204 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2205 const char *name
, domain_enum domain
)
2207 /* We do all the work in the pre_expand_symtabs_matching hook
2212 /* A helper function that expands all symtabs that hold an object
2215 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2217 dw2_setup (objfile
);
2219 if (dwarf2_per_objfile
->index_table
)
2223 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2226 offset_type i
, len
= MAYBE_SWAP (*vec
);
2227 for (i
= 0; i
< len
; ++i
)
2229 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2230 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (cu_index
);
2232 dw2_instantiate_symtab (objfile
, per_cu
);
2239 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2240 int kind
, const char *name
,
2243 dw2_do_expand_symtabs_matching (objfile
, name
);
2247 dw2_print_stats (struct objfile
*objfile
)
2251 dw2_setup (objfile
);
2253 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2254 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2256 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2258 if (!per_cu
->v
.quick
->symtab
)
2261 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2265 dw2_dump (struct objfile
*objfile
)
2267 /* Nothing worth printing. */
2271 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2272 struct section_offsets
*delta
)
2274 /* There's nothing to relocate here. */
2278 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2279 const char *func_name
)
2281 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2285 dw2_expand_all_symtabs (struct objfile
*objfile
)
2289 dw2_setup (objfile
);
2291 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2292 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2294 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2296 dw2_instantiate_symtab (objfile
, per_cu
);
2301 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2302 const char *filename
)
2306 dw2_setup (objfile
);
2307 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2308 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2311 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2313 if (per_cu
->v
.quick
->symtab
)
2316 dw2_require_line_header (objfile
, per_cu
);
2317 if (!per_cu
->v
.quick
->lines
)
2320 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2322 const char *this_name
= per_cu
->v
.quick
->file_names
[j
];
2323 if (strcmp (this_name
, filename
) == 0)
2325 dw2_instantiate_symtab (objfile
, per_cu
);
2333 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2335 struct dwarf2_per_cu_data
*per_cu
;
2338 dw2_setup (objfile
);
2340 if (!dwarf2_per_objfile
->index_table
)
2343 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2347 /* Note that this just looks at the very first one named NAME -- but
2348 actually we are looking for a function. find_main_filename
2349 should be rewritten so that it doesn't require a custom hook. It
2350 could just use the ordinary symbol tables. */
2351 /* vec[0] is the length, which must always be >0. */
2352 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[1]));
2354 dw2_require_line_header (objfile
, per_cu
);
2355 if (!per_cu
->v
.quick
->lines
)
2358 return per_cu
->v
.quick
->file_names
[per_cu
->v
.quick
->lines
->num_file_names
- 1];
2362 dw2_map_ada_symtabs (struct objfile
*objfile
,
2363 int (*wild_match
) (const char *, int, const char *),
2364 int (*is_name_suffix
) (const char *),
2365 void (*callback
) (struct objfile
*,
2366 struct symtab
*, void *),
2367 const char *name
, int global
,
2368 domain_enum
namespace, int wild
,
2371 /* For now, we don't support Ada. Still the function can be called if the
2372 current language is Ada for a non-Ada objfile using GNU index. As Ada
2373 does not look for non-Ada symbols this function should just return. */
2377 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2378 int (*file_matcher
) (const char *, void *),
2379 int (*name_matcher
) (const char *, void *),
2386 dw2_setup (objfile
);
2387 if (!dwarf2_per_objfile
->index_table
)
2390 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2391 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2394 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2396 per_cu
->v
.quick
->mark
= 0;
2397 if (per_cu
->v
.quick
->symtab
)
2400 dw2_require_line_header (objfile
, per_cu
);
2401 if (!per_cu
->v
.quick
->lines
)
2404 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2406 if (file_matcher (per_cu
->v
.quick
->file_names
[j
], data
))
2408 per_cu
->v
.quick
->mark
= 1;
2415 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2418 offset_type idx
= 2 * iter
;
2420 offset_type
*vec
, vec_len
, vec_idx
;
2422 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2423 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2426 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2427 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2429 if (! (*name_matcher
) (name
, data
))
2432 /* The name was matched, now expand corresponding CUs that were
2434 vec
= (offset_type
*) (dwarf2_per_objfile
->index_table
->constant_pool
2435 + dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1]);
2436 vec_len
= MAYBE_SWAP (vec
[0]);
2437 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2439 struct dwarf2_per_cu_data
*per_cu
;
2441 per_cu
= dw2_get_cu (MAYBE_SWAP (vec
[vec_idx
+ 1]));
2442 if (per_cu
->v
.quick
->mark
)
2443 dw2_instantiate_symtab (objfile
, per_cu
);
2448 static struct symtab
*
2449 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2450 struct minimal_symbol
*msymbol
,
2452 struct obj_section
*section
,
2455 struct dwarf2_per_cu_data
*data
;
2457 dw2_setup (objfile
);
2459 if (!objfile
->psymtabs_addrmap
)
2462 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2466 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2467 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
2468 paddress (get_objfile_arch (objfile
), pc
));
2470 return dw2_instantiate_symtab (objfile
, data
);
2474 dw2_map_symbol_names (struct objfile
*objfile
,
2475 void (*fun
) (const char *, void *),
2479 dw2_setup (objfile
);
2481 if (!dwarf2_per_objfile
->index_table
)
2485 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2488 offset_type idx
= 2 * iter
;
2490 offset_type
*vec
, vec_len
, vec_idx
;
2492 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2493 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2496 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2497 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2499 (*fun
) (name
, data
);
2504 dw2_map_symbol_filenames (struct objfile
*objfile
,
2505 void (*fun
) (const char *, const char *, void *),
2510 dw2_setup (objfile
);
2511 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2512 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2515 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2517 if (per_cu
->v
.quick
->symtab
)
2520 dw2_require_line_header (objfile
, per_cu
);
2521 if (!per_cu
->v
.quick
->lines
)
2524 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
2526 const char *this_full_name
= dw2_require_full_path (objfile
, per_cu
,
2528 (*fun
) (per_cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2534 dw2_has_symbols (struct objfile
*objfile
)
2539 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2542 dw2_find_last_source_symtab
,
2543 dw2_forget_cached_source_info
,
2546 dw2_pre_expand_symtabs_matching
,
2550 dw2_expand_symtabs_for_function
,
2551 dw2_expand_all_symtabs
,
2552 dw2_expand_symtabs_with_filename
,
2553 dw2_find_symbol_file
,
2554 dw2_map_ada_symtabs
,
2555 dw2_expand_symtabs_matching
,
2556 dw2_find_pc_sect_symtab
,
2557 dw2_map_symbol_names
,
2558 dw2_map_symbol_filenames
2561 /* Initialize for reading DWARF for this objfile. Return 0 if this
2562 file will use psymtabs, or 1 if using the GNU index. */
2565 dwarf2_initialize_objfile (struct objfile
*objfile
)
2567 /* If we're about to read full symbols, don't bother with the
2568 indices. In this case we also don't care if some other debug
2569 format is making psymtabs, because they are all about to be
2571 if ((objfile
->flags
& OBJF_READNOW
))
2575 dwarf2_per_objfile
->using_index
= 1;
2576 create_all_comp_units (objfile
);
2577 create_debug_types_hash_table (objfile
);
2579 for (i
= 0; i
< (dwarf2_per_objfile
->n_comp_units
2580 + dwarf2_per_objfile
->n_type_comp_units
); ++i
)
2582 struct dwarf2_per_cu_data
*per_cu
= dw2_get_cu (i
);
2584 per_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2585 struct dwarf2_per_cu_quick_data
);
2588 /* Return 1 so that gdb sees the "quick" functions. However,
2589 these functions will be no-ops because we will have expanded
2594 if (dwarf2_read_index (objfile
))
2597 dwarf2_build_psymtabs (objfile
);
2603 /* Build a partial symbol table. */
2606 dwarf2_build_psymtabs (struct objfile
*objfile
)
2608 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2610 init_psymbol_list (objfile
, 1024);
2613 dwarf2_build_psymtabs_hard (objfile
);
2616 /* Return TRUE if OFFSET is within CU_HEADER. */
2619 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2621 unsigned int bottom
= cu_header
->offset
;
2622 unsigned int top
= (cu_header
->offset
2624 + cu_header
->initial_length_size
);
2626 return (offset
>= bottom
&& offset
< top
);
2629 /* Read in the comp unit header information from the debug_info at info_ptr.
2630 NOTE: This leaves members offset, first_die_offset to be filled in
2634 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2635 gdb_byte
*info_ptr
, bfd
*abfd
)
2638 unsigned int bytes_read
;
2640 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2641 cu_header
->initial_length_size
= bytes_read
;
2642 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2643 info_ptr
+= bytes_read
;
2644 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2646 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2648 info_ptr
+= bytes_read
;
2649 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2651 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2652 if (signed_addr
< 0)
2653 internal_error (__FILE__
, __LINE__
,
2654 _("read_comp_unit_head: dwarf from non elf file"));
2655 cu_header
->signed_addr_p
= signed_addr
;
2661 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2662 gdb_byte
*buffer
, unsigned int buffer_size
,
2665 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2667 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2669 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2670 error (_("Dwarf Error: wrong version in compilation unit header "
2671 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2672 bfd_get_filename (abfd
));
2674 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2675 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2676 "(offset 0x%lx + 6) [in module %s]"),
2677 (long) header
->abbrev_offset
,
2678 (long) (beg_of_comp_unit
- buffer
),
2679 bfd_get_filename (abfd
));
2681 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2682 > buffer
+ buffer_size
)
2683 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2684 "(offset 0x%lx + 0) [in module %s]"),
2685 (long) header
->length
,
2686 (long) (beg_of_comp_unit
- buffer
),
2687 bfd_get_filename (abfd
));
2692 /* Read in the types comp unit header information from .debug_types entry at
2693 types_ptr. The result is a pointer to one past the end of the header. */
2696 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2697 ULONGEST
*signature
,
2698 gdb_byte
*types_ptr
, bfd
*abfd
)
2700 gdb_byte
*initial_types_ptr
= types_ptr
;
2702 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2703 &dwarf2_per_objfile
->types
);
2704 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2706 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2708 *signature
= read_8_bytes (abfd
, types_ptr
);
2710 types_ptr
+= cu_header
->offset_size
;
2711 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2716 /* Allocate a new partial symtab for file named NAME and mark this new
2717 partial symtab as being an include of PST. */
2720 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2721 struct objfile
*objfile
)
2723 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2725 subpst
->section_offsets
= pst
->section_offsets
;
2726 subpst
->textlow
= 0;
2727 subpst
->texthigh
= 0;
2729 subpst
->dependencies
= (struct partial_symtab
**)
2730 obstack_alloc (&objfile
->objfile_obstack
,
2731 sizeof (struct partial_symtab
*));
2732 subpst
->dependencies
[0] = pst
;
2733 subpst
->number_of_dependencies
= 1;
2735 subpst
->globals_offset
= 0;
2736 subpst
->n_global_syms
= 0;
2737 subpst
->statics_offset
= 0;
2738 subpst
->n_static_syms
= 0;
2739 subpst
->symtab
= NULL
;
2740 subpst
->read_symtab
= pst
->read_symtab
;
2743 /* No private part is necessary for include psymtabs. This property
2744 can be used to differentiate between such include psymtabs and
2745 the regular ones. */
2746 subpst
->read_symtab_private
= NULL
;
2749 /* Read the Line Number Program data and extract the list of files
2750 included by the source file represented by PST. Build an include
2751 partial symtab for each of these included files. */
2754 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2755 struct die_info
*die
,
2756 struct partial_symtab
*pst
)
2758 struct objfile
*objfile
= cu
->objfile
;
2759 bfd
*abfd
= objfile
->obfd
;
2760 struct line_header
*lh
= NULL
;
2761 struct attribute
*attr
;
2763 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2766 unsigned int line_offset
= DW_UNSND (attr
);
2768 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2771 return; /* No linetable, so no includes. */
2773 /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */
2774 dwarf_decode_lines (lh
, pst
->dirname
, abfd
, cu
, pst
);
2776 free_line_header (lh
);
2780 hash_type_signature (const void *item
)
2782 const struct signatured_type
*type_sig
= item
;
2784 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2785 return type_sig
->signature
;
2789 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2791 const struct signatured_type
*lhs
= item_lhs
;
2792 const struct signatured_type
*rhs
= item_rhs
;
2794 return lhs
->signature
== rhs
->signature
;
2797 /* Allocate a hash table for signatured types. */
2800 allocate_signatured_type_table (struct objfile
*objfile
)
2802 return htab_create_alloc_ex (41,
2803 hash_type_signature
,
2806 &objfile
->objfile_obstack
,
2807 hashtab_obstack_allocate
,
2808 dummy_obstack_deallocate
);
2811 /* A helper function to add a signatured type CU to a list. */
2814 add_signatured_type_cu_to_list (void **slot
, void *datum
)
2816 struct signatured_type
*sigt
= *slot
;
2817 struct dwarf2_per_cu_data
***datap
= datum
;
2819 **datap
= &sigt
->per_cu
;
2825 /* Create the hash table of all entries in the .debug_types section.
2826 The result is zero if there is an error (e.g. missing .debug_types section),
2827 otherwise non-zero. */
2830 create_debug_types_hash_table (struct objfile
*objfile
)
2834 struct dwarf2_per_cu_data
**iter
;
2836 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2837 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2839 if (info_ptr
== NULL
)
2841 dwarf2_per_objfile
->signatured_types
= NULL
;
2845 types_htab
= allocate_signatured_type_table (objfile
);
2847 if (dwarf2_die_debug
)
2848 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2850 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2852 unsigned int offset
;
2853 unsigned int offset_size
;
2854 unsigned int type_offset
;
2855 unsigned int length
, initial_length_size
;
2856 unsigned short version
;
2858 struct signatured_type
*type_sig
;
2860 gdb_byte
*ptr
= info_ptr
;
2862 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2864 /* We need to read the type's signature in order to build the hash
2865 table, but we don't need to read anything else just yet. */
2867 /* Sanity check to ensure entire cu is present. */
2868 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2869 if (ptr
+ length
+ initial_length_size
2870 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2872 complaint (&symfile_complaints
,
2873 _("debug type entry runs off end of `.debug_types' section, ignored"));
2877 offset_size
= initial_length_size
== 4 ? 4 : 8;
2878 ptr
+= initial_length_size
;
2879 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2881 ptr
+= offset_size
; /* abbrev offset */
2882 ptr
+= 1; /* address size */
2883 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2885 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2887 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2888 memset (type_sig
, 0, sizeof (*type_sig
));
2889 type_sig
->signature
= signature
;
2890 type_sig
->offset
= offset
;
2891 type_sig
->type_offset
= type_offset
;
2892 type_sig
->per_cu
.objfile
= objfile
;
2893 type_sig
->per_cu
.from_debug_types
= 1;
2895 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2896 gdb_assert (slot
!= NULL
);
2899 if (dwarf2_die_debug
)
2900 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2901 offset
, phex (signature
, sizeof (signature
)));
2903 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2906 dwarf2_per_objfile
->signatured_types
= types_htab
;
2908 dwarf2_per_objfile
->n_type_comp_units
= htab_elements (types_htab
);
2909 dwarf2_per_objfile
->type_comp_units
2910 = obstack_alloc (&objfile
->objfile_obstack
,
2911 dwarf2_per_objfile
->n_type_comp_units
2912 * sizeof (struct dwarf2_per_cu_data
*));
2913 iter
= &dwarf2_per_objfile
->type_comp_units
[0];
2914 htab_traverse_noresize (types_htab
, add_signatured_type_cu_to_list
, &iter
);
2915 gdb_assert (iter
- &dwarf2_per_objfile
->type_comp_units
[0]
2916 == dwarf2_per_objfile
->n_type_comp_units
);
2921 /* Lookup a signature based type.
2922 Returns NULL if SIG is not present in the table. */
2924 static struct signatured_type
*
2925 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2927 struct signatured_type find_entry
, *entry
;
2929 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2931 complaint (&symfile_complaints
,
2932 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2936 find_entry
.signature
= sig
;
2937 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2941 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2944 init_cu_die_reader (struct die_reader_specs
*reader
,
2945 struct dwarf2_cu
*cu
)
2947 reader
->abfd
= cu
->objfile
->obfd
;
2949 if (cu
->per_cu
->from_debug_types
)
2951 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2952 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2956 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2957 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2961 /* Find the base address of the compilation unit for range lists and
2962 location lists. It will normally be specified by DW_AT_low_pc.
2963 In DWARF-3 draft 4, the base address could be overridden by
2964 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2965 compilation units with discontinuous ranges. */
2968 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2970 struct attribute
*attr
;
2973 cu
->base_address
= 0;
2975 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
2978 cu
->base_address
= DW_ADDR (attr
);
2983 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2986 cu
->base_address
= DW_ADDR (attr
);
2992 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2993 to combine the common parts.
2994 Process a compilation unit for a psymtab.
2995 BUFFER is a pointer to the beginning of the dwarf section buffer,
2996 either .debug_info or debug_types.
2997 INFO_PTR is a pointer to the start of the CU.
2998 Returns a pointer to the next CU. */
3001 process_psymtab_comp_unit (struct objfile
*objfile
,
3002 struct dwarf2_per_cu_data
*this_cu
,
3003 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3004 unsigned int buffer_size
)
3006 bfd
*abfd
= objfile
->obfd
;
3007 gdb_byte
*beg_of_comp_unit
= info_ptr
;
3008 struct die_info
*comp_unit_die
;
3009 struct partial_symtab
*pst
;
3011 struct cleanup
*back_to_inner
;
3012 struct dwarf2_cu cu
;
3013 int has_children
, has_pc_info
;
3014 struct attribute
*attr
;
3015 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
3016 struct die_reader_specs reader_specs
;
3018 memset (&cu
, 0, sizeof (cu
));
3019 cu
.objfile
= objfile
;
3020 obstack_init (&cu
.comp_unit_obstack
);
3022 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
3024 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
3025 buffer
, buffer_size
,
3028 /* Complete the cu_header. */
3029 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
3030 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3032 cu
.list_in_scope
= &file_symbols
;
3034 /* If this compilation unit was already read in, free the
3035 cached copy in order to read it in again. This is
3036 necessary because we skipped some symbols when we first
3037 read in the compilation unit (see load_partial_dies).
3038 This problem could be avoided, but the benefit is
3040 if (this_cu
->cu
!= NULL
)
3041 free_one_cached_comp_unit (this_cu
->cu
);
3043 /* Note that this is a pointer to our stack frame, being
3044 added to a global data structure. It will be cleaned up
3045 in free_stack_comp_unit when we finish with this
3046 compilation unit. */
3048 cu
.per_cu
= this_cu
;
3050 /* Read the abbrevs for this compilation unit into a table. */
3051 dwarf2_read_abbrevs (abfd
, &cu
);
3052 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
3054 /* Read the compilation unit die. */
3055 if (this_cu
->from_debug_types
)
3056 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
3057 init_cu_die_reader (&reader_specs
, &cu
);
3058 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3061 if (this_cu
->from_debug_types
)
3063 /* offset,length haven't been set yet for type units. */
3064 this_cu
->offset
= cu
.header
.offset
;
3065 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
3067 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
3069 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3070 + cu
.header
.initial_length_size
);
3071 do_cleanups (back_to_inner
);
3075 /* Set the language we're debugging. */
3076 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
3078 set_cu_language (DW_UNSND (attr
), &cu
);
3080 set_cu_language (language_minimal
, &cu
);
3082 /* Allocate a new partial symbol table structure. */
3083 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
3084 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
3085 (attr
!= NULL
) ? DW_STRING (attr
) : "",
3086 /* TEXTLOW and TEXTHIGH are set below. */
3088 objfile
->global_psymbols
.next
,
3089 objfile
->static_psymbols
.next
);
3091 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
3093 pst
->dirname
= DW_STRING (attr
);
3095 pst
->read_symtab_private
= this_cu
;
3097 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3099 /* Store the function that reads in the rest of the symbol table */
3100 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
3102 this_cu
->v
.psymtab
= pst
;
3104 dwarf2_find_base_address (comp_unit_die
, &cu
);
3106 /* Possibly set the default values of LOWPC and HIGHPC from
3108 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
3109 &best_highpc
, &cu
, pst
);
3110 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
3111 /* Store the contiguous range if it is not empty; it can be empty for
3112 CUs with no code. */
3113 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3114 best_lowpc
+ baseaddr
,
3115 best_highpc
+ baseaddr
- 1, pst
);
3117 /* Check if comp unit has_children.
3118 If so, read the rest of the partial symbols from this comp unit.
3119 If not, there's no more debug_info for this comp unit. */
3122 struct partial_die_info
*first_die
;
3123 CORE_ADDR lowpc
, highpc
;
3125 lowpc
= ((CORE_ADDR
) -1);
3126 highpc
= ((CORE_ADDR
) 0);
3128 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
3130 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
3131 ! has_pc_info
, &cu
);
3133 /* If we didn't find a lowpc, set it to highpc to avoid
3134 complaints from `maint check'. */
3135 if (lowpc
== ((CORE_ADDR
) -1))
3138 /* If the compilation unit didn't have an explicit address range,
3139 then use the information extracted from its child dies. */
3143 best_highpc
= highpc
;
3146 pst
->textlow
= best_lowpc
+ baseaddr
;
3147 pst
->texthigh
= best_highpc
+ baseaddr
;
3149 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
3150 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
3151 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
3152 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
3153 sort_pst_symbols (pst
);
3155 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
3156 + cu
.header
.initial_length_size
);
3158 if (this_cu
->from_debug_types
)
3160 /* It's not clear we want to do anything with stmt lists here.
3161 Waiting to see what gcc ultimately does. */
3165 /* Get the list of files included in the current compilation unit,
3166 and build a psymtab for each of them. */
3167 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
3170 do_cleanups (back_to_inner
);
3175 /* Traversal function for htab_traverse_noresize.
3176 Process one .debug_types comp-unit. */
3179 process_type_comp_unit (void **slot
, void *info
)
3181 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
3182 struct objfile
*objfile
= (struct objfile
*) info
;
3183 struct dwarf2_per_cu_data
*this_cu
;
3185 this_cu
= &entry
->per_cu
;
3187 gdb_assert (dwarf2_per_objfile
->types
.readin
);
3188 process_psymtab_comp_unit (objfile
, this_cu
,
3189 dwarf2_per_objfile
->types
.buffer
,
3190 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
3191 dwarf2_per_objfile
->types
.size
);
3196 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
3197 Build partial symbol tables for the .debug_types comp-units. */
3200 build_type_psymtabs (struct objfile
*objfile
)
3202 if (! create_debug_types_hash_table (objfile
))
3205 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
3206 process_type_comp_unit
, objfile
);
3209 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
3212 psymtabs_addrmap_cleanup (void *o
)
3214 struct objfile
*objfile
= o
;
3216 objfile
->psymtabs_addrmap
= NULL
;
3219 /* Build the partial symbol table by doing a quick pass through the
3220 .debug_info and .debug_abbrev sections. */
3223 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3226 struct cleanup
*back_to
, *addrmap_cleanup
;
3227 struct obstack temp_obstack
;
3229 dwarf2_per_objfile
->reading_partial_symbols
= 1;
3231 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3232 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3234 /* Any cached compilation units will be linked by the per-objfile
3235 read_in_chain. Make sure to free them when we're done. */
3236 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3238 build_type_psymtabs (objfile
);
3240 create_all_comp_units (objfile
);
3242 /* Create a temporary address map on a temporary obstack. We later
3243 copy this to the final obstack. */
3244 obstack_init (&temp_obstack
);
3245 make_cleanup_obstack_free (&temp_obstack
);
3246 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3247 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3249 /* Since the objects we're extracting from .debug_info vary in
3250 length, only the individual functions to extract them (like
3251 read_comp_unit_head and load_partial_die) can really know whether
3252 the buffer is large enough to hold another complete object.
3254 At the moment, they don't actually check that. If .debug_info
3255 holds just one extra byte after the last compilation unit's dies,
3256 then read_comp_unit_head will happily read off the end of the
3257 buffer. read_partial_die is similarly casual. Those functions
3260 For this loop condition, simply checking whether there's any data
3261 left at all should be sufficient. */
3263 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3264 + dwarf2_per_objfile
->info
.size
))
3266 struct dwarf2_per_cu_data
*this_cu
;
3268 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3271 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3272 dwarf2_per_objfile
->info
.buffer
,
3274 dwarf2_per_objfile
->info
.size
);
3277 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3278 &objfile
->objfile_obstack
);
3279 discard_cleanups (addrmap_cleanup
);
3281 do_cleanups (back_to
);
3284 /* Load the partial DIEs for a secondary CU into memory. */
3287 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3288 struct objfile
*objfile
)
3290 bfd
*abfd
= objfile
->obfd
;
3291 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3292 struct die_info
*comp_unit_die
;
3293 struct dwarf2_cu
*cu
;
3294 struct cleanup
*free_abbrevs_cleanup
, *free_cu_cleanup
= NULL
;
3295 struct attribute
*attr
;
3297 struct die_reader_specs reader_specs
;
3300 gdb_assert (! this_cu
->from_debug_types
);
3302 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3303 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3304 beg_of_comp_unit
= info_ptr
;
3306 if (this_cu
->cu
== NULL
)
3308 cu
= alloc_one_comp_unit (objfile
);
3312 /* If an error occurs while loading, release our storage. */
3313 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3315 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3316 dwarf2_per_objfile
->info
.buffer
,
3317 dwarf2_per_objfile
->info
.size
,
3320 /* Complete the cu_header. */
3321 cu
->header
.offset
= this_cu
->offset
;
3322 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3324 /* Link this compilation unit into the compilation unit tree. */
3326 cu
->per_cu
= this_cu
;
3328 /* Link this CU into read_in_chain. */
3329 this_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3330 dwarf2_per_objfile
->read_in_chain
= this_cu
;
3335 info_ptr
+= cu
->header
.first_die_offset
;
3338 /* Read the abbrevs for this compilation unit into a table. */
3339 gdb_assert (cu
->dwarf2_abbrevs
== NULL
);
3340 dwarf2_read_abbrevs (abfd
, cu
);
3341 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3343 /* Read the compilation unit die. */
3344 init_cu_die_reader (&reader_specs
, cu
);
3345 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3348 /* Set the language we're debugging. */
3349 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
3351 set_cu_language (DW_UNSND (attr
), cu
);
3353 set_cu_language (language_minimal
, cu
);
3355 /* Check if comp unit has_children.
3356 If so, read the rest of the partial symbols from this comp unit.
3357 If not, there's no more debug_info for this comp unit. */
3359 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3361 do_cleanups (free_abbrevs_cleanup
);
3365 /* We've successfully allocated this compilation unit. Let our
3366 caller clean it up when finished with it. */
3367 discard_cleanups (free_cu_cleanup
);
3371 /* Create a list of all compilation units in OBJFILE. We do this only
3372 if an inter-comp-unit reference is found; presumably if there is one,
3373 there will be many, and one will occur early in the .debug_info section.
3374 So there's no point in building this list incrementally. */
3377 create_all_comp_units (struct objfile
*objfile
)
3381 struct dwarf2_per_cu_data
**all_comp_units
;
3384 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3385 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3389 all_comp_units
= xmalloc (n_allocated
3390 * sizeof (struct dwarf2_per_cu_data
*));
3392 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3394 unsigned int length
, initial_length_size
;
3395 struct dwarf2_per_cu_data
*this_cu
;
3396 unsigned int offset
;
3398 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3400 /* Read just enough information to find out where the next
3401 compilation unit is. */
3402 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3403 &initial_length_size
);
3405 /* Save the compilation unit for later lookup. */
3406 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3407 sizeof (struct dwarf2_per_cu_data
));
3408 memset (this_cu
, 0, sizeof (*this_cu
));
3409 this_cu
->offset
= offset
;
3410 this_cu
->length
= length
+ initial_length_size
;
3411 this_cu
->objfile
= objfile
;
3413 if (n_comp_units
== n_allocated
)
3416 all_comp_units
= xrealloc (all_comp_units
,
3418 * sizeof (struct dwarf2_per_cu_data
*));
3420 all_comp_units
[n_comp_units
++] = this_cu
;
3422 info_ptr
= info_ptr
+ this_cu
->length
;
3425 dwarf2_per_objfile
->all_comp_units
3426 = obstack_alloc (&objfile
->objfile_obstack
,
3427 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3428 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3429 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3430 xfree (all_comp_units
);
3431 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3434 /* Process all loaded DIEs for compilation unit CU, starting at
3435 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3436 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3437 DW_AT_ranges). If NEED_PC is set, then this function will set
3438 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3439 and record the covered ranges in the addrmap. */
3442 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3443 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3445 struct partial_die_info
*pdi
;
3447 /* Now, march along the PDI's, descending into ones which have
3448 interesting children but skipping the children of the other ones,
3449 until we reach the end of the compilation unit. */
3455 fixup_partial_die (pdi
, cu
);
3457 /* Anonymous namespaces or modules have no name but have interesting
3458 children, so we need to look at them. Ditto for anonymous
3461 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3462 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3466 case DW_TAG_subprogram
:
3467 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3469 case DW_TAG_constant
:
3470 case DW_TAG_variable
:
3471 case DW_TAG_typedef
:
3472 case DW_TAG_union_type
:
3473 if (!pdi
->is_declaration
)
3475 add_partial_symbol (pdi
, cu
);
3478 case DW_TAG_class_type
:
3479 case DW_TAG_interface_type
:
3480 case DW_TAG_structure_type
:
3481 if (!pdi
->is_declaration
)
3483 add_partial_symbol (pdi
, cu
);
3486 case DW_TAG_enumeration_type
:
3487 if (!pdi
->is_declaration
)
3488 add_partial_enumeration (pdi
, cu
);
3490 case DW_TAG_base_type
:
3491 case DW_TAG_subrange_type
:
3492 /* File scope base type definitions are added to the partial
3494 add_partial_symbol (pdi
, cu
);
3496 case DW_TAG_namespace
:
3497 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3500 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3507 /* If the die has a sibling, skip to the sibling. */
3509 pdi
= pdi
->die_sibling
;
3513 /* Functions used to compute the fully scoped name of a partial DIE.
3515 Normally, this is simple. For C++, the parent DIE's fully scoped
3516 name is concatenated with "::" and the partial DIE's name. For
3517 Java, the same thing occurs except that "." is used instead of "::".
3518 Enumerators are an exception; they use the scope of their parent
3519 enumeration type, i.e. the name of the enumeration type is not
3520 prepended to the enumerator.
3522 There are two complexities. One is DW_AT_specification; in this
3523 case "parent" means the parent of the target of the specification,
3524 instead of the direct parent of the DIE. The other is compilers
3525 which do not emit DW_TAG_namespace; in this case we try to guess
3526 the fully qualified name of structure types from their members'
3527 linkage names. This must be done using the DIE's children rather
3528 than the children of any DW_AT_specification target. We only need
3529 to do this for structures at the top level, i.e. if the target of
3530 any DW_AT_specification (if any; otherwise the DIE itself) does not
3533 /* Compute the scope prefix associated with PDI's parent, in
3534 compilation unit CU. The result will be allocated on CU's
3535 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3536 field. NULL is returned if no prefix is necessary. */
3538 partial_die_parent_scope (struct partial_die_info
*pdi
,
3539 struct dwarf2_cu
*cu
)
3541 char *grandparent_scope
;
3542 struct partial_die_info
*parent
, *real_pdi
;
3544 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3545 then this means the parent of the specification DIE. */
3548 while (real_pdi
->has_specification
)
3549 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3551 parent
= real_pdi
->die_parent
;
3555 if (parent
->scope_set
)
3556 return parent
->scope
;
3558 fixup_partial_die (parent
, cu
);
3560 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3562 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3563 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3564 Work around this problem here. */
3565 if (cu
->language
== language_cplus
3566 && parent
->tag
== DW_TAG_namespace
3567 && strcmp (parent
->name
, "::") == 0
3568 && grandparent_scope
== NULL
)
3570 parent
->scope
= NULL
;
3571 parent
->scope_set
= 1;
3575 if (parent
->tag
== DW_TAG_namespace
3576 || parent
->tag
== DW_TAG_module
3577 || parent
->tag
== DW_TAG_structure_type
3578 || parent
->tag
== DW_TAG_class_type
3579 || parent
->tag
== DW_TAG_interface_type
3580 || parent
->tag
== DW_TAG_union_type
3581 || parent
->tag
== DW_TAG_enumeration_type
)
3583 if (grandparent_scope
== NULL
)
3584 parent
->scope
= parent
->name
;
3586 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3587 parent
->name
, 0, cu
);
3589 else if (parent
->tag
== DW_TAG_enumerator
)
3590 /* Enumerators should not get the name of the enumeration as a prefix. */
3591 parent
->scope
= grandparent_scope
;
3594 /* FIXME drow/2004-04-01: What should we be doing with
3595 function-local names? For partial symbols, we should probably be
3597 complaint (&symfile_complaints
,
3598 _("unhandled containing DIE tag %d for DIE at %d"),
3599 parent
->tag
, pdi
->offset
);
3600 parent
->scope
= grandparent_scope
;
3603 parent
->scope_set
= 1;
3604 return parent
->scope
;
3607 /* Return the fully scoped name associated with PDI, from compilation unit
3608 CU. The result will be allocated with malloc. */
3610 partial_die_full_name (struct partial_die_info
*pdi
,
3611 struct dwarf2_cu
*cu
)
3615 /* If this is a template instantiation, we can not work out the
3616 template arguments from partial DIEs. So, unfortunately, we have
3617 to go through the full DIEs. At least any work we do building
3618 types here will be reused if full symbols are loaded later. */
3619 if (pdi
->has_template_arguments
)
3621 fixup_partial_die (pdi
, cu
);
3623 if (pdi
->name
!= NULL
&& strchr (pdi
->name
, '<') == NULL
)
3625 struct die_info
*die
;
3626 struct attribute attr
;
3627 struct dwarf2_cu
*ref_cu
= cu
;
3630 attr
.form
= DW_FORM_ref_addr
;
3631 attr
.u
.addr
= pdi
->offset
;
3632 die
= follow_die_ref (NULL
, &attr
, &ref_cu
);
3634 return xstrdup (dwarf2_full_name (NULL
, die
, ref_cu
));
3638 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3639 if (parent_scope
== NULL
)
3642 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3646 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3648 struct objfile
*objfile
= cu
->objfile
;
3650 char *actual_name
= NULL
;
3651 const struct partial_symbol
*psym
= NULL
;
3653 int built_actual_name
= 0;
3655 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3657 actual_name
= partial_die_full_name (pdi
, cu
);
3659 built_actual_name
= 1;
3661 if (actual_name
== NULL
)
3662 actual_name
= pdi
->name
;
3666 case DW_TAG_subprogram
:
3667 if (pdi
->is_external
|| cu
->language
== language_ada
)
3669 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3670 of the global scope. But in Ada, we want to be able to access
3671 nested procedures globally. So all Ada subprograms are stored
3672 in the global scope. */
3673 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3674 mst_text, objfile); */
3675 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3677 VAR_DOMAIN
, LOC_BLOCK
,
3678 &objfile
->global_psymbols
,
3679 0, pdi
->lowpc
+ baseaddr
,
3680 cu
->language
, objfile
);
3684 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3685 mst_file_text, objfile); */
3686 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3688 VAR_DOMAIN
, LOC_BLOCK
,
3689 &objfile
->static_psymbols
,
3690 0, pdi
->lowpc
+ baseaddr
,
3691 cu
->language
, objfile
);
3694 case DW_TAG_constant
:
3696 struct psymbol_allocation_list
*list
;
3698 if (pdi
->is_external
)
3699 list
= &objfile
->global_psymbols
;
3701 list
= &objfile
->static_psymbols
;
3702 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3703 built_actual_name
, VAR_DOMAIN
, LOC_STATIC
,
3704 list
, 0, 0, cu
->language
, objfile
);
3708 case DW_TAG_variable
:
3710 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3714 && !dwarf2_per_objfile
->has_section_at_zero
)
3716 /* A global or static variable may also have been stripped
3717 out by the linker if unused, in which case its address
3718 will be nullified; do not add such variables into partial
3719 symbol table then. */
3721 else if (pdi
->is_external
)
3724 Don't enter into the minimal symbol tables as there is
3725 a minimal symbol table entry from the ELF symbols already.
3726 Enter into partial symbol table if it has a location
3727 descriptor or a type.
3728 If the location descriptor is missing, new_symbol will create
3729 a LOC_UNRESOLVED symbol, the address of the variable will then
3730 be determined from the minimal symbol table whenever the variable
3732 The address for the partial symbol table entry is not
3733 used by GDB, but it comes in handy for debugging partial symbol
3736 if (pdi
->locdesc
|| pdi
->has_type
)
3737 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3739 VAR_DOMAIN
, LOC_STATIC
,
3740 &objfile
->global_psymbols
,
3742 cu
->language
, objfile
);
3746 /* Static Variable. Skip symbols without location descriptors. */
3747 if (pdi
->locdesc
== NULL
)
3749 if (built_actual_name
)
3750 xfree (actual_name
);
3753 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3754 mst_file_data, objfile); */
3755 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3757 VAR_DOMAIN
, LOC_STATIC
,
3758 &objfile
->static_psymbols
,
3760 cu
->language
, objfile
);
3763 case DW_TAG_typedef
:
3764 case DW_TAG_base_type
:
3765 case DW_TAG_subrange_type
:
3766 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3768 VAR_DOMAIN
, LOC_TYPEDEF
,
3769 &objfile
->static_psymbols
,
3770 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3772 case DW_TAG_namespace
:
3773 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3775 VAR_DOMAIN
, LOC_TYPEDEF
,
3776 &objfile
->global_psymbols
,
3777 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3779 case DW_TAG_class_type
:
3780 case DW_TAG_interface_type
:
3781 case DW_TAG_structure_type
:
3782 case DW_TAG_union_type
:
3783 case DW_TAG_enumeration_type
:
3784 /* Skip external references. The DWARF standard says in the section
3785 about "Structure, Union, and Class Type Entries": "An incomplete
3786 structure, union or class type is represented by a structure,
3787 union or class entry that does not have a byte size attribute
3788 and that has a DW_AT_declaration attribute." */
3789 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3791 if (built_actual_name
)
3792 xfree (actual_name
);
3796 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3797 static vs. global. */
3798 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3800 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3801 (cu
->language
== language_cplus
3802 || cu
->language
== language_java
)
3803 ? &objfile
->global_psymbols
3804 : &objfile
->static_psymbols
,
3805 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3808 case DW_TAG_enumerator
:
3809 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3811 VAR_DOMAIN
, LOC_CONST
,
3812 (cu
->language
== language_cplus
3813 || cu
->language
== language_java
)
3814 ? &objfile
->global_psymbols
3815 : &objfile
->static_psymbols
,
3816 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3822 if (built_actual_name
)
3823 xfree (actual_name
);
3826 /* Read a partial die corresponding to a namespace; also, add a symbol
3827 corresponding to that namespace to the symbol table. NAMESPACE is
3828 the name of the enclosing namespace. */
3831 add_partial_namespace (struct partial_die_info
*pdi
,
3832 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3833 int need_pc
, struct dwarf2_cu
*cu
)
3835 /* Add a symbol for the namespace. */
3837 add_partial_symbol (pdi
, cu
);
3839 /* Now scan partial symbols in that namespace. */
3841 if (pdi
->has_children
)
3842 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3845 /* Read a partial die corresponding to a Fortran module. */
3848 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3849 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3851 /* Now scan partial symbols in that module. */
3853 if (pdi
->has_children
)
3854 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3857 /* Read a partial die corresponding to a subprogram and create a partial
3858 symbol for that subprogram. When the CU language allows it, this
3859 routine also defines a partial symbol for each nested subprogram
3860 that this subprogram contains.
3862 DIE my also be a lexical block, in which case we simply search
3863 recursively for suprograms defined inside that lexical block.
3864 Again, this is only performed when the CU language allows this
3865 type of definitions. */
3868 add_partial_subprogram (struct partial_die_info
*pdi
,
3869 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3870 int need_pc
, struct dwarf2_cu
*cu
)
3872 if (pdi
->tag
== DW_TAG_subprogram
)
3874 if (pdi
->has_pc_info
)
3876 if (pdi
->lowpc
< *lowpc
)
3877 *lowpc
= pdi
->lowpc
;
3878 if (pdi
->highpc
> *highpc
)
3879 *highpc
= pdi
->highpc
;
3883 struct objfile
*objfile
= cu
->objfile
;
3885 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3886 SECT_OFF_TEXT (objfile
));
3887 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3888 pdi
->lowpc
+ baseaddr
,
3889 pdi
->highpc
- 1 + baseaddr
,
3890 cu
->per_cu
->v
.psymtab
);
3892 if (!pdi
->is_declaration
)
3893 /* Ignore subprogram DIEs that do not have a name, they are
3894 illegal. Do not emit a complaint at this point, we will
3895 do so when we convert this psymtab into a symtab. */
3897 add_partial_symbol (pdi
, cu
);
3901 if (! pdi
->has_children
)
3904 if (cu
->language
== language_ada
)
3906 pdi
= pdi
->die_child
;
3909 fixup_partial_die (pdi
, cu
);
3910 if (pdi
->tag
== DW_TAG_subprogram
3911 || pdi
->tag
== DW_TAG_lexical_block
)
3912 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3913 pdi
= pdi
->die_sibling
;
3918 /* See if we can figure out if the class lives in a namespace. We do
3919 this by looking for a member function; its demangled name will
3920 contain namespace info, if there is any. */
3923 guess_structure_name (struct partial_die_info
*struct_pdi
,
3924 struct dwarf2_cu
*cu
)
3926 if ((cu
->language
== language_cplus
3927 || cu
->language
== language_java
)
3928 && cu
->has_namespace_info
== 0
3929 && struct_pdi
->has_children
)
3931 /* NOTE: carlton/2003-10-07: Getting the info this way changes
3932 what template types look like, because the demangler
3933 frequently doesn't give the same name as the debug info. We
3934 could fix this by only using the demangled name to get the
3935 prefix (but see comment in read_structure_type). */
3937 struct partial_die_info
*real_pdi
;
3939 /* If this DIE (this DIE's specification, if any) has a parent, then
3940 we should not do this. We'll prepend the parent's fully qualified
3941 name when we create the partial symbol. */
3943 real_pdi
= struct_pdi
;
3944 while (real_pdi
->has_specification
)
3945 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3947 if (real_pdi
->die_parent
!= NULL
)
3952 /* Read a partial die corresponding to an enumeration type. */
3955 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3956 struct dwarf2_cu
*cu
)
3958 struct partial_die_info
*pdi
;
3960 if (enum_pdi
->name
!= NULL
)
3961 add_partial_symbol (enum_pdi
, cu
);
3963 pdi
= enum_pdi
->die_child
;
3966 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3967 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3969 add_partial_symbol (pdi
, cu
);
3970 pdi
= pdi
->die_sibling
;
3974 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3975 Return the corresponding abbrev, or NULL if the number is zero (indicating
3976 an empty DIE). In either case *BYTES_READ will be set to the length of
3977 the initial number. */
3979 static struct abbrev_info
*
3980 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3981 struct dwarf2_cu
*cu
)
3983 bfd
*abfd
= cu
->objfile
->obfd
;
3984 unsigned int abbrev_number
;
3985 struct abbrev_info
*abbrev
;
3987 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3989 if (abbrev_number
== 0)
3992 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3995 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3996 bfd_get_filename (abfd
));
4002 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4003 Returns a pointer to the end of a series of DIEs, terminated by an empty
4004 DIE. Any children of the skipped DIEs will also be skipped. */
4007 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
4009 struct abbrev_info
*abbrev
;
4010 unsigned int bytes_read
;
4014 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
4016 return info_ptr
+ bytes_read
;
4018 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
4022 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
4023 INFO_PTR should point just after the initial uleb128 of a DIE, and the
4024 abbrev corresponding to that skipped uleb128 should be passed in
4025 ABBREV. Returns a pointer to this DIE's sibling, skipping any
4029 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4030 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
4032 unsigned int bytes_read
;
4033 struct attribute attr
;
4034 bfd
*abfd
= cu
->objfile
->obfd
;
4035 unsigned int form
, i
;
4037 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
4039 /* The only abbrev we care about is DW_AT_sibling. */
4040 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
4042 read_attribute (&attr
, &abbrev
->attrs
[i
],
4043 abfd
, info_ptr
, cu
);
4044 if (attr
.form
== DW_FORM_ref_addr
)
4045 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
4047 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
4050 /* If it isn't DW_AT_sibling, skip this attribute. */
4051 form
= abbrev
->attrs
[i
].form
;
4055 case DW_FORM_ref_addr
:
4056 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
4057 and later it is offset sized. */
4058 if (cu
->header
.version
== 2)
4059 info_ptr
+= cu
->header
.addr_size
;
4061 info_ptr
+= cu
->header
.offset_size
;
4064 info_ptr
+= cu
->header
.addr_size
;
4071 case DW_FORM_flag_present
:
4086 case DW_FORM_string
:
4087 read_direct_string (abfd
, info_ptr
, &bytes_read
);
4088 info_ptr
+= bytes_read
;
4090 case DW_FORM_sec_offset
:
4092 info_ptr
+= cu
->header
.offset_size
;
4094 case DW_FORM_exprloc
:
4096 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4097 info_ptr
+= bytes_read
;
4099 case DW_FORM_block1
:
4100 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
4102 case DW_FORM_block2
:
4103 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
4105 case DW_FORM_block4
:
4106 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
4110 case DW_FORM_ref_udata
:
4111 info_ptr
= skip_leb128 (abfd
, info_ptr
);
4113 case DW_FORM_indirect
:
4114 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4115 info_ptr
+= bytes_read
;
4116 /* We need to continue parsing from here, so just go back to
4118 goto skip_attribute
;
4121 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
4122 dwarf_form_name (form
),
4123 bfd_get_filename (abfd
));
4127 if (abbrev
->has_children
)
4128 return skip_children (buffer
, info_ptr
, cu
);
4133 /* Locate ORIG_PDI's sibling.
4134 INFO_PTR should point to the start of the next DIE after ORIG_PDI
4138 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
4139 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
4140 bfd
*abfd
, struct dwarf2_cu
*cu
)
4142 /* Do we know the sibling already? */
4144 if (orig_pdi
->sibling
)
4145 return orig_pdi
->sibling
;
4147 /* Are there any children to deal with? */
4149 if (!orig_pdi
->has_children
)
4152 /* Skip the children the long way. */
4154 return skip_children (buffer
, info_ptr
, cu
);
4157 /* Expand this partial symbol table into a full symbol table. */
4160 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
4166 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
4172 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
4173 gdb_flush (gdb_stdout
);
4176 /* Restore our global data. */
4177 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
4178 dwarf2_objfile_data_key
);
4180 /* If this psymtab is constructed from a debug-only objfile, the
4181 has_section_at_zero flag will not necessarily be correct. We
4182 can get the correct value for this flag by looking at the data
4183 associated with the (presumably stripped) associated objfile. */
4184 if (pst
->objfile
->separate_debug_objfile_backlink
)
4186 struct dwarf2_per_objfile
*dpo_backlink
4187 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
4188 dwarf2_objfile_data_key
);
4190 dwarf2_per_objfile
->has_section_at_zero
4191 = dpo_backlink
->has_section_at_zero
;
4194 dwarf2_per_objfile
->reading_partial_symbols
= 0;
4196 psymtab_to_symtab_1 (pst
);
4198 /* Finish up the debug error message. */
4200 printf_filtered (_("done.\n"));
4205 /* Add PER_CU to the queue. */
4208 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4210 struct dwarf2_queue_item
*item
;
4213 item
= xmalloc (sizeof (*item
));
4214 item
->per_cu
= per_cu
;
4217 if (dwarf2_queue
== NULL
)
4218 dwarf2_queue
= item
;
4220 dwarf2_queue_tail
->next
= item
;
4222 dwarf2_queue_tail
= item
;
4225 /* Process the queue. */
4228 process_queue (struct objfile
*objfile
)
4230 struct dwarf2_queue_item
*item
, *next_item
;
4232 /* The queue starts out with one item, but following a DIE reference
4233 may load a new CU, adding it to the end of the queue. */
4234 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
4236 if (dwarf2_per_objfile
->using_index
4237 ? !item
->per_cu
->v
.quick
->symtab
4238 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
4239 process_full_comp_unit (item
->per_cu
);
4241 item
->per_cu
->queued
= 0;
4242 next_item
= item
->next
;
4246 dwarf2_queue_tail
= NULL
;
4249 /* Free all allocated queue entries. This function only releases anything if
4250 an error was thrown; if the queue was processed then it would have been
4251 freed as we went along. */
4254 dwarf2_release_queue (void *dummy
)
4256 struct dwarf2_queue_item
*item
, *last
;
4258 item
= dwarf2_queue
;
4261 /* Anything still marked queued is likely to be in an
4262 inconsistent state, so discard it. */
4263 if (item
->per_cu
->queued
)
4265 if (item
->per_cu
->cu
!= NULL
)
4266 free_one_cached_comp_unit (item
->per_cu
->cu
);
4267 item
->per_cu
->queued
= 0;
4275 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
4278 /* Read in full symbols for PST, and anything it depends on. */
4281 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
4283 struct dwarf2_per_cu_data
*per_cu
;
4284 struct cleanup
*back_to
;
4287 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
4288 if (!pst
->dependencies
[i
]->readin
)
4290 /* Inform about additional files that need to be read in. */
4293 /* FIXME: i18n: Need to make this a single string. */
4294 fputs_filtered (" ", gdb_stdout
);
4296 fputs_filtered ("and ", gdb_stdout
);
4298 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4299 wrap_here (""); /* Flush output */
4300 gdb_flush (gdb_stdout
);
4302 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4305 per_cu
= pst
->read_symtab_private
;
4309 /* It's an include file, no symbols to read for it.
4310 Everything is in the parent symtab. */
4315 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4318 /* Load the DIEs associated with PER_CU into memory. */
4321 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4323 bfd
*abfd
= objfile
->obfd
;
4324 struct dwarf2_cu
*cu
;
4325 unsigned int offset
;
4326 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4327 struct cleanup
*free_abbrevs_cleanup
= NULL
, *free_cu_cleanup
= NULL
;
4328 struct attribute
*attr
;
4331 gdb_assert (! per_cu
->from_debug_types
);
4333 /* Set local variables from the partial symbol table info. */
4334 offset
= per_cu
->offset
;
4336 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4337 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4338 beg_of_comp_unit
= info_ptr
;
4340 if (per_cu
->cu
== NULL
)
4342 cu
= alloc_one_comp_unit (objfile
);
4346 /* If an error occurs while loading, release our storage. */
4347 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4349 /* Read in the comp_unit header. */
4350 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4352 /* Complete the cu_header. */
4353 cu
->header
.offset
= offset
;
4354 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4356 /* Read the abbrevs for this compilation unit. */
4357 dwarf2_read_abbrevs (abfd
, cu
);
4358 free_abbrevs_cleanup
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4360 /* Link this compilation unit into the compilation unit tree. */
4362 cu
->per_cu
= per_cu
;
4364 /* Link this CU into read_in_chain. */
4365 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4366 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4371 info_ptr
+= cu
->header
.first_die_offset
;
4374 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4376 /* We try not to read any attributes in this function, because not
4377 all objfiles needed for references have been loaded yet, and symbol
4378 table processing isn't initialized. But we have to set the CU language,
4379 or we won't be able to build types correctly. */
4380 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
4382 set_cu_language (DW_UNSND (attr
), cu
);
4384 set_cu_language (language_minimal
, cu
);
4386 /* Similarly, if we do not read the producer, we can not apply
4387 producer-specific interpretation. */
4388 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4390 cu
->producer
= DW_STRING (attr
);
4394 do_cleanups (free_abbrevs_cleanup
);
4396 /* We've successfully allocated this compilation unit. Let our
4397 caller clean it up when finished with it. */
4398 discard_cleanups (free_cu_cleanup
);
4402 /* Add a DIE to the delayed physname list. */
4405 add_to_method_list (struct type
*type
, int fnfield_index
, int index
,
4406 const char *name
, struct die_info
*die
,
4407 struct dwarf2_cu
*cu
)
4409 struct delayed_method_info mi
;
4411 mi
.fnfield_index
= fnfield_index
;
4415 VEC_safe_push (delayed_method_info
, cu
->method_list
, &mi
);
4418 /* A cleanup for freeing the delayed method list. */
4421 free_delayed_list (void *ptr
)
4423 struct dwarf2_cu
*cu
= (struct dwarf2_cu
*) ptr
;
4424 if (cu
->method_list
!= NULL
)
4426 VEC_free (delayed_method_info
, cu
->method_list
);
4427 cu
->method_list
= NULL
;
4431 /* Compute the physnames of any methods on the CU's method list.
4433 The computation of method physnames is delayed in order to avoid the
4434 (bad) condition that one of the method's formal parameters is of an as yet
4438 compute_delayed_physnames (struct dwarf2_cu
*cu
)
4441 struct delayed_method_info
*mi
;
4442 for (i
= 0; VEC_iterate (delayed_method_info
, cu
->method_list
, i
, mi
) ; ++i
)
4445 struct fn_fieldlist
*fn_flp
4446 = &TYPE_FN_FIELDLIST (mi
->type
, mi
->fnfield_index
);
4447 physname
= (char *) dwarf2_physname ((char *) mi
->name
, mi
->die
, cu
);
4448 fn_flp
->fn_fields
[mi
->index
].physname
= physname
? physname
: "";
4452 /* Generate full symbol information for PST and CU, whose DIEs have
4453 already been loaded into memory. */
4456 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4458 struct dwarf2_cu
*cu
= per_cu
->cu
;
4459 struct objfile
*objfile
= per_cu
->objfile
;
4460 CORE_ADDR lowpc
, highpc
;
4461 struct symtab
*symtab
;
4462 struct cleanup
*back_to
, *delayed_list_cleanup
;
4465 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4468 back_to
= make_cleanup (really_free_pendings
, NULL
);
4469 delayed_list_cleanup
= make_cleanup (free_delayed_list
, cu
);
4471 cu
->list_in_scope
= &file_symbols
;
4473 dwarf2_find_base_address (cu
->dies
, cu
);
4475 /* Do line number decoding in read_file_scope () */
4476 process_die (cu
->dies
, cu
);
4478 /* Now that we have processed all the DIEs in the CU, all the types
4479 should be complete, and it should now be safe to compute all of the
4481 compute_delayed_physnames (cu
);
4482 do_cleanups (delayed_list_cleanup
);
4484 /* Some compilers don't define a DW_AT_high_pc attribute for the
4485 compilation unit. If the DW_AT_high_pc is missing, synthesize
4486 it, by scanning the DIE's below the compilation unit. */
4487 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4489 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4491 /* Set symtab language to language from DW_AT_language.
4492 If the compilation is from a C file generated by language preprocessors,
4493 do not set the language if it was already deduced by start_subfile. */
4495 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4497 symtab
->language
= cu
->language
;
4500 if (dwarf2_per_objfile
->using_index
)
4501 per_cu
->v
.quick
->symtab
= symtab
;
4504 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4505 pst
->symtab
= symtab
;
4509 do_cleanups (back_to
);
4512 /* Process a die and its children. */
4515 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4519 case DW_TAG_padding
:
4521 case DW_TAG_compile_unit
:
4522 read_file_scope (die
, cu
);
4524 case DW_TAG_type_unit
:
4525 read_type_unit_scope (die
, cu
);
4527 case DW_TAG_subprogram
:
4528 case DW_TAG_inlined_subroutine
:
4529 read_func_scope (die
, cu
);
4531 case DW_TAG_lexical_block
:
4532 case DW_TAG_try_block
:
4533 case DW_TAG_catch_block
:
4534 read_lexical_block_scope (die
, cu
);
4536 case DW_TAG_class_type
:
4537 case DW_TAG_interface_type
:
4538 case DW_TAG_structure_type
:
4539 case DW_TAG_union_type
:
4540 process_structure_scope (die
, cu
);
4542 case DW_TAG_enumeration_type
:
4543 process_enumeration_scope (die
, cu
);
4546 /* These dies have a type, but processing them does not create
4547 a symbol or recurse to process the children. Therefore we can
4548 read them on-demand through read_type_die. */
4549 case DW_TAG_subroutine_type
:
4550 case DW_TAG_set_type
:
4551 case DW_TAG_array_type
:
4552 case DW_TAG_pointer_type
:
4553 case DW_TAG_ptr_to_member_type
:
4554 case DW_TAG_reference_type
:
4555 case DW_TAG_string_type
:
4558 case DW_TAG_base_type
:
4559 case DW_TAG_subrange_type
:
4560 case DW_TAG_typedef
:
4561 /* Add a typedef symbol for the type definition, if it has a
4563 new_symbol (die
, read_type_die (die
, cu
), cu
);
4565 case DW_TAG_common_block
:
4566 read_common_block (die
, cu
);
4568 case DW_TAG_common_inclusion
:
4570 case DW_TAG_namespace
:
4571 processing_has_namespace_info
= 1;
4572 read_namespace (die
, cu
);
4575 processing_has_namespace_info
= 1;
4576 read_module (die
, cu
);
4578 case DW_TAG_imported_declaration
:
4579 case DW_TAG_imported_module
:
4580 processing_has_namespace_info
= 1;
4581 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4582 || cu
->language
!= language_fortran
))
4583 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4584 dwarf_tag_name (die
->tag
));
4585 read_import_statement (die
, cu
);
4588 new_symbol (die
, NULL
, cu
);
4593 /* A helper function for dwarf2_compute_name which determines whether DIE
4594 needs to have the name of the scope prepended to the name listed in the
4598 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4600 struct attribute
*attr
;
4604 case DW_TAG_namespace
:
4605 case DW_TAG_typedef
:
4606 case DW_TAG_class_type
:
4607 case DW_TAG_interface_type
:
4608 case DW_TAG_structure_type
:
4609 case DW_TAG_union_type
:
4610 case DW_TAG_enumeration_type
:
4611 case DW_TAG_enumerator
:
4612 case DW_TAG_subprogram
:
4616 case DW_TAG_variable
:
4617 case DW_TAG_constant
:
4618 /* We only need to prefix "globally" visible variables. These include
4619 any variable marked with DW_AT_external or any variable that
4620 lives in a namespace. [Variables in anonymous namespaces
4621 require prefixing, but they are not DW_AT_external.] */
4623 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4625 struct dwarf2_cu
*spec_cu
= cu
;
4627 return die_needs_namespace (die_specification (die
, &spec_cu
),
4631 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4632 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4633 && die
->parent
->tag
!= DW_TAG_module
)
4635 /* A variable in a lexical block of some kind does not need a
4636 namespace, even though in C++ such variables may be external
4637 and have a mangled name. */
4638 if (die
->parent
->tag
== DW_TAG_lexical_block
4639 || die
->parent
->tag
== DW_TAG_try_block
4640 || die
->parent
->tag
== DW_TAG_catch_block
4641 || die
->parent
->tag
== DW_TAG_subprogram
)
4650 /* Retrieve the last character from a mem_file. */
4653 do_ui_file_peek_last (void *object
, const char *buffer
, long length
)
4655 char *last_char_p
= (char *) object
;
4658 *last_char_p
= buffer
[length
- 1];
4661 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4662 compute the physname for the object, which include a method's
4663 formal parameters (C++/Java) and return type (Java).
4665 For Ada, return the DIE's linkage name rather than the fully qualified
4666 name. PHYSNAME is ignored..
4668 The result is allocated on the objfile_obstack and canonicalized. */
4671 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4675 name
= dwarf2_name (die
, cu
);
4677 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4678 compute it by typename_concat inside GDB. */
4679 if (cu
->language
== language_ada
4680 || (cu
->language
== language_fortran
&& physname
))
4682 /* For Ada unit, we prefer the linkage name over the name, as
4683 the former contains the exported name, which the user expects
4684 to be able to reference. Ideally, we want the user to be able
4685 to reference this entity using either natural or linkage name,
4686 but we haven't started looking at this enhancement yet. */
4687 struct attribute
*attr
;
4689 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4691 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4692 if (attr
&& DW_STRING (attr
))
4693 return DW_STRING (attr
);
4696 /* These are the only languages we know how to qualify names in. */
4698 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4699 || cu
->language
== language_fortran
))
4701 if (die_needs_namespace (die
, cu
))
4705 struct ui_file
*buf
;
4707 prefix
= determine_prefix (die
, cu
);
4708 buf
= mem_fileopen ();
4709 if (*prefix
!= '\0')
4711 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4714 fputs_unfiltered (prefixed_name
, buf
);
4715 xfree (prefixed_name
);
4718 fputs_unfiltered (name
? name
: "", buf
);
4720 /* Template parameters may be specified in the DIE's DW_AT_name, or
4721 as children with DW_TAG_template_type_param or
4722 DW_TAG_value_type_param. If the latter, add them to the name
4723 here. If the name already has template parameters, then
4724 skip this step; some versions of GCC emit both, and
4725 it is more efficient to use the pre-computed name.
4727 Something to keep in mind about this process: it is very
4728 unlikely, or in some cases downright impossible, to produce
4729 something that will match the mangled name of a function.
4730 If the definition of the function has the same debug info,
4731 we should be able to match up with it anyway. But fallbacks
4732 using the minimal symbol, for instance to find a method
4733 implemented in a stripped copy of libstdc++, will not work.
4734 If we do not have debug info for the definition, we will have to
4735 match them up some other way.
4737 When we do name matching there is a related problem with function
4738 templates; two instantiated function templates are allowed to
4739 differ only by their return types, which we do not add here. */
4741 if (cu
->language
== language_cplus
&& strchr (name
, '<') == NULL
)
4743 struct attribute
*attr
;
4744 struct die_info
*child
;
4747 die
->building_fullname
= 1;
4749 for (child
= die
->child
; child
!= NULL
; child
= child
->sibling
)
4754 struct dwarf2_locexpr_baton
*baton
;
4757 if (child
->tag
!= DW_TAG_template_type_param
4758 && child
->tag
!= DW_TAG_template_value_param
)
4763 fputs_unfiltered ("<", buf
);
4767 fputs_unfiltered (", ", buf
);
4769 attr
= dwarf2_attr (child
, DW_AT_type
, cu
);
4772 complaint (&symfile_complaints
,
4773 _("template parameter missing DW_AT_type"));
4774 fputs_unfiltered ("UNKNOWN_TYPE", buf
);
4777 type
= die_type (child
, cu
);
4779 if (child
->tag
== DW_TAG_template_type_param
)
4781 c_print_type (type
, "", buf
, -1, 0);
4785 attr
= dwarf2_attr (child
, DW_AT_const_value
, cu
);
4788 complaint (&symfile_complaints
,
4789 _("template parameter missing DW_AT_const_value"));
4790 fputs_unfiltered ("UNKNOWN_VALUE", buf
);
4794 dwarf2_const_value_attr (attr
, type
, name
,
4795 &cu
->comp_unit_obstack
, cu
,
4796 &value
, &bytes
, &baton
);
4798 if (TYPE_NOSIGN (type
))
4799 /* GDB prints characters as NUMBER 'CHAR'. If that's
4800 changed, this can use value_print instead. */
4801 c_printchar (value
, type
, buf
);
4804 struct value_print_options opts
;
4807 v
= dwarf2_evaluate_loc_desc (type
, NULL
,
4811 else if (bytes
!= NULL
)
4813 v
= allocate_value (type
);
4814 memcpy (value_contents_writeable (v
), bytes
,
4815 TYPE_LENGTH (type
));
4818 v
= value_from_longest (type
, value
);
4820 /* Specify decimal so that we do not depend on the radix. */
4821 get_formatted_print_options (&opts
, 'd');
4823 value_print (v
, buf
, &opts
);
4829 die
->building_fullname
= 0;
4833 /* Close the argument list, with a space if necessary
4834 (nested templates). */
4835 char last_char
= '\0';
4836 ui_file_put (buf
, do_ui_file_peek_last
, &last_char
);
4837 if (last_char
== '>')
4838 fputs_unfiltered (" >", buf
);
4840 fputs_unfiltered (">", buf
);
4844 /* For Java and C++ methods, append formal parameter type
4845 information, if PHYSNAME. */
4847 if (physname
&& die
->tag
== DW_TAG_subprogram
4848 && (cu
->language
== language_cplus
4849 || cu
->language
== language_java
))
4851 struct type
*type
= read_type_die (die
, cu
);
4853 c_type_print_args (type
, buf
, 0, cu
->language
);
4855 if (cu
->language
== language_java
)
4857 /* For java, we must append the return type to method
4859 if (die
->tag
== DW_TAG_subprogram
)
4860 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4863 else if (cu
->language
== language_cplus
)
4865 /* Assume that an artificial first parameter is
4866 "this", but do not crash if it is not. RealView
4867 marks unnamed (and thus unused) parameters as
4868 artificial; there is no way to differentiate
4870 if (TYPE_NFIELDS (type
) > 0
4871 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4872 && TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_PTR
4873 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4874 fputs_unfiltered (" const", buf
);
4878 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4880 ui_file_delete (buf
);
4882 if (cu
->language
== language_cplus
)
4885 = dwarf2_canonicalize_name (name
, cu
,
4886 &cu
->objfile
->objfile_obstack
);
4897 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4898 If scope qualifiers are appropriate they will be added. The result
4899 will be allocated on the objfile_obstack, or NULL if the DIE does
4900 not have a name. NAME may either be from a previous call to
4901 dwarf2_name or NULL.
4903 The output string will be canonicalized (if C++/Java). */
4906 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4908 return dwarf2_compute_name (name
, die
, cu
, 0);
4911 /* Construct a physname for the given DIE in CU. NAME may either be
4912 from a previous call to dwarf2_name or NULL. The result will be
4913 allocated on the objfile_objstack or NULL if the DIE does not have a
4916 The output string will be canonicalized (if C++/Java). */
4919 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4921 return dwarf2_compute_name (name
, die
, cu
, 1);
4924 /* Read the import statement specified by the given die and record it. */
4927 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4929 struct attribute
*import_attr
;
4930 struct die_info
*imported_die
;
4931 struct dwarf2_cu
*imported_cu
;
4932 const char *imported_name
;
4933 const char *imported_name_prefix
;
4934 const char *canonical_name
;
4935 const char *import_alias
;
4936 const char *imported_declaration
= NULL
;
4937 const char *import_prefix
;
4941 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4942 if (import_attr
== NULL
)
4944 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4945 dwarf_tag_name (die
->tag
));
4950 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4951 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4952 if (imported_name
== NULL
)
4954 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4956 The import in the following code:
4970 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4971 <52> DW_AT_decl_file : 1
4972 <53> DW_AT_decl_line : 6
4973 <54> DW_AT_import : <0x75>
4974 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4976 <5b> DW_AT_decl_file : 1
4977 <5c> DW_AT_decl_line : 2
4978 <5d> DW_AT_type : <0x6e>
4980 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4981 <76> DW_AT_byte_size : 4
4982 <77> DW_AT_encoding : 5 (signed)
4984 imports the wrong die ( 0x75 instead of 0x58 ).
4985 This case will be ignored until the gcc bug is fixed. */
4989 /* Figure out the local name after import. */
4990 import_alias
= dwarf2_name (die
, cu
);
4992 /* Figure out where the statement is being imported to. */
4993 import_prefix
= determine_prefix (die
, cu
);
4995 /* Figure out what the scope of the imported die is and prepend it
4996 to the name of the imported die. */
4997 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4999 if (imported_die
->tag
!= DW_TAG_namespace
5000 && imported_die
->tag
!= DW_TAG_module
)
5002 imported_declaration
= imported_name
;
5003 canonical_name
= imported_name_prefix
;
5005 else if (strlen (imported_name_prefix
) > 0)
5007 temp
= alloca (strlen (imported_name_prefix
)
5008 + 2 + strlen (imported_name
) + 1);
5009 strcpy (temp
, imported_name_prefix
);
5010 strcat (temp
, "::");
5011 strcat (temp
, imported_name
);
5012 canonical_name
= temp
;
5015 canonical_name
= imported_name
;
5017 cp_add_using_directive (import_prefix
,
5020 imported_declaration
,
5021 &cu
->objfile
->objfile_obstack
);
5025 initialize_cu_func_list (struct dwarf2_cu
*cu
)
5027 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
5031 free_cu_line_header (void *arg
)
5033 struct dwarf2_cu
*cu
= arg
;
5035 free_line_header (cu
->line_header
);
5036 cu
->line_header
= NULL
;
5040 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
5041 char **name
, char **comp_dir
)
5043 struct attribute
*attr
;
5048 /* Find the filename. Do not use dwarf2_name here, since the filename
5049 is not a source language identifier. */
5050 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5053 *name
= DW_STRING (attr
);
5056 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5058 *comp_dir
= DW_STRING (attr
);
5059 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
5061 *comp_dir
= ldirname (*name
);
5062 if (*comp_dir
!= NULL
)
5063 make_cleanup (xfree
, *comp_dir
);
5065 if (*comp_dir
!= NULL
)
5067 /* Irix 6.2 native cc prepends <machine>.: to the compilation
5068 directory, get rid of it. */
5069 char *cp
= strchr (*comp_dir
, ':');
5071 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
5076 *name
= "<unknown>";
5080 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5082 struct objfile
*objfile
= cu
->objfile
;
5083 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5084 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
5085 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
5086 struct attribute
*attr
;
5088 char *comp_dir
= NULL
;
5089 struct die_info
*child_die
;
5090 bfd
*abfd
= objfile
->obfd
;
5091 struct line_header
*line_header
= 0;
5094 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5096 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
5098 /* If we didn't find a lowpc, set it to highpc to avoid complaints
5099 from finish_block. */
5100 if (lowpc
== ((CORE_ADDR
) -1))
5105 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
5107 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5110 set_cu_language (DW_UNSND (attr
), cu
);
5113 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5115 cu
->producer
= DW_STRING (attr
);
5117 /* We assume that we're processing GCC output. */
5118 processing_gcc_compilation
= 2;
5120 processing_has_namespace_info
= 0;
5122 start_symtab (name
, comp_dir
, lowpc
);
5123 record_debugformat ("DWARF 2");
5124 record_producer (cu
->producer
);
5126 initialize_cu_func_list (cu
);
5128 /* Decode line number information if present. We do this before
5129 processing child DIEs, so that the line header table is available
5130 for DW_AT_decl_file. */
5131 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
5134 unsigned int line_offset
= DW_UNSND (attr
);
5135 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
5138 cu
->line_header
= line_header
;
5139 make_cleanup (free_cu_line_header
, cu
);
5140 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
5144 /* Process all dies in compilation unit. */
5145 if (die
->child
!= NULL
)
5147 child_die
= die
->child
;
5148 while (child_die
&& child_die
->tag
)
5150 process_die (child_die
, cu
);
5151 child_die
= sibling_die (child_die
);
5155 /* Decode macro information, if present. Dwarf 2 macro information
5156 refers to information in the line number info statement program
5157 header, so we can only read it if we've read the header
5159 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
5160 if (attr
&& line_header
)
5162 unsigned int macro_offset
= DW_UNSND (attr
);
5164 dwarf_decode_macros (line_header
, macro_offset
,
5165 comp_dir
, abfd
, cu
);
5167 do_cleanups (back_to
);
5170 /* For TUs we want to skip the first top level sibling if it's not the
5171 actual type being defined by this TU. In this case the first top
5172 level sibling is there to provide context only. */
5175 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5177 struct objfile
*objfile
= cu
->objfile
;
5178 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5180 struct attribute
*attr
;
5182 char *comp_dir
= NULL
;
5183 struct die_info
*child_die
;
5184 bfd
*abfd
= objfile
->obfd
;
5186 /* start_symtab needs a low pc, but we don't really have one.
5187 Do what read_file_scope would do in the absence of such info. */
5188 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5190 /* Find the filename. Do not use dwarf2_name here, since the filename
5191 is not a source language identifier. */
5192 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
5194 name
= DW_STRING (attr
);
5196 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
5198 comp_dir
= DW_STRING (attr
);
5199 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
5201 comp_dir
= ldirname (name
);
5202 if (comp_dir
!= NULL
)
5203 make_cleanup (xfree
, comp_dir
);
5209 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
5211 set_cu_language (DW_UNSND (attr
), cu
);
5213 /* This isn't technically needed today. It is done for symmetry
5214 with read_file_scope. */
5215 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
5217 cu
->producer
= DW_STRING (attr
);
5219 /* We assume that we're processing GCC output. */
5220 processing_gcc_compilation
= 2;
5222 processing_has_namespace_info
= 0;
5224 start_symtab (name
, comp_dir
, lowpc
);
5225 record_debugformat ("DWARF 2");
5226 record_producer (cu
->producer
);
5228 /* Process the dies in the type unit. */
5229 if (die
->child
== NULL
)
5231 dump_die_for_error (die
);
5232 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
5233 bfd_get_filename (abfd
));
5236 child_die
= die
->child
;
5238 while (child_die
&& child_die
->tag
)
5240 process_die (child_die
, cu
);
5242 child_die
= sibling_die (child_die
);
5245 do_cleanups (back_to
);
5249 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
5250 struct dwarf2_cu
*cu
)
5252 struct function_range
*thisfn
;
5254 thisfn
= (struct function_range
*)
5255 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
5256 thisfn
->name
= name
;
5257 thisfn
->lowpc
= lowpc
;
5258 thisfn
->highpc
= highpc
;
5259 thisfn
->seen_line
= 0;
5260 thisfn
->next
= NULL
;
5262 if (cu
->last_fn
== NULL
)
5263 cu
->first_fn
= thisfn
;
5265 cu
->last_fn
->next
= thisfn
;
5267 cu
->last_fn
= thisfn
;
5270 /* qsort helper for inherit_abstract_dies. */
5273 unsigned_int_compar (const void *ap
, const void *bp
)
5275 unsigned int a
= *(unsigned int *) ap
;
5276 unsigned int b
= *(unsigned int *) bp
;
5278 return (a
> b
) - (b
> a
);
5281 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
5282 Inherit only the children of the DW_AT_abstract_origin DIE not being already
5283 referenced by DW_AT_abstract_origin from the children of the current DIE. */
5286 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
5288 struct die_info
*child_die
;
5289 unsigned die_children_count
;
5290 /* CU offsets which were referenced by children of the current DIE. */
5292 unsigned *offsets_end
, *offsetp
;
5293 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
5294 struct die_info
*origin_die
;
5295 /* Iterator of the ORIGIN_DIE children. */
5296 struct die_info
*origin_child_die
;
5297 struct cleanup
*cleanups
;
5298 struct attribute
*attr
;
5299 struct dwarf2_cu
*origin_cu
;
5300 struct pending
**origin_previous_list_in_scope
;
5302 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
5306 /* Note that following die references may follow to a die in a
5310 origin_die
= follow_die_ref (die
, attr
, &origin_cu
);
5312 /* We're inheriting ORIGIN's children into the scope we'd put DIE's
5314 origin_previous_list_in_scope
= origin_cu
->list_in_scope
;
5315 origin_cu
->list_in_scope
= cu
->list_in_scope
;
5317 if (die
->tag
!= origin_die
->tag
5318 && !(die
->tag
== DW_TAG_inlined_subroutine
5319 && origin_die
->tag
== DW_TAG_subprogram
))
5320 complaint (&symfile_complaints
,
5321 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
5322 die
->offset
, origin_die
->offset
);
5324 child_die
= die
->child
;
5325 die_children_count
= 0;
5326 while (child_die
&& child_die
->tag
)
5328 child_die
= sibling_die (child_die
);
5329 die_children_count
++;
5331 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
5332 cleanups
= make_cleanup (xfree
, offsets
);
5334 offsets_end
= offsets
;
5335 child_die
= die
->child
;
5336 while (child_die
&& child_die
->tag
)
5338 /* For each CHILD_DIE, find the corresponding child of
5339 ORIGIN_DIE. If there is more than one layer of
5340 DW_AT_abstract_origin, follow them all; there shouldn't be,
5341 but GCC versions at least through 4.4 generate this (GCC PR
5343 struct die_info
*child_origin_die
= child_die
;
5344 struct dwarf2_cu
*child_origin_cu
= cu
;
5348 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
,
5352 child_origin_die
= follow_die_ref (child_origin_die
, attr
,
5356 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
5357 counterpart may exist. */
5358 if (child_origin_die
!= child_die
)
5360 if (child_die
->tag
!= child_origin_die
->tag
5361 && !(child_die
->tag
== DW_TAG_inlined_subroutine
5362 && child_origin_die
->tag
== DW_TAG_subprogram
))
5363 complaint (&symfile_complaints
,
5364 _("Child DIE 0x%x and its abstract origin 0x%x have "
5365 "different tags"), child_die
->offset
,
5366 child_origin_die
->offset
);
5367 if (child_origin_die
->parent
!= origin_die
)
5368 complaint (&symfile_complaints
,
5369 _("Child DIE 0x%x and its abstract origin 0x%x have "
5370 "different parents"), child_die
->offset
,
5371 child_origin_die
->offset
);
5373 *offsets_end
++ = child_origin_die
->offset
;
5375 child_die
= sibling_die (child_die
);
5377 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
5378 unsigned_int_compar
);
5379 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
5380 if (offsetp
[-1] == *offsetp
)
5381 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
5382 "to DIE 0x%x as their abstract origin"),
5383 die
->offset
, *offsetp
);
5386 origin_child_die
= origin_die
->child
;
5387 while (origin_child_die
&& origin_child_die
->tag
)
5389 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
5390 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
5392 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
5394 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
5395 process_die (origin_child_die
, origin_cu
);
5397 origin_child_die
= sibling_die (origin_child_die
);
5399 origin_cu
->list_in_scope
= origin_previous_list_in_scope
;
5401 do_cleanups (cleanups
);
5405 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5407 struct objfile
*objfile
= cu
->objfile
;
5408 struct context_stack
*new;
5411 struct die_info
*child_die
;
5412 struct attribute
*attr
, *call_line
, *call_file
;
5415 struct block
*block
;
5416 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
5417 VEC (symbolp
) *template_args
= NULL
;
5418 struct template_symbol
*templ_func
= NULL
;
5422 /* If we do not have call site information, we can't show the
5423 caller of this inlined function. That's too confusing, so
5424 only use the scope for local variables. */
5425 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
5426 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
5427 if (call_line
== NULL
|| call_file
== NULL
)
5429 read_lexical_block_scope (die
, cu
);
5434 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5436 name
= dwarf2_name (die
, cu
);
5438 /* Ignore functions with missing or empty names. These are actually
5439 illegal according to the DWARF standard. */
5442 complaint (&symfile_complaints
,
5443 _("missing name for subprogram DIE at %d"), die
->offset
);
5447 /* Ignore functions with missing or invalid low and high pc attributes. */
5448 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5450 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
5451 if (!attr
|| !DW_UNSND (attr
))
5452 complaint (&symfile_complaints
,
5453 _("cannot get low and high bounds for subprogram DIE at %d"),
5461 /* Record the function range for dwarf_decode_lines. */
5462 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
5464 /* If we have any template arguments, then we must allocate a
5465 different sort of symbol. */
5466 for (child_die
= die
->child
; child_die
; child_die
= sibling_die (child_die
))
5468 if (child_die
->tag
== DW_TAG_template_type_param
5469 || child_die
->tag
== DW_TAG_template_value_param
)
5471 templ_func
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
5472 struct template_symbol
);
5473 templ_func
->base
.is_cplus_template_function
= 1;
5478 new = push_context (0, lowpc
);
5479 new->name
= new_symbol_full (die
, read_type_die (die
, cu
), cu
,
5480 (struct symbol
*) templ_func
);
5482 /* If there is a location expression for DW_AT_frame_base, record
5484 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
5486 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
5487 expression is being recorded directly in the function's symbol
5488 and not in a separate frame-base object. I guess this hack is
5489 to avoid adding some sort of frame-base adjunct/annex to the
5490 function's symbol :-(. The problem with doing this is that it
5491 results in a function symbol with a location expression that
5492 has nothing to do with the location of the function, ouch! The
5493 relationship should be: a function's symbol has-a frame base; a
5494 frame-base has-a location expression. */
5495 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
5497 cu
->list_in_scope
= &local_symbols
;
5499 if (die
->child
!= NULL
)
5501 child_die
= die
->child
;
5502 while (child_die
&& child_die
->tag
)
5504 if (child_die
->tag
== DW_TAG_template_type_param
5505 || child_die
->tag
== DW_TAG_template_value_param
)
5507 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
5510 VEC_safe_push (symbolp
, template_args
, arg
);
5513 process_die (child_die
, cu
);
5514 child_die
= sibling_die (child_die
);
5518 inherit_abstract_dies (die
, cu
);
5520 /* If we have a DW_AT_specification, we might need to import using
5521 directives from the context of the specification DIE. See the
5522 comment in determine_prefix. */
5523 if (cu
->language
== language_cplus
5524 && dwarf2_attr (die
, DW_AT_specification
, cu
))
5526 struct dwarf2_cu
*spec_cu
= cu
;
5527 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
5531 child_die
= spec_die
->child
;
5532 while (child_die
&& child_die
->tag
)
5534 if (child_die
->tag
== DW_TAG_imported_module
)
5535 process_die (child_die
, spec_cu
);
5536 child_die
= sibling_die (child_die
);
5539 /* In some cases, GCC generates specification DIEs that
5540 themselves contain DW_AT_specification attributes. */
5541 spec_die
= die_specification (spec_die
, &spec_cu
);
5545 new = pop_context ();
5546 /* Make a block for the local symbols within. */
5547 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5548 lowpc
, highpc
, objfile
);
5550 /* For C++, set the block's scope. */
5551 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5552 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5553 determine_prefix (die
, cu
),
5554 processing_has_namespace_info
);
5556 /* If we have address ranges, record them. */
5557 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5559 /* Attach template arguments to function. */
5560 if (! VEC_empty (symbolp
, template_args
))
5562 gdb_assert (templ_func
!= NULL
);
5564 templ_func
->n_template_arguments
= VEC_length (symbolp
, template_args
);
5565 templ_func
->template_arguments
5566 = obstack_alloc (&objfile
->objfile_obstack
,
5567 (templ_func
->n_template_arguments
5568 * sizeof (struct symbol
*)));
5569 memcpy (templ_func
->template_arguments
,
5570 VEC_address (symbolp
, template_args
),
5571 (templ_func
->n_template_arguments
* sizeof (struct symbol
*)));
5572 VEC_free (symbolp
, template_args
);
5575 /* In C++, we can have functions nested inside functions (e.g., when
5576 a function declares a class that has methods). This means that
5577 when we finish processing a function scope, we may need to go
5578 back to building a containing block's symbol lists. */
5579 local_symbols
= new->locals
;
5580 param_symbols
= new->params
;
5581 using_directives
= new->using_directives
;
5583 /* If we've finished processing a top-level function, subsequent
5584 symbols go in the file symbol list. */
5585 if (outermost_context_p ())
5586 cu
->list_in_scope
= &file_symbols
;
5589 /* Process all the DIES contained within a lexical block scope. Start
5590 a new scope, process the dies, and then close the scope. */
5593 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5595 struct objfile
*objfile
= cu
->objfile
;
5596 struct context_stack
*new;
5597 CORE_ADDR lowpc
, highpc
;
5598 struct die_info
*child_die
;
5601 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5603 /* Ignore blocks with missing or invalid low and high pc attributes. */
5604 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5605 as multiple lexical blocks? Handling children in a sane way would
5606 be nasty. Might be easier to properly extend generic blocks to
5608 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5613 push_context (0, lowpc
);
5614 if (die
->child
!= NULL
)
5616 child_die
= die
->child
;
5617 while (child_die
&& child_die
->tag
)
5619 process_die (child_die
, cu
);
5620 child_die
= sibling_die (child_die
);
5623 new = pop_context ();
5625 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5628 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5631 /* Note that recording ranges after traversing children, as we
5632 do here, means that recording a parent's ranges entails
5633 walking across all its children's ranges as they appear in
5634 the address map, which is quadratic behavior.
5636 It would be nicer to record the parent's ranges before
5637 traversing its children, simply overriding whatever you find
5638 there. But since we don't even decide whether to create a
5639 block until after we've traversed its children, that's hard
5641 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5643 local_symbols
= new->locals
;
5644 using_directives
= new->using_directives
;
5647 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5648 Return 1 if the attributes are present and valid, otherwise, return 0.
5649 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5652 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5653 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5654 struct partial_symtab
*ranges_pst
)
5656 struct objfile
*objfile
= cu
->objfile
;
5657 struct comp_unit_head
*cu_header
= &cu
->header
;
5658 bfd
*obfd
= objfile
->obfd
;
5659 unsigned int addr_size
= cu_header
->addr_size
;
5660 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5661 /* Base address selection entry. */
5672 found_base
= cu
->base_known
;
5673 base
= cu
->base_address
;
5675 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5676 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5678 complaint (&symfile_complaints
,
5679 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5683 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5685 /* Read in the largest possible address. */
5686 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5687 if ((marker
& mask
) == mask
)
5689 /* If we found the largest possible address, then
5690 read the base address. */
5691 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5692 buffer
+= 2 * addr_size
;
5693 offset
+= 2 * addr_size
;
5699 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5703 CORE_ADDR range_beginning
, range_end
;
5705 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5706 buffer
+= addr_size
;
5707 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5708 buffer
+= addr_size
;
5709 offset
+= 2 * addr_size
;
5711 /* An end of list marker is a pair of zero addresses. */
5712 if (range_beginning
== 0 && range_end
== 0)
5713 /* Found the end of list entry. */
5716 /* Each base address selection entry is a pair of 2 values.
5717 The first is the largest possible address, the second is
5718 the base address. Check for a base address here. */
5719 if ((range_beginning
& mask
) == mask
)
5721 /* If we found the largest possible address, then
5722 read the base address. */
5723 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5730 /* We have no valid base address for the ranges
5732 complaint (&symfile_complaints
,
5733 _("Invalid .debug_ranges data (no base address)"));
5737 range_beginning
+= base
;
5740 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5741 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5742 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5745 /* FIXME: This is recording everything as a low-high
5746 segment of consecutive addresses. We should have a
5747 data structure for discontiguous block ranges
5751 low
= range_beginning
;
5757 if (range_beginning
< low
)
5758 low
= range_beginning
;
5759 if (range_end
> high
)
5765 /* If the first entry is an end-of-list marker, the range
5766 describes an empty scope, i.e. no instructions. */
5772 *high_return
= high
;
5776 /* Get low and high pc attributes from a die. Return 1 if the attributes
5777 are present and valid, otherwise, return 0. Return -1 if the range is
5778 discontinuous, i.e. derived from DW_AT_ranges information. */
5780 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5781 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5782 struct partial_symtab
*pst
)
5784 struct attribute
*attr
;
5789 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5792 high
= DW_ADDR (attr
);
5793 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5795 low
= DW_ADDR (attr
);
5797 /* Found high w/o low attribute. */
5800 /* Found consecutive range of addresses. */
5805 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5808 /* Value of the DW_AT_ranges attribute is the offset in the
5809 .debug_ranges section. */
5810 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5812 /* Found discontinuous range of addresses. */
5820 /* When using the GNU linker, .gnu.linkonce. sections are used to
5821 eliminate duplicate copies of functions and vtables and such.
5822 The linker will arbitrarily choose one and discard the others.
5823 The AT_*_pc values for such functions refer to local labels in
5824 these sections. If the section from that file was discarded, the
5825 labels are not in the output, so the relocs get a value of 0.
5826 If this is a discarded function, mark the pc bounds as invalid,
5827 so that GDB will ignore it. */
5828 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5836 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5837 its low and high PC addresses. Do nothing if these addresses could not
5838 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5839 and HIGHPC to the high address if greater than HIGHPC. */
5842 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5843 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5844 struct dwarf2_cu
*cu
)
5846 CORE_ADDR low
, high
;
5847 struct die_info
*child
= die
->child
;
5849 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5851 *lowpc
= min (*lowpc
, low
);
5852 *highpc
= max (*highpc
, high
);
5855 /* If the language does not allow nested subprograms (either inside
5856 subprograms or lexical blocks), we're done. */
5857 if (cu
->language
!= language_ada
)
5860 /* Check all the children of the given DIE. If it contains nested
5861 subprograms, then check their pc bounds. Likewise, we need to
5862 check lexical blocks as well, as they may also contain subprogram
5864 while (child
&& child
->tag
)
5866 if (child
->tag
== DW_TAG_subprogram
5867 || child
->tag
== DW_TAG_lexical_block
)
5868 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5869 child
= sibling_die (child
);
5873 /* Get the low and high pc's represented by the scope DIE, and store
5874 them in *LOWPC and *HIGHPC. If the correct values can't be
5875 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5878 get_scope_pc_bounds (struct die_info
*die
,
5879 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5880 struct dwarf2_cu
*cu
)
5882 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5883 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5884 CORE_ADDR current_low
, current_high
;
5886 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5888 best_low
= current_low
;
5889 best_high
= current_high
;
5893 struct die_info
*child
= die
->child
;
5895 while (child
&& child
->tag
)
5897 switch (child
->tag
) {
5898 case DW_TAG_subprogram
:
5899 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5901 case DW_TAG_namespace
:
5903 /* FIXME: carlton/2004-01-16: Should we do this for
5904 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5905 that current GCC's always emit the DIEs corresponding
5906 to definitions of methods of classes as children of a
5907 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5908 the DIEs giving the declarations, which could be
5909 anywhere). But I don't see any reason why the
5910 standards says that they have to be there. */
5911 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5913 if (current_low
!= ((CORE_ADDR
) -1))
5915 best_low
= min (best_low
, current_low
);
5916 best_high
= max (best_high
, current_high
);
5924 child
= sibling_die (child
);
5929 *highpc
= best_high
;
5932 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5935 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5936 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5938 struct attribute
*attr
;
5940 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5943 CORE_ADDR high
= DW_ADDR (attr
);
5945 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5948 CORE_ADDR low
= DW_ADDR (attr
);
5950 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5954 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5957 bfd
*obfd
= cu
->objfile
->obfd
;
5959 /* The value of the DW_AT_ranges attribute is the offset of the
5960 address range list in the .debug_ranges section. */
5961 unsigned long offset
= DW_UNSND (attr
);
5962 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5964 /* For some target architectures, but not others, the
5965 read_address function sign-extends the addresses it returns.
5966 To recognize base address selection entries, we need a
5968 unsigned int addr_size
= cu
->header
.addr_size
;
5969 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5971 /* The base address, to which the next pair is relative. Note
5972 that this 'base' is a DWARF concept: most entries in a range
5973 list are relative, to reduce the number of relocs against the
5974 debugging information. This is separate from this function's
5975 'baseaddr' argument, which GDB uses to relocate debugging
5976 information from a shared library based on the address at
5977 which the library was loaded. */
5978 CORE_ADDR base
= cu
->base_address
;
5979 int base_known
= cu
->base_known
;
5981 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5982 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5984 complaint (&symfile_complaints
,
5985 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5992 unsigned int bytes_read
;
5993 CORE_ADDR start
, end
;
5995 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5996 buffer
+= bytes_read
;
5997 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5998 buffer
+= bytes_read
;
6000 /* Did we find the end of the range list? */
6001 if (start
== 0 && end
== 0)
6004 /* Did we find a base address selection entry? */
6005 else if ((start
& base_select_mask
) == base_select_mask
)
6011 /* We found an ordinary address range. */
6016 complaint (&symfile_complaints
,
6017 _("Invalid .debug_ranges data (no base address)"));
6021 record_block_range (block
,
6022 baseaddr
+ base
+ start
,
6023 baseaddr
+ base
+ end
- 1);
6029 /* Add an aggregate field to the field list. */
6032 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
6033 struct dwarf2_cu
*cu
)
6035 struct objfile
*objfile
= cu
->objfile
;
6036 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6037 struct nextfield
*new_field
;
6038 struct attribute
*attr
;
6040 char *fieldname
= "";
6042 /* Allocate a new field list entry and link it in. */
6043 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
6044 make_cleanup (xfree
, new_field
);
6045 memset (new_field
, 0, sizeof (struct nextfield
));
6047 if (die
->tag
== DW_TAG_inheritance
)
6049 new_field
->next
= fip
->baseclasses
;
6050 fip
->baseclasses
= new_field
;
6054 new_field
->next
= fip
->fields
;
6055 fip
->fields
= new_field
;
6059 /* Handle accessibility and virtuality of field.
6060 The default accessibility for members is public, the default
6061 accessibility for inheritance is private. */
6062 if (die
->tag
!= DW_TAG_inheritance
)
6063 new_field
->accessibility
= DW_ACCESS_public
;
6065 new_field
->accessibility
= DW_ACCESS_private
;
6066 new_field
->virtuality
= DW_VIRTUALITY_none
;
6068 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6070 new_field
->accessibility
= DW_UNSND (attr
);
6071 if (new_field
->accessibility
!= DW_ACCESS_public
)
6072 fip
->non_public_fields
= 1;
6073 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6075 new_field
->virtuality
= DW_UNSND (attr
);
6077 fp
= &new_field
->field
;
6079 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
6081 /* Data member other than a C++ static data member. */
6083 /* Get type of field. */
6084 fp
->type
= die_type (die
, cu
);
6086 SET_FIELD_BITPOS (*fp
, 0);
6088 /* Get bit size of field (zero if none). */
6089 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
6092 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
6096 FIELD_BITSIZE (*fp
) = 0;
6099 /* Get bit offset of field. */
6100 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6103 int byte_offset
= 0;
6105 if (attr_form_is_section_offset (attr
))
6106 dwarf2_complex_location_expr_complaint ();
6107 else if (attr_form_is_constant (attr
))
6108 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6109 else if (attr_form_is_block (attr
))
6110 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6112 dwarf2_complex_location_expr_complaint ();
6114 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6116 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
6119 if (gdbarch_bits_big_endian (gdbarch
))
6121 /* For big endian bits, the DW_AT_bit_offset gives the
6122 additional bit offset from the MSB of the containing
6123 anonymous object to the MSB of the field. We don't
6124 have to do anything special since we don't need to
6125 know the size of the anonymous object. */
6126 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
6130 /* For little endian bits, compute the bit offset to the
6131 MSB of the anonymous object, subtract off the number of
6132 bits from the MSB of the field to the MSB of the
6133 object, and then subtract off the number of bits of
6134 the field itself. The result is the bit offset of
6135 the LSB of the field. */
6137 int bit_offset
= DW_UNSND (attr
);
6139 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6142 /* The size of the anonymous object containing
6143 the bit field is explicit, so use the
6144 indicated size (in bytes). */
6145 anonymous_size
= DW_UNSND (attr
);
6149 /* The size of the anonymous object containing
6150 the bit field must be inferred from the type
6151 attribute of the data member containing the
6153 anonymous_size
= TYPE_LENGTH (fp
->type
);
6155 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
6156 - bit_offset
- FIELD_BITSIZE (*fp
);
6160 /* Get name of field. */
6161 fieldname
= dwarf2_name (die
, cu
);
6162 if (fieldname
== NULL
)
6165 /* The name is already allocated along with this objfile, so we don't
6166 need to duplicate it for the type. */
6167 fp
->name
= fieldname
;
6169 /* Change accessibility for artificial fields (e.g. virtual table
6170 pointer or virtual base class pointer) to private. */
6171 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
6173 FIELD_ARTIFICIAL (*fp
) = 1;
6174 new_field
->accessibility
= DW_ACCESS_private
;
6175 fip
->non_public_fields
= 1;
6178 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
6180 /* C++ static member. */
6182 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
6183 is a declaration, but all versions of G++ as of this writing
6184 (so through at least 3.2.1) incorrectly generate
6185 DW_TAG_variable tags. */
6189 /* Get name of field. */
6190 fieldname
= dwarf2_name (die
, cu
);
6191 if (fieldname
== NULL
)
6194 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6196 /* Only create a symbol if this is an external value.
6197 new_symbol checks this and puts the value in the global symbol
6198 table, which we want. If it is not external, new_symbol
6199 will try to put the value in cu->list_in_scope which is wrong. */
6200 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
6202 /* A static const member, not much different than an enum as far as
6203 we're concerned, except that we can support more types. */
6204 new_symbol (die
, NULL
, cu
);
6207 /* Get physical name. */
6208 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6210 /* The name is already allocated along with this objfile, so we don't
6211 need to duplicate it for the type. */
6212 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
6213 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6214 FIELD_NAME (*fp
) = fieldname
;
6216 else if (die
->tag
== DW_TAG_inheritance
)
6218 /* C++ base class field. */
6219 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
6222 int byte_offset
= 0;
6224 if (attr_form_is_section_offset (attr
))
6225 dwarf2_complex_location_expr_complaint ();
6226 else if (attr_form_is_constant (attr
))
6227 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6228 else if (attr_form_is_block (attr
))
6229 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6231 dwarf2_complex_location_expr_complaint ();
6233 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
6235 FIELD_BITSIZE (*fp
) = 0;
6236 FIELD_TYPE (*fp
) = die_type (die
, cu
);
6237 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
6238 fip
->nbaseclasses
++;
6242 /* Add a typedef defined in the scope of the FIP's class. */
6245 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
6246 struct dwarf2_cu
*cu
)
6248 struct objfile
*objfile
= cu
->objfile
;
6249 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6250 struct typedef_field_list
*new_field
;
6251 struct attribute
*attr
;
6252 struct typedef_field
*fp
;
6253 char *fieldname
= "";
6255 /* Allocate a new field list entry and link it in. */
6256 new_field
= xzalloc (sizeof (*new_field
));
6257 make_cleanup (xfree
, new_field
);
6259 gdb_assert (die
->tag
== DW_TAG_typedef
);
6261 fp
= &new_field
->field
;
6263 /* Get name of field. */
6264 fp
->name
= dwarf2_name (die
, cu
);
6265 if (fp
->name
== NULL
)
6268 fp
->type
= read_type_die (die
, cu
);
6270 new_field
->next
= fip
->typedef_field_list
;
6271 fip
->typedef_field_list
= new_field
;
6272 fip
->typedef_field_list_count
++;
6275 /* Create the vector of fields, and attach it to the type. */
6278 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
6279 struct dwarf2_cu
*cu
)
6281 int nfields
= fip
->nfields
;
6283 /* Record the field count, allocate space for the array of fields,
6284 and create blank accessibility bitfields if necessary. */
6285 TYPE_NFIELDS (type
) = nfields
;
6286 TYPE_FIELDS (type
) = (struct field
*)
6287 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
6288 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
6290 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
6292 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6294 TYPE_FIELD_PRIVATE_BITS (type
) =
6295 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6296 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
6298 TYPE_FIELD_PROTECTED_BITS (type
) =
6299 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6300 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
6302 TYPE_FIELD_IGNORE_BITS (type
) =
6303 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
6304 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
6307 /* If the type has baseclasses, allocate and clear a bit vector for
6308 TYPE_FIELD_VIRTUAL_BITS. */
6309 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
6311 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
6312 unsigned char *pointer
;
6314 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6315 pointer
= TYPE_ALLOC (type
, num_bytes
);
6316 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
6317 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
6318 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
6321 /* Copy the saved-up fields into the field vector. Start from the head
6322 of the list, adding to the tail of the field array, so that they end
6323 up in the same order in the array in which they were added to the list. */
6324 while (nfields
-- > 0)
6326 struct nextfield
*fieldp
;
6330 fieldp
= fip
->fields
;
6331 fip
->fields
= fieldp
->next
;
6335 fieldp
= fip
->baseclasses
;
6336 fip
->baseclasses
= fieldp
->next
;
6339 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
6340 switch (fieldp
->accessibility
)
6342 case DW_ACCESS_private
:
6343 if (cu
->language
!= language_ada
)
6344 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
6347 case DW_ACCESS_protected
:
6348 if (cu
->language
!= language_ada
)
6349 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
6352 case DW_ACCESS_public
:
6356 /* Unknown accessibility. Complain and treat it as public. */
6358 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
6359 fieldp
->accessibility
);
6363 if (nfields
< fip
->nbaseclasses
)
6365 switch (fieldp
->virtuality
)
6367 case DW_VIRTUALITY_virtual
:
6368 case DW_VIRTUALITY_pure_virtual
:
6369 if (cu
->language
== language_ada
)
6370 error ("unexpected virtuality in component of Ada type");
6371 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
6378 /* Add a member function to the proper fieldlist. */
6381 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
6382 struct type
*type
, struct dwarf2_cu
*cu
)
6384 struct objfile
*objfile
= cu
->objfile
;
6385 struct attribute
*attr
;
6386 struct fnfieldlist
*flp
;
6388 struct fn_field
*fnp
;
6390 struct nextfnfield
*new_fnfield
;
6391 struct type
*this_type
;
6393 if (cu
->language
== language_ada
)
6394 error ("unexpected member function in Ada type");
6396 /* Get name of member function. */
6397 fieldname
= dwarf2_name (die
, cu
);
6398 if (fieldname
== NULL
)
6401 /* Look up member function name in fieldlist. */
6402 for (i
= 0; i
< fip
->nfnfields
; i
++)
6404 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
6408 /* Create new list element if necessary. */
6409 if (i
< fip
->nfnfields
)
6410 flp
= &fip
->fnfieldlists
[i
];
6413 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6415 fip
->fnfieldlists
= (struct fnfieldlist
*)
6416 xrealloc (fip
->fnfieldlists
,
6417 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
6418 * sizeof (struct fnfieldlist
));
6419 if (fip
->nfnfields
== 0)
6420 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
6422 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
6423 flp
->name
= fieldname
;
6426 i
= fip
->nfnfields
++;
6429 /* Create a new member function field and chain it to the field list
6431 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
6432 make_cleanup (xfree
, new_fnfield
);
6433 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
6434 new_fnfield
->next
= flp
->head
;
6435 flp
->head
= new_fnfield
;
6438 /* Fill in the member function field info. */
6439 fnp
= &new_fnfield
->fnfield
;
6441 /* Delay processing of the physname until later. */
6442 if (cu
->language
== language_cplus
|| cu
->language
== language_java
)
6444 add_to_method_list (type
, i
, flp
->length
- 1, fieldname
,
6449 char *physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
6450 fnp
->physname
= physname
? physname
: "";
6453 fnp
->type
= alloc_type (objfile
);
6454 this_type
= read_type_die (die
, cu
);
6455 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
6457 int nparams
= TYPE_NFIELDS (this_type
);
6459 /* TYPE is the domain of this method, and THIS_TYPE is the type
6460 of the method itself (TYPE_CODE_METHOD). */
6461 smash_to_method_type (fnp
->type
, type
,
6462 TYPE_TARGET_TYPE (this_type
),
6463 TYPE_FIELDS (this_type
),
6464 TYPE_NFIELDS (this_type
),
6465 TYPE_VARARGS (this_type
));
6467 /* Handle static member functions.
6468 Dwarf2 has no clean way to discern C++ static and non-static
6469 member functions. G++ helps GDB by marking the first
6470 parameter for non-static member functions (which is the
6471 this pointer) as artificial. We obtain this information
6472 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
6473 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
6474 fnp
->voffset
= VOFFSET_STATIC
;
6477 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
6478 dwarf2_full_name (fieldname
, die
, cu
));
6480 /* Get fcontext from DW_AT_containing_type if present. */
6481 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6482 fnp
->fcontext
= die_containing_type (die
, cu
);
6484 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
6485 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
6487 /* Get accessibility. */
6488 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
6491 switch (DW_UNSND (attr
))
6493 case DW_ACCESS_private
:
6494 fnp
->is_private
= 1;
6496 case DW_ACCESS_protected
:
6497 fnp
->is_protected
= 1;
6502 /* Check for artificial methods. */
6503 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
6504 if (attr
&& DW_UNSND (attr
) != 0)
6505 fnp
->is_artificial
= 1;
6507 /* Get index in virtual function table if it is a virtual member
6508 function. For older versions of GCC, this is an offset in the
6509 appropriate virtual table, as specified by DW_AT_containing_type.
6510 For everyone else, it is an expression to be evaluated relative
6511 to the object address. */
6513 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
6516 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
6518 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
6520 /* Old-style GCC. */
6521 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
6523 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6524 || (DW_BLOCK (attr
)->size
> 1
6525 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
6526 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
6528 struct dwarf_block blk
;
6531 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
6533 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
6534 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
6535 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6536 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
6537 dwarf2_complex_location_expr_complaint ();
6539 fnp
->voffset
/= cu
->header
.addr_size
;
6543 dwarf2_complex_location_expr_complaint ();
6546 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
6548 else if (attr_form_is_section_offset (attr
))
6550 dwarf2_complex_location_expr_complaint ();
6554 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
6560 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
6561 if (attr
&& DW_UNSND (attr
))
6563 /* GCC does this, as of 2008-08-25; PR debug/37237. */
6564 complaint (&symfile_complaints
,
6565 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6566 fieldname
, die
->offset
);
6567 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6568 TYPE_CPLUS_DYNAMIC (type
) = 1;
6573 /* Create the vector of member function fields, and attach it to the type. */
6576 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6577 struct dwarf2_cu
*cu
)
6579 struct fnfieldlist
*flp
;
6580 int total_length
= 0;
6583 if (cu
->language
== language_ada
)
6584 error ("unexpected member functions in Ada type");
6586 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6587 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6588 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6590 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6592 struct nextfnfield
*nfp
= flp
->head
;
6593 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6596 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6597 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6598 fn_flp
->fn_fields
= (struct fn_field
*)
6599 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6600 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6601 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6603 total_length
+= flp
->length
;
6606 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6607 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6610 /* Returns non-zero if NAME is the name of a vtable member in CU's
6611 language, zero otherwise. */
6613 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6615 static const char vptr
[] = "_vptr";
6616 static const char vtable
[] = "vtable";
6618 /* Look for the C++ and Java forms of the vtable. */
6619 if ((cu
->language
== language_java
6620 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6621 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6622 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6628 /* GCC outputs unnamed structures that are really pointers to member
6629 functions, with the ABI-specified layout. If TYPE describes
6630 such a structure, smash it into a member function type.
6632 GCC shouldn't do this; it should just output pointer to member DIEs.
6633 This is GCC PR debug/28767. */
6636 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6638 struct type
*pfn_type
, *domain_type
, *new_type
;
6640 /* Check for a structure with no name and two children. */
6641 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6644 /* Check for __pfn and __delta members. */
6645 if (TYPE_FIELD_NAME (type
, 0) == NULL
6646 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6647 || TYPE_FIELD_NAME (type
, 1) == NULL
6648 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6651 /* Find the type of the method. */
6652 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6653 if (pfn_type
== NULL
6654 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6655 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6658 /* Look for the "this" argument. */
6659 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6660 if (TYPE_NFIELDS (pfn_type
) == 0
6661 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6662 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6665 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6666 new_type
= alloc_type (objfile
);
6667 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6668 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6669 TYPE_VARARGS (pfn_type
));
6670 smash_to_methodptr_type (type
, new_type
);
6673 /* Called when we find the DIE that starts a structure or union scope
6674 (definition) to create a type for the structure or union. Fill in
6675 the type's name and general properties; the members will not be
6676 processed until process_structure_type.
6678 NOTE: we need to call these functions regardless of whether or not the
6679 DIE has a DW_AT_name attribute, since it might be an anonymous
6680 structure or union. This gets the type entered into our set of
6683 However, if the structure is incomplete (an opaque struct/union)
6684 then suppress creating a symbol table entry for it since gdb only
6685 wants to find the one with the complete definition. Note that if
6686 it is complete, we just call new_symbol, which does it's own
6687 checking about whether the struct/union is anonymous or not (and
6688 suppresses creating a symbol table entry itself). */
6690 static struct type
*
6691 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6693 struct objfile
*objfile
= cu
->objfile
;
6695 struct attribute
*attr
;
6698 /* If the definition of this type lives in .debug_types, read that type.
6699 Don't follow DW_AT_specification though, that will take us back up
6700 the chain and we want to go down. */
6701 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6704 struct dwarf2_cu
*type_cu
= cu
;
6705 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6707 /* We could just recurse on read_structure_type, but we need to call
6708 get_die_type to ensure only one type for this DIE is created.
6709 This is important, for example, because for c++ classes we need
6710 TYPE_NAME set which is only done by new_symbol. Blech. */
6711 type
= read_type_die (type_die
, type_cu
);
6713 /* TYPE_CU may not be the same as CU.
6714 Ensure TYPE is recorded in CU's type_hash table. */
6715 return set_die_type (die
, type
, cu
);
6718 type
= alloc_type (objfile
);
6719 INIT_CPLUS_SPECIFIC (type
);
6721 name
= dwarf2_name (die
, cu
);
6724 if (cu
->language
== language_cplus
6725 || cu
->language
== language_java
)
6727 char *full_name
= (char *) dwarf2_full_name (name
, die
, cu
);
6729 /* dwarf2_full_name might have already finished building the DIE's
6730 type. If so, there is no need to continue. */
6731 if (get_die_type (die
, cu
) != NULL
)
6732 return get_die_type (die
, cu
);
6734 TYPE_TAG_NAME (type
) = full_name
;
6735 if (die
->tag
== DW_TAG_structure_type
6736 || die
->tag
== DW_TAG_class_type
)
6737 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6741 /* The name is already allocated along with this objfile, so
6742 we don't need to duplicate it for the type. */
6743 TYPE_TAG_NAME (type
) = (char *) name
;
6744 if (die
->tag
== DW_TAG_class_type
)
6745 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6749 if (die
->tag
== DW_TAG_structure_type
)
6751 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6753 else if (die
->tag
== DW_TAG_union_type
)
6755 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6759 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6762 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6763 TYPE_DECLARED_CLASS (type
) = 1;
6765 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6768 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6772 TYPE_LENGTH (type
) = 0;
6775 TYPE_STUB_SUPPORTED (type
) = 1;
6776 if (die_is_declaration (die
, cu
))
6777 TYPE_STUB (type
) = 1;
6778 else if (attr
== NULL
&& die
->child
== NULL
6779 && producer_is_realview (cu
->producer
))
6780 /* RealView does not output the required DW_AT_declaration
6781 on incomplete types. */
6782 TYPE_STUB (type
) = 1;
6784 /* We need to add the type field to the die immediately so we don't
6785 infinitely recurse when dealing with pointers to the structure
6786 type within the structure itself. */
6787 set_die_type (die
, type
, cu
);
6789 /* set_die_type should be already done. */
6790 set_descriptive_type (type
, die
, cu
);
6795 /* Finish creating a structure or union type, including filling in
6796 its members and creating a symbol for it. */
6799 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6801 struct objfile
*objfile
= cu
->objfile
;
6802 struct die_info
*child_die
= die
->child
;
6805 type
= get_die_type (die
, cu
);
6807 type
= read_structure_type (die
, cu
);
6809 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6811 struct field_info fi
;
6812 struct die_info
*child_die
;
6813 VEC (symbolp
) *template_args
= NULL
;
6814 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
6816 memset (&fi
, 0, sizeof (struct field_info
));
6818 child_die
= die
->child
;
6820 while (child_die
&& child_die
->tag
)
6822 if (child_die
->tag
== DW_TAG_member
6823 || child_die
->tag
== DW_TAG_variable
)
6825 /* NOTE: carlton/2002-11-05: A C++ static data member
6826 should be a DW_TAG_member that is a declaration, but
6827 all versions of G++ as of this writing (so through at
6828 least 3.2.1) incorrectly generate DW_TAG_variable
6829 tags for them instead. */
6830 dwarf2_add_field (&fi
, child_die
, cu
);
6832 else if (child_die
->tag
== DW_TAG_subprogram
)
6834 /* C++ member function. */
6835 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6837 else if (child_die
->tag
== DW_TAG_inheritance
)
6839 /* C++ base class field. */
6840 dwarf2_add_field (&fi
, child_die
, cu
);
6842 else if (child_die
->tag
== DW_TAG_typedef
)
6843 dwarf2_add_typedef (&fi
, child_die
, cu
);
6844 else if (child_die
->tag
== DW_TAG_template_type_param
6845 || child_die
->tag
== DW_TAG_template_value_param
)
6847 struct symbol
*arg
= new_symbol (child_die
, NULL
, cu
);
6850 VEC_safe_push (symbolp
, template_args
, arg
);
6853 child_die
= sibling_die (child_die
);
6856 /* Attach template arguments to type. */
6857 if (! VEC_empty (symbolp
, template_args
))
6859 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6860 TYPE_N_TEMPLATE_ARGUMENTS (type
)
6861 = VEC_length (symbolp
, template_args
);
6862 TYPE_TEMPLATE_ARGUMENTS (type
)
6863 = obstack_alloc (&objfile
->objfile_obstack
,
6864 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6865 * sizeof (struct symbol
*)));
6866 memcpy (TYPE_TEMPLATE_ARGUMENTS (type
),
6867 VEC_address (symbolp
, template_args
),
6868 (TYPE_N_TEMPLATE_ARGUMENTS (type
)
6869 * sizeof (struct symbol
*)));
6870 VEC_free (symbolp
, template_args
);
6873 /* Attach fields and member functions to the type. */
6875 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6878 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6880 /* Get the type which refers to the base class (possibly this
6881 class itself) which contains the vtable pointer for the current
6882 class from the DW_AT_containing_type attribute. This use of
6883 DW_AT_containing_type is a GNU extension. */
6885 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6887 struct type
*t
= die_containing_type (die
, cu
);
6889 TYPE_VPTR_BASETYPE (type
) = t
;
6894 /* Our own class provides vtbl ptr. */
6895 for (i
= TYPE_NFIELDS (t
) - 1;
6896 i
>= TYPE_N_BASECLASSES (t
);
6899 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6901 if (is_vtable_name (fieldname
, cu
))
6903 TYPE_VPTR_FIELDNO (type
) = i
;
6908 /* Complain if virtual function table field not found. */
6909 if (i
< TYPE_N_BASECLASSES (t
))
6910 complaint (&symfile_complaints
,
6911 _("virtual function table pointer not found when defining class '%s'"),
6912 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6917 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6920 else if (cu
->producer
6921 && strncmp (cu
->producer
,
6922 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6924 /* The IBM XLC compiler does not provide direct indication
6925 of the containing type, but the vtable pointer is
6926 always named __vfp. */
6930 for (i
= TYPE_NFIELDS (type
) - 1;
6931 i
>= TYPE_N_BASECLASSES (type
);
6934 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6936 TYPE_VPTR_FIELDNO (type
) = i
;
6937 TYPE_VPTR_BASETYPE (type
) = type
;
6944 /* Copy fi.typedef_field_list linked list elements content into the
6945 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6946 if (fi
.typedef_field_list
)
6948 int i
= fi
.typedef_field_list_count
;
6950 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6951 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6952 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6953 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6955 /* Reverse the list order to keep the debug info elements order. */
6958 struct typedef_field
*dest
, *src
;
6960 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6961 src
= &fi
.typedef_field_list
->field
;
6962 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6967 do_cleanups (back_to
);
6970 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6972 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6973 snapshots) has been known to create a die giving a declaration
6974 for a class that has, as a child, a die giving a definition for a
6975 nested class. So we have to process our children even if the
6976 current die is a declaration. Normally, of course, a declaration
6977 won't have any children at all. */
6979 while (child_die
!= NULL
&& child_die
->tag
)
6981 if (child_die
->tag
== DW_TAG_member
6982 || child_die
->tag
== DW_TAG_variable
6983 || child_die
->tag
== DW_TAG_inheritance
6984 || child_die
->tag
== DW_TAG_template_value_param
6985 || child_die
->tag
== DW_TAG_template_type_param
)
6990 process_die (child_die
, cu
);
6992 child_die
= sibling_die (child_die
);
6995 /* Do not consider external references. According to the DWARF standard,
6996 these DIEs are identified by the fact that they have no byte_size
6997 attribute, and a declaration attribute. */
6998 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6999 || !die_is_declaration (die
, cu
))
7000 new_symbol (die
, type
, cu
);
7003 /* Given a DW_AT_enumeration_type die, set its type. We do not
7004 complete the type's fields yet, or create any symbols. */
7006 static struct type
*
7007 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7009 struct objfile
*objfile
= cu
->objfile
;
7011 struct attribute
*attr
;
7014 /* If the definition of this type lives in .debug_types, read that type.
7015 Don't follow DW_AT_specification though, that will take us back up
7016 the chain and we want to go down. */
7017 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
7020 struct dwarf2_cu
*type_cu
= cu
;
7021 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
7023 type
= read_type_die (type_die
, type_cu
);
7025 /* TYPE_CU may not be the same as CU.
7026 Ensure TYPE is recorded in CU's type_hash table. */
7027 return set_die_type (die
, type
, cu
);
7030 type
= alloc_type (objfile
);
7032 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
7033 name
= dwarf2_full_name (NULL
, die
, cu
);
7035 TYPE_TAG_NAME (type
) = (char *) name
;
7037 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7040 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7044 TYPE_LENGTH (type
) = 0;
7047 /* The enumeration DIE can be incomplete. In Ada, any type can be
7048 declared as private in the package spec, and then defined only
7049 inside the package body. Such types are known as Taft Amendment
7050 Types. When another package uses such a type, an incomplete DIE
7051 may be generated by the compiler. */
7052 if (die_is_declaration (die
, cu
))
7053 TYPE_STUB (type
) = 1;
7055 return set_die_type (die
, type
, cu
);
7058 /* Given a pointer to a die which begins an enumeration, process all
7059 the dies that define the members of the enumeration, and create the
7060 symbol for the enumeration type.
7062 NOTE: We reverse the order of the element list. */
7065 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
7067 struct type
*this_type
;
7069 this_type
= get_die_type (die
, cu
);
7070 if (this_type
== NULL
)
7071 this_type
= read_enumeration_type (die
, cu
);
7073 if (die
->child
!= NULL
)
7075 struct die_info
*child_die
;
7077 struct field
*fields
= NULL
;
7079 int unsigned_enum
= 1;
7082 child_die
= die
->child
;
7083 while (child_die
&& child_die
->tag
)
7085 if (child_die
->tag
!= DW_TAG_enumerator
)
7087 process_die (child_die
, cu
);
7091 name
= dwarf2_name (child_die
, cu
);
7094 sym
= new_symbol (child_die
, this_type
, cu
);
7095 if (SYMBOL_VALUE (sym
) < 0)
7098 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
7100 fields
= (struct field
*)
7102 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
7103 * sizeof (struct field
));
7106 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
7107 FIELD_TYPE (fields
[num_fields
]) = NULL
;
7108 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
7109 FIELD_BITSIZE (fields
[num_fields
]) = 0;
7115 child_die
= sibling_die (child_die
);
7120 TYPE_NFIELDS (this_type
) = num_fields
;
7121 TYPE_FIELDS (this_type
) = (struct field
*)
7122 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
7123 memcpy (TYPE_FIELDS (this_type
), fields
,
7124 sizeof (struct field
) * num_fields
);
7128 TYPE_UNSIGNED (this_type
) = 1;
7131 new_symbol (die
, this_type
, cu
);
7134 /* Extract all information from a DW_TAG_array_type DIE and put it in
7135 the DIE's type field. For now, this only handles one dimensional
7138 static struct type
*
7139 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7141 struct objfile
*objfile
= cu
->objfile
;
7142 struct die_info
*child_die
;
7144 struct type
*element_type
, *range_type
, *index_type
;
7145 struct type
**range_types
= NULL
;
7146 struct attribute
*attr
;
7148 struct cleanup
*back_to
;
7151 element_type
= die_type (die
, cu
);
7153 /* The die_type call above may have already set the type for this DIE. */
7154 type
= get_die_type (die
, cu
);
7158 /* Irix 6.2 native cc creates array types without children for
7159 arrays with unspecified length. */
7160 if (die
->child
== NULL
)
7162 index_type
= objfile_type (objfile
)->builtin_int
;
7163 range_type
= create_range_type (NULL
, index_type
, 0, -1);
7164 type
= create_array_type (NULL
, element_type
, range_type
);
7165 return set_die_type (die
, type
, cu
);
7168 back_to
= make_cleanup (null_cleanup
, NULL
);
7169 child_die
= die
->child
;
7170 while (child_die
&& child_die
->tag
)
7172 if (child_die
->tag
== DW_TAG_subrange_type
)
7174 struct type
*child_type
= read_type_die (child_die
, cu
);
7176 if (child_type
!= NULL
)
7178 /* The range type was succesfully read. Save it for
7179 the array type creation. */
7180 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
7182 range_types
= (struct type
**)
7183 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
7184 * sizeof (struct type
*));
7186 make_cleanup (free_current_contents
, &range_types
);
7188 range_types
[ndim
++] = child_type
;
7191 child_die
= sibling_die (child_die
);
7194 /* Dwarf2 dimensions are output from left to right, create the
7195 necessary array types in backwards order. */
7197 type
= element_type
;
7199 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
7204 type
= create_array_type (NULL
, type
, range_types
[i
++]);
7209 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
7212 /* Understand Dwarf2 support for vector types (like they occur on
7213 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
7214 array type. This is not part of the Dwarf2/3 standard yet, but a
7215 custom vendor extension. The main difference between a regular
7216 array and the vector variant is that vectors are passed by value
7218 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
7220 make_vector_type (type
);
7222 name
= dwarf2_name (die
, cu
);
7224 TYPE_NAME (type
) = name
;
7226 /* Install the type in the die. */
7227 set_die_type (die
, type
, cu
);
7229 /* set_die_type should be already done. */
7230 set_descriptive_type (type
, die
, cu
);
7232 do_cleanups (back_to
);
7237 static enum dwarf_array_dim_ordering
7238 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
7240 struct attribute
*attr
;
7242 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
7244 if (attr
) return DW_SND (attr
);
7247 GNU F77 is a special case, as at 08/2004 array type info is the
7248 opposite order to the dwarf2 specification, but data is still
7249 laid out as per normal fortran.
7251 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
7255 if (cu
->language
== language_fortran
7256 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
7258 return DW_ORD_row_major
;
7261 switch (cu
->language_defn
->la_array_ordering
)
7263 case array_column_major
:
7264 return DW_ORD_col_major
;
7265 case array_row_major
:
7267 return DW_ORD_row_major
;
7271 /* Extract all information from a DW_TAG_set_type DIE and put it in
7272 the DIE's type field. */
7274 static struct type
*
7275 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7277 struct type
*domain_type
, *set_type
;
7278 struct attribute
*attr
;
7280 domain_type
= die_type (die
, cu
);
7282 /* The die_type call above may have already set the type for this DIE. */
7283 set_type
= get_die_type (die
, cu
);
7287 set_type
= create_set_type (NULL
, domain_type
);
7289 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7291 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
7293 return set_die_type (die
, set_type
, cu
);
7296 /* First cut: install each common block member as a global variable. */
7299 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
7301 struct die_info
*child_die
;
7302 struct attribute
*attr
;
7304 CORE_ADDR base
= (CORE_ADDR
) 0;
7306 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7309 /* Support the .debug_loc offsets */
7310 if (attr_form_is_block (attr
))
7312 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
7314 else if (attr_form_is_section_offset (attr
))
7316 dwarf2_complex_location_expr_complaint ();
7320 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
7321 "common block member");
7324 if (die
->child
!= NULL
)
7326 child_die
= die
->child
;
7327 while (child_die
&& child_die
->tag
)
7329 sym
= new_symbol (child_die
, NULL
, cu
);
7330 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
7331 if (sym
!= NULL
&& attr
!= NULL
)
7333 CORE_ADDR byte_offset
= 0;
7335 if (attr_form_is_section_offset (attr
))
7336 dwarf2_complex_location_expr_complaint ();
7337 else if (attr_form_is_constant (attr
))
7338 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
7339 else if (attr_form_is_block (attr
))
7340 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
7342 dwarf2_complex_location_expr_complaint ();
7344 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
7345 add_symbol_to_list (sym
, &global_symbols
);
7347 child_die
= sibling_die (child_die
);
7352 /* Create a type for a C++ namespace. */
7354 static struct type
*
7355 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7357 struct objfile
*objfile
= cu
->objfile
;
7358 const char *previous_prefix
, *name
;
7362 /* For extensions, reuse the type of the original namespace. */
7363 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
7365 struct die_info
*ext_die
;
7366 struct dwarf2_cu
*ext_cu
= cu
;
7368 ext_die
= dwarf2_extension (die
, &ext_cu
);
7369 type
= read_type_die (ext_die
, ext_cu
);
7371 /* EXT_CU may not be the same as CU.
7372 Ensure TYPE is recorded in CU's type_hash table. */
7373 return set_die_type (die
, type
, cu
);
7376 name
= namespace_name (die
, &is_anonymous
, cu
);
7378 /* Now build the name of the current namespace. */
7380 previous_prefix
= determine_prefix (die
, cu
);
7381 if (previous_prefix
[0] != '\0')
7382 name
= typename_concat (&objfile
->objfile_obstack
,
7383 previous_prefix
, name
, 0, cu
);
7385 /* Create the type. */
7386 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
7388 TYPE_NAME (type
) = (char *) name
;
7389 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7391 return set_die_type (die
, type
, cu
);
7394 /* Read a C++ namespace. */
7397 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
7399 struct objfile
*objfile
= cu
->objfile
;
7403 /* Add a symbol associated to this if we haven't seen the namespace
7404 before. Also, add a using directive if it's an anonymous
7407 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
7411 type
= read_type_die (die
, cu
);
7412 new_symbol (die
, type
, cu
);
7414 name
= namespace_name (die
, &is_anonymous
, cu
);
7417 const char *previous_prefix
= determine_prefix (die
, cu
);
7419 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
7420 NULL
, &objfile
->objfile_obstack
);
7424 if (die
->child
!= NULL
)
7426 struct die_info
*child_die
= die
->child
;
7428 while (child_die
&& child_die
->tag
)
7430 process_die (child_die
, cu
);
7431 child_die
= sibling_die (child_die
);
7436 /* Read a Fortran module as type. This DIE can be only a declaration used for
7437 imported module. Still we need that type as local Fortran "use ... only"
7438 declaration imports depend on the created type in determine_prefix. */
7440 static struct type
*
7441 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7443 struct objfile
*objfile
= cu
->objfile
;
7447 module_name
= dwarf2_name (die
, cu
);
7449 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
7451 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
7453 /* determine_prefix uses TYPE_TAG_NAME. */
7454 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
7456 return set_die_type (die
, type
, cu
);
7459 /* Read a Fortran module. */
7462 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
7464 struct die_info
*child_die
= die
->child
;
7466 while (child_die
&& child_die
->tag
)
7468 process_die (child_die
, cu
);
7469 child_die
= sibling_die (child_die
);
7473 /* Return the name of the namespace represented by DIE. Set
7474 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
7478 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
7480 struct die_info
*current_die
;
7481 const char *name
= NULL
;
7483 /* Loop through the extensions until we find a name. */
7485 for (current_die
= die
;
7486 current_die
!= NULL
;
7487 current_die
= dwarf2_extension (die
, &cu
))
7489 name
= dwarf2_name (current_die
, cu
);
7494 /* Is it an anonymous namespace? */
7496 *is_anonymous
= (name
== NULL
);
7498 name
= "(anonymous namespace)";
7503 /* Extract all information from a DW_TAG_pointer_type DIE and add to
7504 the user defined type vector. */
7506 static struct type
*
7507 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7509 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7510 struct comp_unit_head
*cu_header
= &cu
->header
;
7512 struct attribute
*attr_byte_size
;
7513 struct attribute
*attr_address_class
;
7514 int byte_size
, addr_class
;
7515 struct type
*target_type
;
7517 target_type
= die_type (die
, cu
);
7519 /* The die_type call above may have already set the type for this DIE. */
7520 type
= get_die_type (die
, cu
);
7524 type
= lookup_pointer_type (target_type
);
7526 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7528 byte_size
= DW_UNSND (attr_byte_size
);
7530 byte_size
= cu_header
->addr_size
;
7532 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
7533 if (attr_address_class
)
7534 addr_class
= DW_UNSND (attr_address_class
);
7536 addr_class
= DW_ADDR_none
;
7538 /* If the pointer size or address class is different than the
7539 default, create a type variant marked as such and set the
7540 length accordingly. */
7541 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
7543 if (gdbarch_address_class_type_flags_p (gdbarch
))
7547 type_flags
= gdbarch_address_class_type_flags
7548 (gdbarch
, byte_size
, addr_class
);
7549 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
7551 type
= make_type_with_address_space (type
, type_flags
);
7553 else if (TYPE_LENGTH (type
) != byte_size
)
7555 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
7559 /* Should we also complain about unhandled address classes? */
7563 TYPE_LENGTH (type
) = byte_size
;
7564 return set_die_type (die
, type
, cu
);
7567 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
7568 the user defined type vector. */
7570 static struct type
*
7571 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7574 struct type
*to_type
;
7575 struct type
*domain
;
7577 to_type
= die_type (die
, cu
);
7578 domain
= die_containing_type (die
, cu
);
7580 /* The calls above may have already set the type for this DIE. */
7581 type
= get_die_type (die
, cu
);
7585 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
7586 type
= lookup_methodptr_type (to_type
);
7588 type
= lookup_memberptr_type (to_type
, domain
);
7590 return set_die_type (die
, type
, cu
);
7593 /* Extract all information from a DW_TAG_reference_type DIE and add to
7594 the user defined type vector. */
7596 static struct type
*
7597 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7599 struct comp_unit_head
*cu_header
= &cu
->header
;
7600 struct type
*type
, *target_type
;
7601 struct attribute
*attr
;
7603 target_type
= die_type (die
, cu
);
7605 /* The die_type call above may have already set the type for this DIE. */
7606 type
= get_die_type (die
, cu
);
7610 type
= lookup_reference_type (target_type
);
7611 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7614 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7618 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7620 return set_die_type (die
, type
, cu
);
7623 static struct type
*
7624 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7626 struct type
*base_type
, *cv_type
;
7628 base_type
= die_type (die
, cu
);
7630 /* The die_type call above may have already set the type for this DIE. */
7631 cv_type
= get_die_type (die
, cu
);
7635 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7636 return set_die_type (die
, cv_type
, cu
);
7639 static struct type
*
7640 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7642 struct type
*base_type
, *cv_type
;
7644 base_type
= die_type (die
, cu
);
7646 /* The die_type call above may have already set the type for this DIE. */
7647 cv_type
= get_die_type (die
, cu
);
7651 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7652 return set_die_type (die
, cv_type
, cu
);
7655 /* Extract all information from a DW_TAG_string_type DIE and add to
7656 the user defined type vector. It isn't really a user defined type,
7657 but it behaves like one, with other DIE's using an AT_user_def_type
7658 attribute to reference it. */
7660 static struct type
*
7661 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7663 struct objfile
*objfile
= cu
->objfile
;
7664 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7665 struct type
*type
, *range_type
, *index_type
, *char_type
;
7666 struct attribute
*attr
;
7667 unsigned int length
;
7669 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7672 length
= DW_UNSND (attr
);
7676 /* check for the DW_AT_byte_size attribute */
7677 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7680 length
= DW_UNSND (attr
);
7688 index_type
= objfile_type (objfile
)->builtin_int
;
7689 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7690 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7691 type
= create_string_type (NULL
, char_type
, range_type
);
7693 return set_die_type (die
, type
, cu
);
7696 /* Handle DIES due to C code like:
7700 int (*funcp)(int a, long l);
7704 ('funcp' generates a DW_TAG_subroutine_type DIE)
7707 static struct type
*
7708 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7710 struct type
*type
; /* Type that this function returns */
7711 struct type
*ftype
; /* Function that returns above type */
7712 struct attribute
*attr
;
7714 type
= die_type (die
, cu
);
7716 /* The die_type call above may have already set the type for this DIE. */
7717 ftype
= get_die_type (die
, cu
);
7721 ftype
= lookup_function_type (type
);
7723 /* All functions in C++, Pascal and Java have prototypes. */
7724 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7725 if ((attr
&& (DW_UNSND (attr
) != 0))
7726 || cu
->language
== language_cplus
7727 || cu
->language
== language_java
7728 || cu
->language
== language_pascal
)
7729 TYPE_PROTOTYPED (ftype
) = 1;
7730 else if (producer_is_realview (cu
->producer
))
7731 /* RealView does not emit DW_AT_prototyped. We can not
7732 distinguish prototyped and unprototyped functions; default to
7733 prototyped, since that is more common in modern code (and
7734 RealView warns about unprototyped functions). */
7735 TYPE_PROTOTYPED (ftype
) = 1;
7737 /* Store the calling convention in the type if it's available in
7738 the subroutine die. Otherwise set the calling convention to
7739 the default value DW_CC_normal. */
7740 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7741 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7743 /* We need to add the subroutine type to the die immediately so
7744 we don't infinitely recurse when dealing with parameters
7745 declared as the same subroutine type. */
7746 set_die_type (die
, ftype
, cu
);
7748 if (die
->child
!= NULL
)
7750 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7751 struct die_info
*child_die
;
7752 int nparams
, iparams
;
7754 /* Count the number of parameters.
7755 FIXME: GDB currently ignores vararg functions, but knows about
7756 vararg member functions. */
7758 child_die
= die
->child
;
7759 while (child_die
&& child_die
->tag
)
7761 if (child_die
->tag
== DW_TAG_formal_parameter
)
7763 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7764 TYPE_VARARGS (ftype
) = 1;
7765 child_die
= sibling_die (child_die
);
7768 /* Allocate storage for parameters and fill them in. */
7769 TYPE_NFIELDS (ftype
) = nparams
;
7770 TYPE_FIELDS (ftype
) = (struct field
*)
7771 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7773 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7774 even if we error out during the parameters reading below. */
7775 for (iparams
= 0; iparams
< nparams
; iparams
++)
7776 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7779 child_die
= die
->child
;
7780 while (child_die
&& child_die
->tag
)
7782 if (child_die
->tag
== DW_TAG_formal_parameter
)
7784 struct type
*arg_type
;
7786 /* DWARF version 2 has no clean way to discern C++
7787 static and non-static member functions. G++ helps
7788 GDB by marking the first parameter for non-static
7789 member functions (which is the this pointer) as
7790 artificial. We pass this information to
7791 dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL.
7793 DWARF version 3 added DW_AT_object_pointer, which GCC
7794 4.5 does not yet generate. */
7795 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7797 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7800 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7802 /* GCC/43521: In java, the formal parameter
7803 "this" is sometimes not marked with DW_AT_artificial. */
7804 if (cu
->language
== language_java
)
7806 const char *name
= dwarf2_name (child_die
, cu
);
7808 if (name
&& !strcmp (name
, "this"))
7809 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7812 arg_type
= die_type (child_die
, cu
);
7814 /* RealView does not mark THIS as const, which the testsuite
7815 expects. GCC marks THIS as const in method definitions,
7816 but not in the class specifications (GCC PR 43053). */
7817 if (cu
->language
== language_cplus
&& !TYPE_CONST (arg_type
)
7818 && TYPE_FIELD_ARTIFICIAL (ftype
, iparams
))
7821 struct dwarf2_cu
*arg_cu
= cu
;
7822 const char *name
= dwarf2_name (child_die
, cu
);
7824 attr
= dwarf2_attr (die
, DW_AT_object_pointer
, cu
);
7827 /* If the compiler emits this, use it. */
7828 if (follow_die_ref (die
, attr
, &arg_cu
) == child_die
)
7831 else if (name
&& strcmp (name
, "this") == 0)
7832 /* Function definitions will have the argument names. */
7834 else if (name
== NULL
&& iparams
== 0)
7835 /* Declarations may not have the names, so like
7836 elsewhere in GDB, assume an artificial first
7837 argument is "this". */
7841 arg_type
= make_cv_type (1, TYPE_VOLATILE (arg_type
),
7845 TYPE_FIELD_TYPE (ftype
, iparams
) = arg_type
;
7848 child_die
= sibling_die (child_die
);
7855 static struct type
*
7856 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7858 struct objfile
*objfile
= cu
->objfile
;
7859 const char *name
= NULL
;
7860 struct type
*this_type
;
7862 name
= dwarf2_full_name (NULL
, die
, cu
);
7863 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7864 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7865 TYPE_NAME (this_type
) = (char *) name
;
7866 set_die_type (die
, this_type
, cu
);
7867 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7871 /* Find a representation of a given base type and install
7872 it in the TYPE field of the die. */
7874 static struct type
*
7875 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7877 struct objfile
*objfile
= cu
->objfile
;
7879 struct attribute
*attr
;
7880 int encoding
= 0, size
= 0;
7882 enum type_code code
= TYPE_CODE_INT
;
7884 struct type
*target_type
= NULL
;
7886 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7889 encoding
= DW_UNSND (attr
);
7891 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7894 size
= DW_UNSND (attr
);
7896 name
= dwarf2_name (die
, cu
);
7899 complaint (&symfile_complaints
,
7900 _("DW_AT_name missing from DW_TAG_base_type"));
7905 case DW_ATE_address
:
7906 /* Turn DW_ATE_address into a void * pointer. */
7907 code
= TYPE_CODE_PTR
;
7908 type_flags
|= TYPE_FLAG_UNSIGNED
;
7909 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7911 case DW_ATE_boolean
:
7912 code
= TYPE_CODE_BOOL
;
7913 type_flags
|= TYPE_FLAG_UNSIGNED
;
7915 case DW_ATE_complex_float
:
7916 code
= TYPE_CODE_COMPLEX
;
7917 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7919 case DW_ATE_decimal_float
:
7920 code
= TYPE_CODE_DECFLOAT
;
7923 code
= TYPE_CODE_FLT
;
7927 case DW_ATE_unsigned
:
7928 type_flags
|= TYPE_FLAG_UNSIGNED
;
7930 case DW_ATE_signed_char
:
7931 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7932 || cu
->language
== language_pascal
)
7933 code
= TYPE_CODE_CHAR
;
7935 case DW_ATE_unsigned_char
:
7936 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7937 || cu
->language
== language_pascal
)
7938 code
= TYPE_CODE_CHAR
;
7939 type_flags
|= TYPE_FLAG_UNSIGNED
;
7942 /* We just treat this as an integer and then recognize the
7943 type by name elsewhere. */
7947 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7948 dwarf_type_encoding_name (encoding
));
7952 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7953 TYPE_NAME (type
) = name
;
7954 TYPE_TARGET_TYPE (type
) = target_type
;
7956 if (name
&& strcmp (name
, "char") == 0)
7957 TYPE_NOSIGN (type
) = 1;
7959 return set_die_type (die
, type
, cu
);
7962 /* Read the given DW_AT_subrange DIE. */
7964 static struct type
*
7965 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7967 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7968 struct type
*base_type
;
7969 struct type
*range_type
;
7970 struct attribute
*attr
;
7974 LONGEST negative_mask
;
7976 base_type
= die_type (die
, cu
);
7977 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7978 check_typedef (base_type
);
7980 /* The die_type call above may have already set the type for this DIE. */
7981 range_type
= get_die_type (die
, cu
);
7985 if (cu
->language
== language_fortran
)
7987 /* FORTRAN implies a lower bound of 1, if not given. */
7991 /* FIXME: For variable sized arrays either of these could be
7992 a variable rather than a constant value. We'll allow it,
7993 but we don't know how to handle it. */
7994 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
7996 low
= dwarf2_get_attr_constant_value (attr
, 0);
7998 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
8001 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
8003 /* GCC encodes arrays with unspecified or dynamic length
8004 with a DW_FORM_block1 attribute or a reference attribute.
8005 FIXME: GDB does not yet know how to handle dynamic
8006 arrays properly, treat them as arrays with unspecified
8009 FIXME: jimb/2003-09-22: GDB does not really know
8010 how to handle arrays of unspecified length
8011 either; we just represent them as zero-length
8012 arrays. Choose an appropriate upper bound given
8013 the lower bound we've computed above. */
8017 high
= dwarf2_get_attr_constant_value (attr
, 1);
8021 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
8024 int count
= dwarf2_get_attr_constant_value (attr
, 1);
8025 high
= low
+ count
- 1;
8029 /* Dwarf-2 specifications explicitly allows to create subrange types
8030 without specifying a base type.
8031 In that case, the base type must be set to the type of
8032 the lower bound, upper bound or count, in that order, if any of these
8033 three attributes references an object that has a type.
8034 If no base type is found, the Dwarf-2 specifications say that
8035 a signed integer type of size equal to the size of an address should
8037 For the following C code: `extern char gdb_int [];'
8038 GCC produces an empty range DIE.
8039 FIXME: muller/2010-05-28: Possible references to object for low bound,
8040 high bound or count are not yet handled by this code.
8042 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
8044 struct objfile
*objfile
= cu
->objfile
;
8045 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8046 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
8047 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
8049 /* Test "int", "long int", and "long long int" objfile types,
8050 and select the first one having a size above or equal to the
8051 architecture address size. */
8052 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8053 base_type
= int_type
;
8056 int_type
= objfile_type (objfile
)->builtin_long
;
8057 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8058 base_type
= int_type
;
8061 int_type
= objfile_type (objfile
)->builtin_long_long
;
8062 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
8063 base_type
= int_type
;
8069 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
8070 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
8071 low
|= negative_mask
;
8072 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
8073 high
|= negative_mask
;
8075 range_type
= create_range_type (NULL
, base_type
, low
, high
);
8077 /* Mark arrays with dynamic length at least as an array of unspecified
8078 length. GDB could check the boundary but before it gets implemented at
8079 least allow accessing the array elements. */
8080 if (attr
&& attr
->form
== DW_FORM_block1
)
8081 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
8083 name
= dwarf2_name (die
, cu
);
8085 TYPE_NAME (range_type
) = name
;
8087 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
8089 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
8091 set_die_type (die
, range_type
, cu
);
8093 /* set_die_type should be already done. */
8094 set_descriptive_type (range_type
, die
, cu
);
8099 static struct type
*
8100 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8104 /* For now, we only support the C meaning of an unspecified type: void. */
8106 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
8107 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
8109 return set_die_type (die
, type
, cu
);
8112 /* Trivial hash function for die_info: the hash value of a DIE
8113 is its offset in .debug_info for this objfile. */
8116 die_hash (const void *item
)
8118 const struct die_info
*die
= item
;
8123 /* Trivial comparison function for die_info structures: two DIEs
8124 are equal if they have the same offset. */
8127 die_eq (const void *item_lhs
, const void *item_rhs
)
8129 const struct die_info
*die_lhs
= item_lhs
;
8130 const struct die_info
*die_rhs
= item_rhs
;
8132 return die_lhs
->offset
== die_rhs
->offset
;
8135 /* Read a whole compilation unit into a linked list of dies. */
8137 static struct die_info
*
8138 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8140 struct die_reader_specs reader_specs
;
8141 int read_abbrevs
= 0;
8142 struct cleanup
*back_to
= NULL
;
8143 struct die_info
*die
;
8145 if (cu
->dwarf2_abbrevs
== NULL
)
8147 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
8148 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
8152 gdb_assert (cu
->die_hash
== NULL
);
8154 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8158 &cu
->comp_unit_obstack
,
8159 hashtab_obstack_allocate
,
8160 dummy_obstack_deallocate
);
8162 init_cu_die_reader (&reader_specs
, cu
);
8164 die
= read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
8167 do_cleanups (back_to
);
8172 /* Main entry point for reading a DIE and all children.
8173 Read the DIE and dump it if requested. */
8175 static struct die_info
*
8176 read_die_and_children (const struct die_reader_specs
*reader
,
8178 gdb_byte
**new_info_ptr
,
8179 struct die_info
*parent
)
8181 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
8182 new_info_ptr
, parent
);
8184 if (dwarf2_die_debug
)
8186 fprintf_unfiltered (gdb_stdlog
,
8187 "\nRead die from %s of %s:\n",
8188 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
8190 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
8192 : "unknown section",
8193 reader
->abfd
->filename
);
8194 dump_die (result
, dwarf2_die_debug
);
8200 /* Read a single die and all its descendents. Set the die's sibling
8201 field to NULL; set other fields in the die correctly, and set all
8202 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
8203 location of the info_ptr after reading all of those dies. PARENT
8204 is the parent of the die in question. */
8206 static struct die_info
*
8207 read_die_and_children_1 (const struct die_reader_specs
*reader
,
8209 gdb_byte
**new_info_ptr
,
8210 struct die_info
*parent
)
8212 struct die_info
*die
;
8216 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
8219 *new_info_ptr
= cur_ptr
;
8222 store_in_ref_table (die
, reader
->cu
);
8225 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
8229 *new_info_ptr
= cur_ptr
;
8232 die
->sibling
= NULL
;
8233 die
->parent
= parent
;
8237 /* Read a die, all of its descendents, and all of its siblings; set
8238 all of the fields of all of the dies correctly. Arguments are as
8239 in read_die_and_children. */
8241 static struct die_info
*
8242 read_die_and_siblings (const struct die_reader_specs
*reader
,
8244 gdb_byte
**new_info_ptr
,
8245 struct die_info
*parent
)
8247 struct die_info
*first_die
, *last_sibling
;
8251 first_die
= last_sibling
= NULL
;
8255 struct die_info
*die
8256 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
8260 *new_info_ptr
= cur_ptr
;
8267 last_sibling
->sibling
= die
;
8273 /* Read the die from the .debug_info section buffer. Set DIEP to
8274 point to a newly allocated die with its information, except for its
8275 child, sibling, and parent fields. Set HAS_CHILDREN to tell
8276 whether the die has children or not. */
8279 read_full_die (const struct die_reader_specs
*reader
,
8280 struct die_info
**diep
, gdb_byte
*info_ptr
,
8283 unsigned int abbrev_number
, bytes_read
, i
, offset
;
8284 struct abbrev_info
*abbrev
;
8285 struct die_info
*die
;
8286 struct dwarf2_cu
*cu
= reader
->cu
;
8287 bfd
*abfd
= reader
->abfd
;
8289 offset
= info_ptr
- reader
->buffer
;
8290 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8291 info_ptr
+= bytes_read
;
8299 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
8301 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
8303 bfd_get_filename (abfd
));
8305 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
8306 die
->offset
= offset
;
8307 die
->tag
= abbrev
->tag
;
8308 die
->abbrev
= abbrev_number
;
8310 die
->num_attrs
= abbrev
->num_attrs
;
8312 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8313 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
8314 abfd
, info_ptr
, cu
);
8317 *has_children
= abbrev
->has_children
;
8321 /* In DWARF version 2, the description of the debugging information is
8322 stored in a separate .debug_abbrev section. Before we read any
8323 dies from a section we read in all abbreviations and install them
8324 in a hash table. This function also sets flags in CU describing
8325 the data found in the abbrev table. */
8328 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
8330 struct comp_unit_head
*cu_header
= &cu
->header
;
8331 gdb_byte
*abbrev_ptr
;
8332 struct abbrev_info
*cur_abbrev
;
8333 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
8334 unsigned int abbrev_form
, hash_number
;
8335 struct attr_abbrev
*cur_attrs
;
8336 unsigned int allocated_attrs
;
8338 /* Initialize dwarf2 abbrevs */
8339 obstack_init (&cu
->abbrev_obstack
);
8340 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
8342 * sizeof (struct abbrev_info
*)));
8343 memset (cu
->dwarf2_abbrevs
, 0,
8344 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
8346 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
8347 &dwarf2_per_objfile
->abbrev
);
8348 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
8349 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8350 abbrev_ptr
+= bytes_read
;
8352 allocated_attrs
= ATTR_ALLOC_CHUNK
;
8353 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
8355 /* loop until we reach an abbrev number of 0 */
8356 while (abbrev_number
)
8358 cur_abbrev
= dwarf_alloc_abbrev (cu
);
8360 /* read in abbrev header */
8361 cur_abbrev
->number
= abbrev_number
;
8362 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8363 abbrev_ptr
+= bytes_read
;
8364 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
8367 if (cur_abbrev
->tag
== DW_TAG_namespace
)
8368 cu
->has_namespace_info
= 1;
8370 /* now read in declarations */
8371 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8372 abbrev_ptr
+= bytes_read
;
8373 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8374 abbrev_ptr
+= bytes_read
;
8377 if (cur_abbrev
->num_attrs
== allocated_attrs
)
8379 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
8381 = xrealloc (cur_attrs
, (allocated_attrs
8382 * sizeof (struct attr_abbrev
)));
8385 /* Record whether this compilation unit might have
8386 inter-compilation-unit references. If we don't know what form
8387 this attribute will have, then it might potentially be a
8388 DW_FORM_ref_addr, so we conservatively expect inter-CU
8391 if (abbrev_form
== DW_FORM_ref_addr
8392 || abbrev_form
== DW_FORM_indirect
)
8393 cu
->has_form_ref_addr
= 1;
8395 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
8396 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
8397 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8398 abbrev_ptr
+= bytes_read
;
8399 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8400 abbrev_ptr
+= bytes_read
;
8403 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
8404 (cur_abbrev
->num_attrs
8405 * sizeof (struct attr_abbrev
)));
8406 memcpy (cur_abbrev
->attrs
, cur_attrs
,
8407 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
8409 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
8410 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
8411 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
8413 /* Get next abbreviation.
8414 Under Irix6 the abbreviations for a compilation unit are not
8415 always properly terminated with an abbrev number of 0.
8416 Exit loop if we encounter an abbreviation which we have
8417 already read (which means we are about to read the abbreviations
8418 for the next compile unit) or if the end of the abbreviation
8419 table is reached. */
8420 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
8421 >= dwarf2_per_objfile
->abbrev
.size
)
8423 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
8424 abbrev_ptr
+= bytes_read
;
8425 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
8432 /* Release the memory used by the abbrev table for a compilation unit. */
8435 dwarf2_free_abbrev_table (void *ptr_to_cu
)
8437 struct dwarf2_cu
*cu
= ptr_to_cu
;
8439 obstack_free (&cu
->abbrev_obstack
, NULL
);
8440 cu
->dwarf2_abbrevs
= NULL
;
8443 /* Lookup an abbrev_info structure in the abbrev hash table. */
8445 static struct abbrev_info
*
8446 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
8448 unsigned int hash_number
;
8449 struct abbrev_info
*abbrev
;
8451 hash_number
= number
% ABBREV_HASH_SIZE
;
8452 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
8456 if (abbrev
->number
== number
)
8459 abbrev
= abbrev
->next
;
8464 /* Returns nonzero if TAG represents a type that we might generate a partial
8468 is_type_tag_for_partial (int tag
)
8473 /* Some types that would be reasonable to generate partial symbols for,
8474 that we don't at present. */
8475 case DW_TAG_array_type
:
8476 case DW_TAG_file_type
:
8477 case DW_TAG_ptr_to_member_type
:
8478 case DW_TAG_set_type
:
8479 case DW_TAG_string_type
:
8480 case DW_TAG_subroutine_type
:
8482 case DW_TAG_base_type
:
8483 case DW_TAG_class_type
:
8484 case DW_TAG_interface_type
:
8485 case DW_TAG_enumeration_type
:
8486 case DW_TAG_structure_type
:
8487 case DW_TAG_subrange_type
:
8488 case DW_TAG_typedef
:
8489 case DW_TAG_union_type
:
8496 /* Load all DIEs that are interesting for partial symbols into memory. */
8498 static struct partial_die_info
*
8499 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8500 int building_psymtab
, struct dwarf2_cu
*cu
)
8502 struct partial_die_info
*part_die
;
8503 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
8504 struct abbrev_info
*abbrev
;
8505 unsigned int bytes_read
;
8506 unsigned int load_all
= 0;
8508 int nesting_level
= 1;
8513 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
8517 = htab_create_alloc_ex (cu
->header
.length
/ 12,
8521 &cu
->comp_unit_obstack
,
8522 hashtab_obstack_allocate
,
8523 dummy_obstack_deallocate
);
8525 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8526 sizeof (struct partial_die_info
));
8530 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
8532 /* A NULL abbrev means the end of a series of children. */
8535 if (--nesting_level
== 0)
8537 /* PART_DIE was probably the last thing allocated on the
8538 comp_unit_obstack, so we could call obstack_free
8539 here. We don't do that because the waste is small,
8540 and will be cleaned up when we're done with this
8541 compilation unit. This way, we're also more robust
8542 against other users of the comp_unit_obstack. */
8545 info_ptr
+= bytes_read
;
8546 last_die
= parent_die
;
8547 parent_die
= parent_die
->die_parent
;
8551 /* Check for template arguments. We never save these; if
8552 they're seen, we just mark the parent, and go on our way. */
8553 if (parent_die
!= NULL
8554 && cu
->language
== language_cplus
8555 && (abbrev
->tag
== DW_TAG_template_type_param
8556 || abbrev
->tag
== DW_TAG_template_value_param
))
8558 parent_die
->has_template_arguments
= 1;
8562 /* We don't need a partial DIE for the template argument. */
8563 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
,
8569 /* We only recurse into subprograms looking for template arguments.
8570 Skip their other children. */
8572 && cu
->language
== language_cplus
8573 && parent_die
!= NULL
8574 && parent_die
->tag
== DW_TAG_subprogram
)
8576 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8580 /* Check whether this DIE is interesting enough to save. Normally
8581 we would not be interested in members here, but there may be
8582 later variables referencing them via DW_AT_specification (for
8585 && !is_type_tag_for_partial (abbrev
->tag
)
8586 && abbrev
->tag
!= DW_TAG_constant
8587 && abbrev
->tag
!= DW_TAG_enumerator
8588 && abbrev
->tag
!= DW_TAG_subprogram
8589 && abbrev
->tag
!= DW_TAG_lexical_block
8590 && abbrev
->tag
!= DW_TAG_variable
8591 && abbrev
->tag
!= DW_TAG_namespace
8592 && abbrev
->tag
!= DW_TAG_module
8593 && abbrev
->tag
!= DW_TAG_member
)
8595 /* Otherwise we skip to the next sibling, if any. */
8596 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
8600 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
8601 buffer
, info_ptr
, cu
);
8603 /* This two-pass algorithm for processing partial symbols has a
8604 high cost in cache pressure. Thus, handle some simple cases
8605 here which cover the majority of C partial symbols. DIEs
8606 which neither have specification tags in them, nor could have
8607 specification tags elsewhere pointing at them, can simply be
8608 processed and discarded.
8610 This segment is also optional; scan_partial_symbols and
8611 add_partial_symbol will handle these DIEs if we chain
8612 them in normally. When compilers which do not emit large
8613 quantities of duplicate debug information are more common,
8614 this code can probably be removed. */
8616 /* Any complete simple types at the top level (pretty much all
8617 of them, for a language without namespaces), can be processed
8619 if (parent_die
== NULL
8620 && part_die
->has_specification
== 0
8621 && part_die
->is_declaration
== 0
8622 && (part_die
->tag
== DW_TAG_typedef
8623 || part_die
->tag
== DW_TAG_base_type
8624 || part_die
->tag
== DW_TAG_subrange_type
))
8626 if (building_psymtab
&& part_die
->name
!= NULL
)
8627 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8628 VAR_DOMAIN
, LOC_TYPEDEF
,
8629 &cu
->objfile
->static_psymbols
,
8630 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8631 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8635 /* If we're at the second level, and we're an enumerator, and
8636 our parent has no specification (meaning possibly lives in a
8637 namespace elsewhere), then we can add the partial symbol now
8638 instead of queueing it. */
8639 if (part_die
->tag
== DW_TAG_enumerator
8640 && parent_die
!= NULL
8641 && parent_die
->die_parent
== NULL
8642 && parent_die
->tag
== DW_TAG_enumeration_type
8643 && parent_die
->has_specification
== 0)
8645 if (part_die
->name
== NULL
)
8646 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
8647 else if (building_psymtab
)
8648 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
8649 VAR_DOMAIN
, LOC_CONST
,
8650 (cu
->language
== language_cplus
8651 || cu
->language
== language_java
)
8652 ? &cu
->objfile
->global_psymbols
8653 : &cu
->objfile
->static_psymbols
,
8654 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
8656 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
8660 /* We'll save this DIE so link it in. */
8661 part_die
->die_parent
= parent_die
;
8662 part_die
->die_sibling
= NULL
;
8663 part_die
->die_child
= NULL
;
8665 if (last_die
&& last_die
== parent_die
)
8666 last_die
->die_child
= part_die
;
8668 last_die
->die_sibling
= part_die
;
8670 last_die
= part_die
;
8672 if (first_die
== NULL
)
8673 first_die
= part_die
;
8675 /* Maybe add the DIE to the hash table. Not all DIEs that we
8676 find interesting need to be in the hash table, because we
8677 also have the parent/sibling/child chains; only those that we
8678 might refer to by offset later during partial symbol reading.
8680 For now this means things that might have be the target of a
8681 DW_AT_specification, DW_AT_abstract_origin, or
8682 DW_AT_extension. DW_AT_extension will refer only to
8683 namespaces; DW_AT_abstract_origin refers to functions (and
8684 many things under the function DIE, but we do not recurse
8685 into function DIEs during partial symbol reading) and
8686 possibly variables as well; DW_AT_specification refers to
8687 declarations. Declarations ought to have the DW_AT_declaration
8688 flag. It happens that GCC forgets to put it in sometimes, but
8689 only for functions, not for types.
8691 Adding more things than necessary to the hash table is harmless
8692 except for the performance cost. Adding too few will result in
8693 wasted time in find_partial_die, when we reread the compilation
8694 unit with load_all_dies set. */
8697 || abbrev
->tag
== DW_TAG_constant
8698 || abbrev
->tag
== DW_TAG_subprogram
8699 || abbrev
->tag
== DW_TAG_variable
8700 || abbrev
->tag
== DW_TAG_namespace
8701 || part_die
->is_declaration
)
8705 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8706 part_die
->offset
, INSERT
);
8710 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8711 sizeof (struct partial_die_info
));
8713 /* For some DIEs we want to follow their children (if any). For C
8714 we have no reason to follow the children of structures; for other
8715 languages we have to, so that we can get at method physnames
8716 to infer fully qualified class names, for DW_AT_specification,
8717 and for C++ template arguments. For C++, we also look one level
8718 inside functions to find template arguments (if the name of the
8719 function does not already contain the template arguments).
8721 For Ada, we need to scan the children of subprograms and lexical
8722 blocks as well because Ada allows the definition of nested
8723 entities that could be interesting for the debugger, such as
8724 nested subprograms for instance. */
8725 if (last_die
->has_children
8727 || last_die
->tag
== DW_TAG_namespace
8728 || last_die
->tag
== DW_TAG_module
8729 || last_die
->tag
== DW_TAG_enumeration_type
8730 || (cu
->language
== language_cplus
8731 && last_die
->tag
== DW_TAG_subprogram
8732 && (last_die
->name
== NULL
8733 || strchr (last_die
->name
, '<') == NULL
))
8734 || (cu
->language
!= language_c
8735 && (last_die
->tag
== DW_TAG_class_type
8736 || last_die
->tag
== DW_TAG_interface_type
8737 || last_die
->tag
== DW_TAG_structure_type
8738 || last_die
->tag
== DW_TAG_union_type
))
8739 || (cu
->language
== language_ada
8740 && (last_die
->tag
== DW_TAG_subprogram
8741 || last_die
->tag
== DW_TAG_lexical_block
))))
8744 parent_die
= last_die
;
8748 /* Otherwise we skip to the next sibling, if any. */
8749 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8751 /* Back to the top, do it again. */
8755 /* Read a minimal amount of information into the minimal die structure. */
8758 read_partial_die (struct partial_die_info
*part_die
,
8759 struct abbrev_info
*abbrev
,
8760 unsigned int abbrev_len
, bfd
*abfd
,
8761 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8762 struct dwarf2_cu
*cu
)
8765 struct attribute attr
;
8766 int has_low_pc_attr
= 0;
8767 int has_high_pc_attr
= 0;
8769 memset (part_die
, 0, sizeof (struct partial_die_info
));
8771 part_die
->offset
= info_ptr
- buffer
;
8773 info_ptr
+= abbrev_len
;
8778 part_die
->tag
= abbrev
->tag
;
8779 part_die
->has_children
= abbrev
->has_children
;
8781 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8783 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8785 /* Store the data if it is of an attribute we want to keep in a
8786 partial symbol table. */
8790 switch (part_die
->tag
)
8792 case DW_TAG_compile_unit
:
8793 case DW_TAG_type_unit
:
8794 /* Compilation units have a DW_AT_name that is a filename, not
8795 a source language identifier. */
8796 case DW_TAG_enumeration_type
:
8797 case DW_TAG_enumerator
:
8798 /* These tags always have simple identifiers already; no need
8799 to canonicalize them. */
8800 part_die
->name
= DW_STRING (&attr
);
8804 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8805 &cu
->objfile
->objfile_obstack
);
8809 case DW_AT_linkage_name
:
8810 case DW_AT_MIPS_linkage_name
:
8811 /* Note that both forms of linkage name might appear. We
8812 assume they will be the same, and we only store the last
8814 if (cu
->language
== language_ada
)
8815 part_die
->name
= DW_STRING (&attr
);
8818 has_low_pc_attr
= 1;
8819 part_die
->lowpc
= DW_ADDR (&attr
);
8822 has_high_pc_attr
= 1;
8823 part_die
->highpc
= DW_ADDR (&attr
);
8825 case DW_AT_location
:
8826 /* Support the .debug_loc offsets */
8827 if (attr_form_is_block (&attr
))
8829 part_die
->locdesc
= DW_BLOCK (&attr
);
8831 else if (attr_form_is_section_offset (&attr
))
8833 dwarf2_complex_location_expr_complaint ();
8837 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8838 "partial symbol information");
8841 case DW_AT_external
:
8842 part_die
->is_external
= DW_UNSND (&attr
);
8844 case DW_AT_declaration
:
8845 part_die
->is_declaration
= DW_UNSND (&attr
);
8848 part_die
->has_type
= 1;
8850 case DW_AT_abstract_origin
:
8851 case DW_AT_specification
:
8852 case DW_AT_extension
:
8853 part_die
->has_specification
= 1;
8854 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8857 /* Ignore absolute siblings, they might point outside of
8858 the current compile unit. */
8859 if (attr
.form
== DW_FORM_ref_addr
)
8860 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8862 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8864 case DW_AT_byte_size
:
8865 part_die
->has_byte_size
= 1;
8867 case DW_AT_calling_convention
:
8868 /* DWARF doesn't provide a way to identify a program's source-level
8869 entry point. DW_AT_calling_convention attributes are only meant
8870 to describe functions' calling conventions.
8872 However, because it's a necessary piece of information in
8873 Fortran, and because DW_CC_program is the only piece of debugging
8874 information whose definition refers to a 'main program' at all,
8875 several compilers have begun marking Fortran main programs with
8876 DW_CC_program --- even when those functions use the standard
8877 calling conventions.
8879 So until DWARF specifies a way to provide this information and
8880 compilers pick up the new representation, we'll support this
8882 if (DW_UNSND (&attr
) == DW_CC_program
8883 && cu
->language
== language_fortran
)
8884 set_main_name (part_die
->name
);
8891 /* When using the GNU linker, .gnu.linkonce. sections are used to
8892 eliminate duplicate copies of functions and vtables and such.
8893 The linker will arbitrarily choose one and discard the others.
8894 The AT_*_pc values for such functions refer to local labels in
8895 these sections. If the section from that file was discarded, the
8896 labels are not in the output, so the relocs get a value of 0.
8897 If this is a discarded function, mark the pc bounds as invalid,
8898 so that GDB will ignore it. */
8899 if (has_low_pc_attr
&& has_high_pc_attr
8900 && part_die
->lowpc
< part_die
->highpc
8901 && (part_die
->lowpc
!= 0
8902 || dwarf2_per_objfile
->has_section_at_zero
))
8903 part_die
->has_pc_info
= 1;
8908 /* Find a cached partial DIE at OFFSET in CU. */
8910 static struct partial_die_info
*
8911 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8913 struct partial_die_info
*lookup_die
= NULL
;
8914 struct partial_die_info part_die
;
8916 part_die
.offset
= offset
;
8917 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8922 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8923 except in the case of .debug_types DIEs which do not reference
8924 outside their CU (they do however referencing other types via
8927 static struct partial_die_info
*
8928 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8930 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8931 struct partial_die_info
*pd
= NULL
;
8933 if (cu
->per_cu
->from_debug_types
)
8935 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8941 if (offset_in_cu_p (&cu
->header
, offset
))
8943 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8948 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8950 if (per_cu
->cu
== NULL
|| per_cu
->cu
->partial_dies
== NULL
)
8951 load_partial_comp_unit (per_cu
, cu
->objfile
);
8953 per_cu
->cu
->last_used
= 0;
8954 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8956 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8958 struct cleanup
*back_to
;
8959 struct partial_die_info comp_unit_die
;
8960 struct abbrev_info
*abbrev
;
8961 unsigned int bytes_read
;
8964 per_cu
->load_all_dies
= 1;
8966 /* Re-read the DIEs. */
8967 back_to
= make_cleanup (null_cleanup
, 0);
8968 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8970 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8971 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8973 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8974 + per_cu
->cu
->header
.offset
8975 + per_cu
->cu
->header
.first_die_offset
);
8976 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8977 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8978 per_cu
->cu
->objfile
->obfd
,
8979 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8981 if (comp_unit_die
.has_children
)
8982 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8983 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8985 do_cleanups (back_to
);
8987 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8993 internal_error (__FILE__
, __LINE__
,
8994 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8995 offset
, bfd_get_filename (cu
->objfile
->obfd
));
8999 /* Adjust PART_DIE before generating a symbol for it. This function
9000 may set the is_external flag or change the DIE's name. */
9003 fixup_partial_die (struct partial_die_info
*part_die
,
9004 struct dwarf2_cu
*cu
)
9006 /* If we found a reference attribute and the DIE has no name, try
9007 to find a name in the referred to DIE. */
9009 if (part_die
->name
== NULL
&& part_die
->has_specification
)
9011 struct partial_die_info
*spec_die
;
9013 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
9015 fixup_partial_die (spec_die
, cu
);
9019 part_die
->name
= spec_die
->name
;
9021 /* Copy DW_AT_external attribute if it is set. */
9022 if (spec_die
->is_external
)
9023 part_die
->is_external
= spec_die
->is_external
;
9027 /* Set default names for some unnamed DIEs. */
9029 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
9030 part_die
->name
= "(anonymous namespace)";
9032 if (part_die
->tag
== DW_TAG_structure_type
9033 || part_die
->tag
== DW_TAG_class_type
9034 || part_die
->tag
== DW_TAG_union_type
)
9035 guess_structure_name (part_die
, cu
);
9038 /* Read an attribute value described by an attribute form. */
9041 read_attribute_value (struct attribute
*attr
, unsigned form
,
9042 bfd
*abfd
, gdb_byte
*info_ptr
,
9043 struct dwarf2_cu
*cu
)
9045 struct comp_unit_head
*cu_header
= &cu
->header
;
9046 unsigned int bytes_read
;
9047 struct dwarf_block
*blk
;
9052 case DW_FORM_ref_addr
:
9053 if (cu
->header
.version
== 2)
9054 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9056 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9057 info_ptr
+= bytes_read
;
9060 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
9061 info_ptr
+= bytes_read
;
9063 case DW_FORM_block2
:
9064 blk
= dwarf_alloc_block (cu
);
9065 blk
->size
= read_2_bytes (abfd
, info_ptr
);
9067 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9068 info_ptr
+= blk
->size
;
9069 DW_BLOCK (attr
) = blk
;
9071 case DW_FORM_block4
:
9072 blk
= dwarf_alloc_block (cu
);
9073 blk
->size
= read_4_bytes (abfd
, info_ptr
);
9075 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9076 info_ptr
+= blk
->size
;
9077 DW_BLOCK (attr
) = blk
;
9080 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
9084 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
9088 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
9091 case DW_FORM_sec_offset
:
9092 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
9093 info_ptr
+= bytes_read
;
9095 case DW_FORM_string
:
9096 DW_STRING (attr
) = read_direct_string (abfd
, info_ptr
, &bytes_read
);
9097 DW_STRING_IS_CANONICAL (attr
) = 0;
9098 info_ptr
+= bytes_read
;
9101 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
9103 DW_STRING_IS_CANONICAL (attr
) = 0;
9104 info_ptr
+= bytes_read
;
9106 case DW_FORM_exprloc
:
9108 blk
= dwarf_alloc_block (cu
);
9109 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9110 info_ptr
+= bytes_read
;
9111 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9112 info_ptr
+= blk
->size
;
9113 DW_BLOCK (attr
) = blk
;
9115 case DW_FORM_block1
:
9116 blk
= dwarf_alloc_block (cu
);
9117 blk
->size
= read_1_byte (abfd
, info_ptr
);
9119 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
9120 info_ptr
+= blk
->size
;
9121 DW_BLOCK (attr
) = blk
;
9124 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9128 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
9131 case DW_FORM_flag_present
:
9132 DW_UNSND (attr
) = 1;
9135 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
9136 info_ptr
+= bytes_read
;
9139 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9140 info_ptr
+= bytes_read
;
9143 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
9147 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
9151 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
9155 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
9159 /* Convert the signature to something we can record in DW_UNSND
9161 NOTE: This is NULL if the type wasn't found. */
9162 DW_SIGNATURED_TYPE (attr
) =
9163 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
9166 case DW_FORM_ref_udata
:
9167 DW_ADDR (attr
) = (cu
->header
.offset
9168 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
9169 info_ptr
+= bytes_read
;
9171 case DW_FORM_indirect
:
9172 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
9173 info_ptr
+= bytes_read
;
9174 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
9177 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
9178 dwarf_form_name (form
),
9179 bfd_get_filename (abfd
));
9182 /* We have seen instances where the compiler tried to emit a byte
9183 size attribute of -1 which ended up being encoded as an unsigned
9184 0xffffffff. Although 0xffffffff is technically a valid size value,
9185 an object of this size seems pretty unlikely so we can relatively
9186 safely treat these cases as if the size attribute was invalid and
9187 treat them as zero by default. */
9188 if (attr
->name
== DW_AT_byte_size
9189 && form
== DW_FORM_data4
9190 && DW_UNSND (attr
) >= 0xffffffff)
9193 (&symfile_complaints
,
9194 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
9195 hex_string (DW_UNSND (attr
)));
9196 DW_UNSND (attr
) = 0;
9202 /* Read an attribute described by an abbreviated attribute. */
9205 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
9206 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
9208 attr
->name
= abbrev
->name
;
9209 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
9212 /* read dwarf information from a buffer */
9215 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
9217 return bfd_get_8 (abfd
, buf
);
9221 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
9223 return bfd_get_signed_8 (abfd
, buf
);
9227 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
9229 return bfd_get_16 (abfd
, buf
);
9233 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9235 return bfd_get_signed_16 (abfd
, buf
);
9239 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
9241 return bfd_get_32 (abfd
, buf
);
9245 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
9247 return bfd_get_signed_32 (abfd
, buf
);
9251 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
9253 return bfd_get_64 (abfd
, buf
);
9257 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
9258 unsigned int *bytes_read
)
9260 struct comp_unit_head
*cu_header
= &cu
->header
;
9261 CORE_ADDR retval
= 0;
9263 if (cu_header
->signed_addr_p
)
9265 switch (cu_header
->addr_size
)
9268 retval
= bfd_get_signed_16 (abfd
, buf
);
9271 retval
= bfd_get_signed_32 (abfd
, buf
);
9274 retval
= bfd_get_signed_64 (abfd
, buf
);
9277 internal_error (__FILE__
, __LINE__
,
9278 _("read_address: bad switch, signed [in module %s]"),
9279 bfd_get_filename (abfd
));
9284 switch (cu_header
->addr_size
)
9287 retval
= bfd_get_16 (abfd
, buf
);
9290 retval
= bfd_get_32 (abfd
, buf
);
9293 retval
= bfd_get_64 (abfd
, buf
);
9296 internal_error (__FILE__
, __LINE__
,
9297 _("read_address: bad switch, unsigned [in module %s]"),
9298 bfd_get_filename (abfd
));
9302 *bytes_read
= cu_header
->addr_size
;
9306 /* Read the initial length from a section. The (draft) DWARF 3
9307 specification allows the initial length to take up either 4 bytes
9308 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
9309 bytes describe the length and all offsets will be 8 bytes in length
9312 An older, non-standard 64-bit format is also handled by this
9313 function. The older format in question stores the initial length
9314 as an 8-byte quantity without an escape value. Lengths greater
9315 than 2^32 aren't very common which means that the initial 4 bytes
9316 is almost always zero. Since a length value of zero doesn't make
9317 sense for the 32-bit format, this initial zero can be considered to
9318 be an escape value which indicates the presence of the older 64-bit
9319 format. As written, the code can't detect (old format) lengths
9320 greater than 4GB. If it becomes necessary to handle lengths
9321 somewhat larger than 4GB, we could allow other small values (such
9322 as the non-sensical values of 1, 2, and 3) to also be used as
9323 escape values indicating the presence of the old format.
9325 The value returned via bytes_read should be used to increment the
9326 relevant pointer after calling read_initial_length().
9328 [ Note: read_initial_length() and read_offset() are based on the
9329 document entitled "DWARF Debugging Information Format", revision
9330 3, draft 8, dated November 19, 2001. This document was obtained
9333 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
9335 This document is only a draft and is subject to change. (So beware.)
9337 Details regarding the older, non-standard 64-bit format were
9338 determined empirically by examining 64-bit ELF files produced by
9339 the SGI toolchain on an IRIX 6.5 machine.
9341 - Kevin, July 16, 2002
9345 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
9347 LONGEST length
= bfd_get_32 (abfd
, buf
);
9349 if (length
== 0xffffffff)
9351 length
= bfd_get_64 (abfd
, buf
+ 4);
9354 else if (length
== 0)
9356 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
9357 length
= bfd_get_64 (abfd
, buf
);
9368 /* Cover function for read_initial_length.
9369 Returns the length of the object at BUF, and stores the size of the
9370 initial length in *BYTES_READ and stores the size that offsets will be in
9372 If the initial length size is not equivalent to that specified in
9373 CU_HEADER then issue a complaint.
9374 This is useful when reading non-comp-unit headers. */
9377 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
9378 const struct comp_unit_head
*cu_header
,
9379 unsigned int *bytes_read
,
9380 unsigned int *offset_size
)
9382 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
9384 gdb_assert (cu_header
->initial_length_size
== 4
9385 || cu_header
->initial_length_size
== 8
9386 || cu_header
->initial_length_size
== 12);
9388 if (cu_header
->initial_length_size
!= *bytes_read
)
9389 complaint (&symfile_complaints
,
9390 _("intermixed 32-bit and 64-bit DWARF sections"));
9392 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
9396 /* Read an offset from the data stream. The size of the offset is
9397 given by cu_header->offset_size. */
9400 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
9401 unsigned int *bytes_read
)
9403 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
9405 *bytes_read
= cu_header
->offset_size
;
9409 /* Read an offset from the data stream. */
9412 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
9416 switch (offset_size
)
9419 retval
= bfd_get_32 (abfd
, buf
);
9422 retval
= bfd_get_64 (abfd
, buf
);
9425 internal_error (__FILE__
, __LINE__
,
9426 _("read_offset_1: bad switch [in module %s]"),
9427 bfd_get_filename (abfd
));
9434 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
9436 /* If the size of a host char is 8 bits, we can return a pointer
9437 to the buffer, otherwise we have to copy the data to a buffer
9438 allocated on the temporary obstack. */
9439 gdb_assert (HOST_CHAR_BIT
== 8);
9444 read_direct_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9446 /* If the size of a host char is 8 bits, we can return a pointer
9447 to the string, otherwise we have to copy the string to a buffer
9448 allocated on the temporary obstack. */
9449 gdb_assert (HOST_CHAR_BIT
== 8);
9452 *bytes_read_ptr
= 1;
9455 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
9456 return (char *) buf
;
9460 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
9461 const struct comp_unit_head
*cu_header
,
9462 unsigned int *bytes_read_ptr
)
9464 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
9466 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
9467 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
9469 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
9470 bfd_get_filename (abfd
));
9473 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
9475 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
9476 bfd_get_filename (abfd
));
9479 gdb_assert (HOST_CHAR_BIT
== 8);
9480 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
9482 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
9485 static unsigned long
9486 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9488 unsigned long result
;
9489 unsigned int num_read
;
9499 byte
= bfd_get_8 (abfd
, buf
);
9502 result
|= ((unsigned long)(byte
& 127) << shift
);
9503 if ((byte
& 128) == 0)
9509 *bytes_read_ptr
= num_read
;
9514 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
9517 int i
, shift
, num_read
;
9526 byte
= bfd_get_8 (abfd
, buf
);
9529 result
|= ((long)(byte
& 127) << shift
);
9531 if ((byte
& 128) == 0)
9536 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
9537 result
|= -(((long)1) << shift
);
9538 *bytes_read_ptr
= num_read
;
9542 /* Return a pointer to just past the end of an LEB128 number in BUF. */
9545 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
9551 byte
= bfd_get_8 (abfd
, buf
);
9553 if ((byte
& 128) == 0)
9559 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
9566 cu
->language
= language_c
;
9568 case DW_LANG_C_plus_plus
:
9569 cu
->language
= language_cplus
;
9572 cu
->language
= language_d
;
9574 case DW_LANG_Fortran77
:
9575 case DW_LANG_Fortran90
:
9576 case DW_LANG_Fortran95
:
9577 cu
->language
= language_fortran
;
9579 case DW_LANG_Mips_Assembler
:
9580 cu
->language
= language_asm
;
9583 cu
->language
= language_java
;
9587 cu
->language
= language_ada
;
9589 case DW_LANG_Modula2
:
9590 cu
->language
= language_m2
;
9592 case DW_LANG_Pascal83
:
9593 cu
->language
= language_pascal
;
9596 cu
->language
= language_objc
;
9598 case DW_LANG_Cobol74
:
9599 case DW_LANG_Cobol85
:
9601 cu
->language
= language_minimal
;
9604 cu
->language_defn
= language_def (cu
->language
);
9607 /* Return the named attribute or NULL if not there. */
9609 static struct attribute
*
9610 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
9613 struct attribute
*spec
= NULL
;
9615 for (i
= 0; i
< die
->num_attrs
; ++i
)
9617 if (die
->attrs
[i
].name
== name
)
9618 return &die
->attrs
[i
];
9619 if (die
->attrs
[i
].name
== DW_AT_specification
9620 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
9621 spec
= &die
->attrs
[i
];
9626 die
= follow_die_ref (die
, spec
, &cu
);
9627 return dwarf2_attr (die
, name
, cu
);
9633 /* Return the named attribute or NULL if not there,
9634 but do not follow DW_AT_specification, etc.
9635 This is for use in contexts where we're reading .debug_types dies.
9636 Following DW_AT_specification, DW_AT_abstract_origin will take us
9637 back up the chain, and we want to go down. */
9639 static struct attribute
*
9640 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
9641 struct dwarf2_cu
*cu
)
9645 for (i
= 0; i
< die
->num_attrs
; ++i
)
9646 if (die
->attrs
[i
].name
== name
)
9647 return &die
->attrs
[i
];
9652 /* Return non-zero iff the attribute NAME is defined for the given DIE,
9653 and holds a non-zero value. This function should only be used for
9654 DW_FORM_flag or DW_FORM_flag_present attributes. */
9657 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
9659 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
9661 return (attr
&& DW_UNSND (attr
));
9665 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
9667 /* A DIE is a declaration if it has a DW_AT_declaration attribute
9668 which value is non-zero. However, we have to be careful with
9669 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
9670 (via dwarf2_flag_true_p) follows this attribute. So we may
9671 end up accidently finding a declaration attribute that belongs
9672 to a different DIE referenced by the specification attribute,
9673 even though the given DIE does not have a declaration attribute. */
9674 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
9675 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
9678 /* Return the die giving the specification for DIE, if there is
9679 one. *SPEC_CU is the CU containing DIE on input, and the CU
9680 containing the return value on output. If there is no
9681 specification, but there is an abstract origin, that is
9684 static struct die_info
*
9685 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
9687 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
9690 if (spec_attr
== NULL
)
9691 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
9693 if (spec_attr
== NULL
)
9696 return follow_die_ref (die
, spec_attr
, spec_cu
);
9699 /* Free the line_header structure *LH, and any arrays and strings it
9702 free_line_header (struct line_header
*lh
)
9704 if (lh
->standard_opcode_lengths
)
9705 xfree (lh
->standard_opcode_lengths
);
9707 /* Remember that all the lh->file_names[i].name pointers are
9708 pointers into debug_line_buffer, and don't need to be freed. */
9710 xfree (lh
->file_names
);
9712 /* Similarly for the include directory names. */
9713 if (lh
->include_dirs
)
9714 xfree (lh
->include_dirs
);
9720 /* Add an entry to LH's include directory table. */
9722 add_include_dir (struct line_header
*lh
, char *include_dir
)
9724 /* Grow the array if necessary. */
9725 if (lh
->include_dirs_size
== 0)
9727 lh
->include_dirs_size
= 1; /* for testing */
9728 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9729 * sizeof (*lh
->include_dirs
));
9731 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9733 lh
->include_dirs_size
*= 2;
9734 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9735 (lh
->include_dirs_size
9736 * sizeof (*lh
->include_dirs
)));
9739 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9743 /* Add an entry to LH's file name table. */
9745 add_file_name (struct line_header
*lh
,
9747 unsigned int dir_index
,
9748 unsigned int mod_time
,
9749 unsigned int length
)
9751 struct file_entry
*fe
;
9753 /* Grow the array if necessary. */
9754 if (lh
->file_names_size
== 0)
9756 lh
->file_names_size
= 1; /* for testing */
9757 lh
->file_names
= xmalloc (lh
->file_names_size
9758 * sizeof (*lh
->file_names
));
9760 else if (lh
->num_file_names
>= lh
->file_names_size
)
9762 lh
->file_names_size
*= 2;
9763 lh
->file_names
= xrealloc (lh
->file_names
,
9764 (lh
->file_names_size
9765 * sizeof (*lh
->file_names
)));
9768 fe
= &lh
->file_names
[lh
->num_file_names
++];
9770 fe
->dir_index
= dir_index
;
9771 fe
->mod_time
= mod_time
;
9772 fe
->length
= length
;
9778 /* Read the statement program header starting at OFFSET in
9779 .debug_line, according to the endianness of ABFD. Return a pointer
9780 to a struct line_header, allocated using xmalloc.
9782 NOTE: the strings in the include directory and file name tables of
9783 the returned object point into debug_line_buffer, and must not be
9785 static struct line_header
*
9786 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9787 struct dwarf2_cu
*cu
)
9789 struct cleanup
*back_to
;
9790 struct line_header
*lh
;
9792 unsigned int bytes_read
, offset_size
;
9794 char *cur_dir
, *cur_file
;
9796 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9797 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9799 complaint (&symfile_complaints
, _("missing .debug_line section"));
9803 /* Make sure that at least there's room for the total_length field.
9804 That could be 12 bytes long, but we're just going to fudge that. */
9805 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9807 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9811 lh
= xmalloc (sizeof (*lh
));
9812 memset (lh
, 0, sizeof (*lh
));
9813 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9816 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9818 /* Read in the header. */
9820 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9821 &bytes_read
, &offset_size
);
9822 line_ptr
+= bytes_read
;
9823 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9824 + dwarf2_per_objfile
->line
.size
))
9826 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9829 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9830 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9832 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9833 line_ptr
+= offset_size
;
9834 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9836 if (lh
->version
>= 4)
9838 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9842 lh
->maximum_ops_per_instruction
= 1;
9844 if (lh
->maximum_ops_per_instruction
== 0)
9846 lh
->maximum_ops_per_instruction
= 1;
9847 complaint (&symfile_complaints
,
9848 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9851 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9853 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9855 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9857 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9859 lh
->standard_opcode_lengths
9860 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9862 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9863 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9865 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9869 /* Read directory table. */
9870 while ((cur_dir
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9872 line_ptr
+= bytes_read
;
9873 add_include_dir (lh
, cur_dir
);
9875 line_ptr
+= bytes_read
;
9877 /* Read file name table. */
9878 while ((cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9880 unsigned int dir_index
, mod_time
, length
;
9882 line_ptr
+= bytes_read
;
9883 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9884 line_ptr
+= bytes_read
;
9885 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9886 line_ptr
+= bytes_read
;
9887 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9888 line_ptr
+= bytes_read
;
9890 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9892 line_ptr
+= bytes_read
;
9893 lh
->statement_program_start
= line_ptr
;
9895 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9896 + dwarf2_per_objfile
->line
.size
))
9897 complaint (&symfile_complaints
,
9898 _("line number info header doesn't fit in `.debug_line' section"));
9900 discard_cleanups (back_to
);
9904 /* This function exists to work around a bug in certain compilers
9905 (particularly GCC 2.95), in which the first line number marker of a
9906 function does not show up until after the prologue, right before
9907 the second line number marker. This function shifts ADDRESS down
9908 to the beginning of the function if necessary, and is called on
9909 addresses passed to record_line. */
9912 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9914 struct function_range
*fn
;
9916 /* Find the function_range containing address. */
9921 cu
->cached_fn
= cu
->first_fn
;
9925 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9931 while (fn
&& fn
!= cu
->cached_fn
)
9932 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9942 if (address
!= fn
->lowpc
)
9943 complaint (&symfile_complaints
,
9944 _("misplaced first line number at 0x%lx for '%s'"),
9945 (unsigned long) address
, fn
->name
);
9950 /* Subroutine of dwarf_decode_lines to simplify it.
9951 Return the file name of the psymtab for included file FILE_INDEX
9952 in line header LH of PST.
9953 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
9954 If space for the result is malloc'd, it will be freed by a cleanup.
9955 Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */
9958 psymtab_include_file_name (const struct line_header
*lh
, int file_index
,
9959 const struct partial_symtab
*pst
,
9960 const char *comp_dir
)
9962 const struct file_entry fe
= lh
->file_names
[file_index
];
9963 char *include_name
= fe
.name
;
9964 char *include_name_to_compare
= include_name
;
9965 char *dir_name
= NULL
;
9970 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
9972 if (!IS_ABSOLUTE_PATH (include_name
)
9973 && (dir_name
!= NULL
|| comp_dir
!= NULL
))
9975 /* Avoid creating a duplicate psymtab for PST.
9976 We do this by comparing INCLUDE_NAME and PST_FILENAME.
9977 Before we do the comparison, however, we need to account
9978 for DIR_NAME and COMP_DIR.
9979 First prepend dir_name (if non-NULL). If we still don't
9980 have an absolute path prepend comp_dir (if non-NULL).
9981 However, the directory we record in the include-file's
9982 psymtab does not contain COMP_DIR (to match the
9983 corresponding symtab(s)).
9988 bash$ gcc -g ./hello.c
9989 include_name = "hello.c"
9991 DW_AT_comp_dir = comp_dir = "/tmp"
9992 DW_AT_name = "./hello.c" */
9994 if (dir_name
!= NULL
)
9996 include_name
= concat (dir_name
, SLASH_STRING
,
9997 include_name
, (char *)NULL
);
9998 include_name_to_compare
= include_name
;
9999 make_cleanup (xfree
, include_name
);
10001 if (!IS_ABSOLUTE_PATH (include_name
) && comp_dir
!= NULL
)
10003 include_name_to_compare
= concat (comp_dir
, SLASH_STRING
,
10004 include_name
, (char *)NULL
);
10008 pst_filename
= pst
->filename
;
10009 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
10011 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
10012 pst_filename
, (char *)NULL
);
10015 file_is_pst
= strcmp (include_name_to_compare
, pst_filename
) == 0;
10017 if (include_name_to_compare
!= include_name
)
10018 xfree (include_name_to_compare
);
10019 if (pst_filename
!= pst
->filename
)
10020 xfree (pst_filename
);
10024 return include_name
;
10027 /* Decode the Line Number Program (LNP) for the given line_header
10028 structure and CU. The actual information extracted and the type
10029 of structures created from the LNP depends on the value of PST.
10031 1. If PST is NULL, then this procedure uses the data from the program
10032 to create all necessary symbol tables, and their linetables.
10034 2. If PST is not NULL, this procedure reads the program to determine
10035 the list of files included by the unit represented by PST, and
10036 builds all the associated partial symbol tables.
10038 COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown.
10039 It is used for relative paths in the line table.
10040 NOTE: When processing partial symtabs (pst != NULL),
10041 comp_dir == pst->dirname.
10043 NOTE: It is important that psymtabs have the same file name (via strcmp)
10044 as the corresponding symtab. Since COMP_DIR is not used in the name of the
10045 symtab we don't use it in the name of the psymtabs we create.
10046 E.g. expand_line_sal requires this when finding psymtabs to expand.
10047 A good testcase for this is mb-inline.exp. */
10050 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
10051 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
10053 gdb_byte
*line_ptr
, *extended_end
;
10054 gdb_byte
*line_end
;
10055 unsigned int bytes_read
, extended_len
;
10056 unsigned char op_code
, extended_op
, adj_opcode
;
10057 CORE_ADDR baseaddr
;
10058 struct objfile
*objfile
= cu
->objfile
;
10059 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
10060 const int decode_for_pst_p
= (pst
!= NULL
);
10061 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
10063 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10065 line_ptr
= lh
->statement_program_start
;
10066 line_end
= lh
->statement_program_end
;
10068 /* Read the statement sequences until there's nothing left. */
10069 while (line_ptr
< line_end
)
10071 /* state machine registers */
10072 CORE_ADDR address
= 0;
10073 unsigned int file
= 1;
10074 unsigned int line
= 1;
10075 unsigned int column
= 0;
10076 int is_stmt
= lh
->default_is_stmt
;
10077 int basic_block
= 0;
10078 int end_sequence
= 0;
10080 unsigned char op_index
= 0;
10082 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
10084 /* Start a subfile for the current file of the state machine. */
10085 /* lh->include_dirs and lh->file_names are 0-based, but the
10086 directory and file name numbers in the statement program
10088 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10092 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10094 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10097 /* Decode the table. */
10098 while (!end_sequence
)
10100 op_code
= read_1_byte (abfd
, line_ptr
);
10102 if (line_ptr
> line_end
)
10104 dwarf2_debug_line_missing_end_sequence_complaint ();
10108 if (op_code
>= lh
->opcode_base
)
10110 /* Special operand. */
10111 adj_opcode
= op_code
- lh
->opcode_base
;
10112 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
10113 / lh
->maximum_ops_per_instruction
)
10114 * lh
->minimum_instruction_length
);
10115 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
10116 % lh
->maximum_ops_per_instruction
);
10117 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
10118 if (lh
->num_file_names
< file
|| file
== 0)
10119 dwarf2_debug_line_missing_file_complaint ();
10120 /* For now we ignore lines not starting on an
10121 instruction boundary. */
10122 else if (op_index
== 0)
10124 lh
->file_names
[file
- 1].included_p
= 1;
10125 if (!decode_for_pst_p
&& is_stmt
)
10127 if (last_subfile
!= current_subfile
)
10129 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10131 record_line (last_subfile
, 0, addr
);
10132 last_subfile
= current_subfile
;
10134 /* Append row to matrix using current values. */
10135 addr
= check_cu_functions (address
, cu
);
10136 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10137 record_line (current_subfile
, line
, addr
);
10142 else switch (op_code
)
10144 case DW_LNS_extended_op
:
10145 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10146 line_ptr
+= bytes_read
;
10147 extended_end
= line_ptr
+ extended_len
;
10148 extended_op
= read_1_byte (abfd
, line_ptr
);
10150 switch (extended_op
)
10152 case DW_LNE_end_sequence
:
10155 case DW_LNE_set_address
:
10156 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
10158 line_ptr
+= bytes_read
;
10159 address
+= baseaddr
;
10161 case DW_LNE_define_file
:
10164 unsigned int dir_index
, mod_time
, length
;
10166 cur_file
= read_direct_string (abfd
, line_ptr
, &bytes_read
);
10167 line_ptr
+= bytes_read
;
10169 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10170 line_ptr
+= bytes_read
;
10172 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10173 line_ptr
+= bytes_read
;
10175 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10176 line_ptr
+= bytes_read
;
10177 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
10180 case DW_LNE_set_discriminator
:
10181 /* The discriminator is not interesting to the debugger;
10183 line_ptr
= extended_end
;
10186 complaint (&symfile_complaints
,
10187 _("mangled .debug_line section"));
10190 /* Make sure that we parsed the extended op correctly. If e.g.
10191 we expected a different address size than the producer used,
10192 we may have read the wrong number of bytes. */
10193 if (line_ptr
!= extended_end
)
10195 complaint (&symfile_complaints
,
10196 _("mangled .debug_line section"));
10201 if (lh
->num_file_names
< file
|| file
== 0)
10202 dwarf2_debug_line_missing_file_complaint ();
10205 lh
->file_names
[file
- 1].included_p
= 1;
10206 if (!decode_for_pst_p
&& is_stmt
)
10208 if (last_subfile
!= current_subfile
)
10210 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10212 record_line (last_subfile
, 0, addr
);
10213 last_subfile
= current_subfile
;
10215 addr
= check_cu_functions (address
, cu
);
10216 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
10217 record_line (current_subfile
, line
, addr
);
10222 case DW_LNS_advance_pc
:
10225 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10227 address
+= (((op_index
+ adjust
)
10228 / lh
->maximum_ops_per_instruction
)
10229 * lh
->minimum_instruction_length
);
10230 op_index
= ((op_index
+ adjust
)
10231 % lh
->maximum_ops_per_instruction
);
10232 line_ptr
+= bytes_read
;
10235 case DW_LNS_advance_line
:
10236 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
10237 line_ptr
+= bytes_read
;
10239 case DW_LNS_set_file
:
10241 /* The arrays lh->include_dirs and lh->file_names are
10242 0-based, but the directory and file name numbers in
10243 the statement program are 1-based. */
10244 struct file_entry
*fe
;
10247 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10248 line_ptr
+= bytes_read
;
10249 if (lh
->num_file_names
< file
|| file
== 0)
10250 dwarf2_debug_line_missing_file_complaint ();
10253 fe
= &lh
->file_names
[file
- 1];
10255 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10256 if (!decode_for_pst_p
)
10258 last_subfile
= current_subfile
;
10259 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10264 case DW_LNS_set_column
:
10265 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10266 line_ptr
+= bytes_read
;
10268 case DW_LNS_negate_stmt
:
10269 is_stmt
= (!is_stmt
);
10271 case DW_LNS_set_basic_block
:
10274 /* Add to the address register of the state machine the
10275 address increment value corresponding to special opcode
10276 255. I.e., this value is scaled by the minimum
10277 instruction length since special opcode 255 would have
10278 scaled the the increment. */
10279 case DW_LNS_const_add_pc
:
10281 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
10283 address
+= (((op_index
+ adjust
)
10284 / lh
->maximum_ops_per_instruction
)
10285 * lh
->minimum_instruction_length
);
10286 op_index
= ((op_index
+ adjust
)
10287 % lh
->maximum_ops_per_instruction
);
10290 case DW_LNS_fixed_advance_pc
:
10291 address
+= read_2_bytes (abfd
, line_ptr
);
10297 /* Unknown standard opcode, ignore it. */
10300 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
10302 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
10303 line_ptr
+= bytes_read
;
10308 if (lh
->num_file_names
< file
|| file
== 0)
10309 dwarf2_debug_line_missing_file_complaint ();
10312 lh
->file_names
[file
- 1].included_p
= 1;
10313 if (!decode_for_pst_p
)
10315 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
10316 record_line (current_subfile
, 0, addr
);
10321 if (decode_for_pst_p
)
10325 /* Now that we're done scanning the Line Header Program, we can
10326 create the psymtab of each included file. */
10327 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
10328 if (lh
->file_names
[file_index
].included_p
== 1)
10330 char *include_name
=
10331 psymtab_include_file_name (lh
, file_index
, pst
, comp_dir
);
10332 if (include_name
!= NULL
)
10333 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
10338 /* Make sure a symtab is created for every file, even files
10339 which contain only variables (i.e. no code with associated
10343 struct file_entry
*fe
;
10345 for (i
= 0; i
< lh
->num_file_names
; i
++)
10349 fe
= &lh
->file_names
[i
];
10351 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10352 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
10354 /* Skip the main file; we don't need it, and it must be
10355 allocated last, so that it will show up before the
10356 non-primary symtabs in the objfile's symtab list. */
10357 if (current_subfile
== first_subfile
)
10360 if (current_subfile
->symtab
== NULL
)
10361 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
10363 fe
->symtab
= current_subfile
->symtab
;
10368 /* Start a subfile for DWARF. FILENAME is the name of the file and
10369 DIRNAME the name of the source directory which contains FILENAME
10370 or NULL if not known. COMP_DIR is the compilation directory for the
10371 linetable's compilation unit or NULL if not known.
10372 This routine tries to keep line numbers from identical absolute and
10373 relative file names in a common subfile.
10375 Using the `list' example from the GDB testsuite, which resides in
10376 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
10377 of /srcdir/list0.c yields the following debugging information for list0.c:
10379 DW_AT_name: /srcdir/list0.c
10380 DW_AT_comp_dir: /compdir
10381 files.files[0].name: list0.h
10382 files.files[0].dir: /srcdir
10383 files.files[1].name: list0.c
10384 files.files[1].dir: /srcdir
10386 The line number information for list0.c has to end up in a single
10387 subfile, so that `break /srcdir/list0.c:1' works as expected.
10388 start_subfile will ensure that this happens provided that we pass the
10389 concatenation of files.files[1].dir and files.files[1].name as the
10393 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
10397 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
10398 `start_symtab' will always pass the contents of DW_AT_comp_dir as
10399 second argument to start_subfile. To be consistent, we do the
10400 same here. In order not to lose the line information directory,
10401 we concatenate it to the filename when it makes sense.
10402 Note that the Dwarf3 standard says (speaking of filenames in line
10403 information): ``The directory index is ignored for file names
10404 that represent full path names''. Thus ignoring dirname in the
10405 `else' branch below isn't an issue. */
10407 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
10408 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
10410 fullname
= filename
;
10412 start_subfile (fullname
, comp_dir
);
10414 if (fullname
!= filename
)
10419 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
10420 struct dwarf2_cu
*cu
)
10422 struct objfile
*objfile
= cu
->objfile
;
10423 struct comp_unit_head
*cu_header
= &cu
->header
;
10425 /* NOTE drow/2003-01-30: There used to be a comment and some special
10426 code here to turn a symbol with DW_AT_external and a
10427 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
10428 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
10429 with some versions of binutils) where shared libraries could have
10430 relocations against symbols in their debug information - the
10431 minimal symbol would have the right address, but the debug info
10432 would not. It's no longer necessary, because we will explicitly
10433 apply relocations when we read in the debug information now. */
10435 /* A DW_AT_location attribute with no contents indicates that a
10436 variable has been optimized away. */
10437 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
10439 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10443 /* Handle one degenerate form of location expression specially, to
10444 preserve GDB's previous behavior when section offsets are
10445 specified. If this is just a DW_OP_addr then mark this symbol
10448 if (attr_form_is_block (attr
)
10449 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
10450 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
10452 unsigned int dummy
;
10454 SYMBOL_VALUE_ADDRESS (sym
) =
10455 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
10456 SYMBOL_CLASS (sym
) = LOC_STATIC
;
10457 fixup_symbol_section (sym
, objfile
);
10458 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
10459 SYMBOL_SECTION (sym
));
10463 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
10464 expression evaluator, and use LOC_COMPUTED only when necessary
10465 (i.e. when the value of a register or memory location is
10466 referenced, or a thread-local block, etc.). Then again, it might
10467 not be worthwhile. I'm assuming that it isn't unless performance
10468 or memory numbers show me otherwise. */
10470 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
10471 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10474 /* Given a pointer to a DWARF information entry, figure out if we need
10475 to make a symbol table entry for it, and if so, create a new entry
10476 and return a pointer to it.
10477 If TYPE is NULL, determine symbol type from the die, otherwise
10478 used the passed type.
10479 If SPACE is not NULL, use it to hold the new symbol. If it is
10480 NULL, allocate a new symbol on the objfile's obstack. */
10482 static struct symbol
*
10483 new_symbol_full (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
,
10484 struct symbol
*space
)
10486 struct objfile
*objfile
= cu
->objfile
;
10487 struct symbol
*sym
= NULL
;
10489 struct attribute
*attr
= NULL
;
10490 struct attribute
*attr2
= NULL
;
10491 CORE_ADDR baseaddr
;
10492 struct pending
**list_to_add
= NULL
;
10494 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
10496 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
10498 name
= dwarf2_name (die
, cu
);
10501 const char *linkagename
;
10502 int suppress_add
= 0;
10507 sym
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct symbol
);
10508 OBJSTAT (objfile
, n_syms
++);
10510 /* Cache this symbol's name and the name's demangled form (if any). */
10511 SYMBOL_SET_LANGUAGE (sym
, cu
->language
);
10512 linkagename
= dwarf2_physname (name
, die
, cu
);
10513 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
10515 /* Fortran does not have mangling standard and the mangling does differ
10516 between gfortran, iFort etc. */
10517 if (cu
->language
== language_fortran
10518 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
10519 symbol_set_demangled_name (&(sym
->ginfo
),
10520 (char *) dwarf2_full_name (name
, die
, cu
),
10523 /* Default assumptions.
10524 Use the passed type or decode it from the die. */
10525 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10526 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
10528 SYMBOL_TYPE (sym
) = type
;
10530 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
10531 attr
= dwarf2_attr (die
,
10532 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
10536 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
10539 attr
= dwarf2_attr (die
,
10540 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
10544 int file_index
= DW_UNSND (attr
);
10546 if (cu
->line_header
== NULL
10547 || file_index
> cu
->line_header
->num_file_names
)
10548 complaint (&symfile_complaints
,
10549 _("file index out of range"));
10550 else if (file_index
> 0)
10552 struct file_entry
*fe
;
10554 fe
= &cu
->line_header
->file_names
[file_index
- 1];
10555 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
10562 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
10565 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
10567 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
10568 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
10569 SYMBOL_CLASS (sym
) = LOC_LABEL
;
10570 add_symbol_to_list (sym
, cu
->list_in_scope
);
10572 case DW_TAG_subprogram
:
10573 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10575 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10576 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10577 if ((attr2
&& (DW_UNSND (attr2
) != 0))
10578 || cu
->language
== language_ada
)
10580 /* Subprograms marked external are stored as a global symbol.
10581 Ada subprograms, whether marked external or not, are always
10582 stored as a global symbol, because we want to be able to
10583 access them globally. For instance, we want to be able
10584 to break on a nested subprogram without having to
10585 specify the context. */
10586 list_to_add
= &global_symbols
;
10590 list_to_add
= cu
->list_in_scope
;
10593 case DW_TAG_inlined_subroutine
:
10594 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
10596 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
10597 SYMBOL_INLINED (sym
) = 1;
10598 /* Do not add the symbol to any lists. It will be found via
10599 BLOCK_FUNCTION from the blockvector. */
10601 case DW_TAG_template_value_param
:
10603 /* Fall through. */
10604 case DW_TAG_constant
:
10605 case DW_TAG_variable
:
10606 case DW_TAG_member
:
10607 /* Compilation with minimal debug info may result in variables
10608 with missing type entries. Change the misleading `void' type
10609 to something sensible. */
10610 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
10612 = objfile_type (objfile
)->nodebug_data_symbol
;
10614 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10615 /* In the case of DW_TAG_member, we should only be called for
10616 static const members. */
10617 if (die
->tag
== DW_TAG_member
)
10619 /* dwarf2_add_field uses die_is_declaration,
10620 so we do the same. */
10621 gdb_assert (die_is_declaration (die
, cu
));
10626 dwarf2_const_value (attr
, sym
, cu
);
10627 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10630 if (attr2
&& (DW_UNSND (attr2
) != 0))
10631 list_to_add
= &global_symbols
;
10633 list_to_add
= cu
->list_in_scope
;
10637 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10640 var_decode_location (attr
, sym
, cu
);
10641 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10642 if (SYMBOL_CLASS (sym
) == LOC_STATIC
10643 && SYMBOL_VALUE_ADDRESS (sym
) == 0
10644 && !dwarf2_per_objfile
->has_section_at_zero
)
10646 /* When a static variable is eliminated by the linker,
10647 the corresponding debug information is not stripped
10648 out, but the variable address is set to null;
10649 do not add such variables into symbol table. */
10651 else if (attr2
&& (DW_UNSND (attr2
) != 0))
10653 /* Workaround gfortran PR debug/40040 - it uses
10654 DW_AT_location for variables in -fPIC libraries which may
10655 get overriden by other libraries/executable and get
10656 a different address. Resolve it by the minimal symbol
10657 which may come from inferior's executable using copy
10658 relocation. Make this workaround only for gfortran as for
10659 other compilers GDB cannot guess the minimal symbol
10660 Fortran mangling kind. */
10661 if (cu
->language
== language_fortran
&& die
->parent
10662 && die
->parent
->tag
== DW_TAG_module
10664 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
10665 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10667 /* A variable with DW_AT_external is never static,
10668 but it may be block-scoped. */
10669 list_to_add
= (cu
->list_in_scope
== &file_symbols
10670 ? &global_symbols
: cu
->list_in_scope
);
10673 list_to_add
= cu
->list_in_scope
;
10677 /* We do not know the address of this symbol.
10678 If it is an external symbol and we have type information
10679 for it, enter the symbol as a LOC_UNRESOLVED symbol.
10680 The address of the variable will then be determined from
10681 the minimal symbol table whenever the variable is
10683 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
10684 if (attr2
&& (DW_UNSND (attr2
) != 0)
10685 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
10687 /* A variable with DW_AT_external is never static, but it
10688 may be block-scoped. */
10689 list_to_add
= (cu
->list_in_scope
== &file_symbols
10690 ? &global_symbols
: cu
->list_in_scope
);
10692 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
10694 else if (!die_is_declaration (die
, cu
))
10696 /* Use the default LOC_OPTIMIZED_OUT class. */
10697 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
10699 list_to_add
= cu
->list_in_scope
;
10703 case DW_TAG_formal_parameter
:
10704 /* If we are inside a function, mark this as an argument. If
10705 not, we might be looking at an argument to an inlined function
10706 when we do not have enough information to show inlined frames;
10707 pretend it's a local variable in that case so that the user can
10709 if (context_stack_depth
> 0
10710 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
10711 SYMBOL_IS_ARGUMENT (sym
) = 1;
10712 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
10715 var_decode_location (attr
, sym
, cu
);
10717 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10720 dwarf2_const_value (attr
, sym
, cu
);
10722 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
10723 if (attr
&& DW_UNSND (attr
))
10725 struct type
*ref_type
;
10727 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
10728 SYMBOL_TYPE (sym
) = ref_type
;
10731 list_to_add
= cu
->list_in_scope
;
10733 case DW_TAG_unspecified_parameters
:
10734 /* From varargs functions; gdb doesn't seem to have any
10735 interest in this information, so just ignore it for now.
10738 case DW_TAG_template_type_param
:
10740 /* Fall through. */
10741 case DW_TAG_class_type
:
10742 case DW_TAG_interface_type
:
10743 case DW_TAG_structure_type
:
10744 case DW_TAG_union_type
:
10745 case DW_TAG_set_type
:
10746 case DW_TAG_enumeration_type
:
10747 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10748 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
10751 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
10752 really ever be static objects: otherwise, if you try
10753 to, say, break of a class's method and you're in a file
10754 which doesn't mention that class, it won't work unless
10755 the check for all static symbols in lookup_symbol_aux
10756 saves you. See the OtherFileClass tests in
10757 gdb.c++/namespace.exp. */
10761 list_to_add
= (cu
->list_in_scope
== &file_symbols
10762 && (cu
->language
== language_cplus
10763 || cu
->language
== language_java
)
10764 ? &global_symbols
: cu
->list_in_scope
);
10766 /* The semantics of C++ state that "struct foo {
10767 ... }" also defines a typedef for "foo". A Java
10768 class declaration also defines a typedef for the
10770 if (cu
->language
== language_cplus
10771 || cu
->language
== language_java
10772 || cu
->language
== language_ada
)
10774 /* The symbol's name is already allocated along
10775 with this objfile, so we don't need to
10776 duplicate it for the type. */
10777 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
10778 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
10783 case DW_TAG_typedef
:
10784 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10785 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10786 list_to_add
= cu
->list_in_scope
;
10788 case DW_TAG_base_type
:
10789 case DW_TAG_subrange_type
:
10790 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10791 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10792 list_to_add
= cu
->list_in_scope
;
10794 case DW_TAG_enumerator
:
10795 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10798 dwarf2_const_value (attr
, sym
, cu
);
10801 /* NOTE: carlton/2003-11-10: See comment above in the
10802 DW_TAG_class_type, etc. block. */
10804 list_to_add
= (cu
->list_in_scope
== &file_symbols
10805 && (cu
->language
== language_cplus
10806 || cu
->language
== language_java
)
10807 ? &global_symbols
: cu
->list_in_scope
);
10810 case DW_TAG_namespace
:
10811 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10812 list_to_add
= &global_symbols
;
10815 /* Not a tag we recognize. Hopefully we aren't processing
10816 trash data, but since we must specifically ignore things
10817 we don't recognize, there is nothing else we should do at
10819 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10820 dwarf_tag_name (die
->tag
));
10826 sym
->hash_next
= objfile
->template_symbols
;
10827 objfile
->template_symbols
= sym
;
10828 list_to_add
= NULL
;
10831 if (list_to_add
!= NULL
)
10832 add_symbol_to_list (sym
, list_to_add
);
10834 /* For the benefit of old versions of GCC, check for anonymous
10835 namespaces based on the demangled name. */
10836 if (!processing_has_namespace_info
10837 && cu
->language
== language_cplus
)
10838 cp_scan_for_anonymous_namespaces (sym
);
10843 /* A wrapper for new_symbol_full that always allocates a new symbol. */
10845 static struct symbol
*
10846 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10848 return new_symbol_full (die
, type
, cu
, NULL
);
10851 /* Given an attr with a DW_FORM_dataN value in host byte order,
10852 zero-extend it as appropriate for the symbol's type. The DWARF
10853 standard (v4) is not entirely clear about the meaning of using
10854 DW_FORM_dataN for a constant with a signed type, where the type is
10855 wider than the data. The conclusion of a discussion on the DWARF
10856 list was that this is unspecified. We choose to always zero-extend
10857 because that is the interpretation long in use by GCC. */
10860 dwarf2_const_value_data (struct attribute
*attr
, struct type
*type
,
10861 const char *name
, struct obstack
*obstack
,
10862 struct dwarf2_cu
*cu
, long *value
, int bits
)
10864 struct objfile
*objfile
= cu
->objfile
;
10865 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10866 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10867 LONGEST l
= DW_UNSND (attr
);
10869 if (bits
< sizeof (*value
) * 8)
10871 l
&= ((LONGEST
) 1 << bits
) - 1;
10874 else if (bits
== sizeof (*value
) * 8)
10878 gdb_byte
*bytes
= obstack_alloc (obstack
, bits
/ 8);
10879 store_unsigned_integer (bytes
, bits
/ 8, byte_order
, l
);
10886 /* Read a constant value from an attribute. Either set *VALUE, or if
10887 the value does not fit in *VALUE, set *BYTES - either already
10888 allocated on the objfile obstack, or newly allocated on OBSTACK,
10889 or, set *BATON, if we translated the constant to a location
10893 dwarf2_const_value_attr (struct attribute
*attr
, struct type
*type
,
10894 const char *name
, struct obstack
*obstack
,
10895 struct dwarf2_cu
*cu
,
10896 long *value
, gdb_byte
**bytes
,
10897 struct dwarf2_locexpr_baton
**baton
)
10899 struct objfile
*objfile
= cu
->objfile
;
10900 struct comp_unit_head
*cu_header
= &cu
->header
;
10901 struct dwarf_block
*blk
;
10902 enum bfd_endian byte_order
= (bfd_big_endian (objfile
->obfd
) ?
10903 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
);
10909 switch (attr
->form
)
10915 if (TYPE_LENGTH (type
) != cu_header
->addr_size
)
10916 dwarf2_const_value_length_mismatch_complaint (name
,
10917 cu_header
->addr_size
,
10918 TYPE_LENGTH (type
));
10919 /* Symbols of this form are reasonably rare, so we just
10920 piggyback on the existing location code rather than writing
10921 a new implementation of symbol_computed_ops. */
10922 *baton
= obstack_alloc (&objfile
->objfile_obstack
,
10923 sizeof (struct dwarf2_locexpr_baton
));
10924 (*baton
)->per_cu
= cu
->per_cu
;
10925 gdb_assert ((*baton
)->per_cu
);
10927 (*baton
)->size
= 2 + cu_header
->addr_size
;
10928 data
= obstack_alloc (&objfile
->objfile_obstack
, (*baton
)->size
);
10929 (*baton
)->data
= data
;
10931 data
[0] = DW_OP_addr
;
10932 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
10933 byte_order
, DW_ADDR (attr
));
10934 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
10937 case DW_FORM_string
:
10939 /* DW_STRING is already allocated on the objfile obstack, point
10941 *bytes
= (gdb_byte
*) DW_STRING (attr
);
10943 case DW_FORM_block1
:
10944 case DW_FORM_block2
:
10945 case DW_FORM_block4
:
10946 case DW_FORM_block
:
10947 case DW_FORM_exprloc
:
10948 blk
= DW_BLOCK (attr
);
10949 if (TYPE_LENGTH (type
) != blk
->size
)
10950 dwarf2_const_value_length_mismatch_complaint (name
, blk
->size
,
10951 TYPE_LENGTH (type
));
10952 *bytes
= blk
->data
;
10955 /* The DW_AT_const_value attributes are supposed to carry the
10956 symbol's value "represented as it would be on the target
10957 architecture." By the time we get here, it's already been
10958 converted to host endianness, so we just need to sign- or
10959 zero-extend it as appropriate. */
10960 case DW_FORM_data1
:
10961 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 8);
10963 case DW_FORM_data2
:
10964 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 16);
10966 case DW_FORM_data4
:
10967 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 32);
10969 case DW_FORM_data8
:
10970 *bytes
= dwarf2_const_value_data (attr
, type
, name
, obstack
, cu
, value
, 64);
10973 case DW_FORM_sdata
:
10974 *value
= DW_SND (attr
);
10977 case DW_FORM_udata
:
10978 *value
= DW_UNSND (attr
);
10982 complaint (&symfile_complaints
,
10983 _("unsupported const value attribute form: '%s'"),
10984 dwarf_form_name (attr
->form
));
10991 /* Copy constant value from an attribute to a symbol. */
10994 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
10995 struct dwarf2_cu
*cu
)
10997 struct objfile
*objfile
= cu
->objfile
;
10998 struct comp_unit_head
*cu_header
= &cu
->header
;
11001 struct dwarf2_locexpr_baton
*baton
;
11003 dwarf2_const_value_attr (attr
, SYMBOL_TYPE (sym
),
11004 SYMBOL_PRINT_NAME (sym
),
11005 &objfile
->objfile_obstack
, cu
,
11006 &value
, &bytes
, &baton
);
11010 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11011 SYMBOL_LOCATION_BATON (sym
) = baton
;
11012 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
11014 else if (bytes
!= NULL
)
11016 SYMBOL_VALUE_BYTES (sym
) = bytes
;
11017 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
11021 SYMBOL_VALUE (sym
) = value
;
11022 SYMBOL_CLASS (sym
) = LOC_CONST
;
11026 /* Return the type of the die in question using its DW_AT_type attribute. */
11028 static struct type
*
11029 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11031 struct attribute
*type_attr
;
11033 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
11036 /* A missing DW_AT_type represents a void type. */
11037 return objfile_type (cu
->objfile
)->builtin_void
;
11040 return lookup_die_type (die
, type_attr
, cu
);
11043 /* True iff CU's producer generates GNAT Ada auxiliary information
11044 that allows to find parallel types through that information instead
11045 of having to do expensive parallel lookups by type name. */
11048 need_gnat_info (struct dwarf2_cu
*cu
)
11050 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
11051 of GNAT produces this auxiliary information, without any indication
11052 that it is produced. Part of enhancing the FSF version of GNAT
11053 to produce that information will be to put in place an indicator
11054 that we can use in order to determine whether the descriptive type
11055 info is available or not. One suggestion that has been made is
11056 to use a new attribute, attached to the CU die. For now, assume
11057 that the descriptive type info is not available. */
11061 /* Return the auxiliary type of the die in question using its
11062 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
11063 attribute is not present. */
11065 static struct type
*
11066 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11068 struct attribute
*type_attr
;
11070 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
11074 return lookup_die_type (die
, type_attr
, cu
);
11077 /* If DIE has a descriptive_type attribute, then set the TYPE's
11078 descriptive type accordingly. */
11081 set_descriptive_type (struct type
*type
, struct die_info
*die
,
11082 struct dwarf2_cu
*cu
)
11084 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
11086 if (descriptive_type
)
11088 ALLOCATE_GNAT_AUX_TYPE (type
);
11089 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
11093 /* Return the containing type of the die in question using its
11094 DW_AT_containing_type attribute. */
11096 static struct type
*
11097 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11099 struct attribute
*type_attr
;
11101 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
11103 error (_("Dwarf Error: Problem turning containing type into gdb type "
11104 "[in module %s]"), cu
->objfile
->name
);
11106 return lookup_die_type (die
, type_attr
, cu
);
11109 /* Look up the type of DIE in CU using its type attribute ATTR.
11110 If there is no type substitute an error marker. */
11112 static struct type
*
11113 lookup_die_type (struct die_info
*die
, struct attribute
*attr
,
11114 struct dwarf2_cu
*cu
)
11116 struct type
*this_type
;
11118 /* First see if we have it cached. */
11120 if (is_ref_attr (attr
))
11122 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11124 this_type
= get_die_type_at_offset (offset
, cu
->per_cu
);
11126 else if (attr
->form
== DW_FORM_sig8
)
11128 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11129 struct dwarf2_cu
*sig_cu
;
11130 unsigned int offset
;
11132 /* sig_type will be NULL if the signatured type is missing from
11134 if (sig_type
== NULL
)
11135 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11136 "at 0x%x [in module %s]"),
11137 die
->offset
, cu
->objfile
->name
);
11139 gdb_assert (sig_type
->per_cu
.from_debug_types
);
11140 offset
= sig_type
->offset
+ sig_type
->type_offset
;
11141 this_type
= get_die_type_at_offset (offset
, &sig_type
->per_cu
);
11145 dump_die_for_error (die
);
11146 error (_("Dwarf Error: Bad type attribute %s [in module %s]"),
11147 dwarf_attr_name (attr
->name
), cu
->objfile
->name
);
11150 /* If not cached we need to read it in. */
11152 if (this_type
== NULL
)
11154 struct die_info
*type_die
;
11155 struct dwarf2_cu
*type_cu
= cu
;
11157 type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
11158 /* If the type is cached, we should have found it above. */
11159 gdb_assert (get_die_type (type_die
, type_cu
) == NULL
);
11160 this_type
= read_type_die_1 (type_die
, type_cu
);
11163 /* If we still don't have a type use an error marker. */
11165 if (this_type
== NULL
)
11167 char *message
, *saved
;
11169 /* read_type_die already issued a complaint. */
11170 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
11174 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
11175 message
, strlen (message
));
11178 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
11184 /* Return the type in DIE, CU.
11185 Returns NULL for invalid types.
11187 This first does a lookup in the appropriate type_hash table,
11188 and only reads the die in if necessary.
11190 NOTE: This can be called when reading in partial or full symbols. */
11192 static struct type
*
11193 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
11195 struct type
*this_type
;
11197 this_type
= get_die_type (die
, cu
);
11201 return read_type_die_1 (die
, cu
);
11204 /* Read the type in DIE, CU.
11205 Returns NULL for invalid types. */
11207 static struct type
*
11208 read_type_die_1 (struct die_info
*die
, struct dwarf2_cu
*cu
)
11210 struct type
*this_type
= NULL
;
11214 case DW_TAG_class_type
:
11215 case DW_TAG_interface_type
:
11216 case DW_TAG_structure_type
:
11217 case DW_TAG_union_type
:
11218 this_type
= read_structure_type (die
, cu
);
11220 case DW_TAG_enumeration_type
:
11221 this_type
= read_enumeration_type (die
, cu
);
11223 case DW_TAG_subprogram
:
11224 case DW_TAG_subroutine_type
:
11225 case DW_TAG_inlined_subroutine
:
11226 this_type
= read_subroutine_type (die
, cu
);
11228 case DW_TAG_array_type
:
11229 this_type
= read_array_type (die
, cu
);
11231 case DW_TAG_set_type
:
11232 this_type
= read_set_type (die
, cu
);
11234 case DW_TAG_pointer_type
:
11235 this_type
= read_tag_pointer_type (die
, cu
);
11237 case DW_TAG_ptr_to_member_type
:
11238 this_type
= read_tag_ptr_to_member_type (die
, cu
);
11240 case DW_TAG_reference_type
:
11241 this_type
= read_tag_reference_type (die
, cu
);
11243 case DW_TAG_const_type
:
11244 this_type
= read_tag_const_type (die
, cu
);
11246 case DW_TAG_volatile_type
:
11247 this_type
= read_tag_volatile_type (die
, cu
);
11249 case DW_TAG_string_type
:
11250 this_type
= read_tag_string_type (die
, cu
);
11252 case DW_TAG_typedef
:
11253 this_type
= read_typedef (die
, cu
);
11255 case DW_TAG_subrange_type
:
11256 this_type
= read_subrange_type (die
, cu
);
11258 case DW_TAG_base_type
:
11259 this_type
= read_base_type (die
, cu
);
11261 case DW_TAG_unspecified_type
:
11262 this_type
= read_unspecified_type (die
, cu
);
11264 case DW_TAG_namespace
:
11265 this_type
= read_namespace_type (die
, cu
);
11267 case DW_TAG_module
:
11268 this_type
= read_module_type (die
, cu
);
11271 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
11272 dwarf_tag_name (die
->tag
));
11279 /* Return the name of the namespace/class that DIE is defined within,
11280 or "" if we can't tell. The caller should not xfree the result.
11282 For example, if we're within the method foo() in the following
11292 then determine_prefix on foo's die will return "N::C". */
11295 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
11297 struct die_info
*parent
, *spec_die
;
11298 struct dwarf2_cu
*spec_cu
;
11299 struct type
*parent_type
;
11301 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
11302 && cu
->language
!= language_fortran
)
11305 /* We have to be careful in the presence of DW_AT_specification.
11306 For example, with GCC 3.4, given the code
11310 // Definition of N::foo.
11314 then we'll have a tree of DIEs like this:
11316 1: DW_TAG_compile_unit
11317 2: DW_TAG_namespace // N
11318 3: DW_TAG_subprogram // declaration of N::foo
11319 4: DW_TAG_subprogram // definition of N::foo
11320 DW_AT_specification // refers to die #3
11322 Thus, when processing die #4, we have to pretend that we're in
11323 the context of its DW_AT_specification, namely the contex of die
11326 spec_die
= die_specification (die
, &spec_cu
);
11327 if (spec_die
== NULL
)
11328 parent
= die
->parent
;
11331 parent
= spec_die
->parent
;
11335 if (parent
== NULL
)
11337 else if (parent
->building_fullname
)
11340 const char *parent_name
;
11342 /* It has been seen on RealView 2.2 built binaries,
11343 DW_TAG_template_type_param types actually _defined_ as
11344 children of the parent class:
11347 template class <class Enum> Class{};
11348 Class<enum E> class_e;
11350 1: DW_TAG_class_type (Class)
11351 2: DW_TAG_enumeration_type (E)
11352 3: DW_TAG_enumerator (enum1:0)
11353 3: DW_TAG_enumerator (enum2:1)
11355 2: DW_TAG_template_type_param
11356 DW_AT_type DW_FORM_ref_udata (E)
11358 Besides being broken debug info, it can put GDB into an
11359 infinite loop. Consider:
11361 When we're building the full name for Class<E>, we'll start
11362 at Class, and go look over its template type parameters,
11363 finding E. We'll then try to build the full name of E, and
11364 reach here. We're now trying to build the full name of E,
11365 and look over the parent DIE for containing scope. In the
11366 broken case, if we followed the parent DIE of E, we'd again
11367 find Class, and once again go look at its template type
11368 arguments, etc., etc. Simply don't consider such parent die
11369 as source-level parent of this die (it can't be, the language
11370 doesn't allow it), and break the loop here. */
11371 name
= dwarf2_name (die
, cu
);
11372 parent_name
= dwarf2_name (parent
, cu
);
11373 complaint (&symfile_complaints
,
11374 _("template param type '%s' defined within parent '%s'"),
11375 name
? name
: "<unknown>",
11376 parent_name
? parent_name
: "<unknown>");
11380 switch (parent
->tag
)
11382 case DW_TAG_namespace
:
11383 parent_type
= read_type_die (parent
, cu
);
11384 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
11385 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
11386 Work around this problem here. */
11387 if (cu
->language
== language_cplus
11388 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
11390 /* We give a name to even anonymous namespaces. */
11391 return TYPE_TAG_NAME (parent_type
);
11392 case DW_TAG_class_type
:
11393 case DW_TAG_interface_type
:
11394 case DW_TAG_structure_type
:
11395 case DW_TAG_union_type
:
11396 case DW_TAG_module
:
11397 parent_type
= read_type_die (parent
, cu
);
11398 if (TYPE_TAG_NAME (parent_type
) != NULL
)
11399 return TYPE_TAG_NAME (parent_type
);
11401 /* An anonymous structure is only allowed non-static data
11402 members; no typedefs, no member functions, et cetera.
11403 So it does not need a prefix. */
11406 return determine_prefix (parent
, cu
);
11410 /* Return a newly-allocated string formed by concatenating PREFIX and
11411 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
11412 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
11413 perform an obconcat, otherwise allocate storage for the result. The CU argument
11414 is used to determine the language and hence, the appropriate separator. */
11416 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
11419 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
11420 int physname
, struct dwarf2_cu
*cu
)
11422 const char *lead
= "";
11425 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
11427 else if (cu
->language
== language_java
)
11429 else if (cu
->language
== language_fortran
&& physname
)
11431 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
11432 DW_AT_MIPS_linkage_name is preferred and used instead. */
11440 if (prefix
== NULL
)
11442 if (suffix
== NULL
)
11447 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
11449 strcpy (retval
, lead
);
11450 strcat (retval
, prefix
);
11451 strcat (retval
, sep
);
11452 strcat (retval
, suffix
);
11457 /* We have an obstack. */
11458 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
11462 /* Return sibling of die, NULL if no sibling. */
11464 static struct die_info
*
11465 sibling_die (struct die_info
*die
)
11467 return die
->sibling
;
11470 /* Get name of a die, return NULL if not found. */
11473 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
11474 struct obstack
*obstack
)
11476 if (name
&& cu
->language
== language_cplus
)
11478 char *canon_name
= cp_canonicalize_string (name
);
11480 if (canon_name
!= NULL
)
11482 if (strcmp (canon_name
, name
) != 0)
11483 name
= obsavestring (canon_name
, strlen (canon_name
),
11485 xfree (canon_name
);
11492 /* Get name of a die, return NULL if not found. */
11495 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
11497 struct attribute
*attr
;
11499 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
11500 if (!attr
|| !DW_STRING (attr
))
11505 case DW_TAG_compile_unit
:
11506 /* Compilation units have a DW_AT_name that is a filename, not
11507 a source language identifier. */
11508 case DW_TAG_enumeration_type
:
11509 case DW_TAG_enumerator
:
11510 /* These tags always have simple identifiers already; no need
11511 to canonicalize them. */
11512 return DW_STRING (attr
);
11514 case DW_TAG_subprogram
:
11515 /* Java constructors will all be named "<init>", so return
11516 the class name when we see this special case. */
11517 if (cu
->language
== language_java
11518 && DW_STRING (attr
) != NULL
11519 && strcmp (DW_STRING (attr
), "<init>") == 0)
11521 struct dwarf2_cu
*spec_cu
= cu
;
11522 struct die_info
*spec_die
;
11524 /* GCJ will output '<init>' for Java constructor names.
11525 For this special case, return the name of the parent class. */
11527 /* GCJ may output suprogram DIEs with AT_specification set.
11528 If so, use the name of the specified DIE. */
11529 spec_die
= die_specification (die
, &spec_cu
);
11530 if (spec_die
!= NULL
)
11531 return dwarf2_name (spec_die
, spec_cu
);
11536 if (die
->tag
== DW_TAG_class_type
)
11537 return dwarf2_name (die
, cu
);
11539 while (die
->tag
!= DW_TAG_compile_unit
);
11543 case DW_TAG_class_type
:
11544 case DW_TAG_interface_type
:
11545 case DW_TAG_structure_type
:
11546 case DW_TAG_union_type
:
11547 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
11548 structures or unions. These were of the form "._%d" in GCC 4.1,
11549 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
11550 and GCC 4.4. We work around this problem by ignoring these. */
11551 if (strncmp (DW_STRING (attr
), "._", 2) == 0
11552 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
11560 if (!DW_STRING_IS_CANONICAL (attr
))
11563 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
11564 &cu
->objfile
->objfile_obstack
);
11565 DW_STRING_IS_CANONICAL (attr
) = 1;
11567 return DW_STRING (attr
);
11570 /* Return the die that this die in an extension of, or NULL if there
11571 is none. *EXT_CU is the CU containing DIE on input, and the CU
11572 containing the return value on output. */
11574 static struct die_info
*
11575 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
11577 struct attribute
*attr
;
11579 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
11583 return follow_die_ref (die
, attr
, ext_cu
);
11586 /* Convert a DIE tag into its string name. */
11589 dwarf_tag_name (unsigned tag
)
11593 case DW_TAG_padding
:
11594 return "DW_TAG_padding";
11595 case DW_TAG_array_type
:
11596 return "DW_TAG_array_type";
11597 case DW_TAG_class_type
:
11598 return "DW_TAG_class_type";
11599 case DW_TAG_entry_point
:
11600 return "DW_TAG_entry_point";
11601 case DW_TAG_enumeration_type
:
11602 return "DW_TAG_enumeration_type";
11603 case DW_TAG_formal_parameter
:
11604 return "DW_TAG_formal_parameter";
11605 case DW_TAG_imported_declaration
:
11606 return "DW_TAG_imported_declaration";
11608 return "DW_TAG_label";
11609 case DW_TAG_lexical_block
:
11610 return "DW_TAG_lexical_block";
11611 case DW_TAG_member
:
11612 return "DW_TAG_member";
11613 case DW_TAG_pointer_type
:
11614 return "DW_TAG_pointer_type";
11615 case DW_TAG_reference_type
:
11616 return "DW_TAG_reference_type";
11617 case DW_TAG_compile_unit
:
11618 return "DW_TAG_compile_unit";
11619 case DW_TAG_string_type
:
11620 return "DW_TAG_string_type";
11621 case DW_TAG_structure_type
:
11622 return "DW_TAG_structure_type";
11623 case DW_TAG_subroutine_type
:
11624 return "DW_TAG_subroutine_type";
11625 case DW_TAG_typedef
:
11626 return "DW_TAG_typedef";
11627 case DW_TAG_union_type
:
11628 return "DW_TAG_union_type";
11629 case DW_TAG_unspecified_parameters
:
11630 return "DW_TAG_unspecified_parameters";
11631 case DW_TAG_variant
:
11632 return "DW_TAG_variant";
11633 case DW_TAG_common_block
:
11634 return "DW_TAG_common_block";
11635 case DW_TAG_common_inclusion
:
11636 return "DW_TAG_common_inclusion";
11637 case DW_TAG_inheritance
:
11638 return "DW_TAG_inheritance";
11639 case DW_TAG_inlined_subroutine
:
11640 return "DW_TAG_inlined_subroutine";
11641 case DW_TAG_module
:
11642 return "DW_TAG_module";
11643 case DW_TAG_ptr_to_member_type
:
11644 return "DW_TAG_ptr_to_member_type";
11645 case DW_TAG_set_type
:
11646 return "DW_TAG_set_type";
11647 case DW_TAG_subrange_type
:
11648 return "DW_TAG_subrange_type";
11649 case DW_TAG_with_stmt
:
11650 return "DW_TAG_with_stmt";
11651 case DW_TAG_access_declaration
:
11652 return "DW_TAG_access_declaration";
11653 case DW_TAG_base_type
:
11654 return "DW_TAG_base_type";
11655 case DW_TAG_catch_block
:
11656 return "DW_TAG_catch_block";
11657 case DW_TAG_const_type
:
11658 return "DW_TAG_const_type";
11659 case DW_TAG_constant
:
11660 return "DW_TAG_constant";
11661 case DW_TAG_enumerator
:
11662 return "DW_TAG_enumerator";
11663 case DW_TAG_file_type
:
11664 return "DW_TAG_file_type";
11665 case DW_TAG_friend
:
11666 return "DW_TAG_friend";
11667 case DW_TAG_namelist
:
11668 return "DW_TAG_namelist";
11669 case DW_TAG_namelist_item
:
11670 return "DW_TAG_namelist_item";
11671 case DW_TAG_packed_type
:
11672 return "DW_TAG_packed_type";
11673 case DW_TAG_subprogram
:
11674 return "DW_TAG_subprogram";
11675 case DW_TAG_template_type_param
:
11676 return "DW_TAG_template_type_param";
11677 case DW_TAG_template_value_param
:
11678 return "DW_TAG_template_value_param";
11679 case DW_TAG_thrown_type
:
11680 return "DW_TAG_thrown_type";
11681 case DW_TAG_try_block
:
11682 return "DW_TAG_try_block";
11683 case DW_TAG_variant_part
:
11684 return "DW_TAG_variant_part";
11685 case DW_TAG_variable
:
11686 return "DW_TAG_variable";
11687 case DW_TAG_volatile_type
:
11688 return "DW_TAG_volatile_type";
11689 case DW_TAG_dwarf_procedure
:
11690 return "DW_TAG_dwarf_procedure";
11691 case DW_TAG_restrict_type
:
11692 return "DW_TAG_restrict_type";
11693 case DW_TAG_interface_type
:
11694 return "DW_TAG_interface_type";
11695 case DW_TAG_namespace
:
11696 return "DW_TAG_namespace";
11697 case DW_TAG_imported_module
:
11698 return "DW_TAG_imported_module";
11699 case DW_TAG_unspecified_type
:
11700 return "DW_TAG_unspecified_type";
11701 case DW_TAG_partial_unit
:
11702 return "DW_TAG_partial_unit";
11703 case DW_TAG_imported_unit
:
11704 return "DW_TAG_imported_unit";
11705 case DW_TAG_condition
:
11706 return "DW_TAG_condition";
11707 case DW_TAG_shared_type
:
11708 return "DW_TAG_shared_type";
11709 case DW_TAG_type_unit
:
11710 return "DW_TAG_type_unit";
11711 case DW_TAG_MIPS_loop
:
11712 return "DW_TAG_MIPS_loop";
11713 case DW_TAG_HP_array_descriptor
:
11714 return "DW_TAG_HP_array_descriptor";
11715 case DW_TAG_format_label
:
11716 return "DW_TAG_format_label";
11717 case DW_TAG_function_template
:
11718 return "DW_TAG_function_template";
11719 case DW_TAG_class_template
:
11720 return "DW_TAG_class_template";
11721 case DW_TAG_GNU_BINCL
:
11722 return "DW_TAG_GNU_BINCL";
11723 case DW_TAG_GNU_EINCL
:
11724 return "DW_TAG_GNU_EINCL";
11725 case DW_TAG_upc_shared_type
:
11726 return "DW_TAG_upc_shared_type";
11727 case DW_TAG_upc_strict_type
:
11728 return "DW_TAG_upc_strict_type";
11729 case DW_TAG_upc_relaxed_type
:
11730 return "DW_TAG_upc_relaxed_type";
11731 case DW_TAG_PGI_kanji_type
:
11732 return "DW_TAG_PGI_kanji_type";
11733 case DW_TAG_PGI_interface_block
:
11734 return "DW_TAG_PGI_interface_block";
11736 return "DW_TAG_<unknown>";
11740 /* Convert a DWARF attribute code into its string name. */
11743 dwarf_attr_name (unsigned attr
)
11747 case DW_AT_sibling
:
11748 return "DW_AT_sibling";
11749 case DW_AT_location
:
11750 return "DW_AT_location";
11752 return "DW_AT_name";
11753 case DW_AT_ordering
:
11754 return "DW_AT_ordering";
11755 case DW_AT_subscr_data
:
11756 return "DW_AT_subscr_data";
11757 case DW_AT_byte_size
:
11758 return "DW_AT_byte_size";
11759 case DW_AT_bit_offset
:
11760 return "DW_AT_bit_offset";
11761 case DW_AT_bit_size
:
11762 return "DW_AT_bit_size";
11763 case DW_AT_element_list
:
11764 return "DW_AT_element_list";
11765 case DW_AT_stmt_list
:
11766 return "DW_AT_stmt_list";
11768 return "DW_AT_low_pc";
11769 case DW_AT_high_pc
:
11770 return "DW_AT_high_pc";
11771 case DW_AT_language
:
11772 return "DW_AT_language";
11774 return "DW_AT_member";
11776 return "DW_AT_discr";
11777 case DW_AT_discr_value
:
11778 return "DW_AT_discr_value";
11779 case DW_AT_visibility
:
11780 return "DW_AT_visibility";
11782 return "DW_AT_import";
11783 case DW_AT_string_length
:
11784 return "DW_AT_string_length";
11785 case DW_AT_common_reference
:
11786 return "DW_AT_common_reference";
11787 case DW_AT_comp_dir
:
11788 return "DW_AT_comp_dir";
11789 case DW_AT_const_value
:
11790 return "DW_AT_const_value";
11791 case DW_AT_containing_type
:
11792 return "DW_AT_containing_type";
11793 case DW_AT_default_value
:
11794 return "DW_AT_default_value";
11796 return "DW_AT_inline";
11797 case DW_AT_is_optional
:
11798 return "DW_AT_is_optional";
11799 case DW_AT_lower_bound
:
11800 return "DW_AT_lower_bound";
11801 case DW_AT_producer
:
11802 return "DW_AT_producer";
11803 case DW_AT_prototyped
:
11804 return "DW_AT_prototyped";
11805 case DW_AT_return_addr
:
11806 return "DW_AT_return_addr";
11807 case DW_AT_start_scope
:
11808 return "DW_AT_start_scope";
11809 case DW_AT_bit_stride
:
11810 return "DW_AT_bit_stride";
11811 case DW_AT_upper_bound
:
11812 return "DW_AT_upper_bound";
11813 case DW_AT_abstract_origin
:
11814 return "DW_AT_abstract_origin";
11815 case DW_AT_accessibility
:
11816 return "DW_AT_accessibility";
11817 case DW_AT_address_class
:
11818 return "DW_AT_address_class";
11819 case DW_AT_artificial
:
11820 return "DW_AT_artificial";
11821 case DW_AT_base_types
:
11822 return "DW_AT_base_types";
11823 case DW_AT_calling_convention
:
11824 return "DW_AT_calling_convention";
11826 return "DW_AT_count";
11827 case DW_AT_data_member_location
:
11828 return "DW_AT_data_member_location";
11829 case DW_AT_decl_column
:
11830 return "DW_AT_decl_column";
11831 case DW_AT_decl_file
:
11832 return "DW_AT_decl_file";
11833 case DW_AT_decl_line
:
11834 return "DW_AT_decl_line";
11835 case DW_AT_declaration
:
11836 return "DW_AT_declaration";
11837 case DW_AT_discr_list
:
11838 return "DW_AT_discr_list";
11839 case DW_AT_encoding
:
11840 return "DW_AT_encoding";
11841 case DW_AT_external
:
11842 return "DW_AT_external";
11843 case DW_AT_frame_base
:
11844 return "DW_AT_frame_base";
11846 return "DW_AT_friend";
11847 case DW_AT_identifier_case
:
11848 return "DW_AT_identifier_case";
11849 case DW_AT_macro_info
:
11850 return "DW_AT_macro_info";
11851 case DW_AT_namelist_items
:
11852 return "DW_AT_namelist_items";
11853 case DW_AT_priority
:
11854 return "DW_AT_priority";
11855 case DW_AT_segment
:
11856 return "DW_AT_segment";
11857 case DW_AT_specification
:
11858 return "DW_AT_specification";
11859 case DW_AT_static_link
:
11860 return "DW_AT_static_link";
11862 return "DW_AT_type";
11863 case DW_AT_use_location
:
11864 return "DW_AT_use_location";
11865 case DW_AT_variable_parameter
:
11866 return "DW_AT_variable_parameter";
11867 case DW_AT_virtuality
:
11868 return "DW_AT_virtuality";
11869 case DW_AT_vtable_elem_location
:
11870 return "DW_AT_vtable_elem_location";
11871 /* DWARF 3 values. */
11872 case DW_AT_allocated
:
11873 return "DW_AT_allocated";
11874 case DW_AT_associated
:
11875 return "DW_AT_associated";
11876 case DW_AT_data_location
:
11877 return "DW_AT_data_location";
11878 case DW_AT_byte_stride
:
11879 return "DW_AT_byte_stride";
11880 case DW_AT_entry_pc
:
11881 return "DW_AT_entry_pc";
11882 case DW_AT_use_UTF8
:
11883 return "DW_AT_use_UTF8";
11884 case DW_AT_extension
:
11885 return "DW_AT_extension";
11887 return "DW_AT_ranges";
11888 case DW_AT_trampoline
:
11889 return "DW_AT_trampoline";
11890 case DW_AT_call_column
:
11891 return "DW_AT_call_column";
11892 case DW_AT_call_file
:
11893 return "DW_AT_call_file";
11894 case DW_AT_call_line
:
11895 return "DW_AT_call_line";
11896 case DW_AT_description
:
11897 return "DW_AT_description";
11898 case DW_AT_binary_scale
:
11899 return "DW_AT_binary_scale";
11900 case DW_AT_decimal_scale
:
11901 return "DW_AT_decimal_scale";
11903 return "DW_AT_small";
11904 case DW_AT_decimal_sign
:
11905 return "DW_AT_decimal_sign";
11906 case DW_AT_digit_count
:
11907 return "DW_AT_digit_count";
11908 case DW_AT_picture_string
:
11909 return "DW_AT_picture_string";
11910 case DW_AT_mutable
:
11911 return "DW_AT_mutable";
11912 case DW_AT_threads_scaled
:
11913 return "DW_AT_threads_scaled";
11914 case DW_AT_explicit
:
11915 return "DW_AT_explicit";
11916 case DW_AT_object_pointer
:
11917 return "DW_AT_object_pointer";
11918 case DW_AT_endianity
:
11919 return "DW_AT_endianity";
11920 case DW_AT_elemental
:
11921 return "DW_AT_elemental";
11923 return "DW_AT_pure";
11924 case DW_AT_recursive
:
11925 return "DW_AT_recursive";
11926 /* DWARF 4 values. */
11927 case DW_AT_signature
:
11928 return "DW_AT_signature";
11929 case DW_AT_linkage_name
:
11930 return "DW_AT_linkage_name";
11931 /* SGI/MIPS extensions. */
11932 #ifdef MIPS /* collides with DW_AT_HP_block_index */
11933 case DW_AT_MIPS_fde
:
11934 return "DW_AT_MIPS_fde";
11936 case DW_AT_MIPS_loop_begin
:
11937 return "DW_AT_MIPS_loop_begin";
11938 case DW_AT_MIPS_tail_loop_begin
:
11939 return "DW_AT_MIPS_tail_loop_begin";
11940 case DW_AT_MIPS_epilog_begin
:
11941 return "DW_AT_MIPS_epilog_begin";
11942 case DW_AT_MIPS_loop_unroll_factor
:
11943 return "DW_AT_MIPS_loop_unroll_factor";
11944 case DW_AT_MIPS_software_pipeline_depth
:
11945 return "DW_AT_MIPS_software_pipeline_depth";
11946 case DW_AT_MIPS_linkage_name
:
11947 return "DW_AT_MIPS_linkage_name";
11948 case DW_AT_MIPS_stride
:
11949 return "DW_AT_MIPS_stride";
11950 case DW_AT_MIPS_abstract_name
:
11951 return "DW_AT_MIPS_abstract_name";
11952 case DW_AT_MIPS_clone_origin
:
11953 return "DW_AT_MIPS_clone_origin";
11954 case DW_AT_MIPS_has_inlines
:
11955 return "DW_AT_MIPS_has_inlines";
11956 /* HP extensions. */
11957 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11958 case DW_AT_HP_block_index
:
11959 return "DW_AT_HP_block_index";
11961 case DW_AT_HP_unmodifiable
:
11962 return "DW_AT_HP_unmodifiable";
11963 case DW_AT_HP_actuals_stmt_list
:
11964 return "DW_AT_HP_actuals_stmt_list";
11965 case DW_AT_HP_proc_per_section
:
11966 return "DW_AT_HP_proc_per_section";
11967 case DW_AT_HP_raw_data_ptr
:
11968 return "DW_AT_HP_raw_data_ptr";
11969 case DW_AT_HP_pass_by_reference
:
11970 return "DW_AT_HP_pass_by_reference";
11971 case DW_AT_HP_opt_level
:
11972 return "DW_AT_HP_opt_level";
11973 case DW_AT_HP_prof_version_id
:
11974 return "DW_AT_HP_prof_version_id";
11975 case DW_AT_HP_opt_flags
:
11976 return "DW_AT_HP_opt_flags";
11977 case DW_AT_HP_cold_region_low_pc
:
11978 return "DW_AT_HP_cold_region_low_pc";
11979 case DW_AT_HP_cold_region_high_pc
:
11980 return "DW_AT_HP_cold_region_high_pc";
11981 case DW_AT_HP_all_variables_modifiable
:
11982 return "DW_AT_HP_all_variables_modifiable";
11983 case DW_AT_HP_linkage_name
:
11984 return "DW_AT_HP_linkage_name";
11985 case DW_AT_HP_prof_flags
:
11986 return "DW_AT_HP_prof_flags";
11987 /* GNU extensions. */
11988 case DW_AT_sf_names
:
11989 return "DW_AT_sf_names";
11990 case DW_AT_src_info
:
11991 return "DW_AT_src_info";
11992 case DW_AT_mac_info
:
11993 return "DW_AT_mac_info";
11994 case DW_AT_src_coords
:
11995 return "DW_AT_src_coords";
11996 case DW_AT_body_begin
:
11997 return "DW_AT_body_begin";
11998 case DW_AT_body_end
:
11999 return "DW_AT_body_end";
12000 case DW_AT_GNU_vector
:
12001 return "DW_AT_GNU_vector";
12002 case DW_AT_GNU_odr_signature
:
12003 return "DW_AT_GNU_odr_signature";
12004 /* VMS extensions. */
12005 case DW_AT_VMS_rtnbeg_pd_address
:
12006 return "DW_AT_VMS_rtnbeg_pd_address";
12007 /* UPC extension. */
12008 case DW_AT_upc_threads_scaled
:
12009 return "DW_AT_upc_threads_scaled";
12010 /* PGI (STMicroelectronics) extensions. */
12011 case DW_AT_PGI_lbase
:
12012 return "DW_AT_PGI_lbase";
12013 case DW_AT_PGI_soffset
:
12014 return "DW_AT_PGI_soffset";
12015 case DW_AT_PGI_lstride
:
12016 return "DW_AT_PGI_lstride";
12018 return "DW_AT_<unknown>";
12022 /* Convert a DWARF value form code into its string name. */
12025 dwarf_form_name (unsigned form
)
12030 return "DW_FORM_addr";
12031 case DW_FORM_block2
:
12032 return "DW_FORM_block2";
12033 case DW_FORM_block4
:
12034 return "DW_FORM_block4";
12035 case DW_FORM_data2
:
12036 return "DW_FORM_data2";
12037 case DW_FORM_data4
:
12038 return "DW_FORM_data4";
12039 case DW_FORM_data8
:
12040 return "DW_FORM_data8";
12041 case DW_FORM_string
:
12042 return "DW_FORM_string";
12043 case DW_FORM_block
:
12044 return "DW_FORM_block";
12045 case DW_FORM_block1
:
12046 return "DW_FORM_block1";
12047 case DW_FORM_data1
:
12048 return "DW_FORM_data1";
12050 return "DW_FORM_flag";
12051 case DW_FORM_sdata
:
12052 return "DW_FORM_sdata";
12054 return "DW_FORM_strp";
12055 case DW_FORM_udata
:
12056 return "DW_FORM_udata";
12057 case DW_FORM_ref_addr
:
12058 return "DW_FORM_ref_addr";
12060 return "DW_FORM_ref1";
12062 return "DW_FORM_ref2";
12064 return "DW_FORM_ref4";
12066 return "DW_FORM_ref8";
12067 case DW_FORM_ref_udata
:
12068 return "DW_FORM_ref_udata";
12069 case DW_FORM_indirect
:
12070 return "DW_FORM_indirect";
12071 case DW_FORM_sec_offset
:
12072 return "DW_FORM_sec_offset";
12073 case DW_FORM_exprloc
:
12074 return "DW_FORM_exprloc";
12075 case DW_FORM_flag_present
:
12076 return "DW_FORM_flag_present";
12078 return "DW_FORM_sig8";
12080 return "DW_FORM_<unknown>";
12084 /* Convert a DWARF stack opcode into its string name. */
12087 dwarf_stack_op_name (unsigned op
, int def
)
12092 return "DW_OP_addr";
12094 return "DW_OP_deref";
12095 case DW_OP_const1u
:
12096 return "DW_OP_const1u";
12097 case DW_OP_const1s
:
12098 return "DW_OP_const1s";
12099 case DW_OP_const2u
:
12100 return "DW_OP_const2u";
12101 case DW_OP_const2s
:
12102 return "DW_OP_const2s";
12103 case DW_OP_const4u
:
12104 return "DW_OP_const4u";
12105 case DW_OP_const4s
:
12106 return "DW_OP_const4s";
12107 case DW_OP_const8u
:
12108 return "DW_OP_const8u";
12109 case DW_OP_const8s
:
12110 return "DW_OP_const8s";
12112 return "DW_OP_constu";
12114 return "DW_OP_consts";
12116 return "DW_OP_dup";
12118 return "DW_OP_drop";
12120 return "DW_OP_over";
12122 return "DW_OP_pick";
12124 return "DW_OP_swap";
12126 return "DW_OP_rot";
12128 return "DW_OP_xderef";
12130 return "DW_OP_abs";
12132 return "DW_OP_and";
12134 return "DW_OP_div";
12136 return "DW_OP_minus";
12138 return "DW_OP_mod";
12140 return "DW_OP_mul";
12142 return "DW_OP_neg";
12144 return "DW_OP_not";
12148 return "DW_OP_plus";
12149 case DW_OP_plus_uconst
:
12150 return "DW_OP_plus_uconst";
12152 return "DW_OP_shl";
12154 return "DW_OP_shr";
12156 return "DW_OP_shra";
12158 return "DW_OP_xor";
12160 return "DW_OP_bra";
12174 return "DW_OP_skip";
12176 return "DW_OP_lit0";
12178 return "DW_OP_lit1";
12180 return "DW_OP_lit2";
12182 return "DW_OP_lit3";
12184 return "DW_OP_lit4";
12186 return "DW_OP_lit5";
12188 return "DW_OP_lit6";
12190 return "DW_OP_lit7";
12192 return "DW_OP_lit8";
12194 return "DW_OP_lit9";
12196 return "DW_OP_lit10";
12198 return "DW_OP_lit11";
12200 return "DW_OP_lit12";
12202 return "DW_OP_lit13";
12204 return "DW_OP_lit14";
12206 return "DW_OP_lit15";
12208 return "DW_OP_lit16";
12210 return "DW_OP_lit17";
12212 return "DW_OP_lit18";
12214 return "DW_OP_lit19";
12216 return "DW_OP_lit20";
12218 return "DW_OP_lit21";
12220 return "DW_OP_lit22";
12222 return "DW_OP_lit23";
12224 return "DW_OP_lit24";
12226 return "DW_OP_lit25";
12228 return "DW_OP_lit26";
12230 return "DW_OP_lit27";
12232 return "DW_OP_lit28";
12234 return "DW_OP_lit29";
12236 return "DW_OP_lit30";
12238 return "DW_OP_lit31";
12240 return "DW_OP_reg0";
12242 return "DW_OP_reg1";
12244 return "DW_OP_reg2";
12246 return "DW_OP_reg3";
12248 return "DW_OP_reg4";
12250 return "DW_OP_reg5";
12252 return "DW_OP_reg6";
12254 return "DW_OP_reg7";
12256 return "DW_OP_reg8";
12258 return "DW_OP_reg9";
12260 return "DW_OP_reg10";
12262 return "DW_OP_reg11";
12264 return "DW_OP_reg12";
12266 return "DW_OP_reg13";
12268 return "DW_OP_reg14";
12270 return "DW_OP_reg15";
12272 return "DW_OP_reg16";
12274 return "DW_OP_reg17";
12276 return "DW_OP_reg18";
12278 return "DW_OP_reg19";
12280 return "DW_OP_reg20";
12282 return "DW_OP_reg21";
12284 return "DW_OP_reg22";
12286 return "DW_OP_reg23";
12288 return "DW_OP_reg24";
12290 return "DW_OP_reg25";
12292 return "DW_OP_reg26";
12294 return "DW_OP_reg27";
12296 return "DW_OP_reg28";
12298 return "DW_OP_reg29";
12300 return "DW_OP_reg30";
12302 return "DW_OP_reg31";
12304 return "DW_OP_breg0";
12306 return "DW_OP_breg1";
12308 return "DW_OP_breg2";
12310 return "DW_OP_breg3";
12312 return "DW_OP_breg4";
12314 return "DW_OP_breg5";
12316 return "DW_OP_breg6";
12318 return "DW_OP_breg7";
12320 return "DW_OP_breg8";
12322 return "DW_OP_breg9";
12324 return "DW_OP_breg10";
12326 return "DW_OP_breg11";
12328 return "DW_OP_breg12";
12330 return "DW_OP_breg13";
12332 return "DW_OP_breg14";
12334 return "DW_OP_breg15";
12336 return "DW_OP_breg16";
12338 return "DW_OP_breg17";
12340 return "DW_OP_breg18";
12342 return "DW_OP_breg19";
12344 return "DW_OP_breg20";
12346 return "DW_OP_breg21";
12348 return "DW_OP_breg22";
12350 return "DW_OP_breg23";
12352 return "DW_OP_breg24";
12354 return "DW_OP_breg25";
12356 return "DW_OP_breg26";
12358 return "DW_OP_breg27";
12360 return "DW_OP_breg28";
12362 return "DW_OP_breg29";
12364 return "DW_OP_breg30";
12366 return "DW_OP_breg31";
12368 return "DW_OP_regx";
12370 return "DW_OP_fbreg";
12372 return "DW_OP_bregx";
12374 return "DW_OP_piece";
12375 case DW_OP_deref_size
:
12376 return "DW_OP_deref_size";
12377 case DW_OP_xderef_size
:
12378 return "DW_OP_xderef_size";
12380 return "DW_OP_nop";
12381 /* DWARF 3 extensions. */
12382 case DW_OP_push_object_address
:
12383 return "DW_OP_push_object_address";
12385 return "DW_OP_call2";
12387 return "DW_OP_call4";
12388 case DW_OP_call_ref
:
12389 return "DW_OP_call_ref";
12390 case DW_OP_form_tls_address
:
12391 return "DW_OP_form_tls_address";
12392 case DW_OP_call_frame_cfa
:
12393 return "DW_OP_call_frame_cfa";
12394 case DW_OP_bit_piece
:
12395 return "DW_OP_bit_piece";
12396 /* DWARF 4 extensions. */
12397 case DW_OP_implicit_value
:
12398 return "DW_OP_implicit_value";
12399 case DW_OP_stack_value
:
12400 return "DW_OP_stack_value";
12401 /* GNU extensions. */
12402 case DW_OP_GNU_push_tls_address
:
12403 return "DW_OP_GNU_push_tls_address";
12404 case DW_OP_GNU_uninit
:
12405 return "DW_OP_GNU_uninit";
12407 return def
? "OP_<unknown>" : NULL
;
12412 dwarf_bool_name (unsigned mybool
)
12420 /* Convert a DWARF type code into its string name. */
12423 dwarf_type_encoding_name (unsigned enc
)
12428 return "DW_ATE_void";
12429 case DW_ATE_address
:
12430 return "DW_ATE_address";
12431 case DW_ATE_boolean
:
12432 return "DW_ATE_boolean";
12433 case DW_ATE_complex_float
:
12434 return "DW_ATE_complex_float";
12436 return "DW_ATE_float";
12437 case DW_ATE_signed
:
12438 return "DW_ATE_signed";
12439 case DW_ATE_signed_char
:
12440 return "DW_ATE_signed_char";
12441 case DW_ATE_unsigned
:
12442 return "DW_ATE_unsigned";
12443 case DW_ATE_unsigned_char
:
12444 return "DW_ATE_unsigned_char";
12446 case DW_ATE_imaginary_float
:
12447 return "DW_ATE_imaginary_float";
12448 case DW_ATE_packed_decimal
:
12449 return "DW_ATE_packed_decimal";
12450 case DW_ATE_numeric_string
:
12451 return "DW_ATE_numeric_string";
12452 case DW_ATE_edited
:
12453 return "DW_ATE_edited";
12454 case DW_ATE_signed_fixed
:
12455 return "DW_ATE_signed_fixed";
12456 case DW_ATE_unsigned_fixed
:
12457 return "DW_ATE_unsigned_fixed";
12458 case DW_ATE_decimal_float
:
12459 return "DW_ATE_decimal_float";
12462 return "DW_ATE_UTF";
12463 /* HP extensions. */
12464 case DW_ATE_HP_float80
:
12465 return "DW_ATE_HP_float80";
12466 case DW_ATE_HP_complex_float80
:
12467 return "DW_ATE_HP_complex_float80";
12468 case DW_ATE_HP_float128
:
12469 return "DW_ATE_HP_float128";
12470 case DW_ATE_HP_complex_float128
:
12471 return "DW_ATE_HP_complex_float128";
12472 case DW_ATE_HP_floathpintel
:
12473 return "DW_ATE_HP_floathpintel";
12474 case DW_ATE_HP_imaginary_float80
:
12475 return "DW_ATE_HP_imaginary_float80";
12476 case DW_ATE_HP_imaginary_float128
:
12477 return "DW_ATE_HP_imaginary_float128";
12479 return "DW_ATE_<unknown>";
12483 /* Convert a DWARF call frame info operation to its string name. */
12487 dwarf_cfi_name (unsigned cfi_opc
)
12491 case DW_CFA_advance_loc
:
12492 return "DW_CFA_advance_loc";
12493 case DW_CFA_offset
:
12494 return "DW_CFA_offset";
12495 case DW_CFA_restore
:
12496 return "DW_CFA_restore";
12498 return "DW_CFA_nop";
12499 case DW_CFA_set_loc
:
12500 return "DW_CFA_set_loc";
12501 case DW_CFA_advance_loc1
:
12502 return "DW_CFA_advance_loc1";
12503 case DW_CFA_advance_loc2
:
12504 return "DW_CFA_advance_loc2";
12505 case DW_CFA_advance_loc4
:
12506 return "DW_CFA_advance_loc4";
12507 case DW_CFA_offset_extended
:
12508 return "DW_CFA_offset_extended";
12509 case DW_CFA_restore_extended
:
12510 return "DW_CFA_restore_extended";
12511 case DW_CFA_undefined
:
12512 return "DW_CFA_undefined";
12513 case DW_CFA_same_value
:
12514 return "DW_CFA_same_value";
12515 case DW_CFA_register
:
12516 return "DW_CFA_register";
12517 case DW_CFA_remember_state
:
12518 return "DW_CFA_remember_state";
12519 case DW_CFA_restore_state
:
12520 return "DW_CFA_restore_state";
12521 case DW_CFA_def_cfa
:
12522 return "DW_CFA_def_cfa";
12523 case DW_CFA_def_cfa_register
:
12524 return "DW_CFA_def_cfa_register";
12525 case DW_CFA_def_cfa_offset
:
12526 return "DW_CFA_def_cfa_offset";
12528 case DW_CFA_def_cfa_expression
:
12529 return "DW_CFA_def_cfa_expression";
12530 case DW_CFA_expression
:
12531 return "DW_CFA_expression";
12532 case DW_CFA_offset_extended_sf
:
12533 return "DW_CFA_offset_extended_sf";
12534 case DW_CFA_def_cfa_sf
:
12535 return "DW_CFA_def_cfa_sf";
12536 case DW_CFA_def_cfa_offset_sf
:
12537 return "DW_CFA_def_cfa_offset_sf";
12538 case DW_CFA_val_offset
:
12539 return "DW_CFA_val_offset";
12540 case DW_CFA_val_offset_sf
:
12541 return "DW_CFA_val_offset_sf";
12542 case DW_CFA_val_expression
:
12543 return "DW_CFA_val_expression";
12544 /* SGI/MIPS specific. */
12545 case DW_CFA_MIPS_advance_loc8
:
12546 return "DW_CFA_MIPS_advance_loc8";
12547 /* GNU extensions. */
12548 case DW_CFA_GNU_window_save
:
12549 return "DW_CFA_GNU_window_save";
12550 case DW_CFA_GNU_args_size
:
12551 return "DW_CFA_GNU_args_size";
12552 case DW_CFA_GNU_negative_offset_extended
:
12553 return "DW_CFA_GNU_negative_offset_extended";
12555 return "DW_CFA_<unknown>";
12561 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
12565 print_spaces (indent
, f
);
12566 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
12567 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
12569 if (die
->parent
!= NULL
)
12571 print_spaces (indent
, f
);
12572 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
12573 die
->parent
->offset
);
12576 print_spaces (indent
, f
);
12577 fprintf_unfiltered (f
, " has children: %s\n",
12578 dwarf_bool_name (die
->child
!= NULL
));
12580 print_spaces (indent
, f
);
12581 fprintf_unfiltered (f
, " attributes:\n");
12583 for (i
= 0; i
< die
->num_attrs
; ++i
)
12585 print_spaces (indent
, f
);
12586 fprintf_unfiltered (f
, " %s (%s) ",
12587 dwarf_attr_name (die
->attrs
[i
].name
),
12588 dwarf_form_name (die
->attrs
[i
].form
));
12590 switch (die
->attrs
[i
].form
)
12592 case DW_FORM_ref_addr
:
12594 fprintf_unfiltered (f
, "address: ");
12595 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
12597 case DW_FORM_block2
:
12598 case DW_FORM_block4
:
12599 case DW_FORM_block
:
12600 case DW_FORM_block1
:
12601 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
12603 case DW_FORM_exprloc
:
12604 fprintf_unfiltered (f
, "expression: size %u",
12605 DW_BLOCK (&die
->attrs
[i
])->size
);
12610 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
12611 (long) (DW_ADDR (&die
->attrs
[i
])));
12613 case DW_FORM_data1
:
12614 case DW_FORM_data2
:
12615 case DW_FORM_data4
:
12616 case DW_FORM_data8
:
12617 case DW_FORM_udata
:
12618 case DW_FORM_sdata
:
12619 fprintf_unfiltered (f
, "constant: %s",
12620 pulongest (DW_UNSND (&die
->attrs
[i
])));
12622 case DW_FORM_sec_offset
:
12623 fprintf_unfiltered (f
, "section offset: %s",
12624 pulongest (DW_UNSND (&die
->attrs
[i
])));
12627 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
12628 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
12629 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
12631 fprintf_unfiltered (f
, "signatured type, offset: unknown");
12633 case DW_FORM_string
:
12635 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
12636 DW_STRING (&die
->attrs
[i
])
12637 ? DW_STRING (&die
->attrs
[i
]) : "",
12638 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
12641 if (DW_UNSND (&die
->attrs
[i
]))
12642 fprintf_unfiltered (f
, "flag: TRUE");
12644 fprintf_unfiltered (f
, "flag: FALSE");
12646 case DW_FORM_flag_present
:
12647 fprintf_unfiltered (f
, "flag: TRUE");
12649 case DW_FORM_indirect
:
12650 /* the reader will have reduced the indirect form to
12651 the "base form" so this form should not occur */
12652 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
12655 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
12656 die
->attrs
[i
].form
);
12659 fprintf_unfiltered (f
, "\n");
12664 dump_die_for_error (struct die_info
*die
)
12666 dump_die_shallow (gdb_stderr
, 0, die
);
12670 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
12672 int indent
= level
* 4;
12674 gdb_assert (die
!= NULL
);
12676 if (level
>= max_level
)
12679 dump_die_shallow (f
, indent
, die
);
12681 if (die
->child
!= NULL
)
12683 print_spaces (indent
, f
);
12684 fprintf_unfiltered (f
, " Children:");
12685 if (level
+ 1 < max_level
)
12687 fprintf_unfiltered (f
, "\n");
12688 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
12692 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
12696 if (die
->sibling
!= NULL
&& level
> 0)
12698 dump_die_1 (f
, level
, max_level
, die
->sibling
);
12702 /* This is called from the pdie macro in gdbinit.in.
12703 It's not static so gcc will keep a copy callable from gdb. */
12706 dump_die (struct die_info
*die
, int max_level
)
12708 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
12712 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
12716 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
12722 is_ref_attr (struct attribute
*attr
)
12724 switch (attr
->form
)
12726 case DW_FORM_ref_addr
:
12731 case DW_FORM_ref_udata
:
12738 static unsigned int
12739 dwarf2_get_ref_die_offset (struct attribute
*attr
)
12741 if (is_ref_attr (attr
))
12742 return DW_ADDR (attr
);
12744 complaint (&symfile_complaints
,
12745 _("unsupported die ref attribute form: '%s'"),
12746 dwarf_form_name (attr
->form
));
12750 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
12751 * the value held by the attribute is not constant. */
12754 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
12756 if (attr
->form
== DW_FORM_sdata
)
12757 return DW_SND (attr
);
12758 else if (attr
->form
== DW_FORM_udata
12759 || attr
->form
== DW_FORM_data1
12760 || attr
->form
== DW_FORM_data2
12761 || attr
->form
== DW_FORM_data4
12762 || attr
->form
== DW_FORM_data8
)
12763 return DW_UNSND (attr
);
12766 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
12767 dwarf_form_name (attr
->form
));
12768 return default_value
;
12772 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
12773 unit and add it to our queue.
12774 The result is non-zero if PER_CU was queued, otherwise the result is zero
12775 meaning either PER_CU is already queued or it is already loaded. */
12778 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
12779 struct dwarf2_per_cu_data
*per_cu
)
12781 /* We may arrive here during partial symbol reading, if we need full
12782 DIEs to process an unusual case (e.g. template arguments). Do
12783 not queue PER_CU, just tell our caller to load its DIEs. */
12784 if (dwarf2_per_objfile
->reading_partial_symbols
)
12786 if (per_cu
->cu
== NULL
|| per_cu
->cu
->dies
== NULL
)
12791 /* Mark the dependence relation so that we don't flush PER_CU
12793 dwarf2_add_dependence (this_cu
, per_cu
);
12795 /* If it's already on the queue, we have nothing to do. */
12796 if (per_cu
->queued
)
12799 /* If the compilation unit is already loaded, just mark it as
12801 if (per_cu
->cu
!= NULL
)
12803 per_cu
->cu
->last_used
= 0;
12807 /* Add it to the queue. */
12808 queue_comp_unit (per_cu
, this_cu
->objfile
);
12813 /* Follow reference or signature attribute ATTR of SRC_DIE.
12814 On entry *REF_CU is the CU of SRC_DIE.
12815 On exit *REF_CU is the CU of the result. */
12817 static struct die_info
*
12818 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
12819 struct dwarf2_cu
**ref_cu
)
12821 struct die_info
*die
;
12823 if (is_ref_attr (attr
))
12824 die
= follow_die_ref (src_die
, attr
, ref_cu
);
12825 else if (attr
->form
== DW_FORM_sig8
)
12826 die
= follow_die_sig (src_die
, attr
, ref_cu
);
12829 dump_die_for_error (src_die
);
12830 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
12831 (*ref_cu
)->objfile
->name
);
12837 /* Follow reference OFFSET.
12838 On entry *REF_CU is the CU of the source die referencing OFFSET.
12839 On exit *REF_CU is the CU of the result.
12840 Returns NULL if OFFSET is invalid. */
12842 static struct die_info
*
12843 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
12845 struct die_info temp_die
;
12846 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
12848 gdb_assert (cu
->per_cu
!= NULL
);
12852 if (cu
->per_cu
->from_debug_types
)
12854 /* .debug_types CUs cannot reference anything outside their CU.
12855 If they need to, they have to reference a signatured type via
12857 if (! offset_in_cu_p (&cu
->header
, offset
))
12860 else if (! offset_in_cu_p (&cu
->header
, offset
))
12862 struct dwarf2_per_cu_data
*per_cu
;
12864 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
12866 /* If necessary, add it to the queue and load its DIEs. */
12867 if (maybe_queue_comp_unit (cu
, per_cu
))
12868 load_full_comp_unit (per_cu
, cu
->objfile
);
12870 target_cu
= per_cu
->cu
;
12872 else if (cu
->dies
== NULL
)
12874 /* We're loading full DIEs during partial symbol reading. */
12875 gdb_assert (dwarf2_per_objfile
->reading_partial_symbols
);
12876 load_full_comp_unit (cu
->per_cu
, cu
->objfile
);
12879 *ref_cu
= target_cu
;
12880 temp_die
.offset
= offset
;
12881 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
12884 /* Follow reference attribute ATTR of SRC_DIE.
12885 On entry *REF_CU is the CU of SRC_DIE.
12886 On exit *REF_CU is the CU of the result. */
12888 static struct die_info
*
12889 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
12890 struct dwarf2_cu
**ref_cu
)
12892 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
12893 struct dwarf2_cu
*cu
= *ref_cu
;
12894 struct die_info
*die
;
12896 die
= follow_die_offset (offset
, ref_cu
);
12898 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
12899 "at 0x%x [in module %s]"),
12900 offset
, src_die
->offset
, cu
->objfile
->name
);
12905 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
12906 value is intended for DW_OP_call*. */
12908 struct dwarf2_locexpr_baton
12909 dwarf2_fetch_die_location_block (unsigned int offset
,
12910 struct dwarf2_per_cu_data
*per_cu
)
12912 struct dwarf2_cu
*cu
= per_cu
->cu
;
12913 struct die_info
*die
;
12914 struct attribute
*attr
;
12915 struct dwarf2_locexpr_baton retval
;
12917 die
= follow_die_offset (offset
, &cu
);
12919 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
12920 offset
, per_cu
->cu
->objfile
->name
);
12922 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
12925 /* DWARF: "If there is no such attribute, then there is no effect.". */
12927 retval
.data
= NULL
;
12932 if (!attr_form_is_block (attr
))
12933 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
12934 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
12935 offset
, per_cu
->cu
->objfile
->name
);
12937 retval
.data
= DW_BLOCK (attr
)->data
;
12938 retval
.size
= DW_BLOCK (attr
)->size
;
12940 retval
.per_cu
= cu
->per_cu
;
12944 /* Follow the signature attribute ATTR in SRC_DIE.
12945 On entry *REF_CU is the CU of SRC_DIE.
12946 On exit *REF_CU is the CU of the result. */
12948 static struct die_info
*
12949 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
12950 struct dwarf2_cu
**ref_cu
)
12952 struct objfile
*objfile
= (*ref_cu
)->objfile
;
12953 struct die_info temp_die
;
12954 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
12955 struct dwarf2_cu
*sig_cu
;
12956 struct die_info
*die
;
12958 /* sig_type will be NULL if the signatured type is missing from
12960 if (sig_type
== NULL
)
12961 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12962 "at 0x%x [in module %s]"),
12963 src_die
->offset
, objfile
->name
);
12965 /* If necessary, add it to the queue and load its DIEs. */
12967 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
12968 read_signatured_type (objfile
, sig_type
);
12970 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
12972 sig_cu
= sig_type
->per_cu
.cu
;
12973 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
12974 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
12981 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12982 "at 0x%x [in module %s]"),
12983 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
12986 /* Given an offset of a signatured type, return its signatured_type. */
12988 static struct signatured_type
*
12989 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
12991 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
12992 unsigned int length
, initial_length_size
;
12993 unsigned int sig_offset
;
12994 struct signatured_type find_entry
, *type_sig
;
12996 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
12997 sig_offset
= (initial_length_size
12999 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
13000 + 1 /*address_size*/);
13001 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
13002 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
13004 /* This is only used to lookup previously recorded types.
13005 If we didn't find it, it's our bug. */
13006 gdb_assert (type_sig
!= NULL
);
13007 gdb_assert (offset
== type_sig
->offset
);
13012 /* Read in signatured type at OFFSET and build its CU and die(s). */
13015 read_signatured_type_at_offset (struct objfile
*objfile
,
13016 unsigned int offset
)
13018 struct signatured_type
*type_sig
;
13020 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13022 /* We have the section offset, but we need the signature to do the
13023 hash table lookup. */
13024 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
13026 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13028 read_signatured_type (objfile
, type_sig
);
13030 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
13033 /* Read in a signatured type and build its CU and DIEs. */
13036 read_signatured_type (struct objfile
*objfile
,
13037 struct signatured_type
*type_sig
)
13039 gdb_byte
*types_ptr
;
13040 struct die_reader_specs reader_specs
;
13041 struct dwarf2_cu
*cu
;
13042 ULONGEST signature
;
13043 struct cleanup
*back_to
, *free_cu_cleanup
;
13044 struct attribute
*attr
;
13046 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
13047 types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
13049 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
13051 cu
= xmalloc (sizeof (struct dwarf2_cu
));
13052 memset (cu
, 0, sizeof (struct dwarf2_cu
));
13053 obstack_init (&cu
->comp_unit_obstack
);
13054 cu
->objfile
= objfile
;
13055 type_sig
->per_cu
.cu
= cu
;
13056 cu
->per_cu
= &type_sig
->per_cu
;
13058 /* If an error occurs while loading, release our storage. */
13059 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
13061 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
13062 types_ptr
, objfile
->obfd
);
13063 gdb_assert (signature
== type_sig
->signature
);
13066 = htab_create_alloc_ex (cu
->header
.length
/ 12,
13070 &cu
->comp_unit_obstack
,
13071 hashtab_obstack_allocate
,
13072 dummy_obstack_deallocate
);
13074 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
13075 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
13077 init_cu_die_reader (&reader_specs
, cu
);
13079 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
13082 /* We try not to read any attributes in this function, because not
13083 all objfiles needed for references have been loaded yet, and symbol
13084 table processing isn't initialized. But we have to set the CU language,
13085 or we won't be able to build types correctly. */
13086 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
13088 set_cu_language (DW_UNSND (attr
), cu
);
13090 set_cu_language (language_minimal
, cu
);
13092 do_cleanups (back_to
);
13094 /* We've successfully allocated this compilation unit. Let our caller
13095 clean it up when finished with it. */
13096 discard_cleanups (free_cu_cleanup
);
13098 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
13099 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
13102 /* Decode simple location descriptions.
13103 Given a pointer to a dwarf block that defines a location, compute
13104 the location and return the value.
13106 NOTE drow/2003-11-18: This function is called in two situations
13107 now: for the address of static or global variables (partial symbols
13108 only) and for offsets into structures which are expected to be
13109 (more or less) constant. The partial symbol case should go away,
13110 and only the constant case should remain. That will let this
13111 function complain more accurately. A few special modes are allowed
13112 without complaint for global variables (for instance, global
13113 register values and thread-local values).
13115 A location description containing no operations indicates that the
13116 object is optimized out. The return value is 0 for that case.
13117 FIXME drow/2003-11-16: No callers check for this case any more; soon all
13118 callers will only want a very basic result and this can become a
13121 Note that stack[0] is unused except as a default error return.
13122 Note that stack overflow is not yet handled. */
13125 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
13127 struct objfile
*objfile
= cu
->objfile
;
13129 int size
= blk
->size
;
13130 gdb_byte
*data
= blk
->data
;
13131 CORE_ADDR stack
[64];
13133 unsigned int bytes_read
, unsnd
;
13177 stack
[++stacki
] = op
- DW_OP_lit0
;
13212 stack
[++stacki
] = op
- DW_OP_reg0
;
13214 dwarf2_complex_location_expr_complaint ();
13218 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13220 stack
[++stacki
] = unsnd
;
13222 dwarf2_complex_location_expr_complaint ();
13226 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
13231 case DW_OP_const1u
:
13232 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
13236 case DW_OP_const1s
:
13237 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
13241 case DW_OP_const2u
:
13242 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
13246 case DW_OP_const2s
:
13247 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
13251 case DW_OP_const4u
:
13252 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
13256 case DW_OP_const4s
:
13257 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
13262 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
13268 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
13273 stack
[stacki
+ 1] = stack
[stacki
];
13278 stack
[stacki
- 1] += stack
[stacki
];
13282 case DW_OP_plus_uconst
:
13283 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
13288 stack
[stacki
- 1] -= stack
[stacki
];
13293 /* If we're not the last op, then we definitely can't encode
13294 this using GDB's address_class enum. This is valid for partial
13295 global symbols, although the variable's address will be bogus
13298 dwarf2_complex_location_expr_complaint ();
13301 case DW_OP_GNU_push_tls_address
:
13302 /* The top of the stack has the offset from the beginning
13303 of the thread control block at which the variable is located. */
13304 /* Nothing should follow this operator, so the top of stack would
13306 /* This is valid for partial global symbols, but the variable's
13307 address will be bogus in the psymtab. */
13309 dwarf2_complex_location_expr_complaint ();
13312 case DW_OP_GNU_uninit
:
13316 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
13317 dwarf_stack_op_name (op
, 1));
13318 return (stack
[stacki
]);
13321 return (stack
[stacki
]);
13324 /* memory allocation interface */
13326 static struct dwarf_block
*
13327 dwarf_alloc_block (struct dwarf2_cu
*cu
)
13329 struct dwarf_block
*blk
;
13331 blk
= (struct dwarf_block
*)
13332 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
13336 static struct abbrev_info
*
13337 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
13339 struct abbrev_info
*abbrev
;
13341 abbrev
= (struct abbrev_info
*)
13342 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
13343 memset (abbrev
, 0, sizeof (struct abbrev_info
));
13347 static struct die_info
*
13348 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
13350 struct die_info
*die
;
13351 size_t size
= sizeof (struct die_info
);
13354 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
13356 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
13357 memset (die
, 0, sizeof (struct die_info
));
13362 /* Macro support. */
13365 /* Return the full name of file number I in *LH's file name table.
13366 Use COMP_DIR as the name of the current directory of the
13367 compilation. The result is allocated using xmalloc; the caller is
13368 responsible for freeing it. */
13370 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
13372 /* Is the file number a valid index into the line header's file name
13373 table? Remember that file numbers start with one, not zero. */
13374 if (1 <= file
&& file
<= lh
->num_file_names
)
13376 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
13378 if (IS_ABSOLUTE_PATH (fe
->name
))
13379 return xstrdup (fe
->name
);
13387 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
13393 dir_len
= strlen (dir
);
13394 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
13395 strcpy (full_name
, dir
);
13396 full_name
[dir_len
] = '/';
13397 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
13401 return xstrdup (fe
->name
);
13406 /* The compiler produced a bogus file number. We can at least
13407 record the macro definitions made in the file, even if we
13408 won't be able to find the file by name. */
13409 char fake_name
[80];
13411 sprintf (fake_name
, "<bad macro file number %d>", file
);
13413 complaint (&symfile_complaints
,
13414 _("bad file number in macro information (%d)"),
13417 return xstrdup (fake_name
);
13422 static struct macro_source_file
*
13423 macro_start_file (int file
, int line
,
13424 struct macro_source_file
*current_file
,
13425 const char *comp_dir
,
13426 struct line_header
*lh
, struct objfile
*objfile
)
13428 /* The full name of this source file. */
13429 char *full_name
= file_full_name (file
, lh
, comp_dir
);
13431 /* We don't create a macro table for this compilation unit
13432 at all until we actually get a filename. */
13433 if (! pending_macros
)
13434 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
13435 objfile
->macro_cache
);
13437 if (! current_file
)
13438 /* If we have no current file, then this must be the start_file
13439 directive for the compilation unit's main source file. */
13440 current_file
= macro_set_main (pending_macros
, full_name
);
13442 current_file
= macro_include (current_file
, line
, full_name
);
13446 return current_file
;
13450 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
13451 followed by a null byte. */
13453 copy_string (const char *buf
, int len
)
13455 char *s
= xmalloc (len
+ 1);
13457 memcpy (s
, buf
, len
);
13463 static const char *
13464 consume_improper_spaces (const char *p
, const char *body
)
13468 complaint (&symfile_complaints
,
13469 _("macro definition contains spaces in formal argument list:\n`%s'"),
13481 parse_macro_definition (struct macro_source_file
*file
, int line
,
13486 /* The body string takes one of two forms. For object-like macro
13487 definitions, it should be:
13489 <macro name> " " <definition>
13491 For function-like macro definitions, it should be:
13493 <macro name> "() " <definition>
13495 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
13497 Spaces may appear only where explicitly indicated, and in the
13500 The Dwarf 2 spec says that an object-like macro's name is always
13501 followed by a space, but versions of GCC around March 2002 omit
13502 the space when the macro's definition is the empty string.
13504 The Dwarf 2 spec says that there should be no spaces between the
13505 formal arguments in a function-like macro's formal argument list,
13506 but versions of GCC around March 2002 include spaces after the
13510 /* Find the extent of the macro name. The macro name is terminated
13511 by either a space or null character (for an object-like macro) or
13512 an opening paren (for a function-like macro). */
13513 for (p
= body
; *p
; p
++)
13514 if (*p
== ' ' || *p
== '(')
13517 if (*p
== ' ' || *p
== '\0')
13519 /* It's an object-like macro. */
13520 int name_len
= p
- body
;
13521 char *name
= copy_string (body
, name_len
);
13522 const char *replacement
;
13525 replacement
= body
+ name_len
+ 1;
13528 dwarf2_macro_malformed_definition_complaint (body
);
13529 replacement
= body
+ name_len
;
13532 macro_define_object (file
, line
, name
, replacement
);
13536 else if (*p
== '(')
13538 /* It's a function-like macro. */
13539 char *name
= copy_string (body
, p
- body
);
13542 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
13546 p
= consume_improper_spaces (p
, body
);
13548 /* Parse the formal argument list. */
13549 while (*p
&& *p
!= ')')
13551 /* Find the extent of the current argument name. */
13552 const char *arg_start
= p
;
13554 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
13557 if (! *p
|| p
== arg_start
)
13558 dwarf2_macro_malformed_definition_complaint (body
);
13561 /* Make sure argv has room for the new argument. */
13562 if (argc
>= argv_size
)
13565 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
13568 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
13571 p
= consume_improper_spaces (p
, body
);
13573 /* Consume the comma, if present. */
13578 p
= consume_improper_spaces (p
, body
);
13587 /* Perfectly formed definition, no complaints. */
13588 macro_define_function (file
, line
, name
,
13589 argc
, (const char **) argv
,
13591 else if (*p
== '\0')
13593 /* Complain, but do define it. */
13594 dwarf2_macro_malformed_definition_complaint (body
);
13595 macro_define_function (file
, line
, name
,
13596 argc
, (const char **) argv
,
13600 /* Just complain. */
13601 dwarf2_macro_malformed_definition_complaint (body
);
13604 /* Just complain. */
13605 dwarf2_macro_malformed_definition_complaint (body
);
13611 for (i
= 0; i
< argc
; i
++)
13617 dwarf2_macro_malformed_definition_complaint (body
);
13622 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
13623 char *comp_dir
, bfd
*abfd
,
13624 struct dwarf2_cu
*cu
)
13626 gdb_byte
*mac_ptr
, *mac_end
;
13627 struct macro_source_file
*current_file
= 0;
13628 enum dwarf_macinfo_record_type macinfo_type
;
13629 int at_commandline
;
13631 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13632 &dwarf2_per_objfile
->macinfo
);
13633 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
13635 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
13639 /* First pass: Find the name of the base filename.
13640 This filename is needed in order to process all macros whose definition
13641 (or undefinition) comes from the command line. These macros are defined
13642 before the first DW_MACINFO_start_file entry, and yet still need to be
13643 associated to the base file.
13645 To determine the base file name, we scan the macro definitions until we
13646 reach the first DW_MACINFO_start_file entry. We then initialize
13647 CURRENT_FILE accordingly so that any macro definition found before the
13648 first DW_MACINFO_start_file can still be associated to the base file. */
13650 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13651 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
13652 + dwarf2_per_objfile
->macinfo
.size
;
13656 /* Do we at least have room for a macinfo type byte? */
13657 if (mac_ptr
>= mac_end
)
13659 /* Complaint is printed during the second pass as GDB will probably
13660 stop the first pass earlier upon finding DW_MACINFO_start_file. */
13664 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13667 switch (macinfo_type
)
13669 /* A zero macinfo type indicates the end of the macro
13674 case DW_MACINFO_define
:
13675 case DW_MACINFO_undef
:
13676 /* Only skip the data by MAC_PTR. */
13678 unsigned int bytes_read
;
13680 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13681 mac_ptr
+= bytes_read
;
13682 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13683 mac_ptr
+= bytes_read
;
13687 case DW_MACINFO_start_file
:
13689 unsigned int bytes_read
;
13692 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13693 mac_ptr
+= bytes_read
;
13694 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13695 mac_ptr
+= bytes_read
;
13697 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
13702 case DW_MACINFO_end_file
:
13703 /* No data to skip by MAC_PTR. */
13706 case DW_MACINFO_vendor_ext
:
13707 /* Only skip the data by MAC_PTR. */
13709 unsigned int bytes_read
;
13711 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13712 mac_ptr
+= bytes_read
;
13713 read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13714 mac_ptr
+= bytes_read
;
13721 } while (macinfo_type
!= 0 && current_file
== NULL
);
13723 /* Second pass: Process all entries.
13725 Use the AT_COMMAND_LINE flag to determine whether we are still processing
13726 command-line macro definitions/undefinitions. This flag is unset when we
13727 reach the first DW_MACINFO_start_file entry. */
13729 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
13731 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
13732 GDB is still reading the definitions from command line. First
13733 DW_MACINFO_start_file will need to be ignored as it was already executed
13734 to create CURRENT_FILE for the main source holding also the command line
13735 definitions. On first met DW_MACINFO_start_file this flag is reset to
13736 normally execute all the remaining DW_MACINFO_start_file macinfos. */
13738 at_commandline
= 1;
13742 /* Do we at least have room for a macinfo type byte? */
13743 if (mac_ptr
>= mac_end
)
13745 dwarf2_macros_too_long_complaint ();
13749 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
13752 switch (macinfo_type
)
13754 /* A zero macinfo type indicates the end of the macro
13759 case DW_MACINFO_define
:
13760 case DW_MACINFO_undef
:
13762 unsigned int bytes_read
;
13766 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13767 mac_ptr
+= bytes_read
;
13768 body
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13769 mac_ptr
+= bytes_read
;
13771 if (! current_file
)
13773 /* DWARF violation as no main source is present. */
13774 complaint (&symfile_complaints
,
13775 _("debug info with no main source gives macro %s "
13777 macinfo_type
== DW_MACINFO_define
?
13779 macinfo_type
== DW_MACINFO_undef
?
13780 _("undefinition") :
13781 _("something-or-other"), line
, body
);
13784 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13785 complaint (&symfile_complaints
,
13786 _("debug info gives %s macro %s with %s line %d: %s"),
13787 at_commandline
? _("command-line") : _("in-file"),
13788 macinfo_type
== DW_MACINFO_define
?
13790 macinfo_type
== DW_MACINFO_undef
?
13791 _("undefinition") :
13792 _("something-or-other"),
13793 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
13795 if (macinfo_type
== DW_MACINFO_define
)
13796 parse_macro_definition (current_file
, line
, body
);
13797 else if (macinfo_type
== DW_MACINFO_undef
)
13798 macro_undef (current_file
, line
, body
);
13802 case DW_MACINFO_start_file
:
13804 unsigned int bytes_read
;
13807 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13808 mac_ptr
+= bytes_read
;
13809 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13810 mac_ptr
+= bytes_read
;
13812 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
13813 complaint (&symfile_complaints
,
13814 _("debug info gives source %d included "
13815 "from %s at %s line %d"),
13816 file
, at_commandline
? _("command-line") : _("file"),
13817 line
== 0 ? _("zero") : _("non-zero"), line
);
13819 if (at_commandline
)
13821 /* This DW_MACINFO_start_file was executed in the pass one. */
13822 at_commandline
= 0;
13825 current_file
= macro_start_file (file
, line
,
13826 current_file
, comp_dir
,
13831 case DW_MACINFO_end_file
:
13832 if (! current_file
)
13833 complaint (&symfile_complaints
,
13834 _("macro debug info has an unmatched `close_file' directive"));
13837 current_file
= current_file
->included_by
;
13838 if (! current_file
)
13840 enum dwarf_macinfo_record_type next_type
;
13842 /* GCC circa March 2002 doesn't produce the zero
13843 type byte marking the end of the compilation
13844 unit. Complain if it's not there, but exit no
13847 /* Do we at least have room for a macinfo type byte? */
13848 if (mac_ptr
>= mac_end
)
13850 dwarf2_macros_too_long_complaint ();
13854 /* We don't increment mac_ptr here, so this is just
13856 next_type
= read_1_byte (abfd
, mac_ptr
);
13857 if (next_type
!= 0)
13858 complaint (&symfile_complaints
,
13859 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
13866 case DW_MACINFO_vendor_ext
:
13868 unsigned int bytes_read
;
13872 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
13873 mac_ptr
+= bytes_read
;
13874 string
= read_direct_string (abfd
, mac_ptr
, &bytes_read
);
13875 mac_ptr
+= bytes_read
;
13877 /* We don't recognize any vendor extensions. */
13881 } while (macinfo_type
!= 0);
13884 /* Check if the attribute's form is a DW_FORM_block*
13885 if so return true else false. */
13887 attr_form_is_block (struct attribute
*attr
)
13889 return (attr
== NULL
? 0 :
13890 attr
->form
== DW_FORM_block1
13891 || attr
->form
== DW_FORM_block2
13892 || attr
->form
== DW_FORM_block4
13893 || attr
->form
== DW_FORM_block
13894 || attr
->form
== DW_FORM_exprloc
);
13897 /* Return non-zero if ATTR's value is a section offset --- classes
13898 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
13899 You may use DW_UNSND (attr) to retrieve such offsets.
13901 Section 7.5.4, "Attribute Encodings", explains that no attribute
13902 may have a value that belongs to more than one of these classes; it
13903 would be ambiguous if we did, because we use the same forms for all
13906 attr_form_is_section_offset (struct attribute
*attr
)
13908 return (attr
->form
== DW_FORM_data4
13909 || attr
->form
== DW_FORM_data8
13910 || attr
->form
== DW_FORM_sec_offset
);
13914 /* Return non-zero if ATTR's value falls in the 'constant' class, or
13915 zero otherwise. When this function returns true, you can apply
13916 dwarf2_get_attr_constant_value to it.
13918 However, note that for some attributes you must check
13919 attr_form_is_section_offset before using this test. DW_FORM_data4
13920 and DW_FORM_data8 are members of both the constant class, and of
13921 the classes that contain offsets into other debug sections
13922 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
13923 that, if an attribute's can be either a constant or one of the
13924 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
13925 taken as section offsets, not constants. */
13927 attr_form_is_constant (struct attribute
*attr
)
13929 switch (attr
->form
)
13931 case DW_FORM_sdata
:
13932 case DW_FORM_udata
:
13933 case DW_FORM_data1
:
13934 case DW_FORM_data2
:
13935 case DW_FORM_data4
:
13936 case DW_FORM_data8
:
13944 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
13945 struct dwarf2_cu
*cu
)
13947 if (attr_form_is_section_offset (attr
)
13948 /* ".debug_loc" may not exist at all, or the offset may be outside
13949 the section. If so, fall through to the complaint in the
13951 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
13953 struct dwarf2_loclist_baton
*baton
;
13955 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13956 sizeof (struct dwarf2_loclist_baton
));
13957 baton
->per_cu
= cu
->per_cu
;
13958 gdb_assert (baton
->per_cu
);
13960 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
13961 &dwarf2_per_objfile
->loc
);
13963 /* We don't know how long the location list is, but make sure we
13964 don't run off the edge of the section. */
13965 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
13966 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
13967 baton
->base_address
= cu
->base_address
;
13968 if (cu
->base_known
== 0)
13969 complaint (&symfile_complaints
,
13970 _("Location list used without specifying the CU base address."));
13972 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
13973 SYMBOL_LOCATION_BATON (sym
) = baton
;
13977 struct dwarf2_locexpr_baton
*baton
;
13979 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13980 sizeof (struct dwarf2_locexpr_baton
));
13981 baton
->per_cu
= cu
->per_cu
;
13982 gdb_assert (baton
->per_cu
);
13984 if (attr_form_is_block (attr
))
13986 /* Note that we're just copying the block's data pointer
13987 here, not the actual data. We're still pointing into the
13988 info_buffer for SYM's objfile; right now we never release
13989 that buffer, but when we do clean up properly this may
13991 baton
->size
= DW_BLOCK (attr
)->size
;
13992 baton
->data
= DW_BLOCK (attr
)->data
;
13996 dwarf2_invalid_attrib_class_complaint ("location description",
13997 SYMBOL_NATURAL_NAME (sym
));
13999 baton
->data
= NULL
;
14002 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
14003 SYMBOL_LOCATION_BATON (sym
) = baton
;
14007 /* Return the OBJFILE associated with the compilation unit CU. If CU
14008 came from a separate debuginfo file, then the master objfile is
14012 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
14014 struct objfile
*objfile
= per_cu
->objfile
;
14016 /* Return the master objfile, so that we can report and look up the
14017 correct file containing this variable. */
14018 if (objfile
->separate_debug_objfile_backlink
)
14019 objfile
= objfile
->separate_debug_objfile_backlink
;
14024 /* Return the address size given in the compilation unit header for CU. */
14027 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
14030 return per_cu
->cu
->header
.addr_size
;
14033 /* If the CU is not currently read in, we re-read its header. */
14034 struct objfile
*objfile
= per_cu
->objfile
;
14035 struct dwarf2_per_objfile
*per_objfile
14036 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14037 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14038 struct comp_unit_head cu_header
;
14040 memset (&cu_header
, 0, sizeof cu_header
);
14041 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14042 return cu_header
.addr_size
;
14046 /* Return the offset size given in the compilation unit header for CU. */
14049 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
14052 return per_cu
->cu
->header
.offset_size
;
14055 /* If the CU is not currently read in, we re-read its header. */
14056 struct objfile
*objfile
= per_cu
->objfile
;
14057 struct dwarf2_per_objfile
*per_objfile
14058 = objfile_data (objfile
, dwarf2_objfile_data_key
);
14059 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
14060 struct comp_unit_head cu_header
;
14062 memset (&cu_header
, 0, sizeof cu_header
);
14063 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
14064 return cu_header
.offset_size
;
14068 /* Return the text offset of the CU. The returned offset comes from
14069 this CU's objfile. If this objfile came from a separate debuginfo
14070 file, then the offset may be different from the corresponding
14071 offset in the parent objfile. */
14074 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
14076 struct objfile
*objfile
= per_cu
->objfile
;
14078 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14081 /* Locate the .debug_info compilation unit from CU's objfile which contains
14082 the DIE at OFFSET. Raises an error on failure. */
14084 static struct dwarf2_per_cu_data
*
14085 dwarf2_find_containing_comp_unit (unsigned int offset
,
14086 struct objfile
*objfile
)
14088 struct dwarf2_per_cu_data
*this_cu
;
14092 high
= dwarf2_per_objfile
->n_comp_units
- 1;
14095 int mid
= low
+ (high
- low
) / 2;
14097 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
14102 gdb_assert (low
== high
);
14103 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
14106 error (_("Dwarf Error: could not find partial DIE containing "
14107 "offset 0x%lx [in module %s]"),
14108 (long) offset
, bfd_get_filename (objfile
->obfd
));
14110 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
14111 return dwarf2_per_objfile
->all_comp_units
[low
-1];
14115 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
14116 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
14117 && offset
>= this_cu
->offset
+ this_cu
->length
)
14118 error (_("invalid dwarf2 offset %u"), offset
);
14119 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
14124 /* Locate the compilation unit from OBJFILE which is located at exactly
14125 OFFSET. Raises an error on failure. */
14127 static struct dwarf2_per_cu_data
*
14128 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
14130 struct dwarf2_per_cu_data
*this_cu
;
14132 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
14133 if (this_cu
->offset
!= offset
)
14134 error (_("no compilation unit with offset %u."), offset
);
14138 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
14140 static struct dwarf2_cu
*
14141 alloc_one_comp_unit (struct objfile
*objfile
)
14143 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
14144 cu
->objfile
= objfile
;
14145 obstack_init (&cu
->comp_unit_obstack
);
14149 /* Release one cached compilation unit, CU. We unlink it from the tree
14150 of compilation units, but we don't remove it from the read_in_chain;
14151 the caller is responsible for that.
14152 NOTE: DATA is a void * because this function is also used as a
14153 cleanup routine. */
14156 free_one_comp_unit (void *data
)
14158 struct dwarf2_cu
*cu
= data
;
14160 if (cu
->per_cu
!= NULL
)
14161 cu
->per_cu
->cu
= NULL
;
14164 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14169 /* This cleanup function is passed the address of a dwarf2_cu on the stack
14170 when we're finished with it. We can't free the pointer itself, but be
14171 sure to unlink it from the cache. Also release any associated storage
14172 and perform cache maintenance.
14174 Only used during partial symbol parsing. */
14177 free_stack_comp_unit (void *data
)
14179 struct dwarf2_cu
*cu
= data
;
14181 obstack_free (&cu
->comp_unit_obstack
, NULL
);
14182 cu
->partial_dies
= NULL
;
14184 if (cu
->per_cu
!= NULL
)
14186 /* This compilation unit is on the stack in our caller, so we
14187 should not xfree it. Just unlink it. */
14188 cu
->per_cu
->cu
= NULL
;
14191 /* If we had a per-cu pointer, then we may have other compilation
14192 units loaded, so age them now. */
14193 age_cached_comp_units ();
14197 /* Free all cached compilation units. */
14200 free_cached_comp_units (void *data
)
14202 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14204 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14205 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14206 while (per_cu
!= NULL
)
14208 struct dwarf2_per_cu_data
*next_cu
;
14210 next_cu
= per_cu
->cu
->read_in_chain
;
14212 free_one_comp_unit (per_cu
->cu
);
14213 *last_chain
= next_cu
;
14219 /* Increase the age counter on each cached compilation unit, and free
14220 any that are too old. */
14223 age_cached_comp_units (void)
14225 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14227 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
14228 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14229 while (per_cu
!= NULL
)
14231 per_cu
->cu
->last_used
++;
14232 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
14233 dwarf2_mark (per_cu
->cu
);
14234 per_cu
= per_cu
->cu
->read_in_chain
;
14237 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14238 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14239 while (per_cu
!= NULL
)
14241 struct dwarf2_per_cu_data
*next_cu
;
14243 next_cu
= per_cu
->cu
->read_in_chain
;
14245 if (!per_cu
->cu
->mark
)
14247 free_one_comp_unit (per_cu
->cu
);
14248 *last_chain
= next_cu
;
14251 last_chain
= &per_cu
->cu
->read_in_chain
;
14257 /* Remove a single compilation unit from the cache. */
14260 free_one_cached_comp_unit (void *target_cu
)
14262 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
14264 per_cu
= dwarf2_per_objfile
->read_in_chain
;
14265 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
14266 while (per_cu
!= NULL
)
14268 struct dwarf2_per_cu_data
*next_cu
;
14270 next_cu
= per_cu
->cu
->read_in_chain
;
14272 if (per_cu
->cu
== target_cu
)
14274 free_one_comp_unit (per_cu
->cu
);
14275 *last_chain
= next_cu
;
14279 last_chain
= &per_cu
->cu
->read_in_chain
;
14285 /* Release all extra memory associated with OBJFILE. */
14288 dwarf2_free_objfile (struct objfile
*objfile
)
14290 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14292 if (dwarf2_per_objfile
== NULL
)
14295 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
14296 free_cached_comp_units (NULL
);
14298 if (dwarf2_per_objfile
->using_index
)
14302 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14305 struct dwarf2_per_cu_data
*per_cu
=
14306 dwarf2_per_objfile
->all_comp_units
[i
];
14308 if (!per_cu
->v
.quick
->lines
)
14311 for (j
= 0; j
< per_cu
->v
.quick
->lines
->num_file_names
; ++j
)
14313 if (per_cu
->v
.quick
->file_names
)
14314 xfree ((void *) per_cu
->v
.quick
->file_names
[j
]);
14315 if (per_cu
->v
.quick
->full_names
)
14316 xfree ((void *) per_cu
->v
.quick
->full_names
[j
]);
14319 free_line_header (per_cu
->v
.quick
->lines
);
14323 /* Everything else should be on the objfile obstack. */
14326 /* A pair of DIE offset and GDB type pointer. We store these
14327 in a hash table separate from the DIEs, and preserve them
14328 when the DIEs are flushed out of cache. */
14330 struct dwarf2_offset_and_type
14332 unsigned int offset
;
14336 /* Hash function for a dwarf2_offset_and_type. */
14339 offset_and_type_hash (const void *item
)
14341 const struct dwarf2_offset_and_type
*ofs
= item
;
14343 return ofs
->offset
;
14346 /* Equality function for a dwarf2_offset_and_type. */
14349 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
14351 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
14352 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
14354 return ofs_lhs
->offset
== ofs_rhs
->offset
;
14357 /* Set the type associated with DIE to TYPE. Save it in CU's hash
14358 table if necessary. For convenience, return TYPE.
14360 The DIEs reading must have careful ordering to:
14361 * Not cause infite loops trying to read in DIEs as a prerequisite for
14362 reading current DIE.
14363 * Not trying to dereference contents of still incompletely read in types
14364 while reading in other DIEs.
14365 * Enable referencing still incompletely read in types just by a pointer to
14366 the type without accessing its fields.
14368 Therefore caller should follow these rules:
14369 * Try to fetch any prerequisite types we may need to build this DIE type
14370 before building the type and calling set_die_type.
14371 * After building type call set_die_type for current DIE as soon as
14372 possible before fetching more types to complete the current type.
14373 * Make the type as complete as possible before fetching more types. */
14375 static struct type
*
14376 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
14378 struct dwarf2_offset_and_type
**slot
, ofs
;
14379 struct objfile
*objfile
= cu
->objfile
;
14380 htab_t
*type_hash_ptr
;
14382 /* For Ada types, make sure that the gnat-specific data is always
14383 initialized (if not already set). There are a few types where
14384 we should not be doing so, because the type-specific area is
14385 already used to hold some other piece of info (eg: TYPE_CODE_FLT
14386 where the type-specific area is used to store the floatformat).
14387 But this is not a problem, because the gnat-specific information
14388 is actually not needed for these types. */
14389 if (need_gnat_info (cu
)
14390 && TYPE_CODE (type
) != TYPE_CODE_FUNC
14391 && TYPE_CODE (type
) != TYPE_CODE_FLT
14392 && !HAVE_GNAT_AUX_INFO (type
))
14393 INIT_GNAT_SPECIFIC (type
);
14395 if (cu
->per_cu
->from_debug_types
)
14396 type_hash_ptr
= &dwarf2_per_objfile
->debug_types_type_hash
;
14398 type_hash_ptr
= &dwarf2_per_objfile
->debug_info_type_hash
;
14400 if (*type_hash_ptr
== NULL
)
14403 = htab_create_alloc_ex (127,
14404 offset_and_type_hash
,
14405 offset_and_type_eq
,
14407 &objfile
->objfile_obstack
,
14408 hashtab_obstack_allocate
,
14409 dummy_obstack_deallocate
);
14412 ofs
.offset
= die
->offset
;
14414 slot
= (struct dwarf2_offset_and_type
**)
14415 htab_find_slot_with_hash (*type_hash_ptr
, &ofs
, ofs
.offset
, INSERT
);
14417 complaint (&symfile_complaints
,
14418 _("A problem internal to GDB: DIE 0x%x has type already set"),
14420 *slot
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (**slot
));
14425 /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash
14426 table, or return NULL if the die does not have a saved type. */
14428 static struct type
*
14429 get_die_type_at_offset (unsigned int offset
,
14430 struct dwarf2_per_cu_data
*per_cu
)
14432 struct dwarf2_offset_and_type
*slot
, ofs
;
14435 if (per_cu
->from_debug_types
)
14436 type_hash
= dwarf2_per_objfile
->debug_types_type_hash
;
14438 type_hash
= dwarf2_per_objfile
->debug_info_type_hash
;
14439 if (type_hash
== NULL
)
14442 ofs
.offset
= offset
;
14443 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
14450 /* Look up the type for DIE in the appropriate type_hash table,
14451 or return NULL if DIE does not have a saved type. */
14453 static struct type
*
14454 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
14456 return get_die_type_at_offset (die
->offset
, cu
->per_cu
);
14459 /* Add a dependence relationship from CU to REF_PER_CU. */
14462 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
14463 struct dwarf2_per_cu_data
*ref_per_cu
)
14467 if (cu
->dependencies
== NULL
)
14469 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
14470 NULL
, &cu
->comp_unit_obstack
,
14471 hashtab_obstack_allocate
,
14472 dummy_obstack_deallocate
);
14474 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
14476 *slot
= ref_per_cu
;
14479 /* Subroutine of dwarf2_mark to pass to htab_traverse.
14480 Set the mark field in every compilation unit in the
14481 cache that we must keep because we are keeping CU. */
14484 dwarf2_mark_helper (void **slot
, void *data
)
14486 struct dwarf2_per_cu_data
*per_cu
;
14488 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
14489 if (per_cu
->cu
->mark
)
14491 per_cu
->cu
->mark
= 1;
14493 if (per_cu
->cu
->dependencies
!= NULL
)
14494 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14499 /* Set the mark field in CU and in every other compilation unit in the
14500 cache that we must keep because we are keeping CU. */
14503 dwarf2_mark (struct dwarf2_cu
*cu
)
14508 if (cu
->dependencies
!= NULL
)
14509 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
14513 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
14517 per_cu
->cu
->mark
= 0;
14518 per_cu
= per_cu
->cu
->read_in_chain
;
14522 /* Trivial hash function for partial_die_info: the hash value of a DIE
14523 is its offset in .debug_info for this objfile. */
14526 partial_die_hash (const void *item
)
14528 const struct partial_die_info
*part_die
= item
;
14530 return part_die
->offset
;
14533 /* Trivial comparison function for partial_die_info structures: two DIEs
14534 are equal if they have the same offset. */
14537 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
14539 const struct partial_die_info
*part_die_lhs
= item_lhs
;
14540 const struct partial_die_info
*part_die_rhs
= item_rhs
;
14542 return part_die_lhs
->offset
== part_die_rhs
->offset
;
14545 static struct cmd_list_element
*set_dwarf2_cmdlist
;
14546 static struct cmd_list_element
*show_dwarf2_cmdlist
;
14549 set_dwarf2_cmd (char *args
, int from_tty
)
14551 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
14555 show_dwarf2_cmd (char *args
, int from_tty
)
14557 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
14560 /* If section described by INFO was mmapped, munmap it now. */
14563 munmap_section_buffer (struct dwarf2_section_info
*info
)
14565 if (info
->was_mmapped
)
14568 intptr_t begin
= (intptr_t) info
->buffer
;
14569 intptr_t map_begin
= begin
& ~(pagesize
- 1);
14570 size_t map_length
= info
->size
+ begin
- map_begin
;
14572 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
14574 /* Without HAVE_MMAP, we should never be here to begin with. */
14575 gdb_assert_not_reached ("no mmap support");
14580 /* munmap debug sections for OBJFILE, if necessary. */
14583 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
14585 struct dwarf2_per_objfile
*data
= d
;
14587 /* This is sorted according to the order they're defined in to make it easier
14588 to keep in sync. */
14589 munmap_section_buffer (&data
->info
);
14590 munmap_section_buffer (&data
->abbrev
);
14591 munmap_section_buffer (&data
->line
);
14592 munmap_section_buffer (&data
->loc
);
14593 munmap_section_buffer (&data
->macinfo
);
14594 munmap_section_buffer (&data
->str
);
14595 munmap_section_buffer (&data
->ranges
);
14596 munmap_section_buffer (&data
->types
);
14597 munmap_section_buffer (&data
->frame
);
14598 munmap_section_buffer (&data
->eh_frame
);
14599 munmap_section_buffer (&data
->gdb_index
);
14604 /* The contents of the hash table we create when building the string
14606 struct strtab_entry
14608 offset_type offset
;
14612 /* Hash function for a strtab_entry. */
14614 hash_strtab_entry (const void *e
)
14616 const struct strtab_entry
*entry
= e
;
14617 return mapped_index_string_hash (entry
->str
);
14620 /* Equality function for a strtab_entry. */
14622 eq_strtab_entry (const void *a
, const void *b
)
14624 const struct strtab_entry
*ea
= a
;
14625 const struct strtab_entry
*eb
= b
;
14626 return !strcmp (ea
->str
, eb
->str
);
14629 /* Create a strtab_entry hash table. */
14631 create_strtab (void)
14633 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
14634 xfree
, xcalloc
, xfree
);
14637 /* Add a string to the constant pool. Return the string's offset in
14640 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
14643 struct strtab_entry entry
;
14644 struct strtab_entry
*result
;
14647 slot
= htab_find_slot (table
, &entry
, INSERT
);
14652 result
= XNEW (struct strtab_entry
);
14653 result
->offset
= obstack_object_size (cpool
);
14655 obstack_grow_str0 (cpool
, str
);
14658 return result
->offset
;
14661 /* An entry in the symbol table. */
14662 struct symtab_index_entry
14664 /* The name of the symbol. */
14666 /* The offset of the name in the constant pool. */
14667 offset_type index_offset
;
14668 /* A sorted vector of the indices of all the CUs that hold an object
14670 VEC (offset_type
) *cu_indices
;
14673 /* The symbol table. This is a power-of-2-sized hash table. */
14674 struct mapped_symtab
14676 offset_type n_elements
;
14678 struct symtab_index_entry
**data
;
14681 /* Hash function for a symtab_index_entry. */
14683 hash_symtab_entry (const void *e
)
14685 const struct symtab_index_entry
*entry
= e
;
14686 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
14687 sizeof (offset_type
) * VEC_length (offset_type
,
14688 entry
->cu_indices
),
14692 /* Equality function for a symtab_index_entry. */
14694 eq_symtab_entry (const void *a
, const void *b
)
14696 const struct symtab_index_entry
*ea
= a
;
14697 const struct symtab_index_entry
*eb
= b
;
14698 int len
= VEC_length (offset_type
, ea
->cu_indices
);
14699 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
14701 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
14702 VEC_address (offset_type
, eb
->cu_indices
),
14703 sizeof (offset_type
) * len
);
14706 /* Destroy a symtab_index_entry. */
14708 delete_symtab_entry (void *p
)
14710 struct symtab_index_entry
*entry
= p
;
14711 VEC_free (offset_type
, entry
->cu_indices
);
14715 /* Create a hash table holding symtab_index_entry objects. */
14717 create_index_table (void)
14719 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
14720 delete_symtab_entry
, xcalloc
, xfree
);
14723 /* Create a new mapped symtab object. */
14724 static struct mapped_symtab
*
14725 create_mapped_symtab (void)
14727 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
14728 symtab
->n_elements
= 0;
14729 symtab
->size
= 1024;
14730 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14734 /* Destroy a mapped_symtab. */
14736 cleanup_mapped_symtab (void *p
)
14738 struct mapped_symtab
*symtab
= p
;
14739 /* The contents of the array are freed when the other hash table is
14741 xfree (symtab
->data
);
14745 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
14747 static struct symtab_index_entry
**
14748 find_slot (struct mapped_symtab
*symtab
, const char *name
)
14750 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
14752 index
= hash
& (symtab
->size
- 1);
14753 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
14757 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
14758 return &symtab
->data
[index
];
14759 index
= (index
+ step
) & (symtab
->size
- 1);
14763 /* Expand SYMTAB's hash table. */
14765 hash_expand (struct mapped_symtab
*symtab
)
14767 offset_type old_size
= symtab
->size
;
14769 struct symtab_index_entry
**old_entries
= symtab
->data
;
14772 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
14774 for (i
= 0; i
< old_size
; ++i
)
14776 if (old_entries
[i
])
14778 struct symtab_index_entry
**slot
= find_slot (symtab
,
14779 old_entries
[i
]->name
);
14780 *slot
= old_entries
[i
];
14784 xfree (old_entries
);
14787 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
14788 is the index of the CU in which the symbol appears. */
14790 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
14791 offset_type cu_index
)
14793 struct symtab_index_entry
**slot
;
14795 ++symtab
->n_elements
;
14796 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
14797 hash_expand (symtab
);
14799 slot
= find_slot (symtab
, name
);
14802 *slot
= XNEW (struct symtab_index_entry
);
14803 (*slot
)->name
= name
;
14804 (*slot
)->cu_indices
= NULL
;
14806 /* Don't push an index twice. Due to how we add entries we only
14807 have to check the last one. */
14808 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
14809 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
14810 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
14813 /* Add a vector of indices to the constant pool. */
14815 add_indices_to_cpool (htab_t index_table
, struct obstack
*cpool
,
14816 struct symtab_index_entry
*entry
)
14820 slot
= htab_find_slot (index_table
, entry
, INSERT
);
14823 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
14824 offset_type val
= MAYBE_SWAP (len
);
14829 entry
->index_offset
= obstack_object_size (cpool
);
14831 obstack_grow (cpool
, &val
, sizeof (val
));
14833 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
14836 val
= MAYBE_SWAP (iter
);
14837 obstack_grow (cpool
, &val
, sizeof (val
));
14842 struct symtab_index_entry
*old_entry
= *slot
;
14843 entry
->index_offset
= old_entry
->index_offset
;
14846 return entry
->index_offset
;
14849 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
14850 constant pool entries going into the obstack CPOOL. */
14852 write_hash_table (struct mapped_symtab
*symtab
,
14853 struct obstack
*output
, struct obstack
*cpool
)
14856 htab_t index_table
;
14859 index_table
= create_index_table ();
14860 str_table
= create_strtab ();
14861 /* We add all the index vectors to the constant pool first, to
14862 ensure alignment is ok. */
14863 for (i
= 0; i
< symtab
->size
; ++i
)
14865 if (symtab
->data
[i
])
14866 add_indices_to_cpool (index_table
, cpool
, symtab
->data
[i
]);
14869 /* Now write out the hash table. */
14870 for (i
= 0; i
< symtab
->size
; ++i
)
14872 offset_type str_off
, vec_off
;
14874 if (symtab
->data
[i
])
14876 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
14877 vec_off
= symtab
->data
[i
]->index_offset
;
14881 /* While 0 is a valid constant pool index, it is not valid
14882 to have 0 for both offsets. */
14887 str_off
= MAYBE_SWAP (str_off
);
14888 vec_off
= MAYBE_SWAP (vec_off
);
14890 obstack_grow (output
, &str_off
, sizeof (str_off
));
14891 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
14894 htab_delete (str_table
);
14895 htab_delete (index_table
);
14898 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
14899 from PST; CU_INDEX is the index of the CU in the vector of all
14902 add_address_entry (struct objfile
*objfile
,
14903 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
14904 unsigned int cu_index
)
14906 offset_type offset
;
14908 CORE_ADDR baseaddr
;
14910 /* Don't bother recording empty ranges. */
14911 if (pst
->textlow
== pst
->texthigh
)
14914 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
14916 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
14917 obstack_grow (addr_obstack
, addr
, 8);
14918 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
14919 obstack_grow (addr_obstack
, addr
, 8);
14920 offset
= MAYBE_SWAP (cu_index
);
14921 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
14924 /* Add a list of partial symbols to SYMTAB. */
14926 write_psymbols (struct mapped_symtab
*symtab
,
14927 struct partial_symbol
**psymp
,
14929 offset_type cu_index
)
14931 for (; count
-- > 0; ++psymp
)
14933 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
14934 error (_("Ada is not currently supported by the index"));
14935 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
14939 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
14940 exception if there is an error. */
14942 write_obstack (FILE *file
, struct obstack
*obstack
)
14944 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
14946 != obstack_object_size (obstack
))
14947 error (_("couldn't data write to file"));
14950 /* Unlink a file if the argument is not NULL. */
14952 unlink_if_set (void *p
)
14954 char **filename
= p
;
14956 unlink (*filename
);
14959 /* A helper struct used when iterating over debug_types. */
14960 struct signatured_type_index_data
14962 struct objfile
*objfile
;
14963 struct mapped_symtab
*symtab
;
14964 struct obstack
*types_list
;
14968 /* A helper function that writes a single signatured_type to an
14971 write_one_signatured_type (void **slot
, void *d
)
14973 struct signatured_type_index_data
*info
= d
;
14974 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
14975 struct dwarf2_per_cu_data
*per_cu
= &entry
->per_cu
;
14976 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
14979 write_psymbols (info
->symtab
,
14980 info
->objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
14981 psymtab
->n_global_syms
, info
->cu_index
);
14982 write_psymbols (info
->symtab
,
14983 info
->objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
14984 psymtab
->n_static_syms
, info
->cu_index
);
14986 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->offset
);
14987 obstack_grow (info
->types_list
, val
, 8);
14988 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->type_offset
);
14989 obstack_grow (info
->types_list
, val
, 8);
14990 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, entry
->signature
);
14991 obstack_grow (info
->types_list
, val
, 8);
14998 /* Create an index file for OBJFILE in the directory DIR. */
15000 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
15002 struct cleanup
*cleanup
;
15003 char *filename
, *cleanup_filename
;
15004 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
;
15005 struct obstack cu_list
, types_cu_list
;
15008 struct mapped_symtab
*symtab
;
15009 offset_type val
, size_of_contents
, total_len
;
15013 if (!objfile
->psymtabs
)
15015 if (dwarf2_per_objfile
->using_index
)
15016 error (_("Cannot use an index to create the index"));
15018 if (stat (objfile
->name
, &st
) < 0)
15019 perror_with_name (_("Could not stat"));
15021 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
15022 INDEX_SUFFIX
, (char *) NULL
);
15023 cleanup
= make_cleanup (xfree
, filename
);
15025 out_file
= fopen (filename
, "wb");
15027 error (_("Can't open `%s' for writing"), filename
);
15029 cleanup_filename
= filename
;
15030 make_cleanup (unlink_if_set
, &cleanup_filename
);
15032 symtab
= create_mapped_symtab ();
15033 make_cleanup (cleanup_mapped_symtab
, symtab
);
15035 obstack_init (&addr_obstack
);
15036 make_cleanup_obstack_free (&addr_obstack
);
15038 obstack_init (&cu_list
);
15039 make_cleanup_obstack_free (&cu_list
);
15041 obstack_init (&types_cu_list
);
15042 make_cleanup_obstack_free (&types_cu_list
);
15044 /* The list is already sorted, so we don't need to do additional
15045 work here. Also, the debug_types entries do not appear in
15046 all_comp_units, but only in their own hash table. */
15047 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
15049 struct dwarf2_per_cu_data
*per_cu
= dwarf2_per_objfile
->all_comp_units
[i
];
15050 struct partial_symtab
*psymtab
= per_cu
->v
.psymtab
;
15053 write_psymbols (symtab
,
15054 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
15055 psymtab
->n_global_syms
, i
);
15056 write_psymbols (symtab
,
15057 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
15058 psymtab
->n_static_syms
, i
);
15060 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
15062 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->offset
);
15063 obstack_grow (&cu_list
, val
, 8);
15064 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, per_cu
->length
);
15065 obstack_grow (&cu_list
, val
, 8);
15068 /* Write out the .debug_type entries, if any. */
15069 if (dwarf2_per_objfile
->signatured_types
)
15071 struct signatured_type_index_data sig_data
;
15073 sig_data
.objfile
= objfile
;
15074 sig_data
.symtab
= symtab
;
15075 sig_data
.types_list
= &types_cu_list
;
15076 sig_data
.cu_index
= dwarf2_per_objfile
->n_comp_units
;
15077 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
15078 write_one_signatured_type
, &sig_data
);
15081 obstack_init (&constant_pool
);
15082 make_cleanup_obstack_free (&constant_pool
);
15083 obstack_init (&symtab_obstack
);
15084 make_cleanup_obstack_free (&symtab_obstack
);
15085 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
15087 obstack_init (&contents
);
15088 make_cleanup_obstack_free (&contents
);
15089 size_of_contents
= 6 * sizeof (offset_type
);
15090 total_len
= size_of_contents
;
15092 /* The version number. */
15093 val
= MAYBE_SWAP (2);
15094 obstack_grow (&contents
, &val
, sizeof (val
));
15096 /* The offset of the CU list from the start of the file. */
15097 val
= MAYBE_SWAP (total_len
);
15098 obstack_grow (&contents
, &val
, sizeof (val
));
15099 total_len
+= obstack_object_size (&cu_list
);
15101 /* The offset of the types CU list from the start of the file. */
15102 val
= MAYBE_SWAP (total_len
);
15103 obstack_grow (&contents
, &val
, sizeof (val
));
15104 total_len
+= obstack_object_size (&types_cu_list
);
15106 /* The offset of the address table from the start of the file. */
15107 val
= MAYBE_SWAP (total_len
);
15108 obstack_grow (&contents
, &val
, sizeof (val
));
15109 total_len
+= obstack_object_size (&addr_obstack
);
15111 /* The offset of the symbol table from the start of the file. */
15112 val
= MAYBE_SWAP (total_len
);
15113 obstack_grow (&contents
, &val
, sizeof (val
));
15114 total_len
+= obstack_object_size (&symtab_obstack
);
15116 /* The offset of the constant pool from the start of the file. */
15117 val
= MAYBE_SWAP (total_len
);
15118 obstack_grow (&contents
, &val
, sizeof (val
));
15119 total_len
+= obstack_object_size (&constant_pool
);
15121 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
15123 write_obstack (out_file
, &contents
);
15124 write_obstack (out_file
, &cu_list
);
15125 write_obstack (out_file
, &types_cu_list
);
15126 write_obstack (out_file
, &addr_obstack
);
15127 write_obstack (out_file
, &symtab_obstack
);
15128 write_obstack (out_file
, &constant_pool
);
15132 /* We want to keep the file, so we set cleanup_filename to NULL
15133 here. See unlink_if_set. */
15134 cleanup_filename
= NULL
;
15136 do_cleanups (cleanup
);
15139 /* The mapped index file format is designed to be directly mmap()able
15140 on any architecture. In most cases, a datum is represented using a
15141 little-endian 32-bit integer value, called an offset_type. Big
15142 endian machines must byte-swap the values before using them.
15143 Exceptions to this rule are noted. The data is laid out such that
15144 alignment is always respected.
15146 A mapped index consists of several sections.
15148 1. The file header. This is a sequence of values, of offset_type
15149 unless otherwise noted:
15150 [0] The version number. Currently 1 or 2. The differences are
15151 noted below. Version 1 did not account for .debug_types sections;
15152 the presence of a .debug_types section invalidates any version 1
15153 index that may exist.
15154 [1] The offset, from the start of the file, of the CU list.
15155 [1.5] In version 2, the offset, from the start of the file, of the
15156 types CU list. This offset does not appear in version 1. Note
15157 that this can be empty, in which case this offset will be equal to
15159 [2] The offset, from the start of the file, of the address section.
15160 [3] The offset, from the start of the file, of the symbol table.
15161 [4] The offset, from the start of the file, of the constant pool.
15163 2. The CU list. This is a sequence of pairs of 64-bit
15164 little-endian values, sorted by the CU offset. The first element
15165 in each pair is the offset of a CU in the .debug_info section. The
15166 second element in each pair is the length of that CU. References
15167 to a CU elsewhere in the map are done using a CU index, which is
15168 just the 0-based index into this table. Note that if there are
15169 type CUs, then conceptually CUs and type CUs form a single list for
15170 the purposes of CU indices.
15172 2.5 The types CU list. This does not appear in a version 1 index.
15173 This is a sequence of triplets of 64-bit little-endian values. In
15174 a triplet, the first value is the CU offset, the second value is
15175 the type offset in the CU, and the third value is the type
15176 signature. The types CU list is not sorted.
15178 3. The address section. The address section consists of a sequence
15179 of address entries. Each address entry has three elements.
15180 [0] The low address. This is a 64-bit little-endian value.
15181 [1] The high address. This is a 64-bit little-endian value.
15182 [2] The CU index. This is an offset_type value.
15184 4. The symbol table. This is a hash table. The size of the hash
15185 table is always a power of 2. The initial hash and the step are
15186 currently defined by the `find_slot' function.
15188 Each slot in the hash table consists of a pair of offset_type
15189 values. The first value is the offset of the symbol's name in the
15190 constant pool. The second value is the offset of the CU vector in
15193 If both values are 0, then this slot in the hash table is empty.
15194 This is ok because while 0 is a valid constant pool index, it
15195 cannot be a valid index for both a string and a CU vector.
15197 A string in the constant pool is stored as a \0-terminated string,
15200 A CU vector in the constant pool is a sequence of offset_type
15201 values. The first value is the number of CU indices in the vector.
15202 Each subsequent value is the index of a CU in the CU list. This
15203 element in the hash table is used to indicate which CUs define the
15206 5. The constant pool. This is simply a bunch of bytes. It is
15207 organized so that alignment is correct: CU vectors are stored
15208 first, followed by strings. */
15210 save_gdb_index_command (char *arg
, int from_tty
)
15212 struct objfile
*objfile
;
15215 error (_("usage: save gdb-index DIRECTORY"));
15217 ALL_OBJFILES (objfile
)
15221 /* If the objfile does not correspond to an actual file, skip it. */
15222 if (stat (objfile
->name
, &st
) < 0)
15225 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
15226 if (dwarf2_per_objfile
)
15228 volatile struct gdb_exception except
;
15230 TRY_CATCH (except
, RETURN_MASK_ERROR
)
15232 write_psymtabs_to_index (objfile
, arg
);
15234 if (except
.reason
< 0)
15235 exception_fprintf (gdb_stderr
, except
,
15236 _("Error while writing index for `%s': "),
15244 int dwarf2_always_disassemble
;
15247 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
15248 struct cmd_list_element
*c
, const char *value
)
15250 fprintf_filtered (file
, _("\
15251 Whether to always disassemble DWARF expressions is %s.\n"),
15255 void _initialize_dwarf2_read (void);
15258 _initialize_dwarf2_read (void)
15260 struct cmd_list_element
*c
;
15262 dwarf2_objfile_data_key
15263 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
15265 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
15266 Set DWARF 2 specific variables.\n\
15267 Configure DWARF 2 variables such as the cache size"),
15268 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
15269 0/*allow-unknown*/, &maintenance_set_cmdlist
);
15271 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
15272 Show DWARF 2 specific variables\n\
15273 Show DWARF 2 variables such as the cache size"),
15274 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
15275 0/*allow-unknown*/, &maintenance_show_cmdlist
);
15277 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
15278 &dwarf2_max_cache_age
, _("\
15279 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
15280 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
15281 A higher limit means that cached compilation units will be stored\n\
15282 in memory longer, and more total memory will be used. Zero disables\n\
15283 caching, which can slow down startup."),
15285 show_dwarf2_max_cache_age
,
15286 &set_dwarf2_cmdlist
,
15287 &show_dwarf2_cmdlist
);
15289 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
15290 &dwarf2_always_disassemble
, _("\
15291 Set whether `info address' always disassembles DWARF expressions."), _("\
15292 Show whether `info address' always disassembles DWARF expressions."), _("\
15293 When enabled, DWARF expressions are always printed in an assembly-like\n\
15294 syntax. When disabled, expressions will be printed in a more\n\
15295 conversational style, when possible."),
15297 show_dwarf2_always_disassemble
,
15298 &set_dwarf2_cmdlist
,
15299 &show_dwarf2_cmdlist
);
15301 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
15302 Set debugging of the dwarf2 DIE reader."), _("\
15303 Show debugging of the dwarf2 DIE reader."), _("\
15304 When enabled (non-zero), DIEs are dumped after they are read in.\n\
15305 The value is the maximum depth to print."),
15308 &setdebuglist
, &showdebuglist
);
15310 c
= add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
15311 _("Save a .gdb-index file"),
15313 set_cmd_completer (c
, filename_completer
);