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"
58 #include "gdb_string.h"
59 #include "gdb_assert.h"
60 #include <sys/types.h>
67 #define MAP_FAILED ((void *) -1)
72 /* .debug_info header for a compilation unit
73 Because of alignment constraints, this structure has padding and cannot
74 be mapped directly onto the beginning of the .debug_info section. */
75 typedef struct comp_unit_header
77 unsigned int length
; /* length of the .debug_info
79 unsigned short version
; /* version number -- 2 for DWARF
81 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
82 unsigned char addr_size
; /* byte size of an address -- 4 */
85 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
88 /* .debug_line statement program prologue
89 Because of alignment constraints, this structure has padding and cannot
90 be mapped directly onto the beginning of the .debug_info section. */
91 typedef struct statement_prologue
93 unsigned int total_length
; /* byte length of the statement
95 unsigned short version
; /* version number -- 2 for DWARF
97 unsigned int prologue_length
; /* # bytes between prologue &
99 unsigned char minimum_instruction_length
; /* byte size of
101 unsigned char default_is_stmt
; /* initial value of is_stmt
104 unsigned char line_range
;
105 unsigned char opcode_base
; /* number assigned to first special
107 unsigned char *standard_opcode_lengths
;
111 /* When non-zero, dump DIEs after they are read in. */
112 static int dwarf2_die_debug
= 0;
116 /* When set, the file that we're processing is known to have debugging
117 info for C++ namespaces. GCC 3.3.x did not produce this information,
118 but later versions do. */
120 static int processing_has_namespace_info
;
122 static const struct objfile_data
*dwarf2_objfile_data_key
;
124 struct dwarf2_section_info
130 /* True if we have tried to read this section. */
134 /* All offsets in the index are of this type. It must be
135 architecture-independent. */
136 typedef uint32_t offset_type
;
138 DEF_VEC_I (offset_type
);
140 /* A description of the mapped index. The file format is described in
141 a comment by the code that writes the index. */
144 /* The total length of the buffer. */
146 /* A pointer to the address table data. */
147 const gdb_byte
*address_table
;
148 /* Size of the address table data in bytes. */
149 offset_type address_table_size
;
150 /* The hash table. */
151 const offset_type
*index_table
;
152 /* Size in slots, each slot is 2 offset_types. */
153 offset_type index_table_slots
;
154 /* A pointer to the constant pool. */
155 const char *constant_pool
;
158 typedef struct dwarf2_per_cu_data
*dwarf2_per_cu_data_ptr
;
159 DEF_VEC_P (dwarf2_per_cu_data_ptr
);
161 struct dwarf2_per_objfile
163 struct dwarf2_section_info info
;
164 struct dwarf2_section_info abbrev
;
165 struct dwarf2_section_info line
;
166 struct dwarf2_section_info loc
;
167 struct dwarf2_section_info macinfo
;
168 struct dwarf2_section_info str
;
169 struct dwarf2_section_info ranges
;
170 struct dwarf2_section_info types
;
171 struct dwarf2_section_info frame
;
172 struct dwarf2_section_info eh_frame
;
173 struct dwarf2_section_info gdb_index
;
176 struct objfile
*objfile
;
178 /* A list of all the compilation units. This is used to locate
179 the target compilation unit of a particular reference. */
180 struct dwarf2_per_cu_data
**all_comp_units
;
182 /* The number of compilation units in ALL_COMP_UNITS. */
185 /* A chain of compilation units that are currently read in, so that
186 they can be freed later. */
187 struct dwarf2_per_cu_data
*read_in_chain
;
189 /* A table mapping .debug_types signatures to its signatured_type entry.
190 This is NULL if the .debug_types section hasn't been read in yet. */
191 htab_t signatured_types
;
193 /* A flag indicating wether this objfile has a section loaded at a
195 int has_section_at_zero
;
197 /* True if we are using the mapped index. */
198 unsigned char using_index
;
200 /* The mapped index. */
201 struct mapped_index
*index_table
;
204 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
206 /* names of the debugging sections */
208 /* Note that if the debugging section has been compressed, it might
209 have a name like .zdebug_info. */
211 #define INFO_SECTION "debug_info"
212 #define ABBREV_SECTION "debug_abbrev"
213 #define LINE_SECTION "debug_line"
214 #define LOC_SECTION "debug_loc"
215 #define MACINFO_SECTION "debug_macinfo"
216 #define STR_SECTION "debug_str"
217 #define RANGES_SECTION "debug_ranges"
218 #define TYPES_SECTION "debug_types"
219 #define FRAME_SECTION "debug_frame"
220 #define EH_FRAME_SECTION "eh_frame"
221 #define GDB_INDEX_SECTION "gdb_index"
223 /* local data types */
225 /* We hold several abbreviation tables in memory at the same time. */
226 #ifndef ABBREV_HASH_SIZE
227 #define ABBREV_HASH_SIZE 121
230 /* The data in a compilation unit header, after target2host
231 translation, looks like this. */
232 struct comp_unit_head
236 unsigned char addr_size
;
237 unsigned char signed_addr_p
;
238 unsigned int abbrev_offset
;
240 /* Size of file offsets; either 4 or 8. */
241 unsigned int offset_size
;
243 /* Size of the length field; either 4 or 12. */
244 unsigned int initial_length_size
;
246 /* Offset to the first byte of this compilation unit header in the
247 .debug_info section, for resolving relative reference dies. */
250 /* Offset to first die in this cu from the start of the cu.
251 This will be the first byte following the compilation unit header. */
252 unsigned int first_die_offset
;
255 /* Internal state when decoding a particular compilation unit. */
258 /* The objfile containing this compilation unit. */
259 struct objfile
*objfile
;
261 /* The header of the compilation unit. */
262 struct comp_unit_head header
;
264 /* Base address of this compilation unit. */
265 CORE_ADDR base_address
;
267 /* Non-zero if base_address has been set. */
270 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
272 /* The language we are debugging. */
273 enum language language
;
274 const struct language_defn
*language_defn
;
276 const char *producer
;
278 /* The generic symbol table building routines have separate lists for
279 file scope symbols and all all other scopes (local scopes). So
280 we need to select the right one to pass to add_symbol_to_list().
281 We do it by keeping a pointer to the correct list in list_in_scope.
283 FIXME: The original dwarf code just treated the file scope as the
284 first local scope, and all other local scopes as nested local
285 scopes, and worked fine. Check to see if we really need to
286 distinguish these in buildsym.c. */
287 struct pending
**list_in_scope
;
289 /* DWARF abbreviation table associated with this compilation unit. */
290 struct abbrev_info
**dwarf2_abbrevs
;
292 /* Storage for the abbrev table. */
293 struct obstack abbrev_obstack
;
295 /* Hash table holding all the loaded partial DIEs. */
298 /* Storage for things with the same lifetime as this read-in compilation
299 unit, including partial DIEs. */
300 struct obstack comp_unit_obstack
;
302 /* When multiple dwarf2_cu structures are living in memory, this field
303 chains them all together, so that they can be released efficiently.
304 We will probably also want a generation counter so that most-recently-used
305 compilation units are cached... */
306 struct dwarf2_per_cu_data
*read_in_chain
;
308 /* Backchain to our per_cu entry if the tree has been built. */
309 struct dwarf2_per_cu_data
*per_cu
;
311 /* Pointer to the die -> type map. Although it is stored
312 permanently in per_cu, we copy it here to avoid double
316 /* How many compilation units ago was this CU last referenced? */
319 /* A hash table of die offsets for following references. */
322 /* Full DIEs if read in. */
323 struct die_info
*dies
;
325 /* A set of pointers to dwarf2_per_cu_data objects for compilation
326 units referenced by this one. Only set during full symbol processing;
327 partial symbol tables do not have dependencies. */
330 /* Header data from the line table, during full symbol processing. */
331 struct line_header
*line_header
;
333 /* Mark used when releasing cached dies. */
334 unsigned int mark
: 1;
336 /* This flag will be set if this compilation unit might include
337 inter-compilation-unit references. */
338 unsigned int has_form_ref_addr
: 1;
340 /* This flag will be set if this compilation unit includes any
341 DW_TAG_namespace DIEs. If we know that there are explicit
342 DIEs for namespaces, we don't need to try to infer them
343 from mangled names. */
344 unsigned int has_namespace_info
: 1;
347 /* When using the index (and thus not using psymtabs), each CU has an
348 object of this type. This is used to hold information needed by
349 the various "quick" methods. */
350 struct dwarf2_per_cu_quick_data
352 /* The line table. This can be NULL if there was no line table. */
353 struct line_header
*lines
;
355 /* The file names from the line table. */
356 const char **file_names
;
357 /* The file names from the line table after being run through
359 const char **full_names
;
361 /* The corresponding symbol table. This is NULL if symbols for this
362 CU have not yet been read. */
363 struct symtab
*symtab
;
365 /* A temporary mark bit used when iterating over all CUs in
366 expand_symtabs_matching. */
367 unsigned int mark
: 1;
369 /* True if we've tried to read the line table. */
370 unsigned int read_lines
: 1;
373 /* Persistent data held for a compilation unit, even when not
374 processing it. We put a pointer to this structure in the
375 read_symtab_private field of the psymtab. If we encounter
376 inter-compilation-unit references, we also maintain a sorted
377 list of all compilation units. */
379 struct dwarf2_per_cu_data
381 /* The start offset and length of this compilation unit. 2**29-1
382 bytes should suffice to store the length of any compilation unit
383 - if it doesn't, GDB will fall over anyway.
384 NOTE: Unlike comp_unit_head.length, this length includes
385 initial_length_size. */
387 unsigned int length
: 29;
389 /* Flag indicating this compilation unit will be read in before
390 any of the current compilation units are processed. */
391 unsigned int queued
: 1;
393 /* This flag will be set if we need to load absolutely all DIEs
394 for this compilation unit, instead of just the ones we think
395 are interesting. It gets set if we look for a DIE in the
396 hash table and don't find it. */
397 unsigned int load_all_dies
: 1;
399 /* Non-zero if this CU is from .debug_types.
400 Otherwise it's from .debug_info. */
401 unsigned int from_debug_types
: 1;
403 /* Set to non-NULL iff this CU is currently loaded. When it gets freed out
404 of the CU cache it gets reset to NULL again. */
405 struct dwarf2_cu
*cu
;
407 /* If full symbols for this CU have been read in, then this field
408 holds a map of DIE offsets to types. It isn't always possible
409 to reconstruct this information later, so we have to preserve
413 /* The corresponding objfile. */
414 struct objfile
*objfile
;
416 /* When using partial symbol tables, the 'psymtab' field is active.
417 Otherwise the 'quick' field is active. */
420 /* The partial symbol table associated with this compilation unit,
421 or NULL for partial units (which do not have an associated
423 struct partial_symtab
*psymtab
;
425 /* Data needed by the "quick" functions. */
426 struct dwarf2_per_cu_quick_data
*quick
;
430 /* Entry in the signatured_types hash table. */
432 struct signatured_type
436 /* Offset in .debug_types of the TU (type_unit) for this type. */
439 /* Offset in .debug_types of the type defined by this TU. */
440 unsigned int type_offset
;
442 /* The CU(/TU) of this type. */
443 struct dwarf2_per_cu_data per_cu
;
446 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
447 which are used for both .debug_info and .debug_types dies.
448 All parameters here are unchanging for the life of the call.
449 This struct exists to abstract away the constant parameters of
452 struct die_reader_specs
454 /* The bfd of this objfile. */
457 /* The CU of the DIE we are parsing. */
458 struct dwarf2_cu
*cu
;
460 /* Pointer to start of section buffer.
461 This is either the start of .debug_info or .debug_types. */
462 const gdb_byte
*buffer
;
465 /* The line number information for a compilation unit (found in the
466 .debug_line section) begins with a "statement program header",
467 which contains the following information. */
470 unsigned int total_length
;
471 unsigned short version
;
472 unsigned int header_length
;
473 unsigned char minimum_instruction_length
;
474 unsigned char maximum_ops_per_instruction
;
475 unsigned char default_is_stmt
;
477 unsigned char line_range
;
478 unsigned char opcode_base
;
480 /* standard_opcode_lengths[i] is the number of operands for the
481 standard opcode whose value is i. This means that
482 standard_opcode_lengths[0] is unused, and the last meaningful
483 element is standard_opcode_lengths[opcode_base - 1]. */
484 unsigned char *standard_opcode_lengths
;
486 /* The include_directories table. NOTE! These strings are not
487 allocated with xmalloc; instead, they are pointers into
488 debug_line_buffer. If you try to free them, `free' will get
490 unsigned int num_include_dirs
, include_dirs_size
;
493 /* The file_names table. NOTE! These strings are not allocated
494 with xmalloc; instead, they are pointers into debug_line_buffer.
495 Don't try to free them directly. */
496 unsigned int num_file_names
, file_names_size
;
500 unsigned int dir_index
;
501 unsigned int mod_time
;
503 int included_p
; /* Non-zero if referenced by the Line Number Program. */
504 struct symtab
*symtab
; /* The associated symbol table, if any. */
507 /* The start and end of the statement program following this
508 header. These point into dwarf2_per_objfile->line_buffer. */
509 gdb_byte
*statement_program_start
, *statement_program_end
;
512 /* When we construct a partial symbol table entry we only
513 need this much information. */
514 struct partial_die_info
516 /* Offset of this DIE. */
519 /* DWARF-2 tag for this DIE. */
520 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
522 /* Assorted flags describing the data found in this DIE. */
523 unsigned int has_children
: 1;
524 unsigned int is_external
: 1;
525 unsigned int is_declaration
: 1;
526 unsigned int has_type
: 1;
527 unsigned int has_specification
: 1;
528 unsigned int has_pc_info
: 1;
530 /* Flag set if the SCOPE field of this structure has been
532 unsigned int scope_set
: 1;
534 /* Flag set if the DIE has a byte_size attribute. */
535 unsigned int has_byte_size
: 1;
537 /* The name of this DIE. Normally the value of DW_AT_name, but
538 sometimes a default name for unnamed DIEs. */
541 /* The scope to prepend to our children. This is generally
542 allocated on the comp_unit_obstack, so will disappear
543 when this compilation unit leaves the cache. */
546 /* The location description associated with this DIE, if any. */
547 struct dwarf_block
*locdesc
;
549 /* If HAS_PC_INFO, the PC range associated with this DIE. */
553 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
554 DW_AT_sibling, if any. */
557 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
558 DW_AT_specification (or DW_AT_abstract_origin or
560 unsigned int spec_offset
;
562 /* Pointers to this DIE's parent, first child, and next sibling,
564 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
567 /* This data structure holds the information of an abbrev. */
570 unsigned int number
; /* number identifying abbrev */
571 enum dwarf_tag tag
; /* dwarf tag */
572 unsigned short has_children
; /* boolean */
573 unsigned short num_attrs
; /* number of attributes */
574 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
575 struct abbrev_info
*next
; /* next in chain */
580 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
581 ENUM_BITFIELD(dwarf_form
) form
: 16;
584 /* Attributes have a name and a value */
587 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
588 ENUM_BITFIELD(dwarf_form
) form
: 15;
590 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
591 field should be in u.str (existing only for DW_STRING) but it is kept
592 here for better struct attribute alignment. */
593 unsigned int string_is_canonical
: 1;
598 struct dwarf_block
*blk
;
602 struct signatured_type
*signatured_type
;
607 /* This data structure holds a complete die structure. */
610 /* DWARF-2 tag for this DIE. */
611 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
613 /* Number of attributes */
614 unsigned short num_attrs
;
619 /* Offset in .debug_info or .debug_types section. */
622 /* The dies in a compilation unit form an n-ary tree. PARENT
623 points to this die's parent; CHILD points to the first child of
624 this node; and all the children of a given node are chained
625 together via their SIBLING fields, terminated by a die whose
627 struct die_info
*child
; /* Its first child, if any. */
628 struct die_info
*sibling
; /* Its next sibling, if any. */
629 struct die_info
*parent
; /* Its parent, if any. */
631 /* An array of attributes, with NUM_ATTRS elements. There may be
632 zero, but it's not common and zero-sized arrays are not
633 sufficiently portable C. */
634 struct attribute attrs
[1];
637 struct function_range
640 CORE_ADDR lowpc
, highpc
;
642 struct function_range
*next
;
645 /* Get at parts of an attribute structure */
647 #define DW_STRING(attr) ((attr)->u.str)
648 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
649 #define DW_UNSND(attr) ((attr)->u.unsnd)
650 #define DW_BLOCK(attr) ((attr)->u.blk)
651 #define DW_SND(attr) ((attr)->u.snd)
652 #define DW_ADDR(attr) ((attr)->u.addr)
653 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
655 /* Blocks are a bunch of untyped bytes. */
662 #ifndef ATTR_ALLOC_CHUNK
663 #define ATTR_ALLOC_CHUNK 4
666 /* Allocate fields for structs, unions and enums in this size. */
667 #ifndef DW_FIELD_ALLOC_CHUNK
668 #define DW_FIELD_ALLOC_CHUNK 4
671 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
672 but this would require a corresponding change in unpack_field_as_long
674 static int bits_per_byte
= 8;
676 /* The routines that read and process dies for a C struct or C++ class
677 pass lists of data member fields and lists of member function fields
678 in an instance of a field_info structure, as defined below. */
681 /* List of data member and baseclasses fields. */
684 struct nextfield
*next
;
689 *fields
, *baseclasses
;
691 /* Number of fields (including baseclasses). */
694 /* Number of baseclasses. */
697 /* Set if the accesibility of one of the fields is not public. */
698 int non_public_fields
;
700 /* Member function fields array, entries are allocated in the order they
701 are encountered in the object file. */
704 struct nextfnfield
*next
;
705 struct fn_field fnfield
;
709 /* Member function fieldlist array, contains name of possibly overloaded
710 member function, number of overloaded member functions and a pointer
711 to the head of the member function field chain. */
716 struct nextfnfield
*head
;
720 /* Number of entries in the fnfieldlists array. */
723 /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of
724 a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */
725 struct typedef_field_list
727 struct typedef_field field
;
728 struct typedef_field_list
*next
;
731 unsigned typedef_field_list_count
;
734 /* One item on the queue of compilation units to read in full symbols
736 struct dwarf2_queue_item
738 struct dwarf2_per_cu_data
*per_cu
;
739 struct dwarf2_queue_item
*next
;
742 /* The current queue. */
743 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
745 /* Loaded secondary compilation units are kept in memory until they
746 have not been referenced for the processing of this many
747 compilation units. Set this to zero to disable caching. Cache
748 sizes of up to at least twenty will improve startup time for
749 typical inter-CU-reference binaries, at an obvious memory cost. */
750 static int dwarf2_max_cache_age
= 5;
752 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
753 struct cmd_list_element
*c
, const char *value
)
755 fprintf_filtered (file
, _("\
756 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
761 /* Various complaints about symbol reading that don't abort the process */
764 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
766 complaint (&symfile_complaints
,
767 _("statement list doesn't fit in .debug_line section"));
771 dwarf2_debug_line_missing_file_complaint (void)
773 complaint (&symfile_complaints
,
774 _(".debug_line section has line data without a file"));
778 dwarf2_debug_line_missing_end_sequence_complaint (void)
780 complaint (&symfile_complaints
,
781 _(".debug_line section has line program sequence without an end"));
785 dwarf2_complex_location_expr_complaint (void)
787 complaint (&symfile_complaints
, _("location expression too complex"));
791 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
794 complaint (&symfile_complaints
,
795 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
800 dwarf2_macros_too_long_complaint (void)
802 complaint (&symfile_complaints
,
803 _("macro info runs off end of `.debug_macinfo' section"));
807 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
809 complaint (&symfile_complaints
,
810 _("macro debug info contains a malformed macro definition:\n`%s'"),
815 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
817 complaint (&symfile_complaints
,
818 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
821 /* local function prototypes */
823 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
825 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
828 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
830 struct partial_symtab
*);
832 static void dwarf2_build_psymtabs_hard (struct objfile
*);
834 static void scan_partial_symbols (struct partial_die_info
*,
835 CORE_ADDR
*, CORE_ADDR
*,
836 int, struct dwarf2_cu
*);
838 static void add_partial_symbol (struct partial_die_info
*,
841 static void add_partial_namespace (struct partial_die_info
*pdi
,
842 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
843 int need_pc
, struct dwarf2_cu
*cu
);
845 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
846 CORE_ADDR
*highpc
, int need_pc
,
847 struct dwarf2_cu
*cu
);
849 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
850 struct dwarf2_cu
*cu
);
852 static void add_partial_subprogram (struct partial_die_info
*pdi
,
853 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
854 int need_pc
, struct dwarf2_cu
*cu
);
856 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
857 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
858 bfd
*abfd
, struct dwarf2_cu
*cu
);
860 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
862 static void psymtab_to_symtab_1 (struct partial_symtab
*);
864 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
866 static void dwarf2_free_abbrev_table (void *);
868 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
871 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
874 static struct partial_die_info
*load_partial_dies (bfd
*,
875 gdb_byte
*, gdb_byte
*,
876 int, struct dwarf2_cu
*);
878 static gdb_byte
*read_partial_die (struct partial_die_info
*,
879 struct abbrev_info
*abbrev
,
881 gdb_byte
*, gdb_byte
*,
884 static struct partial_die_info
*find_partial_die (unsigned int,
887 static void fixup_partial_die (struct partial_die_info
*,
890 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
891 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
893 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
894 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
896 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
898 static int read_1_signed_byte (bfd
*, gdb_byte
*);
900 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
902 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
904 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
906 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
909 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
911 static LONGEST read_checked_initial_length_and_offset
912 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
913 unsigned int *, unsigned int *);
915 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
918 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
920 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
922 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
924 static char *read_indirect_string (bfd
*, gdb_byte
*,
925 const struct comp_unit_head
*,
928 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
930 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
932 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
934 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
936 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
939 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
943 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
944 struct dwarf2_cu
*cu
);
946 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
948 static struct die_info
*die_specification (struct die_info
*die
,
949 struct dwarf2_cu
**);
951 static void free_line_header (struct line_header
*lh
);
953 static void add_file_name (struct line_header
*, char *, unsigned int,
954 unsigned int, unsigned int);
956 static struct line_header
*(dwarf_decode_line_header
957 (unsigned int offset
,
958 bfd
*abfd
, struct dwarf2_cu
*cu
));
960 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
961 struct dwarf2_cu
*, struct partial_symtab
*);
963 static void dwarf2_start_subfile (char *, char *, char *);
965 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
968 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
971 static void dwarf2_const_value_data (struct attribute
*attr
,
975 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
977 static int need_gnat_info (struct dwarf2_cu
*);
979 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
981 static void set_descriptive_type (struct type
*, struct die_info
*,
984 static struct type
*die_containing_type (struct die_info
*,
987 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
989 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
991 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
993 static char *typename_concat (struct obstack
*obs
, const char *prefix
,
994 const char *suffix
, int physname
,
995 struct dwarf2_cu
*cu
);
997 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
999 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
1001 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
1003 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
1005 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
1006 struct dwarf2_cu
*, struct partial_symtab
*);
1008 static int dwarf2_get_pc_bounds (struct die_info
*,
1009 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
1010 struct partial_symtab
*);
1012 static void get_scope_pc_bounds (struct die_info
*,
1013 CORE_ADDR
*, CORE_ADDR
*,
1014 struct dwarf2_cu
*);
1016 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
1017 CORE_ADDR
, struct dwarf2_cu
*);
1019 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
1020 struct dwarf2_cu
*);
1022 static void dwarf2_attach_fields_to_type (struct field_info
*,
1023 struct type
*, struct dwarf2_cu
*);
1025 static void dwarf2_add_member_fn (struct field_info
*,
1026 struct die_info
*, struct type
*,
1027 struct dwarf2_cu
*);
1029 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
1030 struct type
*, struct dwarf2_cu
*);
1032 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
1034 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
1036 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
1038 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
1040 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1042 static struct type
*read_module_type (struct die_info
*die
,
1043 struct dwarf2_cu
*cu
);
1045 static const char *namespace_name (struct die_info
*die
,
1046 int *is_anonymous
, struct dwarf2_cu
*);
1048 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1050 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1052 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1053 struct dwarf2_cu
*);
1055 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1057 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1059 gdb_byte
**new_info_ptr
,
1060 struct die_info
*parent
);
1062 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1064 gdb_byte
**new_info_ptr
,
1065 struct die_info
*parent
);
1067 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1069 gdb_byte
**new_info_ptr
,
1070 struct die_info
*parent
);
1072 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1073 struct die_info
**, gdb_byte
*,
1076 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1078 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1081 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1083 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1084 struct dwarf2_cu
**);
1086 static char *dwarf_tag_name (unsigned int);
1088 static char *dwarf_attr_name (unsigned int);
1090 static char *dwarf_form_name (unsigned int);
1092 static char *dwarf_bool_name (unsigned int);
1094 static char *dwarf_type_encoding_name (unsigned int);
1097 static char *dwarf_cfi_name (unsigned int);
1100 static struct die_info
*sibling_die (struct die_info
*);
1102 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1104 static void dump_die_for_error (struct die_info
*);
1106 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1109 /*static*/ void dump_die (struct die_info
*, int max_level
);
1111 static void store_in_ref_table (struct die_info
*,
1112 struct dwarf2_cu
*);
1114 static int is_ref_attr (struct attribute
*);
1116 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1118 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1120 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1122 struct dwarf2_cu
**);
1124 static struct die_info
*follow_die_ref (struct die_info
*,
1126 struct dwarf2_cu
**);
1128 static struct die_info
*follow_die_sig (struct die_info
*,
1130 struct dwarf2_cu
**);
1132 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1133 unsigned int offset
);
1135 static void read_signatured_type (struct objfile
*,
1136 struct signatured_type
*type_sig
);
1138 /* memory allocation interface */
1140 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1142 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1144 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1146 static void initialize_cu_func_list (struct dwarf2_cu
*);
1148 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1149 struct dwarf2_cu
*);
1151 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1152 char *, bfd
*, struct dwarf2_cu
*);
1154 static int attr_form_is_block (struct attribute
*);
1156 static int attr_form_is_section_offset (struct attribute
*);
1158 static int attr_form_is_constant (struct attribute
*);
1160 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1162 struct dwarf2_cu
*cu
);
1164 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1165 struct abbrev_info
*abbrev
,
1166 struct dwarf2_cu
*cu
);
1168 static void free_stack_comp_unit (void *);
1170 static hashval_t
partial_die_hash (const void *item
);
1172 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1174 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1175 (unsigned int offset
, struct objfile
*objfile
);
1177 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1178 (unsigned int offset
, struct objfile
*objfile
);
1180 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1182 static void free_one_comp_unit (void *);
1184 static void free_cached_comp_units (void *);
1186 static void age_cached_comp_units (void);
1188 static void free_one_cached_comp_unit (void *);
1190 static struct type
*set_die_type (struct die_info
*, struct type
*,
1191 struct dwarf2_cu
*);
1193 static void create_all_comp_units (struct objfile
*);
1195 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1198 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1200 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1201 struct dwarf2_per_cu_data
*);
1203 static void dwarf2_mark (struct dwarf2_cu
*);
1205 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1207 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1209 static void dwarf2_release_queue (void *dummy
);
1211 static void queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
,
1212 struct objfile
*objfile
);
1214 static void process_queue (struct objfile
*objfile
);
1216 static void find_file_and_directory (struct die_info
*die
,
1217 struct dwarf2_cu
*cu
,
1218 char **name
, char **comp_dir
);
1220 static char *file_full_name (int file
, struct line_header
*lh
,
1221 const char *comp_dir
);
1223 static gdb_byte
*partial_read_comp_unit_head (struct comp_unit_head
*header
,
1226 unsigned int buffer_size
,
1229 static void init_cu_die_reader (struct die_reader_specs
*reader
,
1230 struct dwarf2_cu
*cu
);
1234 /* Convert VALUE between big- and little-endian. */
1236 byte_swap (offset_type value
)
1240 result
= (value
& 0xff) << 24;
1241 result
|= (value
& 0xff00) << 8;
1242 result
|= (value
& 0xff0000) >> 8;
1243 result
|= (value
& 0xff000000) >> 24;
1247 #define MAYBE_SWAP(V) byte_swap (V)
1250 #define MAYBE_SWAP(V) (V)
1251 #endif /* WORDS_BIGENDIAN */
1253 /* The suffix for an index file. */
1254 #define INDEX_SUFFIX ".gdb-index"
1256 /* Try to locate the sections we need for DWARF 2 debugging
1257 information and return true if we have enough to do something. */
1260 dwarf2_has_info (struct objfile
*objfile
)
1262 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1263 if (!dwarf2_per_objfile
)
1265 /* Initialize per-objfile state. */
1266 struct dwarf2_per_objfile
*data
1267 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1269 memset (data
, 0, sizeof (*data
));
1270 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1271 dwarf2_per_objfile
= data
;
1273 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1274 dwarf2_per_objfile
->objfile
= objfile
;
1276 return (dwarf2_per_objfile
->info
.asection
!= NULL
1277 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1280 /* When loading sections, we can either look for ".<name>", or for
1281 * ".z<name>", which indicates a compressed section. */
1284 section_is_p (const char *section_name
, const char *name
)
1286 return (section_name
[0] == '.'
1287 && (strcmp (section_name
+ 1, name
) == 0
1288 || (section_name
[1] == 'z'
1289 && strcmp (section_name
+ 2, name
) == 0)));
1292 /* This function is mapped across the sections and remembers the
1293 offset and size of each of the debugging sections we are interested
1297 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1299 if (section_is_p (sectp
->name
, INFO_SECTION
))
1301 dwarf2_per_objfile
->info
.asection
= sectp
;
1302 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1304 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1306 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1307 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1309 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1311 dwarf2_per_objfile
->line
.asection
= sectp
;
1312 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1314 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1316 dwarf2_per_objfile
->loc
.asection
= sectp
;
1317 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1319 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1321 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1322 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1324 else if (section_is_p (sectp
->name
, STR_SECTION
))
1326 dwarf2_per_objfile
->str
.asection
= sectp
;
1327 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1329 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1331 dwarf2_per_objfile
->frame
.asection
= sectp
;
1332 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1334 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1336 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1338 if (aflag
& SEC_HAS_CONTENTS
)
1340 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1341 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1344 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1346 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1347 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1349 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1351 dwarf2_per_objfile
->types
.asection
= sectp
;
1352 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1354 else if (section_is_p (sectp
->name
, GDB_INDEX_SECTION
))
1356 dwarf2_per_objfile
->gdb_index
.asection
= sectp
;
1357 dwarf2_per_objfile
->gdb_index
.size
= bfd_get_section_size (sectp
);
1360 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1361 && bfd_section_vma (abfd
, sectp
) == 0)
1362 dwarf2_per_objfile
->has_section_at_zero
= 1;
1365 /* Decompress a section that was compressed using zlib. Store the
1366 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1369 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1370 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1372 bfd
*abfd
= objfile
->obfd
;
1374 error (_("Support for zlib-compressed DWARF data (from '%s') "
1375 "is disabled in this copy of GDB"),
1376 bfd_get_filename (abfd
));
1378 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1379 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1380 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1381 bfd_size_type uncompressed_size
;
1382 gdb_byte
*uncompressed_buffer
;
1385 int header_size
= 12;
1387 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1388 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1389 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1390 bfd_get_filename (abfd
));
1392 /* Read the zlib header. In this case, it should be "ZLIB" followed
1393 by the uncompressed section size, 8 bytes in big-endian order. */
1394 if (compressed_size
< header_size
1395 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1396 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1397 bfd_get_filename (abfd
));
1398 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1399 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1400 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1401 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1402 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1403 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1404 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1405 uncompressed_size
+= compressed_buffer
[11];
1407 /* It is possible the section consists of several compressed
1408 buffers concatenated together, so we uncompress in a loop. */
1412 strm
.avail_in
= compressed_size
- header_size
;
1413 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1414 strm
.avail_out
= uncompressed_size
;
1415 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1417 rc
= inflateInit (&strm
);
1418 while (strm
.avail_in
> 0)
1421 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1422 bfd_get_filename (abfd
), rc
);
1423 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1424 + (uncompressed_size
- strm
.avail_out
));
1425 rc
= inflate (&strm
, Z_FINISH
);
1426 if (rc
!= Z_STREAM_END
)
1427 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1428 bfd_get_filename (abfd
), rc
);
1429 rc
= inflateReset (&strm
);
1431 rc
= inflateEnd (&strm
);
1433 || strm
.avail_out
!= 0)
1434 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1435 bfd_get_filename (abfd
), rc
);
1437 do_cleanups (cleanup
);
1438 *outbuf
= uncompressed_buffer
;
1439 *outsize
= uncompressed_size
;
1443 /* Read the contents of the section SECTP from object file specified by
1444 OBJFILE, store info about the section into INFO.
1445 If the section is compressed, uncompress it before returning. */
1448 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1450 bfd
*abfd
= objfile
->obfd
;
1451 asection
*sectp
= info
->asection
;
1452 gdb_byte
*buf
, *retbuf
;
1453 unsigned char header
[4];
1457 info
->buffer
= NULL
;
1458 info
->was_mmapped
= 0;
1461 if (info
->asection
== NULL
|| info
->size
== 0)
1464 /* Check if the file has a 4-byte header indicating compression. */
1465 if (info
->size
> sizeof (header
)
1466 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1467 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1469 /* Upon decompression, update the buffer and its size. */
1470 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1472 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1480 pagesize
= getpagesize ();
1482 /* Only try to mmap sections which are large enough: we don't want to
1483 waste space due to fragmentation. Also, only try mmap for sections
1484 without relocations. */
1486 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1488 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1489 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1490 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1491 MAP_PRIVATE
, pg_offset
);
1493 if (retbuf
!= MAP_FAILED
)
1495 info
->was_mmapped
= 1;
1496 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1497 #if HAVE_POSIX_MADVISE
1498 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1505 /* If we get here, we are a normal, not-compressed section. */
1507 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1509 /* When debugging .o files, we may need to apply relocations; see
1510 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1511 We never compress sections in .o files, so we only need to
1512 try this when the section is not compressed. */
1513 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1516 info
->buffer
= retbuf
;
1520 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1521 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1522 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1523 bfd_get_filename (abfd
));
1526 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1530 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1531 asection
**sectp
, gdb_byte
**bufp
,
1532 bfd_size_type
*sizep
)
1534 struct dwarf2_per_objfile
*data
1535 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1536 struct dwarf2_section_info
*info
;
1538 /* We may see an objfile without any DWARF, in which case we just
1547 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1548 info
= &data
->eh_frame
;
1549 else if (section_is_p (section_name
, FRAME_SECTION
))
1550 info
= &data
->frame
;
1554 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1555 /* We haven't read this section in yet. Do it now. */
1556 dwarf2_read_section (objfile
, info
);
1558 *sectp
= info
->asection
;
1559 *bufp
= info
->buffer
;
1560 *sizep
= info
->size
;
1565 /* Read in the symbols for PER_CU. OBJFILE is the objfile from which
1568 dw2_do_instantiate_symtab (struct objfile
*objfile
,
1569 struct dwarf2_per_cu_data
*per_cu
)
1571 struct cleanup
*back_to
;
1573 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
1575 queue_comp_unit (per_cu
, objfile
);
1577 if (per_cu
->from_debug_types
)
1578 read_signatured_type_at_offset (objfile
, per_cu
->offset
);
1580 load_full_comp_unit (per_cu
, objfile
);
1582 process_queue (objfile
);
1584 /* Age the cache, releasing compilation units that have not
1585 been used recently. */
1586 age_cached_comp_units ();
1588 do_cleanups (back_to
);
1591 /* Ensure that the symbols for PER_CU have been read in. OBJFILE is
1592 the objfile from which this CU came. Returns the resulting symbol
1594 static struct symtab
*
1595 dw2_instantiate_symtab (struct objfile
*objfile
,
1596 struct dwarf2_per_cu_data
*per_cu
)
1598 if (!per_cu
->v
.quick
->symtab
)
1600 struct cleanup
*back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1601 increment_reading_symtab ();
1602 dw2_do_instantiate_symtab (objfile
, per_cu
);
1603 do_cleanups (back_to
);
1605 return per_cu
->v
.quick
->symtab
;
1608 /* A helper function that knows how to read a 64-bit value in a way
1609 that doesn't make gdb die. Returns 1 if the conversion went ok, 0
1612 extract_cu_value (const char *bytes
, ULONGEST
*result
)
1614 if (sizeof (ULONGEST
) < 8)
1618 /* Ignore the upper 4 bytes if they are all zero. */
1619 for (i
= 0; i
< 4; ++i
)
1620 if (bytes
[i
+ 4] != 0)
1623 *result
= extract_unsigned_integer (bytes
, 4, BFD_ENDIAN_LITTLE
);
1626 *result
= extract_unsigned_integer (bytes
, 8, BFD_ENDIAN_LITTLE
);
1630 /* Read the CU list from the mapped index, and use it to create all
1631 the CU objects for this objfile. Return 0 if something went wrong,
1632 1 if everything went ok. */
1634 create_cus_from_index (struct objfile
*objfile
, struct mapped_index
*index
,
1635 const gdb_byte
*cu_list
, offset_type cu_list_elements
)
1640 dwarf2_per_objfile
->n_comp_units
= cu_list_elements
/ 2;
1641 dwarf2_per_objfile
->all_comp_units
1642 = obstack_alloc (&objfile
->objfile_obstack
,
1643 dwarf2_per_objfile
->n_comp_units
1644 * sizeof (struct dwarf2_per_cu_data
*));
1646 for (i
= 0; i
< cu_list_elements
; i
+= 2)
1648 struct dwarf2_per_cu_data
*the_cu
;
1649 ULONGEST offset
, length
;
1651 if (!extract_cu_value (cu_list
, &offset
)
1652 || !extract_cu_value (cu_list
+ 8, &length
))
1656 the_cu
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1657 struct dwarf2_per_cu_data
);
1658 the_cu
->offset
= offset
;
1659 the_cu
->length
= length
;
1660 the_cu
->objfile
= objfile
;
1661 the_cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
1662 struct dwarf2_per_cu_quick_data
);
1663 dwarf2_per_objfile
->all_comp_units
[i
/ 2] = the_cu
;
1669 /* Read the address map data from the mapped index, and use it to
1670 populate the objfile's psymtabs_addrmap. */
1672 create_addrmap_from_index (struct objfile
*objfile
, struct mapped_index
*index
)
1674 const gdb_byte
*iter
, *end
;
1675 struct obstack temp_obstack
;
1676 struct addrmap
*mutable_map
;
1677 struct cleanup
*cleanup
;
1680 obstack_init (&temp_obstack
);
1681 cleanup
= make_cleanup_obstack_free (&temp_obstack
);
1682 mutable_map
= addrmap_create_mutable (&temp_obstack
);
1684 iter
= index
->address_table
;
1685 end
= iter
+ index
->address_table_size
;
1687 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1691 ULONGEST hi
, lo
, cu_index
;
1692 lo
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1694 hi
= extract_unsigned_integer (iter
, 8, BFD_ENDIAN_LITTLE
);
1696 cu_index
= extract_unsigned_integer (iter
, 4, BFD_ENDIAN_LITTLE
);
1699 addrmap_set_empty (mutable_map
, lo
+ baseaddr
, hi
+ baseaddr
- 1,
1700 dwarf2_per_objfile
->all_comp_units
[cu_index
]);
1703 objfile
->psymtabs_addrmap
= addrmap_create_fixed (mutable_map
,
1704 &objfile
->objfile_obstack
);
1705 do_cleanups (cleanup
);
1708 /* The hash function for strings in the mapped index. This is the
1709 same as the hashtab.c hash function, but we keep a separate copy to
1710 maintain control over the implementation. This is necessary
1711 because the hash function is tied to the format of the mapped index
1714 mapped_index_string_hash (const void *p
)
1716 const unsigned char *str
= (const unsigned char *) p
;
1720 while ((c
= *str
++) != 0)
1721 r
= r
* 67 + c
- 113;
1726 /* Find a slot in the mapped index INDEX for the object named NAME.
1727 If NAME is found, set *VEC_OUT to point to the CU vector in the
1728 constant pool and return 1. If NAME cannot be found, return 0. */
1730 find_slot_in_mapped_hash (struct mapped_index
*index
, const char *name
,
1731 offset_type
**vec_out
)
1733 offset_type hash
= mapped_index_string_hash (name
);
1734 offset_type slot
, step
;
1736 slot
= hash
& (index
->index_table_slots
- 1);
1737 step
= ((hash
* 17) & (index
->index_table_slots
- 1)) | 1;
1741 /* Convert a slot number to an offset into the table. */
1742 offset_type i
= 2 * slot
;
1744 if (index
->index_table
[i
] == 0 && index
->index_table
[i
+ 1] == 0)
1747 str
= index
->constant_pool
+ MAYBE_SWAP (index
->index_table
[i
]);
1748 if (!strcmp (name
, str
))
1750 *vec_out
= (offset_type
*) (index
->constant_pool
1751 + MAYBE_SWAP (index
->index_table
[i
+ 1]));
1755 slot
= (slot
+ step
) & (index
->index_table_slots
- 1);
1759 /* Read the index file. If everything went ok, initialize the "quick"
1760 elements of all the CUs and return 1. Otherwise, return 0. */
1762 dwarf2_read_index (struct objfile
*objfile
)
1765 struct mapped_index
*map
;
1766 offset_type
*metadata
;
1767 const gdb_byte
*cu_list
;
1768 offset_type cu_list_elements
;
1770 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1771 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1773 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1775 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1776 /* Version check. */
1777 if (MAYBE_SWAP (*(offset_type
*) addr
) != 1)
1780 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1781 map
->total_size
= dwarf2_per_objfile
->gdb_index
.size
;
1783 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1784 cu_list
= addr
+ MAYBE_SWAP (metadata
[0]);
1785 cu_list_elements
= ((MAYBE_SWAP (metadata
[1]) - MAYBE_SWAP (metadata
[0]))
1787 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[1]);
1788 map
->address_table_size
= (MAYBE_SWAP (metadata
[2])
1789 - MAYBE_SWAP (metadata
[1]));
1790 map
->index_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[2]));
1791 map
->index_table_slots
= ((MAYBE_SWAP (metadata
[3])
1792 - MAYBE_SWAP (metadata
[2]))
1793 / (2 * sizeof (offset_type
)));
1794 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[3]);
1796 if (!create_cus_from_index (objfile
, map
, cu_list
, cu_list_elements
))
1799 create_addrmap_from_index (objfile
, map
);
1801 dwarf2_per_objfile
->index_table
= map
;
1802 dwarf2_per_objfile
->using_index
= 1;
1807 /* A helper for the "quick" functions which sets the global
1808 dwarf2_per_objfile according to OBJFILE. */
1810 dw2_setup (struct objfile
*objfile
)
1812 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1813 gdb_assert (dwarf2_per_objfile
);
1816 /* A helper for the "quick" functions which attempts to read the line
1817 table for THIS_CU. */
1819 dw2_require_line_header (struct objfile
*objfile
,
1820 struct dwarf2_per_cu_data
*this_cu
)
1822 bfd
*abfd
= objfile
->obfd
;
1823 struct line_header
*lh
= NULL
;
1824 struct attribute
*attr
;
1825 struct cleanup
*cleanups
;
1826 struct die_info
*comp_unit_die
;
1827 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
1828 int has_children
, i
;
1829 struct dwarf2_cu cu
;
1830 unsigned int bytes_read
, buffer_size
;
1831 struct die_reader_specs reader_specs
;
1832 char *name
, *comp_dir
;
1834 if (this_cu
->v
.quick
->read_lines
)
1836 this_cu
->v
.quick
->read_lines
= 1;
1838 memset (&cu
, 0, sizeof (cu
));
1839 cu
.objfile
= objfile
;
1840 obstack_init (&cu
.comp_unit_obstack
);
1842 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
1844 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1845 buffer_size
= dwarf2_per_objfile
->info
.size
;
1846 buffer
= dwarf2_per_objfile
->info
.buffer
;
1847 info_ptr
= buffer
+ this_cu
->offset
;
1848 beg_of_comp_unit
= info_ptr
;
1850 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1851 buffer
, buffer_size
,
1854 /* Complete the cu_header. */
1855 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1856 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1859 cu
.per_cu
= this_cu
;
1861 dwarf2_read_abbrevs (abfd
, &cu
);
1862 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1864 if (this_cu
->from_debug_types
)
1865 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1866 init_cu_die_reader (&reader_specs
, &cu
);
1867 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1870 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
1873 unsigned int line_offset
= DW_UNSND (attr
);
1874 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
1878 do_cleanups (cleanups
);
1882 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
1884 this_cu
->v
.quick
->lines
= lh
;
1886 this_cu
->v
.quick
->file_names
1887 = obstack_alloc (&objfile
->objfile_obstack
,
1888 lh
->num_file_names
* sizeof (char *));
1889 for (i
= 0; i
< lh
->num_file_names
; ++i
)
1890 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
1892 do_cleanups (cleanups
);
1895 /* A helper for the "quick" functions which computes and caches the
1896 real path for a given file name from the line table.
1897 dw2_require_line_header must have been called before this is
1900 dw2_require_full_path (struct objfile
*objfile
,
1901 struct dwarf2_per_cu_data
*cu
,
1904 if (!cu
->v
.quick
->full_names
)
1905 cu
->v
.quick
->full_names
1906 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
1907 cu
->v
.quick
->lines
->num_file_names
,
1910 if (!cu
->v
.quick
->full_names
[index
])
1911 cu
->v
.quick
->full_names
[index
]
1912 = gdb_realpath (cu
->v
.quick
->file_names
[index
]);
1914 return cu
->v
.quick
->full_names
[index
];
1917 static struct symtab
*
1918 dw2_find_last_source_symtab (struct objfile
*objfile
)
1921 dw2_setup (objfile
);
1922 index
= dwarf2_per_objfile
->n_comp_units
- 1;
1923 return dw2_instantiate_symtab (objfile
,
1924 dwarf2_per_objfile
->all_comp_units
[index
]);
1928 dw2_forget_cached_source_info (struct objfile
*objfile
)
1932 dw2_setup (objfile
);
1933 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
1935 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
1937 if (cu
->v
.quick
->full_names
)
1941 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
1942 xfree ((void *) cu
->v
.quick
->full_names
[j
]);
1948 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
1949 const char *full_path
, const char *real_path
,
1950 struct symtab
**result
)
1953 int check_basename
= lbasename (name
) == name
;
1954 struct dwarf2_per_cu_data
*base_cu
= NULL
;
1956 dw2_setup (objfile
);
1957 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
1960 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
1962 if (cu
->v
.quick
->symtab
)
1965 dw2_require_line_header (objfile
, cu
);
1966 if (!cu
->v
.quick
->lines
)
1969 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
1971 const char *this_name
= cu
->v
.quick
->file_names
[j
];
1973 if (FILENAME_CMP (name
, this_name
) == 0)
1975 *result
= dw2_instantiate_symtab (objfile
, cu
);
1979 if (check_basename
&& ! base_cu
1980 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
1983 if (full_path
!= NULL
)
1985 const char *this_full_name
= dw2_require_full_path (objfile
,
1989 && FILENAME_CMP (full_path
, this_full_name
) == 0)
1991 *result
= dw2_instantiate_symtab (objfile
, cu
);
1996 if (real_path
!= NULL
)
1998 const char *this_full_name
= dw2_require_full_path (objfile
,
2001 if (this_full_name
!= NULL
)
2003 char *rp
= gdb_realpath (this_full_name
);
2004 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
2007 *result
= dw2_instantiate_symtab (objfile
, cu
);
2018 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2025 static struct symtab
*
2026 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2027 const char *name
, domain_enum domain
)
2029 /* We do all the work in the pre_expand_symtabs_matching hook
2034 /* A helper function that expands all symtabs that hold an object
2037 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2039 dw2_setup (objfile
);
2041 if (dwarf2_per_objfile
->index_table
)
2045 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2048 offset_type i
, len
= MAYBE_SWAP (*vec
);
2049 for (i
= 0; i
< len
; ++i
)
2051 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2052 struct dwarf2_per_cu_data
*cu
;
2053 cu
= dwarf2_per_objfile
->all_comp_units
[cu_index
];
2054 dw2_instantiate_symtab (objfile
, cu
);
2061 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2062 int kind
, const char *name
,
2065 dw2_do_expand_symtabs_matching (objfile
, name
);
2069 dw2_print_stats (struct objfile
*objfile
)
2073 dw2_setup (objfile
);
2075 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2077 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2079 if (!cu
->v
.quick
->symtab
)
2082 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2086 dw2_dump (struct objfile
*objfile
)
2088 /* Nothing worth printing. */
2092 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2093 struct section_offsets
*delta
)
2095 /* There's nothing to relocate here. */
2099 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2100 const char *func_name
)
2102 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2106 dw2_expand_all_symtabs (struct objfile
*objfile
)
2110 dw2_setup (objfile
);
2111 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2113 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2115 dw2_instantiate_symtab (objfile
, cu
);
2120 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2121 const char *filename
)
2125 dw2_setup (objfile
);
2126 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2129 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2131 if (cu
->v
.quick
->symtab
)
2134 dw2_require_line_header (objfile
, cu
);
2135 if (!cu
->v
.quick
->lines
)
2138 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2140 const char *this_name
= cu
->v
.quick
->file_names
[j
];
2141 if (strcmp (this_name
, filename
) == 0)
2143 dw2_instantiate_symtab (objfile
, cu
);
2151 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2153 struct dwarf2_per_cu_data
*cu
;
2156 dw2_setup (objfile
);
2158 if (!dwarf2_per_objfile
->index_table
)
2161 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2165 /* Note that this just looks at the very first one named NAME -- but
2166 actually we are looking for a function. find_main_filename
2167 should be rewritten so that it doesn't require a custom hook. It
2168 could just use the ordinary symbol tables. */
2169 /* vec[0] is the length, which must always be >0. */
2170 cu
= dwarf2_per_objfile
->all_comp_units
[MAYBE_SWAP (vec
[1])];
2172 dw2_require_line_header (objfile
, cu
);
2173 if (!cu
->v
.quick
->lines
)
2176 return cu
->v
.quick
->file_names
[cu
->v
.quick
->lines
->num_file_names
- 1];
2180 dw2_map_ada_symtabs (struct objfile
*objfile
,
2181 int (*wild_match
) (const char *, int, const char *),
2182 int (*is_name_suffix
) (const char *),
2183 void (*callback
) (struct objfile
*,
2184 struct symtab
*, void *),
2185 const char *name
, int global
,
2186 domain_enum
namespace, int wild
,
2189 /* For now, we don't support Ada, so this function can't be
2191 internal_error (__FILE__
, __LINE__
,
2192 _("map_ada_symtabs called via index method"));
2196 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2197 int (*file_matcher
) (const char *, void *),
2198 int (*name_matcher
) (const char *, void *),
2205 dw2_setup (objfile
);
2206 if (!dwarf2_per_objfile
->index_table
)
2209 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2212 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2214 cu
->v
.quick
->mark
= 0;
2215 if (cu
->v
.quick
->symtab
)
2218 dw2_require_line_header (objfile
, cu
);
2219 if (!cu
->v
.quick
->lines
)
2222 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2224 if (file_matcher (cu
->v
.quick
->file_names
[j
], data
))
2226 cu
->v
.quick
->mark
= 1;
2233 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2236 offset_type idx
= 2 * iter
;
2238 offset_type
*vec
, vec_len
, vec_idx
;
2240 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2241 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2244 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2245 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2247 if (! (*name_matcher
) (name
, data
))
2250 /* The name was matched, now expand corresponding CUs that were
2252 vec
= (offset_type
*) (dwarf2_per_objfile
->index_table
->constant_pool
2253 + dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1]);
2254 vec_len
= MAYBE_SWAP (vec
[0]);
2255 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2257 struct dwarf2_per_cu_data
*cu
2258 = dwarf2_per_objfile
->all_comp_units
[MAYBE_SWAP (vec
[vec_idx
+ 1])];
2259 if (cu
->v
.quick
->mark
)
2260 dw2_instantiate_symtab (objfile
, cu
);
2265 static struct symtab
*
2266 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2267 struct minimal_symbol
*msymbol
,
2269 struct obj_section
*section
,
2272 struct dwarf2_per_cu_data
*data
;
2274 dw2_setup (objfile
);
2276 if (!objfile
->psymtabs_addrmap
)
2279 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2283 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2284 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)\n"),
2285 paddress (get_objfile_arch (objfile
), pc
));
2287 return dw2_instantiate_symtab (objfile
, data
);
2291 dw2_map_symbol_names (struct objfile
*objfile
,
2292 void (*fun
) (const char *, void *),
2296 dw2_setup (objfile
);
2298 if (!dwarf2_per_objfile
->index_table
)
2302 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2305 offset_type idx
= 2 * iter
;
2307 offset_type
*vec
, vec_len
, vec_idx
;
2309 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2310 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2313 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2314 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2316 (*fun
) (name
, data
);
2321 dw2_map_symbol_filenames (struct objfile
*objfile
,
2322 void (*fun
) (const char *, const char *, void *),
2327 dw2_setup (objfile
);
2328 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2331 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2333 if (cu
->v
.quick
->symtab
)
2336 dw2_require_line_header (objfile
, cu
);
2337 if (!cu
->v
.quick
->lines
)
2340 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2342 const char *this_full_name
= dw2_require_full_path (objfile
, cu
, j
);
2343 (*fun
) (cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2349 dw2_has_symbols (struct objfile
*objfile
)
2354 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2357 dw2_find_last_source_symtab
,
2358 dw2_forget_cached_source_info
,
2361 dw2_pre_expand_symtabs_matching
,
2365 dw2_expand_symtabs_for_function
,
2366 dw2_expand_all_symtabs
,
2367 dw2_expand_symtabs_with_filename
,
2368 dw2_find_symbol_file
,
2369 dw2_map_ada_symtabs
,
2370 dw2_expand_symtabs_matching
,
2371 dw2_find_pc_sect_symtab
,
2372 dw2_map_symbol_names
,
2373 dw2_map_symbol_filenames
2376 /* Initialize for reading DWARF for this objfile. Return 0 if this
2377 file will use psymtabs, or 1 if using the GNU index. */
2380 dwarf2_initialize_objfile (struct objfile
*objfile
)
2382 /* If we're about to read full symbols, don't bother with the
2383 indices. In this case we also don't care if some other debug
2384 format is making psymtabs, because they are all about to be
2386 if ((objfile
->flags
& OBJF_READNOW
))
2390 dwarf2_per_objfile
->using_index
= 1;
2391 create_all_comp_units (objfile
);
2393 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2395 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2397 cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2398 struct dwarf2_per_cu_quick_data
);
2401 /* Return 1 so that gdb sees the "quick" functions. However,
2402 these functions will be no-ops because we will have expanded
2407 if (dwarf2_read_index (objfile
))
2410 dwarf2_build_psymtabs (objfile
);
2416 /* Build a partial symbol table. */
2419 dwarf2_build_psymtabs (struct objfile
*objfile
)
2421 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2423 init_psymbol_list (objfile
, 1024);
2426 dwarf2_build_psymtabs_hard (objfile
);
2429 /* Return TRUE if OFFSET is within CU_HEADER. */
2432 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2434 unsigned int bottom
= cu_header
->offset
;
2435 unsigned int top
= (cu_header
->offset
2437 + cu_header
->initial_length_size
);
2439 return (offset
>= bottom
&& offset
< top
);
2442 /* Read in the comp unit header information from the debug_info at info_ptr.
2443 NOTE: This leaves members offset, first_die_offset to be filled in
2447 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2448 gdb_byte
*info_ptr
, bfd
*abfd
)
2451 unsigned int bytes_read
;
2453 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2454 cu_header
->initial_length_size
= bytes_read
;
2455 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2456 info_ptr
+= bytes_read
;
2457 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2459 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2461 info_ptr
+= bytes_read
;
2462 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2464 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2465 if (signed_addr
< 0)
2466 internal_error (__FILE__
, __LINE__
,
2467 _("read_comp_unit_head: dwarf from non elf file"));
2468 cu_header
->signed_addr_p
= signed_addr
;
2474 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2475 gdb_byte
*buffer
, unsigned int buffer_size
,
2478 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2480 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2482 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2483 error (_("Dwarf Error: wrong version in compilation unit header "
2484 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2485 bfd_get_filename (abfd
));
2487 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2488 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2489 "(offset 0x%lx + 6) [in module %s]"),
2490 (long) header
->abbrev_offset
,
2491 (long) (beg_of_comp_unit
- buffer
),
2492 bfd_get_filename (abfd
));
2494 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2495 > buffer
+ buffer_size
)
2496 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2497 "(offset 0x%lx + 0) [in module %s]"),
2498 (long) header
->length
,
2499 (long) (beg_of_comp_unit
- buffer
),
2500 bfd_get_filename (abfd
));
2505 /* Read in the types comp unit header information from .debug_types entry at
2506 types_ptr. The result is a pointer to one past the end of the header. */
2509 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2510 ULONGEST
*signature
,
2511 gdb_byte
*types_ptr
, bfd
*abfd
)
2513 gdb_byte
*initial_types_ptr
= types_ptr
;
2515 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2516 &dwarf2_per_objfile
->types
);
2517 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2519 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2521 *signature
= read_8_bytes (abfd
, types_ptr
);
2523 types_ptr
+= cu_header
->offset_size
;
2524 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2529 /* Allocate a new partial symtab for file named NAME and mark this new
2530 partial symtab as being an include of PST. */
2533 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2534 struct objfile
*objfile
)
2536 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2538 subpst
->section_offsets
= pst
->section_offsets
;
2539 subpst
->textlow
= 0;
2540 subpst
->texthigh
= 0;
2542 subpst
->dependencies
= (struct partial_symtab
**)
2543 obstack_alloc (&objfile
->objfile_obstack
,
2544 sizeof (struct partial_symtab
*));
2545 subpst
->dependencies
[0] = pst
;
2546 subpst
->number_of_dependencies
= 1;
2548 subpst
->globals_offset
= 0;
2549 subpst
->n_global_syms
= 0;
2550 subpst
->statics_offset
= 0;
2551 subpst
->n_static_syms
= 0;
2552 subpst
->symtab
= NULL
;
2553 subpst
->read_symtab
= pst
->read_symtab
;
2556 /* No private part is necessary for include psymtabs. This property
2557 can be used to differentiate between such include psymtabs and
2558 the regular ones. */
2559 subpst
->read_symtab_private
= NULL
;
2562 /* Read the Line Number Program data and extract the list of files
2563 included by the source file represented by PST. Build an include
2564 partial symtab for each of these included files. */
2567 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2568 struct die_info
*die
,
2569 struct partial_symtab
*pst
)
2571 struct objfile
*objfile
= cu
->objfile
;
2572 bfd
*abfd
= objfile
->obfd
;
2573 struct line_header
*lh
= NULL
;
2574 struct attribute
*attr
;
2576 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2579 unsigned int line_offset
= DW_UNSND (attr
);
2581 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2584 return; /* No linetable, so no includes. */
2586 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
2588 free_line_header (lh
);
2592 hash_type_signature (const void *item
)
2594 const struct signatured_type
*type_sig
= item
;
2596 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2597 return type_sig
->signature
;
2601 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2603 const struct signatured_type
*lhs
= item_lhs
;
2604 const struct signatured_type
*rhs
= item_rhs
;
2606 return lhs
->signature
== rhs
->signature
;
2609 /* Create the hash table of all entries in the .debug_types section.
2610 The result is zero if there is an error (e.g. missing .debug_types section),
2611 otherwise non-zero. */
2614 create_debug_types_hash_table (struct objfile
*objfile
)
2619 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2620 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2622 if (info_ptr
== NULL
)
2624 dwarf2_per_objfile
->signatured_types
= NULL
;
2628 types_htab
= htab_create_alloc_ex (41,
2629 hash_type_signature
,
2632 &objfile
->objfile_obstack
,
2633 hashtab_obstack_allocate
,
2634 dummy_obstack_deallocate
);
2636 if (dwarf2_die_debug
)
2637 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2639 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2641 unsigned int offset
;
2642 unsigned int offset_size
;
2643 unsigned int type_offset
;
2644 unsigned int length
, initial_length_size
;
2645 unsigned short version
;
2647 struct signatured_type
*type_sig
;
2649 gdb_byte
*ptr
= info_ptr
;
2651 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2653 /* We need to read the type's signature in order to build the hash
2654 table, but we don't need to read anything else just yet. */
2656 /* Sanity check to ensure entire cu is present. */
2657 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2658 if (ptr
+ length
+ initial_length_size
2659 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2661 complaint (&symfile_complaints
,
2662 _("debug type entry runs off end of `.debug_types' section, ignored"));
2666 offset_size
= initial_length_size
== 4 ? 4 : 8;
2667 ptr
+= initial_length_size
;
2668 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2670 ptr
+= offset_size
; /* abbrev offset */
2671 ptr
+= 1; /* address size */
2672 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2674 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2676 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2677 memset (type_sig
, 0, sizeof (*type_sig
));
2678 type_sig
->signature
= signature
;
2679 type_sig
->offset
= offset
;
2680 type_sig
->type_offset
= type_offset
;
2682 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2683 gdb_assert (slot
!= NULL
);
2686 if (dwarf2_die_debug
)
2687 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2688 offset
, phex (signature
, sizeof (signature
)));
2690 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2693 dwarf2_per_objfile
->signatured_types
= types_htab
;
2698 /* Lookup a signature based type.
2699 Returns NULL if SIG is not present in the table. */
2701 static struct signatured_type
*
2702 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2704 struct signatured_type find_entry
, *entry
;
2706 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2708 complaint (&symfile_complaints
,
2709 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2713 find_entry
.signature
= sig
;
2714 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2718 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2721 init_cu_die_reader (struct die_reader_specs
*reader
,
2722 struct dwarf2_cu
*cu
)
2724 reader
->abfd
= cu
->objfile
->obfd
;
2726 if (cu
->per_cu
->from_debug_types
)
2728 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2729 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2733 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2734 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2738 /* Find the base address of the compilation unit for range lists and
2739 location lists. It will normally be specified by DW_AT_low_pc.
2740 In DWARF-3 draft 4, the base address could be overridden by
2741 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2742 compilation units with discontinuous ranges. */
2745 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2747 struct attribute
*attr
;
2750 cu
->base_address
= 0;
2752 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
2755 cu
->base_address
= DW_ADDR (attr
);
2760 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2763 cu
->base_address
= DW_ADDR (attr
);
2769 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2770 to combine the common parts.
2771 Process a compilation unit for a psymtab.
2772 BUFFER is a pointer to the beginning of the dwarf section buffer,
2773 either .debug_info or debug_types.
2774 INFO_PTR is a pointer to the start of the CU.
2775 Returns a pointer to the next CU. */
2778 process_psymtab_comp_unit (struct objfile
*objfile
,
2779 struct dwarf2_per_cu_data
*this_cu
,
2780 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2781 unsigned int buffer_size
)
2783 bfd
*abfd
= objfile
->obfd
;
2784 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2785 struct die_info
*comp_unit_die
;
2786 struct partial_symtab
*pst
;
2788 struct cleanup
*back_to_inner
;
2789 struct dwarf2_cu cu
;
2790 int has_children
, has_pc_info
;
2791 struct attribute
*attr
;
2792 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
2793 struct die_reader_specs reader_specs
;
2795 memset (&cu
, 0, sizeof (cu
));
2796 cu
.objfile
= objfile
;
2797 obstack_init (&cu
.comp_unit_obstack
);
2799 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
2801 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2802 buffer
, buffer_size
,
2805 /* Complete the cu_header. */
2806 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2807 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2809 cu
.list_in_scope
= &file_symbols
;
2811 /* If this compilation unit was already read in, free the
2812 cached copy in order to read it in again. This is
2813 necessary because we skipped some symbols when we first
2814 read in the compilation unit (see load_partial_dies).
2815 This problem could be avoided, but the benefit is
2817 if (this_cu
->cu
!= NULL
)
2818 free_one_cached_comp_unit (this_cu
->cu
);
2820 /* Note that this is a pointer to our stack frame, being
2821 added to a global data structure. It will be cleaned up
2822 in free_stack_comp_unit when we finish with this
2823 compilation unit. */
2825 cu
.per_cu
= this_cu
;
2827 /* Read the abbrevs for this compilation unit into a table. */
2828 dwarf2_read_abbrevs (abfd
, &cu
);
2829 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2831 /* Read the compilation unit die. */
2832 if (this_cu
->from_debug_types
)
2833 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2834 init_cu_die_reader (&reader_specs
, &cu
);
2835 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2838 if (this_cu
->from_debug_types
)
2840 /* offset,length haven't been set yet for type units. */
2841 this_cu
->offset
= cu
.header
.offset
;
2842 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
2844 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2846 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
2847 + cu
.header
.initial_length_size
);
2848 do_cleanups (back_to_inner
);
2852 /* Set the language we're debugging. */
2853 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
2855 set_cu_language (DW_UNSND (attr
), &cu
);
2857 set_cu_language (language_minimal
, &cu
);
2859 /* Allocate a new partial symbol table structure. */
2860 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
2861 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
2862 (attr
!= NULL
) ? DW_STRING (attr
) : "",
2863 /* TEXTLOW and TEXTHIGH are set below. */
2865 objfile
->global_psymbols
.next
,
2866 objfile
->static_psymbols
.next
);
2868 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
2870 pst
->dirname
= DW_STRING (attr
);
2872 pst
->read_symtab_private
= this_cu
;
2874 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2876 /* Store the function that reads in the rest of the symbol table */
2877 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
2879 this_cu
->v
.psymtab
= pst
;
2881 dwarf2_find_base_address (comp_unit_die
, &cu
);
2883 /* Possibly set the default values of LOWPC and HIGHPC from
2885 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
2886 &best_highpc
, &cu
, pst
);
2887 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
2888 /* Store the contiguous range if it is not empty; it can be empty for
2889 CUs with no code. */
2890 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2891 best_lowpc
+ baseaddr
,
2892 best_highpc
+ baseaddr
- 1, pst
);
2894 /* Check if comp unit has_children.
2895 If so, read the rest of the partial symbols from this comp unit.
2896 If not, there's no more debug_info for this comp unit. */
2899 struct partial_die_info
*first_die
;
2900 CORE_ADDR lowpc
, highpc
;
2902 lowpc
= ((CORE_ADDR
) -1);
2903 highpc
= ((CORE_ADDR
) 0);
2905 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
2907 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
2908 ! has_pc_info
, &cu
);
2910 /* If we didn't find a lowpc, set it to highpc to avoid
2911 complaints from `maint check'. */
2912 if (lowpc
== ((CORE_ADDR
) -1))
2915 /* If the compilation unit didn't have an explicit address range,
2916 then use the information extracted from its child dies. */
2920 best_highpc
= highpc
;
2923 pst
->textlow
= best_lowpc
+ baseaddr
;
2924 pst
->texthigh
= best_highpc
+ baseaddr
;
2926 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
2927 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2928 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
2929 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2930 sort_pst_symbols (pst
);
2932 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
2933 + cu
.header
.initial_length_size
);
2935 if (this_cu
->from_debug_types
)
2937 /* It's not clear we want to do anything with stmt lists here.
2938 Waiting to see what gcc ultimately does. */
2942 /* Get the list of files included in the current compilation unit,
2943 and build a psymtab for each of them. */
2944 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
2947 do_cleanups (back_to_inner
);
2952 /* Traversal function for htab_traverse_noresize.
2953 Process one .debug_types comp-unit. */
2956 process_type_comp_unit (void **slot
, void *info
)
2958 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
2959 struct objfile
*objfile
= (struct objfile
*) info
;
2960 struct dwarf2_per_cu_data
*this_cu
;
2962 this_cu
= &entry
->per_cu
;
2963 this_cu
->from_debug_types
= 1;
2965 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2966 process_psymtab_comp_unit (objfile
, this_cu
,
2967 dwarf2_per_objfile
->types
.buffer
,
2968 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
2969 dwarf2_per_objfile
->types
.size
);
2974 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
2975 Build partial symbol tables for the .debug_types comp-units. */
2978 build_type_psymtabs (struct objfile
*objfile
)
2980 if (! create_debug_types_hash_table (objfile
))
2983 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
2984 process_type_comp_unit
, objfile
);
2987 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
2990 psymtabs_addrmap_cleanup (void *o
)
2992 struct objfile
*objfile
= o
;
2994 objfile
->psymtabs_addrmap
= NULL
;
2997 /* Build the partial symbol table by doing a quick pass through the
2998 .debug_info and .debug_abbrev sections. */
3001 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3004 struct cleanup
*back_to
, *addrmap_cleanup
;
3005 struct obstack temp_obstack
;
3007 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3008 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3010 /* Any cached compilation units will be linked by the per-objfile
3011 read_in_chain. Make sure to free them when we're done. */
3012 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3014 build_type_psymtabs (objfile
);
3016 create_all_comp_units (objfile
);
3018 /* Create a temporary address map on a temporary obstack. We later
3019 copy this to the final obstack. */
3020 obstack_init (&temp_obstack
);
3021 make_cleanup_obstack_free (&temp_obstack
);
3022 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3023 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3025 /* Since the objects we're extracting from .debug_info vary in
3026 length, only the individual functions to extract them (like
3027 read_comp_unit_head and load_partial_die) can really know whether
3028 the buffer is large enough to hold another complete object.
3030 At the moment, they don't actually check that. If .debug_info
3031 holds just one extra byte after the last compilation unit's dies,
3032 then read_comp_unit_head will happily read off the end of the
3033 buffer. read_partial_die is similarly casual. Those functions
3036 For this loop condition, simply checking whether there's any data
3037 left at all should be sufficient. */
3039 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3040 + dwarf2_per_objfile
->info
.size
))
3042 struct dwarf2_per_cu_data
*this_cu
;
3044 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3047 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3048 dwarf2_per_objfile
->info
.buffer
,
3050 dwarf2_per_objfile
->info
.size
);
3053 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3054 &objfile
->objfile_obstack
);
3055 discard_cleanups (addrmap_cleanup
);
3057 do_cleanups (back_to
);
3060 /* Load the partial DIEs for a secondary CU into memory. */
3063 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3064 struct objfile
*objfile
)
3066 bfd
*abfd
= objfile
->obfd
;
3067 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3068 struct die_info
*comp_unit_die
;
3069 struct dwarf2_cu
*cu
;
3070 struct cleanup
*back_to
;
3071 struct attribute
*attr
;
3073 struct die_reader_specs reader_specs
;
3075 gdb_assert (! this_cu
->from_debug_types
);
3077 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3078 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3079 beg_of_comp_unit
= info_ptr
;
3081 cu
= alloc_one_comp_unit (objfile
);
3083 /* ??? Missing cleanup for CU? */
3085 /* Link this compilation unit into the compilation unit tree. */
3087 cu
->per_cu
= this_cu
;
3088 cu
->type_hash
= this_cu
->type_hash
;
3090 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3091 dwarf2_per_objfile
->info
.buffer
,
3092 dwarf2_per_objfile
->info
.size
,
3095 /* Complete the cu_header. */
3096 cu
->header
.offset
= this_cu
->offset
;
3097 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3099 /* Read the abbrevs for this compilation unit into a table. */
3100 dwarf2_read_abbrevs (abfd
, cu
);
3101 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3103 /* Read the compilation unit die. */
3104 init_cu_die_reader (&reader_specs
, cu
);
3105 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3108 /* Set the language we're debugging. */
3109 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
3111 set_cu_language (DW_UNSND (attr
), cu
);
3113 set_cu_language (language_minimal
, cu
);
3115 /* Check if comp unit has_children.
3116 If so, read the rest of the partial symbols from this comp unit.
3117 If not, there's no more debug_info for this comp unit. */
3119 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3121 do_cleanups (back_to
);
3124 /* Create a list of all compilation units in OBJFILE. We do this only
3125 if an inter-comp-unit reference is found; presumably if there is one,
3126 there will be many, and one will occur early in the .debug_info section.
3127 So there's no point in building this list incrementally. */
3130 create_all_comp_units (struct objfile
*objfile
)
3134 struct dwarf2_per_cu_data
**all_comp_units
;
3137 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3138 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3142 all_comp_units
= xmalloc (n_allocated
3143 * sizeof (struct dwarf2_per_cu_data
*));
3145 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3147 unsigned int length
, initial_length_size
;
3148 struct dwarf2_per_cu_data
*this_cu
;
3149 unsigned int offset
;
3151 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3153 /* Read just enough information to find out where the next
3154 compilation unit is. */
3155 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3156 &initial_length_size
);
3158 /* Save the compilation unit for later lookup. */
3159 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3160 sizeof (struct dwarf2_per_cu_data
));
3161 memset (this_cu
, 0, sizeof (*this_cu
));
3162 this_cu
->offset
= offset
;
3163 this_cu
->length
= length
+ initial_length_size
;
3164 this_cu
->objfile
= objfile
;
3166 if (n_comp_units
== n_allocated
)
3169 all_comp_units
= xrealloc (all_comp_units
,
3171 * sizeof (struct dwarf2_per_cu_data
*));
3173 all_comp_units
[n_comp_units
++] = this_cu
;
3175 info_ptr
= info_ptr
+ this_cu
->length
;
3178 dwarf2_per_objfile
->all_comp_units
3179 = obstack_alloc (&objfile
->objfile_obstack
,
3180 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3181 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3182 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3183 xfree (all_comp_units
);
3184 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3187 /* Process all loaded DIEs for compilation unit CU, starting at
3188 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3189 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3190 DW_AT_ranges). If NEED_PC is set, then this function will set
3191 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3192 and record the covered ranges in the addrmap. */
3195 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3196 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3198 struct partial_die_info
*pdi
;
3200 /* Now, march along the PDI's, descending into ones which have
3201 interesting children but skipping the children of the other ones,
3202 until we reach the end of the compilation unit. */
3208 fixup_partial_die (pdi
, cu
);
3210 /* Anonymous namespaces or modules have no name but have interesting
3211 children, so we need to look at them. Ditto for anonymous
3214 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3215 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3219 case DW_TAG_subprogram
:
3220 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3222 case DW_TAG_variable
:
3223 case DW_TAG_typedef
:
3224 case DW_TAG_union_type
:
3225 if (!pdi
->is_declaration
)
3227 add_partial_symbol (pdi
, cu
);
3230 case DW_TAG_class_type
:
3231 case DW_TAG_interface_type
:
3232 case DW_TAG_structure_type
:
3233 if (!pdi
->is_declaration
)
3235 add_partial_symbol (pdi
, cu
);
3238 case DW_TAG_enumeration_type
:
3239 if (!pdi
->is_declaration
)
3240 add_partial_enumeration (pdi
, cu
);
3242 case DW_TAG_base_type
:
3243 case DW_TAG_subrange_type
:
3244 /* File scope base type definitions are added to the partial
3246 add_partial_symbol (pdi
, cu
);
3248 case DW_TAG_namespace
:
3249 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3252 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3259 /* If the die has a sibling, skip to the sibling. */
3261 pdi
= pdi
->die_sibling
;
3265 /* Functions used to compute the fully scoped name of a partial DIE.
3267 Normally, this is simple. For C++, the parent DIE's fully scoped
3268 name is concatenated with "::" and the partial DIE's name. For
3269 Java, the same thing occurs except that "." is used instead of "::".
3270 Enumerators are an exception; they use the scope of their parent
3271 enumeration type, i.e. the name of the enumeration type is not
3272 prepended to the enumerator.
3274 There are two complexities. One is DW_AT_specification; in this
3275 case "parent" means the parent of the target of the specification,
3276 instead of the direct parent of the DIE. The other is compilers
3277 which do not emit DW_TAG_namespace; in this case we try to guess
3278 the fully qualified name of structure types from their members'
3279 linkage names. This must be done using the DIE's children rather
3280 than the children of any DW_AT_specification target. We only need
3281 to do this for structures at the top level, i.e. if the target of
3282 any DW_AT_specification (if any; otherwise the DIE itself) does not
3285 /* Compute the scope prefix associated with PDI's parent, in
3286 compilation unit CU. The result will be allocated on CU's
3287 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3288 field. NULL is returned if no prefix is necessary. */
3290 partial_die_parent_scope (struct partial_die_info
*pdi
,
3291 struct dwarf2_cu
*cu
)
3293 char *grandparent_scope
;
3294 struct partial_die_info
*parent
, *real_pdi
;
3296 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3297 then this means the parent of the specification DIE. */
3300 while (real_pdi
->has_specification
)
3301 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3303 parent
= real_pdi
->die_parent
;
3307 if (parent
->scope_set
)
3308 return parent
->scope
;
3310 fixup_partial_die (parent
, cu
);
3312 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3314 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3315 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3316 Work around this problem here. */
3317 if (cu
->language
== language_cplus
3318 && parent
->tag
== DW_TAG_namespace
3319 && strcmp (parent
->name
, "::") == 0
3320 && grandparent_scope
== NULL
)
3322 parent
->scope
= NULL
;
3323 parent
->scope_set
= 1;
3327 if (parent
->tag
== DW_TAG_namespace
3328 || parent
->tag
== DW_TAG_module
3329 || parent
->tag
== DW_TAG_structure_type
3330 || parent
->tag
== DW_TAG_class_type
3331 || parent
->tag
== DW_TAG_interface_type
3332 || parent
->tag
== DW_TAG_union_type
3333 || parent
->tag
== DW_TAG_enumeration_type
)
3335 if (grandparent_scope
== NULL
)
3336 parent
->scope
= parent
->name
;
3338 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3339 parent
->name
, 0, cu
);
3341 else if (parent
->tag
== DW_TAG_enumerator
)
3342 /* Enumerators should not get the name of the enumeration as a prefix. */
3343 parent
->scope
= grandparent_scope
;
3346 /* FIXME drow/2004-04-01: What should we be doing with
3347 function-local names? For partial symbols, we should probably be
3349 complaint (&symfile_complaints
,
3350 _("unhandled containing DIE tag %d for DIE at %d"),
3351 parent
->tag
, pdi
->offset
);
3352 parent
->scope
= grandparent_scope
;
3355 parent
->scope_set
= 1;
3356 return parent
->scope
;
3359 /* Return the fully scoped name associated with PDI, from compilation unit
3360 CU. The result will be allocated with malloc. */
3362 partial_die_full_name (struct partial_die_info
*pdi
,
3363 struct dwarf2_cu
*cu
)
3367 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3368 if (parent_scope
== NULL
)
3371 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3375 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3377 struct objfile
*objfile
= cu
->objfile
;
3379 char *actual_name
= NULL
;
3380 const struct partial_symbol
*psym
= NULL
;
3382 int built_actual_name
= 0;
3384 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3386 actual_name
= partial_die_full_name (pdi
, cu
);
3388 built_actual_name
= 1;
3390 if (actual_name
== NULL
)
3391 actual_name
= pdi
->name
;
3395 case DW_TAG_subprogram
:
3396 if (pdi
->is_external
|| cu
->language
== language_ada
)
3398 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3399 of the global scope. But in Ada, we want to be able to access
3400 nested procedures globally. So all Ada subprograms are stored
3401 in the global scope. */
3402 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3403 mst_text, objfile); */
3404 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3406 VAR_DOMAIN
, LOC_BLOCK
,
3407 &objfile
->global_psymbols
,
3408 0, pdi
->lowpc
+ baseaddr
,
3409 cu
->language
, objfile
);
3413 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3414 mst_file_text, objfile); */
3415 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3417 VAR_DOMAIN
, LOC_BLOCK
,
3418 &objfile
->static_psymbols
,
3419 0, pdi
->lowpc
+ baseaddr
,
3420 cu
->language
, objfile
);
3423 case DW_TAG_variable
:
3424 if (pdi
->is_external
)
3427 Don't enter into the minimal symbol tables as there is
3428 a minimal symbol table entry from the ELF symbols already.
3429 Enter into partial symbol table if it has a location
3430 descriptor or a type.
3431 If the location descriptor is missing, new_symbol will create
3432 a LOC_UNRESOLVED symbol, the address of the variable will then
3433 be determined from the minimal symbol table whenever the variable
3435 The address for the partial symbol table entry is not
3436 used by GDB, but it comes in handy for debugging partial symbol
3440 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3441 if (pdi
->locdesc
|| pdi
->has_type
)
3442 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3444 VAR_DOMAIN
, LOC_STATIC
,
3445 &objfile
->global_psymbols
,
3447 cu
->language
, objfile
);
3451 /* Static Variable. Skip symbols without location descriptors. */
3452 if (pdi
->locdesc
== NULL
)
3454 if (built_actual_name
)
3455 xfree (actual_name
);
3458 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3459 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3460 mst_file_data, objfile); */
3461 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3463 VAR_DOMAIN
, LOC_STATIC
,
3464 &objfile
->static_psymbols
,
3466 cu
->language
, objfile
);
3469 case DW_TAG_typedef
:
3470 case DW_TAG_base_type
:
3471 case DW_TAG_subrange_type
:
3472 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3474 VAR_DOMAIN
, LOC_TYPEDEF
,
3475 &objfile
->static_psymbols
,
3476 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3478 case DW_TAG_namespace
:
3479 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3481 VAR_DOMAIN
, LOC_TYPEDEF
,
3482 &objfile
->global_psymbols
,
3483 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3485 case DW_TAG_class_type
:
3486 case DW_TAG_interface_type
:
3487 case DW_TAG_structure_type
:
3488 case DW_TAG_union_type
:
3489 case DW_TAG_enumeration_type
:
3490 /* Skip external references. The DWARF standard says in the section
3491 about "Structure, Union, and Class Type Entries": "An incomplete
3492 structure, union or class type is represented by a structure,
3493 union or class entry that does not have a byte size attribute
3494 and that has a DW_AT_declaration attribute." */
3495 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3497 if (built_actual_name
)
3498 xfree (actual_name
);
3502 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3503 static vs. global. */
3504 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3506 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3507 (cu
->language
== language_cplus
3508 || cu
->language
== language_java
)
3509 ? &objfile
->global_psymbols
3510 : &objfile
->static_psymbols
,
3511 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3514 case DW_TAG_enumerator
:
3515 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3517 VAR_DOMAIN
, LOC_CONST
,
3518 (cu
->language
== language_cplus
3519 || cu
->language
== language_java
)
3520 ? &objfile
->global_psymbols
3521 : &objfile
->static_psymbols
,
3522 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3528 if (built_actual_name
)
3529 xfree (actual_name
);
3532 /* Read a partial die corresponding to a namespace; also, add a symbol
3533 corresponding to that namespace to the symbol table. NAMESPACE is
3534 the name of the enclosing namespace. */
3537 add_partial_namespace (struct partial_die_info
*pdi
,
3538 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3539 int need_pc
, struct dwarf2_cu
*cu
)
3541 /* Add a symbol for the namespace. */
3543 add_partial_symbol (pdi
, cu
);
3545 /* Now scan partial symbols in that namespace. */
3547 if (pdi
->has_children
)
3548 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3551 /* Read a partial die corresponding to a Fortran module. */
3554 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3555 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3557 /* Now scan partial symbols in that module. */
3559 if (pdi
->has_children
)
3560 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3563 /* Read a partial die corresponding to a subprogram and create a partial
3564 symbol for that subprogram. When the CU language allows it, this
3565 routine also defines a partial symbol for each nested subprogram
3566 that this subprogram contains.
3568 DIE my also be a lexical block, in which case we simply search
3569 recursively for suprograms defined inside that lexical block.
3570 Again, this is only performed when the CU language allows this
3571 type of definitions. */
3574 add_partial_subprogram (struct partial_die_info
*pdi
,
3575 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3576 int need_pc
, struct dwarf2_cu
*cu
)
3578 if (pdi
->tag
== DW_TAG_subprogram
)
3580 if (pdi
->has_pc_info
)
3582 if (pdi
->lowpc
< *lowpc
)
3583 *lowpc
= pdi
->lowpc
;
3584 if (pdi
->highpc
> *highpc
)
3585 *highpc
= pdi
->highpc
;
3589 struct objfile
*objfile
= cu
->objfile
;
3591 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3592 SECT_OFF_TEXT (objfile
));
3593 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3594 pdi
->lowpc
+ baseaddr
,
3595 pdi
->highpc
- 1 + baseaddr
,
3596 cu
->per_cu
->v
.psymtab
);
3598 if (!pdi
->is_declaration
)
3599 /* Ignore subprogram DIEs that do not have a name, they are
3600 illegal. Do not emit a complaint at this point, we will
3601 do so when we convert this psymtab into a symtab. */
3603 add_partial_symbol (pdi
, cu
);
3607 if (! pdi
->has_children
)
3610 if (cu
->language
== language_ada
)
3612 pdi
= pdi
->die_child
;
3615 fixup_partial_die (pdi
, cu
);
3616 if (pdi
->tag
== DW_TAG_subprogram
3617 || pdi
->tag
== DW_TAG_lexical_block
)
3618 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3619 pdi
= pdi
->die_sibling
;
3624 /* See if we can figure out if the class lives in a namespace. We do
3625 this by looking for a member function; its demangled name will
3626 contain namespace info, if there is any. */
3629 guess_structure_name (struct partial_die_info
*struct_pdi
,
3630 struct dwarf2_cu
*cu
)
3632 if ((cu
->language
== language_cplus
3633 || cu
->language
== language_java
)
3634 && cu
->has_namespace_info
== 0
3635 && struct_pdi
->has_children
)
3637 /* NOTE: carlton/2003-10-07: Getting the info this way changes
3638 what template types look like, because the demangler
3639 frequently doesn't give the same name as the debug info. We
3640 could fix this by only using the demangled name to get the
3641 prefix (but see comment in read_structure_type). */
3643 struct partial_die_info
*real_pdi
;
3645 /* If this DIE (this DIE's specification, if any) has a parent, then
3646 we should not do this. We'll prepend the parent's fully qualified
3647 name when we create the partial symbol. */
3649 real_pdi
= struct_pdi
;
3650 while (real_pdi
->has_specification
)
3651 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3653 if (real_pdi
->die_parent
!= NULL
)
3658 /* Read a partial die corresponding to an enumeration type. */
3661 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3662 struct dwarf2_cu
*cu
)
3664 struct partial_die_info
*pdi
;
3666 if (enum_pdi
->name
!= NULL
)
3667 add_partial_symbol (enum_pdi
, cu
);
3669 pdi
= enum_pdi
->die_child
;
3672 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3673 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3675 add_partial_symbol (pdi
, cu
);
3676 pdi
= pdi
->die_sibling
;
3680 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3681 Return the corresponding abbrev, or NULL if the number is zero (indicating
3682 an empty DIE). In either case *BYTES_READ will be set to the length of
3683 the initial number. */
3685 static struct abbrev_info
*
3686 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3687 struct dwarf2_cu
*cu
)
3689 bfd
*abfd
= cu
->objfile
->obfd
;
3690 unsigned int abbrev_number
;
3691 struct abbrev_info
*abbrev
;
3693 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3695 if (abbrev_number
== 0)
3698 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3701 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3702 bfd_get_filename (abfd
));
3708 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3709 Returns a pointer to the end of a series of DIEs, terminated by an empty
3710 DIE. Any children of the skipped DIEs will also be skipped. */
3713 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
3715 struct abbrev_info
*abbrev
;
3716 unsigned int bytes_read
;
3720 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
3722 return info_ptr
+ bytes_read
;
3724 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
3728 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3729 INFO_PTR should point just after the initial uleb128 of a DIE, and the
3730 abbrev corresponding to that skipped uleb128 should be passed in
3731 ABBREV. Returns a pointer to this DIE's sibling, skipping any
3735 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3736 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
3738 unsigned int bytes_read
;
3739 struct attribute attr
;
3740 bfd
*abfd
= cu
->objfile
->obfd
;
3741 unsigned int form
, i
;
3743 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
3745 /* The only abbrev we care about is DW_AT_sibling. */
3746 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
3748 read_attribute (&attr
, &abbrev
->attrs
[i
],
3749 abfd
, info_ptr
, cu
);
3750 if (attr
.form
== DW_FORM_ref_addr
)
3751 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
3753 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
3756 /* If it isn't DW_AT_sibling, skip this attribute. */
3757 form
= abbrev
->attrs
[i
].form
;
3761 case DW_FORM_ref_addr
:
3762 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
3763 and later it is offset sized. */
3764 if (cu
->header
.version
== 2)
3765 info_ptr
+= cu
->header
.addr_size
;
3767 info_ptr
+= cu
->header
.offset_size
;
3770 info_ptr
+= cu
->header
.addr_size
;
3777 case DW_FORM_flag_present
:
3792 case DW_FORM_string
:
3793 read_string (abfd
, info_ptr
, &bytes_read
);
3794 info_ptr
+= bytes_read
;
3796 case DW_FORM_sec_offset
:
3798 info_ptr
+= cu
->header
.offset_size
;
3800 case DW_FORM_exprloc
:
3802 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3803 info_ptr
+= bytes_read
;
3805 case DW_FORM_block1
:
3806 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
3808 case DW_FORM_block2
:
3809 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
3811 case DW_FORM_block4
:
3812 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
3816 case DW_FORM_ref_udata
:
3817 info_ptr
= skip_leb128 (abfd
, info_ptr
);
3819 case DW_FORM_indirect
:
3820 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3821 info_ptr
+= bytes_read
;
3822 /* We need to continue parsing from here, so just go back to
3824 goto skip_attribute
;
3827 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
3828 dwarf_form_name (form
),
3829 bfd_get_filename (abfd
));
3833 if (abbrev
->has_children
)
3834 return skip_children (buffer
, info_ptr
, cu
);
3839 /* Locate ORIG_PDI's sibling.
3840 INFO_PTR should point to the start of the next DIE after ORIG_PDI
3844 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
3845 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3846 bfd
*abfd
, struct dwarf2_cu
*cu
)
3848 /* Do we know the sibling already? */
3850 if (orig_pdi
->sibling
)
3851 return orig_pdi
->sibling
;
3853 /* Are there any children to deal with? */
3855 if (!orig_pdi
->has_children
)
3858 /* Skip the children the long way. */
3860 return skip_children (buffer
, info_ptr
, cu
);
3863 /* Expand this partial symbol table into a full symbol table. */
3866 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
3872 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
3878 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
3879 gdb_flush (gdb_stdout
);
3882 /* Restore our global data. */
3883 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
3884 dwarf2_objfile_data_key
);
3886 /* If this psymtab is constructed from a debug-only objfile, the
3887 has_section_at_zero flag will not necessarily be correct. We
3888 can get the correct value for this flag by looking at the data
3889 associated with the (presumably stripped) associated objfile. */
3890 if (pst
->objfile
->separate_debug_objfile_backlink
)
3892 struct dwarf2_per_objfile
*dpo_backlink
3893 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
3894 dwarf2_objfile_data_key
);
3896 dwarf2_per_objfile
->has_section_at_zero
3897 = dpo_backlink
->has_section_at_zero
;
3900 psymtab_to_symtab_1 (pst
);
3902 /* Finish up the debug error message. */
3904 printf_filtered (_("done.\n"));
3909 /* Add PER_CU to the queue. */
3912 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3914 struct dwarf2_queue_item
*item
;
3917 item
= xmalloc (sizeof (*item
));
3918 item
->per_cu
= per_cu
;
3921 if (dwarf2_queue
== NULL
)
3922 dwarf2_queue
= item
;
3924 dwarf2_queue_tail
->next
= item
;
3926 dwarf2_queue_tail
= item
;
3929 /* Process the queue. */
3932 process_queue (struct objfile
*objfile
)
3934 struct dwarf2_queue_item
*item
, *next_item
;
3936 /* The queue starts out with one item, but following a DIE reference
3937 may load a new CU, adding it to the end of the queue. */
3938 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
3940 if (dwarf2_per_objfile
->using_index
3941 ? !item
->per_cu
->v
.quick
->symtab
3942 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
3943 process_full_comp_unit (item
->per_cu
);
3945 item
->per_cu
->queued
= 0;
3946 next_item
= item
->next
;
3950 dwarf2_queue_tail
= NULL
;
3953 /* Free all allocated queue entries. This function only releases anything if
3954 an error was thrown; if the queue was processed then it would have been
3955 freed as we went along. */
3958 dwarf2_release_queue (void *dummy
)
3960 struct dwarf2_queue_item
*item
, *last
;
3962 item
= dwarf2_queue
;
3965 /* Anything still marked queued is likely to be in an
3966 inconsistent state, so discard it. */
3967 if (item
->per_cu
->queued
)
3969 if (item
->per_cu
->cu
!= NULL
)
3970 free_one_cached_comp_unit (item
->per_cu
->cu
);
3971 item
->per_cu
->queued
= 0;
3979 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
3982 /* Read in full symbols for PST, and anything it depends on. */
3985 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
3987 struct dwarf2_per_cu_data
*per_cu
;
3988 struct cleanup
*back_to
;
3991 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
3992 if (!pst
->dependencies
[i
]->readin
)
3994 /* Inform about additional files that need to be read in. */
3997 /* FIXME: i18n: Need to make this a single string. */
3998 fputs_filtered (" ", gdb_stdout
);
4000 fputs_filtered ("and ", gdb_stdout
);
4002 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4003 wrap_here (""); /* Flush output */
4004 gdb_flush (gdb_stdout
);
4006 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4009 per_cu
= pst
->read_symtab_private
;
4013 /* It's an include file, no symbols to read for it.
4014 Everything is in the parent symtab. */
4019 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4022 /* Load the DIEs associated with PER_CU into memory. */
4025 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4027 bfd
*abfd
= objfile
->obfd
;
4028 struct dwarf2_cu
*cu
;
4029 unsigned int offset
;
4030 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4031 struct cleanup
*back_to
, *free_cu_cleanup
;
4032 struct attribute
*attr
;
4034 gdb_assert (! per_cu
->from_debug_types
);
4036 /* Set local variables from the partial symbol table info. */
4037 offset
= per_cu
->offset
;
4039 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4040 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4041 beg_of_comp_unit
= info_ptr
;
4043 cu
= alloc_one_comp_unit (objfile
);
4045 /* If an error occurs while loading, release our storage. */
4046 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4048 /* Read in the comp_unit header. */
4049 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4051 /* Complete the cu_header. */
4052 cu
->header
.offset
= offset
;
4053 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4055 /* Read the abbrevs for this compilation unit. */
4056 dwarf2_read_abbrevs (abfd
, cu
);
4057 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4059 /* Link this compilation unit into the compilation unit tree. */
4061 cu
->per_cu
= per_cu
;
4062 cu
->type_hash
= per_cu
->type_hash
;
4064 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4066 /* We try not to read any attributes in this function, because not
4067 all objfiles needed for references have been loaded yet, and symbol
4068 table processing isn't initialized. But we have to set the CU language,
4069 or we won't be able to build types correctly. */
4070 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
4072 set_cu_language (DW_UNSND (attr
), cu
);
4074 set_cu_language (language_minimal
, cu
);
4076 /* Similarly, if we do not read the producer, we can not apply
4077 producer-specific interpretation. */
4078 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4080 cu
->producer
= DW_STRING (attr
);
4082 /* Link this CU into read_in_chain. */
4083 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4084 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4086 do_cleanups (back_to
);
4088 /* We've successfully allocated this compilation unit. Let our caller
4089 clean it up when finished with it. */
4090 discard_cleanups (free_cu_cleanup
);
4093 /* Generate full symbol information for PST and CU, whose DIEs have
4094 already been loaded into memory. */
4097 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4099 struct dwarf2_cu
*cu
= per_cu
->cu
;
4100 struct objfile
*objfile
= per_cu
->objfile
;
4101 CORE_ADDR lowpc
, highpc
;
4102 struct symtab
*symtab
;
4103 struct cleanup
*back_to
;
4106 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4109 back_to
= make_cleanup (really_free_pendings
, NULL
);
4111 cu
->list_in_scope
= &file_symbols
;
4113 dwarf2_find_base_address (cu
->dies
, cu
);
4115 /* Do line number decoding in read_file_scope () */
4116 process_die (cu
->dies
, cu
);
4118 /* Some compilers don't define a DW_AT_high_pc attribute for the
4119 compilation unit. If the DW_AT_high_pc is missing, synthesize
4120 it, by scanning the DIE's below the compilation unit. */
4121 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4123 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4125 /* Set symtab language to language from DW_AT_language.
4126 If the compilation is from a C file generated by language preprocessors,
4127 do not set the language if it was already deduced by start_subfile. */
4129 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4131 symtab
->language
= cu
->language
;
4134 if (dwarf2_per_objfile
->using_index
)
4135 per_cu
->v
.quick
->symtab
= symtab
;
4138 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4139 pst
->symtab
= symtab
;
4143 do_cleanups (back_to
);
4146 /* Process a die and its children. */
4149 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4153 case DW_TAG_padding
:
4155 case DW_TAG_compile_unit
:
4156 read_file_scope (die
, cu
);
4158 case DW_TAG_type_unit
:
4159 read_type_unit_scope (die
, cu
);
4161 case DW_TAG_subprogram
:
4162 case DW_TAG_inlined_subroutine
:
4163 read_func_scope (die
, cu
);
4165 case DW_TAG_lexical_block
:
4166 case DW_TAG_try_block
:
4167 case DW_TAG_catch_block
:
4168 read_lexical_block_scope (die
, cu
);
4170 case DW_TAG_class_type
:
4171 case DW_TAG_interface_type
:
4172 case DW_TAG_structure_type
:
4173 case DW_TAG_union_type
:
4174 process_structure_scope (die
, cu
);
4176 case DW_TAG_enumeration_type
:
4177 process_enumeration_scope (die
, cu
);
4180 /* These dies have a type, but processing them does not create
4181 a symbol or recurse to process the children. Therefore we can
4182 read them on-demand through read_type_die. */
4183 case DW_TAG_subroutine_type
:
4184 case DW_TAG_set_type
:
4185 case DW_TAG_array_type
:
4186 case DW_TAG_pointer_type
:
4187 case DW_TAG_ptr_to_member_type
:
4188 case DW_TAG_reference_type
:
4189 case DW_TAG_string_type
:
4192 case DW_TAG_base_type
:
4193 case DW_TAG_subrange_type
:
4194 case DW_TAG_typedef
:
4195 case DW_TAG_const_type
:
4196 case DW_TAG_volatile_type
:
4197 /* Add a typedef symbol for the type definition, if it has a
4199 new_symbol (die
, read_type_die (die
, cu
), cu
);
4201 case DW_TAG_common_block
:
4202 read_common_block (die
, cu
);
4204 case DW_TAG_common_inclusion
:
4206 case DW_TAG_namespace
:
4207 processing_has_namespace_info
= 1;
4208 read_namespace (die
, cu
);
4211 processing_has_namespace_info
= 1;
4212 read_module (die
, cu
);
4214 case DW_TAG_imported_declaration
:
4215 case DW_TAG_imported_module
:
4216 processing_has_namespace_info
= 1;
4217 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4218 || cu
->language
!= language_fortran
))
4219 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4220 dwarf_tag_name (die
->tag
));
4221 read_import_statement (die
, cu
);
4224 new_symbol (die
, NULL
, cu
);
4229 /* A helper function for dwarf2_compute_name which determines whether DIE
4230 needs to have the name of the scope prepended to the name listed in the
4234 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4236 struct attribute
*attr
;
4240 case DW_TAG_namespace
:
4241 case DW_TAG_typedef
:
4242 case DW_TAG_class_type
:
4243 case DW_TAG_interface_type
:
4244 case DW_TAG_structure_type
:
4245 case DW_TAG_union_type
:
4246 case DW_TAG_enumeration_type
:
4247 case DW_TAG_enumerator
:
4248 case DW_TAG_subprogram
:
4252 case DW_TAG_variable
:
4253 /* We only need to prefix "globally" visible variables. These include
4254 any variable marked with DW_AT_external or any variable that
4255 lives in a namespace. [Variables in anonymous namespaces
4256 require prefixing, but they are not DW_AT_external.] */
4258 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4260 struct dwarf2_cu
*spec_cu
= cu
;
4262 return die_needs_namespace (die_specification (die
, &spec_cu
),
4266 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4267 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4268 && die
->parent
->tag
!= DW_TAG_module
)
4270 /* A variable in a lexical block of some kind does not need a
4271 namespace, even though in C++ such variables may be external
4272 and have a mangled name. */
4273 if (die
->parent
->tag
== DW_TAG_lexical_block
4274 || die
->parent
->tag
== DW_TAG_try_block
4275 || die
->parent
->tag
== DW_TAG_catch_block
4276 || die
->parent
->tag
== DW_TAG_subprogram
)
4285 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4286 compute the physname for the object, which include a method's
4287 formal parameters (C++/Java) and return type (Java).
4289 For Ada, return the DIE's linkage name rather than the fully qualified
4290 name. PHYSNAME is ignored..
4292 The result is allocated on the objfile_obstack and canonicalized. */
4295 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4299 name
= dwarf2_name (die
, cu
);
4301 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4302 compute it by typename_concat inside GDB. */
4303 if (cu
->language
== language_ada
4304 || (cu
->language
== language_fortran
&& physname
))
4306 /* For Ada unit, we prefer the linkage name over the name, as
4307 the former contains the exported name, which the user expects
4308 to be able to reference. Ideally, we want the user to be able
4309 to reference this entity using either natural or linkage name,
4310 but we haven't started looking at this enhancement yet. */
4311 struct attribute
*attr
;
4313 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4315 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4316 if (attr
&& DW_STRING (attr
))
4317 return DW_STRING (attr
);
4320 /* These are the only languages we know how to qualify names in. */
4322 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4323 || cu
->language
== language_fortran
))
4325 if (die_needs_namespace (die
, cu
))
4329 struct ui_file
*buf
;
4331 prefix
= determine_prefix (die
, cu
);
4332 buf
= mem_fileopen ();
4333 if (*prefix
!= '\0')
4335 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4338 fputs_unfiltered (prefixed_name
, buf
);
4339 xfree (prefixed_name
);
4342 fputs_unfiltered (name
? name
: "", buf
);
4344 /* For Java and C++ methods, append formal parameter type
4345 information, if PHYSNAME. */
4347 if (physname
&& die
->tag
== DW_TAG_subprogram
4348 && (cu
->language
== language_cplus
4349 || cu
->language
== language_java
))
4351 struct type
*type
= read_type_die (die
, cu
);
4353 c_type_print_args (type
, buf
, 0, cu
->language
);
4355 if (cu
->language
== language_java
)
4357 /* For java, we must append the return type to method
4359 if (die
->tag
== DW_TAG_subprogram
)
4360 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4363 else if (cu
->language
== language_cplus
)
4365 if (TYPE_NFIELDS (type
) > 0
4366 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4367 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4368 fputs_unfiltered (" const", buf
);
4372 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4374 ui_file_delete (buf
);
4376 if (cu
->language
== language_cplus
)
4379 = dwarf2_canonicalize_name (name
, cu
,
4380 &cu
->objfile
->objfile_obstack
);
4391 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4392 If scope qualifiers are appropriate they will be added. The result
4393 will be allocated on the objfile_obstack, or NULL if the DIE does
4394 not have a name. NAME may either be from a previous call to
4395 dwarf2_name or NULL.
4397 The output string will be canonicalized (if C++/Java). */
4400 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4402 return dwarf2_compute_name (name
, die
, cu
, 0);
4405 /* Construct a physname for the given DIE in CU. NAME may either be
4406 from a previous call to dwarf2_name or NULL. The result will be
4407 allocated on the objfile_objstack or NULL if the DIE does not have a
4410 The output string will be canonicalized (if C++/Java). */
4413 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4415 return dwarf2_compute_name (name
, die
, cu
, 1);
4418 /* Read the import statement specified by the given die and record it. */
4421 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4423 struct attribute
*import_attr
;
4424 struct die_info
*imported_die
;
4425 struct dwarf2_cu
*imported_cu
;
4426 const char *imported_name
;
4427 const char *imported_name_prefix
;
4428 const char *canonical_name
;
4429 const char *import_alias
;
4430 const char *imported_declaration
= NULL
;
4431 const char *import_prefix
;
4435 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4436 if (import_attr
== NULL
)
4438 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4439 dwarf_tag_name (die
->tag
));
4444 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4445 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4446 if (imported_name
== NULL
)
4448 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4450 The import in the following code:
4464 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4465 <52> DW_AT_decl_file : 1
4466 <53> DW_AT_decl_line : 6
4467 <54> DW_AT_import : <0x75>
4468 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4470 <5b> DW_AT_decl_file : 1
4471 <5c> DW_AT_decl_line : 2
4472 <5d> DW_AT_type : <0x6e>
4474 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4475 <76> DW_AT_byte_size : 4
4476 <77> DW_AT_encoding : 5 (signed)
4478 imports the wrong die ( 0x75 instead of 0x58 ).
4479 This case will be ignored until the gcc bug is fixed. */
4483 /* Figure out the local name after import. */
4484 import_alias
= dwarf2_name (die
, cu
);
4486 /* Figure out where the statement is being imported to. */
4487 import_prefix
= determine_prefix (die
, cu
);
4489 /* Figure out what the scope of the imported die is and prepend it
4490 to the name of the imported die. */
4491 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4493 if (imported_die
->tag
!= DW_TAG_namespace
4494 && imported_die
->tag
!= DW_TAG_module
)
4496 imported_declaration
= imported_name
;
4497 canonical_name
= imported_name_prefix
;
4499 else if (strlen (imported_name_prefix
) > 0)
4501 temp
= alloca (strlen (imported_name_prefix
)
4502 + 2 + strlen (imported_name
) + 1);
4503 strcpy (temp
, imported_name_prefix
);
4504 strcat (temp
, "::");
4505 strcat (temp
, imported_name
);
4506 canonical_name
= temp
;
4509 canonical_name
= imported_name
;
4511 cp_add_using_directive (import_prefix
,
4514 imported_declaration
,
4515 &cu
->objfile
->objfile_obstack
);
4519 initialize_cu_func_list (struct dwarf2_cu
*cu
)
4521 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
4525 free_cu_line_header (void *arg
)
4527 struct dwarf2_cu
*cu
= arg
;
4529 free_line_header (cu
->line_header
);
4530 cu
->line_header
= NULL
;
4534 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
4535 char **name
, char **comp_dir
)
4537 struct attribute
*attr
;
4542 /* Find the filename. Do not use dwarf2_name here, since the filename
4543 is not a source language identifier. */
4544 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4547 *name
= DW_STRING (attr
);
4550 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
4552 *comp_dir
= DW_STRING (attr
);
4553 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
4555 *comp_dir
= ldirname (*name
);
4556 if (*comp_dir
!= NULL
)
4557 make_cleanup (xfree
, *comp_dir
);
4559 if (*comp_dir
!= NULL
)
4561 /* Irix 6.2 native cc prepends <machine>.: to the compilation
4562 directory, get rid of it. */
4563 char *cp
= strchr (*comp_dir
, ':');
4565 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
4570 *name
= "<unknown>";
4574 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4576 struct objfile
*objfile
= cu
->objfile
;
4577 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4578 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
4579 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
4580 struct attribute
*attr
;
4582 char *comp_dir
= NULL
;
4583 struct die_info
*child_die
;
4584 bfd
*abfd
= objfile
->obfd
;
4585 struct line_header
*line_header
= 0;
4588 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4590 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
4592 /* If we didn't find a lowpc, set it to highpc to avoid complaints
4593 from finish_block. */
4594 if (lowpc
== ((CORE_ADDR
) -1))
4599 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
4601 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
4604 set_cu_language (DW_UNSND (attr
), cu
);
4607 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
4609 cu
->producer
= DW_STRING (attr
);
4611 /* We assume that we're processing GCC output. */
4612 processing_gcc_compilation
= 2;
4614 processing_has_namespace_info
= 0;
4616 start_symtab (name
, comp_dir
, lowpc
);
4617 record_debugformat ("DWARF 2");
4618 record_producer (cu
->producer
);
4620 initialize_cu_func_list (cu
);
4622 /* Decode line number information if present. We do this before
4623 processing child DIEs, so that the line header table is available
4624 for DW_AT_decl_file. */
4625 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4628 unsigned int line_offset
= DW_UNSND (attr
);
4629 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
4632 cu
->line_header
= line_header
;
4633 make_cleanup (free_cu_line_header
, cu
);
4634 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
4638 /* Process all dies in compilation unit. */
4639 if (die
->child
!= NULL
)
4641 child_die
= die
->child
;
4642 while (child_die
&& child_die
->tag
)
4644 process_die (child_die
, cu
);
4645 child_die
= sibling_die (child_die
);
4649 /* Decode macro information, if present. Dwarf 2 macro information
4650 refers to information in the line number info statement program
4651 header, so we can only read it if we've read the header
4653 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
4654 if (attr
&& line_header
)
4656 unsigned int macro_offset
= DW_UNSND (attr
);
4658 dwarf_decode_macros (line_header
, macro_offset
,
4659 comp_dir
, abfd
, cu
);
4661 do_cleanups (back_to
);
4664 /* For TUs we want to skip the first top level sibling if it's not the
4665 actual type being defined by this TU. In this case the first top
4666 level sibling is there to provide context only. */
4669 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4671 struct objfile
*objfile
= cu
->objfile
;
4672 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4674 struct attribute
*attr
;
4676 char *comp_dir
= NULL
;
4677 struct die_info
*child_die
;
4678 bfd
*abfd
= objfile
->obfd
;
4680 /* start_symtab needs a low pc, but we don't really have one.
4681 Do what read_file_scope would do in the absence of such info. */
4682 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4684 /* Find the filename. Do not use dwarf2_name here, since the filename
4685 is not a source language identifier. */
4686 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4688 name
= DW_STRING (attr
);
4690 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
4692 comp_dir
= DW_STRING (attr
);
4693 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
4695 comp_dir
= ldirname (name
);
4696 if (comp_dir
!= NULL
)
4697 make_cleanup (xfree
, comp_dir
);
4703 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
4705 set_cu_language (DW_UNSND (attr
), cu
);
4707 /* This isn't technically needed today. It is done for symmetry
4708 with read_file_scope. */
4709 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
4711 cu
->producer
= DW_STRING (attr
);
4713 /* We assume that we're processing GCC output. */
4714 processing_gcc_compilation
= 2;
4716 processing_has_namespace_info
= 0;
4718 start_symtab (name
, comp_dir
, lowpc
);
4719 record_debugformat ("DWARF 2");
4720 record_producer (cu
->producer
);
4722 /* Process the dies in the type unit. */
4723 if (die
->child
== NULL
)
4725 dump_die_for_error (die
);
4726 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
4727 bfd_get_filename (abfd
));
4730 child_die
= die
->child
;
4732 while (child_die
&& child_die
->tag
)
4734 process_die (child_die
, cu
);
4736 child_die
= sibling_die (child_die
);
4739 do_cleanups (back_to
);
4743 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
4744 struct dwarf2_cu
*cu
)
4746 struct function_range
*thisfn
;
4748 thisfn
= (struct function_range
*)
4749 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
4750 thisfn
->name
= name
;
4751 thisfn
->lowpc
= lowpc
;
4752 thisfn
->highpc
= highpc
;
4753 thisfn
->seen_line
= 0;
4754 thisfn
->next
= NULL
;
4756 if (cu
->last_fn
== NULL
)
4757 cu
->first_fn
= thisfn
;
4759 cu
->last_fn
->next
= thisfn
;
4761 cu
->last_fn
= thisfn
;
4764 /* qsort helper for inherit_abstract_dies. */
4767 unsigned_int_compar (const void *ap
, const void *bp
)
4769 unsigned int a
= *(unsigned int *) ap
;
4770 unsigned int b
= *(unsigned int *) bp
;
4772 return (a
> b
) - (b
> a
);
4775 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
4776 Inherit only the children of the DW_AT_abstract_origin DIE not being already
4777 referenced by DW_AT_abstract_origin from the children of the current DIE. */
4780 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
4782 struct die_info
*child_die
;
4783 unsigned die_children_count
;
4784 /* CU offsets which were referenced by children of the current DIE. */
4786 unsigned *offsets_end
, *offsetp
;
4787 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
4788 struct die_info
*origin_die
;
4789 /* Iterator of the ORIGIN_DIE children. */
4790 struct die_info
*origin_child_die
;
4791 struct cleanup
*cleanups
;
4792 struct attribute
*attr
;
4794 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
4798 origin_die
= follow_die_ref (die
, attr
, &cu
);
4799 if (die
->tag
!= origin_die
->tag
4800 && !(die
->tag
== DW_TAG_inlined_subroutine
4801 && origin_die
->tag
== DW_TAG_subprogram
))
4802 complaint (&symfile_complaints
,
4803 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
4804 die
->offset
, origin_die
->offset
);
4806 child_die
= die
->child
;
4807 die_children_count
= 0;
4808 while (child_die
&& child_die
->tag
)
4810 child_die
= sibling_die (child_die
);
4811 die_children_count
++;
4813 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
4814 cleanups
= make_cleanup (xfree
, offsets
);
4816 offsets_end
= offsets
;
4817 child_die
= die
->child
;
4818 while (child_die
&& child_die
->tag
)
4820 /* For each CHILD_DIE, find the corresponding child of
4821 ORIGIN_DIE. If there is more than one layer of
4822 DW_AT_abstract_origin, follow them all; there shouldn't be,
4823 but GCC versions at least through 4.4 generate this (GCC PR
4825 struct die_info
*child_origin_die
= child_die
;
4829 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
4832 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
4835 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
4836 counterpart may exist. */
4837 if (child_origin_die
!= child_die
)
4839 if (child_die
->tag
!= child_origin_die
->tag
4840 && !(child_die
->tag
== DW_TAG_inlined_subroutine
4841 && child_origin_die
->tag
== DW_TAG_subprogram
))
4842 complaint (&symfile_complaints
,
4843 _("Child DIE 0x%x and its abstract origin 0x%x have "
4844 "different tags"), child_die
->offset
,
4845 child_origin_die
->offset
);
4846 if (child_origin_die
->parent
!= origin_die
)
4847 complaint (&symfile_complaints
,
4848 _("Child DIE 0x%x and its abstract origin 0x%x have "
4849 "different parents"), child_die
->offset
,
4850 child_origin_die
->offset
);
4852 *offsets_end
++ = child_origin_die
->offset
;
4854 child_die
= sibling_die (child_die
);
4856 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
4857 unsigned_int_compar
);
4858 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
4859 if (offsetp
[-1] == *offsetp
)
4860 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
4861 "to DIE 0x%x as their abstract origin"),
4862 die
->offset
, *offsetp
);
4865 origin_child_die
= origin_die
->child
;
4866 while (origin_child_die
&& origin_child_die
->tag
)
4868 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
4869 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
4871 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
4873 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
4874 process_die (origin_child_die
, cu
);
4876 origin_child_die
= sibling_die (origin_child_die
);
4879 do_cleanups (cleanups
);
4883 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4885 struct objfile
*objfile
= cu
->objfile
;
4886 struct context_stack
*new;
4889 struct die_info
*child_die
;
4890 struct attribute
*attr
, *call_line
, *call_file
;
4893 struct block
*block
;
4894 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
4898 /* If we do not have call site information, we can't show the
4899 caller of this inlined function. That's too confusing, so
4900 only use the scope for local variables. */
4901 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
4902 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
4903 if (call_line
== NULL
|| call_file
== NULL
)
4905 read_lexical_block_scope (die
, cu
);
4910 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4912 name
= dwarf2_name (die
, cu
);
4914 /* Ignore functions with missing or empty names. These are actually
4915 illegal according to the DWARF standard. */
4918 complaint (&symfile_complaints
,
4919 _("missing name for subprogram DIE at %d"), die
->offset
);
4923 /* Ignore functions with missing or invalid low and high pc attributes. */
4924 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
4926 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4927 if (!attr
|| !DW_UNSND (attr
))
4928 complaint (&symfile_complaints
,
4929 _("cannot get low and high bounds for subprogram DIE at %d"),
4937 /* Record the function range for dwarf_decode_lines. */
4938 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
4940 new = push_context (0, lowpc
);
4941 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
4943 /* If there is a location expression for DW_AT_frame_base, record
4945 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
4947 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
4948 expression is being recorded directly in the function's symbol
4949 and not in a separate frame-base object. I guess this hack is
4950 to avoid adding some sort of frame-base adjunct/annex to the
4951 function's symbol :-(. The problem with doing this is that it
4952 results in a function symbol with a location expression that
4953 has nothing to do with the location of the function, ouch! The
4954 relationship should be: a function's symbol has-a frame base; a
4955 frame-base has-a location expression. */
4956 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
4958 cu
->list_in_scope
= &local_symbols
;
4960 if (die
->child
!= NULL
)
4962 child_die
= die
->child
;
4963 while (child_die
&& child_die
->tag
)
4965 process_die (child_die
, cu
);
4966 child_die
= sibling_die (child_die
);
4970 inherit_abstract_dies (die
, cu
);
4972 /* If we have a DW_AT_specification, we might need to import using
4973 directives from the context of the specification DIE. See the
4974 comment in determine_prefix. */
4975 if (cu
->language
== language_cplus
4976 && dwarf2_attr (die
, DW_AT_specification
, cu
))
4978 struct dwarf2_cu
*spec_cu
= cu
;
4979 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
4983 child_die
= spec_die
->child
;
4984 while (child_die
&& child_die
->tag
)
4986 if (child_die
->tag
== DW_TAG_imported_module
)
4987 process_die (child_die
, spec_cu
);
4988 child_die
= sibling_die (child_die
);
4991 /* In some cases, GCC generates specification DIEs that
4992 themselves contain DW_AT_specification attributes. */
4993 spec_die
= die_specification (spec_die
, &spec_cu
);
4997 new = pop_context ();
4998 /* Make a block for the local symbols within. */
4999 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5000 lowpc
, highpc
, objfile
);
5002 /* For C++, set the block's scope. */
5003 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5004 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5005 determine_prefix (die
, cu
),
5006 processing_has_namespace_info
);
5008 /* If we have address ranges, record them. */
5009 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5011 /* In C++, we can have functions nested inside functions (e.g., when
5012 a function declares a class that has methods). This means that
5013 when we finish processing a function scope, we may need to go
5014 back to building a containing block's symbol lists. */
5015 local_symbols
= new->locals
;
5016 param_symbols
= new->params
;
5017 using_directives
= new->using_directives
;
5019 /* If we've finished processing a top-level function, subsequent
5020 symbols go in the file symbol list. */
5021 if (outermost_context_p ())
5022 cu
->list_in_scope
= &file_symbols
;
5025 /* Process all the DIES contained within a lexical block scope. Start
5026 a new scope, process the dies, and then close the scope. */
5029 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5031 struct objfile
*objfile
= cu
->objfile
;
5032 struct context_stack
*new;
5033 CORE_ADDR lowpc
, highpc
;
5034 struct die_info
*child_die
;
5037 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5039 /* Ignore blocks with missing or invalid low and high pc attributes. */
5040 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5041 as multiple lexical blocks? Handling children in a sane way would
5042 be nasty. Might be easier to properly extend generic blocks to
5044 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5049 push_context (0, lowpc
);
5050 if (die
->child
!= NULL
)
5052 child_die
= die
->child
;
5053 while (child_die
&& child_die
->tag
)
5055 process_die (child_die
, cu
);
5056 child_die
= sibling_die (child_die
);
5059 new = pop_context ();
5061 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5064 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5067 /* Note that recording ranges after traversing children, as we
5068 do here, means that recording a parent's ranges entails
5069 walking across all its children's ranges as they appear in
5070 the address map, which is quadratic behavior.
5072 It would be nicer to record the parent's ranges before
5073 traversing its children, simply overriding whatever you find
5074 there. But since we don't even decide whether to create a
5075 block until after we've traversed its children, that's hard
5077 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5079 local_symbols
= new->locals
;
5080 using_directives
= new->using_directives
;
5083 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5084 Return 1 if the attributes are present and valid, otherwise, return 0.
5085 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5088 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5089 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5090 struct partial_symtab
*ranges_pst
)
5092 struct objfile
*objfile
= cu
->objfile
;
5093 struct comp_unit_head
*cu_header
= &cu
->header
;
5094 bfd
*obfd
= objfile
->obfd
;
5095 unsigned int addr_size
= cu_header
->addr_size
;
5096 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5097 /* Base address selection entry. */
5108 found_base
= cu
->base_known
;
5109 base
= cu
->base_address
;
5111 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5112 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5114 complaint (&symfile_complaints
,
5115 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5119 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5121 /* Read in the largest possible address. */
5122 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5123 if ((marker
& mask
) == mask
)
5125 /* If we found the largest possible address, then
5126 read the base address. */
5127 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5128 buffer
+= 2 * addr_size
;
5129 offset
+= 2 * addr_size
;
5135 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5139 CORE_ADDR range_beginning
, range_end
;
5141 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5142 buffer
+= addr_size
;
5143 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5144 buffer
+= addr_size
;
5145 offset
+= 2 * addr_size
;
5147 /* An end of list marker is a pair of zero addresses. */
5148 if (range_beginning
== 0 && range_end
== 0)
5149 /* Found the end of list entry. */
5152 /* Each base address selection entry is a pair of 2 values.
5153 The first is the largest possible address, the second is
5154 the base address. Check for a base address here. */
5155 if ((range_beginning
& mask
) == mask
)
5157 /* If we found the largest possible address, then
5158 read the base address. */
5159 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5166 /* We have no valid base address for the ranges
5168 complaint (&symfile_complaints
,
5169 _("Invalid .debug_ranges data (no base address)"));
5173 range_beginning
+= base
;
5176 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5177 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5178 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5181 /* FIXME: This is recording everything as a low-high
5182 segment of consecutive addresses. We should have a
5183 data structure for discontiguous block ranges
5187 low
= range_beginning
;
5193 if (range_beginning
< low
)
5194 low
= range_beginning
;
5195 if (range_end
> high
)
5201 /* If the first entry is an end-of-list marker, the range
5202 describes an empty scope, i.e. no instructions. */
5208 *high_return
= high
;
5212 /* Get low and high pc attributes from a die. Return 1 if the attributes
5213 are present and valid, otherwise, return 0. Return -1 if the range is
5214 discontinuous, i.e. derived from DW_AT_ranges information. */
5216 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5217 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5218 struct partial_symtab
*pst
)
5220 struct attribute
*attr
;
5225 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5228 high
= DW_ADDR (attr
);
5229 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5231 low
= DW_ADDR (attr
);
5233 /* Found high w/o low attribute. */
5236 /* Found consecutive range of addresses. */
5241 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5244 /* Value of the DW_AT_ranges attribute is the offset in the
5245 .debug_ranges section. */
5246 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5248 /* Found discontinuous range of addresses. */
5256 /* When using the GNU linker, .gnu.linkonce. sections are used to
5257 eliminate duplicate copies of functions and vtables and such.
5258 The linker will arbitrarily choose one and discard the others.
5259 The AT_*_pc values for such functions refer to local labels in
5260 these sections. If the section from that file was discarded, the
5261 labels are not in the output, so the relocs get a value of 0.
5262 If this is a discarded function, mark the pc bounds as invalid,
5263 so that GDB will ignore it. */
5264 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5272 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5273 its low and high PC addresses. Do nothing if these addresses could not
5274 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5275 and HIGHPC to the high address if greater than HIGHPC. */
5278 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5279 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5280 struct dwarf2_cu
*cu
)
5282 CORE_ADDR low
, high
;
5283 struct die_info
*child
= die
->child
;
5285 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5287 *lowpc
= min (*lowpc
, low
);
5288 *highpc
= max (*highpc
, high
);
5291 /* If the language does not allow nested subprograms (either inside
5292 subprograms or lexical blocks), we're done. */
5293 if (cu
->language
!= language_ada
)
5296 /* Check all the children of the given DIE. If it contains nested
5297 subprograms, then check their pc bounds. Likewise, we need to
5298 check lexical blocks as well, as they may also contain subprogram
5300 while (child
&& child
->tag
)
5302 if (child
->tag
== DW_TAG_subprogram
5303 || child
->tag
== DW_TAG_lexical_block
)
5304 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5305 child
= sibling_die (child
);
5309 /* Get the low and high pc's represented by the scope DIE, and store
5310 them in *LOWPC and *HIGHPC. If the correct values can't be
5311 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5314 get_scope_pc_bounds (struct die_info
*die
,
5315 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5316 struct dwarf2_cu
*cu
)
5318 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5319 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5320 CORE_ADDR current_low
, current_high
;
5322 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5324 best_low
= current_low
;
5325 best_high
= current_high
;
5329 struct die_info
*child
= die
->child
;
5331 while (child
&& child
->tag
)
5333 switch (child
->tag
) {
5334 case DW_TAG_subprogram
:
5335 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5337 case DW_TAG_namespace
:
5339 /* FIXME: carlton/2004-01-16: Should we do this for
5340 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5341 that current GCC's always emit the DIEs corresponding
5342 to definitions of methods of classes as children of a
5343 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5344 the DIEs giving the declarations, which could be
5345 anywhere). But I don't see any reason why the
5346 standards says that they have to be there. */
5347 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5349 if (current_low
!= ((CORE_ADDR
) -1))
5351 best_low
= min (best_low
, current_low
);
5352 best_high
= max (best_high
, current_high
);
5360 child
= sibling_die (child
);
5365 *highpc
= best_high
;
5368 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5371 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5372 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5374 struct attribute
*attr
;
5376 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5379 CORE_ADDR high
= DW_ADDR (attr
);
5381 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5384 CORE_ADDR low
= DW_ADDR (attr
);
5386 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5390 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5393 bfd
*obfd
= cu
->objfile
->obfd
;
5395 /* The value of the DW_AT_ranges attribute is the offset of the
5396 address range list in the .debug_ranges section. */
5397 unsigned long offset
= DW_UNSND (attr
);
5398 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5400 /* For some target architectures, but not others, the
5401 read_address function sign-extends the addresses it returns.
5402 To recognize base address selection entries, we need a
5404 unsigned int addr_size
= cu
->header
.addr_size
;
5405 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5407 /* The base address, to which the next pair is relative. Note
5408 that this 'base' is a DWARF concept: most entries in a range
5409 list are relative, to reduce the number of relocs against the
5410 debugging information. This is separate from this function's
5411 'baseaddr' argument, which GDB uses to relocate debugging
5412 information from a shared library based on the address at
5413 which the library was loaded. */
5414 CORE_ADDR base
= cu
->base_address
;
5415 int base_known
= cu
->base_known
;
5417 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5418 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5420 complaint (&symfile_complaints
,
5421 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5428 unsigned int bytes_read
;
5429 CORE_ADDR start
, end
;
5431 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5432 buffer
+= bytes_read
;
5433 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5434 buffer
+= bytes_read
;
5436 /* Did we find the end of the range list? */
5437 if (start
== 0 && end
== 0)
5440 /* Did we find a base address selection entry? */
5441 else if ((start
& base_select_mask
) == base_select_mask
)
5447 /* We found an ordinary address range. */
5452 complaint (&symfile_complaints
,
5453 _("Invalid .debug_ranges data (no base address)"));
5457 record_block_range (block
,
5458 baseaddr
+ base
+ start
,
5459 baseaddr
+ base
+ end
- 1);
5465 /* Add an aggregate field to the field list. */
5468 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
5469 struct dwarf2_cu
*cu
)
5471 struct objfile
*objfile
= cu
->objfile
;
5472 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5473 struct nextfield
*new_field
;
5474 struct attribute
*attr
;
5476 char *fieldname
= "";
5478 /* Allocate a new field list entry and link it in. */
5479 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
5480 make_cleanup (xfree
, new_field
);
5481 memset (new_field
, 0, sizeof (struct nextfield
));
5483 if (die
->tag
== DW_TAG_inheritance
)
5485 new_field
->next
= fip
->baseclasses
;
5486 fip
->baseclasses
= new_field
;
5490 new_field
->next
= fip
->fields
;
5491 fip
->fields
= new_field
;
5495 /* Handle accessibility and virtuality of field.
5496 The default accessibility for members is public, the default
5497 accessibility for inheritance is private. */
5498 if (die
->tag
!= DW_TAG_inheritance
)
5499 new_field
->accessibility
= DW_ACCESS_public
;
5501 new_field
->accessibility
= DW_ACCESS_private
;
5502 new_field
->virtuality
= DW_VIRTUALITY_none
;
5504 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
5506 new_field
->accessibility
= DW_UNSND (attr
);
5507 if (new_field
->accessibility
!= DW_ACCESS_public
)
5508 fip
->non_public_fields
= 1;
5509 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
5511 new_field
->virtuality
= DW_UNSND (attr
);
5513 fp
= &new_field
->field
;
5515 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
5517 /* Data member other than a C++ static data member. */
5519 /* Get type of field. */
5520 fp
->type
= die_type (die
, cu
);
5522 SET_FIELD_BITPOS (*fp
, 0);
5524 /* Get bit size of field (zero if none). */
5525 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
5528 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
5532 FIELD_BITSIZE (*fp
) = 0;
5535 /* Get bit offset of field. */
5536 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
5539 int byte_offset
= 0;
5541 if (attr_form_is_section_offset (attr
))
5542 dwarf2_complex_location_expr_complaint ();
5543 else if (attr_form_is_constant (attr
))
5544 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5545 else if (attr_form_is_block (attr
))
5546 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5548 dwarf2_complex_location_expr_complaint ();
5550 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
5552 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
5555 if (gdbarch_bits_big_endian (gdbarch
))
5557 /* For big endian bits, the DW_AT_bit_offset gives the
5558 additional bit offset from the MSB of the containing
5559 anonymous object to the MSB of the field. We don't
5560 have to do anything special since we don't need to
5561 know the size of the anonymous object. */
5562 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
5566 /* For little endian bits, compute the bit offset to the
5567 MSB of the anonymous object, subtract off the number of
5568 bits from the MSB of the field to the MSB of the
5569 object, and then subtract off the number of bits of
5570 the field itself. The result is the bit offset of
5571 the LSB of the field. */
5573 int bit_offset
= DW_UNSND (attr
);
5575 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5578 /* The size of the anonymous object containing
5579 the bit field is explicit, so use the
5580 indicated size (in bytes). */
5581 anonymous_size
= DW_UNSND (attr
);
5585 /* The size of the anonymous object containing
5586 the bit field must be inferred from the type
5587 attribute of the data member containing the
5589 anonymous_size
= TYPE_LENGTH (fp
->type
);
5591 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
5592 - bit_offset
- FIELD_BITSIZE (*fp
);
5596 /* Get name of field. */
5597 fieldname
= dwarf2_name (die
, cu
);
5598 if (fieldname
== NULL
)
5601 /* The name is already allocated along with this objfile, so we don't
5602 need to duplicate it for the type. */
5603 fp
->name
= fieldname
;
5605 /* Change accessibility for artificial fields (e.g. virtual table
5606 pointer or virtual base class pointer) to private. */
5607 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
5609 FIELD_ARTIFICIAL (*fp
) = 1;
5610 new_field
->accessibility
= DW_ACCESS_private
;
5611 fip
->non_public_fields
= 1;
5614 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
5616 /* C++ static member. */
5618 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
5619 is a declaration, but all versions of G++ as of this writing
5620 (so through at least 3.2.1) incorrectly generate
5621 DW_TAG_variable tags. */
5625 /* Get name of field. */
5626 fieldname
= dwarf2_name (die
, cu
);
5627 if (fieldname
== NULL
)
5630 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5632 /* Only create a symbol if this is an external value.
5633 new_symbol checks this and puts the value in the global symbol
5634 table, which we want. If it is not external, new_symbol
5635 will try to put the value in cu->list_in_scope which is wrong. */
5636 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
5638 /* A static const member, not much different than an enum as far as
5639 we're concerned, except that we can support more types. */
5640 new_symbol (die
, NULL
, cu
);
5643 /* Get physical name. */
5644 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
5646 /* The name is already allocated along with this objfile, so we don't
5647 need to duplicate it for the type. */
5648 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
5649 FIELD_TYPE (*fp
) = die_type (die
, cu
);
5650 FIELD_NAME (*fp
) = fieldname
;
5652 else if (die
->tag
== DW_TAG_inheritance
)
5654 /* C++ base class field. */
5655 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
5658 int byte_offset
= 0;
5660 if (attr_form_is_section_offset (attr
))
5661 dwarf2_complex_location_expr_complaint ();
5662 else if (attr_form_is_constant (attr
))
5663 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5664 else if (attr_form_is_block (attr
))
5665 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5667 dwarf2_complex_location_expr_complaint ();
5669 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
5671 FIELD_BITSIZE (*fp
) = 0;
5672 FIELD_TYPE (*fp
) = die_type (die
, cu
);
5673 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
5674 fip
->nbaseclasses
++;
5678 /* Add a typedef defined in the scope of the FIP's class. */
5681 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
5682 struct dwarf2_cu
*cu
)
5684 struct objfile
*objfile
= cu
->objfile
;
5685 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5686 struct typedef_field_list
*new_field
;
5687 struct attribute
*attr
;
5688 struct typedef_field
*fp
;
5689 char *fieldname
= "";
5691 /* Allocate a new field list entry and link it in. */
5692 new_field
= xzalloc (sizeof (*new_field
));
5693 make_cleanup (xfree
, new_field
);
5695 gdb_assert (die
->tag
== DW_TAG_typedef
);
5697 fp
= &new_field
->field
;
5699 /* Get name of field. */
5700 fp
->name
= dwarf2_name (die
, cu
);
5701 if (fp
->name
== NULL
)
5704 fp
->type
= read_type_die (die
, cu
);
5706 new_field
->next
= fip
->typedef_field_list
;
5707 fip
->typedef_field_list
= new_field
;
5708 fip
->typedef_field_list_count
++;
5711 /* Create the vector of fields, and attach it to the type. */
5714 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
5715 struct dwarf2_cu
*cu
)
5717 int nfields
= fip
->nfields
;
5719 /* Record the field count, allocate space for the array of fields,
5720 and create blank accessibility bitfields if necessary. */
5721 TYPE_NFIELDS (type
) = nfields
;
5722 TYPE_FIELDS (type
) = (struct field
*)
5723 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
5724 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
5726 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
5728 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
5730 TYPE_FIELD_PRIVATE_BITS (type
) =
5731 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
5732 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
5734 TYPE_FIELD_PROTECTED_BITS (type
) =
5735 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
5736 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
5738 TYPE_FIELD_IGNORE_BITS (type
) =
5739 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
5740 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
5743 /* If the type has baseclasses, allocate and clear a bit vector for
5744 TYPE_FIELD_VIRTUAL_BITS. */
5745 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
5747 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
5748 unsigned char *pointer
;
5750 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
5751 pointer
= TYPE_ALLOC (type
, num_bytes
);
5752 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
5753 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
5754 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
5757 /* Copy the saved-up fields into the field vector. Start from the head
5758 of the list, adding to the tail of the field array, so that they end
5759 up in the same order in the array in which they were added to the list. */
5760 while (nfields
-- > 0)
5762 struct nextfield
*fieldp
;
5766 fieldp
= fip
->fields
;
5767 fip
->fields
= fieldp
->next
;
5771 fieldp
= fip
->baseclasses
;
5772 fip
->baseclasses
= fieldp
->next
;
5775 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
5776 switch (fieldp
->accessibility
)
5778 case DW_ACCESS_private
:
5779 if (cu
->language
!= language_ada
)
5780 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
5783 case DW_ACCESS_protected
:
5784 if (cu
->language
!= language_ada
)
5785 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
5788 case DW_ACCESS_public
:
5792 /* Unknown accessibility. Complain and treat it as public. */
5794 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
5795 fieldp
->accessibility
);
5799 if (nfields
< fip
->nbaseclasses
)
5801 switch (fieldp
->virtuality
)
5803 case DW_VIRTUALITY_virtual
:
5804 case DW_VIRTUALITY_pure_virtual
:
5805 if (cu
->language
== language_ada
)
5806 error ("unexpected virtuality in component of Ada type");
5807 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
5814 /* Add a member function to the proper fieldlist. */
5817 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
5818 struct type
*type
, struct dwarf2_cu
*cu
)
5820 struct objfile
*objfile
= cu
->objfile
;
5821 struct attribute
*attr
;
5822 struct fnfieldlist
*flp
;
5824 struct fn_field
*fnp
;
5827 struct nextfnfield
*new_fnfield
;
5828 struct type
*this_type
;
5830 if (cu
->language
== language_ada
)
5831 error ("unexpected member function in Ada type");
5833 /* Get name of member function. */
5834 fieldname
= dwarf2_name (die
, cu
);
5835 if (fieldname
== NULL
)
5838 /* Get the mangled name. */
5839 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
5841 /* Look up member function name in fieldlist. */
5842 for (i
= 0; i
< fip
->nfnfields
; i
++)
5844 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
5848 /* Create new list element if necessary. */
5849 if (i
< fip
->nfnfields
)
5850 flp
= &fip
->fnfieldlists
[i
];
5853 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5855 fip
->fnfieldlists
= (struct fnfieldlist
*)
5856 xrealloc (fip
->fnfieldlists
,
5857 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
5858 * sizeof (struct fnfieldlist
));
5859 if (fip
->nfnfields
== 0)
5860 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
5862 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
5863 flp
->name
= fieldname
;
5869 /* Create a new member function field and chain it to the field list
5871 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
5872 make_cleanup (xfree
, new_fnfield
);
5873 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
5874 new_fnfield
->next
= flp
->head
;
5875 flp
->head
= new_fnfield
;
5878 /* Fill in the member function field info. */
5879 fnp
= &new_fnfield
->fnfield
;
5880 /* The name is already allocated along with this objfile, so we don't
5881 need to duplicate it for the type. */
5882 fnp
->physname
= physname
? physname
: "";
5883 fnp
->type
= alloc_type (objfile
);
5884 this_type
= read_type_die (die
, cu
);
5885 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
5887 int nparams
= TYPE_NFIELDS (this_type
);
5889 /* TYPE is the domain of this method, and THIS_TYPE is the type
5890 of the method itself (TYPE_CODE_METHOD). */
5891 smash_to_method_type (fnp
->type
, type
,
5892 TYPE_TARGET_TYPE (this_type
),
5893 TYPE_FIELDS (this_type
),
5894 TYPE_NFIELDS (this_type
),
5895 TYPE_VARARGS (this_type
));
5897 /* Handle static member functions.
5898 Dwarf2 has no clean way to discern C++ static and non-static
5899 member functions. G++ helps GDB by marking the first
5900 parameter for non-static member functions (which is the
5901 this pointer) as artificial. We obtain this information
5902 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
5903 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
5904 fnp
->voffset
= VOFFSET_STATIC
;
5907 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
5910 /* Get fcontext from DW_AT_containing_type if present. */
5911 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5912 fnp
->fcontext
= die_containing_type (die
, cu
);
5914 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
5915 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
5917 /* Get accessibility. */
5918 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
5921 switch (DW_UNSND (attr
))
5923 case DW_ACCESS_private
:
5924 fnp
->is_private
= 1;
5926 case DW_ACCESS_protected
:
5927 fnp
->is_protected
= 1;
5932 /* Check for artificial methods. */
5933 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
5934 if (attr
&& DW_UNSND (attr
) != 0)
5935 fnp
->is_artificial
= 1;
5937 /* Get index in virtual function table if it is a virtual member
5938 function. For older versions of GCC, this is an offset in the
5939 appropriate virtual table, as specified by DW_AT_containing_type.
5940 For everyone else, it is an expression to be evaluated relative
5941 to the object address. */
5943 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
5946 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
5948 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
5950 /* Old-style GCC. */
5951 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
5953 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
5954 || (DW_BLOCK (attr
)->size
> 1
5955 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
5956 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
5958 struct dwarf_block blk
;
5961 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
5963 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
5964 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
5965 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5966 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
5967 dwarf2_complex_location_expr_complaint ();
5969 fnp
->voffset
/= cu
->header
.addr_size
;
5973 dwarf2_complex_location_expr_complaint ();
5976 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
5978 else if (attr_form_is_section_offset (attr
))
5980 dwarf2_complex_location_expr_complaint ();
5984 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
5990 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
5991 if (attr
&& DW_UNSND (attr
))
5993 /* GCC does this, as of 2008-08-25; PR debug/37237. */
5994 complaint (&symfile_complaints
,
5995 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
5996 fieldname
, die
->offset
);
5997 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
5998 TYPE_CPLUS_DYNAMIC (type
) = 1;
6003 /* Create the vector of member function fields, and attach it to the type. */
6006 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6007 struct dwarf2_cu
*cu
)
6009 struct fnfieldlist
*flp
;
6010 int total_length
= 0;
6013 if (cu
->language
== language_ada
)
6014 error ("unexpected member functions in Ada type");
6016 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6017 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6018 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6020 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6022 struct nextfnfield
*nfp
= flp
->head
;
6023 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6026 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6027 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6028 fn_flp
->fn_fields
= (struct fn_field
*)
6029 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6030 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6031 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6033 total_length
+= flp
->length
;
6036 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6037 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6040 /* Returns non-zero if NAME is the name of a vtable member in CU's
6041 language, zero otherwise. */
6043 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6045 static const char vptr
[] = "_vptr";
6046 static const char vtable
[] = "vtable";
6048 /* Look for the C++ and Java forms of the vtable. */
6049 if ((cu
->language
== language_java
6050 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6051 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6052 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6058 /* GCC outputs unnamed structures that are really pointers to member
6059 functions, with the ABI-specified layout. If TYPE describes
6060 such a structure, smash it into a member function type.
6062 GCC shouldn't do this; it should just output pointer to member DIEs.
6063 This is GCC PR debug/28767. */
6066 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6068 struct type
*pfn_type
, *domain_type
, *new_type
;
6070 /* Check for a structure with no name and two children. */
6071 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6074 /* Check for __pfn and __delta members. */
6075 if (TYPE_FIELD_NAME (type
, 0) == NULL
6076 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6077 || TYPE_FIELD_NAME (type
, 1) == NULL
6078 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6081 /* Find the type of the method. */
6082 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6083 if (pfn_type
== NULL
6084 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6085 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6088 /* Look for the "this" argument. */
6089 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6090 if (TYPE_NFIELDS (pfn_type
) == 0
6091 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6092 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6095 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6096 new_type
= alloc_type (objfile
);
6097 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6098 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6099 TYPE_VARARGS (pfn_type
));
6100 smash_to_methodptr_type (type
, new_type
);
6103 /* Called when we find the DIE that starts a structure or union scope
6104 (definition) to process all dies that define the members of the
6107 NOTE: we need to call struct_type regardless of whether or not the
6108 DIE has an at_name attribute, since it might be an anonymous
6109 structure or union. This gets the type entered into our set of
6112 However, if the structure is incomplete (an opaque struct/union)
6113 then suppress creating a symbol table entry for it since gdb only
6114 wants to find the one with the complete definition. Note that if
6115 it is complete, we just call new_symbol, which does it's own
6116 checking about whether the struct/union is anonymous or not (and
6117 suppresses creating a symbol table entry itself). */
6119 static struct type
*
6120 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6122 struct objfile
*objfile
= cu
->objfile
;
6124 struct attribute
*attr
;
6126 struct cleanup
*back_to
;
6128 /* If the definition of this type lives in .debug_types, read that type.
6129 Don't follow DW_AT_specification though, that will take us back up
6130 the chain and we want to go down. */
6131 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6134 struct dwarf2_cu
*type_cu
= cu
;
6135 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6137 /* We could just recurse on read_structure_type, but we need to call
6138 get_die_type to ensure only one type for this DIE is created.
6139 This is important, for example, because for c++ classes we need
6140 TYPE_NAME set which is only done by new_symbol. Blech. */
6141 type
= read_type_die (type_die
, type_cu
);
6142 return set_die_type (die
, type
, cu
);
6145 back_to
= make_cleanup (null_cleanup
, 0);
6147 type
= alloc_type (objfile
);
6148 INIT_CPLUS_SPECIFIC (type
);
6150 name
= dwarf2_name (die
, cu
);
6153 if (cu
->language
== language_cplus
6154 || cu
->language
== language_java
)
6156 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
6157 if (die
->tag
== DW_TAG_structure_type
6158 || die
->tag
== DW_TAG_class_type
)
6159 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6163 /* The name is already allocated along with this objfile, so
6164 we don't need to duplicate it for the type. */
6165 TYPE_TAG_NAME (type
) = (char *) name
;
6166 if (die
->tag
== DW_TAG_class_type
)
6167 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6171 if (die
->tag
== DW_TAG_structure_type
)
6173 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6175 else if (die
->tag
== DW_TAG_union_type
)
6177 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6181 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6184 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6185 TYPE_DECLARED_CLASS (type
) = 1;
6187 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6190 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6194 TYPE_LENGTH (type
) = 0;
6197 TYPE_STUB_SUPPORTED (type
) = 1;
6198 if (die_is_declaration (die
, cu
))
6199 TYPE_STUB (type
) = 1;
6200 else if (attr
== NULL
&& die
->child
== NULL
6201 && producer_is_realview (cu
->producer
))
6202 /* RealView does not output the required DW_AT_declaration
6203 on incomplete types. */
6204 TYPE_STUB (type
) = 1;
6206 /* We need to add the type field to the die immediately so we don't
6207 infinitely recurse when dealing with pointers to the structure
6208 type within the structure itself. */
6209 set_die_type (die
, type
, cu
);
6211 /* set_die_type should be already done. */
6212 set_descriptive_type (type
, die
, cu
);
6214 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6216 struct field_info fi
;
6217 struct die_info
*child_die
;
6219 memset (&fi
, 0, sizeof (struct field_info
));
6221 child_die
= die
->child
;
6223 while (child_die
&& child_die
->tag
)
6225 if (child_die
->tag
== DW_TAG_member
6226 || child_die
->tag
== DW_TAG_variable
)
6228 /* NOTE: carlton/2002-11-05: A C++ static data member
6229 should be a DW_TAG_member that is a declaration, but
6230 all versions of G++ as of this writing (so through at
6231 least 3.2.1) incorrectly generate DW_TAG_variable
6232 tags for them instead. */
6233 dwarf2_add_field (&fi
, child_die
, cu
);
6235 else if (child_die
->tag
== DW_TAG_subprogram
)
6237 /* C++ member function. */
6238 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6240 else if (child_die
->tag
== DW_TAG_inheritance
)
6242 /* C++ base class field. */
6243 dwarf2_add_field (&fi
, child_die
, cu
);
6245 else if (child_die
->tag
== DW_TAG_typedef
)
6246 dwarf2_add_typedef (&fi
, child_die
, cu
);
6247 child_die
= sibling_die (child_die
);
6250 /* Attach fields and member functions to the type. */
6252 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6255 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6257 /* Get the type which refers to the base class (possibly this
6258 class itself) which contains the vtable pointer for the current
6259 class from the DW_AT_containing_type attribute. This use of
6260 DW_AT_containing_type is a GNU extension. */
6262 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6264 struct type
*t
= die_containing_type (die
, cu
);
6266 TYPE_VPTR_BASETYPE (type
) = t
;
6271 /* Our own class provides vtbl ptr. */
6272 for (i
= TYPE_NFIELDS (t
) - 1;
6273 i
>= TYPE_N_BASECLASSES (t
);
6276 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6278 if (is_vtable_name (fieldname
, cu
))
6280 TYPE_VPTR_FIELDNO (type
) = i
;
6285 /* Complain if virtual function table field not found. */
6286 if (i
< TYPE_N_BASECLASSES (t
))
6287 complaint (&symfile_complaints
,
6288 _("virtual function table pointer not found when defining class '%s'"),
6289 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6294 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6297 else if (cu
->producer
6298 && strncmp (cu
->producer
,
6299 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6301 /* The IBM XLC compiler does not provide direct indication
6302 of the containing type, but the vtable pointer is
6303 always named __vfp. */
6307 for (i
= TYPE_NFIELDS (type
) - 1;
6308 i
>= TYPE_N_BASECLASSES (type
);
6311 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6313 TYPE_VPTR_FIELDNO (type
) = i
;
6314 TYPE_VPTR_BASETYPE (type
) = type
;
6321 /* Copy fi.typedef_field_list linked list elements content into the
6322 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6323 if (fi
.typedef_field_list
)
6325 int i
= fi
.typedef_field_list_count
;
6327 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6328 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6329 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6330 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6332 /* Reverse the list order to keep the debug info elements order. */
6335 struct typedef_field
*dest
, *src
;
6337 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6338 src
= &fi
.typedef_field_list
->field
;
6339 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6345 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6347 do_cleanups (back_to
);
6352 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6354 struct die_info
*child_die
= die
->child
;
6355 struct type
*this_type
;
6357 this_type
= get_die_type (die
, cu
);
6358 if (this_type
== NULL
)
6359 this_type
= read_structure_type (die
, cu
);
6361 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6362 snapshots) has been known to create a die giving a declaration
6363 for a class that has, as a child, a die giving a definition for a
6364 nested class. So we have to process our children even if the
6365 current die is a declaration. Normally, of course, a declaration
6366 won't have any children at all. */
6368 while (child_die
!= NULL
&& child_die
->tag
)
6370 if (child_die
->tag
== DW_TAG_member
6371 || child_die
->tag
== DW_TAG_variable
6372 || child_die
->tag
== DW_TAG_inheritance
)
6377 process_die (child_die
, cu
);
6379 child_die
= sibling_die (child_die
);
6382 /* Do not consider external references. According to the DWARF standard,
6383 these DIEs are identified by the fact that they have no byte_size
6384 attribute, and a declaration attribute. */
6385 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6386 || !die_is_declaration (die
, cu
))
6387 new_symbol (die
, this_type
, cu
);
6390 /* Given a DW_AT_enumeration_type die, set its type. We do not
6391 complete the type's fields yet, or create any symbols. */
6393 static struct type
*
6394 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6396 struct objfile
*objfile
= cu
->objfile
;
6398 struct attribute
*attr
;
6401 /* If the definition of this type lives in .debug_types, read that type.
6402 Don't follow DW_AT_specification though, that will take us back up
6403 the chain and we want to go down. */
6404 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6407 struct dwarf2_cu
*type_cu
= cu
;
6408 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6410 type
= read_type_die (type_die
, type_cu
);
6411 return set_die_type (die
, type
, cu
);
6414 type
= alloc_type (objfile
);
6416 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
6417 name
= dwarf2_full_name (NULL
, die
, cu
);
6419 TYPE_TAG_NAME (type
) = (char *) name
;
6421 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6424 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6428 TYPE_LENGTH (type
) = 0;
6431 /* The enumeration DIE can be incomplete. In Ada, any type can be
6432 declared as private in the package spec, and then defined only
6433 inside the package body. Such types are known as Taft Amendment
6434 Types. When another package uses such a type, an incomplete DIE
6435 may be generated by the compiler. */
6436 if (die_is_declaration (die
, cu
))
6437 TYPE_STUB (type
) = 1;
6439 return set_die_type (die
, type
, cu
);
6442 /* Given a pointer to a die which begins an enumeration, process all
6443 the dies that define the members of the enumeration, and create the
6444 symbol for the enumeration type.
6446 NOTE: We reverse the order of the element list. */
6449 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6451 struct die_info
*child_die
;
6452 struct field
*fields
;
6455 int unsigned_enum
= 1;
6457 struct type
*this_type
;
6461 this_type
= get_die_type (die
, cu
);
6462 if (this_type
== NULL
)
6463 this_type
= read_enumeration_type (die
, cu
);
6464 if (die
->child
!= NULL
)
6466 child_die
= die
->child
;
6467 while (child_die
&& child_die
->tag
)
6469 if (child_die
->tag
!= DW_TAG_enumerator
)
6471 process_die (child_die
, cu
);
6475 name
= dwarf2_name (child_die
, cu
);
6478 sym
= new_symbol (child_die
, this_type
, cu
);
6479 if (SYMBOL_VALUE (sym
) < 0)
6482 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6484 fields
= (struct field
*)
6486 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
6487 * sizeof (struct field
));
6490 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
6491 FIELD_TYPE (fields
[num_fields
]) = NULL
;
6492 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
6493 FIELD_BITSIZE (fields
[num_fields
]) = 0;
6499 child_die
= sibling_die (child_die
);
6504 TYPE_NFIELDS (this_type
) = num_fields
;
6505 TYPE_FIELDS (this_type
) = (struct field
*)
6506 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
6507 memcpy (TYPE_FIELDS (this_type
), fields
,
6508 sizeof (struct field
) * num_fields
);
6512 TYPE_UNSIGNED (this_type
) = 1;
6515 new_symbol (die
, this_type
, cu
);
6518 /* Extract all information from a DW_TAG_array_type DIE and put it in
6519 the DIE's type field. For now, this only handles one dimensional
6522 static struct type
*
6523 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6525 struct objfile
*objfile
= cu
->objfile
;
6526 struct die_info
*child_die
;
6528 struct type
*element_type
, *range_type
, *index_type
;
6529 struct type
**range_types
= NULL
;
6530 struct attribute
*attr
;
6532 struct cleanup
*back_to
;
6535 element_type
= die_type (die
, cu
);
6537 /* The die_type call above may have already set the type for this DIE. */
6538 type
= get_die_type (die
, cu
);
6542 /* Irix 6.2 native cc creates array types without children for
6543 arrays with unspecified length. */
6544 if (die
->child
== NULL
)
6546 index_type
= objfile_type (objfile
)->builtin_int
;
6547 range_type
= create_range_type (NULL
, index_type
, 0, -1);
6548 type
= create_array_type (NULL
, element_type
, range_type
);
6549 return set_die_type (die
, type
, cu
);
6552 back_to
= make_cleanup (null_cleanup
, NULL
);
6553 child_die
= die
->child
;
6554 while (child_die
&& child_die
->tag
)
6556 if (child_die
->tag
== DW_TAG_subrange_type
)
6558 struct type
*child_type
= read_type_die (child_die
, cu
);
6560 if (child_type
!= NULL
)
6562 /* The range type was succesfully read. Save it for
6563 the array type creation. */
6564 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
6566 range_types
= (struct type
**)
6567 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
6568 * sizeof (struct type
*));
6570 make_cleanup (free_current_contents
, &range_types
);
6572 range_types
[ndim
++] = child_type
;
6575 child_die
= sibling_die (child_die
);
6578 /* Dwarf2 dimensions are output from left to right, create the
6579 necessary array types in backwards order. */
6581 type
= element_type
;
6583 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
6588 type
= create_array_type (NULL
, type
, range_types
[i
++]);
6593 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
6596 /* Understand Dwarf2 support for vector types (like they occur on
6597 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
6598 array type. This is not part of the Dwarf2/3 standard yet, but a
6599 custom vendor extension. The main difference between a regular
6600 array and the vector variant is that vectors are passed by value
6602 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
6604 make_vector_type (type
);
6606 name
= dwarf2_name (die
, cu
);
6608 TYPE_NAME (type
) = name
;
6610 /* Install the type in the die. */
6611 set_die_type (die
, type
, cu
);
6613 /* set_die_type should be already done. */
6614 set_descriptive_type (type
, die
, cu
);
6616 do_cleanups (back_to
);
6621 static enum dwarf_array_dim_ordering
6622 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
6624 struct attribute
*attr
;
6626 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
6628 if (attr
) return DW_SND (attr
);
6631 GNU F77 is a special case, as at 08/2004 array type info is the
6632 opposite order to the dwarf2 specification, but data is still
6633 laid out as per normal fortran.
6635 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
6639 if (cu
->language
== language_fortran
6640 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
6642 return DW_ORD_row_major
;
6645 switch (cu
->language_defn
->la_array_ordering
)
6647 case array_column_major
:
6648 return DW_ORD_col_major
;
6649 case array_row_major
:
6651 return DW_ORD_row_major
;
6655 /* Extract all information from a DW_TAG_set_type DIE and put it in
6656 the DIE's type field. */
6658 static struct type
*
6659 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6661 struct type
*domain_type
, *set_type
;
6662 struct attribute
*attr
;
6664 domain_type
= die_type (die
, cu
);
6666 /* The die_type call above may have already set the type for this DIE. */
6667 set_type
= get_die_type (die
, cu
);
6671 set_type
= create_set_type (NULL
, domain_type
);
6673 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6675 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
6677 return set_die_type (die
, set_type
, cu
);
6680 /* First cut: install each common block member as a global variable. */
6683 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
6685 struct die_info
*child_die
;
6686 struct attribute
*attr
;
6688 CORE_ADDR base
= (CORE_ADDR
) 0;
6690 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6693 /* Support the .debug_loc offsets */
6694 if (attr_form_is_block (attr
))
6696 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
6698 else if (attr_form_is_section_offset (attr
))
6700 dwarf2_complex_location_expr_complaint ();
6704 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6705 "common block member");
6708 if (die
->child
!= NULL
)
6710 child_die
= die
->child
;
6711 while (child_die
&& child_die
->tag
)
6713 sym
= new_symbol (child_die
, NULL
, cu
);
6714 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
6717 CORE_ADDR byte_offset
= 0;
6719 if (attr_form_is_section_offset (attr
))
6720 dwarf2_complex_location_expr_complaint ();
6721 else if (attr_form_is_constant (attr
))
6722 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6723 else if (attr_form_is_block (attr
))
6724 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6726 dwarf2_complex_location_expr_complaint ();
6728 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
6729 add_symbol_to_list (sym
, &global_symbols
);
6731 child_die
= sibling_die (child_die
);
6736 /* Create a type for a C++ namespace. */
6738 static struct type
*
6739 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6741 struct objfile
*objfile
= cu
->objfile
;
6742 const char *previous_prefix
, *name
;
6746 /* For extensions, reuse the type of the original namespace. */
6747 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
6749 struct die_info
*ext_die
;
6750 struct dwarf2_cu
*ext_cu
= cu
;
6752 ext_die
= dwarf2_extension (die
, &ext_cu
);
6753 type
= read_type_die (ext_die
, ext_cu
);
6754 return set_die_type (die
, type
, cu
);
6757 name
= namespace_name (die
, &is_anonymous
, cu
);
6759 /* Now build the name of the current namespace. */
6761 previous_prefix
= determine_prefix (die
, cu
);
6762 if (previous_prefix
[0] != '\0')
6763 name
= typename_concat (&objfile
->objfile_obstack
,
6764 previous_prefix
, name
, 0, cu
);
6766 /* Create the type. */
6767 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
6769 TYPE_NAME (type
) = (char *) name
;
6770 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6772 return set_die_type (die
, type
, cu
);
6775 /* Read a C++ namespace. */
6778 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6780 struct objfile
*objfile
= cu
->objfile
;
6784 /* Add a symbol associated to this if we haven't seen the namespace
6785 before. Also, add a using directive if it's an anonymous
6788 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
6792 type
= read_type_die (die
, cu
);
6793 new_symbol (die
, type
, cu
);
6795 name
= namespace_name (die
, &is_anonymous
, cu
);
6798 const char *previous_prefix
= determine_prefix (die
, cu
);
6800 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
6801 NULL
, &objfile
->objfile_obstack
);
6805 if (die
->child
!= NULL
)
6807 struct die_info
*child_die
= die
->child
;
6809 while (child_die
&& child_die
->tag
)
6811 process_die (child_die
, cu
);
6812 child_die
= sibling_die (child_die
);
6817 /* Read a Fortran module as type. This DIE can be only a declaration used for
6818 imported module. Still we need that type as local Fortran "use ... only"
6819 declaration imports depend on the created type in determine_prefix. */
6821 static struct type
*
6822 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6824 struct objfile
*objfile
= cu
->objfile
;
6828 module_name
= dwarf2_name (die
, cu
);
6830 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
6832 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
6834 /* determine_prefix uses TYPE_TAG_NAME. */
6835 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6837 return set_die_type (die
, type
, cu
);
6840 /* Read a Fortran module. */
6843 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
6845 struct die_info
*child_die
= die
->child
;
6847 while (child_die
&& child_die
->tag
)
6849 process_die (child_die
, cu
);
6850 child_die
= sibling_die (child_die
);
6854 /* Return the name of the namespace represented by DIE. Set
6855 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
6859 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
6861 struct die_info
*current_die
;
6862 const char *name
= NULL
;
6864 /* Loop through the extensions until we find a name. */
6866 for (current_die
= die
;
6867 current_die
!= NULL
;
6868 current_die
= dwarf2_extension (die
, &cu
))
6870 name
= dwarf2_name (current_die
, cu
);
6875 /* Is it an anonymous namespace? */
6877 *is_anonymous
= (name
== NULL
);
6879 name
= "(anonymous namespace)";
6884 /* Extract all information from a DW_TAG_pointer_type DIE and add to
6885 the user defined type vector. */
6887 static struct type
*
6888 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6890 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6891 struct comp_unit_head
*cu_header
= &cu
->header
;
6893 struct attribute
*attr_byte_size
;
6894 struct attribute
*attr_address_class
;
6895 int byte_size
, addr_class
;
6896 struct type
*target_type
;
6898 target_type
= die_type (die
, cu
);
6900 /* The die_type call above may have already set the type for this DIE. */
6901 type
= get_die_type (die
, cu
);
6905 type
= lookup_pointer_type (target_type
);
6907 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6909 byte_size
= DW_UNSND (attr_byte_size
);
6911 byte_size
= cu_header
->addr_size
;
6913 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
6914 if (attr_address_class
)
6915 addr_class
= DW_UNSND (attr_address_class
);
6917 addr_class
= DW_ADDR_none
;
6919 /* If the pointer size or address class is different than the
6920 default, create a type variant marked as such and set the
6921 length accordingly. */
6922 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
6924 if (gdbarch_address_class_type_flags_p (gdbarch
))
6928 type_flags
= gdbarch_address_class_type_flags
6929 (gdbarch
, byte_size
, addr_class
);
6930 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
6932 type
= make_type_with_address_space (type
, type_flags
);
6934 else if (TYPE_LENGTH (type
) != byte_size
)
6936 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
6940 /* Should we also complain about unhandled address classes? */
6944 TYPE_LENGTH (type
) = byte_size
;
6945 return set_die_type (die
, type
, cu
);
6948 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
6949 the user defined type vector. */
6951 static struct type
*
6952 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6955 struct type
*to_type
;
6956 struct type
*domain
;
6958 to_type
= die_type (die
, cu
);
6959 domain
= die_containing_type (die
, cu
);
6961 /* The calls above may have already set the type for this DIE. */
6962 type
= get_die_type (die
, cu
);
6966 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
6967 type
= lookup_methodptr_type (to_type
);
6969 type
= lookup_memberptr_type (to_type
, domain
);
6971 return set_die_type (die
, type
, cu
);
6974 /* Extract all information from a DW_TAG_reference_type DIE and add to
6975 the user defined type vector. */
6977 static struct type
*
6978 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6980 struct comp_unit_head
*cu_header
= &cu
->header
;
6981 struct type
*type
, *target_type
;
6982 struct attribute
*attr
;
6984 target_type
= die_type (die
, cu
);
6986 /* The die_type call above may have already set the type for this DIE. */
6987 type
= get_die_type (die
, cu
);
6991 type
= lookup_reference_type (target_type
);
6992 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6995 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6999 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7001 return set_die_type (die
, type
, cu
);
7004 static struct type
*
7005 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7007 struct type
*base_type
, *cv_type
;
7009 base_type
= die_type (die
, cu
);
7011 /* The die_type call above may have already set the type for this DIE. */
7012 cv_type
= get_die_type (die
, cu
);
7016 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7017 return set_die_type (die
, cv_type
, cu
);
7020 static struct type
*
7021 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7023 struct type
*base_type
, *cv_type
;
7025 base_type
= die_type (die
, cu
);
7027 /* The die_type call above may have already set the type for this DIE. */
7028 cv_type
= get_die_type (die
, cu
);
7032 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7033 return set_die_type (die
, cv_type
, cu
);
7036 /* Extract all information from a DW_TAG_string_type DIE and add to
7037 the user defined type vector. It isn't really a user defined type,
7038 but it behaves like one, with other DIE's using an AT_user_def_type
7039 attribute to reference it. */
7041 static struct type
*
7042 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7044 struct objfile
*objfile
= cu
->objfile
;
7045 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7046 struct type
*type
, *range_type
, *index_type
, *char_type
;
7047 struct attribute
*attr
;
7048 unsigned int length
;
7050 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7053 length
= DW_UNSND (attr
);
7057 /* check for the DW_AT_byte_size attribute */
7058 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7061 length
= DW_UNSND (attr
);
7069 index_type
= objfile_type (objfile
)->builtin_int
;
7070 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7071 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7072 type
= create_string_type (NULL
, char_type
, range_type
);
7074 return set_die_type (die
, type
, cu
);
7077 /* Handle DIES due to C code like:
7081 int (*funcp)(int a, long l);
7085 ('funcp' generates a DW_TAG_subroutine_type DIE)
7088 static struct type
*
7089 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7091 struct type
*type
; /* Type that this function returns */
7092 struct type
*ftype
; /* Function that returns above type */
7093 struct attribute
*attr
;
7095 type
= die_type (die
, cu
);
7097 /* The die_type call above may have already set the type for this DIE. */
7098 ftype
= get_die_type (die
, cu
);
7102 ftype
= lookup_function_type (type
);
7104 /* All functions in C++, Pascal and Java have prototypes. */
7105 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7106 if ((attr
&& (DW_UNSND (attr
) != 0))
7107 || cu
->language
== language_cplus
7108 || cu
->language
== language_java
7109 || cu
->language
== language_pascal
)
7110 TYPE_PROTOTYPED (ftype
) = 1;
7111 else if (producer_is_realview (cu
->producer
))
7112 /* RealView does not emit DW_AT_prototyped. We can not
7113 distinguish prototyped and unprototyped functions; default to
7114 prototyped, since that is more common in modern code (and
7115 RealView warns about unprototyped functions). */
7116 TYPE_PROTOTYPED (ftype
) = 1;
7118 /* Store the calling convention in the type if it's available in
7119 the subroutine die. Otherwise set the calling convention to
7120 the default value DW_CC_normal. */
7121 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7122 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7124 /* We need to add the subroutine type to the die immediately so
7125 we don't infinitely recurse when dealing with parameters
7126 declared as the same subroutine type. */
7127 set_die_type (die
, ftype
, cu
);
7129 if (die
->child
!= NULL
)
7131 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7132 struct die_info
*child_die
;
7133 int nparams
, iparams
;
7135 /* Count the number of parameters.
7136 FIXME: GDB currently ignores vararg functions, but knows about
7137 vararg member functions. */
7139 child_die
= die
->child
;
7140 while (child_die
&& child_die
->tag
)
7142 if (child_die
->tag
== DW_TAG_formal_parameter
)
7144 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7145 TYPE_VARARGS (ftype
) = 1;
7146 child_die
= sibling_die (child_die
);
7149 /* Allocate storage for parameters and fill them in. */
7150 TYPE_NFIELDS (ftype
) = nparams
;
7151 TYPE_FIELDS (ftype
) = (struct field
*)
7152 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7154 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7155 even if we error out during the parameters reading below. */
7156 for (iparams
= 0; iparams
< nparams
; iparams
++)
7157 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7160 child_die
= die
->child
;
7161 while (child_die
&& child_die
->tag
)
7163 if (child_die
->tag
== DW_TAG_formal_parameter
)
7165 /* Dwarf2 has no clean way to discern C++ static and non-static
7166 member functions. G++ helps GDB by marking the first
7167 parameter for non-static member functions (which is the
7168 this pointer) as artificial. We pass this information
7169 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
7170 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7172 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7175 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7177 /* GCC/43521: In java, the formal parameter
7178 "this" is sometimes not marked with DW_AT_artificial. */
7179 if (cu
->language
== language_java
)
7181 const char *name
= dwarf2_name (child_die
, cu
);
7183 if (name
&& !strcmp (name
, "this"))
7184 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7187 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
7190 child_die
= sibling_die (child_die
);
7197 static struct type
*
7198 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7200 struct objfile
*objfile
= cu
->objfile
;
7201 const char *name
= NULL
;
7202 struct type
*this_type
;
7204 name
= dwarf2_full_name (NULL
, die
, cu
);
7205 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7206 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7207 TYPE_NAME (this_type
) = (char *) name
;
7208 set_die_type (die
, this_type
, cu
);
7209 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7213 /* Find a representation of a given base type and install
7214 it in the TYPE field of the die. */
7216 static struct type
*
7217 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7219 struct objfile
*objfile
= cu
->objfile
;
7221 struct attribute
*attr
;
7222 int encoding
= 0, size
= 0;
7224 enum type_code code
= TYPE_CODE_INT
;
7226 struct type
*target_type
= NULL
;
7228 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7231 encoding
= DW_UNSND (attr
);
7233 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7236 size
= DW_UNSND (attr
);
7238 name
= dwarf2_name (die
, cu
);
7241 complaint (&symfile_complaints
,
7242 _("DW_AT_name missing from DW_TAG_base_type"));
7247 case DW_ATE_address
:
7248 /* Turn DW_ATE_address into a void * pointer. */
7249 code
= TYPE_CODE_PTR
;
7250 type_flags
|= TYPE_FLAG_UNSIGNED
;
7251 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7253 case DW_ATE_boolean
:
7254 code
= TYPE_CODE_BOOL
;
7255 type_flags
|= TYPE_FLAG_UNSIGNED
;
7257 case DW_ATE_complex_float
:
7258 code
= TYPE_CODE_COMPLEX
;
7259 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7261 case DW_ATE_decimal_float
:
7262 code
= TYPE_CODE_DECFLOAT
;
7265 code
= TYPE_CODE_FLT
;
7269 case DW_ATE_unsigned
:
7270 type_flags
|= TYPE_FLAG_UNSIGNED
;
7272 case DW_ATE_signed_char
:
7273 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7274 || cu
->language
== language_pascal
)
7275 code
= TYPE_CODE_CHAR
;
7277 case DW_ATE_unsigned_char
:
7278 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7279 || cu
->language
== language_pascal
)
7280 code
= TYPE_CODE_CHAR
;
7281 type_flags
|= TYPE_FLAG_UNSIGNED
;
7284 /* We just treat this as an integer and then recognize the
7285 type by name elsewhere. */
7289 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7290 dwarf_type_encoding_name (encoding
));
7294 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7295 TYPE_NAME (type
) = name
;
7296 TYPE_TARGET_TYPE (type
) = target_type
;
7298 if (name
&& strcmp (name
, "char") == 0)
7299 TYPE_NOSIGN (type
) = 1;
7301 return set_die_type (die
, type
, cu
);
7304 /* Read the given DW_AT_subrange DIE. */
7306 static struct type
*
7307 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7309 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7310 struct type
*base_type
;
7311 struct type
*range_type
;
7312 struct attribute
*attr
;
7316 LONGEST negative_mask
;
7318 base_type
= die_type (die
, cu
);
7319 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7320 check_typedef (base_type
);
7322 /* The die_type call above may have already set the type for this DIE. */
7323 range_type
= get_die_type (die
, cu
);
7327 if (cu
->language
== language_fortran
)
7329 /* FORTRAN implies a lower bound of 1, if not given. */
7333 /* FIXME: For variable sized arrays either of these could be
7334 a variable rather than a constant value. We'll allow it,
7335 but we don't know how to handle it. */
7336 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
7338 low
= dwarf2_get_attr_constant_value (attr
, 0);
7340 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
7343 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
7345 /* GCC encodes arrays with unspecified or dynamic length
7346 with a DW_FORM_block1 attribute or a reference attribute.
7347 FIXME: GDB does not yet know how to handle dynamic
7348 arrays properly, treat them as arrays with unspecified
7351 FIXME: jimb/2003-09-22: GDB does not really know
7352 how to handle arrays of unspecified length
7353 either; we just represent them as zero-length
7354 arrays. Choose an appropriate upper bound given
7355 the lower bound we've computed above. */
7359 high
= dwarf2_get_attr_constant_value (attr
, 1);
7363 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
7366 int count
= dwarf2_get_attr_constant_value (attr
, 1);
7367 high
= low
+ count
- 1;
7371 /* Dwarf-2 specifications explicitly allows to create subrange types
7372 without specifying a base type.
7373 In that case, the base type must be set to the type of
7374 the lower bound, upper bound or count, in that order, if any of these
7375 three attributes references an object that has a type.
7376 If no base type is found, the Dwarf-2 specifications say that
7377 a signed integer type of size equal to the size of an address should
7379 For the following C code: `extern char gdb_int [];'
7380 GCC produces an empty range DIE.
7381 FIXME: muller/2010-05-28: Possible references to object for low bound,
7382 high bound or count are not yet handled by this code.
7384 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
7386 struct objfile
*objfile
= cu
->objfile
;
7387 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7388 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
7389 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
7391 /* Test "int", "long int", and "long long int" objfile types,
7392 and select the first one having a size above or equal to the
7393 architecture address size. */
7394 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7395 base_type
= int_type
;
7398 int_type
= objfile_type (objfile
)->builtin_long
;
7399 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7400 base_type
= int_type
;
7403 int_type
= objfile_type (objfile
)->builtin_long_long
;
7404 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7405 base_type
= int_type
;
7411 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
7412 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
7413 low
|= negative_mask
;
7414 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
7415 high
|= negative_mask
;
7417 range_type
= create_range_type (NULL
, base_type
, low
, high
);
7419 /* Mark arrays with dynamic length at least as an array of unspecified
7420 length. GDB could check the boundary but before it gets implemented at
7421 least allow accessing the array elements. */
7422 if (attr
&& attr
->form
== DW_FORM_block1
)
7423 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
7425 name
= dwarf2_name (die
, cu
);
7427 TYPE_NAME (range_type
) = name
;
7429 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7431 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
7433 set_die_type (die
, range_type
, cu
);
7435 /* set_die_type should be already done. */
7436 set_descriptive_type (range_type
, die
, cu
);
7441 static struct type
*
7442 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7446 /* For now, we only support the C meaning of an unspecified type: void. */
7448 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
7449 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
7451 return set_die_type (die
, type
, cu
);
7454 /* Trivial hash function for die_info: the hash value of a DIE
7455 is its offset in .debug_info for this objfile. */
7458 die_hash (const void *item
)
7460 const struct die_info
*die
= item
;
7465 /* Trivial comparison function for die_info structures: two DIEs
7466 are equal if they have the same offset. */
7469 die_eq (const void *item_lhs
, const void *item_rhs
)
7471 const struct die_info
*die_lhs
= item_lhs
;
7472 const struct die_info
*die_rhs
= item_rhs
;
7474 return die_lhs
->offset
== die_rhs
->offset
;
7477 /* Read a whole compilation unit into a linked list of dies. */
7479 static struct die_info
*
7480 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7482 struct die_reader_specs reader_specs
;
7484 gdb_assert (cu
->die_hash
== NULL
);
7486 = htab_create_alloc_ex (cu
->header
.length
/ 12,
7490 &cu
->comp_unit_obstack
,
7491 hashtab_obstack_allocate
,
7492 dummy_obstack_deallocate
);
7494 init_cu_die_reader (&reader_specs
, cu
);
7496 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
7499 /* Main entry point for reading a DIE and all children.
7500 Read the DIE and dump it if requested. */
7502 static struct die_info
*
7503 read_die_and_children (const struct die_reader_specs
*reader
,
7505 gdb_byte
**new_info_ptr
,
7506 struct die_info
*parent
)
7508 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
7509 new_info_ptr
, parent
);
7511 if (dwarf2_die_debug
)
7513 fprintf_unfiltered (gdb_stdlog
,
7514 "\nRead die from %s of %s:\n",
7515 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
7517 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
7519 : "unknown section",
7520 reader
->abfd
->filename
);
7521 dump_die (result
, dwarf2_die_debug
);
7527 /* Read a single die and all its descendents. Set the die's sibling
7528 field to NULL; set other fields in the die correctly, and set all
7529 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
7530 location of the info_ptr after reading all of those dies. PARENT
7531 is the parent of the die in question. */
7533 static struct die_info
*
7534 read_die_and_children_1 (const struct die_reader_specs
*reader
,
7536 gdb_byte
**new_info_ptr
,
7537 struct die_info
*parent
)
7539 struct die_info
*die
;
7543 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
7546 *new_info_ptr
= cur_ptr
;
7549 store_in_ref_table (die
, reader
->cu
);
7552 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
7556 *new_info_ptr
= cur_ptr
;
7559 die
->sibling
= NULL
;
7560 die
->parent
= parent
;
7564 /* Read a die, all of its descendents, and all of its siblings; set
7565 all of the fields of all of the dies correctly. Arguments are as
7566 in read_die_and_children. */
7568 static struct die_info
*
7569 read_die_and_siblings (const struct die_reader_specs
*reader
,
7571 gdb_byte
**new_info_ptr
,
7572 struct die_info
*parent
)
7574 struct die_info
*first_die
, *last_sibling
;
7578 first_die
= last_sibling
= NULL
;
7582 struct die_info
*die
7583 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
7587 *new_info_ptr
= cur_ptr
;
7594 last_sibling
->sibling
= die
;
7600 /* Read the die from the .debug_info section buffer. Set DIEP to
7601 point to a newly allocated die with its information, except for its
7602 child, sibling, and parent fields. Set HAS_CHILDREN to tell
7603 whether the die has children or not. */
7606 read_full_die (const struct die_reader_specs
*reader
,
7607 struct die_info
**diep
, gdb_byte
*info_ptr
,
7610 unsigned int abbrev_number
, bytes_read
, i
, offset
;
7611 struct abbrev_info
*abbrev
;
7612 struct die_info
*die
;
7613 struct dwarf2_cu
*cu
= reader
->cu
;
7614 bfd
*abfd
= reader
->abfd
;
7616 offset
= info_ptr
- reader
->buffer
;
7617 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7618 info_ptr
+= bytes_read
;
7626 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
7628 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
7630 bfd_get_filename (abfd
));
7632 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
7633 die
->offset
= offset
;
7634 die
->tag
= abbrev
->tag
;
7635 die
->abbrev
= abbrev_number
;
7637 die
->num_attrs
= abbrev
->num_attrs
;
7639 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
7640 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
7641 abfd
, info_ptr
, cu
);
7644 *has_children
= abbrev
->has_children
;
7648 /* In DWARF version 2, the description of the debugging information is
7649 stored in a separate .debug_abbrev section. Before we read any
7650 dies from a section we read in all abbreviations and install them
7651 in a hash table. This function also sets flags in CU describing
7652 the data found in the abbrev table. */
7655 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
7657 struct comp_unit_head
*cu_header
= &cu
->header
;
7658 gdb_byte
*abbrev_ptr
;
7659 struct abbrev_info
*cur_abbrev
;
7660 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
7661 unsigned int abbrev_form
, hash_number
;
7662 struct attr_abbrev
*cur_attrs
;
7663 unsigned int allocated_attrs
;
7665 /* Initialize dwarf2 abbrevs */
7666 obstack_init (&cu
->abbrev_obstack
);
7667 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
7669 * sizeof (struct abbrev_info
*)));
7670 memset (cu
->dwarf2_abbrevs
, 0,
7671 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
7673 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
7674 &dwarf2_per_objfile
->abbrev
);
7675 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
7676 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7677 abbrev_ptr
+= bytes_read
;
7679 allocated_attrs
= ATTR_ALLOC_CHUNK
;
7680 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
7682 /* loop until we reach an abbrev number of 0 */
7683 while (abbrev_number
)
7685 cur_abbrev
= dwarf_alloc_abbrev (cu
);
7687 /* read in abbrev header */
7688 cur_abbrev
->number
= abbrev_number
;
7689 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7690 abbrev_ptr
+= bytes_read
;
7691 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
7694 if (cur_abbrev
->tag
== DW_TAG_namespace
)
7695 cu
->has_namespace_info
= 1;
7697 /* now read in declarations */
7698 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7699 abbrev_ptr
+= bytes_read
;
7700 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7701 abbrev_ptr
+= bytes_read
;
7704 if (cur_abbrev
->num_attrs
== allocated_attrs
)
7706 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
7708 = xrealloc (cur_attrs
, (allocated_attrs
7709 * sizeof (struct attr_abbrev
)));
7712 /* Record whether this compilation unit might have
7713 inter-compilation-unit references. If we don't know what form
7714 this attribute will have, then it might potentially be a
7715 DW_FORM_ref_addr, so we conservatively expect inter-CU
7718 if (abbrev_form
== DW_FORM_ref_addr
7719 || abbrev_form
== DW_FORM_indirect
)
7720 cu
->has_form_ref_addr
= 1;
7722 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
7723 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
7724 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7725 abbrev_ptr
+= bytes_read
;
7726 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7727 abbrev_ptr
+= bytes_read
;
7730 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
7731 (cur_abbrev
->num_attrs
7732 * sizeof (struct attr_abbrev
)));
7733 memcpy (cur_abbrev
->attrs
, cur_attrs
,
7734 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
7736 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
7737 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
7738 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
7740 /* Get next abbreviation.
7741 Under Irix6 the abbreviations for a compilation unit are not
7742 always properly terminated with an abbrev number of 0.
7743 Exit loop if we encounter an abbreviation which we have
7744 already read (which means we are about to read the abbreviations
7745 for the next compile unit) or if the end of the abbreviation
7746 table is reached. */
7747 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
7748 >= dwarf2_per_objfile
->abbrev
.size
)
7750 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7751 abbrev_ptr
+= bytes_read
;
7752 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
7759 /* Release the memory used by the abbrev table for a compilation unit. */
7762 dwarf2_free_abbrev_table (void *ptr_to_cu
)
7764 struct dwarf2_cu
*cu
= ptr_to_cu
;
7766 obstack_free (&cu
->abbrev_obstack
, NULL
);
7767 cu
->dwarf2_abbrevs
= NULL
;
7770 /* Lookup an abbrev_info structure in the abbrev hash table. */
7772 static struct abbrev_info
*
7773 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
7775 unsigned int hash_number
;
7776 struct abbrev_info
*abbrev
;
7778 hash_number
= number
% ABBREV_HASH_SIZE
;
7779 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
7783 if (abbrev
->number
== number
)
7786 abbrev
= abbrev
->next
;
7791 /* Returns nonzero if TAG represents a type that we might generate a partial
7795 is_type_tag_for_partial (int tag
)
7800 /* Some types that would be reasonable to generate partial symbols for,
7801 that we don't at present. */
7802 case DW_TAG_array_type
:
7803 case DW_TAG_file_type
:
7804 case DW_TAG_ptr_to_member_type
:
7805 case DW_TAG_set_type
:
7806 case DW_TAG_string_type
:
7807 case DW_TAG_subroutine_type
:
7809 case DW_TAG_base_type
:
7810 case DW_TAG_class_type
:
7811 case DW_TAG_interface_type
:
7812 case DW_TAG_enumeration_type
:
7813 case DW_TAG_structure_type
:
7814 case DW_TAG_subrange_type
:
7815 case DW_TAG_typedef
:
7816 case DW_TAG_union_type
:
7823 /* Load all DIEs that are interesting for partial symbols into memory. */
7825 static struct partial_die_info
*
7826 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
7827 int building_psymtab
, struct dwarf2_cu
*cu
)
7829 struct partial_die_info
*part_die
;
7830 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
7831 struct abbrev_info
*abbrev
;
7832 unsigned int bytes_read
;
7833 unsigned int load_all
= 0;
7835 int nesting_level
= 1;
7840 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
7844 = htab_create_alloc_ex (cu
->header
.length
/ 12,
7848 &cu
->comp_unit_obstack
,
7849 hashtab_obstack_allocate
,
7850 dummy_obstack_deallocate
);
7852 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
7853 sizeof (struct partial_die_info
));
7857 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7859 /* A NULL abbrev means the end of a series of children. */
7862 if (--nesting_level
== 0)
7864 /* PART_DIE was probably the last thing allocated on the
7865 comp_unit_obstack, so we could call obstack_free
7866 here. We don't do that because the waste is small,
7867 and will be cleaned up when we're done with this
7868 compilation unit. This way, we're also more robust
7869 against other users of the comp_unit_obstack. */
7872 info_ptr
+= bytes_read
;
7873 last_die
= parent_die
;
7874 parent_die
= parent_die
->die_parent
;
7878 /* Check whether this DIE is interesting enough to save. Normally
7879 we would not be interested in members here, but there may be
7880 later variables referencing them via DW_AT_specification (for
7883 && !is_type_tag_for_partial (abbrev
->tag
)
7884 && abbrev
->tag
!= DW_TAG_enumerator
7885 && abbrev
->tag
!= DW_TAG_subprogram
7886 && abbrev
->tag
!= DW_TAG_lexical_block
7887 && abbrev
->tag
!= DW_TAG_variable
7888 && abbrev
->tag
!= DW_TAG_namespace
7889 && abbrev
->tag
!= DW_TAG_module
7890 && abbrev
->tag
!= DW_TAG_member
)
7892 /* Otherwise we skip to the next sibling, if any. */
7893 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
7897 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
7898 buffer
, info_ptr
, cu
);
7900 /* This two-pass algorithm for processing partial symbols has a
7901 high cost in cache pressure. Thus, handle some simple cases
7902 here which cover the majority of C partial symbols. DIEs
7903 which neither have specification tags in them, nor could have
7904 specification tags elsewhere pointing at them, can simply be
7905 processed and discarded.
7907 This segment is also optional; scan_partial_symbols and
7908 add_partial_symbol will handle these DIEs if we chain
7909 them in normally. When compilers which do not emit large
7910 quantities of duplicate debug information are more common,
7911 this code can probably be removed. */
7913 /* Any complete simple types at the top level (pretty much all
7914 of them, for a language without namespaces), can be processed
7916 if (parent_die
== NULL
7917 && part_die
->has_specification
== 0
7918 && part_die
->is_declaration
== 0
7919 && (part_die
->tag
== DW_TAG_typedef
7920 || part_die
->tag
== DW_TAG_base_type
7921 || part_die
->tag
== DW_TAG_subrange_type
))
7923 if (building_psymtab
&& part_die
->name
!= NULL
)
7924 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
7925 VAR_DOMAIN
, LOC_TYPEDEF
,
7926 &cu
->objfile
->static_psymbols
,
7927 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
7928 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
7932 /* If we're at the second level, and we're an enumerator, and
7933 our parent has no specification (meaning possibly lives in a
7934 namespace elsewhere), then we can add the partial symbol now
7935 instead of queueing it. */
7936 if (part_die
->tag
== DW_TAG_enumerator
7937 && parent_die
!= NULL
7938 && parent_die
->die_parent
== NULL
7939 && parent_die
->tag
== DW_TAG_enumeration_type
7940 && parent_die
->has_specification
== 0)
7942 if (part_die
->name
== NULL
)
7943 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7944 else if (building_psymtab
)
7945 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
7946 VAR_DOMAIN
, LOC_CONST
,
7947 (cu
->language
== language_cplus
7948 || cu
->language
== language_java
)
7949 ? &cu
->objfile
->global_psymbols
7950 : &cu
->objfile
->static_psymbols
,
7951 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
7953 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
7957 /* We'll save this DIE so link it in. */
7958 part_die
->die_parent
= parent_die
;
7959 part_die
->die_sibling
= NULL
;
7960 part_die
->die_child
= NULL
;
7962 if (last_die
&& last_die
== parent_die
)
7963 last_die
->die_child
= part_die
;
7965 last_die
->die_sibling
= part_die
;
7967 last_die
= part_die
;
7969 if (first_die
== NULL
)
7970 first_die
= part_die
;
7972 /* Maybe add the DIE to the hash table. Not all DIEs that we
7973 find interesting need to be in the hash table, because we
7974 also have the parent/sibling/child chains; only those that we
7975 might refer to by offset later during partial symbol reading.
7977 For now this means things that might have be the target of a
7978 DW_AT_specification, DW_AT_abstract_origin, or
7979 DW_AT_extension. DW_AT_extension will refer only to
7980 namespaces; DW_AT_abstract_origin refers to functions (and
7981 many things under the function DIE, but we do not recurse
7982 into function DIEs during partial symbol reading) and
7983 possibly variables as well; DW_AT_specification refers to
7984 declarations. Declarations ought to have the DW_AT_declaration
7985 flag. It happens that GCC forgets to put it in sometimes, but
7986 only for functions, not for types.
7988 Adding more things than necessary to the hash table is harmless
7989 except for the performance cost. Adding too few will result in
7990 wasted time in find_partial_die, when we reread the compilation
7991 unit with load_all_dies set. */
7994 || abbrev
->tag
== DW_TAG_subprogram
7995 || abbrev
->tag
== DW_TAG_variable
7996 || abbrev
->tag
== DW_TAG_namespace
7997 || part_die
->is_declaration
)
8001 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8002 part_die
->offset
, INSERT
);
8006 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8007 sizeof (struct partial_die_info
));
8009 /* For some DIEs we want to follow their children (if any). For C
8010 we have no reason to follow the children of structures; for other
8011 languages we have to, both so that we can get at method physnames
8012 to infer fully qualified class names, and for DW_AT_specification.
8014 For Ada, we need to scan the children of subprograms and lexical
8015 blocks as well because Ada allows the definition of nested
8016 entities that could be interesting for the debugger, such as
8017 nested subprograms for instance. */
8018 if (last_die
->has_children
8020 || last_die
->tag
== DW_TAG_namespace
8021 || last_die
->tag
== DW_TAG_module
8022 || last_die
->tag
== DW_TAG_enumeration_type
8023 || (cu
->language
!= language_c
8024 && (last_die
->tag
== DW_TAG_class_type
8025 || last_die
->tag
== DW_TAG_interface_type
8026 || last_die
->tag
== DW_TAG_structure_type
8027 || last_die
->tag
== DW_TAG_union_type
))
8028 || (cu
->language
== language_ada
8029 && (last_die
->tag
== DW_TAG_subprogram
8030 || last_die
->tag
== DW_TAG_lexical_block
))))
8033 parent_die
= last_die
;
8037 /* Otherwise we skip to the next sibling, if any. */
8038 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8040 /* Back to the top, do it again. */
8044 /* Read a minimal amount of information into the minimal die structure. */
8047 read_partial_die (struct partial_die_info
*part_die
,
8048 struct abbrev_info
*abbrev
,
8049 unsigned int abbrev_len
, bfd
*abfd
,
8050 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8051 struct dwarf2_cu
*cu
)
8054 struct attribute attr
;
8055 int has_low_pc_attr
= 0;
8056 int has_high_pc_attr
= 0;
8058 memset (part_die
, 0, sizeof (struct partial_die_info
));
8060 part_die
->offset
= info_ptr
- buffer
;
8062 info_ptr
+= abbrev_len
;
8067 part_die
->tag
= abbrev
->tag
;
8068 part_die
->has_children
= abbrev
->has_children
;
8070 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8072 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8074 /* Store the data if it is of an attribute we want to keep in a
8075 partial symbol table. */
8079 switch (part_die
->tag
)
8081 case DW_TAG_compile_unit
:
8082 case DW_TAG_type_unit
:
8083 /* Compilation units have a DW_AT_name that is a filename, not
8084 a source language identifier. */
8085 case DW_TAG_enumeration_type
:
8086 case DW_TAG_enumerator
:
8087 /* These tags always have simple identifiers already; no need
8088 to canonicalize them. */
8089 part_die
->name
= DW_STRING (&attr
);
8093 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8094 &cu
->objfile
->objfile_obstack
);
8098 case DW_AT_linkage_name
:
8099 case DW_AT_MIPS_linkage_name
:
8100 /* Note that both forms of linkage name might appear. We
8101 assume they will be the same, and we only store the last
8103 if (cu
->language
== language_ada
)
8104 part_die
->name
= DW_STRING (&attr
);
8107 has_low_pc_attr
= 1;
8108 part_die
->lowpc
= DW_ADDR (&attr
);
8111 has_high_pc_attr
= 1;
8112 part_die
->highpc
= DW_ADDR (&attr
);
8114 case DW_AT_location
:
8115 /* Support the .debug_loc offsets */
8116 if (attr_form_is_block (&attr
))
8118 part_die
->locdesc
= DW_BLOCK (&attr
);
8120 else if (attr_form_is_section_offset (&attr
))
8122 dwarf2_complex_location_expr_complaint ();
8126 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8127 "partial symbol information");
8130 case DW_AT_external
:
8131 part_die
->is_external
= DW_UNSND (&attr
);
8133 case DW_AT_declaration
:
8134 part_die
->is_declaration
= DW_UNSND (&attr
);
8137 part_die
->has_type
= 1;
8139 case DW_AT_abstract_origin
:
8140 case DW_AT_specification
:
8141 case DW_AT_extension
:
8142 part_die
->has_specification
= 1;
8143 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8146 /* Ignore absolute siblings, they might point outside of
8147 the current compile unit. */
8148 if (attr
.form
== DW_FORM_ref_addr
)
8149 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8151 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8153 case DW_AT_byte_size
:
8154 part_die
->has_byte_size
= 1;
8156 case DW_AT_calling_convention
:
8157 /* DWARF doesn't provide a way to identify a program's source-level
8158 entry point. DW_AT_calling_convention attributes are only meant
8159 to describe functions' calling conventions.
8161 However, because it's a necessary piece of information in
8162 Fortran, and because DW_CC_program is the only piece of debugging
8163 information whose definition refers to a 'main program' at all,
8164 several compilers have begun marking Fortran main programs with
8165 DW_CC_program --- even when those functions use the standard
8166 calling conventions.
8168 So until DWARF specifies a way to provide this information and
8169 compilers pick up the new representation, we'll support this
8171 if (DW_UNSND (&attr
) == DW_CC_program
8172 && cu
->language
== language_fortran
)
8173 set_main_name (part_die
->name
);
8180 /* When using the GNU linker, .gnu.linkonce. sections are used to
8181 eliminate duplicate copies of functions and vtables and such.
8182 The linker will arbitrarily choose one and discard the others.
8183 The AT_*_pc values for such functions refer to local labels in
8184 these sections. If the section from that file was discarded, the
8185 labels are not in the output, so the relocs get a value of 0.
8186 If this is a discarded function, mark the pc bounds as invalid,
8187 so that GDB will ignore it. */
8188 if (has_low_pc_attr
&& has_high_pc_attr
8189 && part_die
->lowpc
< part_die
->highpc
8190 && (part_die
->lowpc
!= 0
8191 || dwarf2_per_objfile
->has_section_at_zero
))
8192 part_die
->has_pc_info
= 1;
8197 /* Find a cached partial DIE at OFFSET in CU. */
8199 static struct partial_die_info
*
8200 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8202 struct partial_die_info
*lookup_die
= NULL
;
8203 struct partial_die_info part_die
;
8205 part_die
.offset
= offset
;
8206 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8211 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8212 except in the case of .debug_types DIEs which do not reference
8213 outside their CU (they do however referencing other types via
8216 static struct partial_die_info
*
8217 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8219 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8220 struct partial_die_info
*pd
= NULL
;
8222 if (cu
->per_cu
->from_debug_types
)
8224 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8230 if (offset_in_cu_p (&cu
->header
, offset
))
8232 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8237 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8239 if (per_cu
->cu
== NULL
)
8241 load_partial_comp_unit (per_cu
, cu
->objfile
);
8242 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
8243 dwarf2_per_objfile
->read_in_chain
= per_cu
;
8246 per_cu
->cu
->last_used
= 0;
8247 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8249 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8251 struct cleanup
*back_to
;
8252 struct partial_die_info comp_unit_die
;
8253 struct abbrev_info
*abbrev
;
8254 unsigned int bytes_read
;
8257 per_cu
->load_all_dies
= 1;
8259 /* Re-read the DIEs. */
8260 back_to
= make_cleanup (null_cleanup
, 0);
8261 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8263 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8264 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8266 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8267 + per_cu
->cu
->header
.offset
8268 + per_cu
->cu
->header
.first_die_offset
);
8269 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8270 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8271 per_cu
->cu
->objfile
->obfd
,
8272 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8274 if (comp_unit_die
.has_children
)
8275 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8276 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8278 do_cleanups (back_to
);
8280 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8286 internal_error (__FILE__
, __LINE__
,
8287 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8288 offset
, bfd_get_filename (cu
->objfile
->obfd
));
8292 /* Adjust PART_DIE before generating a symbol for it. This function
8293 may set the is_external flag or change the DIE's name. */
8296 fixup_partial_die (struct partial_die_info
*part_die
,
8297 struct dwarf2_cu
*cu
)
8299 /* If we found a reference attribute and the DIE has no name, try
8300 to find a name in the referred to DIE. */
8302 if (part_die
->name
== NULL
&& part_die
->has_specification
)
8304 struct partial_die_info
*spec_die
;
8306 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
8308 fixup_partial_die (spec_die
, cu
);
8312 part_die
->name
= spec_die
->name
;
8314 /* Copy DW_AT_external attribute if it is set. */
8315 if (spec_die
->is_external
)
8316 part_die
->is_external
= spec_die
->is_external
;
8320 /* Set default names for some unnamed DIEs. */
8321 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
8322 || part_die
->tag
== DW_TAG_class_type
))
8323 part_die
->name
= "(anonymous class)";
8325 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
8326 part_die
->name
= "(anonymous namespace)";
8328 if (part_die
->tag
== DW_TAG_structure_type
8329 || part_die
->tag
== DW_TAG_class_type
8330 || part_die
->tag
== DW_TAG_union_type
)
8331 guess_structure_name (part_die
, cu
);
8334 /* Read an attribute value described by an attribute form. */
8337 read_attribute_value (struct attribute
*attr
, unsigned form
,
8338 bfd
*abfd
, gdb_byte
*info_ptr
,
8339 struct dwarf2_cu
*cu
)
8341 struct comp_unit_head
*cu_header
= &cu
->header
;
8342 unsigned int bytes_read
;
8343 struct dwarf_block
*blk
;
8348 case DW_FORM_ref_addr
:
8349 if (cu
->header
.version
== 2)
8350 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8352 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
8353 info_ptr
+= bytes_read
;
8356 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8357 info_ptr
+= bytes_read
;
8359 case DW_FORM_block2
:
8360 blk
= dwarf_alloc_block (cu
);
8361 blk
->size
= read_2_bytes (abfd
, info_ptr
);
8363 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8364 info_ptr
+= blk
->size
;
8365 DW_BLOCK (attr
) = blk
;
8367 case DW_FORM_block4
:
8368 blk
= dwarf_alloc_block (cu
);
8369 blk
->size
= read_4_bytes (abfd
, info_ptr
);
8371 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8372 info_ptr
+= blk
->size
;
8373 DW_BLOCK (attr
) = blk
;
8376 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
8380 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
8384 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
8387 case DW_FORM_sec_offset
:
8388 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
8389 info_ptr
+= bytes_read
;
8391 case DW_FORM_string
:
8392 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
8393 DW_STRING_IS_CANONICAL (attr
) = 0;
8394 info_ptr
+= bytes_read
;
8397 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
8399 DW_STRING_IS_CANONICAL (attr
) = 0;
8400 info_ptr
+= bytes_read
;
8402 case DW_FORM_exprloc
:
8404 blk
= dwarf_alloc_block (cu
);
8405 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8406 info_ptr
+= bytes_read
;
8407 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8408 info_ptr
+= blk
->size
;
8409 DW_BLOCK (attr
) = blk
;
8411 case DW_FORM_block1
:
8412 blk
= dwarf_alloc_block (cu
);
8413 blk
->size
= read_1_byte (abfd
, info_ptr
);
8415 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8416 info_ptr
+= blk
->size
;
8417 DW_BLOCK (attr
) = blk
;
8420 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
8424 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
8427 case DW_FORM_flag_present
:
8428 DW_UNSND (attr
) = 1;
8431 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
8432 info_ptr
+= bytes_read
;
8435 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8436 info_ptr
+= bytes_read
;
8439 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
8443 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
8447 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
8451 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
8455 /* Convert the signature to something we can record in DW_UNSND
8457 NOTE: This is NULL if the type wasn't found. */
8458 DW_SIGNATURED_TYPE (attr
) =
8459 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
8462 case DW_FORM_ref_udata
:
8463 DW_ADDR (attr
) = (cu
->header
.offset
8464 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
8465 info_ptr
+= bytes_read
;
8467 case DW_FORM_indirect
:
8468 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8469 info_ptr
+= bytes_read
;
8470 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
8473 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
8474 dwarf_form_name (form
),
8475 bfd_get_filename (abfd
));
8478 /* We have seen instances where the compiler tried to emit a byte
8479 size attribute of -1 which ended up being encoded as an unsigned
8480 0xffffffff. Although 0xffffffff is technically a valid size value,
8481 an object of this size seems pretty unlikely so we can relatively
8482 safely treat these cases as if the size attribute was invalid and
8483 treat them as zero by default. */
8484 if (attr
->name
== DW_AT_byte_size
8485 && form
== DW_FORM_data4
8486 && DW_UNSND (attr
) >= 0xffffffff)
8489 (&symfile_complaints
,
8490 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
8491 hex_string (DW_UNSND (attr
)));
8492 DW_UNSND (attr
) = 0;
8498 /* Read an attribute described by an abbreviated attribute. */
8501 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
8502 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8504 attr
->name
= abbrev
->name
;
8505 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
8508 /* read dwarf information from a buffer */
8511 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
8513 return bfd_get_8 (abfd
, buf
);
8517 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
8519 return bfd_get_signed_8 (abfd
, buf
);
8523 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
8525 return bfd_get_16 (abfd
, buf
);
8529 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
8531 return bfd_get_signed_16 (abfd
, buf
);
8535 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
8537 return bfd_get_32 (abfd
, buf
);
8541 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
8543 return bfd_get_signed_32 (abfd
, buf
);
8547 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
8549 return bfd_get_64 (abfd
, buf
);
8553 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
8554 unsigned int *bytes_read
)
8556 struct comp_unit_head
*cu_header
= &cu
->header
;
8557 CORE_ADDR retval
= 0;
8559 if (cu_header
->signed_addr_p
)
8561 switch (cu_header
->addr_size
)
8564 retval
= bfd_get_signed_16 (abfd
, buf
);
8567 retval
= bfd_get_signed_32 (abfd
, buf
);
8570 retval
= bfd_get_signed_64 (abfd
, buf
);
8573 internal_error (__FILE__
, __LINE__
,
8574 _("read_address: bad switch, signed [in module %s]"),
8575 bfd_get_filename (abfd
));
8580 switch (cu_header
->addr_size
)
8583 retval
= bfd_get_16 (abfd
, buf
);
8586 retval
= bfd_get_32 (abfd
, buf
);
8589 retval
= bfd_get_64 (abfd
, buf
);
8592 internal_error (__FILE__
, __LINE__
,
8593 _("read_address: bad switch, unsigned [in module %s]"),
8594 bfd_get_filename (abfd
));
8598 *bytes_read
= cu_header
->addr_size
;
8602 /* Read the initial length from a section. The (draft) DWARF 3
8603 specification allows the initial length to take up either 4 bytes
8604 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
8605 bytes describe the length and all offsets will be 8 bytes in length
8608 An older, non-standard 64-bit format is also handled by this
8609 function. The older format in question stores the initial length
8610 as an 8-byte quantity without an escape value. Lengths greater
8611 than 2^32 aren't very common which means that the initial 4 bytes
8612 is almost always zero. Since a length value of zero doesn't make
8613 sense for the 32-bit format, this initial zero can be considered to
8614 be an escape value which indicates the presence of the older 64-bit
8615 format. As written, the code can't detect (old format) lengths
8616 greater than 4GB. If it becomes necessary to handle lengths
8617 somewhat larger than 4GB, we could allow other small values (such
8618 as the non-sensical values of 1, 2, and 3) to also be used as
8619 escape values indicating the presence of the old format.
8621 The value returned via bytes_read should be used to increment the
8622 relevant pointer after calling read_initial_length().
8624 [ Note: read_initial_length() and read_offset() are based on the
8625 document entitled "DWARF Debugging Information Format", revision
8626 3, draft 8, dated November 19, 2001. This document was obtained
8629 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
8631 This document is only a draft and is subject to change. (So beware.)
8633 Details regarding the older, non-standard 64-bit format were
8634 determined empirically by examining 64-bit ELF files produced by
8635 the SGI toolchain on an IRIX 6.5 machine.
8637 - Kevin, July 16, 2002
8641 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
8643 LONGEST length
= bfd_get_32 (abfd
, buf
);
8645 if (length
== 0xffffffff)
8647 length
= bfd_get_64 (abfd
, buf
+ 4);
8650 else if (length
== 0)
8652 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
8653 length
= bfd_get_64 (abfd
, buf
);
8664 /* Cover function for read_initial_length.
8665 Returns the length of the object at BUF, and stores the size of the
8666 initial length in *BYTES_READ and stores the size that offsets will be in
8668 If the initial length size is not equivalent to that specified in
8669 CU_HEADER then issue a complaint.
8670 This is useful when reading non-comp-unit headers. */
8673 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
8674 const struct comp_unit_head
*cu_header
,
8675 unsigned int *bytes_read
,
8676 unsigned int *offset_size
)
8678 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
8680 gdb_assert (cu_header
->initial_length_size
== 4
8681 || cu_header
->initial_length_size
== 8
8682 || cu_header
->initial_length_size
== 12);
8684 if (cu_header
->initial_length_size
!= *bytes_read
)
8685 complaint (&symfile_complaints
,
8686 _("intermixed 32-bit and 64-bit DWARF sections"));
8688 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
8692 /* Read an offset from the data stream. The size of the offset is
8693 given by cu_header->offset_size. */
8696 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
8697 unsigned int *bytes_read
)
8699 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
8701 *bytes_read
= cu_header
->offset_size
;
8705 /* Read an offset from the data stream. */
8708 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
8712 switch (offset_size
)
8715 retval
= bfd_get_32 (abfd
, buf
);
8718 retval
= bfd_get_64 (abfd
, buf
);
8721 internal_error (__FILE__
, __LINE__
,
8722 _("read_offset_1: bad switch [in module %s]"),
8723 bfd_get_filename (abfd
));
8730 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
8732 /* If the size of a host char is 8 bits, we can return a pointer
8733 to the buffer, otherwise we have to copy the data to a buffer
8734 allocated on the temporary obstack. */
8735 gdb_assert (HOST_CHAR_BIT
== 8);
8740 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
8742 /* If the size of a host char is 8 bits, we can return a pointer
8743 to the string, otherwise we have to copy the string to a buffer
8744 allocated on the temporary obstack. */
8745 gdb_assert (HOST_CHAR_BIT
== 8);
8748 *bytes_read_ptr
= 1;
8751 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
8752 return (char *) buf
;
8756 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
8757 const struct comp_unit_head
*cu_header
,
8758 unsigned int *bytes_read_ptr
)
8760 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
8762 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
8763 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
8765 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
8766 bfd_get_filename (abfd
));
8769 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
8771 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
8772 bfd_get_filename (abfd
));
8775 gdb_assert (HOST_CHAR_BIT
== 8);
8776 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
8778 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
8781 static unsigned long
8782 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
8784 unsigned long result
;
8785 unsigned int num_read
;
8795 byte
= bfd_get_8 (abfd
, buf
);
8798 result
|= ((unsigned long)(byte
& 127) << shift
);
8799 if ((byte
& 128) == 0)
8805 *bytes_read_ptr
= num_read
;
8810 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
8813 int i
, shift
, num_read
;
8822 byte
= bfd_get_8 (abfd
, buf
);
8825 result
|= ((long)(byte
& 127) << shift
);
8827 if ((byte
& 128) == 0)
8832 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
8833 result
|= -(((long)1) << shift
);
8834 *bytes_read_ptr
= num_read
;
8838 /* Return a pointer to just past the end of an LEB128 number in BUF. */
8841 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
8847 byte
= bfd_get_8 (abfd
, buf
);
8849 if ((byte
& 128) == 0)
8855 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
8862 cu
->language
= language_c
;
8864 case DW_LANG_C_plus_plus
:
8865 cu
->language
= language_cplus
;
8868 cu
->language
= language_d
;
8870 case DW_LANG_Fortran77
:
8871 case DW_LANG_Fortran90
:
8872 case DW_LANG_Fortran95
:
8873 cu
->language
= language_fortran
;
8875 case DW_LANG_Mips_Assembler
:
8876 cu
->language
= language_asm
;
8879 cu
->language
= language_java
;
8883 cu
->language
= language_ada
;
8885 case DW_LANG_Modula2
:
8886 cu
->language
= language_m2
;
8888 case DW_LANG_Pascal83
:
8889 cu
->language
= language_pascal
;
8892 cu
->language
= language_objc
;
8894 case DW_LANG_Cobol74
:
8895 case DW_LANG_Cobol85
:
8897 cu
->language
= language_minimal
;
8900 cu
->language_defn
= language_def (cu
->language
);
8903 /* Return the named attribute or NULL if not there. */
8905 static struct attribute
*
8906 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
8909 struct attribute
*spec
= NULL
;
8911 for (i
= 0; i
< die
->num_attrs
; ++i
)
8913 if (die
->attrs
[i
].name
== name
)
8914 return &die
->attrs
[i
];
8915 if (die
->attrs
[i
].name
== DW_AT_specification
8916 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
8917 spec
= &die
->attrs
[i
];
8922 die
= follow_die_ref (die
, spec
, &cu
);
8923 return dwarf2_attr (die
, name
, cu
);
8929 /* Return the named attribute or NULL if not there,
8930 but do not follow DW_AT_specification, etc.
8931 This is for use in contexts where we're reading .debug_types dies.
8932 Following DW_AT_specification, DW_AT_abstract_origin will take us
8933 back up the chain, and we want to go down. */
8935 static struct attribute
*
8936 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
8937 struct dwarf2_cu
*cu
)
8941 for (i
= 0; i
< die
->num_attrs
; ++i
)
8942 if (die
->attrs
[i
].name
== name
)
8943 return &die
->attrs
[i
];
8948 /* Return non-zero iff the attribute NAME is defined for the given DIE,
8949 and holds a non-zero value. This function should only be used for
8950 DW_FORM_flag or DW_FORM_flag_present attributes. */
8953 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
8955 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
8957 return (attr
&& DW_UNSND (attr
));
8961 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
8963 /* A DIE is a declaration if it has a DW_AT_declaration attribute
8964 which value is non-zero. However, we have to be careful with
8965 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
8966 (via dwarf2_flag_true_p) follows this attribute. So we may
8967 end up accidently finding a declaration attribute that belongs
8968 to a different DIE referenced by the specification attribute,
8969 even though the given DIE does not have a declaration attribute. */
8970 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
8971 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
8974 /* Return the die giving the specification for DIE, if there is
8975 one. *SPEC_CU is the CU containing DIE on input, and the CU
8976 containing the return value on output. If there is no
8977 specification, but there is an abstract origin, that is
8980 static struct die_info
*
8981 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
8983 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
8986 if (spec_attr
== NULL
)
8987 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
8989 if (spec_attr
== NULL
)
8992 return follow_die_ref (die
, spec_attr
, spec_cu
);
8995 /* Free the line_header structure *LH, and any arrays and strings it
8998 free_line_header (struct line_header
*lh
)
9000 if (lh
->standard_opcode_lengths
)
9001 xfree (lh
->standard_opcode_lengths
);
9003 /* Remember that all the lh->file_names[i].name pointers are
9004 pointers into debug_line_buffer, and don't need to be freed. */
9006 xfree (lh
->file_names
);
9008 /* Similarly for the include directory names. */
9009 if (lh
->include_dirs
)
9010 xfree (lh
->include_dirs
);
9016 /* Add an entry to LH's include directory table. */
9018 add_include_dir (struct line_header
*lh
, char *include_dir
)
9020 /* Grow the array if necessary. */
9021 if (lh
->include_dirs_size
== 0)
9023 lh
->include_dirs_size
= 1; /* for testing */
9024 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9025 * sizeof (*lh
->include_dirs
));
9027 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9029 lh
->include_dirs_size
*= 2;
9030 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9031 (lh
->include_dirs_size
9032 * sizeof (*lh
->include_dirs
)));
9035 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9039 /* Add an entry to LH's file name table. */
9041 add_file_name (struct line_header
*lh
,
9043 unsigned int dir_index
,
9044 unsigned int mod_time
,
9045 unsigned int length
)
9047 struct file_entry
*fe
;
9049 /* Grow the array if necessary. */
9050 if (lh
->file_names_size
== 0)
9052 lh
->file_names_size
= 1; /* for testing */
9053 lh
->file_names
= xmalloc (lh
->file_names_size
9054 * sizeof (*lh
->file_names
));
9056 else if (lh
->num_file_names
>= lh
->file_names_size
)
9058 lh
->file_names_size
*= 2;
9059 lh
->file_names
= xrealloc (lh
->file_names
,
9060 (lh
->file_names_size
9061 * sizeof (*lh
->file_names
)));
9064 fe
= &lh
->file_names
[lh
->num_file_names
++];
9066 fe
->dir_index
= dir_index
;
9067 fe
->mod_time
= mod_time
;
9068 fe
->length
= length
;
9074 /* Read the statement program header starting at OFFSET in
9075 .debug_line, according to the endianness of ABFD. Return a pointer
9076 to a struct line_header, allocated using xmalloc.
9078 NOTE: the strings in the include directory and file name tables of
9079 the returned object point into debug_line_buffer, and must not be
9081 static struct line_header
*
9082 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9083 struct dwarf2_cu
*cu
)
9085 struct cleanup
*back_to
;
9086 struct line_header
*lh
;
9088 unsigned int bytes_read
, offset_size
;
9090 char *cur_dir
, *cur_file
;
9092 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9093 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9095 complaint (&symfile_complaints
, _("missing .debug_line section"));
9099 /* Make sure that at least there's room for the total_length field.
9100 That could be 12 bytes long, but we're just going to fudge that. */
9101 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9103 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9107 lh
= xmalloc (sizeof (*lh
));
9108 memset (lh
, 0, sizeof (*lh
));
9109 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9112 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9114 /* Read in the header. */
9116 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9117 &bytes_read
, &offset_size
);
9118 line_ptr
+= bytes_read
;
9119 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9120 + dwarf2_per_objfile
->line
.size
))
9122 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9125 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9126 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9128 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9129 line_ptr
+= offset_size
;
9130 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9132 if (lh
->version
>= 4)
9134 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9138 lh
->maximum_ops_per_instruction
= 1;
9140 if (lh
->maximum_ops_per_instruction
== 0)
9142 lh
->maximum_ops_per_instruction
= 1;
9143 complaint (&symfile_complaints
,
9144 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9147 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9149 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9151 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9153 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9155 lh
->standard_opcode_lengths
9156 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9158 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9159 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9161 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9165 /* Read directory table. */
9166 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9168 line_ptr
+= bytes_read
;
9169 add_include_dir (lh
, cur_dir
);
9171 line_ptr
+= bytes_read
;
9173 /* Read file name table. */
9174 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9176 unsigned int dir_index
, mod_time
, length
;
9178 line_ptr
+= bytes_read
;
9179 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9180 line_ptr
+= bytes_read
;
9181 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9182 line_ptr
+= bytes_read
;
9183 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9184 line_ptr
+= bytes_read
;
9186 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9188 line_ptr
+= bytes_read
;
9189 lh
->statement_program_start
= line_ptr
;
9191 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9192 + dwarf2_per_objfile
->line
.size
))
9193 complaint (&symfile_complaints
,
9194 _("line number info header doesn't fit in `.debug_line' section"));
9196 discard_cleanups (back_to
);
9200 /* This function exists to work around a bug in certain compilers
9201 (particularly GCC 2.95), in which the first line number marker of a
9202 function does not show up until after the prologue, right before
9203 the second line number marker. This function shifts ADDRESS down
9204 to the beginning of the function if necessary, and is called on
9205 addresses passed to record_line. */
9208 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9210 struct function_range
*fn
;
9212 /* Find the function_range containing address. */
9217 cu
->cached_fn
= cu
->first_fn
;
9221 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9227 while (fn
&& fn
!= cu
->cached_fn
)
9228 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9238 if (address
!= fn
->lowpc
)
9239 complaint (&symfile_complaints
,
9240 _("misplaced first line number at 0x%lx for '%s'"),
9241 (unsigned long) address
, fn
->name
);
9246 /* Decode the Line Number Program (LNP) for the given line_header
9247 structure and CU. The actual information extracted and the type
9248 of structures created from the LNP depends on the value of PST.
9250 1. If PST is NULL, then this procedure uses the data from the program
9251 to create all necessary symbol tables, and their linetables.
9252 The compilation directory of the file is passed in COMP_DIR,
9253 and must not be NULL.
9255 2. If PST is not NULL, this procedure reads the program to determine
9256 the list of files included by the unit represented by PST, and
9257 builds all the associated partial symbol tables. In this case,
9258 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
9259 is not used to compute the full name of the symtab, and therefore
9260 omitting it when building the partial symtab does not introduce
9261 the potential for inconsistency - a partial symtab and its associated
9262 symbtab having a different fullname -). */
9265 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
9266 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
9268 gdb_byte
*line_ptr
, *extended_end
;
9270 unsigned int bytes_read
, extended_len
;
9271 unsigned char op_code
, extended_op
, adj_opcode
;
9273 struct objfile
*objfile
= cu
->objfile
;
9274 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9275 const int decode_for_pst_p
= (pst
!= NULL
);
9276 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
9278 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9280 line_ptr
= lh
->statement_program_start
;
9281 line_end
= lh
->statement_program_end
;
9283 /* Read the statement sequences until there's nothing left. */
9284 while (line_ptr
< line_end
)
9286 /* state machine registers */
9287 CORE_ADDR address
= 0;
9288 unsigned int file
= 1;
9289 unsigned int line
= 1;
9290 unsigned int column
= 0;
9291 int is_stmt
= lh
->default_is_stmt
;
9292 int basic_block
= 0;
9293 int end_sequence
= 0;
9295 unsigned char op_index
= 0;
9297 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
9299 /* Start a subfile for the current file of the state machine. */
9300 /* lh->include_dirs and lh->file_names are 0-based, but the
9301 directory and file name numbers in the statement program
9303 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9307 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9309 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9312 /* Decode the table. */
9313 while (!end_sequence
)
9315 op_code
= read_1_byte (abfd
, line_ptr
);
9317 if (line_ptr
> line_end
)
9319 dwarf2_debug_line_missing_end_sequence_complaint ();
9323 if (op_code
>= lh
->opcode_base
)
9325 /* Special operand. */
9326 adj_opcode
= op_code
- lh
->opcode_base
;
9327 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
9328 / lh
->maximum_ops_per_instruction
)
9329 * lh
->minimum_instruction_length
);
9330 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
9331 % lh
->maximum_ops_per_instruction
);
9332 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
9333 if (lh
->num_file_names
< file
|| file
== 0)
9334 dwarf2_debug_line_missing_file_complaint ();
9335 /* For now we ignore lines not starting on an
9336 instruction boundary. */
9337 else if (op_index
== 0)
9339 lh
->file_names
[file
- 1].included_p
= 1;
9340 if (!decode_for_pst_p
&& is_stmt
)
9342 if (last_subfile
!= current_subfile
)
9344 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9346 record_line (last_subfile
, 0, addr
);
9347 last_subfile
= current_subfile
;
9349 /* Append row to matrix using current values. */
9350 addr
= check_cu_functions (address
, cu
);
9351 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
9352 record_line (current_subfile
, line
, addr
);
9357 else switch (op_code
)
9359 case DW_LNS_extended_op
:
9360 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9361 line_ptr
+= bytes_read
;
9362 extended_end
= line_ptr
+ extended_len
;
9363 extended_op
= read_1_byte (abfd
, line_ptr
);
9365 switch (extended_op
)
9367 case DW_LNE_end_sequence
:
9370 case DW_LNE_set_address
:
9371 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
9373 line_ptr
+= bytes_read
;
9374 address
+= baseaddr
;
9376 case DW_LNE_define_file
:
9379 unsigned int dir_index
, mod_time
, length
;
9381 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
9382 line_ptr
+= bytes_read
;
9384 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9385 line_ptr
+= bytes_read
;
9387 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9388 line_ptr
+= bytes_read
;
9390 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9391 line_ptr
+= bytes_read
;
9392 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9395 case DW_LNE_set_discriminator
:
9396 /* The discriminator is not interesting to the debugger;
9398 line_ptr
= extended_end
;
9401 complaint (&symfile_complaints
,
9402 _("mangled .debug_line section"));
9405 /* Make sure that we parsed the extended op correctly. If e.g.
9406 we expected a different address size than the producer used,
9407 we may have read the wrong number of bytes. */
9408 if (line_ptr
!= extended_end
)
9410 complaint (&symfile_complaints
,
9411 _("mangled .debug_line section"));
9416 if (lh
->num_file_names
< file
|| file
== 0)
9417 dwarf2_debug_line_missing_file_complaint ();
9420 lh
->file_names
[file
- 1].included_p
= 1;
9421 if (!decode_for_pst_p
&& is_stmt
)
9423 if (last_subfile
!= current_subfile
)
9425 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9427 record_line (last_subfile
, 0, addr
);
9428 last_subfile
= current_subfile
;
9430 addr
= check_cu_functions (address
, cu
);
9431 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
9432 record_line (current_subfile
, line
, addr
);
9437 case DW_LNS_advance_pc
:
9440 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9442 address
+= (((op_index
+ adjust
)
9443 / lh
->maximum_ops_per_instruction
)
9444 * lh
->minimum_instruction_length
);
9445 op_index
= ((op_index
+ adjust
)
9446 % lh
->maximum_ops_per_instruction
);
9447 line_ptr
+= bytes_read
;
9450 case DW_LNS_advance_line
:
9451 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
9452 line_ptr
+= bytes_read
;
9454 case DW_LNS_set_file
:
9456 /* The arrays lh->include_dirs and lh->file_names are
9457 0-based, but the directory and file name numbers in
9458 the statement program are 1-based. */
9459 struct file_entry
*fe
;
9462 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9463 line_ptr
+= bytes_read
;
9464 if (lh
->num_file_names
< file
|| file
== 0)
9465 dwarf2_debug_line_missing_file_complaint ();
9468 fe
= &lh
->file_names
[file
- 1];
9470 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9471 if (!decode_for_pst_p
)
9473 last_subfile
= current_subfile
;
9474 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9479 case DW_LNS_set_column
:
9480 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9481 line_ptr
+= bytes_read
;
9483 case DW_LNS_negate_stmt
:
9484 is_stmt
= (!is_stmt
);
9486 case DW_LNS_set_basic_block
:
9489 /* Add to the address register of the state machine the
9490 address increment value corresponding to special opcode
9491 255. I.e., this value is scaled by the minimum
9492 instruction length since special opcode 255 would have
9493 scaled the the increment. */
9494 case DW_LNS_const_add_pc
:
9496 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
9498 address
+= (((op_index
+ adjust
)
9499 / lh
->maximum_ops_per_instruction
)
9500 * lh
->minimum_instruction_length
);
9501 op_index
= ((op_index
+ adjust
)
9502 % lh
->maximum_ops_per_instruction
);
9505 case DW_LNS_fixed_advance_pc
:
9506 address
+= read_2_bytes (abfd
, line_ptr
);
9512 /* Unknown standard opcode, ignore it. */
9515 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
9517 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9518 line_ptr
+= bytes_read
;
9523 if (lh
->num_file_names
< file
|| file
== 0)
9524 dwarf2_debug_line_missing_file_complaint ();
9527 lh
->file_names
[file
- 1].included_p
= 1;
9528 if (!decode_for_pst_p
)
9530 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9531 record_line (current_subfile
, 0, addr
);
9536 if (decode_for_pst_p
)
9540 /* Now that we're done scanning the Line Header Program, we can
9541 create the psymtab of each included file. */
9542 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
9543 if (lh
->file_names
[file_index
].included_p
== 1)
9545 const struct file_entry fe
= lh
->file_names
[file_index
];
9546 char *include_name
= fe
.name
;
9547 char *dir_name
= NULL
;
9548 char *pst_filename
= pst
->filename
;
9551 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
9553 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
9555 include_name
= concat (dir_name
, SLASH_STRING
,
9556 include_name
, (char *)NULL
);
9557 make_cleanup (xfree
, include_name
);
9560 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
9562 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
9563 pst_filename
, (char *)NULL
);
9564 make_cleanup (xfree
, pst_filename
);
9567 if (strcmp (include_name
, pst_filename
) != 0)
9568 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
9573 /* Make sure a symtab is created for every file, even files
9574 which contain only variables (i.e. no code with associated
9578 struct file_entry
*fe
;
9580 for (i
= 0; i
< lh
->num_file_names
; i
++)
9584 fe
= &lh
->file_names
[i
];
9586 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9587 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9589 /* Skip the main file; we don't need it, and it must be
9590 allocated last, so that it will show up before the
9591 non-primary symtabs in the objfile's symtab list. */
9592 if (current_subfile
== first_subfile
)
9595 if (current_subfile
->symtab
== NULL
)
9596 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
9598 fe
->symtab
= current_subfile
->symtab
;
9603 /* Start a subfile for DWARF. FILENAME is the name of the file and
9604 DIRNAME the name of the source directory which contains FILENAME
9605 or NULL if not known. COMP_DIR is the compilation directory for the
9606 linetable's compilation unit or NULL if not known.
9607 This routine tries to keep line numbers from identical absolute and
9608 relative file names in a common subfile.
9610 Using the `list' example from the GDB testsuite, which resides in
9611 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
9612 of /srcdir/list0.c yields the following debugging information for list0.c:
9614 DW_AT_name: /srcdir/list0.c
9615 DW_AT_comp_dir: /compdir
9616 files.files[0].name: list0.h
9617 files.files[0].dir: /srcdir
9618 files.files[1].name: list0.c
9619 files.files[1].dir: /srcdir
9621 The line number information for list0.c has to end up in a single
9622 subfile, so that `break /srcdir/list0.c:1' works as expected.
9623 start_subfile will ensure that this happens provided that we pass the
9624 concatenation of files.files[1].dir and files.files[1].name as the
9628 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
9632 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
9633 `start_symtab' will always pass the contents of DW_AT_comp_dir as
9634 second argument to start_subfile. To be consistent, we do the
9635 same here. In order not to lose the line information directory,
9636 we concatenate it to the filename when it makes sense.
9637 Note that the Dwarf3 standard says (speaking of filenames in line
9638 information): ``The directory index is ignored for file names
9639 that represent full path names''. Thus ignoring dirname in the
9640 `else' branch below isn't an issue. */
9642 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
9643 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
9645 fullname
= filename
;
9647 start_subfile (fullname
, comp_dir
);
9649 if (fullname
!= filename
)
9654 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
9655 struct dwarf2_cu
*cu
)
9657 struct objfile
*objfile
= cu
->objfile
;
9658 struct comp_unit_head
*cu_header
= &cu
->header
;
9660 /* NOTE drow/2003-01-30: There used to be a comment and some special
9661 code here to turn a symbol with DW_AT_external and a
9662 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
9663 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
9664 with some versions of binutils) where shared libraries could have
9665 relocations against symbols in their debug information - the
9666 minimal symbol would have the right address, but the debug info
9667 would not. It's no longer necessary, because we will explicitly
9668 apply relocations when we read in the debug information now. */
9670 /* A DW_AT_location attribute with no contents indicates that a
9671 variable has been optimized away. */
9672 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
9674 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
9678 /* Handle one degenerate form of location expression specially, to
9679 preserve GDB's previous behavior when section offsets are
9680 specified. If this is just a DW_OP_addr then mark this symbol
9683 if (attr_form_is_block (attr
)
9684 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
9685 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
9689 SYMBOL_VALUE_ADDRESS (sym
) =
9690 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
9691 SYMBOL_CLASS (sym
) = LOC_STATIC
;
9692 fixup_symbol_section (sym
, objfile
);
9693 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
9694 SYMBOL_SECTION (sym
));
9698 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
9699 expression evaluator, and use LOC_COMPUTED only when necessary
9700 (i.e. when the value of a register or memory location is
9701 referenced, or a thread-local block, etc.). Then again, it might
9702 not be worthwhile. I'm assuming that it isn't unless performance
9703 or memory numbers show me otherwise. */
9705 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
9706 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
9709 /* Given a pointer to a DWARF information entry, figure out if we need
9710 to make a symbol table entry for it, and if so, create a new entry
9711 and return a pointer to it.
9712 If TYPE is NULL, determine symbol type from the die, otherwise
9713 used the passed type. */
9715 static struct symbol
*
9716 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
9718 struct objfile
*objfile
= cu
->objfile
;
9719 struct symbol
*sym
= NULL
;
9721 struct attribute
*attr
= NULL
;
9722 struct attribute
*attr2
= NULL
;
9724 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9726 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9728 name
= dwarf2_name (die
, cu
);
9731 const char *linkagename
;
9733 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
9734 sizeof (struct symbol
));
9735 OBJSTAT (objfile
, n_syms
++);
9736 memset (sym
, 0, sizeof (struct symbol
));
9738 /* Cache this symbol's name and the name's demangled form (if any). */
9739 SYMBOL_LANGUAGE (sym
) = cu
->language
;
9740 linkagename
= dwarf2_physname (name
, die
, cu
);
9741 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
9743 /* Fortran does not have mangling standard and the mangling does differ
9744 between gfortran, iFort etc. */
9745 if (cu
->language
== language_fortran
9746 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
9747 symbol_set_demangled_name (&(sym
->ginfo
),
9748 (char *) dwarf2_full_name (name
, die
, cu
),
9751 /* Default assumptions.
9752 Use the passed type or decode it from the die. */
9753 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
9754 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
9756 SYMBOL_TYPE (sym
) = type
;
9758 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
9759 attr
= dwarf2_attr (die
,
9760 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
9764 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
9767 attr
= dwarf2_attr (die
,
9768 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
9772 int file_index
= DW_UNSND (attr
);
9774 if (cu
->line_header
== NULL
9775 || file_index
> cu
->line_header
->num_file_names
)
9776 complaint (&symfile_complaints
,
9777 _("file index out of range"));
9778 else if (file_index
> 0)
9780 struct file_entry
*fe
;
9782 fe
= &cu
->line_header
->file_names
[file_index
- 1];
9783 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
9790 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9793 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
9795 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
9796 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
9797 SYMBOL_CLASS (sym
) = LOC_LABEL
;
9798 add_symbol_to_list (sym
, cu
->list_in_scope
);
9800 case DW_TAG_subprogram
:
9801 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9803 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
9804 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9805 if ((attr2
&& (DW_UNSND (attr2
) != 0))
9806 || cu
->language
== language_ada
)
9808 /* Subprograms marked external are stored as a global symbol.
9809 Ada subprograms, whether marked external or not, are always
9810 stored as a global symbol, because we want to be able to
9811 access them globally. For instance, we want to be able
9812 to break on a nested subprogram without having to
9813 specify the context. */
9814 add_symbol_to_list (sym
, &global_symbols
);
9818 add_symbol_to_list (sym
, cu
->list_in_scope
);
9821 case DW_TAG_inlined_subroutine
:
9822 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9824 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
9825 SYMBOL_INLINED (sym
) = 1;
9826 /* Do not add the symbol to any lists. It will be found via
9827 BLOCK_FUNCTION from the blockvector. */
9829 case DW_TAG_variable
:
9831 /* Compilation with minimal debug info may result in variables
9832 with missing type entries. Change the misleading `void' type
9833 to something sensible. */
9834 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
9836 = objfile_type (objfile
)->nodebug_data_symbol
;
9838 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9839 /* In the case of DW_TAG_member, we should only be called for
9840 static const members. */
9841 if (die
->tag
== DW_TAG_member
)
9843 /* dwarf2_add_field uses die_is_declaration,
9844 so we do the same. */
9845 gdb_assert (die_is_declaration (die
, cu
));
9850 dwarf2_const_value (attr
, sym
, cu
);
9851 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9852 if (attr2
&& (DW_UNSND (attr2
) != 0))
9853 add_symbol_to_list (sym
, &global_symbols
);
9855 add_symbol_to_list (sym
, cu
->list_in_scope
);
9858 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9861 var_decode_location (attr
, sym
, cu
);
9862 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9863 if (attr2
&& (DW_UNSND (attr2
) != 0))
9865 struct pending
**list_to_add
;
9867 /* Workaround gfortran PR debug/40040 - it uses
9868 DW_AT_location for variables in -fPIC libraries which may
9869 get overriden by other libraries/executable and get
9870 a different address. Resolve it by the minimal symbol
9871 which may come from inferior's executable using copy
9872 relocation. Make this workaround only for gfortran as for
9873 other compilers GDB cannot guess the minimal symbol
9874 Fortran mangling kind. */
9875 if (cu
->language
== language_fortran
&& die
->parent
9876 && die
->parent
->tag
== DW_TAG_module
9878 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
9879 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
9881 /* A variable with DW_AT_external is never static,
9882 but it may be block-scoped. */
9883 list_to_add
= (cu
->list_in_scope
== &file_symbols
9884 ? &global_symbols
: cu
->list_in_scope
);
9885 add_symbol_to_list (sym
, list_to_add
);
9888 add_symbol_to_list (sym
, cu
->list_in_scope
);
9892 /* We do not know the address of this symbol.
9893 If it is an external symbol and we have type information
9894 for it, enter the symbol as a LOC_UNRESOLVED symbol.
9895 The address of the variable will then be determined from
9896 the minimal symbol table whenever the variable is
9898 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9899 if (attr2
&& (DW_UNSND (attr2
) != 0)
9900 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
9902 struct pending
**list_to_add
;
9904 /* A variable with DW_AT_external is never static, but it
9905 may be block-scoped. */
9906 list_to_add
= (cu
->list_in_scope
== &file_symbols
9907 ? &global_symbols
: cu
->list_in_scope
);
9909 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
9910 add_symbol_to_list (sym
, list_to_add
);
9912 else if (!die_is_declaration (die
, cu
))
9914 /* Use the default LOC_OPTIMIZED_OUT class. */
9915 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
9916 add_symbol_to_list (sym
, cu
->list_in_scope
);
9920 case DW_TAG_formal_parameter
:
9921 /* If we are inside a function, mark this as an argument. If
9922 not, we might be looking at an argument to an inlined function
9923 when we do not have enough information to show inlined frames;
9924 pretend it's a local variable in that case so that the user can
9926 if (context_stack_depth
> 0
9927 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
9928 SYMBOL_IS_ARGUMENT (sym
) = 1;
9929 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9932 var_decode_location (attr
, sym
, cu
);
9934 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9937 dwarf2_const_value (attr
, sym
, cu
);
9939 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
9940 if (attr
&& DW_UNSND (attr
))
9942 struct type
*ref_type
;
9944 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
9945 SYMBOL_TYPE (sym
) = ref_type
;
9948 add_symbol_to_list (sym
, cu
->list_in_scope
);
9950 case DW_TAG_unspecified_parameters
:
9951 /* From varargs functions; gdb doesn't seem to have any
9952 interest in this information, so just ignore it for now.
9955 case DW_TAG_class_type
:
9956 case DW_TAG_interface_type
:
9957 case DW_TAG_structure_type
:
9958 case DW_TAG_union_type
:
9959 case DW_TAG_set_type
:
9960 case DW_TAG_enumeration_type
:
9961 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
9962 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9965 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
9966 really ever be static objects: otherwise, if you try
9967 to, say, break of a class's method and you're in a file
9968 which doesn't mention that class, it won't work unless
9969 the check for all static symbols in lookup_symbol_aux
9970 saves you. See the OtherFileClass tests in
9971 gdb.c++/namespace.exp. */
9973 struct pending
**list_to_add
;
9975 list_to_add
= (cu
->list_in_scope
== &file_symbols
9976 && (cu
->language
== language_cplus
9977 || cu
->language
== language_java
)
9978 ? &global_symbols
: cu
->list_in_scope
);
9980 add_symbol_to_list (sym
, list_to_add
);
9982 /* The semantics of C++ state that "struct foo { ... }" also
9983 defines a typedef for "foo". A Java class declaration also
9984 defines a typedef for the class. */
9985 if (cu
->language
== language_cplus
9986 || cu
->language
== language_java
9987 || cu
->language
== language_ada
)
9989 /* The symbol's name is already allocated along with
9990 this objfile, so we don't need to duplicate it for
9992 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
9993 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
9997 case DW_TAG_typedef
:
9998 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
9999 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10000 add_symbol_to_list (sym
, cu
->list_in_scope
);
10002 case DW_TAG_base_type
:
10003 case DW_TAG_subrange_type
:
10004 case DW_TAG_const_type
:
10005 case DW_TAG_volatile_type
:
10006 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10007 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10008 add_symbol_to_list (sym
, cu
->list_in_scope
);
10010 case DW_TAG_enumerator
:
10011 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10014 dwarf2_const_value (attr
, sym
, cu
);
10017 /* NOTE: carlton/2003-11-10: See comment above in the
10018 DW_TAG_class_type, etc. block. */
10020 struct pending
**list_to_add
;
10022 list_to_add
= (cu
->list_in_scope
== &file_symbols
10023 && (cu
->language
== language_cplus
10024 || cu
->language
== language_java
)
10025 ? &global_symbols
: cu
->list_in_scope
);
10027 add_symbol_to_list (sym
, list_to_add
);
10030 case DW_TAG_namespace
:
10031 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10032 add_symbol_to_list (sym
, &global_symbols
);
10035 /* Not a tag we recognize. Hopefully we aren't processing
10036 trash data, but since we must specifically ignore things
10037 we don't recognize, there is nothing else we should do at
10039 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10040 dwarf_tag_name (die
->tag
));
10044 /* For the benefit of old versions of GCC, check for anonymous
10045 namespaces based on the demangled name. */
10046 if (!processing_has_namespace_info
10047 && cu
->language
== language_cplus
)
10048 cp_scan_for_anonymous_namespaces (sym
);
10053 /* Copy constant value from an attribute to a symbol. */
10056 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
10057 struct dwarf2_cu
*cu
)
10059 struct objfile
*objfile
= cu
->objfile
;
10060 struct comp_unit_head
*cu_header
= &cu
->header
;
10061 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10062 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10063 struct dwarf_block
*blk
;
10065 switch (attr
->form
)
10069 struct dwarf2_locexpr_baton
*baton
;
10072 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
10073 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
10074 cu_header
->addr_size
,
10075 TYPE_LENGTH (SYMBOL_TYPE
10077 /* Symbols of this form are reasonably rare, so we just
10078 piggyback on the existing location code rather than writing
10079 a new implementation of symbol_computed_ops. */
10080 baton
= obstack_alloc (&objfile
->objfile_obstack
,
10081 sizeof (struct dwarf2_locexpr_baton
));
10082 baton
->per_cu
= cu
->per_cu
;
10083 gdb_assert (baton
->per_cu
);
10085 baton
->size
= 2 + cu_header
->addr_size
;
10086 data
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
10087 baton
->data
= data
;
10089 data
[0] = DW_OP_addr
;
10090 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
10091 byte_order
, DW_ADDR (attr
));
10092 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
10094 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10095 SYMBOL_LOCATION_BATON (sym
) = baton
;
10096 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10099 case DW_FORM_string
:
10101 /* DW_STRING is already allocated on the obstack, point directly
10103 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
10104 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
10106 case DW_FORM_block1
:
10107 case DW_FORM_block2
:
10108 case DW_FORM_block4
:
10109 case DW_FORM_block
:
10110 case DW_FORM_exprloc
:
10111 blk
= DW_BLOCK (attr
);
10112 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
10113 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
10115 TYPE_LENGTH (SYMBOL_TYPE
10117 SYMBOL_VALUE_BYTES (sym
) =
10118 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
10119 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
10120 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
10123 /* The DW_AT_const_value attributes are supposed to carry the
10124 symbol's value "represented as it would be on the target
10125 architecture." By the time we get here, it's already been
10126 converted to host endianness, so we just need to sign- or
10127 zero-extend it as appropriate. */
10128 case DW_FORM_data1
:
10129 dwarf2_const_value_data (attr
, sym
, 8);
10131 case DW_FORM_data2
:
10132 dwarf2_const_value_data (attr
, sym
, 16);
10134 case DW_FORM_data4
:
10135 dwarf2_const_value_data (attr
, sym
, 32);
10137 case DW_FORM_data8
:
10138 dwarf2_const_value_data (attr
, sym
, 64);
10141 case DW_FORM_sdata
:
10142 SYMBOL_VALUE (sym
) = DW_SND (attr
);
10143 SYMBOL_CLASS (sym
) = LOC_CONST
;
10146 case DW_FORM_udata
:
10147 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
10148 SYMBOL_CLASS (sym
) = LOC_CONST
;
10152 complaint (&symfile_complaints
,
10153 _("unsupported const value attribute form: '%s'"),
10154 dwarf_form_name (attr
->form
));
10155 SYMBOL_VALUE (sym
) = 0;
10156 SYMBOL_CLASS (sym
) = LOC_CONST
;
10162 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
10163 or zero-extend it as appropriate for the symbol's type. */
10165 dwarf2_const_value_data (struct attribute
*attr
,
10166 struct symbol
*sym
,
10169 LONGEST l
= DW_UNSND (attr
);
10171 if (bits
< sizeof (l
) * 8)
10173 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
10174 l
&= ((LONGEST
) 1 << bits
) - 1;
10176 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
10179 SYMBOL_VALUE (sym
) = l
;
10180 SYMBOL_CLASS (sym
) = LOC_CONST
;
10184 /* Return the type of the die in question using its DW_AT_type attribute. */
10186 static struct type
*
10187 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10189 struct attribute
*type_attr
;
10190 struct die_info
*type_die
;
10192 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
10195 /* A missing DW_AT_type represents a void type. */
10196 return objfile_type (cu
->objfile
)->builtin_void
;
10199 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10201 return tag_type_to_type (type_die
, cu
);
10204 /* True iff CU's producer generates GNAT Ada auxiliary information
10205 that allows to find parallel types through that information instead
10206 of having to do expensive parallel lookups by type name. */
10209 need_gnat_info (struct dwarf2_cu
*cu
)
10211 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
10212 of GNAT produces this auxiliary information, without any indication
10213 that it is produced. Part of enhancing the FSF version of GNAT
10214 to produce that information will be to put in place an indicator
10215 that we can use in order to determine whether the descriptive type
10216 info is available or not. One suggestion that has been made is
10217 to use a new attribute, attached to the CU die. For now, assume
10218 that the descriptive type info is not available. */
10223 /* Return the auxiliary type of the die in question using its
10224 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
10225 attribute is not present. */
10227 static struct type
*
10228 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10230 struct attribute
*type_attr
;
10231 struct die_info
*type_die
;
10233 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
10237 type_die
= follow_die_ref (die
, type_attr
, &cu
);
10238 return tag_type_to_type (type_die
, cu
);
10241 /* If DIE has a descriptive_type attribute, then set the TYPE's
10242 descriptive type accordingly. */
10245 set_descriptive_type (struct type
*type
, struct die_info
*die
,
10246 struct dwarf2_cu
*cu
)
10248 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
10250 if (descriptive_type
)
10252 ALLOCATE_GNAT_AUX_TYPE (type
);
10253 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
10257 /* Return the containing type of the die in question using its
10258 DW_AT_containing_type attribute. */
10260 static struct type
*
10261 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10263 struct attribute
*type_attr
;
10264 struct die_info
*type_die
;
10266 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
10268 error (_("Dwarf Error: Problem turning containing type into gdb type "
10269 "[in module %s]"), cu
->objfile
->name
);
10271 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10272 return tag_type_to_type (type_die
, cu
);
10275 static struct type
*
10276 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10278 struct type
*this_type
;
10280 this_type
= read_type_die (die
, cu
);
10283 char *message
, *saved
;
10285 /* read_type_die already issued a complaint. */
10286 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
10290 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
10291 message
, strlen (message
));
10294 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
10299 static struct type
*
10300 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10302 struct type
*this_type
;
10304 this_type
= get_die_type (die
, cu
);
10310 case DW_TAG_class_type
:
10311 case DW_TAG_interface_type
:
10312 case DW_TAG_structure_type
:
10313 case DW_TAG_union_type
:
10314 this_type
= read_structure_type (die
, cu
);
10316 case DW_TAG_enumeration_type
:
10317 this_type
= read_enumeration_type (die
, cu
);
10319 case DW_TAG_subprogram
:
10320 case DW_TAG_subroutine_type
:
10321 case DW_TAG_inlined_subroutine
:
10322 this_type
= read_subroutine_type (die
, cu
);
10324 case DW_TAG_array_type
:
10325 this_type
= read_array_type (die
, cu
);
10327 case DW_TAG_set_type
:
10328 this_type
= read_set_type (die
, cu
);
10330 case DW_TAG_pointer_type
:
10331 this_type
= read_tag_pointer_type (die
, cu
);
10333 case DW_TAG_ptr_to_member_type
:
10334 this_type
= read_tag_ptr_to_member_type (die
, cu
);
10336 case DW_TAG_reference_type
:
10337 this_type
= read_tag_reference_type (die
, cu
);
10339 case DW_TAG_const_type
:
10340 this_type
= read_tag_const_type (die
, cu
);
10342 case DW_TAG_volatile_type
:
10343 this_type
= read_tag_volatile_type (die
, cu
);
10345 case DW_TAG_string_type
:
10346 this_type
= read_tag_string_type (die
, cu
);
10348 case DW_TAG_typedef
:
10349 this_type
= read_typedef (die
, cu
);
10351 case DW_TAG_subrange_type
:
10352 this_type
= read_subrange_type (die
, cu
);
10354 case DW_TAG_base_type
:
10355 this_type
= read_base_type (die
, cu
);
10357 case DW_TAG_unspecified_type
:
10358 this_type
= read_unspecified_type (die
, cu
);
10360 case DW_TAG_namespace
:
10361 this_type
= read_namespace_type (die
, cu
);
10363 case DW_TAG_module
:
10364 this_type
= read_module_type (die
, cu
);
10367 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
10368 dwarf_tag_name (die
->tag
));
10375 /* Return the name of the namespace/class that DIE is defined within,
10376 or "" if we can't tell. The caller should not xfree the result.
10378 For example, if we're within the method foo() in the following
10388 then determine_prefix on foo's die will return "N::C". */
10391 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
10393 struct die_info
*parent
, *spec_die
;
10394 struct dwarf2_cu
*spec_cu
;
10395 struct type
*parent_type
;
10397 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
10398 && cu
->language
!= language_fortran
)
10401 /* We have to be careful in the presence of DW_AT_specification.
10402 For example, with GCC 3.4, given the code
10406 // Definition of N::foo.
10410 then we'll have a tree of DIEs like this:
10412 1: DW_TAG_compile_unit
10413 2: DW_TAG_namespace // N
10414 3: DW_TAG_subprogram // declaration of N::foo
10415 4: DW_TAG_subprogram // definition of N::foo
10416 DW_AT_specification // refers to die #3
10418 Thus, when processing die #4, we have to pretend that we're in
10419 the context of its DW_AT_specification, namely the contex of die
10422 spec_die
= die_specification (die
, &spec_cu
);
10423 if (spec_die
== NULL
)
10424 parent
= die
->parent
;
10427 parent
= spec_die
->parent
;
10431 if (parent
== NULL
)
10434 switch (parent
->tag
)
10436 case DW_TAG_namespace
:
10437 parent_type
= read_type_die (parent
, cu
);
10438 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
10439 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
10440 Work around this problem here. */
10441 if (cu
->language
== language_cplus
10442 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
10444 /* We give a name to even anonymous namespaces. */
10445 return TYPE_TAG_NAME (parent_type
);
10446 case DW_TAG_class_type
:
10447 case DW_TAG_interface_type
:
10448 case DW_TAG_structure_type
:
10449 case DW_TAG_union_type
:
10450 case DW_TAG_module
:
10451 parent_type
= read_type_die (parent
, cu
);
10452 if (TYPE_TAG_NAME (parent_type
) != NULL
)
10453 return TYPE_TAG_NAME (parent_type
);
10455 /* An anonymous structure is only allowed non-static data
10456 members; no typedefs, no member functions, et cetera.
10457 So it does not need a prefix. */
10460 return determine_prefix (parent
, cu
);
10464 /* Return a newly-allocated string formed by concatenating PREFIX and
10465 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
10466 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
10467 perform an obconcat, otherwise allocate storage for the result. The CU argument
10468 is used to determine the language and hence, the appropriate separator. */
10470 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
10473 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
10474 int physname
, struct dwarf2_cu
*cu
)
10476 const char *lead
= "";
10479 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
10481 else if (cu
->language
== language_java
)
10483 else if (cu
->language
== language_fortran
&& physname
)
10485 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
10486 DW_AT_MIPS_linkage_name is preferred and used instead. */
10494 if (prefix
== NULL
)
10496 if (suffix
== NULL
)
10501 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
10503 strcpy (retval
, lead
);
10504 strcat (retval
, prefix
);
10505 strcat (retval
, sep
);
10506 strcat (retval
, suffix
);
10511 /* We have an obstack. */
10512 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
10516 /* Return sibling of die, NULL if no sibling. */
10518 static struct die_info
*
10519 sibling_die (struct die_info
*die
)
10521 return die
->sibling
;
10524 /* Get name of a die, return NULL if not found. */
10527 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
10528 struct obstack
*obstack
)
10530 if (name
&& cu
->language
== language_cplus
)
10532 char *canon_name
= cp_canonicalize_string (name
);
10534 if (canon_name
!= NULL
)
10536 if (strcmp (canon_name
, name
) != 0)
10537 name
= obsavestring (canon_name
, strlen (canon_name
),
10539 xfree (canon_name
);
10546 /* Get name of a die, return NULL if not found. */
10549 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10551 struct attribute
*attr
;
10553 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10554 if (!attr
|| !DW_STRING (attr
))
10559 case DW_TAG_compile_unit
:
10560 /* Compilation units have a DW_AT_name that is a filename, not
10561 a source language identifier. */
10562 case DW_TAG_enumeration_type
:
10563 case DW_TAG_enumerator
:
10564 /* These tags always have simple identifiers already; no need
10565 to canonicalize them. */
10566 return DW_STRING (attr
);
10568 case DW_TAG_subprogram
:
10569 /* Java constructors will all be named "<init>", so return
10570 the class name when we see this special case. */
10571 if (cu
->language
== language_java
10572 && DW_STRING (attr
) != NULL
10573 && strcmp (DW_STRING (attr
), "<init>") == 0)
10575 struct dwarf2_cu
*spec_cu
= cu
;
10576 struct die_info
*spec_die
;
10578 /* GCJ will output '<init>' for Java constructor names.
10579 For this special case, return the name of the parent class. */
10581 /* GCJ may output suprogram DIEs with AT_specification set.
10582 If so, use the name of the specified DIE. */
10583 spec_die
= die_specification (die
, &spec_cu
);
10584 if (spec_die
!= NULL
)
10585 return dwarf2_name (spec_die
, spec_cu
);
10590 if (die
->tag
== DW_TAG_class_type
)
10591 return dwarf2_name (die
, cu
);
10593 while (die
->tag
!= DW_TAG_compile_unit
);
10597 case DW_TAG_class_type
:
10598 case DW_TAG_interface_type
:
10599 case DW_TAG_structure_type
:
10600 case DW_TAG_union_type
:
10601 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
10602 structures or unions. These were of the form "._%d" in GCC 4.1,
10603 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
10604 and GCC 4.4. We work around this problem by ignoring these. */
10605 if (strncmp (DW_STRING (attr
), "._", 2) == 0
10606 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
10614 if (!DW_STRING_IS_CANONICAL (attr
))
10617 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
10618 &cu
->objfile
->objfile_obstack
);
10619 DW_STRING_IS_CANONICAL (attr
) = 1;
10621 return DW_STRING (attr
);
10624 /* Return the die that this die in an extension of, or NULL if there
10625 is none. *EXT_CU is the CU containing DIE on input, and the CU
10626 containing the return value on output. */
10628 static struct die_info
*
10629 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
10631 struct attribute
*attr
;
10633 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
10637 return follow_die_ref (die
, attr
, ext_cu
);
10640 /* Convert a DIE tag into its string name. */
10643 dwarf_tag_name (unsigned tag
)
10647 case DW_TAG_padding
:
10648 return "DW_TAG_padding";
10649 case DW_TAG_array_type
:
10650 return "DW_TAG_array_type";
10651 case DW_TAG_class_type
:
10652 return "DW_TAG_class_type";
10653 case DW_TAG_entry_point
:
10654 return "DW_TAG_entry_point";
10655 case DW_TAG_enumeration_type
:
10656 return "DW_TAG_enumeration_type";
10657 case DW_TAG_formal_parameter
:
10658 return "DW_TAG_formal_parameter";
10659 case DW_TAG_imported_declaration
:
10660 return "DW_TAG_imported_declaration";
10662 return "DW_TAG_label";
10663 case DW_TAG_lexical_block
:
10664 return "DW_TAG_lexical_block";
10665 case DW_TAG_member
:
10666 return "DW_TAG_member";
10667 case DW_TAG_pointer_type
:
10668 return "DW_TAG_pointer_type";
10669 case DW_TAG_reference_type
:
10670 return "DW_TAG_reference_type";
10671 case DW_TAG_compile_unit
:
10672 return "DW_TAG_compile_unit";
10673 case DW_TAG_string_type
:
10674 return "DW_TAG_string_type";
10675 case DW_TAG_structure_type
:
10676 return "DW_TAG_structure_type";
10677 case DW_TAG_subroutine_type
:
10678 return "DW_TAG_subroutine_type";
10679 case DW_TAG_typedef
:
10680 return "DW_TAG_typedef";
10681 case DW_TAG_union_type
:
10682 return "DW_TAG_union_type";
10683 case DW_TAG_unspecified_parameters
:
10684 return "DW_TAG_unspecified_parameters";
10685 case DW_TAG_variant
:
10686 return "DW_TAG_variant";
10687 case DW_TAG_common_block
:
10688 return "DW_TAG_common_block";
10689 case DW_TAG_common_inclusion
:
10690 return "DW_TAG_common_inclusion";
10691 case DW_TAG_inheritance
:
10692 return "DW_TAG_inheritance";
10693 case DW_TAG_inlined_subroutine
:
10694 return "DW_TAG_inlined_subroutine";
10695 case DW_TAG_module
:
10696 return "DW_TAG_module";
10697 case DW_TAG_ptr_to_member_type
:
10698 return "DW_TAG_ptr_to_member_type";
10699 case DW_TAG_set_type
:
10700 return "DW_TAG_set_type";
10701 case DW_TAG_subrange_type
:
10702 return "DW_TAG_subrange_type";
10703 case DW_TAG_with_stmt
:
10704 return "DW_TAG_with_stmt";
10705 case DW_TAG_access_declaration
:
10706 return "DW_TAG_access_declaration";
10707 case DW_TAG_base_type
:
10708 return "DW_TAG_base_type";
10709 case DW_TAG_catch_block
:
10710 return "DW_TAG_catch_block";
10711 case DW_TAG_const_type
:
10712 return "DW_TAG_const_type";
10713 case DW_TAG_constant
:
10714 return "DW_TAG_constant";
10715 case DW_TAG_enumerator
:
10716 return "DW_TAG_enumerator";
10717 case DW_TAG_file_type
:
10718 return "DW_TAG_file_type";
10719 case DW_TAG_friend
:
10720 return "DW_TAG_friend";
10721 case DW_TAG_namelist
:
10722 return "DW_TAG_namelist";
10723 case DW_TAG_namelist_item
:
10724 return "DW_TAG_namelist_item";
10725 case DW_TAG_packed_type
:
10726 return "DW_TAG_packed_type";
10727 case DW_TAG_subprogram
:
10728 return "DW_TAG_subprogram";
10729 case DW_TAG_template_type_param
:
10730 return "DW_TAG_template_type_param";
10731 case DW_TAG_template_value_param
:
10732 return "DW_TAG_template_value_param";
10733 case DW_TAG_thrown_type
:
10734 return "DW_TAG_thrown_type";
10735 case DW_TAG_try_block
:
10736 return "DW_TAG_try_block";
10737 case DW_TAG_variant_part
:
10738 return "DW_TAG_variant_part";
10739 case DW_TAG_variable
:
10740 return "DW_TAG_variable";
10741 case DW_TAG_volatile_type
:
10742 return "DW_TAG_volatile_type";
10743 case DW_TAG_dwarf_procedure
:
10744 return "DW_TAG_dwarf_procedure";
10745 case DW_TAG_restrict_type
:
10746 return "DW_TAG_restrict_type";
10747 case DW_TAG_interface_type
:
10748 return "DW_TAG_interface_type";
10749 case DW_TAG_namespace
:
10750 return "DW_TAG_namespace";
10751 case DW_TAG_imported_module
:
10752 return "DW_TAG_imported_module";
10753 case DW_TAG_unspecified_type
:
10754 return "DW_TAG_unspecified_type";
10755 case DW_TAG_partial_unit
:
10756 return "DW_TAG_partial_unit";
10757 case DW_TAG_imported_unit
:
10758 return "DW_TAG_imported_unit";
10759 case DW_TAG_condition
:
10760 return "DW_TAG_condition";
10761 case DW_TAG_shared_type
:
10762 return "DW_TAG_shared_type";
10763 case DW_TAG_type_unit
:
10764 return "DW_TAG_type_unit";
10765 case DW_TAG_MIPS_loop
:
10766 return "DW_TAG_MIPS_loop";
10767 case DW_TAG_HP_array_descriptor
:
10768 return "DW_TAG_HP_array_descriptor";
10769 case DW_TAG_format_label
:
10770 return "DW_TAG_format_label";
10771 case DW_TAG_function_template
:
10772 return "DW_TAG_function_template";
10773 case DW_TAG_class_template
:
10774 return "DW_TAG_class_template";
10775 case DW_TAG_GNU_BINCL
:
10776 return "DW_TAG_GNU_BINCL";
10777 case DW_TAG_GNU_EINCL
:
10778 return "DW_TAG_GNU_EINCL";
10779 case DW_TAG_upc_shared_type
:
10780 return "DW_TAG_upc_shared_type";
10781 case DW_TAG_upc_strict_type
:
10782 return "DW_TAG_upc_strict_type";
10783 case DW_TAG_upc_relaxed_type
:
10784 return "DW_TAG_upc_relaxed_type";
10785 case DW_TAG_PGI_kanji_type
:
10786 return "DW_TAG_PGI_kanji_type";
10787 case DW_TAG_PGI_interface_block
:
10788 return "DW_TAG_PGI_interface_block";
10790 return "DW_TAG_<unknown>";
10794 /* Convert a DWARF attribute code into its string name. */
10797 dwarf_attr_name (unsigned attr
)
10801 case DW_AT_sibling
:
10802 return "DW_AT_sibling";
10803 case DW_AT_location
:
10804 return "DW_AT_location";
10806 return "DW_AT_name";
10807 case DW_AT_ordering
:
10808 return "DW_AT_ordering";
10809 case DW_AT_subscr_data
:
10810 return "DW_AT_subscr_data";
10811 case DW_AT_byte_size
:
10812 return "DW_AT_byte_size";
10813 case DW_AT_bit_offset
:
10814 return "DW_AT_bit_offset";
10815 case DW_AT_bit_size
:
10816 return "DW_AT_bit_size";
10817 case DW_AT_element_list
:
10818 return "DW_AT_element_list";
10819 case DW_AT_stmt_list
:
10820 return "DW_AT_stmt_list";
10822 return "DW_AT_low_pc";
10823 case DW_AT_high_pc
:
10824 return "DW_AT_high_pc";
10825 case DW_AT_language
:
10826 return "DW_AT_language";
10828 return "DW_AT_member";
10830 return "DW_AT_discr";
10831 case DW_AT_discr_value
:
10832 return "DW_AT_discr_value";
10833 case DW_AT_visibility
:
10834 return "DW_AT_visibility";
10836 return "DW_AT_import";
10837 case DW_AT_string_length
:
10838 return "DW_AT_string_length";
10839 case DW_AT_common_reference
:
10840 return "DW_AT_common_reference";
10841 case DW_AT_comp_dir
:
10842 return "DW_AT_comp_dir";
10843 case DW_AT_const_value
:
10844 return "DW_AT_const_value";
10845 case DW_AT_containing_type
:
10846 return "DW_AT_containing_type";
10847 case DW_AT_default_value
:
10848 return "DW_AT_default_value";
10850 return "DW_AT_inline";
10851 case DW_AT_is_optional
:
10852 return "DW_AT_is_optional";
10853 case DW_AT_lower_bound
:
10854 return "DW_AT_lower_bound";
10855 case DW_AT_producer
:
10856 return "DW_AT_producer";
10857 case DW_AT_prototyped
:
10858 return "DW_AT_prototyped";
10859 case DW_AT_return_addr
:
10860 return "DW_AT_return_addr";
10861 case DW_AT_start_scope
:
10862 return "DW_AT_start_scope";
10863 case DW_AT_bit_stride
:
10864 return "DW_AT_bit_stride";
10865 case DW_AT_upper_bound
:
10866 return "DW_AT_upper_bound";
10867 case DW_AT_abstract_origin
:
10868 return "DW_AT_abstract_origin";
10869 case DW_AT_accessibility
:
10870 return "DW_AT_accessibility";
10871 case DW_AT_address_class
:
10872 return "DW_AT_address_class";
10873 case DW_AT_artificial
:
10874 return "DW_AT_artificial";
10875 case DW_AT_base_types
:
10876 return "DW_AT_base_types";
10877 case DW_AT_calling_convention
:
10878 return "DW_AT_calling_convention";
10880 return "DW_AT_count";
10881 case DW_AT_data_member_location
:
10882 return "DW_AT_data_member_location";
10883 case DW_AT_decl_column
:
10884 return "DW_AT_decl_column";
10885 case DW_AT_decl_file
:
10886 return "DW_AT_decl_file";
10887 case DW_AT_decl_line
:
10888 return "DW_AT_decl_line";
10889 case DW_AT_declaration
:
10890 return "DW_AT_declaration";
10891 case DW_AT_discr_list
:
10892 return "DW_AT_discr_list";
10893 case DW_AT_encoding
:
10894 return "DW_AT_encoding";
10895 case DW_AT_external
:
10896 return "DW_AT_external";
10897 case DW_AT_frame_base
:
10898 return "DW_AT_frame_base";
10900 return "DW_AT_friend";
10901 case DW_AT_identifier_case
:
10902 return "DW_AT_identifier_case";
10903 case DW_AT_macro_info
:
10904 return "DW_AT_macro_info";
10905 case DW_AT_namelist_items
:
10906 return "DW_AT_namelist_items";
10907 case DW_AT_priority
:
10908 return "DW_AT_priority";
10909 case DW_AT_segment
:
10910 return "DW_AT_segment";
10911 case DW_AT_specification
:
10912 return "DW_AT_specification";
10913 case DW_AT_static_link
:
10914 return "DW_AT_static_link";
10916 return "DW_AT_type";
10917 case DW_AT_use_location
:
10918 return "DW_AT_use_location";
10919 case DW_AT_variable_parameter
:
10920 return "DW_AT_variable_parameter";
10921 case DW_AT_virtuality
:
10922 return "DW_AT_virtuality";
10923 case DW_AT_vtable_elem_location
:
10924 return "DW_AT_vtable_elem_location";
10925 /* DWARF 3 values. */
10926 case DW_AT_allocated
:
10927 return "DW_AT_allocated";
10928 case DW_AT_associated
:
10929 return "DW_AT_associated";
10930 case DW_AT_data_location
:
10931 return "DW_AT_data_location";
10932 case DW_AT_byte_stride
:
10933 return "DW_AT_byte_stride";
10934 case DW_AT_entry_pc
:
10935 return "DW_AT_entry_pc";
10936 case DW_AT_use_UTF8
:
10937 return "DW_AT_use_UTF8";
10938 case DW_AT_extension
:
10939 return "DW_AT_extension";
10941 return "DW_AT_ranges";
10942 case DW_AT_trampoline
:
10943 return "DW_AT_trampoline";
10944 case DW_AT_call_column
:
10945 return "DW_AT_call_column";
10946 case DW_AT_call_file
:
10947 return "DW_AT_call_file";
10948 case DW_AT_call_line
:
10949 return "DW_AT_call_line";
10950 case DW_AT_description
:
10951 return "DW_AT_description";
10952 case DW_AT_binary_scale
:
10953 return "DW_AT_binary_scale";
10954 case DW_AT_decimal_scale
:
10955 return "DW_AT_decimal_scale";
10957 return "DW_AT_small";
10958 case DW_AT_decimal_sign
:
10959 return "DW_AT_decimal_sign";
10960 case DW_AT_digit_count
:
10961 return "DW_AT_digit_count";
10962 case DW_AT_picture_string
:
10963 return "DW_AT_picture_string";
10964 case DW_AT_mutable
:
10965 return "DW_AT_mutable";
10966 case DW_AT_threads_scaled
:
10967 return "DW_AT_threads_scaled";
10968 case DW_AT_explicit
:
10969 return "DW_AT_explicit";
10970 case DW_AT_object_pointer
:
10971 return "DW_AT_object_pointer";
10972 case DW_AT_endianity
:
10973 return "DW_AT_endianity";
10974 case DW_AT_elemental
:
10975 return "DW_AT_elemental";
10977 return "DW_AT_pure";
10978 case DW_AT_recursive
:
10979 return "DW_AT_recursive";
10980 /* DWARF 4 values. */
10981 case DW_AT_signature
:
10982 return "DW_AT_signature";
10983 case DW_AT_linkage_name
:
10984 return "DW_AT_linkage_name";
10985 /* SGI/MIPS extensions. */
10986 #ifdef MIPS /* collides with DW_AT_HP_block_index */
10987 case DW_AT_MIPS_fde
:
10988 return "DW_AT_MIPS_fde";
10990 case DW_AT_MIPS_loop_begin
:
10991 return "DW_AT_MIPS_loop_begin";
10992 case DW_AT_MIPS_tail_loop_begin
:
10993 return "DW_AT_MIPS_tail_loop_begin";
10994 case DW_AT_MIPS_epilog_begin
:
10995 return "DW_AT_MIPS_epilog_begin";
10996 case DW_AT_MIPS_loop_unroll_factor
:
10997 return "DW_AT_MIPS_loop_unroll_factor";
10998 case DW_AT_MIPS_software_pipeline_depth
:
10999 return "DW_AT_MIPS_software_pipeline_depth";
11000 case DW_AT_MIPS_linkage_name
:
11001 return "DW_AT_MIPS_linkage_name";
11002 case DW_AT_MIPS_stride
:
11003 return "DW_AT_MIPS_stride";
11004 case DW_AT_MIPS_abstract_name
:
11005 return "DW_AT_MIPS_abstract_name";
11006 case DW_AT_MIPS_clone_origin
:
11007 return "DW_AT_MIPS_clone_origin";
11008 case DW_AT_MIPS_has_inlines
:
11009 return "DW_AT_MIPS_has_inlines";
11010 /* HP extensions. */
11011 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11012 case DW_AT_HP_block_index
:
11013 return "DW_AT_HP_block_index";
11015 case DW_AT_HP_unmodifiable
:
11016 return "DW_AT_HP_unmodifiable";
11017 case DW_AT_HP_actuals_stmt_list
:
11018 return "DW_AT_HP_actuals_stmt_list";
11019 case DW_AT_HP_proc_per_section
:
11020 return "DW_AT_HP_proc_per_section";
11021 case DW_AT_HP_raw_data_ptr
:
11022 return "DW_AT_HP_raw_data_ptr";
11023 case DW_AT_HP_pass_by_reference
:
11024 return "DW_AT_HP_pass_by_reference";
11025 case DW_AT_HP_opt_level
:
11026 return "DW_AT_HP_opt_level";
11027 case DW_AT_HP_prof_version_id
:
11028 return "DW_AT_HP_prof_version_id";
11029 case DW_AT_HP_opt_flags
:
11030 return "DW_AT_HP_opt_flags";
11031 case DW_AT_HP_cold_region_low_pc
:
11032 return "DW_AT_HP_cold_region_low_pc";
11033 case DW_AT_HP_cold_region_high_pc
:
11034 return "DW_AT_HP_cold_region_high_pc";
11035 case DW_AT_HP_all_variables_modifiable
:
11036 return "DW_AT_HP_all_variables_modifiable";
11037 case DW_AT_HP_linkage_name
:
11038 return "DW_AT_HP_linkage_name";
11039 case DW_AT_HP_prof_flags
:
11040 return "DW_AT_HP_prof_flags";
11041 /* GNU extensions. */
11042 case DW_AT_sf_names
:
11043 return "DW_AT_sf_names";
11044 case DW_AT_src_info
:
11045 return "DW_AT_src_info";
11046 case DW_AT_mac_info
:
11047 return "DW_AT_mac_info";
11048 case DW_AT_src_coords
:
11049 return "DW_AT_src_coords";
11050 case DW_AT_body_begin
:
11051 return "DW_AT_body_begin";
11052 case DW_AT_body_end
:
11053 return "DW_AT_body_end";
11054 case DW_AT_GNU_vector
:
11055 return "DW_AT_GNU_vector";
11056 /* VMS extensions. */
11057 case DW_AT_VMS_rtnbeg_pd_address
:
11058 return "DW_AT_VMS_rtnbeg_pd_address";
11059 /* UPC extension. */
11060 case DW_AT_upc_threads_scaled
:
11061 return "DW_AT_upc_threads_scaled";
11062 /* PGI (STMicroelectronics) extensions. */
11063 case DW_AT_PGI_lbase
:
11064 return "DW_AT_PGI_lbase";
11065 case DW_AT_PGI_soffset
:
11066 return "DW_AT_PGI_soffset";
11067 case DW_AT_PGI_lstride
:
11068 return "DW_AT_PGI_lstride";
11070 return "DW_AT_<unknown>";
11074 /* Convert a DWARF value form code into its string name. */
11077 dwarf_form_name (unsigned form
)
11082 return "DW_FORM_addr";
11083 case DW_FORM_block2
:
11084 return "DW_FORM_block2";
11085 case DW_FORM_block4
:
11086 return "DW_FORM_block4";
11087 case DW_FORM_data2
:
11088 return "DW_FORM_data2";
11089 case DW_FORM_data4
:
11090 return "DW_FORM_data4";
11091 case DW_FORM_data8
:
11092 return "DW_FORM_data8";
11093 case DW_FORM_string
:
11094 return "DW_FORM_string";
11095 case DW_FORM_block
:
11096 return "DW_FORM_block";
11097 case DW_FORM_block1
:
11098 return "DW_FORM_block1";
11099 case DW_FORM_data1
:
11100 return "DW_FORM_data1";
11102 return "DW_FORM_flag";
11103 case DW_FORM_sdata
:
11104 return "DW_FORM_sdata";
11106 return "DW_FORM_strp";
11107 case DW_FORM_udata
:
11108 return "DW_FORM_udata";
11109 case DW_FORM_ref_addr
:
11110 return "DW_FORM_ref_addr";
11112 return "DW_FORM_ref1";
11114 return "DW_FORM_ref2";
11116 return "DW_FORM_ref4";
11118 return "DW_FORM_ref8";
11119 case DW_FORM_ref_udata
:
11120 return "DW_FORM_ref_udata";
11121 case DW_FORM_indirect
:
11122 return "DW_FORM_indirect";
11123 case DW_FORM_sec_offset
:
11124 return "DW_FORM_sec_offset";
11125 case DW_FORM_exprloc
:
11126 return "DW_FORM_exprloc";
11127 case DW_FORM_flag_present
:
11128 return "DW_FORM_flag_present";
11130 return "DW_FORM_sig8";
11132 return "DW_FORM_<unknown>";
11136 /* Convert a DWARF stack opcode into its string name. */
11139 dwarf_stack_op_name (unsigned op
, int def
)
11144 return "DW_OP_addr";
11146 return "DW_OP_deref";
11147 case DW_OP_const1u
:
11148 return "DW_OP_const1u";
11149 case DW_OP_const1s
:
11150 return "DW_OP_const1s";
11151 case DW_OP_const2u
:
11152 return "DW_OP_const2u";
11153 case DW_OP_const2s
:
11154 return "DW_OP_const2s";
11155 case DW_OP_const4u
:
11156 return "DW_OP_const4u";
11157 case DW_OP_const4s
:
11158 return "DW_OP_const4s";
11159 case DW_OP_const8u
:
11160 return "DW_OP_const8u";
11161 case DW_OP_const8s
:
11162 return "DW_OP_const8s";
11164 return "DW_OP_constu";
11166 return "DW_OP_consts";
11168 return "DW_OP_dup";
11170 return "DW_OP_drop";
11172 return "DW_OP_over";
11174 return "DW_OP_pick";
11176 return "DW_OP_swap";
11178 return "DW_OP_rot";
11180 return "DW_OP_xderef";
11182 return "DW_OP_abs";
11184 return "DW_OP_and";
11186 return "DW_OP_div";
11188 return "DW_OP_minus";
11190 return "DW_OP_mod";
11192 return "DW_OP_mul";
11194 return "DW_OP_neg";
11196 return "DW_OP_not";
11200 return "DW_OP_plus";
11201 case DW_OP_plus_uconst
:
11202 return "DW_OP_plus_uconst";
11204 return "DW_OP_shl";
11206 return "DW_OP_shr";
11208 return "DW_OP_shra";
11210 return "DW_OP_xor";
11212 return "DW_OP_bra";
11226 return "DW_OP_skip";
11228 return "DW_OP_lit0";
11230 return "DW_OP_lit1";
11232 return "DW_OP_lit2";
11234 return "DW_OP_lit3";
11236 return "DW_OP_lit4";
11238 return "DW_OP_lit5";
11240 return "DW_OP_lit6";
11242 return "DW_OP_lit7";
11244 return "DW_OP_lit8";
11246 return "DW_OP_lit9";
11248 return "DW_OP_lit10";
11250 return "DW_OP_lit11";
11252 return "DW_OP_lit12";
11254 return "DW_OP_lit13";
11256 return "DW_OP_lit14";
11258 return "DW_OP_lit15";
11260 return "DW_OP_lit16";
11262 return "DW_OP_lit17";
11264 return "DW_OP_lit18";
11266 return "DW_OP_lit19";
11268 return "DW_OP_lit20";
11270 return "DW_OP_lit21";
11272 return "DW_OP_lit22";
11274 return "DW_OP_lit23";
11276 return "DW_OP_lit24";
11278 return "DW_OP_lit25";
11280 return "DW_OP_lit26";
11282 return "DW_OP_lit27";
11284 return "DW_OP_lit28";
11286 return "DW_OP_lit29";
11288 return "DW_OP_lit30";
11290 return "DW_OP_lit31";
11292 return "DW_OP_reg0";
11294 return "DW_OP_reg1";
11296 return "DW_OP_reg2";
11298 return "DW_OP_reg3";
11300 return "DW_OP_reg4";
11302 return "DW_OP_reg5";
11304 return "DW_OP_reg6";
11306 return "DW_OP_reg7";
11308 return "DW_OP_reg8";
11310 return "DW_OP_reg9";
11312 return "DW_OP_reg10";
11314 return "DW_OP_reg11";
11316 return "DW_OP_reg12";
11318 return "DW_OP_reg13";
11320 return "DW_OP_reg14";
11322 return "DW_OP_reg15";
11324 return "DW_OP_reg16";
11326 return "DW_OP_reg17";
11328 return "DW_OP_reg18";
11330 return "DW_OP_reg19";
11332 return "DW_OP_reg20";
11334 return "DW_OP_reg21";
11336 return "DW_OP_reg22";
11338 return "DW_OP_reg23";
11340 return "DW_OP_reg24";
11342 return "DW_OP_reg25";
11344 return "DW_OP_reg26";
11346 return "DW_OP_reg27";
11348 return "DW_OP_reg28";
11350 return "DW_OP_reg29";
11352 return "DW_OP_reg30";
11354 return "DW_OP_reg31";
11356 return "DW_OP_breg0";
11358 return "DW_OP_breg1";
11360 return "DW_OP_breg2";
11362 return "DW_OP_breg3";
11364 return "DW_OP_breg4";
11366 return "DW_OP_breg5";
11368 return "DW_OP_breg6";
11370 return "DW_OP_breg7";
11372 return "DW_OP_breg8";
11374 return "DW_OP_breg9";
11376 return "DW_OP_breg10";
11378 return "DW_OP_breg11";
11380 return "DW_OP_breg12";
11382 return "DW_OP_breg13";
11384 return "DW_OP_breg14";
11386 return "DW_OP_breg15";
11388 return "DW_OP_breg16";
11390 return "DW_OP_breg17";
11392 return "DW_OP_breg18";
11394 return "DW_OP_breg19";
11396 return "DW_OP_breg20";
11398 return "DW_OP_breg21";
11400 return "DW_OP_breg22";
11402 return "DW_OP_breg23";
11404 return "DW_OP_breg24";
11406 return "DW_OP_breg25";
11408 return "DW_OP_breg26";
11410 return "DW_OP_breg27";
11412 return "DW_OP_breg28";
11414 return "DW_OP_breg29";
11416 return "DW_OP_breg30";
11418 return "DW_OP_breg31";
11420 return "DW_OP_regx";
11422 return "DW_OP_fbreg";
11424 return "DW_OP_bregx";
11426 return "DW_OP_piece";
11427 case DW_OP_deref_size
:
11428 return "DW_OP_deref_size";
11429 case DW_OP_xderef_size
:
11430 return "DW_OP_xderef_size";
11432 return "DW_OP_nop";
11433 /* DWARF 3 extensions. */
11434 case DW_OP_push_object_address
:
11435 return "DW_OP_push_object_address";
11437 return "DW_OP_call2";
11439 return "DW_OP_call4";
11440 case DW_OP_call_ref
:
11441 return "DW_OP_call_ref";
11442 case DW_OP_form_tls_address
:
11443 return "DW_OP_form_tls_address";
11444 case DW_OP_call_frame_cfa
:
11445 return "DW_OP_call_frame_cfa";
11446 case DW_OP_bit_piece
:
11447 return "DW_OP_bit_piece";
11448 /* DWARF 4 extensions. */
11449 case DW_OP_implicit_value
:
11450 return "DW_OP_implicit_value";
11451 case DW_OP_stack_value
:
11452 return "DW_OP_stack_value";
11453 /* GNU extensions. */
11454 case DW_OP_GNU_push_tls_address
:
11455 return "DW_OP_GNU_push_tls_address";
11456 case DW_OP_GNU_uninit
:
11457 return "DW_OP_GNU_uninit";
11459 return def
? "OP_<unknown>" : NULL
;
11464 dwarf_bool_name (unsigned mybool
)
11472 /* Convert a DWARF type code into its string name. */
11475 dwarf_type_encoding_name (unsigned enc
)
11480 return "DW_ATE_void";
11481 case DW_ATE_address
:
11482 return "DW_ATE_address";
11483 case DW_ATE_boolean
:
11484 return "DW_ATE_boolean";
11485 case DW_ATE_complex_float
:
11486 return "DW_ATE_complex_float";
11488 return "DW_ATE_float";
11489 case DW_ATE_signed
:
11490 return "DW_ATE_signed";
11491 case DW_ATE_signed_char
:
11492 return "DW_ATE_signed_char";
11493 case DW_ATE_unsigned
:
11494 return "DW_ATE_unsigned";
11495 case DW_ATE_unsigned_char
:
11496 return "DW_ATE_unsigned_char";
11498 case DW_ATE_imaginary_float
:
11499 return "DW_ATE_imaginary_float";
11500 case DW_ATE_packed_decimal
:
11501 return "DW_ATE_packed_decimal";
11502 case DW_ATE_numeric_string
:
11503 return "DW_ATE_numeric_string";
11504 case DW_ATE_edited
:
11505 return "DW_ATE_edited";
11506 case DW_ATE_signed_fixed
:
11507 return "DW_ATE_signed_fixed";
11508 case DW_ATE_unsigned_fixed
:
11509 return "DW_ATE_unsigned_fixed";
11510 case DW_ATE_decimal_float
:
11511 return "DW_ATE_decimal_float";
11514 return "DW_ATE_UTF";
11515 /* HP extensions. */
11516 case DW_ATE_HP_float80
:
11517 return "DW_ATE_HP_float80";
11518 case DW_ATE_HP_complex_float80
:
11519 return "DW_ATE_HP_complex_float80";
11520 case DW_ATE_HP_float128
:
11521 return "DW_ATE_HP_float128";
11522 case DW_ATE_HP_complex_float128
:
11523 return "DW_ATE_HP_complex_float128";
11524 case DW_ATE_HP_floathpintel
:
11525 return "DW_ATE_HP_floathpintel";
11526 case DW_ATE_HP_imaginary_float80
:
11527 return "DW_ATE_HP_imaginary_float80";
11528 case DW_ATE_HP_imaginary_float128
:
11529 return "DW_ATE_HP_imaginary_float128";
11531 return "DW_ATE_<unknown>";
11535 /* Convert a DWARF call frame info operation to its string name. */
11539 dwarf_cfi_name (unsigned cfi_opc
)
11543 case DW_CFA_advance_loc
:
11544 return "DW_CFA_advance_loc";
11545 case DW_CFA_offset
:
11546 return "DW_CFA_offset";
11547 case DW_CFA_restore
:
11548 return "DW_CFA_restore";
11550 return "DW_CFA_nop";
11551 case DW_CFA_set_loc
:
11552 return "DW_CFA_set_loc";
11553 case DW_CFA_advance_loc1
:
11554 return "DW_CFA_advance_loc1";
11555 case DW_CFA_advance_loc2
:
11556 return "DW_CFA_advance_loc2";
11557 case DW_CFA_advance_loc4
:
11558 return "DW_CFA_advance_loc4";
11559 case DW_CFA_offset_extended
:
11560 return "DW_CFA_offset_extended";
11561 case DW_CFA_restore_extended
:
11562 return "DW_CFA_restore_extended";
11563 case DW_CFA_undefined
:
11564 return "DW_CFA_undefined";
11565 case DW_CFA_same_value
:
11566 return "DW_CFA_same_value";
11567 case DW_CFA_register
:
11568 return "DW_CFA_register";
11569 case DW_CFA_remember_state
:
11570 return "DW_CFA_remember_state";
11571 case DW_CFA_restore_state
:
11572 return "DW_CFA_restore_state";
11573 case DW_CFA_def_cfa
:
11574 return "DW_CFA_def_cfa";
11575 case DW_CFA_def_cfa_register
:
11576 return "DW_CFA_def_cfa_register";
11577 case DW_CFA_def_cfa_offset
:
11578 return "DW_CFA_def_cfa_offset";
11580 case DW_CFA_def_cfa_expression
:
11581 return "DW_CFA_def_cfa_expression";
11582 case DW_CFA_expression
:
11583 return "DW_CFA_expression";
11584 case DW_CFA_offset_extended_sf
:
11585 return "DW_CFA_offset_extended_sf";
11586 case DW_CFA_def_cfa_sf
:
11587 return "DW_CFA_def_cfa_sf";
11588 case DW_CFA_def_cfa_offset_sf
:
11589 return "DW_CFA_def_cfa_offset_sf";
11590 case DW_CFA_val_offset
:
11591 return "DW_CFA_val_offset";
11592 case DW_CFA_val_offset_sf
:
11593 return "DW_CFA_val_offset_sf";
11594 case DW_CFA_val_expression
:
11595 return "DW_CFA_val_expression";
11596 /* SGI/MIPS specific. */
11597 case DW_CFA_MIPS_advance_loc8
:
11598 return "DW_CFA_MIPS_advance_loc8";
11599 /* GNU extensions. */
11600 case DW_CFA_GNU_window_save
:
11601 return "DW_CFA_GNU_window_save";
11602 case DW_CFA_GNU_args_size
:
11603 return "DW_CFA_GNU_args_size";
11604 case DW_CFA_GNU_negative_offset_extended
:
11605 return "DW_CFA_GNU_negative_offset_extended";
11607 return "DW_CFA_<unknown>";
11613 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
11617 print_spaces (indent
, f
);
11618 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
11619 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
11621 if (die
->parent
!= NULL
)
11623 print_spaces (indent
, f
);
11624 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
11625 die
->parent
->offset
);
11628 print_spaces (indent
, f
);
11629 fprintf_unfiltered (f
, " has children: %s\n",
11630 dwarf_bool_name (die
->child
!= NULL
));
11632 print_spaces (indent
, f
);
11633 fprintf_unfiltered (f
, " attributes:\n");
11635 for (i
= 0; i
< die
->num_attrs
; ++i
)
11637 print_spaces (indent
, f
);
11638 fprintf_unfiltered (f
, " %s (%s) ",
11639 dwarf_attr_name (die
->attrs
[i
].name
),
11640 dwarf_form_name (die
->attrs
[i
].form
));
11642 switch (die
->attrs
[i
].form
)
11644 case DW_FORM_ref_addr
:
11646 fprintf_unfiltered (f
, "address: ");
11647 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
11649 case DW_FORM_block2
:
11650 case DW_FORM_block4
:
11651 case DW_FORM_block
:
11652 case DW_FORM_block1
:
11653 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
11655 case DW_FORM_exprloc
:
11656 fprintf_unfiltered (f
, "expression: size %u",
11657 DW_BLOCK (&die
->attrs
[i
])->size
);
11662 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
11663 (long) (DW_ADDR (&die
->attrs
[i
])));
11665 case DW_FORM_data1
:
11666 case DW_FORM_data2
:
11667 case DW_FORM_data4
:
11668 case DW_FORM_data8
:
11669 case DW_FORM_udata
:
11670 case DW_FORM_sdata
:
11671 fprintf_unfiltered (f
, "constant: %s",
11672 pulongest (DW_UNSND (&die
->attrs
[i
])));
11674 case DW_FORM_sec_offset
:
11675 fprintf_unfiltered (f
, "section offset: %s",
11676 pulongest (DW_UNSND (&die
->attrs
[i
])));
11679 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
11680 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
11681 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
11683 fprintf_unfiltered (f
, "signatured type, offset: unknown");
11685 case DW_FORM_string
:
11687 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
11688 DW_STRING (&die
->attrs
[i
])
11689 ? DW_STRING (&die
->attrs
[i
]) : "",
11690 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
11693 if (DW_UNSND (&die
->attrs
[i
]))
11694 fprintf_unfiltered (f
, "flag: TRUE");
11696 fprintf_unfiltered (f
, "flag: FALSE");
11698 case DW_FORM_flag_present
:
11699 fprintf_unfiltered (f
, "flag: TRUE");
11701 case DW_FORM_indirect
:
11702 /* the reader will have reduced the indirect form to
11703 the "base form" so this form should not occur */
11704 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
11707 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
11708 die
->attrs
[i
].form
);
11711 fprintf_unfiltered (f
, "\n");
11716 dump_die_for_error (struct die_info
*die
)
11718 dump_die_shallow (gdb_stderr
, 0, die
);
11722 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
11724 int indent
= level
* 4;
11726 gdb_assert (die
!= NULL
);
11728 if (level
>= max_level
)
11731 dump_die_shallow (f
, indent
, die
);
11733 if (die
->child
!= NULL
)
11735 print_spaces (indent
, f
);
11736 fprintf_unfiltered (f
, " Children:");
11737 if (level
+ 1 < max_level
)
11739 fprintf_unfiltered (f
, "\n");
11740 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
11744 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
11748 if (die
->sibling
!= NULL
&& level
> 0)
11750 dump_die_1 (f
, level
, max_level
, die
->sibling
);
11754 /* This is called from the pdie macro in gdbinit.in.
11755 It's not static so gcc will keep a copy callable from gdb. */
11758 dump_die (struct die_info
*die
, int max_level
)
11760 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
11764 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
11768 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
11774 is_ref_attr (struct attribute
*attr
)
11776 switch (attr
->form
)
11778 case DW_FORM_ref_addr
:
11783 case DW_FORM_ref_udata
:
11790 static unsigned int
11791 dwarf2_get_ref_die_offset (struct attribute
*attr
)
11793 if (is_ref_attr (attr
))
11794 return DW_ADDR (attr
);
11796 complaint (&symfile_complaints
,
11797 _("unsupported die ref attribute form: '%s'"),
11798 dwarf_form_name (attr
->form
));
11802 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
11803 * the value held by the attribute is not constant. */
11806 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
11808 if (attr
->form
== DW_FORM_sdata
)
11809 return DW_SND (attr
);
11810 else if (attr
->form
== DW_FORM_udata
11811 || attr
->form
== DW_FORM_data1
11812 || attr
->form
== DW_FORM_data2
11813 || attr
->form
== DW_FORM_data4
11814 || attr
->form
== DW_FORM_data8
)
11815 return DW_UNSND (attr
);
11818 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
11819 dwarf_form_name (attr
->form
));
11820 return default_value
;
11824 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
11825 unit and add it to our queue.
11826 The result is non-zero if PER_CU was queued, otherwise the result is zero
11827 meaning either PER_CU is already queued or it is already loaded. */
11830 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
11831 struct dwarf2_per_cu_data
*per_cu
)
11833 /* Mark the dependence relation so that we don't flush PER_CU
11835 dwarf2_add_dependence (this_cu
, per_cu
);
11837 /* If it's already on the queue, we have nothing to do. */
11838 if (per_cu
->queued
)
11841 /* If the compilation unit is already loaded, just mark it as
11843 if (per_cu
->cu
!= NULL
)
11845 per_cu
->cu
->last_used
= 0;
11849 /* Add it to the queue. */
11850 queue_comp_unit (per_cu
, this_cu
->objfile
);
11855 /* Follow reference or signature attribute ATTR of SRC_DIE.
11856 On entry *REF_CU is the CU of SRC_DIE.
11857 On exit *REF_CU is the CU of the result. */
11859 static struct die_info
*
11860 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
11861 struct dwarf2_cu
**ref_cu
)
11863 struct die_info
*die
;
11865 if (is_ref_attr (attr
))
11866 die
= follow_die_ref (src_die
, attr
, ref_cu
);
11867 else if (attr
->form
== DW_FORM_sig8
)
11868 die
= follow_die_sig (src_die
, attr
, ref_cu
);
11871 dump_die_for_error (src_die
);
11872 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
11873 (*ref_cu
)->objfile
->name
);
11879 /* Follow reference OFFSET.
11880 On entry *REF_CU is the CU of source DIE referencing OFFSET.
11881 On exit *REF_CU is the CU of the result. */
11883 static struct die_info
*
11884 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
11886 struct die_info temp_die
;
11887 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
11889 gdb_assert (cu
->per_cu
!= NULL
);
11891 if (cu
->per_cu
->from_debug_types
)
11893 /* .debug_types CUs cannot reference anything outside their CU.
11894 If they need to, they have to reference a signatured type via
11896 if (! offset_in_cu_p (&cu
->header
, offset
))
11900 else if (! offset_in_cu_p (&cu
->header
, offset
))
11902 struct dwarf2_per_cu_data
*per_cu
;
11904 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
11906 /* If necessary, add it to the queue and load its DIEs. */
11907 if (maybe_queue_comp_unit (cu
, per_cu
))
11908 load_full_comp_unit (per_cu
, cu
->objfile
);
11910 target_cu
= per_cu
->cu
;
11915 *ref_cu
= target_cu
;
11916 temp_die
.offset
= offset
;
11917 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
11920 /* Follow reference attribute ATTR of SRC_DIE.
11921 On entry *REF_CU is the CU of SRC_DIE.
11922 On exit *REF_CU is the CU of the result. */
11924 static struct die_info
*
11925 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
11926 struct dwarf2_cu
**ref_cu
)
11928 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11929 struct dwarf2_cu
*cu
= *ref_cu
;
11930 struct die_info
*die
;
11932 die
= follow_die_offset (offset
, ref_cu
);
11934 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
11935 "at 0x%x [in module %s]"),
11936 offset
, src_die
->offset
, cu
->objfile
->name
);
11941 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
11942 value is intended for DW_OP_call*. */
11944 struct dwarf2_locexpr_baton
11945 dwarf2_fetch_die_location_block (unsigned int offset
,
11946 struct dwarf2_per_cu_data
*per_cu
)
11948 struct dwarf2_cu
*cu
= per_cu
->cu
;
11949 struct die_info
*die
;
11950 struct attribute
*attr
;
11951 struct dwarf2_locexpr_baton retval
;
11953 die
= follow_die_offset (offset
, &cu
);
11955 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
11956 offset
, per_cu
->cu
->objfile
->name
);
11958 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11961 /* DWARF: "If there is no such attribute, then there is no effect.". */
11963 retval
.data
= NULL
;
11968 if (!attr_form_is_block (attr
))
11969 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
11970 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
11971 offset
, per_cu
->cu
->objfile
->name
);
11973 retval
.data
= DW_BLOCK (attr
)->data
;
11974 retval
.size
= DW_BLOCK (attr
)->size
;
11976 retval
.per_cu
= cu
->per_cu
;
11980 /* Follow the signature attribute ATTR in SRC_DIE.
11981 On entry *REF_CU is the CU of SRC_DIE.
11982 On exit *REF_CU is the CU of the result. */
11984 static struct die_info
*
11985 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
11986 struct dwarf2_cu
**ref_cu
)
11988 struct objfile
*objfile
= (*ref_cu
)->objfile
;
11989 struct die_info temp_die
;
11990 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11991 struct dwarf2_cu
*sig_cu
;
11992 struct die_info
*die
;
11994 /* sig_type will be NULL if the signatured type is missing from
11996 if (sig_type
== NULL
)
11997 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11998 "at 0x%x [in module %s]"),
11999 src_die
->offset
, objfile
->name
);
12001 /* If necessary, add it to the queue and load its DIEs. */
12003 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
12004 read_signatured_type (objfile
, sig_type
);
12006 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
12008 sig_cu
= sig_type
->per_cu
.cu
;
12009 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
12010 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
12017 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12018 "at 0x%x [in module %s]"),
12019 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
12022 /* Given an offset of a signatured type, return its signatured_type. */
12024 static struct signatured_type
*
12025 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
12027 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
12028 unsigned int length
, initial_length_size
;
12029 unsigned int sig_offset
;
12030 struct signatured_type find_entry
, *type_sig
;
12032 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
12033 sig_offset
= (initial_length_size
12035 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
12036 + 1 /*address_size*/);
12037 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
12038 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
12040 /* This is only used to lookup previously recorded types.
12041 If we didn't find it, it's our bug. */
12042 gdb_assert (type_sig
!= NULL
);
12043 gdb_assert (offset
== type_sig
->offset
);
12048 /* Read in signatured type at OFFSET and build its CU and die(s). */
12051 read_signatured_type_at_offset (struct objfile
*objfile
,
12052 unsigned int offset
)
12054 struct signatured_type
*type_sig
;
12056 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
12058 /* We have the section offset, but we need the signature to do the
12059 hash table lookup. */
12060 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
12062 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12064 read_signatured_type (objfile
, type_sig
);
12066 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
12069 /* Read in a signatured type and build its CU and DIEs. */
12072 read_signatured_type (struct objfile
*objfile
,
12073 struct signatured_type
*type_sig
)
12075 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
12076 struct die_reader_specs reader_specs
;
12077 struct dwarf2_cu
*cu
;
12078 ULONGEST signature
;
12079 struct cleanup
*back_to
, *free_cu_cleanup
;
12080 struct attribute
*attr
;
12082 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12084 cu
= xmalloc (sizeof (struct dwarf2_cu
));
12085 memset (cu
, 0, sizeof (struct dwarf2_cu
));
12086 obstack_init (&cu
->comp_unit_obstack
);
12087 cu
->objfile
= objfile
;
12088 type_sig
->per_cu
.cu
= cu
;
12089 cu
->per_cu
= &type_sig
->per_cu
;
12091 /* If an error occurs while loading, release our storage. */
12092 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
12094 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
12095 types_ptr
, objfile
->obfd
);
12096 gdb_assert (signature
== type_sig
->signature
);
12099 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12103 &cu
->comp_unit_obstack
,
12104 hashtab_obstack_allocate
,
12105 dummy_obstack_deallocate
);
12107 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
12108 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
12110 init_cu_die_reader (&reader_specs
, cu
);
12112 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
12115 /* We try not to read any attributes in this function, because not
12116 all objfiles needed for references have been loaded yet, and symbol
12117 table processing isn't initialized. But we have to set the CU language,
12118 or we won't be able to build types correctly. */
12119 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
12121 set_cu_language (DW_UNSND (attr
), cu
);
12123 set_cu_language (language_minimal
, cu
);
12125 do_cleanups (back_to
);
12127 /* We've successfully allocated this compilation unit. Let our caller
12128 clean it up when finished with it. */
12129 discard_cleanups (free_cu_cleanup
);
12131 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
12132 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
12135 /* Decode simple location descriptions.
12136 Given a pointer to a dwarf block that defines a location, compute
12137 the location and return the value.
12139 NOTE drow/2003-11-18: This function is called in two situations
12140 now: for the address of static or global variables (partial symbols
12141 only) and for offsets into structures which are expected to be
12142 (more or less) constant. The partial symbol case should go away,
12143 and only the constant case should remain. That will let this
12144 function complain more accurately. A few special modes are allowed
12145 without complaint for global variables (for instance, global
12146 register values and thread-local values).
12148 A location description containing no operations indicates that the
12149 object is optimized out. The return value is 0 for that case.
12150 FIXME drow/2003-11-16: No callers check for this case any more; soon all
12151 callers will only want a very basic result and this can become a
12154 Note that stack[0] is unused except as a default error return.
12155 Note that stack overflow is not yet handled. */
12158 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
12160 struct objfile
*objfile
= cu
->objfile
;
12162 int size
= blk
->size
;
12163 gdb_byte
*data
= blk
->data
;
12164 CORE_ADDR stack
[64];
12166 unsigned int bytes_read
, unsnd
;
12210 stack
[++stacki
] = op
- DW_OP_lit0
;
12245 stack
[++stacki
] = op
- DW_OP_reg0
;
12247 dwarf2_complex_location_expr_complaint ();
12251 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
12253 stack
[++stacki
] = unsnd
;
12255 dwarf2_complex_location_expr_complaint ();
12259 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
12264 case DW_OP_const1u
:
12265 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
12269 case DW_OP_const1s
:
12270 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
12274 case DW_OP_const2u
:
12275 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
12279 case DW_OP_const2s
:
12280 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
12284 case DW_OP_const4u
:
12285 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
12289 case DW_OP_const4s
:
12290 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
12295 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
12301 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
12306 stack
[stacki
+ 1] = stack
[stacki
];
12311 stack
[stacki
- 1] += stack
[stacki
];
12315 case DW_OP_plus_uconst
:
12316 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
12321 stack
[stacki
- 1] -= stack
[stacki
];
12326 /* If we're not the last op, then we definitely can't encode
12327 this using GDB's address_class enum. This is valid for partial
12328 global symbols, although the variable's address will be bogus
12331 dwarf2_complex_location_expr_complaint ();
12334 case DW_OP_GNU_push_tls_address
:
12335 /* The top of the stack has the offset from the beginning
12336 of the thread control block at which the variable is located. */
12337 /* Nothing should follow this operator, so the top of stack would
12339 /* This is valid for partial global symbols, but the variable's
12340 address will be bogus in the psymtab. */
12342 dwarf2_complex_location_expr_complaint ();
12345 case DW_OP_GNU_uninit
:
12349 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
12350 dwarf_stack_op_name (op
, 1));
12351 return (stack
[stacki
]);
12354 return (stack
[stacki
]);
12357 /* memory allocation interface */
12359 static struct dwarf_block
*
12360 dwarf_alloc_block (struct dwarf2_cu
*cu
)
12362 struct dwarf_block
*blk
;
12364 blk
= (struct dwarf_block
*)
12365 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
12369 static struct abbrev_info
*
12370 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
12372 struct abbrev_info
*abbrev
;
12374 abbrev
= (struct abbrev_info
*)
12375 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
12376 memset (abbrev
, 0, sizeof (struct abbrev_info
));
12380 static struct die_info
*
12381 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
12383 struct die_info
*die
;
12384 size_t size
= sizeof (struct die_info
);
12387 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
12389 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
12390 memset (die
, 0, sizeof (struct die_info
));
12395 /* Macro support. */
12398 /* Return the full name of file number I in *LH's file name table.
12399 Use COMP_DIR as the name of the current directory of the
12400 compilation. The result is allocated using xmalloc; the caller is
12401 responsible for freeing it. */
12403 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
12405 /* Is the file number a valid index into the line header's file name
12406 table? Remember that file numbers start with one, not zero. */
12407 if (1 <= file
&& file
<= lh
->num_file_names
)
12409 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12411 if (IS_ABSOLUTE_PATH (fe
->name
))
12412 return xstrdup (fe
->name
);
12420 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12426 dir_len
= strlen (dir
);
12427 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
12428 strcpy (full_name
, dir
);
12429 full_name
[dir_len
] = '/';
12430 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
12434 return xstrdup (fe
->name
);
12439 /* The compiler produced a bogus file number. We can at least
12440 record the macro definitions made in the file, even if we
12441 won't be able to find the file by name. */
12442 char fake_name
[80];
12444 sprintf (fake_name
, "<bad macro file number %d>", file
);
12446 complaint (&symfile_complaints
,
12447 _("bad file number in macro information (%d)"),
12450 return xstrdup (fake_name
);
12455 static struct macro_source_file
*
12456 macro_start_file (int file
, int line
,
12457 struct macro_source_file
*current_file
,
12458 const char *comp_dir
,
12459 struct line_header
*lh
, struct objfile
*objfile
)
12461 /* The full name of this source file. */
12462 char *full_name
= file_full_name (file
, lh
, comp_dir
);
12464 /* We don't create a macro table for this compilation unit
12465 at all until we actually get a filename. */
12466 if (! pending_macros
)
12467 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
12468 objfile
->macro_cache
);
12470 if (! current_file
)
12471 /* If we have no current file, then this must be the start_file
12472 directive for the compilation unit's main source file. */
12473 current_file
= macro_set_main (pending_macros
, full_name
);
12475 current_file
= macro_include (current_file
, line
, full_name
);
12479 return current_file
;
12483 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
12484 followed by a null byte. */
12486 copy_string (const char *buf
, int len
)
12488 char *s
= xmalloc (len
+ 1);
12490 memcpy (s
, buf
, len
);
12496 static const char *
12497 consume_improper_spaces (const char *p
, const char *body
)
12501 complaint (&symfile_complaints
,
12502 _("macro definition contains spaces in formal argument list:\n`%s'"),
12514 parse_macro_definition (struct macro_source_file
*file
, int line
,
12519 /* The body string takes one of two forms. For object-like macro
12520 definitions, it should be:
12522 <macro name> " " <definition>
12524 For function-like macro definitions, it should be:
12526 <macro name> "() " <definition>
12528 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
12530 Spaces may appear only where explicitly indicated, and in the
12533 The Dwarf 2 spec says that an object-like macro's name is always
12534 followed by a space, but versions of GCC around March 2002 omit
12535 the space when the macro's definition is the empty string.
12537 The Dwarf 2 spec says that there should be no spaces between the
12538 formal arguments in a function-like macro's formal argument list,
12539 but versions of GCC around March 2002 include spaces after the
12543 /* Find the extent of the macro name. The macro name is terminated
12544 by either a space or null character (for an object-like macro) or
12545 an opening paren (for a function-like macro). */
12546 for (p
= body
; *p
; p
++)
12547 if (*p
== ' ' || *p
== '(')
12550 if (*p
== ' ' || *p
== '\0')
12552 /* It's an object-like macro. */
12553 int name_len
= p
- body
;
12554 char *name
= copy_string (body
, name_len
);
12555 const char *replacement
;
12558 replacement
= body
+ name_len
+ 1;
12561 dwarf2_macro_malformed_definition_complaint (body
);
12562 replacement
= body
+ name_len
;
12565 macro_define_object (file
, line
, name
, replacement
);
12569 else if (*p
== '(')
12571 /* It's a function-like macro. */
12572 char *name
= copy_string (body
, p
- body
);
12575 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
12579 p
= consume_improper_spaces (p
, body
);
12581 /* Parse the formal argument list. */
12582 while (*p
&& *p
!= ')')
12584 /* Find the extent of the current argument name. */
12585 const char *arg_start
= p
;
12587 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
12590 if (! *p
|| p
== arg_start
)
12591 dwarf2_macro_malformed_definition_complaint (body
);
12594 /* Make sure argv has room for the new argument. */
12595 if (argc
>= argv_size
)
12598 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
12601 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
12604 p
= consume_improper_spaces (p
, body
);
12606 /* Consume the comma, if present. */
12611 p
= consume_improper_spaces (p
, body
);
12620 /* Perfectly formed definition, no complaints. */
12621 macro_define_function (file
, line
, name
,
12622 argc
, (const char **) argv
,
12624 else if (*p
== '\0')
12626 /* Complain, but do define it. */
12627 dwarf2_macro_malformed_definition_complaint (body
);
12628 macro_define_function (file
, line
, name
,
12629 argc
, (const char **) argv
,
12633 /* Just complain. */
12634 dwarf2_macro_malformed_definition_complaint (body
);
12637 /* Just complain. */
12638 dwarf2_macro_malformed_definition_complaint (body
);
12644 for (i
= 0; i
< argc
; i
++)
12650 dwarf2_macro_malformed_definition_complaint (body
);
12655 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
12656 char *comp_dir
, bfd
*abfd
,
12657 struct dwarf2_cu
*cu
)
12659 gdb_byte
*mac_ptr
, *mac_end
;
12660 struct macro_source_file
*current_file
= 0;
12661 enum dwarf_macinfo_record_type macinfo_type
;
12662 int at_commandline
;
12664 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
12665 &dwarf2_per_objfile
->macinfo
);
12666 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
12668 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
12672 /* First pass: Find the name of the base filename.
12673 This filename is needed in order to process all macros whose definition
12674 (or undefinition) comes from the command line. These macros are defined
12675 before the first DW_MACINFO_start_file entry, and yet still need to be
12676 associated to the base file.
12678 To determine the base file name, we scan the macro definitions until we
12679 reach the first DW_MACINFO_start_file entry. We then initialize
12680 CURRENT_FILE accordingly so that any macro definition found before the
12681 first DW_MACINFO_start_file can still be associated to the base file. */
12683 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
12684 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
12685 + dwarf2_per_objfile
->macinfo
.size
;
12689 /* Do we at least have room for a macinfo type byte? */
12690 if (mac_ptr
>= mac_end
)
12692 /* Complaint is printed during the second pass as GDB will probably
12693 stop the first pass earlier upon finding DW_MACINFO_start_file. */
12697 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
12700 switch (macinfo_type
)
12702 /* A zero macinfo type indicates the end of the macro
12707 case DW_MACINFO_define
:
12708 case DW_MACINFO_undef
:
12709 /* Only skip the data by MAC_PTR. */
12711 unsigned int bytes_read
;
12713 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12714 mac_ptr
+= bytes_read
;
12715 read_string (abfd
, mac_ptr
, &bytes_read
);
12716 mac_ptr
+= bytes_read
;
12720 case DW_MACINFO_start_file
:
12722 unsigned int bytes_read
;
12725 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12726 mac_ptr
+= bytes_read
;
12727 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12728 mac_ptr
+= bytes_read
;
12730 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
12735 case DW_MACINFO_end_file
:
12736 /* No data to skip by MAC_PTR. */
12739 case DW_MACINFO_vendor_ext
:
12740 /* Only skip the data by MAC_PTR. */
12742 unsigned int bytes_read
;
12744 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12745 mac_ptr
+= bytes_read
;
12746 read_string (abfd
, mac_ptr
, &bytes_read
);
12747 mac_ptr
+= bytes_read
;
12754 } while (macinfo_type
!= 0 && current_file
== NULL
);
12756 /* Second pass: Process all entries.
12758 Use the AT_COMMAND_LINE flag to determine whether we are still processing
12759 command-line macro definitions/undefinitions. This flag is unset when we
12760 reach the first DW_MACINFO_start_file entry. */
12762 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
12764 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
12765 GDB is still reading the definitions from command line. First
12766 DW_MACINFO_start_file will need to be ignored as it was already executed
12767 to create CURRENT_FILE for the main source holding also the command line
12768 definitions. On first met DW_MACINFO_start_file this flag is reset to
12769 normally execute all the remaining DW_MACINFO_start_file macinfos. */
12771 at_commandline
= 1;
12775 /* Do we at least have room for a macinfo type byte? */
12776 if (mac_ptr
>= mac_end
)
12778 dwarf2_macros_too_long_complaint ();
12782 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
12785 switch (macinfo_type
)
12787 /* A zero macinfo type indicates the end of the macro
12792 case DW_MACINFO_define
:
12793 case DW_MACINFO_undef
:
12795 unsigned int bytes_read
;
12799 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12800 mac_ptr
+= bytes_read
;
12801 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
12802 mac_ptr
+= bytes_read
;
12804 if (! current_file
)
12806 /* DWARF violation as no main source is present. */
12807 complaint (&symfile_complaints
,
12808 _("debug info with no main source gives macro %s "
12810 macinfo_type
== DW_MACINFO_define
?
12812 macinfo_type
== DW_MACINFO_undef
?
12813 _("undefinition") :
12814 _("something-or-other"), line
, body
);
12817 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
12818 complaint (&symfile_complaints
,
12819 _("debug info gives %s macro %s with %s line %d: %s"),
12820 at_commandline
? _("command-line") : _("in-file"),
12821 macinfo_type
== DW_MACINFO_define
?
12823 macinfo_type
== DW_MACINFO_undef
?
12824 _("undefinition") :
12825 _("something-or-other"),
12826 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
12828 if (macinfo_type
== DW_MACINFO_define
)
12829 parse_macro_definition (current_file
, line
, body
);
12830 else if (macinfo_type
== DW_MACINFO_undef
)
12831 macro_undef (current_file
, line
, body
);
12835 case DW_MACINFO_start_file
:
12837 unsigned int bytes_read
;
12840 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12841 mac_ptr
+= bytes_read
;
12842 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12843 mac_ptr
+= bytes_read
;
12845 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
12846 complaint (&symfile_complaints
,
12847 _("debug info gives source %d included "
12848 "from %s at %s line %d"),
12849 file
, at_commandline
? _("command-line") : _("file"),
12850 line
== 0 ? _("zero") : _("non-zero"), line
);
12852 if (at_commandline
)
12854 /* This DW_MACINFO_start_file was executed in the pass one. */
12855 at_commandline
= 0;
12858 current_file
= macro_start_file (file
, line
,
12859 current_file
, comp_dir
,
12864 case DW_MACINFO_end_file
:
12865 if (! current_file
)
12866 complaint (&symfile_complaints
,
12867 _("macro debug info has an unmatched `close_file' directive"));
12870 current_file
= current_file
->included_by
;
12871 if (! current_file
)
12873 enum dwarf_macinfo_record_type next_type
;
12875 /* GCC circa March 2002 doesn't produce the zero
12876 type byte marking the end of the compilation
12877 unit. Complain if it's not there, but exit no
12880 /* Do we at least have room for a macinfo type byte? */
12881 if (mac_ptr
>= mac_end
)
12883 dwarf2_macros_too_long_complaint ();
12887 /* We don't increment mac_ptr here, so this is just
12889 next_type
= read_1_byte (abfd
, mac_ptr
);
12890 if (next_type
!= 0)
12891 complaint (&symfile_complaints
,
12892 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
12899 case DW_MACINFO_vendor_ext
:
12901 unsigned int bytes_read
;
12905 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12906 mac_ptr
+= bytes_read
;
12907 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
12908 mac_ptr
+= bytes_read
;
12910 /* We don't recognize any vendor extensions. */
12914 } while (macinfo_type
!= 0);
12917 /* Check if the attribute's form is a DW_FORM_block*
12918 if so return true else false. */
12920 attr_form_is_block (struct attribute
*attr
)
12922 return (attr
== NULL
? 0 :
12923 attr
->form
== DW_FORM_block1
12924 || attr
->form
== DW_FORM_block2
12925 || attr
->form
== DW_FORM_block4
12926 || attr
->form
== DW_FORM_block
12927 || attr
->form
== DW_FORM_exprloc
);
12930 /* Return non-zero if ATTR's value is a section offset --- classes
12931 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
12932 You may use DW_UNSND (attr) to retrieve such offsets.
12934 Section 7.5.4, "Attribute Encodings", explains that no attribute
12935 may have a value that belongs to more than one of these classes; it
12936 would be ambiguous if we did, because we use the same forms for all
12939 attr_form_is_section_offset (struct attribute
*attr
)
12941 return (attr
->form
== DW_FORM_data4
12942 || attr
->form
== DW_FORM_data8
12943 || attr
->form
== DW_FORM_sec_offset
);
12947 /* Return non-zero if ATTR's value falls in the 'constant' class, or
12948 zero otherwise. When this function returns true, you can apply
12949 dwarf2_get_attr_constant_value to it.
12951 However, note that for some attributes you must check
12952 attr_form_is_section_offset before using this test. DW_FORM_data4
12953 and DW_FORM_data8 are members of both the constant class, and of
12954 the classes that contain offsets into other debug sections
12955 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
12956 that, if an attribute's can be either a constant or one of the
12957 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
12958 taken as section offsets, not constants. */
12960 attr_form_is_constant (struct attribute
*attr
)
12962 switch (attr
->form
)
12964 case DW_FORM_sdata
:
12965 case DW_FORM_udata
:
12966 case DW_FORM_data1
:
12967 case DW_FORM_data2
:
12968 case DW_FORM_data4
:
12969 case DW_FORM_data8
:
12977 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
12978 struct dwarf2_cu
*cu
)
12980 if (attr_form_is_section_offset (attr
)
12981 /* ".debug_loc" may not exist at all, or the offset may be outside
12982 the section. If so, fall through to the complaint in the
12984 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
12986 struct dwarf2_loclist_baton
*baton
;
12988 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
12989 sizeof (struct dwarf2_loclist_baton
));
12990 baton
->per_cu
= cu
->per_cu
;
12991 gdb_assert (baton
->per_cu
);
12993 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
12994 &dwarf2_per_objfile
->loc
);
12996 /* We don't know how long the location list is, but make sure we
12997 don't run off the edge of the section. */
12998 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
12999 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
13000 baton
->base_address
= cu
->base_address
;
13001 if (cu
->base_known
== 0)
13002 complaint (&symfile_complaints
,
13003 _("Location list used without specifying the CU base address."));
13005 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
13006 SYMBOL_LOCATION_BATON (sym
) = baton
;
13010 struct dwarf2_locexpr_baton
*baton
;
13012 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13013 sizeof (struct dwarf2_locexpr_baton
));
13014 baton
->per_cu
= cu
->per_cu
;
13015 gdb_assert (baton
->per_cu
);
13017 if (attr_form_is_block (attr
))
13019 /* Note that we're just copying the block's data pointer
13020 here, not the actual data. We're still pointing into the
13021 info_buffer for SYM's objfile; right now we never release
13022 that buffer, but when we do clean up properly this may
13024 baton
->size
= DW_BLOCK (attr
)->size
;
13025 baton
->data
= DW_BLOCK (attr
)->data
;
13029 dwarf2_invalid_attrib_class_complaint ("location description",
13030 SYMBOL_NATURAL_NAME (sym
));
13032 baton
->data
= NULL
;
13035 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13036 SYMBOL_LOCATION_BATON (sym
) = baton
;
13040 /* Return the OBJFILE associated with the compilation unit CU. If CU
13041 came from a separate debuginfo file, then the master objfile is
13045 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
13047 struct objfile
*objfile
= per_cu
->objfile
;
13049 /* Return the master objfile, so that we can report and look up the
13050 correct file containing this variable. */
13051 if (objfile
->separate_debug_objfile_backlink
)
13052 objfile
= objfile
->separate_debug_objfile_backlink
;
13057 /* Return the address size given in the compilation unit header for CU. */
13060 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
13063 return per_cu
->cu
->header
.addr_size
;
13066 /* If the CU is not currently read in, we re-read its header. */
13067 struct objfile
*objfile
= per_cu
->objfile
;
13068 struct dwarf2_per_objfile
*per_objfile
13069 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13070 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13071 struct comp_unit_head cu_header
;
13073 memset (&cu_header
, 0, sizeof cu_header
);
13074 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13075 return cu_header
.addr_size
;
13079 /* Return the offset size given in the compilation unit header for CU. */
13082 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
13085 return per_cu
->cu
->header
.offset_size
;
13088 /* If the CU is not currently read in, we re-read its header. */
13089 struct objfile
*objfile
= per_cu
->objfile
;
13090 struct dwarf2_per_objfile
*per_objfile
13091 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13092 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13093 struct comp_unit_head cu_header
;
13095 memset (&cu_header
, 0, sizeof cu_header
);
13096 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13097 return cu_header
.offset_size
;
13101 /* Return the text offset of the CU. The returned offset comes from
13102 this CU's objfile. If this objfile came from a separate debuginfo
13103 file, then the offset may be different from the corresponding
13104 offset in the parent objfile. */
13107 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
13109 struct objfile
*objfile
= per_cu
->objfile
;
13111 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13114 /* Locate the .debug_info compilation unit from CU's objfile which contains
13115 the DIE at OFFSET. Raises an error on failure. */
13117 static struct dwarf2_per_cu_data
*
13118 dwarf2_find_containing_comp_unit (unsigned int offset
,
13119 struct objfile
*objfile
)
13121 struct dwarf2_per_cu_data
*this_cu
;
13125 high
= dwarf2_per_objfile
->n_comp_units
- 1;
13128 int mid
= low
+ (high
- low
) / 2;
13130 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
13135 gdb_assert (low
== high
);
13136 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
13139 error (_("Dwarf Error: could not find partial DIE containing "
13140 "offset 0x%lx [in module %s]"),
13141 (long) offset
, bfd_get_filename (objfile
->obfd
));
13143 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
13144 return dwarf2_per_objfile
->all_comp_units
[low
-1];
13148 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
13149 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
13150 && offset
>= this_cu
->offset
+ this_cu
->length
)
13151 error (_("invalid dwarf2 offset %u"), offset
);
13152 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
13157 /* Locate the compilation unit from OBJFILE which is located at exactly
13158 OFFSET. Raises an error on failure. */
13160 static struct dwarf2_per_cu_data
*
13161 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
13163 struct dwarf2_per_cu_data
*this_cu
;
13165 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
13166 if (this_cu
->offset
!= offset
)
13167 error (_("no compilation unit with offset %u."), offset
);
13171 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
13173 static struct dwarf2_cu
*
13174 alloc_one_comp_unit (struct objfile
*objfile
)
13176 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
13177 cu
->objfile
= objfile
;
13178 obstack_init (&cu
->comp_unit_obstack
);
13182 /* Release one cached compilation unit, CU. We unlink it from the tree
13183 of compilation units, but we don't remove it from the read_in_chain;
13184 the caller is responsible for that.
13185 NOTE: DATA is a void * because this function is also used as a
13186 cleanup routine. */
13189 free_one_comp_unit (void *data
)
13191 struct dwarf2_cu
*cu
= data
;
13193 if (cu
->per_cu
!= NULL
)
13194 cu
->per_cu
->cu
= NULL
;
13197 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13202 /* This cleanup function is passed the address of a dwarf2_cu on the stack
13203 when we're finished with it. We can't free the pointer itself, but be
13204 sure to unlink it from the cache. Also release any associated storage
13205 and perform cache maintenance.
13207 Only used during partial symbol parsing. */
13210 free_stack_comp_unit (void *data
)
13212 struct dwarf2_cu
*cu
= data
;
13214 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13215 cu
->partial_dies
= NULL
;
13217 if (cu
->per_cu
!= NULL
)
13219 /* This compilation unit is on the stack in our caller, so we
13220 should not xfree it. Just unlink it. */
13221 cu
->per_cu
->cu
= NULL
;
13224 /* If we had a per-cu pointer, then we may have other compilation
13225 units loaded, so age them now. */
13226 age_cached_comp_units ();
13230 /* Free all cached compilation units. */
13233 free_cached_comp_units (void *data
)
13235 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13237 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13238 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13239 while (per_cu
!= NULL
)
13241 struct dwarf2_per_cu_data
*next_cu
;
13243 next_cu
= per_cu
->cu
->read_in_chain
;
13245 free_one_comp_unit (per_cu
->cu
);
13246 *last_chain
= next_cu
;
13252 /* Increase the age counter on each cached compilation unit, and free
13253 any that are too old. */
13256 age_cached_comp_units (void)
13258 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13260 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
13261 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13262 while (per_cu
!= NULL
)
13264 per_cu
->cu
->last_used
++;
13265 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
13266 dwarf2_mark (per_cu
->cu
);
13267 per_cu
= per_cu
->cu
->read_in_chain
;
13270 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13271 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13272 while (per_cu
!= NULL
)
13274 struct dwarf2_per_cu_data
*next_cu
;
13276 next_cu
= per_cu
->cu
->read_in_chain
;
13278 if (!per_cu
->cu
->mark
)
13280 free_one_comp_unit (per_cu
->cu
);
13281 *last_chain
= next_cu
;
13284 last_chain
= &per_cu
->cu
->read_in_chain
;
13290 /* Remove a single compilation unit from the cache. */
13293 free_one_cached_comp_unit (void *target_cu
)
13295 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13297 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13298 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13299 while (per_cu
!= NULL
)
13301 struct dwarf2_per_cu_data
*next_cu
;
13303 next_cu
= per_cu
->cu
->read_in_chain
;
13305 if (per_cu
->cu
== target_cu
)
13307 free_one_comp_unit (per_cu
->cu
);
13308 *last_chain
= next_cu
;
13312 last_chain
= &per_cu
->cu
->read_in_chain
;
13318 /* Release all extra memory associated with OBJFILE. */
13321 dwarf2_free_objfile (struct objfile
*objfile
)
13323 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
13325 if (dwarf2_per_objfile
== NULL
)
13328 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
13329 free_cached_comp_units (NULL
);
13331 if (dwarf2_per_objfile
->using_index
)
13335 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
13338 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
13340 if (!cu
->v
.quick
->lines
)
13343 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
13345 if (cu
->v
.quick
->file_names
)
13346 xfree ((void *) cu
->v
.quick
->file_names
[j
]);
13347 if (cu
->v
.quick
->full_names
)
13348 xfree ((void *) cu
->v
.quick
->full_names
[j
]);
13351 free_line_header (cu
->v
.quick
->lines
);
13355 /* Everything else should be on the objfile obstack. */
13358 /* A pair of DIE offset and GDB type pointer. We store these
13359 in a hash table separate from the DIEs, and preserve them
13360 when the DIEs are flushed out of cache. */
13362 struct dwarf2_offset_and_type
13364 unsigned int offset
;
13368 /* Hash function for a dwarf2_offset_and_type. */
13371 offset_and_type_hash (const void *item
)
13373 const struct dwarf2_offset_and_type
*ofs
= item
;
13375 return ofs
->offset
;
13378 /* Equality function for a dwarf2_offset_and_type. */
13381 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
13383 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
13384 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
13386 return ofs_lhs
->offset
== ofs_rhs
->offset
;
13389 /* Set the type associated with DIE to TYPE. Save it in CU's hash
13390 table if necessary. For convenience, return TYPE.
13392 The DIEs reading must have careful ordering to:
13393 * Not cause infite loops trying to read in DIEs as a prerequisite for
13394 reading current DIE.
13395 * Not trying to dereference contents of still incompletely read in types
13396 while reading in other DIEs.
13397 * Enable referencing still incompletely read in types just by a pointer to
13398 the type without accessing its fields.
13400 Therefore caller should follow these rules:
13401 * Try to fetch any prerequisite types we may need to build this DIE type
13402 before building the type and calling set_die_type.
13403 * After building typer call set_die_type for current DIE as soon as
13404 possible before fetching more types to complete the current type.
13405 * Make the type as complete as possible before fetching more types. */
13407 static struct type
*
13408 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13410 struct dwarf2_offset_and_type
**slot
, ofs
;
13412 /* For Ada types, make sure that the gnat-specific data is always
13413 initialized (if not already set). There are a few types where
13414 we should not be doing so, because the type-specific area is
13415 already used to hold some other piece of info (eg: TYPE_CODE_FLT
13416 where the type-specific area is used to store the floatformat).
13417 But this is not a problem, because the gnat-specific information
13418 is actually not needed for these types. */
13419 if (need_gnat_info (cu
)
13420 && TYPE_CODE (type
) != TYPE_CODE_FUNC
13421 && TYPE_CODE (type
) != TYPE_CODE_FLT
13422 && !HAVE_GNAT_AUX_INFO (type
))
13423 INIT_GNAT_SPECIFIC (type
);
13425 if (cu
->type_hash
== NULL
)
13427 gdb_assert (cu
->per_cu
!= NULL
);
13428 cu
->per_cu
->type_hash
13429 = htab_create_alloc_ex (cu
->header
.length
/ 24,
13430 offset_and_type_hash
,
13431 offset_and_type_eq
,
13433 &cu
->objfile
->objfile_obstack
,
13434 hashtab_obstack_allocate
,
13435 dummy_obstack_deallocate
);
13436 cu
->type_hash
= cu
->per_cu
->type_hash
;
13439 ofs
.offset
= die
->offset
;
13441 slot
= (struct dwarf2_offset_and_type
**)
13442 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
13444 complaint (&symfile_complaints
,
13445 _("A problem internal to GDB: DIE 0x%x has type already set"),
13447 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
13452 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
13453 not have a saved type. */
13455 static struct type
*
13456 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13458 struct dwarf2_offset_and_type
*slot
, ofs
;
13459 htab_t type_hash
= cu
->type_hash
;
13461 if (type_hash
== NULL
)
13464 ofs
.offset
= die
->offset
;
13465 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
13472 /* Add a dependence relationship from CU to REF_PER_CU. */
13475 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
13476 struct dwarf2_per_cu_data
*ref_per_cu
)
13480 if (cu
->dependencies
== NULL
)
13482 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
13483 NULL
, &cu
->comp_unit_obstack
,
13484 hashtab_obstack_allocate
,
13485 dummy_obstack_deallocate
);
13487 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
13489 *slot
= ref_per_cu
;
13492 /* Subroutine of dwarf2_mark to pass to htab_traverse.
13493 Set the mark field in every compilation unit in the
13494 cache that we must keep because we are keeping CU. */
13497 dwarf2_mark_helper (void **slot
, void *data
)
13499 struct dwarf2_per_cu_data
*per_cu
;
13501 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
13502 if (per_cu
->cu
->mark
)
13504 per_cu
->cu
->mark
= 1;
13506 if (per_cu
->cu
->dependencies
!= NULL
)
13507 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
13512 /* Set the mark field in CU and in every other compilation unit in the
13513 cache that we must keep because we are keeping CU. */
13516 dwarf2_mark (struct dwarf2_cu
*cu
)
13521 if (cu
->dependencies
!= NULL
)
13522 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
13526 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
13530 per_cu
->cu
->mark
= 0;
13531 per_cu
= per_cu
->cu
->read_in_chain
;
13535 /* Trivial hash function for partial_die_info: the hash value of a DIE
13536 is its offset in .debug_info for this objfile. */
13539 partial_die_hash (const void *item
)
13541 const struct partial_die_info
*part_die
= item
;
13543 return part_die
->offset
;
13546 /* Trivial comparison function for partial_die_info structures: two DIEs
13547 are equal if they have the same offset. */
13550 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
13552 const struct partial_die_info
*part_die_lhs
= item_lhs
;
13553 const struct partial_die_info
*part_die_rhs
= item_rhs
;
13555 return part_die_lhs
->offset
== part_die_rhs
->offset
;
13558 static struct cmd_list_element
*set_dwarf2_cmdlist
;
13559 static struct cmd_list_element
*show_dwarf2_cmdlist
;
13562 set_dwarf2_cmd (char *args
, int from_tty
)
13564 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
13568 show_dwarf2_cmd (char *args
, int from_tty
)
13570 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
13573 /* If section described by INFO was mmapped, munmap it now. */
13576 munmap_section_buffer (struct dwarf2_section_info
*info
)
13578 if (info
->was_mmapped
)
13581 intptr_t begin
= (intptr_t) info
->buffer
;
13582 intptr_t map_begin
= begin
& ~(pagesize
- 1);
13583 size_t map_length
= info
->size
+ begin
- map_begin
;
13585 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
13587 /* Without HAVE_MMAP, we should never be here to begin with. */
13593 /* munmap debug sections for OBJFILE, if necessary. */
13596 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
13598 struct dwarf2_per_objfile
*data
= d
;
13600 munmap_section_buffer (&data
->info
);
13601 munmap_section_buffer (&data
->abbrev
);
13602 munmap_section_buffer (&data
->line
);
13603 munmap_section_buffer (&data
->str
);
13604 munmap_section_buffer (&data
->macinfo
);
13605 munmap_section_buffer (&data
->ranges
);
13606 munmap_section_buffer (&data
->loc
);
13607 munmap_section_buffer (&data
->frame
);
13608 munmap_section_buffer (&data
->eh_frame
);
13609 munmap_section_buffer (&data
->gdb_index
);
13614 /* The contents of the hash table we create when building the string
13616 struct strtab_entry
13618 offset_type offset
;
13622 /* Hash function for a strtab_entry. */
13624 hash_strtab_entry (const void *e
)
13626 const struct strtab_entry
*entry
= e
;
13627 return mapped_index_string_hash (entry
->str
);
13630 /* Equality function for a strtab_entry. */
13632 eq_strtab_entry (const void *a
, const void *b
)
13634 const struct strtab_entry
*ea
= a
;
13635 const struct strtab_entry
*eb
= b
;
13636 return !strcmp (ea
->str
, eb
->str
);
13639 /* Create a strtab_entry hash table. */
13641 create_strtab (void)
13643 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
13644 xfree
, xcalloc
, xfree
);
13647 /* Add a string to the constant pool. Return the string's offset in
13650 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
13653 struct strtab_entry entry
;
13654 struct strtab_entry
*result
;
13657 slot
= htab_find_slot (table
, &entry
, INSERT
);
13662 result
= XNEW (struct strtab_entry
);
13663 result
->offset
= obstack_object_size (cpool
);
13665 obstack_grow_str0 (cpool
, str
);
13668 return result
->offset
;
13671 /* An entry in the symbol table. */
13672 struct symtab_index_entry
13674 /* The name of the symbol. */
13676 /* The offset of the name in the constant pool. */
13677 offset_type index_offset
;
13678 /* A sorted vector of the indices of all the CUs that hold an object
13680 VEC (offset_type
) *cu_indices
;
13683 /* The symbol table. This is a power-of-2-sized hash table. */
13684 struct mapped_symtab
13686 offset_type n_elements
;
13688 struct symtab_index_entry
**data
;
13691 /* Hash function for a symtab_index_entry. */
13693 hash_symtab_entry (const void *e
)
13695 const struct symtab_index_entry
*entry
= e
;
13696 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
13697 sizeof (offset_type
) * VEC_length (offset_type
,
13698 entry
->cu_indices
),
13702 /* Equality function for a symtab_index_entry. */
13704 eq_symtab_entry (const void *a
, const void *b
)
13706 const struct symtab_index_entry
*ea
= a
;
13707 const struct symtab_index_entry
*eb
= b
;
13708 int len
= VEC_length (offset_type
, ea
->cu_indices
);
13709 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
13711 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
13712 VEC_address (offset_type
, eb
->cu_indices
),
13713 sizeof (offset_type
) * len
);
13716 /* Destroy a symtab_index_entry. */
13718 delete_symtab_entry (void *p
)
13720 struct symtab_index_entry
*entry
= p
;
13721 VEC_free (offset_type
, entry
->cu_indices
);
13725 /* Create a hash table holding symtab_index_entry objects. */
13727 create_index_table (void)
13729 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
13730 delete_symtab_entry
, xcalloc
, xfree
);
13733 /* Create a new mapped symtab object. */
13734 static struct mapped_symtab
*
13735 create_mapped_symtab (void)
13737 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
13738 symtab
->n_elements
= 0;
13739 symtab
->size
= 1024;
13740 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
13744 /* Destroy a mapped_symtab. */
13746 cleanup_mapped_symtab (void *p
)
13748 struct mapped_symtab
*symtab
= p
;
13749 /* The contents of the array are freed when the other hash table is
13751 xfree (symtab
->data
);
13755 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
13757 static struct symtab_index_entry
**
13758 find_slot (struct mapped_symtab
*symtab
, const char *name
)
13760 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
13762 index
= hash
& (symtab
->size
- 1);
13763 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
13767 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
13768 return &symtab
->data
[index
];
13769 index
= (index
+ step
) & (symtab
->size
- 1);
13773 /* Expand SYMTAB's hash table. */
13775 hash_expand (struct mapped_symtab
*symtab
)
13777 offset_type old_size
= symtab
->size
;
13779 struct symtab_index_entry
**old_entries
= symtab
->data
;
13782 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
13784 for (i
= 0; i
< old_size
; ++i
)
13786 if (old_entries
[i
])
13788 struct symtab_index_entry
**slot
= find_slot (symtab
,
13789 old_entries
[i
]->name
);
13790 *slot
= old_entries
[i
];
13794 xfree (old_entries
);
13797 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
13798 is the index of the CU in which the symbol appears. */
13800 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
13801 offset_type cu_index
)
13803 struct symtab_index_entry
**slot
;
13805 ++symtab
->n_elements
;
13806 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
13807 hash_expand (symtab
);
13809 slot
= find_slot (symtab
, name
);
13812 *slot
= XNEW (struct symtab_index_entry
);
13813 (*slot
)->name
= name
;
13814 (*slot
)->cu_indices
= NULL
;
13816 /* Don't push an index twice. Due to how we add entries we only
13817 have to check the last one. */
13818 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
13819 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
13820 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
13823 /* Add a vector of indices to the constant pool. */
13825 add_indices_to_cpool (htab_t index_table
, struct obstack
*cpool
,
13826 struct symtab_index_entry
*entry
)
13830 slot
= htab_find_slot (index_table
, entry
, INSERT
);
13833 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
13834 offset_type val
= MAYBE_SWAP (len
);
13839 entry
->index_offset
= obstack_object_size (cpool
);
13841 obstack_grow (cpool
, &val
, sizeof (val
));
13843 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
13846 val
= MAYBE_SWAP (iter
);
13847 obstack_grow (cpool
, &val
, sizeof (val
));
13852 struct symtab_index_entry
*old_entry
= *slot
;
13853 entry
->index_offset
= old_entry
->index_offset
;
13856 return entry
->index_offset
;
13859 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
13860 constant pool entries going into the obstack CPOOL. */
13862 write_hash_table (struct mapped_symtab
*symtab
,
13863 struct obstack
*output
, struct obstack
*cpool
)
13866 htab_t index_table
;
13869 index_table
= create_index_table ();
13870 str_table
= create_strtab ();
13871 /* We add all the index vectors to the constant pool first, to
13872 ensure alignment is ok. */
13873 for (i
= 0; i
< symtab
->size
; ++i
)
13875 if (symtab
->data
[i
])
13876 add_indices_to_cpool (index_table
, cpool
, symtab
->data
[i
]);
13879 /* Now write out the hash table. */
13880 for (i
= 0; i
< symtab
->size
; ++i
)
13882 offset_type str_off
, vec_off
;
13884 if (symtab
->data
[i
])
13886 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
13887 vec_off
= symtab
->data
[i
]->index_offset
;
13891 /* While 0 is a valid constant pool index, it is not valid
13892 to have 0 for both offsets. */
13897 str_off
= MAYBE_SWAP (str_off
);
13898 vec_off
= MAYBE_SWAP (vec_off
);
13900 obstack_grow (output
, &str_off
, sizeof (str_off
));
13901 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
13904 htab_delete (str_table
);
13905 htab_delete (index_table
);
13908 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
13909 from PST; CU_INDEX is the index of the CU in the vector of all
13912 add_address_entry (struct objfile
*objfile
,
13913 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
13914 unsigned int cu_index
)
13916 offset_type offset
;
13918 CORE_ADDR baseaddr
;
13920 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13922 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
13923 obstack_grow (addr_obstack
, addr
, 8);
13924 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
13925 obstack_grow (addr_obstack
, addr
, 8);
13926 offset
= MAYBE_SWAP (cu_index
);
13927 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
13930 /* Add a list of partial symbols to SYMTAB. */
13932 write_psymbols (struct mapped_symtab
*symtab
,
13933 struct partial_symbol
**psymp
,
13935 offset_type cu_index
)
13937 for (; count
-- > 0; ++psymp
)
13939 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
13940 error (_("Ada is not currently supported by the index"));
13941 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
13945 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
13946 exception if there is an error. */
13948 write_obstack (FILE *file
, struct obstack
*obstack
)
13950 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
13952 != obstack_object_size (obstack
))
13953 error (_("couldn't data write to file"));
13956 /* Unlink a file if the argument is not NULL. */
13958 unlink_if_set (void *p
)
13960 char **filename
= p
;
13962 unlink (*filename
);
13965 /* Create an index file for OBJFILE in the directory DIR. */
13967 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
13969 struct cleanup
*cleanup
;
13970 char *filename
, *cleanup_filename
;
13971 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
, cu_list
;
13974 struct mapped_symtab
*symtab
;
13975 offset_type val
, size_of_contents
, total_len
;
13979 if (!objfile
->psymtabs
)
13981 if (dwarf2_per_objfile
->using_index
)
13982 error (_("Cannot use an index to create the index"));
13984 if (stat (objfile
->name
, &st
) < 0)
13985 perror_with_name (_("Could not stat"));
13987 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
13988 INDEX_SUFFIX
, (char *) NULL
);
13989 cleanup
= make_cleanup (xfree
, filename
);
13991 out_file
= fopen (filename
, "wb");
13993 error (_("Can't open `%s' for writing"), filename
);
13995 cleanup_filename
= filename
;
13996 make_cleanup (unlink_if_set
, &cleanup_filename
);
13998 symtab
= create_mapped_symtab ();
13999 make_cleanup (cleanup_mapped_symtab
, symtab
);
14001 obstack_init (&addr_obstack
);
14002 make_cleanup_obstack_free (&addr_obstack
);
14004 obstack_init (&cu_list
);
14005 make_cleanup_obstack_free (&cu_list
);
14007 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14009 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
14010 struct partial_symtab
*psymtab
= cu
->v
.psymtab
;
14013 write_psymbols (symtab
,
14014 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
14015 psymtab
->n_global_syms
, i
);
14016 write_psymbols (symtab
,
14017 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
14018 psymtab
->n_static_syms
, i
);
14020 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
14022 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->offset
);
14023 obstack_grow (&cu_list
, val
, 8);
14024 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->length
);
14025 obstack_grow (&cu_list
, val
, 8);
14028 obstack_init (&constant_pool
);
14029 make_cleanup_obstack_free (&constant_pool
);
14030 obstack_init (&symtab_obstack
);
14031 make_cleanup_obstack_free (&symtab_obstack
);
14032 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
14034 obstack_init (&contents
);
14035 make_cleanup_obstack_free (&contents
);
14036 size_of_contents
= 5 * sizeof (offset_type
);
14037 total_len
= size_of_contents
;
14039 /* The version number. */
14040 val
= MAYBE_SWAP (1);
14041 obstack_grow (&contents
, &val
, sizeof (val
));
14043 /* The offset of the CU list from the start of the file. */
14044 val
= MAYBE_SWAP (total_len
);
14045 obstack_grow (&contents
, &val
, sizeof (val
));
14046 total_len
+= obstack_object_size (&cu_list
);
14048 /* The offset of the address table from the start of the file. */
14049 val
= MAYBE_SWAP (total_len
);
14050 obstack_grow (&contents
, &val
, sizeof (val
));
14051 total_len
+= obstack_object_size (&addr_obstack
);
14053 /* The offset of the symbol table from the start of the file. */
14054 val
= MAYBE_SWAP (total_len
);
14055 obstack_grow (&contents
, &val
, sizeof (val
));
14056 total_len
+= obstack_object_size (&symtab_obstack
);
14058 /* The offset of the constant pool from the start of the file. */
14059 val
= MAYBE_SWAP (total_len
);
14060 obstack_grow (&contents
, &val
, sizeof (val
));
14061 total_len
+= obstack_object_size (&constant_pool
);
14063 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
14065 write_obstack (out_file
, &contents
);
14066 write_obstack (out_file
, &cu_list
);
14067 write_obstack (out_file
, &addr_obstack
);
14068 write_obstack (out_file
, &symtab_obstack
);
14069 write_obstack (out_file
, &constant_pool
);
14073 /* We want to keep the file, so we set cleanup_filename to NULL
14074 here. See unlink_if_set. */
14075 cleanup_filename
= NULL
;
14077 do_cleanups (cleanup
);
14080 /* The mapped index file format is designed to be directly mmap()able
14081 on any architecture. In most cases, a datum is represented using a
14082 little-endian 32-bit integer value, called an offset_type. Big
14083 endian machines must byte-swap the values before using them.
14084 Exceptions to this rule are noted. The data is laid out such that
14085 alignment is always respected.
14087 A mapped index consists of several sections.
14089 1. The file header. This is a sequence of values, of offset_type
14090 unless otherwise noted:
14091 [0] The version number. Currently 1.
14092 [1] The offset, from the start of the file, of the CU list.
14093 [2] The offset, from the start of the file, of the address section.
14094 [3] The offset, from the start of the file, of the symbol table.
14095 [4] The offset, from the start of the file, of the constant pool.
14097 2. The CU list. This is a sequence of pairs of 64-bit
14098 little-endian values. The first element in each pair is the offset
14099 of a CU in the .debug_info section. The second element in each
14100 pair is the length of that CU. References to a CU elsewhere in the
14101 map are done using a CU index, which is just the 0-based index into
14104 3. The address section. The address section consists of a sequence
14105 of address entries. Each address entry has three elements.
14106 [0] The low address. This is a 64-bit little-endian value.
14107 [1] The high address. This is a 64-bit little-endian value.
14108 [2] The CU index. This is an offset_type value.
14110 4. The symbol table. This is a hash table. The size of the hash
14111 table is always a power of 2. The initial hash and the step are
14112 currently defined by the `find_slot' function.
14114 Each slot in the hash table consists of a pair of offset_type
14115 values. The first value is the offset of the symbol's name in the
14116 constant pool. The second value is the offset of the CU vector in
14119 If both values are 0, then this slot in the hash table is empty.
14120 This is ok because while 0 is a valid constant pool index, it
14121 cannot be a valid index for both a string and a CU vector.
14123 A string in the constant pool is stored as a \0-terminated string,
14126 A CU vector in the constant pool is a sequence of offset_type
14127 values. The first value is the number of CU indices in the vector.
14128 Each subsequent value is the index of a CU in the CU list. This
14129 element in the hash table is used to indicate which CUs define the
14132 5. The constant pool. This is simply a bunch of bytes. It is
14133 organized so that alignment is correct: CU vectors are stored
14134 first, followed by strings. */
14136 save_gdb_index_command (char *arg
, int from_tty
)
14138 struct objfile
*objfile
;
14141 error (_("usage: maintenance save-gdb-index DIRECTORY"));
14143 ALL_OBJFILES (objfile
)
14147 /* If the objfile does not correspond to an actual file, skip it. */
14148 if (stat (objfile
->name
, &st
) < 0)
14151 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14152 if (dwarf2_per_objfile
)
14154 volatile struct gdb_exception except
;
14156 TRY_CATCH (except
, RETURN_MASK_ERROR
)
14158 write_psymtabs_to_index (objfile
, arg
);
14160 if (except
.reason
< 0)
14161 exception_fprintf (gdb_stderr
, except
,
14162 _("Error while writing index for `%s': "),
14170 int dwarf2_always_disassemble
;
14173 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
14174 struct cmd_list_element
*c
, const char *value
)
14176 fprintf_filtered (file
, _("\
14177 Whether to always disassemble DWARF expressions is %s.\n"),
14181 void _initialize_dwarf2_read (void);
14184 _initialize_dwarf2_read (void)
14186 dwarf2_objfile_data_key
14187 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
14189 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
14190 Set DWARF 2 specific variables.\n\
14191 Configure DWARF 2 variables such as the cache size"),
14192 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
14193 0/*allow-unknown*/, &maintenance_set_cmdlist
);
14195 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
14196 Show DWARF 2 specific variables\n\
14197 Show DWARF 2 variables such as the cache size"),
14198 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
14199 0/*allow-unknown*/, &maintenance_show_cmdlist
);
14201 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
14202 &dwarf2_max_cache_age
, _("\
14203 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
14204 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
14205 A higher limit means that cached compilation units will be stored\n\
14206 in memory longer, and more total memory will be used. Zero disables\n\
14207 caching, which can slow down startup."),
14209 show_dwarf2_max_cache_age
,
14210 &set_dwarf2_cmdlist
,
14211 &show_dwarf2_cmdlist
);
14213 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
14214 &dwarf2_always_disassemble
, _("\
14215 Set whether `info address' always disassembles DWARF expressions."), _("\
14216 Show whether `info address' always disassembles DWARF expressions."), _("\
14217 When enabled, DWARF expressions are always printed in an assembly-like\n\
14218 syntax. When disabled, expressions will be printed in a more\n\
14219 conversational style, when possible."),
14221 show_dwarf2_always_disassemble
,
14222 &set_dwarf2_cmdlist
,
14223 &show_dwarf2_cmdlist
);
14225 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
14226 Set debugging of the dwarf2 DIE reader."), _("\
14227 Show debugging of the dwarf2 DIE reader."), _("\
14228 When enabled (non-zero), DIEs are dumped after they are read in.\n\
14229 The value is the maximum depth to print."),
14232 &setdebuglist
, &showdebuglist
);
14234 add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
14235 _("Save a .gdb-index file"),