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 /* Add a typedef symbol for the type definition, if it has a
4197 new_symbol (die
, read_type_die (die
, cu
), cu
);
4199 case DW_TAG_common_block
:
4200 read_common_block (die
, cu
);
4202 case DW_TAG_common_inclusion
:
4204 case DW_TAG_namespace
:
4205 processing_has_namespace_info
= 1;
4206 read_namespace (die
, cu
);
4209 processing_has_namespace_info
= 1;
4210 read_module (die
, cu
);
4212 case DW_TAG_imported_declaration
:
4213 case DW_TAG_imported_module
:
4214 processing_has_namespace_info
= 1;
4215 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4216 || cu
->language
!= language_fortran
))
4217 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4218 dwarf_tag_name (die
->tag
));
4219 read_import_statement (die
, cu
);
4222 new_symbol (die
, NULL
, cu
);
4227 /* A helper function for dwarf2_compute_name which determines whether DIE
4228 needs to have the name of the scope prepended to the name listed in the
4232 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4234 struct attribute
*attr
;
4238 case DW_TAG_namespace
:
4239 case DW_TAG_typedef
:
4240 case DW_TAG_class_type
:
4241 case DW_TAG_interface_type
:
4242 case DW_TAG_structure_type
:
4243 case DW_TAG_union_type
:
4244 case DW_TAG_enumeration_type
:
4245 case DW_TAG_enumerator
:
4246 case DW_TAG_subprogram
:
4250 case DW_TAG_variable
:
4251 /* We only need to prefix "globally" visible variables. These include
4252 any variable marked with DW_AT_external or any variable that
4253 lives in a namespace. [Variables in anonymous namespaces
4254 require prefixing, but they are not DW_AT_external.] */
4256 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4258 struct dwarf2_cu
*spec_cu
= cu
;
4260 return die_needs_namespace (die_specification (die
, &spec_cu
),
4264 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4265 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4266 && die
->parent
->tag
!= DW_TAG_module
)
4268 /* A variable in a lexical block of some kind does not need a
4269 namespace, even though in C++ such variables may be external
4270 and have a mangled name. */
4271 if (die
->parent
->tag
== DW_TAG_lexical_block
4272 || die
->parent
->tag
== DW_TAG_try_block
4273 || die
->parent
->tag
== DW_TAG_catch_block
4274 || die
->parent
->tag
== DW_TAG_subprogram
)
4283 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4284 compute the physname for the object, which include a method's
4285 formal parameters (C++/Java) and return type (Java).
4287 For Ada, return the DIE's linkage name rather than the fully qualified
4288 name. PHYSNAME is ignored..
4290 The result is allocated on the objfile_obstack and canonicalized. */
4293 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4297 name
= dwarf2_name (die
, cu
);
4299 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4300 compute it by typename_concat inside GDB. */
4301 if (cu
->language
== language_ada
4302 || (cu
->language
== language_fortran
&& physname
))
4304 /* For Ada unit, we prefer the linkage name over the name, as
4305 the former contains the exported name, which the user expects
4306 to be able to reference. Ideally, we want the user to be able
4307 to reference this entity using either natural or linkage name,
4308 but we haven't started looking at this enhancement yet. */
4309 struct attribute
*attr
;
4311 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4313 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4314 if (attr
&& DW_STRING (attr
))
4315 return DW_STRING (attr
);
4318 /* These are the only languages we know how to qualify names in. */
4320 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4321 || cu
->language
== language_fortran
))
4323 if (die_needs_namespace (die
, cu
))
4327 struct ui_file
*buf
;
4329 prefix
= determine_prefix (die
, cu
);
4330 buf
= mem_fileopen ();
4331 if (*prefix
!= '\0')
4333 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4336 fputs_unfiltered (prefixed_name
, buf
);
4337 xfree (prefixed_name
);
4340 fputs_unfiltered (name
? name
: "", buf
);
4342 /* For Java and C++ methods, append formal parameter type
4343 information, if PHYSNAME. */
4345 if (physname
&& die
->tag
== DW_TAG_subprogram
4346 && (cu
->language
== language_cplus
4347 || cu
->language
== language_java
))
4349 struct type
*type
= read_type_die (die
, cu
);
4351 c_type_print_args (type
, buf
, 0, cu
->language
);
4353 if (cu
->language
== language_java
)
4355 /* For java, we must append the return type to method
4357 if (die
->tag
== DW_TAG_subprogram
)
4358 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4361 else if (cu
->language
== language_cplus
)
4363 if (TYPE_NFIELDS (type
) > 0
4364 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4365 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4366 fputs_unfiltered (" const", buf
);
4370 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4372 ui_file_delete (buf
);
4374 if (cu
->language
== language_cplus
)
4377 = dwarf2_canonicalize_name (name
, cu
,
4378 &cu
->objfile
->objfile_obstack
);
4389 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4390 If scope qualifiers are appropriate they will be added. The result
4391 will be allocated on the objfile_obstack, or NULL if the DIE does
4392 not have a name. NAME may either be from a previous call to
4393 dwarf2_name or NULL.
4395 The output string will be canonicalized (if C++/Java). */
4398 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4400 return dwarf2_compute_name (name
, die
, cu
, 0);
4403 /* Construct a physname for the given DIE in CU. NAME may either be
4404 from a previous call to dwarf2_name or NULL. The result will be
4405 allocated on the objfile_objstack or NULL if the DIE does not have a
4408 The output string will be canonicalized (if C++/Java). */
4411 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4413 return dwarf2_compute_name (name
, die
, cu
, 1);
4416 /* Read the import statement specified by the given die and record it. */
4419 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4421 struct attribute
*import_attr
;
4422 struct die_info
*imported_die
;
4423 struct dwarf2_cu
*imported_cu
;
4424 const char *imported_name
;
4425 const char *imported_name_prefix
;
4426 const char *canonical_name
;
4427 const char *import_alias
;
4428 const char *imported_declaration
= NULL
;
4429 const char *import_prefix
;
4433 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4434 if (import_attr
== NULL
)
4436 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4437 dwarf_tag_name (die
->tag
));
4442 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4443 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4444 if (imported_name
== NULL
)
4446 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4448 The import in the following code:
4462 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4463 <52> DW_AT_decl_file : 1
4464 <53> DW_AT_decl_line : 6
4465 <54> DW_AT_import : <0x75>
4466 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4468 <5b> DW_AT_decl_file : 1
4469 <5c> DW_AT_decl_line : 2
4470 <5d> DW_AT_type : <0x6e>
4472 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4473 <76> DW_AT_byte_size : 4
4474 <77> DW_AT_encoding : 5 (signed)
4476 imports the wrong die ( 0x75 instead of 0x58 ).
4477 This case will be ignored until the gcc bug is fixed. */
4481 /* Figure out the local name after import. */
4482 import_alias
= dwarf2_name (die
, cu
);
4484 /* Figure out where the statement is being imported to. */
4485 import_prefix
= determine_prefix (die
, cu
);
4487 /* Figure out what the scope of the imported die is and prepend it
4488 to the name of the imported die. */
4489 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4491 if (imported_die
->tag
!= DW_TAG_namespace
4492 && imported_die
->tag
!= DW_TAG_module
)
4494 imported_declaration
= imported_name
;
4495 canonical_name
= imported_name_prefix
;
4497 else if (strlen (imported_name_prefix
) > 0)
4499 temp
= alloca (strlen (imported_name_prefix
)
4500 + 2 + strlen (imported_name
) + 1);
4501 strcpy (temp
, imported_name_prefix
);
4502 strcat (temp
, "::");
4503 strcat (temp
, imported_name
);
4504 canonical_name
= temp
;
4507 canonical_name
= imported_name
;
4509 cp_add_using_directive (import_prefix
,
4512 imported_declaration
,
4513 &cu
->objfile
->objfile_obstack
);
4517 initialize_cu_func_list (struct dwarf2_cu
*cu
)
4519 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
4523 free_cu_line_header (void *arg
)
4525 struct dwarf2_cu
*cu
= arg
;
4527 free_line_header (cu
->line_header
);
4528 cu
->line_header
= NULL
;
4532 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
4533 char **name
, char **comp_dir
)
4535 struct attribute
*attr
;
4540 /* Find the filename. Do not use dwarf2_name here, since the filename
4541 is not a source language identifier. */
4542 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4545 *name
= DW_STRING (attr
);
4548 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
4550 *comp_dir
= DW_STRING (attr
);
4551 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
4553 *comp_dir
= ldirname (*name
);
4554 if (*comp_dir
!= NULL
)
4555 make_cleanup (xfree
, *comp_dir
);
4557 if (*comp_dir
!= NULL
)
4559 /* Irix 6.2 native cc prepends <machine>.: to the compilation
4560 directory, get rid of it. */
4561 char *cp
= strchr (*comp_dir
, ':');
4563 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
4568 *name
= "<unknown>";
4572 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4574 struct objfile
*objfile
= cu
->objfile
;
4575 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4576 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
4577 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
4578 struct attribute
*attr
;
4580 char *comp_dir
= NULL
;
4581 struct die_info
*child_die
;
4582 bfd
*abfd
= objfile
->obfd
;
4583 struct line_header
*line_header
= 0;
4586 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4588 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
4590 /* If we didn't find a lowpc, set it to highpc to avoid complaints
4591 from finish_block. */
4592 if (lowpc
== ((CORE_ADDR
) -1))
4597 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
4599 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
4602 set_cu_language (DW_UNSND (attr
), cu
);
4605 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
4607 cu
->producer
= DW_STRING (attr
);
4609 /* We assume that we're processing GCC output. */
4610 processing_gcc_compilation
= 2;
4612 processing_has_namespace_info
= 0;
4614 start_symtab (name
, comp_dir
, lowpc
);
4615 record_debugformat ("DWARF 2");
4616 record_producer (cu
->producer
);
4618 initialize_cu_func_list (cu
);
4620 /* Decode line number information if present. We do this before
4621 processing child DIEs, so that the line header table is available
4622 for DW_AT_decl_file. */
4623 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4626 unsigned int line_offset
= DW_UNSND (attr
);
4627 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
4630 cu
->line_header
= line_header
;
4631 make_cleanup (free_cu_line_header
, cu
);
4632 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
4636 /* Process all dies in compilation unit. */
4637 if (die
->child
!= NULL
)
4639 child_die
= die
->child
;
4640 while (child_die
&& child_die
->tag
)
4642 process_die (child_die
, cu
);
4643 child_die
= sibling_die (child_die
);
4647 /* Decode macro information, if present. Dwarf 2 macro information
4648 refers to information in the line number info statement program
4649 header, so we can only read it if we've read the header
4651 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
4652 if (attr
&& line_header
)
4654 unsigned int macro_offset
= DW_UNSND (attr
);
4656 dwarf_decode_macros (line_header
, macro_offset
,
4657 comp_dir
, abfd
, cu
);
4659 do_cleanups (back_to
);
4662 /* For TUs we want to skip the first top level sibling if it's not the
4663 actual type being defined by this TU. In this case the first top
4664 level sibling is there to provide context only. */
4667 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4669 struct objfile
*objfile
= cu
->objfile
;
4670 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4672 struct attribute
*attr
;
4674 char *comp_dir
= NULL
;
4675 struct die_info
*child_die
;
4676 bfd
*abfd
= objfile
->obfd
;
4678 /* start_symtab needs a low pc, but we don't really have one.
4679 Do what read_file_scope would do in the absence of such info. */
4680 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4682 /* Find the filename. Do not use dwarf2_name here, since the filename
4683 is not a source language identifier. */
4684 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4686 name
= DW_STRING (attr
);
4688 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
4690 comp_dir
= DW_STRING (attr
);
4691 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
4693 comp_dir
= ldirname (name
);
4694 if (comp_dir
!= NULL
)
4695 make_cleanup (xfree
, comp_dir
);
4701 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
4703 set_cu_language (DW_UNSND (attr
), cu
);
4705 /* This isn't technically needed today. It is done for symmetry
4706 with read_file_scope. */
4707 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
4709 cu
->producer
= DW_STRING (attr
);
4711 /* We assume that we're processing GCC output. */
4712 processing_gcc_compilation
= 2;
4714 processing_has_namespace_info
= 0;
4716 start_symtab (name
, comp_dir
, lowpc
);
4717 record_debugformat ("DWARF 2");
4718 record_producer (cu
->producer
);
4720 /* Process the dies in the type unit. */
4721 if (die
->child
== NULL
)
4723 dump_die_for_error (die
);
4724 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
4725 bfd_get_filename (abfd
));
4728 child_die
= die
->child
;
4730 while (child_die
&& child_die
->tag
)
4732 process_die (child_die
, cu
);
4734 child_die
= sibling_die (child_die
);
4737 do_cleanups (back_to
);
4741 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
4742 struct dwarf2_cu
*cu
)
4744 struct function_range
*thisfn
;
4746 thisfn
= (struct function_range
*)
4747 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
4748 thisfn
->name
= name
;
4749 thisfn
->lowpc
= lowpc
;
4750 thisfn
->highpc
= highpc
;
4751 thisfn
->seen_line
= 0;
4752 thisfn
->next
= NULL
;
4754 if (cu
->last_fn
== NULL
)
4755 cu
->first_fn
= thisfn
;
4757 cu
->last_fn
->next
= thisfn
;
4759 cu
->last_fn
= thisfn
;
4762 /* qsort helper for inherit_abstract_dies. */
4765 unsigned_int_compar (const void *ap
, const void *bp
)
4767 unsigned int a
= *(unsigned int *) ap
;
4768 unsigned int b
= *(unsigned int *) bp
;
4770 return (a
> b
) - (b
> a
);
4773 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
4774 Inherit only the children of the DW_AT_abstract_origin DIE not being already
4775 referenced by DW_AT_abstract_origin from the children of the current DIE. */
4778 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
4780 struct die_info
*child_die
;
4781 unsigned die_children_count
;
4782 /* CU offsets which were referenced by children of the current DIE. */
4784 unsigned *offsets_end
, *offsetp
;
4785 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
4786 struct die_info
*origin_die
;
4787 /* Iterator of the ORIGIN_DIE children. */
4788 struct die_info
*origin_child_die
;
4789 struct cleanup
*cleanups
;
4790 struct attribute
*attr
;
4792 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
4796 origin_die
= follow_die_ref (die
, attr
, &cu
);
4797 if (die
->tag
!= origin_die
->tag
4798 && !(die
->tag
== DW_TAG_inlined_subroutine
4799 && origin_die
->tag
== DW_TAG_subprogram
))
4800 complaint (&symfile_complaints
,
4801 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
4802 die
->offset
, origin_die
->offset
);
4804 child_die
= die
->child
;
4805 die_children_count
= 0;
4806 while (child_die
&& child_die
->tag
)
4808 child_die
= sibling_die (child_die
);
4809 die_children_count
++;
4811 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
4812 cleanups
= make_cleanup (xfree
, offsets
);
4814 offsets_end
= offsets
;
4815 child_die
= die
->child
;
4816 while (child_die
&& child_die
->tag
)
4818 /* For each CHILD_DIE, find the corresponding child of
4819 ORIGIN_DIE. If there is more than one layer of
4820 DW_AT_abstract_origin, follow them all; there shouldn't be,
4821 but GCC versions at least through 4.4 generate this (GCC PR
4823 struct die_info
*child_origin_die
= child_die
;
4827 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
4830 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
4833 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
4834 counterpart may exist. */
4835 if (child_origin_die
!= child_die
)
4837 if (child_die
->tag
!= child_origin_die
->tag
4838 && !(child_die
->tag
== DW_TAG_inlined_subroutine
4839 && child_origin_die
->tag
== DW_TAG_subprogram
))
4840 complaint (&symfile_complaints
,
4841 _("Child DIE 0x%x and its abstract origin 0x%x have "
4842 "different tags"), child_die
->offset
,
4843 child_origin_die
->offset
);
4844 if (child_origin_die
->parent
!= origin_die
)
4845 complaint (&symfile_complaints
,
4846 _("Child DIE 0x%x and its abstract origin 0x%x have "
4847 "different parents"), child_die
->offset
,
4848 child_origin_die
->offset
);
4850 *offsets_end
++ = child_origin_die
->offset
;
4852 child_die
= sibling_die (child_die
);
4854 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
4855 unsigned_int_compar
);
4856 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
4857 if (offsetp
[-1] == *offsetp
)
4858 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
4859 "to DIE 0x%x as their abstract origin"),
4860 die
->offset
, *offsetp
);
4863 origin_child_die
= origin_die
->child
;
4864 while (origin_child_die
&& origin_child_die
->tag
)
4866 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
4867 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
4869 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
4871 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
4872 process_die (origin_child_die
, cu
);
4874 origin_child_die
= sibling_die (origin_child_die
);
4877 do_cleanups (cleanups
);
4881 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4883 struct objfile
*objfile
= cu
->objfile
;
4884 struct context_stack
*new;
4887 struct die_info
*child_die
;
4888 struct attribute
*attr
, *call_line
, *call_file
;
4891 struct block
*block
;
4892 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
4896 /* If we do not have call site information, we can't show the
4897 caller of this inlined function. That's too confusing, so
4898 only use the scope for local variables. */
4899 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
4900 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
4901 if (call_line
== NULL
|| call_file
== NULL
)
4903 read_lexical_block_scope (die
, cu
);
4908 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4910 name
= dwarf2_name (die
, cu
);
4912 /* Ignore functions with missing or empty names. These are actually
4913 illegal according to the DWARF standard. */
4916 complaint (&symfile_complaints
,
4917 _("missing name for subprogram DIE at %d"), die
->offset
);
4921 /* Ignore functions with missing or invalid low and high pc attributes. */
4922 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
4924 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4925 if (!attr
|| !DW_UNSND (attr
))
4926 complaint (&symfile_complaints
,
4927 _("cannot get low and high bounds for subprogram DIE at %d"),
4935 /* Record the function range for dwarf_decode_lines. */
4936 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
4938 new = push_context (0, lowpc
);
4939 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
4941 /* If there is a location expression for DW_AT_frame_base, record
4943 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
4945 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
4946 expression is being recorded directly in the function's symbol
4947 and not in a separate frame-base object. I guess this hack is
4948 to avoid adding some sort of frame-base adjunct/annex to the
4949 function's symbol :-(. The problem with doing this is that it
4950 results in a function symbol with a location expression that
4951 has nothing to do with the location of the function, ouch! The
4952 relationship should be: a function's symbol has-a frame base; a
4953 frame-base has-a location expression. */
4954 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
4956 cu
->list_in_scope
= &local_symbols
;
4958 if (die
->child
!= NULL
)
4960 child_die
= die
->child
;
4961 while (child_die
&& child_die
->tag
)
4963 process_die (child_die
, cu
);
4964 child_die
= sibling_die (child_die
);
4968 inherit_abstract_dies (die
, cu
);
4970 /* If we have a DW_AT_specification, we might need to import using
4971 directives from the context of the specification DIE. See the
4972 comment in determine_prefix. */
4973 if (cu
->language
== language_cplus
4974 && dwarf2_attr (die
, DW_AT_specification
, cu
))
4976 struct dwarf2_cu
*spec_cu
= cu
;
4977 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
4981 child_die
= spec_die
->child
;
4982 while (child_die
&& child_die
->tag
)
4984 if (child_die
->tag
== DW_TAG_imported_module
)
4985 process_die (child_die
, spec_cu
);
4986 child_die
= sibling_die (child_die
);
4989 /* In some cases, GCC generates specification DIEs that
4990 themselves contain DW_AT_specification attributes. */
4991 spec_die
= die_specification (spec_die
, &spec_cu
);
4995 new = pop_context ();
4996 /* Make a block for the local symbols within. */
4997 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
4998 lowpc
, highpc
, objfile
);
5000 /* For C++, set the block's scope. */
5001 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5002 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5003 determine_prefix (die
, cu
),
5004 processing_has_namespace_info
);
5006 /* If we have address ranges, record them. */
5007 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5009 /* In C++, we can have functions nested inside functions (e.g., when
5010 a function declares a class that has methods). This means that
5011 when we finish processing a function scope, we may need to go
5012 back to building a containing block's symbol lists. */
5013 local_symbols
= new->locals
;
5014 param_symbols
= new->params
;
5015 using_directives
= new->using_directives
;
5017 /* If we've finished processing a top-level function, subsequent
5018 symbols go in the file symbol list. */
5019 if (outermost_context_p ())
5020 cu
->list_in_scope
= &file_symbols
;
5023 /* Process all the DIES contained within a lexical block scope. Start
5024 a new scope, process the dies, and then close the scope. */
5027 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5029 struct objfile
*objfile
= cu
->objfile
;
5030 struct context_stack
*new;
5031 CORE_ADDR lowpc
, highpc
;
5032 struct die_info
*child_die
;
5035 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5037 /* Ignore blocks with missing or invalid low and high pc attributes. */
5038 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5039 as multiple lexical blocks? Handling children in a sane way would
5040 be nasty. Might be easier to properly extend generic blocks to
5042 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5047 push_context (0, lowpc
);
5048 if (die
->child
!= NULL
)
5050 child_die
= die
->child
;
5051 while (child_die
&& child_die
->tag
)
5053 process_die (child_die
, cu
);
5054 child_die
= sibling_die (child_die
);
5057 new = pop_context ();
5059 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5062 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5065 /* Note that recording ranges after traversing children, as we
5066 do here, means that recording a parent's ranges entails
5067 walking across all its children's ranges as they appear in
5068 the address map, which is quadratic behavior.
5070 It would be nicer to record the parent's ranges before
5071 traversing its children, simply overriding whatever you find
5072 there. But since we don't even decide whether to create a
5073 block until after we've traversed its children, that's hard
5075 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5077 local_symbols
= new->locals
;
5078 using_directives
= new->using_directives
;
5081 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5082 Return 1 if the attributes are present and valid, otherwise, return 0.
5083 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5086 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5087 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5088 struct partial_symtab
*ranges_pst
)
5090 struct objfile
*objfile
= cu
->objfile
;
5091 struct comp_unit_head
*cu_header
= &cu
->header
;
5092 bfd
*obfd
= objfile
->obfd
;
5093 unsigned int addr_size
= cu_header
->addr_size
;
5094 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5095 /* Base address selection entry. */
5106 found_base
= cu
->base_known
;
5107 base
= cu
->base_address
;
5109 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5110 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5112 complaint (&symfile_complaints
,
5113 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5117 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5119 /* Read in the largest possible address. */
5120 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5121 if ((marker
& mask
) == mask
)
5123 /* If we found the largest possible address, then
5124 read the base address. */
5125 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5126 buffer
+= 2 * addr_size
;
5127 offset
+= 2 * addr_size
;
5133 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5137 CORE_ADDR range_beginning
, range_end
;
5139 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5140 buffer
+= addr_size
;
5141 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5142 buffer
+= addr_size
;
5143 offset
+= 2 * addr_size
;
5145 /* An end of list marker is a pair of zero addresses. */
5146 if (range_beginning
== 0 && range_end
== 0)
5147 /* Found the end of list entry. */
5150 /* Each base address selection entry is a pair of 2 values.
5151 The first is the largest possible address, the second is
5152 the base address. Check for a base address here. */
5153 if ((range_beginning
& mask
) == mask
)
5155 /* If we found the largest possible address, then
5156 read the base address. */
5157 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5164 /* We have no valid base address for the ranges
5166 complaint (&symfile_complaints
,
5167 _("Invalid .debug_ranges data (no base address)"));
5171 range_beginning
+= base
;
5174 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5175 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5176 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5179 /* FIXME: This is recording everything as a low-high
5180 segment of consecutive addresses. We should have a
5181 data structure for discontiguous block ranges
5185 low
= range_beginning
;
5191 if (range_beginning
< low
)
5192 low
= range_beginning
;
5193 if (range_end
> high
)
5199 /* If the first entry is an end-of-list marker, the range
5200 describes an empty scope, i.e. no instructions. */
5206 *high_return
= high
;
5210 /* Get low and high pc attributes from a die. Return 1 if the attributes
5211 are present and valid, otherwise, return 0. Return -1 if the range is
5212 discontinuous, i.e. derived from DW_AT_ranges information. */
5214 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5215 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5216 struct partial_symtab
*pst
)
5218 struct attribute
*attr
;
5223 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5226 high
= DW_ADDR (attr
);
5227 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5229 low
= DW_ADDR (attr
);
5231 /* Found high w/o low attribute. */
5234 /* Found consecutive range of addresses. */
5239 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5242 /* Value of the DW_AT_ranges attribute is the offset in the
5243 .debug_ranges section. */
5244 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5246 /* Found discontinuous range of addresses. */
5254 /* When using the GNU linker, .gnu.linkonce. sections are used to
5255 eliminate duplicate copies of functions and vtables and such.
5256 The linker will arbitrarily choose one and discard the others.
5257 The AT_*_pc values for such functions refer to local labels in
5258 these sections. If the section from that file was discarded, the
5259 labels are not in the output, so the relocs get a value of 0.
5260 If this is a discarded function, mark the pc bounds as invalid,
5261 so that GDB will ignore it. */
5262 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5270 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5271 its low and high PC addresses. Do nothing if these addresses could not
5272 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5273 and HIGHPC to the high address if greater than HIGHPC. */
5276 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5277 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5278 struct dwarf2_cu
*cu
)
5280 CORE_ADDR low
, high
;
5281 struct die_info
*child
= die
->child
;
5283 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5285 *lowpc
= min (*lowpc
, low
);
5286 *highpc
= max (*highpc
, high
);
5289 /* If the language does not allow nested subprograms (either inside
5290 subprograms or lexical blocks), we're done. */
5291 if (cu
->language
!= language_ada
)
5294 /* Check all the children of the given DIE. If it contains nested
5295 subprograms, then check their pc bounds. Likewise, we need to
5296 check lexical blocks as well, as they may also contain subprogram
5298 while (child
&& child
->tag
)
5300 if (child
->tag
== DW_TAG_subprogram
5301 || child
->tag
== DW_TAG_lexical_block
)
5302 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5303 child
= sibling_die (child
);
5307 /* Get the low and high pc's represented by the scope DIE, and store
5308 them in *LOWPC and *HIGHPC. If the correct values can't be
5309 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5312 get_scope_pc_bounds (struct die_info
*die
,
5313 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5314 struct dwarf2_cu
*cu
)
5316 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5317 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5318 CORE_ADDR current_low
, current_high
;
5320 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5322 best_low
= current_low
;
5323 best_high
= current_high
;
5327 struct die_info
*child
= die
->child
;
5329 while (child
&& child
->tag
)
5331 switch (child
->tag
) {
5332 case DW_TAG_subprogram
:
5333 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5335 case DW_TAG_namespace
:
5337 /* FIXME: carlton/2004-01-16: Should we do this for
5338 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5339 that current GCC's always emit the DIEs corresponding
5340 to definitions of methods of classes as children of a
5341 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5342 the DIEs giving the declarations, which could be
5343 anywhere). But I don't see any reason why the
5344 standards says that they have to be there. */
5345 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5347 if (current_low
!= ((CORE_ADDR
) -1))
5349 best_low
= min (best_low
, current_low
);
5350 best_high
= max (best_high
, current_high
);
5358 child
= sibling_die (child
);
5363 *highpc
= best_high
;
5366 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5369 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5370 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5372 struct attribute
*attr
;
5374 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5377 CORE_ADDR high
= DW_ADDR (attr
);
5379 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5382 CORE_ADDR low
= DW_ADDR (attr
);
5384 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5388 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5391 bfd
*obfd
= cu
->objfile
->obfd
;
5393 /* The value of the DW_AT_ranges attribute is the offset of the
5394 address range list in the .debug_ranges section. */
5395 unsigned long offset
= DW_UNSND (attr
);
5396 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5398 /* For some target architectures, but not others, the
5399 read_address function sign-extends the addresses it returns.
5400 To recognize base address selection entries, we need a
5402 unsigned int addr_size
= cu
->header
.addr_size
;
5403 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5405 /* The base address, to which the next pair is relative. Note
5406 that this 'base' is a DWARF concept: most entries in a range
5407 list are relative, to reduce the number of relocs against the
5408 debugging information. This is separate from this function's
5409 'baseaddr' argument, which GDB uses to relocate debugging
5410 information from a shared library based on the address at
5411 which the library was loaded. */
5412 CORE_ADDR base
= cu
->base_address
;
5413 int base_known
= cu
->base_known
;
5415 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5416 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5418 complaint (&symfile_complaints
,
5419 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5426 unsigned int bytes_read
;
5427 CORE_ADDR start
, end
;
5429 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5430 buffer
+= bytes_read
;
5431 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5432 buffer
+= bytes_read
;
5434 /* Did we find the end of the range list? */
5435 if (start
== 0 && end
== 0)
5438 /* Did we find a base address selection entry? */
5439 else if ((start
& base_select_mask
) == base_select_mask
)
5445 /* We found an ordinary address range. */
5450 complaint (&symfile_complaints
,
5451 _("Invalid .debug_ranges data (no base address)"));
5455 record_block_range (block
,
5456 baseaddr
+ base
+ start
,
5457 baseaddr
+ base
+ end
- 1);
5463 /* Add an aggregate field to the field list. */
5466 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
5467 struct dwarf2_cu
*cu
)
5469 struct objfile
*objfile
= cu
->objfile
;
5470 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5471 struct nextfield
*new_field
;
5472 struct attribute
*attr
;
5474 char *fieldname
= "";
5476 /* Allocate a new field list entry and link it in. */
5477 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
5478 make_cleanup (xfree
, new_field
);
5479 memset (new_field
, 0, sizeof (struct nextfield
));
5481 if (die
->tag
== DW_TAG_inheritance
)
5483 new_field
->next
= fip
->baseclasses
;
5484 fip
->baseclasses
= new_field
;
5488 new_field
->next
= fip
->fields
;
5489 fip
->fields
= new_field
;
5493 /* Handle accessibility and virtuality of field.
5494 The default accessibility for members is public, the default
5495 accessibility for inheritance is private. */
5496 if (die
->tag
!= DW_TAG_inheritance
)
5497 new_field
->accessibility
= DW_ACCESS_public
;
5499 new_field
->accessibility
= DW_ACCESS_private
;
5500 new_field
->virtuality
= DW_VIRTUALITY_none
;
5502 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
5504 new_field
->accessibility
= DW_UNSND (attr
);
5505 if (new_field
->accessibility
!= DW_ACCESS_public
)
5506 fip
->non_public_fields
= 1;
5507 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
5509 new_field
->virtuality
= DW_UNSND (attr
);
5511 fp
= &new_field
->field
;
5513 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
5515 /* Data member other than a C++ static data member. */
5517 /* Get type of field. */
5518 fp
->type
= die_type (die
, cu
);
5520 SET_FIELD_BITPOS (*fp
, 0);
5522 /* Get bit size of field (zero if none). */
5523 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
5526 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
5530 FIELD_BITSIZE (*fp
) = 0;
5533 /* Get bit offset of field. */
5534 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
5537 int byte_offset
= 0;
5539 if (attr_form_is_section_offset (attr
))
5540 dwarf2_complex_location_expr_complaint ();
5541 else if (attr_form_is_constant (attr
))
5542 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5543 else if (attr_form_is_block (attr
))
5544 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5546 dwarf2_complex_location_expr_complaint ();
5548 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
5550 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
5553 if (gdbarch_bits_big_endian (gdbarch
))
5555 /* For big endian bits, the DW_AT_bit_offset gives the
5556 additional bit offset from the MSB of the containing
5557 anonymous object to the MSB of the field. We don't
5558 have to do anything special since we don't need to
5559 know the size of the anonymous object. */
5560 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
5564 /* For little endian bits, compute the bit offset to the
5565 MSB of the anonymous object, subtract off the number of
5566 bits from the MSB of the field to the MSB of the
5567 object, and then subtract off the number of bits of
5568 the field itself. The result is the bit offset of
5569 the LSB of the field. */
5571 int bit_offset
= DW_UNSND (attr
);
5573 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5576 /* The size of the anonymous object containing
5577 the bit field is explicit, so use the
5578 indicated size (in bytes). */
5579 anonymous_size
= DW_UNSND (attr
);
5583 /* The size of the anonymous object containing
5584 the bit field must be inferred from the type
5585 attribute of the data member containing the
5587 anonymous_size
= TYPE_LENGTH (fp
->type
);
5589 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
5590 - bit_offset
- FIELD_BITSIZE (*fp
);
5594 /* Get name of field. */
5595 fieldname
= dwarf2_name (die
, cu
);
5596 if (fieldname
== NULL
)
5599 /* The name is already allocated along with this objfile, so we don't
5600 need to duplicate it for the type. */
5601 fp
->name
= fieldname
;
5603 /* Change accessibility for artificial fields (e.g. virtual table
5604 pointer or virtual base class pointer) to private. */
5605 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
5607 FIELD_ARTIFICIAL (*fp
) = 1;
5608 new_field
->accessibility
= DW_ACCESS_private
;
5609 fip
->non_public_fields
= 1;
5612 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
5614 /* C++ static member. */
5616 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
5617 is a declaration, but all versions of G++ as of this writing
5618 (so through at least 3.2.1) incorrectly generate
5619 DW_TAG_variable tags. */
5623 /* Get name of field. */
5624 fieldname
= dwarf2_name (die
, cu
);
5625 if (fieldname
== NULL
)
5628 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5630 /* Only create a symbol if this is an external value.
5631 new_symbol checks this and puts the value in the global symbol
5632 table, which we want. If it is not external, new_symbol
5633 will try to put the value in cu->list_in_scope which is wrong. */
5634 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
5636 /* A static const member, not much different than an enum as far as
5637 we're concerned, except that we can support more types. */
5638 new_symbol (die
, NULL
, cu
);
5641 /* Get physical name. */
5642 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
5644 /* The name is already allocated along with this objfile, so we don't
5645 need to duplicate it for the type. */
5646 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
5647 FIELD_TYPE (*fp
) = die_type (die
, cu
);
5648 FIELD_NAME (*fp
) = fieldname
;
5650 else if (die
->tag
== DW_TAG_inheritance
)
5652 /* C++ base class field. */
5653 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
5656 int byte_offset
= 0;
5658 if (attr_form_is_section_offset (attr
))
5659 dwarf2_complex_location_expr_complaint ();
5660 else if (attr_form_is_constant (attr
))
5661 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5662 else if (attr_form_is_block (attr
))
5663 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5665 dwarf2_complex_location_expr_complaint ();
5667 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
5669 FIELD_BITSIZE (*fp
) = 0;
5670 FIELD_TYPE (*fp
) = die_type (die
, cu
);
5671 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
5672 fip
->nbaseclasses
++;
5676 /* Add a typedef defined in the scope of the FIP's class. */
5679 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
5680 struct dwarf2_cu
*cu
)
5682 struct objfile
*objfile
= cu
->objfile
;
5683 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5684 struct typedef_field_list
*new_field
;
5685 struct attribute
*attr
;
5686 struct typedef_field
*fp
;
5687 char *fieldname
= "";
5689 /* Allocate a new field list entry and link it in. */
5690 new_field
= xzalloc (sizeof (*new_field
));
5691 make_cleanup (xfree
, new_field
);
5693 gdb_assert (die
->tag
== DW_TAG_typedef
);
5695 fp
= &new_field
->field
;
5697 /* Get name of field. */
5698 fp
->name
= dwarf2_name (die
, cu
);
5699 if (fp
->name
== NULL
)
5702 fp
->type
= read_type_die (die
, cu
);
5704 new_field
->next
= fip
->typedef_field_list
;
5705 fip
->typedef_field_list
= new_field
;
5706 fip
->typedef_field_list_count
++;
5709 /* Create the vector of fields, and attach it to the type. */
5712 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
5713 struct dwarf2_cu
*cu
)
5715 int nfields
= fip
->nfields
;
5717 /* Record the field count, allocate space for the array of fields,
5718 and create blank accessibility bitfields if necessary. */
5719 TYPE_NFIELDS (type
) = nfields
;
5720 TYPE_FIELDS (type
) = (struct field
*)
5721 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
5722 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
5724 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
5726 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
5728 TYPE_FIELD_PRIVATE_BITS (type
) =
5729 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
5730 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
5732 TYPE_FIELD_PROTECTED_BITS (type
) =
5733 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
5734 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
5736 TYPE_FIELD_IGNORE_BITS (type
) =
5737 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
5738 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
5741 /* If the type has baseclasses, allocate and clear a bit vector for
5742 TYPE_FIELD_VIRTUAL_BITS. */
5743 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
5745 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
5746 unsigned char *pointer
;
5748 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
5749 pointer
= TYPE_ALLOC (type
, num_bytes
);
5750 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
5751 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
5752 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
5755 /* Copy the saved-up fields into the field vector. Start from the head
5756 of the list, adding to the tail of the field array, so that they end
5757 up in the same order in the array in which they were added to the list. */
5758 while (nfields
-- > 0)
5760 struct nextfield
*fieldp
;
5764 fieldp
= fip
->fields
;
5765 fip
->fields
= fieldp
->next
;
5769 fieldp
= fip
->baseclasses
;
5770 fip
->baseclasses
= fieldp
->next
;
5773 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
5774 switch (fieldp
->accessibility
)
5776 case DW_ACCESS_private
:
5777 if (cu
->language
!= language_ada
)
5778 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
5781 case DW_ACCESS_protected
:
5782 if (cu
->language
!= language_ada
)
5783 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
5786 case DW_ACCESS_public
:
5790 /* Unknown accessibility. Complain and treat it as public. */
5792 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
5793 fieldp
->accessibility
);
5797 if (nfields
< fip
->nbaseclasses
)
5799 switch (fieldp
->virtuality
)
5801 case DW_VIRTUALITY_virtual
:
5802 case DW_VIRTUALITY_pure_virtual
:
5803 if (cu
->language
== language_ada
)
5804 error ("unexpected virtuality in component of Ada type");
5805 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
5812 /* Add a member function to the proper fieldlist. */
5815 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
5816 struct type
*type
, struct dwarf2_cu
*cu
)
5818 struct objfile
*objfile
= cu
->objfile
;
5819 struct attribute
*attr
;
5820 struct fnfieldlist
*flp
;
5822 struct fn_field
*fnp
;
5825 struct nextfnfield
*new_fnfield
;
5826 struct type
*this_type
;
5828 if (cu
->language
== language_ada
)
5829 error ("unexpected member function in Ada type");
5831 /* Get name of member function. */
5832 fieldname
= dwarf2_name (die
, cu
);
5833 if (fieldname
== NULL
)
5836 /* Get the mangled name. */
5837 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
5839 /* Look up member function name in fieldlist. */
5840 for (i
= 0; i
< fip
->nfnfields
; i
++)
5842 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
5846 /* Create new list element if necessary. */
5847 if (i
< fip
->nfnfields
)
5848 flp
= &fip
->fnfieldlists
[i
];
5851 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5853 fip
->fnfieldlists
= (struct fnfieldlist
*)
5854 xrealloc (fip
->fnfieldlists
,
5855 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
5856 * sizeof (struct fnfieldlist
));
5857 if (fip
->nfnfields
== 0)
5858 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
5860 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
5861 flp
->name
= fieldname
;
5867 /* Create a new member function field and chain it to the field list
5869 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
5870 make_cleanup (xfree
, new_fnfield
);
5871 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
5872 new_fnfield
->next
= flp
->head
;
5873 flp
->head
= new_fnfield
;
5876 /* Fill in the member function field info. */
5877 fnp
= &new_fnfield
->fnfield
;
5878 /* The name is already allocated along with this objfile, so we don't
5879 need to duplicate it for the type. */
5880 fnp
->physname
= physname
? physname
: "";
5881 fnp
->type
= alloc_type (objfile
);
5882 this_type
= read_type_die (die
, cu
);
5883 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
5885 int nparams
= TYPE_NFIELDS (this_type
);
5887 /* TYPE is the domain of this method, and THIS_TYPE is the type
5888 of the method itself (TYPE_CODE_METHOD). */
5889 smash_to_method_type (fnp
->type
, type
,
5890 TYPE_TARGET_TYPE (this_type
),
5891 TYPE_FIELDS (this_type
),
5892 TYPE_NFIELDS (this_type
),
5893 TYPE_VARARGS (this_type
));
5895 /* Handle static member functions.
5896 Dwarf2 has no clean way to discern C++ static and non-static
5897 member functions. G++ helps GDB by marking the first
5898 parameter for non-static member functions (which is the
5899 this pointer) as artificial. We obtain this information
5900 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
5901 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
5902 fnp
->voffset
= VOFFSET_STATIC
;
5905 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
5908 /* Get fcontext from DW_AT_containing_type if present. */
5909 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5910 fnp
->fcontext
= die_containing_type (die
, cu
);
5912 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
5913 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
5915 /* Get accessibility. */
5916 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
5919 switch (DW_UNSND (attr
))
5921 case DW_ACCESS_private
:
5922 fnp
->is_private
= 1;
5924 case DW_ACCESS_protected
:
5925 fnp
->is_protected
= 1;
5930 /* Check for artificial methods. */
5931 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
5932 if (attr
&& DW_UNSND (attr
) != 0)
5933 fnp
->is_artificial
= 1;
5935 /* Get index in virtual function table if it is a virtual member
5936 function. For older versions of GCC, this is an offset in the
5937 appropriate virtual table, as specified by DW_AT_containing_type.
5938 For everyone else, it is an expression to be evaluated relative
5939 to the object address. */
5941 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
5944 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
5946 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
5948 /* Old-style GCC. */
5949 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
5951 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
5952 || (DW_BLOCK (attr
)->size
> 1
5953 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
5954 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
5956 struct dwarf_block blk
;
5959 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
5961 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
5962 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
5963 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5964 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
5965 dwarf2_complex_location_expr_complaint ();
5967 fnp
->voffset
/= cu
->header
.addr_size
;
5971 dwarf2_complex_location_expr_complaint ();
5974 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
5976 else if (attr_form_is_section_offset (attr
))
5978 dwarf2_complex_location_expr_complaint ();
5982 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
5988 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
5989 if (attr
&& DW_UNSND (attr
))
5991 /* GCC does this, as of 2008-08-25; PR debug/37237. */
5992 complaint (&symfile_complaints
,
5993 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
5994 fieldname
, die
->offset
);
5995 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
5996 TYPE_CPLUS_DYNAMIC (type
) = 1;
6001 /* Create the vector of member function fields, and attach it to the type. */
6004 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6005 struct dwarf2_cu
*cu
)
6007 struct fnfieldlist
*flp
;
6008 int total_length
= 0;
6011 if (cu
->language
== language_ada
)
6012 error ("unexpected member functions in Ada type");
6014 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6015 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6016 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6018 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6020 struct nextfnfield
*nfp
= flp
->head
;
6021 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6024 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6025 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6026 fn_flp
->fn_fields
= (struct fn_field
*)
6027 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6028 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6029 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6031 total_length
+= flp
->length
;
6034 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6035 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6038 /* Returns non-zero if NAME is the name of a vtable member in CU's
6039 language, zero otherwise. */
6041 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6043 static const char vptr
[] = "_vptr";
6044 static const char vtable
[] = "vtable";
6046 /* Look for the C++ and Java forms of the vtable. */
6047 if ((cu
->language
== language_java
6048 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6049 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6050 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6056 /* GCC outputs unnamed structures that are really pointers to member
6057 functions, with the ABI-specified layout. If TYPE describes
6058 such a structure, smash it into a member function type.
6060 GCC shouldn't do this; it should just output pointer to member DIEs.
6061 This is GCC PR debug/28767. */
6064 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6066 struct type
*pfn_type
, *domain_type
, *new_type
;
6068 /* Check for a structure with no name and two children. */
6069 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6072 /* Check for __pfn and __delta members. */
6073 if (TYPE_FIELD_NAME (type
, 0) == NULL
6074 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6075 || TYPE_FIELD_NAME (type
, 1) == NULL
6076 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6079 /* Find the type of the method. */
6080 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6081 if (pfn_type
== NULL
6082 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6083 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6086 /* Look for the "this" argument. */
6087 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6088 if (TYPE_NFIELDS (pfn_type
) == 0
6089 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6090 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6093 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6094 new_type
= alloc_type (objfile
);
6095 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6096 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6097 TYPE_VARARGS (pfn_type
));
6098 smash_to_methodptr_type (type
, new_type
);
6101 /* Called when we find the DIE that starts a structure or union scope
6102 (definition) to process all dies that define the members of the
6105 NOTE: we need to call struct_type regardless of whether or not the
6106 DIE has an at_name attribute, since it might be an anonymous
6107 structure or union. This gets the type entered into our set of
6110 However, if the structure is incomplete (an opaque struct/union)
6111 then suppress creating a symbol table entry for it since gdb only
6112 wants to find the one with the complete definition. Note that if
6113 it is complete, we just call new_symbol, which does it's own
6114 checking about whether the struct/union is anonymous or not (and
6115 suppresses creating a symbol table entry itself). */
6117 static struct type
*
6118 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6120 struct objfile
*objfile
= cu
->objfile
;
6122 struct attribute
*attr
;
6124 struct cleanup
*back_to
;
6126 /* If the definition of this type lives in .debug_types, read that type.
6127 Don't follow DW_AT_specification though, that will take us back up
6128 the chain and we want to go down. */
6129 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6132 struct dwarf2_cu
*type_cu
= cu
;
6133 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6135 /* We could just recurse on read_structure_type, but we need to call
6136 get_die_type to ensure only one type for this DIE is created.
6137 This is important, for example, because for c++ classes we need
6138 TYPE_NAME set which is only done by new_symbol. Blech. */
6139 type
= read_type_die (type_die
, type_cu
);
6140 return set_die_type (die
, type
, cu
);
6143 back_to
= make_cleanup (null_cleanup
, 0);
6145 type
= alloc_type (objfile
);
6146 INIT_CPLUS_SPECIFIC (type
);
6148 name
= dwarf2_name (die
, cu
);
6151 if (cu
->language
== language_cplus
6152 || cu
->language
== language_java
)
6154 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
6155 if (die
->tag
== DW_TAG_structure_type
6156 || die
->tag
== DW_TAG_class_type
)
6157 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6161 /* The name is already allocated along with this objfile, so
6162 we don't need to duplicate it for the type. */
6163 TYPE_TAG_NAME (type
) = (char *) name
;
6164 if (die
->tag
== DW_TAG_class_type
)
6165 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6169 if (die
->tag
== DW_TAG_structure_type
)
6171 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6173 else if (die
->tag
== DW_TAG_union_type
)
6175 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6179 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6182 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6183 TYPE_DECLARED_CLASS (type
) = 1;
6185 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6188 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6192 TYPE_LENGTH (type
) = 0;
6195 TYPE_STUB_SUPPORTED (type
) = 1;
6196 if (die_is_declaration (die
, cu
))
6197 TYPE_STUB (type
) = 1;
6198 else if (attr
== NULL
&& die
->child
== NULL
6199 && producer_is_realview (cu
->producer
))
6200 /* RealView does not output the required DW_AT_declaration
6201 on incomplete types. */
6202 TYPE_STUB (type
) = 1;
6204 /* We need to add the type field to the die immediately so we don't
6205 infinitely recurse when dealing with pointers to the structure
6206 type within the structure itself. */
6207 set_die_type (die
, type
, cu
);
6209 /* set_die_type should be already done. */
6210 set_descriptive_type (type
, die
, cu
);
6212 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6214 struct field_info fi
;
6215 struct die_info
*child_die
;
6217 memset (&fi
, 0, sizeof (struct field_info
));
6219 child_die
= die
->child
;
6221 while (child_die
&& child_die
->tag
)
6223 if (child_die
->tag
== DW_TAG_member
6224 || child_die
->tag
== DW_TAG_variable
)
6226 /* NOTE: carlton/2002-11-05: A C++ static data member
6227 should be a DW_TAG_member that is a declaration, but
6228 all versions of G++ as of this writing (so through at
6229 least 3.2.1) incorrectly generate DW_TAG_variable
6230 tags for them instead. */
6231 dwarf2_add_field (&fi
, child_die
, cu
);
6233 else if (child_die
->tag
== DW_TAG_subprogram
)
6235 /* C++ member function. */
6236 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6238 else if (child_die
->tag
== DW_TAG_inheritance
)
6240 /* C++ base class field. */
6241 dwarf2_add_field (&fi
, child_die
, cu
);
6243 else if (child_die
->tag
== DW_TAG_typedef
)
6244 dwarf2_add_typedef (&fi
, child_die
, cu
);
6245 child_die
= sibling_die (child_die
);
6248 /* Attach fields and member functions to the type. */
6250 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6253 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6255 /* Get the type which refers to the base class (possibly this
6256 class itself) which contains the vtable pointer for the current
6257 class from the DW_AT_containing_type attribute. This use of
6258 DW_AT_containing_type is a GNU extension. */
6260 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6262 struct type
*t
= die_containing_type (die
, cu
);
6264 TYPE_VPTR_BASETYPE (type
) = t
;
6269 /* Our own class provides vtbl ptr. */
6270 for (i
= TYPE_NFIELDS (t
) - 1;
6271 i
>= TYPE_N_BASECLASSES (t
);
6274 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6276 if (is_vtable_name (fieldname
, cu
))
6278 TYPE_VPTR_FIELDNO (type
) = i
;
6283 /* Complain if virtual function table field not found. */
6284 if (i
< TYPE_N_BASECLASSES (t
))
6285 complaint (&symfile_complaints
,
6286 _("virtual function table pointer not found when defining class '%s'"),
6287 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6292 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6295 else if (cu
->producer
6296 && strncmp (cu
->producer
,
6297 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6299 /* The IBM XLC compiler does not provide direct indication
6300 of the containing type, but the vtable pointer is
6301 always named __vfp. */
6305 for (i
= TYPE_NFIELDS (type
) - 1;
6306 i
>= TYPE_N_BASECLASSES (type
);
6309 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6311 TYPE_VPTR_FIELDNO (type
) = i
;
6312 TYPE_VPTR_BASETYPE (type
) = type
;
6319 /* Copy fi.typedef_field_list linked list elements content into the
6320 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6321 if (fi
.typedef_field_list
)
6323 int i
= fi
.typedef_field_list_count
;
6325 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6326 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6327 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6328 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6330 /* Reverse the list order to keep the debug info elements order. */
6333 struct typedef_field
*dest
, *src
;
6335 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6336 src
= &fi
.typedef_field_list
->field
;
6337 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6343 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6345 do_cleanups (back_to
);
6350 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6352 struct die_info
*child_die
= die
->child
;
6353 struct type
*this_type
;
6355 this_type
= get_die_type (die
, cu
);
6356 if (this_type
== NULL
)
6357 this_type
= read_structure_type (die
, cu
);
6359 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6360 snapshots) has been known to create a die giving a declaration
6361 for a class that has, as a child, a die giving a definition for a
6362 nested class. So we have to process our children even if the
6363 current die is a declaration. Normally, of course, a declaration
6364 won't have any children at all. */
6366 while (child_die
!= NULL
&& child_die
->tag
)
6368 if (child_die
->tag
== DW_TAG_member
6369 || child_die
->tag
== DW_TAG_variable
6370 || child_die
->tag
== DW_TAG_inheritance
)
6375 process_die (child_die
, cu
);
6377 child_die
= sibling_die (child_die
);
6380 /* Do not consider external references. According to the DWARF standard,
6381 these DIEs are identified by the fact that they have no byte_size
6382 attribute, and a declaration attribute. */
6383 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6384 || !die_is_declaration (die
, cu
))
6385 new_symbol (die
, this_type
, cu
);
6388 /* Given a DW_AT_enumeration_type die, set its type. We do not
6389 complete the type's fields yet, or create any symbols. */
6391 static struct type
*
6392 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6394 struct objfile
*objfile
= cu
->objfile
;
6396 struct attribute
*attr
;
6399 /* If the definition of this type lives in .debug_types, read that type.
6400 Don't follow DW_AT_specification though, that will take us back up
6401 the chain and we want to go down. */
6402 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6405 struct dwarf2_cu
*type_cu
= cu
;
6406 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6408 type
= read_type_die (type_die
, type_cu
);
6409 return set_die_type (die
, type
, cu
);
6412 type
= alloc_type (objfile
);
6414 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
6415 name
= dwarf2_full_name (NULL
, die
, cu
);
6417 TYPE_TAG_NAME (type
) = (char *) name
;
6419 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6422 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6426 TYPE_LENGTH (type
) = 0;
6429 /* The enumeration DIE can be incomplete. In Ada, any type can be
6430 declared as private in the package spec, and then defined only
6431 inside the package body. Such types are known as Taft Amendment
6432 Types. When another package uses such a type, an incomplete DIE
6433 may be generated by the compiler. */
6434 if (die_is_declaration (die
, cu
))
6435 TYPE_STUB (type
) = 1;
6437 return set_die_type (die
, type
, cu
);
6440 /* Given a pointer to a die which begins an enumeration, process all
6441 the dies that define the members of the enumeration, and create the
6442 symbol for the enumeration type.
6444 NOTE: We reverse the order of the element list. */
6447 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6449 struct die_info
*child_die
;
6450 struct field
*fields
;
6453 int unsigned_enum
= 1;
6455 struct type
*this_type
;
6459 this_type
= get_die_type (die
, cu
);
6460 if (this_type
== NULL
)
6461 this_type
= read_enumeration_type (die
, cu
);
6462 if (die
->child
!= NULL
)
6464 child_die
= die
->child
;
6465 while (child_die
&& child_die
->tag
)
6467 if (child_die
->tag
!= DW_TAG_enumerator
)
6469 process_die (child_die
, cu
);
6473 name
= dwarf2_name (child_die
, cu
);
6476 sym
= new_symbol (child_die
, this_type
, cu
);
6477 if (SYMBOL_VALUE (sym
) < 0)
6480 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6482 fields
= (struct field
*)
6484 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
6485 * sizeof (struct field
));
6488 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
6489 FIELD_TYPE (fields
[num_fields
]) = NULL
;
6490 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
6491 FIELD_BITSIZE (fields
[num_fields
]) = 0;
6497 child_die
= sibling_die (child_die
);
6502 TYPE_NFIELDS (this_type
) = num_fields
;
6503 TYPE_FIELDS (this_type
) = (struct field
*)
6504 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
6505 memcpy (TYPE_FIELDS (this_type
), fields
,
6506 sizeof (struct field
) * num_fields
);
6510 TYPE_UNSIGNED (this_type
) = 1;
6513 new_symbol (die
, this_type
, cu
);
6516 /* Extract all information from a DW_TAG_array_type DIE and put it in
6517 the DIE's type field. For now, this only handles one dimensional
6520 static struct type
*
6521 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6523 struct objfile
*objfile
= cu
->objfile
;
6524 struct die_info
*child_die
;
6526 struct type
*element_type
, *range_type
, *index_type
;
6527 struct type
**range_types
= NULL
;
6528 struct attribute
*attr
;
6530 struct cleanup
*back_to
;
6533 element_type
= die_type (die
, cu
);
6535 /* The die_type call above may have already set the type for this DIE. */
6536 type
= get_die_type (die
, cu
);
6540 /* Irix 6.2 native cc creates array types without children for
6541 arrays with unspecified length. */
6542 if (die
->child
== NULL
)
6544 index_type
= objfile_type (objfile
)->builtin_int
;
6545 range_type
= create_range_type (NULL
, index_type
, 0, -1);
6546 type
= create_array_type (NULL
, element_type
, range_type
);
6547 return set_die_type (die
, type
, cu
);
6550 back_to
= make_cleanup (null_cleanup
, NULL
);
6551 child_die
= die
->child
;
6552 while (child_die
&& child_die
->tag
)
6554 if (child_die
->tag
== DW_TAG_subrange_type
)
6556 struct type
*child_type
= read_type_die (child_die
, cu
);
6558 if (child_type
!= NULL
)
6560 /* The range type was succesfully read. Save it for
6561 the array type creation. */
6562 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
6564 range_types
= (struct type
**)
6565 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
6566 * sizeof (struct type
*));
6568 make_cleanup (free_current_contents
, &range_types
);
6570 range_types
[ndim
++] = child_type
;
6573 child_die
= sibling_die (child_die
);
6576 /* Dwarf2 dimensions are output from left to right, create the
6577 necessary array types in backwards order. */
6579 type
= element_type
;
6581 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
6586 type
= create_array_type (NULL
, type
, range_types
[i
++]);
6591 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
6594 /* Understand Dwarf2 support for vector types (like they occur on
6595 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
6596 array type. This is not part of the Dwarf2/3 standard yet, but a
6597 custom vendor extension. The main difference between a regular
6598 array and the vector variant is that vectors are passed by value
6600 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
6602 make_vector_type (type
);
6604 name
= dwarf2_name (die
, cu
);
6606 TYPE_NAME (type
) = name
;
6608 /* Install the type in the die. */
6609 set_die_type (die
, type
, cu
);
6611 /* set_die_type should be already done. */
6612 set_descriptive_type (type
, die
, cu
);
6614 do_cleanups (back_to
);
6619 static enum dwarf_array_dim_ordering
6620 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
6622 struct attribute
*attr
;
6624 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
6626 if (attr
) return DW_SND (attr
);
6629 GNU F77 is a special case, as at 08/2004 array type info is the
6630 opposite order to the dwarf2 specification, but data is still
6631 laid out as per normal fortran.
6633 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
6637 if (cu
->language
== language_fortran
6638 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
6640 return DW_ORD_row_major
;
6643 switch (cu
->language_defn
->la_array_ordering
)
6645 case array_column_major
:
6646 return DW_ORD_col_major
;
6647 case array_row_major
:
6649 return DW_ORD_row_major
;
6653 /* Extract all information from a DW_TAG_set_type DIE and put it in
6654 the DIE's type field. */
6656 static struct type
*
6657 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6659 struct type
*domain_type
, *set_type
;
6660 struct attribute
*attr
;
6662 domain_type
= die_type (die
, cu
);
6664 /* The die_type call above may have already set the type for this DIE. */
6665 set_type
= get_die_type (die
, cu
);
6669 set_type
= create_set_type (NULL
, domain_type
);
6671 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6673 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
6675 return set_die_type (die
, set_type
, cu
);
6678 /* First cut: install each common block member as a global variable. */
6681 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
6683 struct die_info
*child_die
;
6684 struct attribute
*attr
;
6686 CORE_ADDR base
= (CORE_ADDR
) 0;
6688 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6691 /* Support the .debug_loc offsets */
6692 if (attr_form_is_block (attr
))
6694 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
6696 else if (attr_form_is_section_offset (attr
))
6698 dwarf2_complex_location_expr_complaint ();
6702 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6703 "common block member");
6706 if (die
->child
!= NULL
)
6708 child_die
= die
->child
;
6709 while (child_die
&& child_die
->tag
)
6711 sym
= new_symbol (child_die
, NULL
, cu
);
6712 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
6715 CORE_ADDR byte_offset
= 0;
6717 if (attr_form_is_section_offset (attr
))
6718 dwarf2_complex_location_expr_complaint ();
6719 else if (attr_form_is_constant (attr
))
6720 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6721 else if (attr_form_is_block (attr
))
6722 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6724 dwarf2_complex_location_expr_complaint ();
6726 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
6727 add_symbol_to_list (sym
, &global_symbols
);
6729 child_die
= sibling_die (child_die
);
6734 /* Create a type for a C++ namespace. */
6736 static struct type
*
6737 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6739 struct objfile
*objfile
= cu
->objfile
;
6740 const char *previous_prefix
, *name
;
6744 /* For extensions, reuse the type of the original namespace. */
6745 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
6747 struct die_info
*ext_die
;
6748 struct dwarf2_cu
*ext_cu
= cu
;
6750 ext_die
= dwarf2_extension (die
, &ext_cu
);
6751 type
= read_type_die (ext_die
, ext_cu
);
6752 return set_die_type (die
, type
, cu
);
6755 name
= namespace_name (die
, &is_anonymous
, cu
);
6757 /* Now build the name of the current namespace. */
6759 previous_prefix
= determine_prefix (die
, cu
);
6760 if (previous_prefix
[0] != '\0')
6761 name
= typename_concat (&objfile
->objfile_obstack
,
6762 previous_prefix
, name
, 0, cu
);
6764 /* Create the type. */
6765 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
6767 TYPE_NAME (type
) = (char *) name
;
6768 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6770 return set_die_type (die
, type
, cu
);
6773 /* Read a C++ namespace. */
6776 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6778 struct objfile
*objfile
= cu
->objfile
;
6782 /* Add a symbol associated to this if we haven't seen the namespace
6783 before. Also, add a using directive if it's an anonymous
6786 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
6790 type
= read_type_die (die
, cu
);
6791 new_symbol (die
, type
, cu
);
6793 name
= namespace_name (die
, &is_anonymous
, cu
);
6796 const char *previous_prefix
= determine_prefix (die
, cu
);
6798 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
6799 NULL
, &objfile
->objfile_obstack
);
6803 if (die
->child
!= NULL
)
6805 struct die_info
*child_die
= die
->child
;
6807 while (child_die
&& child_die
->tag
)
6809 process_die (child_die
, cu
);
6810 child_die
= sibling_die (child_die
);
6815 /* Read a Fortran module as type. This DIE can be only a declaration used for
6816 imported module. Still we need that type as local Fortran "use ... only"
6817 declaration imports depend on the created type in determine_prefix. */
6819 static struct type
*
6820 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6822 struct objfile
*objfile
= cu
->objfile
;
6826 module_name
= dwarf2_name (die
, cu
);
6828 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
6830 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
6832 /* determine_prefix uses TYPE_TAG_NAME. */
6833 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6835 return set_die_type (die
, type
, cu
);
6838 /* Read a Fortran module. */
6841 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
6843 struct die_info
*child_die
= die
->child
;
6845 while (child_die
&& child_die
->tag
)
6847 process_die (child_die
, cu
);
6848 child_die
= sibling_die (child_die
);
6852 /* Return the name of the namespace represented by DIE. Set
6853 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
6857 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
6859 struct die_info
*current_die
;
6860 const char *name
= NULL
;
6862 /* Loop through the extensions until we find a name. */
6864 for (current_die
= die
;
6865 current_die
!= NULL
;
6866 current_die
= dwarf2_extension (die
, &cu
))
6868 name
= dwarf2_name (current_die
, cu
);
6873 /* Is it an anonymous namespace? */
6875 *is_anonymous
= (name
== NULL
);
6877 name
= "(anonymous namespace)";
6882 /* Extract all information from a DW_TAG_pointer_type DIE and add to
6883 the user defined type vector. */
6885 static struct type
*
6886 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6888 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6889 struct comp_unit_head
*cu_header
= &cu
->header
;
6891 struct attribute
*attr_byte_size
;
6892 struct attribute
*attr_address_class
;
6893 int byte_size
, addr_class
;
6894 struct type
*target_type
;
6896 target_type
= die_type (die
, cu
);
6898 /* The die_type call above may have already set the type for this DIE. */
6899 type
= get_die_type (die
, cu
);
6903 type
= lookup_pointer_type (target_type
);
6905 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6907 byte_size
= DW_UNSND (attr_byte_size
);
6909 byte_size
= cu_header
->addr_size
;
6911 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
6912 if (attr_address_class
)
6913 addr_class
= DW_UNSND (attr_address_class
);
6915 addr_class
= DW_ADDR_none
;
6917 /* If the pointer size or address class is different than the
6918 default, create a type variant marked as such and set the
6919 length accordingly. */
6920 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
6922 if (gdbarch_address_class_type_flags_p (gdbarch
))
6926 type_flags
= gdbarch_address_class_type_flags
6927 (gdbarch
, byte_size
, addr_class
);
6928 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
6930 type
= make_type_with_address_space (type
, type_flags
);
6932 else if (TYPE_LENGTH (type
) != byte_size
)
6934 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
6938 /* Should we also complain about unhandled address classes? */
6942 TYPE_LENGTH (type
) = byte_size
;
6943 return set_die_type (die
, type
, cu
);
6946 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
6947 the user defined type vector. */
6949 static struct type
*
6950 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6953 struct type
*to_type
;
6954 struct type
*domain
;
6956 to_type
= die_type (die
, cu
);
6957 domain
= die_containing_type (die
, cu
);
6959 /* The calls above may have already set the type for this DIE. */
6960 type
= get_die_type (die
, cu
);
6964 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
6965 type
= lookup_methodptr_type (to_type
);
6967 type
= lookup_memberptr_type (to_type
, domain
);
6969 return set_die_type (die
, type
, cu
);
6972 /* Extract all information from a DW_TAG_reference_type DIE and add to
6973 the user defined type vector. */
6975 static struct type
*
6976 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6978 struct comp_unit_head
*cu_header
= &cu
->header
;
6979 struct type
*type
, *target_type
;
6980 struct attribute
*attr
;
6982 target_type
= die_type (die
, cu
);
6984 /* The die_type call above may have already set the type for this DIE. */
6985 type
= get_die_type (die
, cu
);
6989 type
= lookup_reference_type (target_type
);
6990 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6993 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6997 TYPE_LENGTH (type
) = cu_header
->addr_size
;
6999 return set_die_type (die
, type
, cu
);
7002 static struct type
*
7003 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7005 struct type
*base_type
, *cv_type
;
7007 base_type
= die_type (die
, cu
);
7009 /* The die_type call above may have already set the type for this DIE. */
7010 cv_type
= get_die_type (die
, cu
);
7014 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7015 return set_die_type (die
, cv_type
, cu
);
7018 static struct type
*
7019 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7021 struct type
*base_type
, *cv_type
;
7023 base_type
= die_type (die
, cu
);
7025 /* The die_type call above may have already set the type for this DIE. */
7026 cv_type
= get_die_type (die
, cu
);
7030 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7031 return set_die_type (die
, cv_type
, cu
);
7034 /* Extract all information from a DW_TAG_string_type DIE and add to
7035 the user defined type vector. It isn't really a user defined type,
7036 but it behaves like one, with other DIE's using an AT_user_def_type
7037 attribute to reference it. */
7039 static struct type
*
7040 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7042 struct objfile
*objfile
= cu
->objfile
;
7043 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7044 struct type
*type
, *range_type
, *index_type
, *char_type
;
7045 struct attribute
*attr
;
7046 unsigned int length
;
7048 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7051 length
= DW_UNSND (attr
);
7055 /* check for the DW_AT_byte_size attribute */
7056 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7059 length
= DW_UNSND (attr
);
7067 index_type
= objfile_type (objfile
)->builtin_int
;
7068 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7069 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7070 type
= create_string_type (NULL
, char_type
, range_type
);
7072 return set_die_type (die
, type
, cu
);
7075 /* Handle DIES due to C code like:
7079 int (*funcp)(int a, long l);
7083 ('funcp' generates a DW_TAG_subroutine_type DIE)
7086 static struct type
*
7087 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7089 struct type
*type
; /* Type that this function returns */
7090 struct type
*ftype
; /* Function that returns above type */
7091 struct attribute
*attr
;
7093 type
= die_type (die
, cu
);
7095 /* The die_type call above may have already set the type for this DIE. */
7096 ftype
= get_die_type (die
, cu
);
7100 ftype
= lookup_function_type (type
);
7102 /* All functions in C++, Pascal and Java have prototypes. */
7103 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7104 if ((attr
&& (DW_UNSND (attr
) != 0))
7105 || cu
->language
== language_cplus
7106 || cu
->language
== language_java
7107 || cu
->language
== language_pascal
)
7108 TYPE_PROTOTYPED (ftype
) = 1;
7109 else if (producer_is_realview (cu
->producer
))
7110 /* RealView does not emit DW_AT_prototyped. We can not
7111 distinguish prototyped and unprototyped functions; default to
7112 prototyped, since that is more common in modern code (and
7113 RealView warns about unprototyped functions). */
7114 TYPE_PROTOTYPED (ftype
) = 1;
7116 /* Store the calling convention in the type if it's available in
7117 the subroutine die. Otherwise set the calling convention to
7118 the default value DW_CC_normal. */
7119 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7120 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7122 /* We need to add the subroutine type to the die immediately so
7123 we don't infinitely recurse when dealing with parameters
7124 declared as the same subroutine type. */
7125 set_die_type (die
, ftype
, cu
);
7127 if (die
->child
!= NULL
)
7129 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7130 struct die_info
*child_die
;
7131 int nparams
, iparams
;
7133 /* Count the number of parameters.
7134 FIXME: GDB currently ignores vararg functions, but knows about
7135 vararg member functions. */
7137 child_die
= die
->child
;
7138 while (child_die
&& child_die
->tag
)
7140 if (child_die
->tag
== DW_TAG_formal_parameter
)
7142 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7143 TYPE_VARARGS (ftype
) = 1;
7144 child_die
= sibling_die (child_die
);
7147 /* Allocate storage for parameters and fill them in. */
7148 TYPE_NFIELDS (ftype
) = nparams
;
7149 TYPE_FIELDS (ftype
) = (struct field
*)
7150 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7152 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7153 even if we error out during the parameters reading below. */
7154 for (iparams
= 0; iparams
< nparams
; iparams
++)
7155 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7158 child_die
= die
->child
;
7159 while (child_die
&& child_die
->tag
)
7161 if (child_die
->tag
== DW_TAG_formal_parameter
)
7163 /* Dwarf2 has no clean way to discern C++ static and non-static
7164 member functions. G++ helps GDB by marking the first
7165 parameter for non-static member functions (which is the
7166 this pointer) as artificial. We pass this information
7167 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
7168 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7170 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7173 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7175 /* GCC/43521: In java, the formal parameter
7176 "this" is sometimes not marked with DW_AT_artificial. */
7177 if (cu
->language
== language_java
)
7179 const char *name
= dwarf2_name (child_die
, cu
);
7181 if (name
&& !strcmp (name
, "this"))
7182 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7185 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
7188 child_die
= sibling_die (child_die
);
7195 static struct type
*
7196 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7198 struct objfile
*objfile
= cu
->objfile
;
7199 const char *name
= NULL
;
7200 struct type
*this_type
;
7202 name
= dwarf2_full_name (NULL
, die
, cu
);
7203 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7204 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7205 TYPE_NAME (this_type
) = (char *) name
;
7206 set_die_type (die
, this_type
, cu
);
7207 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7211 /* Find a representation of a given base type and install
7212 it in the TYPE field of the die. */
7214 static struct type
*
7215 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7217 struct objfile
*objfile
= cu
->objfile
;
7219 struct attribute
*attr
;
7220 int encoding
= 0, size
= 0;
7222 enum type_code code
= TYPE_CODE_INT
;
7224 struct type
*target_type
= NULL
;
7226 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7229 encoding
= DW_UNSND (attr
);
7231 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7234 size
= DW_UNSND (attr
);
7236 name
= dwarf2_name (die
, cu
);
7239 complaint (&symfile_complaints
,
7240 _("DW_AT_name missing from DW_TAG_base_type"));
7245 case DW_ATE_address
:
7246 /* Turn DW_ATE_address into a void * pointer. */
7247 code
= TYPE_CODE_PTR
;
7248 type_flags
|= TYPE_FLAG_UNSIGNED
;
7249 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7251 case DW_ATE_boolean
:
7252 code
= TYPE_CODE_BOOL
;
7253 type_flags
|= TYPE_FLAG_UNSIGNED
;
7255 case DW_ATE_complex_float
:
7256 code
= TYPE_CODE_COMPLEX
;
7257 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7259 case DW_ATE_decimal_float
:
7260 code
= TYPE_CODE_DECFLOAT
;
7263 code
= TYPE_CODE_FLT
;
7267 case DW_ATE_unsigned
:
7268 type_flags
|= TYPE_FLAG_UNSIGNED
;
7270 case DW_ATE_signed_char
:
7271 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7272 || cu
->language
== language_pascal
)
7273 code
= TYPE_CODE_CHAR
;
7275 case DW_ATE_unsigned_char
:
7276 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7277 || cu
->language
== language_pascal
)
7278 code
= TYPE_CODE_CHAR
;
7279 type_flags
|= TYPE_FLAG_UNSIGNED
;
7282 /* We just treat this as an integer and then recognize the
7283 type by name elsewhere. */
7287 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7288 dwarf_type_encoding_name (encoding
));
7292 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7293 TYPE_NAME (type
) = name
;
7294 TYPE_TARGET_TYPE (type
) = target_type
;
7296 if (name
&& strcmp (name
, "char") == 0)
7297 TYPE_NOSIGN (type
) = 1;
7299 return set_die_type (die
, type
, cu
);
7302 /* Read the given DW_AT_subrange DIE. */
7304 static struct type
*
7305 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7307 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7308 struct type
*base_type
;
7309 struct type
*range_type
;
7310 struct attribute
*attr
;
7314 LONGEST negative_mask
;
7316 base_type
= die_type (die
, cu
);
7317 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7318 check_typedef (base_type
);
7320 /* The die_type call above may have already set the type for this DIE. */
7321 range_type
= get_die_type (die
, cu
);
7325 if (cu
->language
== language_fortran
)
7327 /* FORTRAN implies a lower bound of 1, if not given. */
7331 /* FIXME: For variable sized arrays either of these could be
7332 a variable rather than a constant value. We'll allow it,
7333 but we don't know how to handle it. */
7334 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
7336 low
= dwarf2_get_attr_constant_value (attr
, 0);
7338 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
7341 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
7343 /* GCC encodes arrays with unspecified or dynamic length
7344 with a DW_FORM_block1 attribute or a reference attribute.
7345 FIXME: GDB does not yet know how to handle dynamic
7346 arrays properly, treat them as arrays with unspecified
7349 FIXME: jimb/2003-09-22: GDB does not really know
7350 how to handle arrays of unspecified length
7351 either; we just represent them as zero-length
7352 arrays. Choose an appropriate upper bound given
7353 the lower bound we've computed above. */
7357 high
= dwarf2_get_attr_constant_value (attr
, 1);
7361 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
7364 int count
= dwarf2_get_attr_constant_value (attr
, 1);
7365 high
= low
+ count
- 1;
7369 /* Dwarf-2 specifications explicitly allows to create subrange types
7370 without specifying a base type.
7371 In that case, the base type must be set to the type of
7372 the lower bound, upper bound or count, in that order, if any of these
7373 three attributes references an object that has a type.
7374 If no base type is found, the Dwarf-2 specifications say that
7375 a signed integer type of size equal to the size of an address should
7377 For the following C code: `extern char gdb_int [];'
7378 GCC produces an empty range DIE.
7379 FIXME: muller/2010-05-28: Possible references to object for low bound,
7380 high bound or count are not yet handled by this code.
7382 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
7384 struct objfile
*objfile
= cu
->objfile
;
7385 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7386 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
7387 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
7389 /* Test "int", "long int", and "long long int" objfile types,
7390 and select the first one having a size above or equal to the
7391 architecture address size. */
7392 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7393 base_type
= int_type
;
7396 int_type
= objfile_type (objfile
)->builtin_long
;
7397 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7398 base_type
= int_type
;
7401 int_type
= objfile_type (objfile
)->builtin_long_long
;
7402 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7403 base_type
= int_type
;
7409 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
7410 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
7411 low
|= negative_mask
;
7412 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
7413 high
|= negative_mask
;
7415 range_type
= create_range_type (NULL
, base_type
, low
, high
);
7417 /* Mark arrays with dynamic length at least as an array of unspecified
7418 length. GDB could check the boundary but before it gets implemented at
7419 least allow accessing the array elements. */
7420 if (attr
&& attr
->form
== DW_FORM_block1
)
7421 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
7423 name
= dwarf2_name (die
, cu
);
7425 TYPE_NAME (range_type
) = name
;
7427 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7429 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
7431 set_die_type (die
, range_type
, cu
);
7433 /* set_die_type should be already done. */
7434 set_descriptive_type (range_type
, die
, cu
);
7439 static struct type
*
7440 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7444 /* For now, we only support the C meaning of an unspecified type: void. */
7446 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
7447 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
7449 return set_die_type (die
, type
, cu
);
7452 /* Trivial hash function for die_info: the hash value of a DIE
7453 is its offset in .debug_info for this objfile. */
7456 die_hash (const void *item
)
7458 const struct die_info
*die
= item
;
7463 /* Trivial comparison function for die_info structures: two DIEs
7464 are equal if they have the same offset. */
7467 die_eq (const void *item_lhs
, const void *item_rhs
)
7469 const struct die_info
*die_lhs
= item_lhs
;
7470 const struct die_info
*die_rhs
= item_rhs
;
7472 return die_lhs
->offset
== die_rhs
->offset
;
7475 /* Read a whole compilation unit into a linked list of dies. */
7477 static struct die_info
*
7478 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7480 struct die_reader_specs reader_specs
;
7482 gdb_assert (cu
->die_hash
== NULL
);
7484 = htab_create_alloc_ex (cu
->header
.length
/ 12,
7488 &cu
->comp_unit_obstack
,
7489 hashtab_obstack_allocate
,
7490 dummy_obstack_deallocate
);
7492 init_cu_die_reader (&reader_specs
, cu
);
7494 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
7497 /* Main entry point for reading a DIE and all children.
7498 Read the DIE and dump it if requested. */
7500 static struct die_info
*
7501 read_die_and_children (const struct die_reader_specs
*reader
,
7503 gdb_byte
**new_info_ptr
,
7504 struct die_info
*parent
)
7506 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
7507 new_info_ptr
, parent
);
7509 if (dwarf2_die_debug
)
7511 fprintf_unfiltered (gdb_stdlog
,
7512 "\nRead die from %s of %s:\n",
7513 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
7515 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
7517 : "unknown section",
7518 reader
->abfd
->filename
);
7519 dump_die (result
, dwarf2_die_debug
);
7525 /* Read a single die and all its descendents. Set the die's sibling
7526 field to NULL; set other fields in the die correctly, and set all
7527 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
7528 location of the info_ptr after reading all of those dies. PARENT
7529 is the parent of the die in question. */
7531 static struct die_info
*
7532 read_die_and_children_1 (const struct die_reader_specs
*reader
,
7534 gdb_byte
**new_info_ptr
,
7535 struct die_info
*parent
)
7537 struct die_info
*die
;
7541 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
7544 *new_info_ptr
= cur_ptr
;
7547 store_in_ref_table (die
, reader
->cu
);
7550 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
7554 *new_info_ptr
= cur_ptr
;
7557 die
->sibling
= NULL
;
7558 die
->parent
= parent
;
7562 /* Read a die, all of its descendents, and all of its siblings; set
7563 all of the fields of all of the dies correctly. Arguments are as
7564 in read_die_and_children. */
7566 static struct die_info
*
7567 read_die_and_siblings (const struct die_reader_specs
*reader
,
7569 gdb_byte
**new_info_ptr
,
7570 struct die_info
*parent
)
7572 struct die_info
*first_die
, *last_sibling
;
7576 first_die
= last_sibling
= NULL
;
7580 struct die_info
*die
7581 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
7585 *new_info_ptr
= cur_ptr
;
7592 last_sibling
->sibling
= die
;
7598 /* Read the die from the .debug_info section buffer. Set DIEP to
7599 point to a newly allocated die with its information, except for its
7600 child, sibling, and parent fields. Set HAS_CHILDREN to tell
7601 whether the die has children or not. */
7604 read_full_die (const struct die_reader_specs
*reader
,
7605 struct die_info
**diep
, gdb_byte
*info_ptr
,
7608 unsigned int abbrev_number
, bytes_read
, i
, offset
;
7609 struct abbrev_info
*abbrev
;
7610 struct die_info
*die
;
7611 struct dwarf2_cu
*cu
= reader
->cu
;
7612 bfd
*abfd
= reader
->abfd
;
7614 offset
= info_ptr
- reader
->buffer
;
7615 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7616 info_ptr
+= bytes_read
;
7624 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
7626 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
7628 bfd_get_filename (abfd
));
7630 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
7631 die
->offset
= offset
;
7632 die
->tag
= abbrev
->tag
;
7633 die
->abbrev
= abbrev_number
;
7635 die
->num_attrs
= abbrev
->num_attrs
;
7637 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
7638 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
7639 abfd
, info_ptr
, cu
);
7642 *has_children
= abbrev
->has_children
;
7646 /* In DWARF version 2, the description of the debugging information is
7647 stored in a separate .debug_abbrev section. Before we read any
7648 dies from a section we read in all abbreviations and install them
7649 in a hash table. This function also sets flags in CU describing
7650 the data found in the abbrev table. */
7653 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
7655 struct comp_unit_head
*cu_header
= &cu
->header
;
7656 gdb_byte
*abbrev_ptr
;
7657 struct abbrev_info
*cur_abbrev
;
7658 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
7659 unsigned int abbrev_form
, hash_number
;
7660 struct attr_abbrev
*cur_attrs
;
7661 unsigned int allocated_attrs
;
7663 /* Initialize dwarf2 abbrevs */
7664 obstack_init (&cu
->abbrev_obstack
);
7665 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
7667 * sizeof (struct abbrev_info
*)));
7668 memset (cu
->dwarf2_abbrevs
, 0,
7669 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
7671 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
7672 &dwarf2_per_objfile
->abbrev
);
7673 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
7674 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7675 abbrev_ptr
+= bytes_read
;
7677 allocated_attrs
= ATTR_ALLOC_CHUNK
;
7678 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
7680 /* loop until we reach an abbrev number of 0 */
7681 while (abbrev_number
)
7683 cur_abbrev
= dwarf_alloc_abbrev (cu
);
7685 /* read in abbrev header */
7686 cur_abbrev
->number
= abbrev_number
;
7687 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7688 abbrev_ptr
+= bytes_read
;
7689 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
7692 if (cur_abbrev
->tag
== DW_TAG_namespace
)
7693 cu
->has_namespace_info
= 1;
7695 /* now read in declarations */
7696 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7697 abbrev_ptr
+= bytes_read
;
7698 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7699 abbrev_ptr
+= bytes_read
;
7702 if (cur_abbrev
->num_attrs
== allocated_attrs
)
7704 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
7706 = xrealloc (cur_attrs
, (allocated_attrs
7707 * sizeof (struct attr_abbrev
)));
7710 /* Record whether this compilation unit might have
7711 inter-compilation-unit references. If we don't know what form
7712 this attribute will have, then it might potentially be a
7713 DW_FORM_ref_addr, so we conservatively expect inter-CU
7716 if (abbrev_form
== DW_FORM_ref_addr
7717 || abbrev_form
== DW_FORM_indirect
)
7718 cu
->has_form_ref_addr
= 1;
7720 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
7721 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
7722 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7723 abbrev_ptr
+= bytes_read
;
7724 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7725 abbrev_ptr
+= bytes_read
;
7728 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
7729 (cur_abbrev
->num_attrs
7730 * sizeof (struct attr_abbrev
)));
7731 memcpy (cur_abbrev
->attrs
, cur_attrs
,
7732 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
7734 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
7735 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
7736 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
7738 /* Get next abbreviation.
7739 Under Irix6 the abbreviations for a compilation unit are not
7740 always properly terminated with an abbrev number of 0.
7741 Exit loop if we encounter an abbreviation which we have
7742 already read (which means we are about to read the abbreviations
7743 for the next compile unit) or if the end of the abbreviation
7744 table is reached. */
7745 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
7746 >= dwarf2_per_objfile
->abbrev
.size
)
7748 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7749 abbrev_ptr
+= bytes_read
;
7750 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
7757 /* Release the memory used by the abbrev table for a compilation unit. */
7760 dwarf2_free_abbrev_table (void *ptr_to_cu
)
7762 struct dwarf2_cu
*cu
= ptr_to_cu
;
7764 obstack_free (&cu
->abbrev_obstack
, NULL
);
7765 cu
->dwarf2_abbrevs
= NULL
;
7768 /* Lookup an abbrev_info structure in the abbrev hash table. */
7770 static struct abbrev_info
*
7771 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
7773 unsigned int hash_number
;
7774 struct abbrev_info
*abbrev
;
7776 hash_number
= number
% ABBREV_HASH_SIZE
;
7777 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
7781 if (abbrev
->number
== number
)
7784 abbrev
= abbrev
->next
;
7789 /* Returns nonzero if TAG represents a type that we might generate a partial
7793 is_type_tag_for_partial (int tag
)
7798 /* Some types that would be reasonable to generate partial symbols for,
7799 that we don't at present. */
7800 case DW_TAG_array_type
:
7801 case DW_TAG_file_type
:
7802 case DW_TAG_ptr_to_member_type
:
7803 case DW_TAG_set_type
:
7804 case DW_TAG_string_type
:
7805 case DW_TAG_subroutine_type
:
7807 case DW_TAG_base_type
:
7808 case DW_TAG_class_type
:
7809 case DW_TAG_interface_type
:
7810 case DW_TAG_enumeration_type
:
7811 case DW_TAG_structure_type
:
7812 case DW_TAG_subrange_type
:
7813 case DW_TAG_typedef
:
7814 case DW_TAG_union_type
:
7821 /* Load all DIEs that are interesting for partial symbols into memory. */
7823 static struct partial_die_info
*
7824 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
7825 int building_psymtab
, struct dwarf2_cu
*cu
)
7827 struct partial_die_info
*part_die
;
7828 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
7829 struct abbrev_info
*abbrev
;
7830 unsigned int bytes_read
;
7831 unsigned int load_all
= 0;
7833 int nesting_level
= 1;
7838 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
7842 = htab_create_alloc_ex (cu
->header
.length
/ 12,
7846 &cu
->comp_unit_obstack
,
7847 hashtab_obstack_allocate
,
7848 dummy_obstack_deallocate
);
7850 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
7851 sizeof (struct partial_die_info
));
7855 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7857 /* A NULL abbrev means the end of a series of children. */
7860 if (--nesting_level
== 0)
7862 /* PART_DIE was probably the last thing allocated on the
7863 comp_unit_obstack, so we could call obstack_free
7864 here. We don't do that because the waste is small,
7865 and will be cleaned up when we're done with this
7866 compilation unit. This way, we're also more robust
7867 against other users of the comp_unit_obstack. */
7870 info_ptr
+= bytes_read
;
7871 last_die
= parent_die
;
7872 parent_die
= parent_die
->die_parent
;
7876 /* Check whether this DIE is interesting enough to save. Normally
7877 we would not be interested in members here, but there may be
7878 later variables referencing them via DW_AT_specification (for
7881 && !is_type_tag_for_partial (abbrev
->tag
)
7882 && abbrev
->tag
!= DW_TAG_enumerator
7883 && abbrev
->tag
!= DW_TAG_subprogram
7884 && abbrev
->tag
!= DW_TAG_lexical_block
7885 && abbrev
->tag
!= DW_TAG_variable
7886 && abbrev
->tag
!= DW_TAG_namespace
7887 && abbrev
->tag
!= DW_TAG_module
7888 && abbrev
->tag
!= DW_TAG_member
)
7890 /* Otherwise we skip to the next sibling, if any. */
7891 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
7895 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
7896 buffer
, info_ptr
, cu
);
7898 /* This two-pass algorithm for processing partial symbols has a
7899 high cost in cache pressure. Thus, handle some simple cases
7900 here which cover the majority of C partial symbols. DIEs
7901 which neither have specification tags in them, nor could have
7902 specification tags elsewhere pointing at them, can simply be
7903 processed and discarded.
7905 This segment is also optional; scan_partial_symbols and
7906 add_partial_symbol will handle these DIEs if we chain
7907 them in normally. When compilers which do not emit large
7908 quantities of duplicate debug information are more common,
7909 this code can probably be removed. */
7911 /* Any complete simple types at the top level (pretty much all
7912 of them, for a language without namespaces), can be processed
7914 if (parent_die
== NULL
7915 && part_die
->has_specification
== 0
7916 && part_die
->is_declaration
== 0
7917 && (part_die
->tag
== DW_TAG_typedef
7918 || part_die
->tag
== DW_TAG_base_type
7919 || part_die
->tag
== DW_TAG_subrange_type
))
7921 if (building_psymtab
&& part_die
->name
!= NULL
)
7922 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
7923 VAR_DOMAIN
, LOC_TYPEDEF
,
7924 &cu
->objfile
->static_psymbols
,
7925 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
7926 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
7930 /* If we're at the second level, and we're an enumerator, and
7931 our parent has no specification (meaning possibly lives in a
7932 namespace elsewhere), then we can add the partial symbol now
7933 instead of queueing it. */
7934 if (part_die
->tag
== DW_TAG_enumerator
7935 && parent_die
!= NULL
7936 && parent_die
->die_parent
== NULL
7937 && parent_die
->tag
== DW_TAG_enumeration_type
7938 && parent_die
->has_specification
== 0)
7940 if (part_die
->name
== NULL
)
7941 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7942 else if (building_psymtab
)
7943 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
7944 VAR_DOMAIN
, LOC_CONST
,
7945 (cu
->language
== language_cplus
7946 || cu
->language
== language_java
)
7947 ? &cu
->objfile
->global_psymbols
7948 : &cu
->objfile
->static_psymbols
,
7949 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
7951 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
7955 /* We'll save this DIE so link it in. */
7956 part_die
->die_parent
= parent_die
;
7957 part_die
->die_sibling
= NULL
;
7958 part_die
->die_child
= NULL
;
7960 if (last_die
&& last_die
== parent_die
)
7961 last_die
->die_child
= part_die
;
7963 last_die
->die_sibling
= part_die
;
7965 last_die
= part_die
;
7967 if (first_die
== NULL
)
7968 first_die
= part_die
;
7970 /* Maybe add the DIE to the hash table. Not all DIEs that we
7971 find interesting need to be in the hash table, because we
7972 also have the parent/sibling/child chains; only those that we
7973 might refer to by offset later during partial symbol reading.
7975 For now this means things that might have be the target of a
7976 DW_AT_specification, DW_AT_abstract_origin, or
7977 DW_AT_extension. DW_AT_extension will refer only to
7978 namespaces; DW_AT_abstract_origin refers to functions (and
7979 many things under the function DIE, but we do not recurse
7980 into function DIEs during partial symbol reading) and
7981 possibly variables as well; DW_AT_specification refers to
7982 declarations. Declarations ought to have the DW_AT_declaration
7983 flag. It happens that GCC forgets to put it in sometimes, but
7984 only for functions, not for types.
7986 Adding more things than necessary to the hash table is harmless
7987 except for the performance cost. Adding too few will result in
7988 wasted time in find_partial_die, when we reread the compilation
7989 unit with load_all_dies set. */
7992 || abbrev
->tag
== DW_TAG_subprogram
7993 || abbrev
->tag
== DW_TAG_variable
7994 || abbrev
->tag
== DW_TAG_namespace
7995 || part_die
->is_declaration
)
7999 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8000 part_die
->offset
, INSERT
);
8004 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8005 sizeof (struct partial_die_info
));
8007 /* For some DIEs we want to follow their children (if any). For C
8008 we have no reason to follow the children of structures; for other
8009 languages we have to, both so that we can get at method physnames
8010 to infer fully qualified class names, and for DW_AT_specification.
8012 For Ada, we need to scan the children of subprograms and lexical
8013 blocks as well because Ada allows the definition of nested
8014 entities that could be interesting for the debugger, such as
8015 nested subprograms for instance. */
8016 if (last_die
->has_children
8018 || last_die
->tag
== DW_TAG_namespace
8019 || last_die
->tag
== DW_TAG_module
8020 || last_die
->tag
== DW_TAG_enumeration_type
8021 || (cu
->language
!= language_c
8022 && (last_die
->tag
== DW_TAG_class_type
8023 || last_die
->tag
== DW_TAG_interface_type
8024 || last_die
->tag
== DW_TAG_structure_type
8025 || last_die
->tag
== DW_TAG_union_type
))
8026 || (cu
->language
== language_ada
8027 && (last_die
->tag
== DW_TAG_subprogram
8028 || last_die
->tag
== DW_TAG_lexical_block
))))
8031 parent_die
= last_die
;
8035 /* Otherwise we skip to the next sibling, if any. */
8036 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8038 /* Back to the top, do it again. */
8042 /* Read a minimal amount of information into the minimal die structure. */
8045 read_partial_die (struct partial_die_info
*part_die
,
8046 struct abbrev_info
*abbrev
,
8047 unsigned int abbrev_len
, bfd
*abfd
,
8048 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8049 struct dwarf2_cu
*cu
)
8052 struct attribute attr
;
8053 int has_low_pc_attr
= 0;
8054 int has_high_pc_attr
= 0;
8056 memset (part_die
, 0, sizeof (struct partial_die_info
));
8058 part_die
->offset
= info_ptr
- buffer
;
8060 info_ptr
+= abbrev_len
;
8065 part_die
->tag
= abbrev
->tag
;
8066 part_die
->has_children
= abbrev
->has_children
;
8068 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8070 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8072 /* Store the data if it is of an attribute we want to keep in a
8073 partial symbol table. */
8077 switch (part_die
->tag
)
8079 case DW_TAG_compile_unit
:
8080 case DW_TAG_type_unit
:
8081 /* Compilation units have a DW_AT_name that is a filename, not
8082 a source language identifier. */
8083 case DW_TAG_enumeration_type
:
8084 case DW_TAG_enumerator
:
8085 /* These tags always have simple identifiers already; no need
8086 to canonicalize them. */
8087 part_die
->name
= DW_STRING (&attr
);
8091 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8092 &cu
->objfile
->objfile_obstack
);
8096 case DW_AT_linkage_name
:
8097 case DW_AT_MIPS_linkage_name
:
8098 /* Note that both forms of linkage name might appear. We
8099 assume they will be the same, and we only store the last
8101 if (cu
->language
== language_ada
)
8102 part_die
->name
= DW_STRING (&attr
);
8105 has_low_pc_attr
= 1;
8106 part_die
->lowpc
= DW_ADDR (&attr
);
8109 has_high_pc_attr
= 1;
8110 part_die
->highpc
= DW_ADDR (&attr
);
8112 case DW_AT_location
:
8113 /* Support the .debug_loc offsets */
8114 if (attr_form_is_block (&attr
))
8116 part_die
->locdesc
= DW_BLOCK (&attr
);
8118 else if (attr_form_is_section_offset (&attr
))
8120 dwarf2_complex_location_expr_complaint ();
8124 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8125 "partial symbol information");
8128 case DW_AT_external
:
8129 part_die
->is_external
= DW_UNSND (&attr
);
8131 case DW_AT_declaration
:
8132 part_die
->is_declaration
= DW_UNSND (&attr
);
8135 part_die
->has_type
= 1;
8137 case DW_AT_abstract_origin
:
8138 case DW_AT_specification
:
8139 case DW_AT_extension
:
8140 part_die
->has_specification
= 1;
8141 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8144 /* Ignore absolute siblings, they might point outside of
8145 the current compile unit. */
8146 if (attr
.form
== DW_FORM_ref_addr
)
8147 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8149 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8151 case DW_AT_byte_size
:
8152 part_die
->has_byte_size
= 1;
8154 case DW_AT_calling_convention
:
8155 /* DWARF doesn't provide a way to identify a program's source-level
8156 entry point. DW_AT_calling_convention attributes are only meant
8157 to describe functions' calling conventions.
8159 However, because it's a necessary piece of information in
8160 Fortran, and because DW_CC_program is the only piece of debugging
8161 information whose definition refers to a 'main program' at all,
8162 several compilers have begun marking Fortran main programs with
8163 DW_CC_program --- even when those functions use the standard
8164 calling conventions.
8166 So until DWARF specifies a way to provide this information and
8167 compilers pick up the new representation, we'll support this
8169 if (DW_UNSND (&attr
) == DW_CC_program
8170 && cu
->language
== language_fortran
)
8171 set_main_name (part_die
->name
);
8178 /* When using the GNU linker, .gnu.linkonce. sections are used to
8179 eliminate duplicate copies of functions and vtables and such.
8180 The linker will arbitrarily choose one and discard the others.
8181 The AT_*_pc values for such functions refer to local labels in
8182 these sections. If the section from that file was discarded, the
8183 labels are not in the output, so the relocs get a value of 0.
8184 If this is a discarded function, mark the pc bounds as invalid,
8185 so that GDB will ignore it. */
8186 if (has_low_pc_attr
&& has_high_pc_attr
8187 && part_die
->lowpc
< part_die
->highpc
8188 && (part_die
->lowpc
!= 0
8189 || dwarf2_per_objfile
->has_section_at_zero
))
8190 part_die
->has_pc_info
= 1;
8195 /* Find a cached partial DIE at OFFSET in CU. */
8197 static struct partial_die_info
*
8198 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8200 struct partial_die_info
*lookup_die
= NULL
;
8201 struct partial_die_info part_die
;
8203 part_die
.offset
= offset
;
8204 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8209 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8210 except in the case of .debug_types DIEs which do not reference
8211 outside their CU (they do however referencing other types via
8214 static struct partial_die_info
*
8215 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8217 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8218 struct partial_die_info
*pd
= NULL
;
8220 if (cu
->per_cu
->from_debug_types
)
8222 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8228 if (offset_in_cu_p (&cu
->header
, offset
))
8230 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8235 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8237 if (per_cu
->cu
== NULL
)
8239 load_partial_comp_unit (per_cu
, cu
->objfile
);
8240 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
8241 dwarf2_per_objfile
->read_in_chain
= per_cu
;
8244 per_cu
->cu
->last_used
= 0;
8245 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8247 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8249 struct cleanup
*back_to
;
8250 struct partial_die_info comp_unit_die
;
8251 struct abbrev_info
*abbrev
;
8252 unsigned int bytes_read
;
8255 per_cu
->load_all_dies
= 1;
8257 /* Re-read the DIEs. */
8258 back_to
= make_cleanup (null_cleanup
, 0);
8259 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8261 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8262 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8264 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8265 + per_cu
->cu
->header
.offset
8266 + per_cu
->cu
->header
.first_die_offset
);
8267 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8268 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8269 per_cu
->cu
->objfile
->obfd
,
8270 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8272 if (comp_unit_die
.has_children
)
8273 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8274 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8276 do_cleanups (back_to
);
8278 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8284 internal_error (__FILE__
, __LINE__
,
8285 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8286 offset
, bfd_get_filename (cu
->objfile
->obfd
));
8290 /* Adjust PART_DIE before generating a symbol for it. This function
8291 may set the is_external flag or change the DIE's name. */
8294 fixup_partial_die (struct partial_die_info
*part_die
,
8295 struct dwarf2_cu
*cu
)
8297 /* If we found a reference attribute and the DIE has no name, try
8298 to find a name in the referred to DIE. */
8300 if (part_die
->name
== NULL
&& part_die
->has_specification
)
8302 struct partial_die_info
*spec_die
;
8304 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
8306 fixup_partial_die (spec_die
, cu
);
8310 part_die
->name
= spec_die
->name
;
8312 /* Copy DW_AT_external attribute if it is set. */
8313 if (spec_die
->is_external
)
8314 part_die
->is_external
= spec_die
->is_external
;
8318 /* Set default names for some unnamed DIEs. */
8319 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
8320 || part_die
->tag
== DW_TAG_class_type
))
8321 part_die
->name
= "(anonymous class)";
8323 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
8324 part_die
->name
= "(anonymous namespace)";
8326 if (part_die
->tag
== DW_TAG_structure_type
8327 || part_die
->tag
== DW_TAG_class_type
8328 || part_die
->tag
== DW_TAG_union_type
)
8329 guess_structure_name (part_die
, cu
);
8332 /* Read an attribute value described by an attribute form. */
8335 read_attribute_value (struct attribute
*attr
, unsigned form
,
8336 bfd
*abfd
, gdb_byte
*info_ptr
,
8337 struct dwarf2_cu
*cu
)
8339 struct comp_unit_head
*cu_header
= &cu
->header
;
8340 unsigned int bytes_read
;
8341 struct dwarf_block
*blk
;
8346 case DW_FORM_ref_addr
:
8347 if (cu
->header
.version
== 2)
8348 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8350 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
8351 info_ptr
+= bytes_read
;
8354 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8355 info_ptr
+= bytes_read
;
8357 case DW_FORM_block2
:
8358 blk
= dwarf_alloc_block (cu
);
8359 blk
->size
= read_2_bytes (abfd
, info_ptr
);
8361 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8362 info_ptr
+= blk
->size
;
8363 DW_BLOCK (attr
) = blk
;
8365 case DW_FORM_block4
:
8366 blk
= dwarf_alloc_block (cu
);
8367 blk
->size
= read_4_bytes (abfd
, info_ptr
);
8369 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8370 info_ptr
+= blk
->size
;
8371 DW_BLOCK (attr
) = blk
;
8374 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
8378 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
8382 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
8385 case DW_FORM_sec_offset
:
8386 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
8387 info_ptr
+= bytes_read
;
8389 case DW_FORM_string
:
8390 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
8391 DW_STRING_IS_CANONICAL (attr
) = 0;
8392 info_ptr
+= bytes_read
;
8395 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
8397 DW_STRING_IS_CANONICAL (attr
) = 0;
8398 info_ptr
+= bytes_read
;
8400 case DW_FORM_exprloc
:
8402 blk
= dwarf_alloc_block (cu
);
8403 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8404 info_ptr
+= bytes_read
;
8405 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8406 info_ptr
+= blk
->size
;
8407 DW_BLOCK (attr
) = blk
;
8409 case DW_FORM_block1
:
8410 blk
= dwarf_alloc_block (cu
);
8411 blk
->size
= read_1_byte (abfd
, info_ptr
);
8413 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8414 info_ptr
+= blk
->size
;
8415 DW_BLOCK (attr
) = blk
;
8418 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
8422 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
8425 case DW_FORM_flag_present
:
8426 DW_UNSND (attr
) = 1;
8429 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
8430 info_ptr
+= bytes_read
;
8433 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8434 info_ptr
+= bytes_read
;
8437 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
8441 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
8445 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
8449 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
8453 /* Convert the signature to something we can record in DW_UNSND
8455 NOTE: This is NULL if the type wasn't found. */
8456 DW_SIGNATURED_TYPE (attr
) =
8457 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
8460 case DW_FORM_ref_udata
:
8461 DW_ADDR (attr
) = (cu
->header
.offset
8462 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
8463 info_ptr
+= bytes_read
;
8465 case DW_FORM_indirect
:
8466 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8467 info_ptr
+= bytes_read
;
8468 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
8471 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
8472 dwarf_form_name (form
),
8473 bfd_get_filename (abfd
));
8476 /* We have seen instances where the compiler tried to emit a byte
8477 size attribute of -1 which ended up being encoded as an unsigned
8478 0xffffffff. Although 0xffffffff is technically a valid size value,
8479 an object of this size seems pretty unlikely so we can relatively
8480 safely treat these cases as if the size attribute was invalid and
8481 treat them as zero by default. */
8482 if (attr
->name
== DW_AT_byte_size
8483 && form
== DW_FORM_data4
8484 && DW_UNSND (attr
) >= 0xffffffff)
8487 (&symfile_complaints
,
8488 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
8489 hex_string (DW_UNSND (attr
)));
8490 DW_UNSND (attr
) = 0;
8496 /* Read an attribute described by an abbreviated attribute. */
8499 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
8500 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8502 attr
->name
= abbrev
->name
;
8503 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
8506 /* read dwarf information from a buffer */
8509 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
8511 return bfd_get_8 (abfd
, buf
);
8515 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
8517 return bfd_get_signed_8 (abfd
, buf
);
8521 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
8523 return bfd_get_16 (abfd
, buf
);
8527 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
8529 return bfd_get_signed_16 (abfd
, buf
);
8533 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
8535 return bfd_get_32 (abfd
, buf
);
8539 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
8541 return bfd_get_signed_32 (abfd
, buf
);
8545 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
8547 return bfd_get_64 (abfd
, buf
);
8551 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
8552 unsigned int *bytes_read
)
8554 struct comp_unit_head
*cu_header
= &cu
->header
;
8555 CORE_ADDR retval
= 0;
8557 if (cu_header
->signed_addr_p
)
8559 switch (cu_header
->addr_size
)
8562 retval
= bfd_get_signed_16 (abfd
, buf
);
8565 retval
= bfd_get_signed_32 (abfd
, buf
);
8568 retval
= bfd_get_signed_64 (abfd
, buf
);
8571 internal_error (__FILE__
, __LINE__
,
8572 _("read_address: bad switch, signed [in module %s]"),
8573 bfd_get_filename (abfd
));
8578 switch (cu_header
->addr_size
)
8581 retval
= bfd_get_16 (abfd
, buf
);
8584 retval
= bfd_get_32 (abfd
, buf
);
8587 retval
= bfd_get_64 (abfd
, buf
);
8590 internal_error (__FILE__
, __LINE__
,
8591 _("read_address: bad switch, unsigned [in module %s]"),
8592 bfd_get_filename (abfd
));
8596 *bytes_read
= cu_header
->addr_size
;
8600 /* Read the initial length from a section. The (draft) DWARF 3
8601 specification allows the initial length to take up either 4 bytes
8602 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
8603 bytes describe the length and all offsets will be 8 bytes in length
8606 An older, non-standard 64-bit format is also handled by this
8607 function. The older format in question stores the initial length
8608 as an 8-byte quantity without an escape value. Lengths greater
8609 than 2^32 aren't very common which means that the initial 4 bytes
8610 is almost always zero. Since a length value of zero doesn't make
8611 sense for the 32-bit format, this initial zero can be considered to
8612 be an escape value which indicates the presence of the older 64-bit
8613 format. As written, the code can't detect (old format) lengths
8614 greater than 4GB. If it becomes necessary to handle lengths
8615 somewhat larger than 4GB, we could allow other small values (such
8616 as the non-sensical values of 1, 2, and 3) to also be used as
8617 escape values indicating the presence of the old format.
8619 The value returned via bytes_read should be used to increment the
8620 relevant pointer after calling read_initial_length().
8622 [ Note: read_initial_length() and read_offset() are based on the
8623 document entitled "DWARF Debugging Information Format", revision
8624 3, draft 8, dated November 19, 2001. This document was obtained
8627 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
8629 This document is only a draft and is subject to change. (So beware.)
8631 Details regarding the older, non-standard 64-bit format were
8632 determined empirically by examining 64-bit ELF files produced by
8633 the SGI toolchain on an IRIX 6.5 machine.
8635 - Kevin, July 16, 2002
8639 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
8641 LONGEST length
= bfd_get_32 (abfd
, buf
);
8643 if (length
== 0xffffffff)
8645 length
= bfd_get_64 (abfd
, buf
+ 4);
8648 else if (length
== 0)
8650 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
8651 length
= bfd_get_64 (abfd
, buf
);
8662 /* Cover function for read_initial_length.
8663 Returns the length of the object at BUF, and stores the size of the
8664 initial length in *BYTES_READ and stores the size that offsets will be in
8666 If the initial length size is not equivalent to that specified in
8667 CU_HEADER then issue a complaint.
8668 This is useful when reading non-comp-unit headers. */
8671 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
8672 const struct comp_unit_head
*cu_header
,
8673 unsigned int *bytes_read
,
8674 unsigned int *offset_size
)
8676 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
8678 gdb_assert (cu_header
->initial_length_size
== 4
8679 || cu_header
->initial_length_size
== 8
8680 || cu_header
->initial_length_size
== 12);
8682 if (cu_header
->initial_length_size
!= *bytes_read
)
8683 complaint (&symfile_complaints
,
8684 _("intermixed 32-bit and 64-bit DWARF sections"));
8686 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
8690 /* Read an offset from the data stream. The size of the offset is
8691 given by cu_header->offset_size. */
8694 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
8695 unsigned int *bytes_read
)
8697 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
8699 *bytes_read
= cu_header
->offset_size
;
8703 /* Read an offset from the data stream. */
8706 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
8710 switch (offset_size
)
8713 retval
= bfd_get_32 (abfd
, buf
);
8716 retval
= bfd_get_64 (abfd
, buf
);
8719 internal_error (__FILE__
, __LINE__
,
8720 _("read_offset_1: bad switch [in module %s]"),
8721 bfd_get_filename (abfd
));
8728 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
8730 /* If the size of a host char is 8 bits, we can return a pointer
8731 to the buffer, otherwise we have to copy the data to a buffer
8732 allocated on the temporary obstack. */
8733 gdb_assert (HOST_CHAR_BIT
== 8);
8738 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
8740 /* If the size of a host char is 8 bits, we can return a pointer
8741 to the string, otherwise we have to copy the string to a buffer
8742 allocated on the temporary obstack. */
8743 gdb_assert (HOST_CHAR_BIT
== 8);
8746 *bytes_read_ptr
= 1;
8749 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
8750 return (char *) buf
;
8754 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
8755 const struct comp_unit_head
*cu_header
,
8756 unsigned int *bytes_read_ptr
)
8758 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
8760 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
8761 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
8763 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
8764 bfd_get_filename (abfd
));
8767 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
8769 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
8770 bfd_get_filename (abfd
));
8773 gdb_assert (HOST_CHAR_BIT
== 8);
8774 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
8776 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
8779 static unsigned long
8780 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
8782 unsigned long result
;
8783 unsigned int num_read
;
8793 byte
= bfd_get_8 (abfd
, buf
);
8796 result
|= ((unsigned long)(byte
& 127) << shift
);
8797 if ((byte
& 128) == 0)
8803 *bytes_read_ptr
= num_read
;
8808 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
8811 int i
, shift
, num_read
;
8820 byte
= bfd_get_8 (abfd
, buf
);
8823 result
|= ((long)(byte
& 127) << shift
);
8825 if ((byte
& 128) == 0)
8830 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
8831 result
|= -(((long)1) << shift
);
8832 *bytes_read_ptr
= num_read
;
8836 /* Return a pointer to just past the end of an LEB128 number in BUF. */
8839 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
8845 byte
= bfd_get_8 (abfd
, buf
);
8847 if ((byte
& 128) == 0)
8853 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
8860 cu
->language
= language_c
;
8862 case DW_LANG_C_plus_plus
:
8863 cu
->language
= language_cplus
;
8866 cu
->language
= language_d
;
8868 case DW_LANG_Fortran77
:
8869 case DW_LANG_Fortran90
:
8870 case DW_LANG_Fortran95
:
8871 cu
->language
= language_fortran
;
8873 case DW_LANG_Mips_Assembler
:
8874 cu
->language
= language_asm
;
8877 cu
->language
= language_java
;
8881 cu
->language
= language_ada
;
8883 case DW_LANG_Modula2
:
8884 cu
->language
= language_m2
;
8886 case DW_LANG_Pascal83
:
8887 cu
->language
= language_pascal
;
8890 cu
->language
= language_objc
;
8892 case DW_LANG_Cobol74
:
8893 case DW_LANG_Cobol85
:
8895 cu
->language
= language_minimal
;
8898 cu
->language_defn
= language_def (cu
->language
);
8901 /* Return the named attribute or NULL if not there. */
8903 static struct attribute
*
8904 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
8907 struct attribute
*spec
= NULL
;
8909 for (i
= 0; i
< die
->num_attrs
; ++i
)
8911 if (die
->attrs
[i
].name
== name
)
8912 return &die
->attrs
[i
];
8913 if (die
->attrs
[i
].name
== DW_AT_specification
8914 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
8915 spec
= &die
->attrs
[i
];
8920 die
= follow_die_ref (die
, spec
, &cu
);
8921 return dwarf2_attr (die
, name
, cu
);
8927 /* Return the named attribute or NULL if not there,
8928 but do not follow DW_AT_specification, etc.
8929 This is for use in contexts where we're reading .debug_types dies.
8930 Following DW_AT_specification, DW_AT_abstract_origin will take us
8931 back up the chain, and we want to go down. */
8933 static struct attribute
*
8934 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
8935 struct dwarf2_cu
*cu
)
8939 for (i
= 0; i
< die
->num_attrs
; ++i
)
8940 if (die
->attrs
[i
].name
== name
)
8941 return &die
->attrs
[i
];
8946 /* Return non-zero iff the attribute NAME is defined for the given DIE,
8947 and holds a non-zero value. This function should only be used for
8948 DW_FORM_flag or DW_FORM_flag_present attributes. */
8951 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
8953 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
8955 return (attr
&& DW_UNSND (attr
));
8959 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
8961 /* A DIE is a declaration if it has a DW_AT_declaration attribute
8962 which value is non-zero. However, we have to be careful with
8963 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
8964 (via dwarf2_flag_true_p) follows this attribute. So we may
8965 end up accidently finding a declaration attribute that belongs
8966 to a different DIE referenced by the specification attribute,
8967 even though the given DIE does not have a declaration attribute. */
8968 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
8969 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
8972 /* Return the die giving the specification for DIE, if there is
8973 one. *SPEC_CU is the CU containing DIE on input, and the CU
8974 containing the return value on output. If there is no
8975 specification, but there is an abstract origin, that is
8978 static struct die_info
*
8979 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
8981 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
8984 if (spec_attr
== NULL
)
8985 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
8987 if (spec_attr
== NULL
)
8990 return follow_die_ref (die
, spec_attr
, spec_cu
);
8993 /* Free the line_header structure *LH, and any arrays and strings it
8996 free_line_header (struct line_header
*lh
)
8998 if (lh
->standard_opcode_lengths
)
8999 xfree (lh
->standard_opcode_lengths
);
9001 /* Remember that all the lh->file_names[i].name pointers are
9002 pointers into debug_line_buffer, and don't need to be freed. */
9004 xfree (lh
->file_names
);
9006 /* Similarly for the include directory names. */
9007 if (lh
->include_dirs
)
9008 xfree (lh
->include_dirs
);
9014 /* Add an entry to LH's include directory table. */
9016 add_include_dir (struct line_header
*lh
, char *include_dir
)
9018 /* Grow the array if necessary. */
9019 if (lh
->include_dirs_size
== 0)
9021 lh
->include_dirs_size
= 1; /* for testing */
9022 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9023 * sizeof (*lh
->include_dirs
));
9025 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9027 lh
->include_dirs_size
*= 2;
9028 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9029 (lh
->include_dirs_size
9030 * sizeof (*lh
->include_dirs
)));
9033 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9037 /* Add an entry to LH's file name table. */
9039 add_file_name (struct line_header
*lh
,
9041 unsigned int dir_index
,
9042 unsigned int mod_time
,
9043 unsigned int length
)
9045 struct file_entry
*fe
;
9047 /* Grow the array if necessary. */
9048 if (lh
->file_names_size
== 0)
9050 lh
->file_names_size
= 1; /* for testing */
9051 lh
->file_names
= xmalloc (lh
->file_names_size
9052 * sizeof (*lh
->file_names
));
9054 else if (lh
->num_file_names
>= lh
->file_names_size
)
9056 lh
->file_names_size
*= 2;
9057 lh
->file_names
= xrealloc (lh
->file_names
,
9058 (lh
->file_names_size
9059 * sizeof (*lh
->file_names
)));
9062 fe
= &lh
->file_names
[lh
->num_file_names
++];
9064 fe
->dir_index
= dir_index
;
9065 fe
->mod_time
= mod_time
;
9066 fe
->length
= length
;
9072 /* Read the statement program header starting at OFFSET in
9073 .debug_line, according to the endianness of ABFD. Return a pointer
9074 to a struct line_header, allocated using xmalloc.
9076 NOTE: the strings in the include directory and file name tables of
9077 the returned object point into debug_line_buffer, and must not be
9079 static struct line_header
*
9080 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9081 struct dwarf2_cu
*cu
)
9083 struct cleanup
*back_to
;
9084 struct line_header
*lh
;
9086 unsigned int bytes_read
, offset_size
;
9088 char *cur_dir
, *cur_file
;
9090 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9091 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9093 complaint (&symfile_complaints
, _("missing .debug_line section"));
9097 /* Make sure that at least there's room for the total_length field.
9098 That could be 12 bytes long, but we're just going to fudge that. */
9099 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9101 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9105 lh
= xmalloc (sizeof (*lh
));
9106 memset (lh
, 0, sizeof (*lh
));
9107 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9110 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9112 /* Read in the header. */
9114 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9115 &bytes_read
, &offset_size
);
9116 line_ptr
+= bytes_read
;
9117 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9118 + dwarf2_per_objfile
->line
.size
))
9120 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9123 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9124 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9126 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9127 line_ptr
+= offset_size
;
9128 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9130 if (lh
->version
>= 4)
9132 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9136 lh
->maximum_ops_per_instruction
= 1;
9138 if (lh
->maximum_ops_per_instruction
== 0)
9140 lh
->maximum_ops_per_instruction
= 1;
9141 complaint (&symfile_complaints
,
9142 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9145 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9147 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9149 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9151 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9153 lh
->standard_opcode_lengths
9154 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9156 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9157 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9159 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9163 /* Read directory table. */
9164 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9166 line_ptr
+= bytes_read
;
9167 add_include_dir (lh
, cur_dir
);
9169 line_ptr
+= bytes_read
;
9171 /* Read file name table. */
9172 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9174 unsigned int dir_index
, mod_time
, length
;
9176 line_ptr
+= bytes_read
;
9177 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9178 line_ptr
+= bytes_read
;
9179 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9180 line_ptr
+= bytes_read
;
9181 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9182 line_ptr
+= bytes_read
;
9184 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9186 line_ptr
+= bytes_read
;
9187 lh
->statement_program_start
= line_ptr
;
9189 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9190 + dwarf2_per_objfile
->line
.size
))
9191 complaint (&symfile_complaints
,
9192 _("line number info header doesn't fit in `.debug_line' section"));
9194 discard_cleanups (back_to
);
9198 /* This function exists to work around a bug in certain compilers
9199 (particularly GCC 2.95), in which the first line number marker of a
9200 function does not show up until after the prologue, right before
9201 the second line number marker. This function shifts ADDRESS down
9202 to the beginning of the function if necessary, and is called on
9203 addresses passed to record_line. */
9206 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9208 struct function_range
*fn
;
9210 /* Find the function_range containing address. */
9215 cu
->cached_fn
= cu
->first_fn
;
9219 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9225 while (fn
&& fn
!= cu
->cached_fn
)
9226 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9236 if (address
!= fn
->lowpc
)
9237 complaint (&symfile_complaints
,
9238 _("misplaced first line number at 0x%lx for '%s'"),
9239 (unsigned long) address
, fn
->name
);
9244 /* Decode the Line Number Program (LNP) for the given line_header
9245 structure and CU. The actual information extracted and the type
9246 of structures created from the LNP depends on the value of PST.
9248 1. If PST is NULL, then this procedure uses the data from the program
9249 to create all necessary symbol tables, and their linetables.
9250 The compilation directory of the file is passed in COMP_DIR,
9251 and must not be NULL.
9253 2. If PST is not NULL, this procedure reads the program to determine
9254 the list of files included by the unit represented by PST, and
9255 builds all the associated partial symbol tables. In this case,
9256 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
9257 is not used to compute the full name of the symtab, and therefore
9258 omitting it when building the partial symtab does not introduce
9259 the potential for inconsistency - a partial symtab and its associated
9260 symbtab having a different fullname -). */
9263 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
9264 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
9266 gdb_byte
*line_ptr
, *extended_end
;
9268 unsigned int bytes_read
, extended_len
;
9269 unsigned char op_code
, extended_op
, adj_opcode
;
9271 struct objfile
*objfile
= cu
->objfile
;
9272 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9273 const int decode_for_pst_p
= (pst
!= NULL
);
9274 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
9276 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9278 line_ptr
= lh
->statement_program_start
;
9279 line_end
= lh
->statement_program_end
;
9281 /* Read the statement sequences until there's nothing left. */
9282 while (line_ptr
< line_end
)
9284 /* state machine registers */
9285 CORE_ADDR address
= 0;
9286 unsigned int file
= 1;
9287 unsigned int line
= 1;
9288 unsigned int column
= 0;
9289 int is_stmt
= lh
->default_is_stmt
;
9290 int basic_block
= 0;
9291 int end_sequence
= 0;
9293 unsigned char op_index
= 0;
9295 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
9297 /* Start a subfile for the current file of the state machine. */
9298 /* lh->include_dirs and lh->file_names are 0-based, but the
9299 directory and file name numbers in the statement program
9301 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9305 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9307 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9310 /* Decode the table. */
9311 while (!end_sequence
)
9313 op_code
= read_1_byte (abfd
, line_ptr
);
9315 if (line_ptr
> line_end
)
9317 dwarf2_debug_line_missing_end_sequence_complaint ();
9321 if (op_code
>= lh
->opcode_base
)
9323 /* Special operand. */
9324 adj_opcode
= op_code
- lh
->opcode_base
;
9325 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
9326 / lh
->maximum_ops_per_instruction
)
9327 * lh
->minimum_instruction_length
);
9328 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
9329 % lh
->maximum_ops_per_instruction
);
9330 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
9331 if (lh
->num_file_names
< file
|| file
== 0)
9332 dwarf2_debug_line_missing_file_complaint ();
9333 /* For now we ignore lines not starting on an
9334 instruction boundary. */
9335 else if (op_index
== 0)
9337 lh
->file_names
[file
- 1].included_p
= 1;
9338 if (!decode_for_pst_p
&& is_stmt
)
9340 if (last_subfile
!= current_subfile
)
9342 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9344 record_line (last_subfile
, 0, addr
);
9345 last_subfile
= current_subfile
;
9347 /* Append row to matrix using current values. */
9348 addr
= check_cu_functions (address
, cu
);
9349 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
9350 record_line (current_subfile
, line
, addr
);
9355 else switch (op_code
)
9357 case DW_LNS_extended_op
:
9358 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9359 line_ptr
+= bytes_read
;
9360 extended_end
= line_ptr
+ extended_len
;
9361 extended_op
= read_1_byte (abfd
, line_ptr
);
9363 switch (extended_op
)
9365 case DW_LNE_end_sequence
:
9368 case DW_LNE_set_address
:
9369 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
9371 line_ptr
+= bytes_read
;
9372 address
+= baseaddr
;
9374 case DW_LNE_define_file
:
9377 unsigned int dir_index
, mod_time
, length
;
9379 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
9380 line_ptr
+= bytes_read
;
9382 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9383 line_ptr
+= bytes_read
;
9385 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9386 line_ptr
+= bytes_read
;
9388 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9389 line_ptr
+= bytes_read
;
9390 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9393 case DW_LNE_set_discriminator
:
9394 /* The discriminator is not interesting to the debugger;
9396 line_ptr
= extended_end
;
9399 complaint (&symfile_complaints
,
9400 _("mangled .debug_line section"));
9403 /* Make sure that we parsed the extended op correctly. If e.g.
9404 we expected a different address size than the producer used,
9405 we may have read the wrong number of bytes. */
9406 if (line_ptr
!= extended_end
)
9408 complaint (&symfile_complaints
,
9409 _("mangled .debug_line section"));
9414 if (lh
->num_file_names
< file
|| file
== 0)
9415 dwarf2_debug_line_missing_file_complaint ();
9418 lh
->file_names
[file
- 1].included_p
= 1;
9419 if (!decode_for_pst_p
&& is_stmt
)
9421 if (last_subfile
!= current_subfile
)
9423 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9425 record_line (last_subfile
, 0, addr
);
9426 last_subfile
= current_subfile
;
9428 addr
= check_cu_functions (address
, cu
);
9429 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
9430 record_line (current_subfile
, line
, addr
);
9435 case DW_LNS_advance_pc
:
9438 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9440 address
+= (((op_index
+ adjust
)
9441 / lh
->maximum_ops_per_instruction
)
9442 * lh
->minimum_instruction_length
);
9443 op_index
= ((op_index
+ adjust
)
9444 % lh
->maximum_ops_per_instruction
);
9445 line_ptr
+= bytes_read
;
9448 case DW_LNS_advance_line
:
9449 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
9450 line_ptr
+= bytes_read
;
9452 case DW_LNS_set_file
:
9454 /* The arrays lh->include_dirs and lh->file_names are
9455 0-based, but the directory and file name numbers in
9456 the statement program are 1-based. */
9457 struct file_entry
*fe
;
9460 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9461 line_ptr
+= bytes_read
;
9462 if (lh
->num_file_names
< file
|| file
== 0)
9463 dwarf2_debug_line_missing_file_complaint ();
9466 fe
= &lh
->file_names
[file
- 1];
9468 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9469 if (!decode_for_pst_p
)
9471 last_subfile
= current_subfile
;
9472 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9477 case DW_LNS_set_column
:
9478 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9479 line_ptr
+= bytes_read
;
9481 case DW_LNS_negate_stmt
:
9482 is_stmt
= (!is_stmt
);
9484 case DW_LNS_set_basic_block
:
9487 /* Add to the address register of the state machine the
9488 address increment value corresponding to special opcode
9489 255. I.e., this value is scaled by the minimum
9490 instruction length since special opcode 255 would have
9491 scaled the the increment. */
9492 case DW_LNS_const_add_pc
:
9494 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
9496 address
+= (((op_index
+ adjust
)
9497 / lh
->maximum_ops_per_instruction
)
9498 * lh
->minimum_instruction_length
);
9499 op_index
= ((op_index
+ adjust
)
9500 % lh
->maximum_ops_per_instruction
);
9503 case DW_LNS_fixed_advance_pc
:
9504 address
+= read_2_bytes (abfd
, line_ptr
);
9510 /* Unknown standard opcode, ignore it. */
9513 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
9515 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9516 line_ptr
+= bytes_read
;
9521 if (lh
->num_file_names
< file
|| file
== 0)
9522 dwarf2_debug_line_missing_file_complaint ();
9525 lh
->file_names
[file
- 1].included_p
= 1;
9526 if (!decode_for_pst_p
)
9528 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9529 record_line (current_subfile
, 0, addr
);
9534 if (decode_for_pst_p
)
9538 /* Now that we're done scanning the Line Header Program, we can
9539 create the psymtab of each included file. */
9540 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
9541 if (lh
->file_names
[file_index
].included_p
== 1)
9543 const struct file_entry fe
= lh
->file_names
[file_index
];
9544 char *include_name
= fe
.name
;
9545 char *dir_name
= NULL
;
9546 char *pst_filename
= pst
->filename
;
9549 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
9551 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
9553 include_name
= concat (dir_name
, SLASH_STRING
,
9554 include_name
, (char *)NULL
);
9555 make_cleanup (xfree
, include_name
);
9558 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
9560 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
9561 pst_filename
, (char *)NULL
);
9562 make_cleanup (xfree
, pst_filename
);
9565 if (strcmp (include_name
, pst_filename
) != 0)
9566 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
9571 /* Make sure a symtab is created for every file, even files
9572 which contain only variables (i.e. no code with associated
9576 struct file_entry
*fe
;
9578 for (i
= 0; i
< lh
->num_file_names
; i
++)
9582 fe
= &lh
->file_names
[i
];
9584 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9585 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9587 /* Skip the main file; we don't need it, and it must be
9588 allocated last, so that it will show up before the
9589 non-primary symtabs in the objfile's symtab list. */
9590 if (current_subfile
== first_subfile
)
9593 if (current_subfile
->symtab
== NULL
)
9594 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
9596 fe
->symtab
= current_subfile
->symtab
;
9601 /* Start a subfile for DWARF. FILENAME is the name of the file and
9602 DIRNAME the name of the source directory which contains FILENAME
9603 or NULL if not known. COMP_DIR is the compilation directory for the
9604 linetable's compilation unit or NULL if not known.
9605 This routine tries to keep line numbers from identical absolute and
9606 relative file names in a common subfile.
9608 Using the `list' example from the GDB testsuite, which resides in
9609 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
9610 of /srcdir/list0.c yields the following debugging information for list0.c:
9612 DW_AT_name: /srcdir/list0.c
9613 DW_AT_comp_dir: /compdir
9614 files.files[0].name: list0.h
9615 files.files[0].dir: /srcdir
9616 files.files[1].name: list0.c
9617 files.files[1].dir: /srcdir
9619 The line number information for list0.c has to end up in a single
9620 subfile, so that `break /srcdir/list0.c:1' works as expected.
9621 start_subfile will ensure that this happens provided that we pass the
9622 concatenation of files.files[1].dir and files.files[1].name as the
9626 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
9630 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
9631 `start_symtab' will always pass the contents of DW_AT_comp_dir as
9632 second argument to start_subfile. To be consistent, we do the
9633 same here. In order not to lose the line information directory,
9634 we concatenate it to the filename when it makes sense.
9635 Note that the Dwarf3 standard says (speaking of filenames in line
9636 information): ``The directory index is ignored for file names
9637 that represent full path names''. Thus ignoring dirname in the
9638 `else' branch below isn't an issue. */
9640 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
9641 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
9643 fullname
= filename
;
9645 start_subfile (fullname
, comp_dir
);
9647 if (fullname
!= filename
)
9652 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
9653 struct dwarf2_cu
*cu
)
9655 struct objfile
*objfile
= cu
->objfile
;
9656 struct comp_unit_head
*cu_header
= &cu
->header
;
9658 /* NOTE drow/2003-01-30: There used to be a comment and some special
9659 code here to turn a symbol with DW_AT_external and a
9660 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
9661 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
9662 with some versions of binutils) where shared libraries could have
9663 relocations against symbols in their debug information - the
9664 minimal symbol would have the right address, but the debug info
9665 would not. It's no longer necessary, because we will explicitly
9666 apply relocations when we read in the debug information now. */
9668 /* A DW_AT_location attribute with no contents indicates that a
9669 variable has been optimized away. */
9670 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
9672 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
9676 /* Handle one degenerate form of location expression specially, to
9677 preserve GDB's previous behavior when section offsets are
9678 specified. If this is just a DW_OP_addr then mark this symbol
9681 if (attr_form_is_block (attr
)
9682 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
9683 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
9687 SYMBOL_VALUE_ADDRESS (sym
) =
9688 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
9689 SYMBOL_CLASS (sym
) = LOC_STATIC
;
9690 fixup_symbol_section (sym
, objfile
);
9691 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
9692 SYMBOL_SECTION (sym
));
9696 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
9697 expression evaluator, and use LOC_COMPUTED only when necessary
9698 (i.e. when the value of a register or memory location is
9699 referenced, or a thread-local block, etc.). Then again, it might
9700 not be worthwhile. I'm assuming that it isn't unless performance
9701 or memory numbers show me otherwise. */
9703 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
9704 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
9707 /* Given a pointer to a DWARF information entry, figure out if we need
9708 to make a symbol table entry for it, and if so, create a new entry
9709 and return a pointer to it.
9710 If TYPE is NULL, determine symbol type from the die, otherwise
9711 used the passed type. */
9713 static struct symbol
*
9714 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
9716 struct objfile
*objfile
= cu
->objfile
;
9717 struct symbol
*sym
= NULL
;
9719 struct attribute
*attr
= NULL
;
9720 struct attribute
*attr2
= NULL
;
9722 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9724 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9726 name
= dwarf2_name (die
, cu
);
9729 const char *linkagename
;
9731 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
9732 sizeof (struct symbol
));
9733 OBJSTAT (objfile
, n_syms
++);
9734 memset (sym
, 0, sizeof (struct symbol
));
9736 /* Cache this symbol's name and the name's demangled form (if any). */
9737 SYMBOL_LANGUAGE (sym
) = cu
->language
;
9738 linkagename
= dwarf2_physname (name
, die
, cu
);
9739 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
9741 /* Fortran does not have mangling standard and the mangling does differ
9742 between gfortran, iFort etc. */
9743 if (cu
->language
== language_fortran
9744 && symbol_get_demangled_name (&(sym
->ginfo
)) == NULL
)
9745 symbol_set_demangled_name (&(sym
->ginfo
),
9746 (char *) dwarf2_full_name (name
, die
, cu
),
9749 /* Default assumptions.
9750 Use the passed type or decode it from the die. */
9751 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
9752 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
9754 SYMBOL_TYPE (sym
) = type
;
9756 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
9757 attr
= dwarf2_attr (die
,
9758 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
9762 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
9765 attr
= dwarf2_attr (die
,
9766 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
9770 int file_index
= DW_UNSND (attr
);
9772 if (cu
->line_header
== NULL
9773 || file_index
> cu
->line_header
->num_file_names
)
9774 complaint (&symfile_complaints
,
9775 _("file index out of range"));
9776 else if (file_index
> 0)
9778 struct file_entry
*fe
;
9780 fe
= &cu
->line_header
->file_names
[file_index
- 1];
9781 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
9788 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9791 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
9793 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
9794 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
9795 SYMBOL_CLASS (sym
) = LOC_LABEL
;
9796 add_symbol_to_list (sym
, cu
->list_in_scope
);
9798 case DW_TAG_subprogram
:
9799 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9801 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
9802 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9803 if ((attr2
&& (DW_UNSND (attr2
) != 0))
9804 || cu
->language
== language_ada
)
9806 /* Subprograms marked external are stored as a global symbol.
9807 Ada subprograms, whether marked external or not, are always
9808 stored as a global symbol, because we want to be able to
9809 access them globally. For instance, we want to be able
9810 to break on a nested subprogram without having to
9811 specify the context. */
9812 add_symbol_to_list (sym
, &global_symbols
);
9816 add_symbol_to_list (sym
, cu
->list_in_scope
);
9819 case DW_TAG_inlined_subroutine
:
9820 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9822 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
9823 SYMBOL_INLINED (sym
) = 1;
9824 /* Do not add the symbol to any lists. It will be found via
9825 BLOCK_FUNCTION from the blockvector. */
9827 case DW_TAG_variable
:
9829 /* Compilation with minimal debug info may result in variables
9830 with missing type entries. Change the misleading `void' type
9831 to something sensible. */
9832 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
9834 = objfile_type (objfile
)->nodebug_data_symbol
;
9836 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9837 /* In the case of DW_TAG_member, we should only be called for
9838 static const members. */
9839 if (die
->tag
== DW_TAG_member
)
9841 /* dwarf2_add_field uses die_is_declaration,
9842 so we do the same. */
9843 gdb_assert (die_is_declaration (die
, cu
));
9848 dwarf2_const_value (attr
, sym
, cu
);
9849 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9850 if (attr2
&& (DW_UNSND (attr2
) != 0))
9851 add_symbol_to_list (sym
, &global_symbols
);
9853 add_symbol_to_list (sym
, cu
->list_in_scope
);
9856 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9859 var_decode_location (attr
, sym
, cu
);
9860 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9861 if (attr2
&& (DW_UNSND (attr2
) != 0))
9863 struct pending
**list_to_add
;
9865 /* Workaround gfortran PR debug/40040 - it uses
9866 DW_AT_location for variables in -fPIC libraries which may
9867 get overriden by other libraries/executable and get
9868 a different address. Resolve it by the minimal symbol
9869 which may come from inferior's executable using copy
9870 relocation. Make this workaround only for gfortran as for
9871 other compilers GDB cannot guess the minimal symbol
9872 Fortran mangling kind. */
9873 if (cu
->language
== language_fortran
&& die
->parent
9874 && die
->parent
->tag
== DW_TAG_module
9876 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
9877 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
9879 /* A variable with DW_AT_external is never static,
9880 but it may be block-scoped. */
9881 list_to_add
= (cu
->list_in_scope
== &file_symbols
9882 ? &global_symbols
: cu
->list_in_scope
);
9883 add_symbol_to_list (sym
, list_to_add
);
9886 add_symbol_to_list (sym
, cu
->list_in_scope
);
9890 /* We do not know the address of this symbol.
9891 If it is an external symbol and we have type information
9892 for it, enter the symbol as a LOC_UNRESOLVED symbol.
9893 The address of the variable will then be determined from
9894 the minimal symbol table whenever the variable is
9896 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9897 if (attr2
&& (DW_UNSND (attr2
) != 0)
9898 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
9900 struct pending
**list_to_add
;
9902 /* A variable with DW_AT_external is never static, but it
9903 may be block-scoped. */
9904 list_to_add
= (cu
->list_in_scope
== &file_symbols
9905 ? &global_symbols
: cu
->list_in_scope
);
9907 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
9908 add_symbol_to_list (sym
, list_to_add
);
9910 else if (!die_is_declaration (die
, cu
))
9912 /* Use the default LOC_OPTIMIZED_OUT class. */
9913 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
9914 add_symbol_to_list (sym
, cu
->list_in_scope
);
9918 case DW_TAG_formal_parameter
:
9919 /* If we are inside a function, mark this as an argument. If
9920 not, we might be looking at an argument to an inlined function
9921 when we do not have enough information to show inlined frames;
9922 pretend it's a local variable in that case so that the user can
9924 if (context_stack_depth
> 0
9925 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
9926 SYMBOL_IS_ARGUMENT (sym
) = 1;
9927 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9930 var_decode_location (attr
, sym
, cu
);
9932 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9935 dwarf2_const_value (attr
, sym
, cu
);
9937 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
9938 if (attr
&& DW_UNSND (attr
))
9940 struct type
*ref_type
;
9942 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
9943 SYMBOL_TYPE (sym
) = ref_type
;
9946 add_symbol_to_list (sym
, cu
->list_in_scope
);
9948 case DW_TAG_unspecified_parameters
:
9949 /* From varargs functions; gdb doesn't seem to have any
9950 interest in this information, so just ignore it for now.
9953 case DW_TAG_class_type
:
9954 case DW_TAG_interface_type
:
9955 case DW_TAG_structure_type
:
9956 case DW_TAG_union_type
:
9957 case DW_TAG_set_type
:
9958 case DW_TAG_enumeration_type
:
9959 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
9960 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9963 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
9964 really ever be static objects: otherwise, if you try
9965 to, say, break of a class's method and you're in a file
9966 which doesn't mention that class, it won't work unless
9967 the check for all static symbols in lookup_symbol_aux
9968 saves you. See the OtherFileClass tests in
9969 gdb.c++/namespace.exp. */
9971 struct pending
**list_to_add
;
9973 list_to_add
= (cu
->list_in_scope
== &file_symbols
9974 && (cu
->language
== language_cplus
9975 || cu
->language
== language_java
)
9976 ? &global_symbols
: cu
->list_in_scope
);
9978 add_symbol_to_list (sym
, list_to_add
);
9980 /* The semantics of C++ state that "struct foo { ... }" also
9981 defines a typedef for "foo". A Java class declaration also
9982 defines a typedef for the class. */
9983 if (cu
->language
== language_cplus
9984 || cu
->language
== language_java
9985 || cu
->language
== language_ada
)
9987 /* The symbol's name is already allocated along with
9988 this objfile, so we don't need to duplicate it for
9990 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
9991 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
9995 case DW_TAG_typedef
:
9996 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
9997 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
9998 add_symbol_to_list (sym
, cu
->list_in_scope
);
10000 case DW_TAG_base_type
:
10001 case DW_TAG_subrange_type
:
10002 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10003 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10004 add_symbol_to_list (sym
, cu
->list_in_scope
);
10006 case DW_TAG_enumerator
:
10007 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10010 dwarf2_const_value (attr
, sym
, cu
);
10013 /* NOTE: carlton/2003-11-10: See comment above in the
10014 DW_TAG_class_type, etc. block. */
10016 struct pending
**list_to_add
;
10018 list_to_add
= (cu
->list_in_scope
== &file_symbols
10019 && (cu
->language
== language_cplus
10020 || cu
->language
== language_java
)
10021 ? &global_symbols
: cu
->list_in_scope
);
10023 add_symbol_to_list (sym
, list_to_add
);
10026 case DW_TAG_namespace
:
10027 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10028 add_symbol_to_list (sym
, &global_symbols
);
10031 /* Not a tag we recognize. Hopefully we aren't processing
10032 trash data, but since we must specifically ignore things
10033 we don't recognize, there is nothing else we should do at
10035 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10036 dwarf_tag_name (die
->tag
));
10040 /* For the benefit of old versions of GCC, check for anonymous
10041 namespaces based on the demangled name. */
10042 if (!processing_has_namespace_info
10043 && cu
->language
== language_cplus
)
10044 cp_scan_for_anonymous_namespaces (sym
);
10049 /* Copy constant value from an attribute to a symbol. */
10052 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
10053 struct dwarf2_cu
*cu
)
10055 struct objfile
*objfile
= cu
->objfile
;
10056 struct comp_unit_head
*cu_header
= &cu
->header
;
10057 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10058 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10059 struct dwarf_block
*blk
;
10061 switch (attr
->form
)
10065 struct dwarf2_locexpr_baton
*baton
;
10068 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
10069 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
10070 cu_header
->addr_size
,
10071 TYPE_LENGTH (SYMBOL_TYPE
10073 /* Symbols of this form are reasonably rare, so we just
10074 piggyback on the existing location code rather than writing
10075 a new implementation of symbol_computed_ops. */
10076 baton
= obstack_alloc (&objfile
->objfile_obstack
,
10077 sizeof (struct dwarf2_locexpr_baton
));
10078 baton
->per_cu
= cu
->per_cu
;
10079 gdb_assert (baton
->per_cu
);
10081 baton
->size
= 2 + cu_header
->addr_size
;
10082 data
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
10083 baton
->data
= data
;
10085 data
[0] = DW_OP_addr
;
10086 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
10087 byte_order
, DW_ADDR (attr
));
10088 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
10090 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10091 SYMBOL_LOCATION_BATON (sym
) = baton
;
10092 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10095 case DW_FORM_string
:
10097 /* DW_STRING is already allocated on the obstack, point directly
10099 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
10100 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
10102 case DW_FORM_block1
:
10103 case DW_FORM_block2
:
10104 case DW_FORM_block4
:
10105 case DW_FORM_block
:
10106 case DW_FORM_exprloc
:
10107 blk
= DW_BLOCK (attr
);
10108 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
10109 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
10111 TYPE_LENGTH (SYMBOL_TYPE
10113 SYMBOL_VALUE_BYTES (sym
) =
10114 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
10115 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
10116 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
10119 /* The DW_AT_const_value attributes are supposed to carry the
10120 symbol's value "represented as it would be on the target
10121 architecture." By the time we get here, it's already been
10122 converted to host endianness, so we just need to sign- or
10123 zero-extend it as appropriate. */
10124 case DW_FORM_data1
:
10125 dwarf2_const_value_data (attr
, sym
, 8);
10127 case DW_FORM_data2
:
10128 dwarf2_const_value_data (attr
, sym
, 16);
10130 case DW_FORM_data4
:
10131 dwarf2_const_value_data (attr
, sym
, 32);
10133 case DW_FORM_data8
:
10134 dwarf2_const_value_data (attr
, sym
, 64);
10137 case DW_FORM_sdata
:
10138 SYMBOL_VALUE (sym
) = DW_SND (attr
);
10139 SYMBOL_CLASS (sym
) = LOC_CONST
;
10142 case DW_FORM_udata
:
10143 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
10144 SYMBOL_CLASS (sym
) = LOC_CONST
;
10148 complaint (&symfile_complaints
,
10149 _("unsupported const value attribute form: '%s'"),
10150 dwarf_form_name (attr
->form
));
10151 SYMBOL_VALUE (sym
) = 0;
10152 SYMBOL_CLASS (sym
) = LOC_CONST
;
10158 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
10159 or zero-extend it as appropriate for the symbol's type. */
10161 dwarf2_const_value_data (struct attribute
*attr
,
10162 struct symbol
*sym
,
10165 LONGEST l
= DW_UNSND (attr
);
10167 if (bits
< sizeof (l
) * 8)
10169 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
10170 l
&= ((LONGEST
) 1 << bits
) - 1;
10172 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
10175 SYMBOL_VALUE (sym
) = l
;
10176 SYMBOL_CLASS (sym
) = LOC_CONST
;
10180 /* Return the type of the die in question using its DW_AT_type attribute. */
10182 static struct type
*
10183 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10185 struct attribute
*type_attr
;
10186 struct die_info
*type_die
;
10188 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
10191 /* A missing DW_AT_type represents a void type. */
10192 return objfile_type (cu
->objfile
)->builtin_void
;
10195 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10197 return tag_type_to_type (type_die
, cu
);
10200 /* True iff CU's producer generates GNAT Ada auxiliary information
10201 that allows to find parallel types through that information instead
10202 of having to do expensive parallel lookups by type name. */
10205 need_gnat_info (struct dwarf2_cu
*cu
)
10207 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
10208 of GNAT produces this auxiliary information, without any indication
10209 that it is produced. Part of enhancing the FSF version of GNAT
10210 to produce that information will be to put in place an indicator
10211 that we can use in order to determine whether the descriptive type
10212 info is available or not. One suggestion that has been made is
10213 to use a new attribute, attached to the CU die. For now, assume
10214 that the descriptive type info is not available. */
10219 /* Return the auxiliary type of the die in question using its
10220 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
10221 attribute is not present. */
10223 static struct type
*
10224 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10226 struct attribute
*type_attr
;
10227 struct die_info
*type_die
;
10229 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
10233 type_die
= follow_die_ref (die
, type_attr
, &cu
);
10234 return tag_type_to_type (type_die
, cu
);
10237 /* If DIE has a descriptive_type attribute, then set the TYPE's
10238 descriptive type accordingly. */
10241 set_descriptive_type (struct type
*type
, struct die_info
*die
,
10242 struct dwarf2_cu
*cu
)
10244 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
10246 if (descriptive_type
)
10248 ALLOCATE_GNAT_AUX_TYPE (type
);
10249 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
10253 /* Return the containing type of the die in question using its
10254 DW_AT_containing_type attribute. */
10256 static struct type
*
10257 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10259 struct attribute
*type_attr
;
10260 struct die_info
*type_die
;
10262 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
10264 error (_("Dwarf Error: Problem turning containing type into gdb type "
10265 "[in module %s]"), cu
->objfile
->name
);
10267 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10268 return tag_type_to_type (type_die
, cu
);
10271 static struct type
*
10272 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10274 struct type
*this_type
;
10276 this_type
= read_type_die (die
, cu
);
10279 char *message
, *saved
;
10281 /* read_type_die already issued a complaint. */
10282 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
10286 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
10287 message
, strlen (message
));
10290 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
10295 static struct type
*
10296 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10298 struct type
*this_type
;
10300 this_type
= get_die_type (die
, cu
);
10306 case DW_TAG_class_type
:
10307 case DW_TAG_interface_type
:
10308 case DW_TAG_structure_type
:
10309 case DW_TAG_union_type
:
10310 this_type
= read_structure_type (die
, cu
);
10312 case DW_TAG_enumeration_type
:
10313 this_type
= read_enumeration_type (die
, cu
);
10315 case DW_TAG_subprogram
:
10316 case DW_TAG_subroutine_type
:
10317 case DW_TAG_inlined_subroutine
:
10318 this_type
= read_subroutine_type (die
, cu
);
10320 case DW_TAG_array_type
:
10321 this_type
= read_array_type (die
, cu
);
10323 case DW_TAG_set_type
:
10324 this_type
= read_set_type (die
, cu
);
10326 case DW_TAG_pointer_type
:
10327 this_type
= read_tag_pointer_type (die
, cu
);
10329 case DW_TAG_ptr_to_member_type
:
10330 this_type
= read_tag_ptr_to_member_type (die
, cu
);
10332 case DW_TAG_reference_type
:
10333 this_type
= read_tag_reference_type (die
, cu
);
10335 case DW_TAG_const_type
:
10336 this_type
= read_tag_const_type (die
, cu
);
10338 case DW_TAG_volatile_type
:
10339 this_type
= read_tag_volatile_type (die
, cu
);
10341 case DW_TAG_string_type
:
10342 this_type
= read_tag_string_type (die
, cu
);
10344 case DW_TAG_typedef
:
10345 this_type
= read_typedef (die
, cu
);
10347 case DW_TAG_subrange_type
:
10348 this_type
= read_subrange_type (die
, cu
);
10350 case DW_TAG_base_type
:
10351 this_type
= read_base_type (die
, cu
);
10353 case DW_TAG_unspecified_type
:
10354 this_type
= read_unspecified_type (die
, cu
);
10356 case DW_TAG_namespace
:
10357 this_type
= read_namespace_type (die
, cu
);
10359 case DW_TAG_module
:
10360 this_type
= read_module_type (die
, cu
);
10363 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
10364 dwarf_tag_name (die
->tag
));
10371 /* Return the name of the namespace/class that DIE is defined within,
10372 or "" if we can't tell. The caller should not xfree the result.
10374 For example, if we're within the method foo() in the following
10384 then determine_prefix on foo's die will return "N::C". */
10387 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
10389 struct die_info
*parent
, *spec_die
;
10390 struct dwarf2_cu
*spec_cu
;
10391 struct type
*parent_type
;
10393 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
10394 && cu
->language
!= language_fortran
)
10397 /* We have to be careful in the presence of DW_AT_specification.
10398 For example, with GCC 3.4, given the code
10402 // Definition of N::foo.
10406 then we'll have a tree of DIEs like this:
10408 1: DW_TAG_compile_unit
10409 2: DW_TAG_namespace // N
10410 3: DW_TAG_subprogram // declaration of N::foo
10411 4: DW_TAG_subprogram // definition of N::foo
10412 DW_AT_specification // refers to die #3
10414 Thus, when processing die #4, we have to pretend that we're in
10415 the context of its DW_AT_specification, namely the contex of die
10418 spec_die
= die_specification (die
, &spec_cu
);
10419 if (spec_die
== NULL
)
10420 parent
= die
->parent
;
10423 parent
= spec_die
->parent
;
10427 if (parent
== NULL
)
10430 switch (parent
->tag
)
10432 case DW_TAG_namespace
:
10433 parent_type
= read_type_die (parent
, cu
);
10434 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
10435 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
10436 Work around this problem here. */
10437 if (cu
->language
== language_cplus
10438 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
10440 /* We give a name to even anonymous namespaces. */
10441 return TYPE_TAG_NAME (parent_type
);
10442 case DW_TAG_class_type
:
10443 case DW_TAG_interface_type
:
10444 case DW_TAG_structure_type
:
10445 case DW_TAG_union_type
:
10446 case DW_TAG_module
:
10447 parent_type
= read_type_die (parent
, cu
);
10448 if (TYPE_TAG_NAME (parent_type
) != NULL
)
10449 return TYPE_TAG_NAME (parent_type
);
10451 /* An anonymous structure is only allowed non-static data
10452 members; no typedefs, no member functions, et cetera.
10453 So it does not need a prefix. */
10456 return determine_prefix (parent
, cu
);
10460 /* Return a newly-allocated string formed by concatenating PREFIX and
10461 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
10462 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
10463 perform an obconcat, otherwise allocate storage for the result. The CU argument
10464 is used to determine the language and hence, the appropriate separator. */
10466 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
10469 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
10470 int physname
, struct dwarf2_cu
*cu
)
10472 const char *lead
= "";
10475 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
10477 else if (cu
->language
== language_java
)
10479 else if (cu
->language
== language_fortran
&& physname
)
10481 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
10482 DW_AT_MIPS_linkage_name is preferred and used instead. */
10490 if (prefix
== NULL
)
10492 if (suffix
== NULL
)
10497 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
10499 strcpy (retval
, lead
);
10500 strcat (retval
, prefix
);
10501 strcat (retval
, sep
);
10502 strcat (retval
, suffix
);
10507 /* We have an obstack. */
10508 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
10512 /* Return sibling of die, NULL if no sibling. */
10514 static struct die_info
*
10515 sibling_die (struct die_info
*die
)
10517 return die
->sibling
;
10520 /* Get name of a die, return NULL if not found. */
10523 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
10524 struct obstack
*obstack
)
10526 if (name
&& cu
->language
== language_cplus
)
10528 char *canon_name
= cp_canonicalize_string (name
);
10530 if (canon_name
!= NULL
)
10532 if (strcmp (canon_name
, name
) != 0)
10533 name
= obsavestring (canon_name
, strlen (canon_name
),
10535 xfree (canon_name
);
10542 /* Get name of a die, return NULL if not found. */
10545 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10547 struct attribute
*attr
;
10549 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10550 if (!attr
|| !DW_STRING (attr
))
10555 case DW_TAG_compile_unit
:
10556 /* Compilation units have a DW_AT_name that is a filename, not
10557 a source language identifier. */
10558 case DW_TAG_enumeration_type
:
10559 case DW_TAG_enumerator
:
10560 /* These tags always have simple identifiers already; no need
10561 to canonicalize them. */
10562 return DW_STRING (attr
);
10564 case DW_TAG_subprogram
:
10565 /* Java constructors will all be named "<init>", so return
10566 the class name when we see this special case. */
10567 if (cu
->language
== language_java
10568 && DW_STRING (attr
) != NULL
10569 && strcmp (DW_STRING (attr
), "<init>") == 0)
10571 struct dwarf2_cu
*spec_cu
= cu
;
10572 struct die_info
*spec_die
;
10574 /* GCJ will output '<init>' for Java constructor names.
10575 For this special case, return the name of the parent class. */
10577 /* GCJ may output suprogram DIEs with AT_specification set.
10578 If so, use the name of the specified DIE. */
10579 spec_die
= die_specification (die
, &spec_cu
);
10580 if (spec_die
!= NULL
)
10581 return dwarf2_name (spec_die
, spec_cu
);
10586 if (die
->tag
== DW_TAG_class_type
)
10587 return dwarf2_name (die
, cu
);
10589 while (die
->tag
!= DW_TAG_compile_unit
);
10593 case DW_TAG_class_type
:
10594 case DW_TAG_interface_type
:
10595 case DW_TAG_structure_type
:
10596 case DW_TAG_union_type
:
10597 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
10598 structures or unions. These were of the form "._%d" in GCC 4.1,
10599 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
10600 and GCC 4.4. We work around this problem by ignoring these. */
10601 if (strncmp (DW_STRING (attr
), "._", 2) == 0
10602 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
10610 if (!DW_STRING_IS_CANONICAL (attr
))
10613 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
10614 &cu
->objfile
->objfile_obstack
);
10615 DW_STRING_IS_CANONICAL (attr
) = 1;
10617 return DW_STRING (attr
);
10620 /* Return the die that this die in an extension of, or NULL if there
10621 is none. *EXT_CU is the CU containing DIE on input, and the CU
10622 containing the return value on output. */
10624 static struct die_info
*
10625 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
10627 struct attribute
*attr
;
10629 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
10633 return follow_die_ref (die
, attr
, ext_cu
);
10636 /* Convert a DIE tag into its string name. */
10639 dwarf_tag_name (unsigned tag
)
10643 case DW_TAG_padding
:
10644 return "DW_TAG_padding";
10645 case DW_TAG_array_type
:
10646 return "DW_TAG_array_type";
10647 case DW_TAG_class_type
:
10648 return "DW_TAG_class_type";
10649 case DW_TAG_entry_point
:
10650 return "DW_TAG_entry_point";
10651 case DW_TAG_enumeration_type
:
10652 return "DW_TAG_enumeration_type";
10653 case DW_TAG_formal_parameter
:
10654 return "DW_TAG_formal_parameter";
10655 case DW_TAG_imported_declaration
:
10656 return "DW_TAG_imported_declaration";
10658 return "DW_TAG_label";
10659 case DW_TAG_lexical_block
:
10660 return "DW_TAG_lexical_block";
10661 case DW_TAG_member
:
10662 return "DW_TAG_member";
10663 case DW_TAG_pointer_type
:
10664 return "DW_TAG_pointer_type";
10665 case DW_TAG_reference_type
:
10666 return "DW_TAG_reference_type";
10667 case DW_TAG_compile_unit
:
10668 return "DW_TAG_compile_unit";
10669 case DW_TAG_string_type
:
10670 return "DW_TAG_string_type";
10671 case DW_TAG_structure_type
:
10672 return "DW_TAG_structure_type";
10673 case DW_TAG_subroutine_type
:
10674 return "DW_TAG_subroutine_type";
10675 case DW_TAG_typedef
:
10676 return "DW_TAG_typedef";
10677 case DW_TAG_union_type
:
10678 return "DW_TAG_union_type";
10679 case DW_TAG_unspecified_parameters
:
10680 return "DW_TAG_unspecified_parameters";
10681 case DW_TAG_variant
:
10682 return "DW_TAG_variant";
10683 case DW_TAG_common_block
:
10684 return "DW_TAG_common_block";
10685 case DW_TAG_common_inclusion
:
10686 return "DW_TAG_common_inclusion";
10687 case DW_TAG_inheritance
:
10688 return "DW_TAG_inheritance";
10689 case DW_TAG_inlined_subroutine
:
10690 return "DW_TAG_inlined_subroutine";
10691 case DW_TAG_module
:
10692 return "DW_TAG_module";
10693 case DW_TAG_ptr_to_member_type
:
10694 return "DW_TAG_ptr_to_member_type";
10695 case DW_TAG_set_type
:
10696 return "DW_TAG_set_type";
10697 case DW_TAG_subrange_type
:
10698 return "DW_TAG_subrange_type";
10699 case DW_TAG_with_stmt
:
10700 return "DW_TAG_with_stmt";
10701 case DW_TAG_access_declaration
:
10702 return "DW_TAG_access_declaration";
10703 case DW_TAG_base_type
:
10704 return "DW_TAG_base_type";
10705 case DW_TAG_catch_block
:
10706 return "DW_TAG_catch_block";
10707 case DW_TAG_const_type
:
10708 return "DW_TAG_const_type";
10709 case DW_TAG_constant
:
10710 return "DW_TAG_constant";
10711 case DW_TAG_enumerator
:
10712 return "DW_TAG_enumerator";
10713 case DW_TAG_file_type
:
10714 return "DW_TAG_file_type";
10715 case DW_TAG_friend
:
10716 return "DW_TAG_friend";
10717 case DW_TAG_namelist
:
10718 return "DW_TAG_namelist";
10719 case DW_TAG_namelist_item
:
10720 return "DW_TAG_namelist_item";
10721 case DW_TAG_packed_type
:
10722 return "DW_TAG_packed_type";
10723 case DW_TAG_subprogram
:
10724 return "DW_TAG_subprogram";
10725 case DW_TAG_template_type_param
:
10726 return "DW_TAG_template_type_param";
10727 case DW_TAG_template_value_param
:
10728 return "DW_TAG_template_value_param";
10729 case DW_TAG_thrown_type
:
10730 return "DW_TAG_thrown_type";
10731 case DW_TAG_try_block
:
10732 return "DW_TAG_try_block";
10733 case DW_TAG_variant_part
:
10734 return "DW_TAG_variant_part";
10735 case DW_TAG_variable
:
10736 return "DW_TAG_variable";
10737 case DW_TAG_volatile_type
:
10738 return "DW_TAG_volatile_type";
10739 case DW_TAG_dwarf_procedure
:
10740 return "DW_TAG_dwarf_procedure";
10741 case DW_TAG_restrict_type
:
10742 return "DW_TAG_restrict_type";
10743 case DW_TAG_interface_type
:
10744 return "DW_TAG_interface_type";
10745 case DW_TAG_namespace
:
10746 return "DW_TAG_namespace";
10747 case DW_TAG_imported_module
:
10748 return "DW_TAG_imported_module";
10749 case DW_TAG_unspecified_type
:
10750 return "DW_TAG_unspecified_type";
10751 case DW_TAG_partial_unit
:
10752 return "DW_TAG_partial_unit";
10753 case DW_TAG_imported_unit
:
10754 return "DW_TAG_imported_unit";
10755 case DW_TAG_condition
:
10756 return "DW_TAG_condition";
10757 case DW_TAG_shared_type
:
10758 return "DW_TAG_shared_type";
10759 case DW_TAG_type_unit
:
10760 return "DW_TAG_type_unit";
10761 case DW_TAG_MIPS_loop
:
10762 return "DW_TAG_MIPS_loop";
10763 case DW_TAG_HP_array_descriptor
:
10764 return "DW_TAG_HP_array_descriptor";
10765 case DW_TAG_format_label
:
10766 return "DW_TAG_format_label";
10767 case DW_TAG_function_template
:
10768 return "DW_TAG_function_template";
10769 case DW_TAG_class_template
:
10770 return "DW_TAG_class_template";
10771 case DW_TAG_GNU_BINCL
:
10772 return "DW_TAG_GNU_BINCL";
10773 case DW_TAG_GNU_EINCL
:
10774 return "DW_TAG_GNU_EINCL";
10775 case DW_TAG_upc_shared_type
:
10776 return "DW_TAG_upc_shared_type";
10777 case DW_TAG_upc_strict_type
:
10778 return "DW_TAG_upc_strict_type";
10779 case DW_TAG_upc_relaxed_type
:
10780 return "DW_TAG_upc_relaxed_type";
10781 case DW_TAG_PGI_kanji_type
:
10782 return "DW_TAG_PGI_kanji_type";
10783 case DW_TAG_PGI_interface_block
:
10784 return "DW_TAG_PGI_interface_block";
10786 return "DW_TAG_<unknown>";
10790 /* Convert a DWARF attribute code into its string name. */
10793 dwarf_attr_name (unsigned attr
)
10797 case DW_AT_sibling
:
10798 return "DW_AT_sibling";
10799 case DW_AT_location
:
10800 return "DW_AT_location";
10802 return "DW_AT_name";
10803 case DW_AT_ordering
:
10804 return "DW_AT_ordering";
10805 case DW_AT_subscr_data
:
10806 return "DW_AT_subscr_data";
10807 case DW_AT_byte_size
:
10808 return "DW_AT_byte_size";
10809 case DW_AT_bit_offset
:
10810 return "DW_AT_bit_offset";
10811 case DW_AT_bit_size
:
10812 return "DW_AT_bit_size";
10813 case DW_AT_element_list
:
10814 return "DW_AT_element_list";
10815 case DW_AT_stmt_list
:
10816 return "DW_AT_stmt_list";
10818 return "DW_AT_low_pc";
10819 case DW_AT_high_pc
:
10820 return "DW_AT_high_pc";
10821 case DW_AT_language
:
10822 return "DW_AT_language";
10824 return "DW_AT_member";
10826 return "DW_AT_discr";
10827 case DW_AT_discr_value
:
10828 return "DW_AT_discr_value";
10829 case DW_AT_visibility
:
10830 return "DW_AT_visibility";
10832 return "DW_AT_import";
10833 case DW_AT_string_length
:
10834 return "DW_AT_string_length";
10835 case DW_AT_common_reference
:
10836 return "DW_AT_common_reference";
10837 case DW_AT_comp_dir
:
10838 return "DW_AT_comp_dir";
10839 case DW_AT_const_value
:
10840 return "DW_AT_const_value";
10841 case DW_AT_containing_type
:
10842 return "DW_AT_containing_type";
10843 case DW_AT_default_value
:
10844 return "DW_AT_default_value";
10846 return "DW_AT_inline";
10847 case DW_AT_is_optional
:
10848 return "DW_AT_is_optional";
10849 case DW_AT_lower_bound
:
10850 return "DW_AT_lower_bound";
10851 case DW_AT_producer
:
10852 return "DW_AT_producer";
10853 case DW_AT_prototyped
:
10854 return "DW_AT_prototyped";
10855 case DW_AT_return_addr
:
10856 return "DW_AT_return_addr";
10857 case DW_AT_start_scope
:
10858 return "DW_AT_start_scope";
10859 case DW_AT_bit_stride
:
10860 return "DW_AT_bit_stride";
10861 case DW_AT_upper_bound
:
10862 return "DW_AT_upper_bound";
10863 case DW_AT_abstract_origin
:
10864 return "DW_AT_abstract_origin";
10865 case DW_AT_accessibility
:
10866 return "DW_AT_accessibility";
10867 case DW_AT_address_class
:
10868 return "DW_AT_address_class";
10869 case DW_AT_artificial
:
10870 return "DW_AT_artificial";
10871 case DW_AT_base_types
:
10872 return "DW_AT_base_types";
10873 case DW_AT_calling_convention
:
10874 return "DW_AT_calling_convention";
10876 return "DW_AT_count";
10877 case DW_AT_data_member_location
:
10878 return "DW_AT_data_member_location";
10879 case DW_AT_decl_column
:
10880 return "DW_AT_decl_column";
10881 case DW_AT_decl_file
:
10882 return "DW_AT_decl_file";
10883 case DW_AT_decl_line
:
10884 return "DW_AT_decl_line";
10885 case DW_AT_declaration
:
10886 return "DW_AT_declaration";
10887 case DW_AT_discr_list
:
10888 return "DW_AT_discr_list";
10889 case DW_AT_encoding
:
10890 return "DW_AT_encoding";
10891 case DW_AT_external
:
10892 return "DW_AT_external";
10893 case DW_AT_frame_base
:
10894 return "DW_AT_frame_base";
10896 return "DW_AT_friend";
10897 case DW_AT_identifier_case
:
10898 return "DW_AT_identifier_case";
10899 case DW_AT_macro_info
:
10900 return "DW_AT_macro_info";
10901 case DW_AT_namelist_items
:
10902 return "DW_AT_namelist_items";
10903 case DW_AT_priority
:
10904 return "DW_AT_priority";
10905 case DW_AT_segment
:
10906 return "DW_AT_segment";
10907 case DW_AT_specification
:
10908 return "DW_AT_specification";
10909 case DW_AT_static_link
:
10910 return "DW_AT_static_link";
10912 return "DW_AT_type";
10913 case DW_AT_use_location
:
10914 return "DW_AT_use_location";
10915 case DW_AT_variable_parameter
:
10916 return "DW_AT_variable_parameter";
10917 case DW_AT_virtuality
:
10918 return "DW_AT_virtuality";
10919 case DW_AT_vtable_elem_location
:
10920 return "DW_AT_vtable_elem_location";
10921 /* DWARF 3 values. */
10922 case DW_AT_allocated
:
10923 return "DW_AT_allocated";
10924 case DW_AT_associated
:
10925 return "DW_AT_associated";
10926 case DW_AT_data_location
:
10927 return "DW_AT_data_location";
10928 case DW_AT_byte_stride
:
10929 return "DW_AT_byte_stride";
10930 case DW_AT_entry_pc
:
10931 return "DW_AT_entry_pc";
10932 case DW_AT_use_UTF8
:
10933 return "DW_AT_use_UTF8";
10934 case DW_AT_extension
:
10935 return "DW_AT_extension";
10937 return "DW_AT_ranges";
10938 case DW_AT_trampoline
:
10939 return "DW_AT_trampoline";
10940 case DW_AT_call_column
:
10941 return "DW_AT_call_column";
10942 case DW_AT_call_file
:
10943 return "DW_AT_call_file";
10944 case DW_AT_call_line
:
10945 return "DW_AT_call_line";
10946 case DW_AT_description
:
10947 return "DW_AT_description";
10948 case DW_AT_binary_scale
:
10949 return "DW_AT_binary_scale";
10950 case DW_AT_decimal_scale
:
10951 return "DW_AT_decimal_scale";
10953 return "DW_AT_small";
10954 case DW_AT_decimal_sign
:
10955 return "DW_AT_decimal_sign";
10956 case DW_AT_digit_count
:
10957 return "DW_AT_digit_count";
10958 case DW_AT_picture_string
:
10959 return "DW_AT_picture_string";
10960 case DW_AT_mutable
:
10961 return "DW_AT_mutable";
10962 case DW_AT_threads_scaled
:
10963 return "DW_AT_threads_scaled";
10964 case DW_AT_explicit
:
10965 return "DW_AT_explicit";
10966 case DW_AT_object_pointer
:
10967 return "DW_AT_object_pointer";
10968 case DW_AT_endianity
:
10969 return "DW_AT_endianity";
10970 case DW_AT_elemental
:
10971 return "DW_AT_elemental";
10973 return "DW_AT_pure";
10974 case DW_AT_recursive
:
10975 return "DW_AT_recursive";
10976 /* DWARF 4 values. */
10977 case DW_AT_signature
:
10978 return "DW_AT_signature";
10979 case DW_AT_linkage_name
:
10980 return "DW_AT_linkage_name";
10981 /* SGI/MIPS extensions. */
10982 #ifdef MIPS /* collides with DW_AT_HP_block_index */
10983 case DW_AT_MIPS_fde
:
10984 return "DW_AT_MIPS_fde";
10986 case DW_AT_MIPS_loop_begin
:
10987 return "DW_AT_MIPS_loop_begin";
10988 case DW_AT_MIPS_tail_loop_begin
:
10989 return "DW_AT_MIPS_tail_loop_begin";
10990 case DW_AT_MIPS_epilog_begin
:
10991 return "DW_AT_MIPS_epilog_begin";
10992 case DW_AT_MIPS_loop_unroll_factor
:
10993 return "DW_AT_MIPS_loop_unroll_factor";
10994 case DW_AT_MIPS_software_pipeline_depth
:
10995 return "DW_AT_MIPS_software_pipeline_depth";
10996 case DW_AT_MIPS_linkage_name
:
10997 return "DW_AT_MIPS_linkage_name";
10998 case DW_AT_MIPS_stride
:
10999 return "DW_AT_MIPS_stride";
11000 case DW_AT_MIPS_abstract_name
:
11001 return "DW_AT_MIPS_abstract_name";
11002 case DW_AT_MIPS_clone_origin
:
11003 return "DW_AT_MIPS_clone_origin";
11004 case DW_AT_MIPS_has_inlines
:
11005 return "DW_AT_MIPS_has_inlines";
11006 /* HP extensions. */
11007 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11008 case DW_AT_HP_block_index
:
11009 return "DW_AT_HP_block_index";
11011 case DW_AT_HP_unmodifiable
:
11012 return "DW_AT_HP_unmodifiable";
11013 case DW_AT_HP_actuals_stmt_list
:
11014 return "DW_AT_HP_actuals_stmt_list";
11015 case DW_AT_HP_proc_per_section
:
11016 return "DW_AT_HP_proc_per_section";
11017 case DW_AT_HP_raw_data_ptr
:
11018 return "DW_AT_HP_raw_data_ptr";
11019 case DW_AT_HP_pass_by_reference
:
11020 return "DW_AT_HP_pass_by_reference";
11021 case DW_AT_HP_opt_level
:
11022 return "DW_AT_HP_opt_level";
11023 case DW_AT_HP_prof_version_id
:
11024 return "DW_AT_HP_prof_version_id";
11025 case DW_AT_HP_opt_flags
:
11026 return "DW_AT_HP_opt_flags";
11027 case DW_AT_HP_cold_region_low_pc
:
11028 return "DW_AT_HP_cold_region_low_pc";
11029 case DW_AT_HP_cold_region_high_pc
:
11030 return "DW_AT_HP_cold_region_high_pc";
11031 case DW_AT_HP_all_variables_modifiable
:
11032 return "DW_AT_HP_all_variables_modifiable";
11033 case DW_AT_HP_linkage_name
:
11034 return "DW_AT_HP_linkage_name";
11035 case DW_AT_HP_prof_flags
:
11036 return "DW_AT_HP_prof_flags";
11037 /* GNU extensions. */
11038 case DW_AT_sf_names
:
11039 return "DW_AT_sf_names";
11040 case DW_AT_src_info
:
11041 return "DW_AT_src_info";
11042 case DW_AT_mac_info
:
11043 return "DW_AT_mac_info";
11044 case DW_AT_src_coords
:
11045 return "DW_AT_src_coords";
11046 case DW_AT_body_begin
:
11047 return "DW_AT_body_begin";
11048 case DW_AT_body_end
:
11049 return "DW_AT_body_end";
11050 case DW_AT_GNU_vector
:
11051 return "DW_AT_GNU_vector";
11052 /* VMS extensions. */
11053 case DW_AT_VMS_rtnbeg_pd_address
:
11054 return "DW_AT_VMS_rtnbeg_pd_address";
11055 /* UPC extension. */
11056 case DW_AT_upc_threads_scaled
:
11057 return "DW_AT_upc_threads_scaled";
11058 /* PGI (STMicroelectronics) extensions. */
11059 case DW_AT_PGI_lbase
:
11060 return "DW_AT_PGI_lbase";
11061 case DW_AT_PGI_soffset
:
11062 return "DW_AT_PGI_soffset";
11063 case DW_AT_PGI_lstride
:
11064 return "DW_AT_PGI_lstride";
11066 return "DW_AT_<unknown>";
11070 /* Convert a DWARF value form code into its string name. */
11073 dwarf_form_name (unsigned form
)
11078 return "DW_FORM_addr";
11079 case DW_FORM_block2
:
11080 return "DW_FORM_block2";
11081 case DW_FORM_block4
:
11082 return "DW_FORM_block4";
11083 case DW_FORM_data2
:
11084 return "DW_FORM_data2";
11085 case DW_FORM_data4
:
11086 return "DW_FORM_data4";
11087 case DW_FORM_data8
:
11088 return "DW_FORM_data8";
11089 case DW_FORM_string
:
11090 return "DW_FORM_string";
11091 case DW_FORM_block
:
11092 return "DW_FORM_block";
11093 case DW_FORM_block1
:
11094 return "DW_FORM_block1";
11095 case DW_FORM_data1
:
11096 return "DW_FORM_data1";
11098 return "DW_FORM_flag";
11099 case DW_FORM_sdata
:
11100 return "DW_FORM_sdata";
11102 return "DW_FORM_strp";
11103 case DW_FORM_udata
:
11104 return "DW_FORM_udata";
11105 case DW_FORM_ref_addr
:
11106 return "DW_FORM_ref_addr";
11108 return "DW_FORM_ref1";
11110 return "DW_FORM_ref2";
11112 return "DW_FORM_ref4";
11114 return "DW_FORM_ref8";
11115 case DW_FORM_ref_udata
:
11116 return "DW_FORM_ref_udata";
11117 case DW_FORM_indirect
:
11118 return "DW_FORM_indirect";
11119 case DW_FORM_sec_offset
:
11120 return "DW_FORM_sec_offset";
11121 case DW_FORM_exprloc
:
11122 return "DW_FORM_exprloc";
11123 case DW_FORM_flag_present
:
11124 return "DW_FORM_flag_present";
11126 return "DW_FORM_sig8";
11128 return "DW_FORM_<unknown>";
11132 /* Convert a DWARF stack opcode into its string name. */
11135 dwarf_stack_op_name (unsigned op
, int def
)
11140 return "DW_OP_addr";
11142 return "DW_OP_deref";
11143 case DW_OP_const1u
:
11144 return "DW_OP_const1u";
11145 case DW_OP_const1s
:
11146 return "DW_OP_const1s";
11147 case DW_OP_const2u
:
11148 return "DW_OP_const2u";
11149 case DW_OP_const2s
:
11150 return "DW_OP_const2s";
11151 case DW_OP_const4u
:
11152 return "DW_OP_const4u";
11153 case DW_OP_const4s
:
11154 return "DW_OP_const4s";
11155 case DW_OP_const8u
:
11156 return "DW_OP_const8u";
11157 case DW_OP_const8s
:
11158 return "DW_OP_const8s";
11160 return "DW_OP_constu";
11162 return "DW_OP_consts";
11164 return "DW_OP_dup";
11166 return "DW_OP_drop";
11168 return "DW_OP_over";
11170 return "DW_OP_pick";
11172 return "DW_OP_swap";
11174 return "DW_OP_rot";
11176 return "DW_OP_xderef";
11178 return "DW_OP_abs";
11180 return "DW_OP_and";
11182 return "DW_OP_div";
11184 return "DW_OP_minus";
11186 return "DW_OP_mod";
11188 return "DW_OP_mul";
11190 return "DW_OP_neg";
11192 return "DW_OP_not";
11196 return "DW_OP_plus";
11197 case DW_OP_plus_uconst
:
11198 return "DW_OP_plus_uconst";
11200 return "DW_OP_shl";
11202 return "DW_OP_shr";
11204 return "DW_OP_shra";
11206 return "DW_OP_xor";
11208 return "DW_OP_bra";
11222 return "DW_OP_skip";
11224 return "DW_OP_lit0";
11226 return "DW_OP_lit1";
11228 return "DW_OP_lit2";
11230 return "DW_OP_lit3";
11232 return "DW_OP_lit4";
11234 return "DW_OP_lit5";
11236 return "DW_OP_lit6";
11238 return "DW_OP_lit7";
11240 return "DW_OP_lit8";
11242 return "DW_OP_lit9";
11244 return "DW_OP_lit10";
11246 return "DW_OP_lit11";
11248 return "DW_OP_lit12";
11250 return "DW_OP_lit13";
11252 return "DW_OP_lit14";
11254 return "DW_OP_lit15";
11256 return "DW_OP_lit16";
11258 return "DW_OP_lit17";
11260 return "DW_OP_lit18";
11262 return "DW_OP_lit19";
11264 return "DW_OP_lit20";
11266 return "DW_OP_lit21";
11268 return "DW_OP_lit22";
11270 return "DW_OP_lit23";
11272 return "DW_OP_lit24";
11274 return "DW_OP_lit25";
11276 return "DW_OP_lit26";
11278 return "DW_OP_lit27";
11280 return "DW_OP_lit28";
11282 return "DW_OP_lit29";
11284 return "DW_OP_lit30";
11286 return "DW_OP_lit31";
11288 return "DW_OP_reg0";
11290 return "DW_OP_reg1";
11292 return "DW_OP_reg2";
11294 return "DW_OP_reg3";
11296 return "DW_OP_reg4";
11298 return "DW_OP_reg5";
11300 return "DW_OP_reg6";
11302 return "DW_OP_reg7";
11304 return "DW_OP_reg8";
11306 return "DW_OP_reg9";
11308 return "DW_OP_reg10";
11310 return "DW_OP_reg11";
11312 return "DW_OP_reg12";
11314 return "DW_OP_reg13";
11316 return "DW_OP_reg14";
11318 return "DW_OP_reg15";
11320 return "DW_OP_reg16";
11322 return "DW_OP_reg17";
11324 return "DW_OP_reg18";
11326 return "DW_OP_reg19";
11328 return "DW_OP_reg20";
11330 return "DW_OP_reg21";
11332 return "DW_OP_reg22";
11334 return "DW_OP_reg23";
11336 return "DW_OP_reg24";
11338 return "DW_OP_reg25";
11340 return "DW_OP_reg26";
11342 return "DW_OP_reg27";
11344 return "DW_OP_reg28";
11346 return "DW_OP_reg29";
11348 return "DW_OP_reg30";
11350 return "DW_OP_reg31";
11352 return "DW_OP_breg0";
11354 return "DW_OP_breg1";
11356 return "DW_OP_breg2";
11358 return "DW_OP_breg3";
11360 return "DW_OP_breg4";
11362 return "DW_OP_breg5";
11364 return "DW_OP_breg6";
11366 return "DW_OP_breg7";
11368 return "DW_OP_breg8";
11370 return "DW_OP_breg9";
11372 return "DW_OP_breg10";
11374 return "DW_OP_breg11";
11376 return "DW_OP_breg12";
11378 return "DW_OP_breg13";
11380 return "DW_OP_breg14";
11382 return "DW_OP_breg15";
11384 return "DW_OP_breg16";
11386 return "DW_OP_breg17";
11388 return "DW_OP_breg18";
11390 return "DW_OP_breg19";
11392 return "DW_OP_breg20";
11394 return "DW_OP_breg21";
11396 return "DW_OP_breg22";
11398 return "DW_OP_breg23";
11400 return "DW_OP_breg24";
11402 return "DW_OP_breg25";
11404 return "DW_OP_breg26";
11406 return "DW_OP_breg27";
11408 return "DW_OP_breg28";
11410 return "DW_OP_breg29";
11412 return "DW_OP_breg30";
11414 return "DW_OP_breg31";
11416 return "DW_OP_regx";
11418 return "DW_OP_fbreg";
11420 return "DW_OP_bregx";
11422 return "DW_OP_piece";
11423 case DW_OP_deref_size
:
11424 return "DW_OP_deref_size";
11425 case DW_OP_xderef_size
:
11426 return "DW_OP_xderef_size";
11428 return "DW_OP_nop";
11429 /* DWARF 3 extensions. */
11430 case DW_OP_push_object_address
:
11431 return "DW_OP_push_object_address";
11433 return "DW_OP_call2";
11435 return "DW_OP_call4";
11436 case DW_OP_call_ref
:
11437 return "DW_OP_call_ref";
11438 case DW_OP_form_tls_address
:
11439 return "DW_OP_form_tls_address";
11440 case DW_OP_call_frame_cfa
:
11441 return "DW_OP_call_frame_cfa";
11442 case DW_OP_bit_piece
:
11443 return "DW_OP_bit_piece";
11444 /* DWARF 4 extensions. */
11445 case DW_OP_implicit_value
:
11446 return "DW_OP_implicit_value";
11447 case DW_OP_stack_value
:
11448 return "DW_OP_stack_value";
11449 /* GNU extensions. */
11450 case DW_OP_GNU_push_tls_address
:
11451 return "DW_OP_GNU_push_tls_address";
11452 case DW_OP_GNU_uninit
:
11453 return "DW_OP_GNU_uninit";
11455 return def
? "OP_<unknown>" : NULL
;
11460 dwarf_bool_name (unsigned mybool
)
11468 /* Convert a DWARF type code into its string name. */
11471 dwarf_type_encoding_name (unsigned enc
)
11476 return "DW_ATE_void";
11477 case DW_ATE_address
:
11478 return "DW_ATE_address";
11479 case DW_ATE_boolean
:
11480 return "DW_ATE_boolean";
11481 case DW_ATE_complex_float
:
11482 return "DW_ATE_complex_float";
11484 return "DW_ATE_float";
11485 case DW_ATE_signed
:
11486 return "DW_ATE_signed";
11487 case DW_ATE_signed_char
:
11488 return "DW_ATE_signed_char";
11489 case DW_ATE_unsigned
:
11490 return "DW_ATE_unsigned";
11491 case DW_ATE_unsigned_char
:
11492 return "DW_ATE_unsigned_char";
11494 case DW_ATE_imaginary_float
:
11495 return "DW_ATE_imaginary_float";
11496 case DW_ATE_packed_decimal
:
11497 return "DW_ATE_packed_decimal";
11498 case DW_ATE_numeric_string
:
11499 return "DW_ATE_numeric_string";
11500 case DW_ATE_edited
:
11501 return "DW_ATE_edited";
11502 case DW_ATE_signed_fixed
:
11503 return "DW_ATE_signed_fixed";
11504 case DW_ATE_unsigned_fixed
:
11505 return "DW_ATE_unsigned_fixed";
11506 case DW_ATE_decimal_float
:
11507 return "DW_ATE_decimal_float";
11510 return "DW_ATE_UTF";
11511 /* HP extensions. */
11512 case DW_ATE_HP_float80
:
11513 return "DW_ATE_HP_float80";
11514 case DW_ATE_HP_complex_float80
:
11515 return "DW_ATE_HP_complex_float80";
11516 case DW_ATE_HP_float128
:
11517 return "DW_ATE_HP_float128";
11518 case DW_ATE_HP_complex_float128
:
11519 return "DW_ATE_HP_complex_float128";
11520 case DW_ATE_HP_floathpintel
:
11521 return "DW_ATE_HP_floathpintel";
11522 case DW_ATE_HP_imaginary_float80
:
11523 return "DW_ATE_HP_imaginary_float80";
11524 case DW_ATE_HP_imaginary_float128
:
11525 return "DW_ATE_HP_imaginary_float128";
11527 return "DW_ATE_<unknown>";
11531 /* Convert a DWARF call frame info operation to its string name. */
11535 dwarf_cfi_name (unsigned cfi_opc
)
11539 case DW_CFA_advance_loc
:
11540 return "DW_CFA_advance_loc";
11541 case DW_CFA_offset
:
11542 return "DW_CFA_offset";
11543 case DW_CFA_restore
:
11544 return "DW_CFA_restore";
11546 return "DW_CFA_nop";
11547 case DW_CFA_set_loc
:
11548 return "DW_CFA_set_loc";
11549 case DW_CFA_advance_loc1
:
11550 return "DW_CFA_advance_loc1";
11551 case DW_CFA_advance_loc2
:
11552 return "DW_CFA_advance_loc2";
11553 case DW_CFA_advance_loc4
:
11554 return "DW_CFA_advance_loc4";
11555 case DW_CFA_offset_extended
:
11556 return "DW_CFA_offset_extended";
11557 case DW_CFA_restore_extended
:
11558 return "DW_CFA_restore_extended";
11559 case DW_CFA_undefined
:
11560 return "DW_CFA_undefined";
11561 case DW_CFA_same_value
:
11562 return "DW_CFA_same_value";
11563 case DW_CFA_register
:
11564 return "DW_CFA_register";
11565 case DW_CFA_remember_state
:
11566 return "DW_CFA_remember_state";
11567 case DW_CFA_restore_state
:
11568 return "DW_CFA_restore_state";
11569 case DW_CFA_def_cfa
:
11570 return "DW_CFA_def_cfa";
11571 case DW_CFA_def_cfa_register
:
11572 return "DW_CFA_def_cfa_register";
11573 case DW_CFA_def_cfa_offset
:
11574 return "DW_CFA_def_cfa_offset";
11576 case DW_CFA_def_cfa_expression
:
11577 return "DW_CFA_def_cfa_expression";
11578 case DW_CFA_expression
:
11579 return "DW_CFA_expression";
11580 case DW_CFA_offset_extended_sf
:
11581 return "DW_CFA_offset_extended_sf";
11582 case DW_CFA_def_cfa_sf
:
11583 return "DW_CFA_def_cfa_sf";
11584 case DW_CFA_def_cfa_offset_sf
:
11585 return "DW_CFA_def_cfa_offset_sf";
11586 case DW_CFA_val_offset
:
11587 return "DW_CFA_val_offset";
11588 case DW_CFA_val_offset_sf
:
11589 return "DW_CFA_val_offset_sf";
11590 case DW_CFA_val_expression
:
11591 return "DW_CFA_val_expression";
11592 /* SGI/MIPS specific. */
11593 case DW_CFA_MIPS_advance_loc8
:
11594 return "DW_CFA_MIPS_advance_loc8";
11595 /* GNU extensions. */
11596 case DW_CFA_GNU_window_save
:
11597 return "DW_CFA_GNU_window_save";
11598 case DW_CFA_GNU_args_size
:
11599 return "DW_CFA_GNU_args_size";
11600 case DW_CFA_GNU_negative_offset_extended
:
11601 return "DW_CFA_GNU_negative_offset_extended";
11603 return "DW_CFA_<unknown>";
11609 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
11613 print_spaces (indent
, f
);
11614 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
11615 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
11617 if (die
->parent
!= NULL
)
11619 print_spaces (indent
, f
);
11620 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
11621 die
->parent
->offset
);
11624 print_spaces (indent
, f
);
11625 fprintf_unfiltered (f
, " has children: %s\n",
11626 dwarf_bool_name (die
->child
!= NULL
));
11628 print_spaces (indent
, f
);
11629 fprintf_unfiltered (f
, " attributes:\n");
11631 for (i
= 0; i
< die
->num_attrs
; ++i
)
11633 print_spaces (indent
, f
);
11634 fprintf_unfiltered (f
, " %s (%s) ",
11635 dwarf_attr_name (die
->attrs
[i
].name
),
11636 dwarf_form_name (die
->attrs
[i
].form
));
11638 switch (die
->attrs
[i
].form
)
11640 case DW_FORM_ref_addr
:
11642 fprintf_unfiltered (f
, "address: ");
11643 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
11645 case DW_FORM_block2
:
11646 case DW_FORM_block4
:
11647 case DW_FORM_block
:
11648 case DW_FORM_block1
:
11649 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
11651 case DW_FORM_exprloc
:
11652 fprintf_unfiltered (f
, "expression: size %u",
11653 DW_BLOCK (&die
->attrs
[i
])->size
);
11658 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
11659 (long) (DW_ADDR (&die
->attrs
[i
])));
11661 case DW_FORM_data1
:
11662 case DW_FORM_data2
:
11663 case DW_FORM_data4
:
11664 case DW_FORM_data8
:
11665 case DW_FORM_udata
:
11666 case DW_FORM_sdata
:
11667 fprintf_unfiltered (f
, "constant: %s",
11668 pulongest (DW_UNSND (&die
->attrs
[i
])));
11670 case DW_FORM_sec_offset
:
11671 fprintf_unfiltered (f
, "section offset: %s",
11672 pulongest (DW_UNSND (&die
->attrs
[i
])));
11675 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
11676 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
11677 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
11679 fprintf_unfiltered (f
, "signatured type, offset: unknown");
11681 case DW_FORM_string
:
11683 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
11684 DW_STRING (&die
->attrs
[i
])
11685 ? DW_STRING (&die
->attrs
[i
]) : "",
11686 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
11689 if (DW_UNSND (&die
->attrs
[i
]))
11690 fprintf_unfiltered (f
, "flag: TRUE");
11692 fprintf_unfiltered (f
, "flag: FALSE");
11694 case DW_FORM_flag_present
:
11695 fprintf_unfiltered (f
, "flag: TRUE");
11697 case DW_FORM_indirect
:
11698 /* the reader will have reduced the indirect form to
11699 the "base form" so this form should not occur */
11700 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
11703 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
11704 die
->attrs
[i
].form
);
11707 fprintf_unfiltered (f
, "\n");
11712 dump_die_for_error (struct die_info
*die
)
11714 dump_die_shallow (gdb_stderr
, 0, die
);
11718 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
11720 int indent
= level
* 4;
11722 gdb_assert (die
!= NULL
);
11724 if (level
>= max_level
)
11727 dump_die_shallow (f
, indent
, die
);
11729 if (die
->child
!= NULL
)
11731 print_spaces (indent
, f
);
11732 fprintf_unfiltered (f
, " Children:");
11733 if (level
+ 1 < max_level
)
11735 fprintf_unfiltered (f
, "\n");
11736 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
11740 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
11744 if (die
->sibling
!= NULL
&& level
> 0)
11746 dump_die_1 (f
, level
, max_level
, die
->sibling
);
11750 /* This is called from the pdie macro in gdbinit.in.
11751 It's not static so gcc will keep a copy callable from gdb. */
11754 dump_die (struct die_info
*die
, int max_level
)
11756 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
11760 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
11764 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
11770 is_ref_attr (struct attribute
*attr
)
11772 switch (attr
->form
)
11774 case DW_FORM_ref_addr
:
11779 case DW_FORM_ref_udata
:
11786 static unsigned int
11787 dwarf2_get_ref_die_offset (struct attribute
*attr
)
11789 if (is_ref_attr (attr
))
11790 return DW_ADDR (attr
);
11792 complaint (&symfile_complaints
,
11793 _("unsupported die ref attribute form: '%s'"),
11794 dwarf_form_name (attr
->form
));
11798 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
11799 * the value held by the attribute is not constant. */
11802 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
11804 if (attr
->form
== DW_FORM_sdata
)
11805 return DW_SND (attr
);
11806 else if (attr
->form
== DW_FORM_udata
11807 || attr
->form
== DW_FORM_data1
11808 || attr
->form
== DW_FORM_data2
11809 || attr
->form
== DW_FORM_data4
11810 || attr
->form
== DW_FORM_data8
)
11811 return DW_UNSND (attr
);
11814 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
11815 dwarf_form_name (attr
->form
));
11816 return default_value
;
11820 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
11821 unit and add it to our queue.
11822 The result is non-zero if PER_CU was queued, otherwise the result is zero
11823 meaning either PER_CU is already queued or it is already loaded. */
11826 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
11827 struct dwarf2_per_cu_data
*per_cu
)
11829 /* Mark the dependence relation so that we don't flush PER_CU
11831 dwarf2_add_dependence (this_cu
, per_cu
);
11833 /* If it's already on the queue, we have nothing to do. */
11834 if (per_cu
->queued
)
11837 /* If the compilation unit is already loaded, just mark it as
11839 if (per_cu
->cu
!= NULL
)
11841 per_cu
->cu
->last_used
= 0;
11845 /* Add it to the queue. */
11846 queue_comp_unit (per_cu
, this_cu
->objfile
);
11851 /* Follow reference or signature attribute ATTR of SRC_DIE.
11852 On entry *REF_CU is the CU of SRC_DIE.
11853 On exit *REF_CU is the CU of the result. */
11855 static struct die_info
*
11856 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
11857 struct dwarf2_cu
**ref_cu
)
11859 struct die_info
*die
;
11861 if (is_ref_attr (attr
))
11862 die
= follow_die_ref (src_die
, attr
, ref_cu
);
11863 else if (attr
->form
== DW_FORM_sig8
)
11864 die
= follow_die_sig (src_die
, attr
, ref_cu
);
11867 dump_die_for_error (src_die
);
11868 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
11869 (*ref_cu
)->objfile
->name
);
11875 /* Follow reference OFFSET.
11876 On entry *REF_CU is the CU of source DIE referencing OFFSET.
11877 On exit *REF_CU is the CU of the result. */
11879 static struct die_info
*
11880 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
11882 struct die_info temp_die
;
11883 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
11885 gdb_assert (cu
->per_cu
!= NULL
);
11887 if (cu
->per_cu
->from_debug_types
)
11889 /* .debug_types CUs cannot reference anything outside their CU.
11890 If they need to, they have to reference a signatured type via
11892 if (! offset_in_cu_p (&cu
->header
, offset
))
11896 else if (! offset_in_cu_p (&cu
->header
, offset
))
11898 struct dwarf2_per_cu_data
*per_cu
;
11900 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
11902 /* If necessary, add it to the queue and load its DIEs. */
11903 if (maybe_queue_comp_unit (cu
, per_cu
))
11904 load_full_comp_unit (per_cu
, cu
->objfile
);
11906 target_cu
= per_cu
->cu
;
11911 *ref_cu
= target_cu
;
11912 temp_die
.offset
= offset
;
11913 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
11916 /* Follow reference attribute ATTR of SRC_DIE.
11917 On entry *REF_CU is the CU of SRC_DIE.
11918 On exit *REF_CU is the CU of the result. */
11920 static struct die_info
*
11921 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
11922 struct dwarf2_cu
**ref_cu
)
11924 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11925 struct dwarf2_cu
*cu
= *ref_cu
;
11926 struct die_info
*die
;
11928 die
= follow_die_offset (offset
, ref_cu
);
11930 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
11931 "at 0x%x [in module %s]"),
11932 offset
, src_die
->offset
, cu
->objfile
->name
);
11937 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
11938 value is intended for DW_OP_call*. */
11940 struct dwarf2_locexpr_baton
11941 dwarf2_fetch_die_location_block (unsigned int offset
,
11942 struct dwarf2_per_cu_data
*per_cu
)
11944 struct dwarf2_cu
*cu
= per_cu
->cu
;
11945 struct die_info
*die
;
11946 struct attribute
*attr
;
11947 struct dwarf2_locexpr_baton retval
;
11949 die
= follow_die_offset (offset
, &cu
);
11951 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
11952 offset
, per_cu
->cu
->objfile
->name
);
11954 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11957 /* DWARF: "If there is no such attribute, then there is no effect.". */
11959 retval
.data
= NULL
;
11964 if (!attr_form_is_block (attr
))
11965 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
11966 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
11967 offset
, per_cu
->cu
->objfile
->name
);
11969 retval
.data
= DW_BLOCK (attr
)->data
;
11970 retval
.size
= DW_BLOCK (attr
)->size
;
11972 retval
.per_cu
= cu
->per_cu
;
11976 /* Follow the signature attribute ATTR in SRC_DIE.
11977 On entry *REF_CU is the CU of SRC_DIE.
11978 On exit *REF_CU is the CU of the result. */
11980 static struct die_info
*
11981 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
11982 struct dwarf2_cu
**ref_cu
)
11984 struct objfile
*objfile
= (*ref_cu
)->objfile
;
11985 struct die_info temp_die
;
11986 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11987 struct dwarf2_cu
*sig_cu
;
11988 struct die_info
*die
;
11990 /* sig_type will be NULL if the signatured type is missing from
11992 if (sig_type
== NULL
)
11993 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
11994 "at 0x%x [in module %s]"),
11995 src_die
->offset
, objfile
->name
);
11997 /* If necessary, add it to the queue and load its DIEs. */
11999 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
12000 read_signatured_type (objfile
, sig_type
);
12002 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
12004 sig_cu
= sig_type
->per_cu
.cu
;
12005 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
12006 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
12013 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12014 "at 0x%x [in module %s]"),
12015 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
12018 /* Given an offset of a signatured type, return its signatured_type. */
12020 static struct signatured_type
*
12021 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
12023 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
12024 unsigned int length
, initial_length_size
;
12025 unsigned int sig_offset
;
12026 struct signatured_type find_entry
, *type_sig
;
12028 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
12029 sig_offset
= (initial_length_size
12031 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
12032 + 1 /*address_size*/);
12033 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
12034 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
12036 /* This is only used to lookup previously recorded types.
12037 If we didn't find it, it's our bug. */
12038 gdb_assert (type_sig
!= NULL
);
12039 gdb_assert (offset
== type_sig
->offset
);
12044 /* Read in signatured type at OFFSET and build its CU and die(s). */
12047 read_signatured_type_at_offset (struct objfile
*objfile
,
12048 unsigned int offset
)
12050 struct signatured_type
*type_sig
;
12052 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
12054 /* We have the section offset, but we need the signature to do the
12055 hash table lookup. */
12056 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
12058 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12060 read_signatured_type (objfile
, type_sig
);
12062 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
12065 /* Read in a signatured type and build its CU and DIEs. */
12068 read_signatured_type (struct objfile
*objfile
,
12069 struct signatured_type
*type_sig
)
12071 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
12072 struct die_reader_specs reader_specs
;
12073 struct dwarf2_cu
*cu
;
12074 ULONGEST signature
;
12075 struct cleanup
*back_to
, *free_cu_cleanup
;
12076 struct attribute
*attr
;
12078 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12080 cu
= xmalloc (sizeof (struct dwarf2_cu
));
12081 memset (cu
, 0, sizeof (struct dwarf2_cu
));
12082 obstack_init (&cu
->comp_unit_obstack
);
12083 cu
->objfile
= objfile
;
12084 type_sig
->per_cu
.cu
= cu
;
12085 cu
->per_cu
= &type_sig
->per_cu
;
12087 /* If an error occurs while loading, release our storage. */
12088 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
12090 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
12091 types_ptr
, objfile
->obfd
);
12092 gdb_assert (signature
== type_sig
->signature
);
12095 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12099 &cu
->comp_unit_obstack
,
12100 hashtab_obstack_allocate
,
12101 dummy_obstack_deallocate
);
12103 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
12104 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
12106 init_cu_die_reader (&reader_specs
, cu
);
12108 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
12111 /* We try not to read any attributes in this function, because not
12112 all objfiles needed for references have been loaded yet, and symbol
12113 table processing isn't initialized. But we have to set the CU language,
12114 or we won't be able to build types correctly. */
12115 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
12117 set_cu_language (DW_UNSND (attr
), cu
);
12119 set_cu_language (language_minimal
, cu
);
12121 do_cleanups (back_to
);
12123 /* We've successfully allocated this compilation unit. Let our caller
12124 clean it up when finished with it. */
12125 discard_cleanups (free_cu_cleanup
);
12127 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
12128 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
12131 /* Decode simple location descriptions.
12132 Given a pointer to a dwarf block that defines a location, compute
12133 the location and return the value.
12135 NOTE drow/2003-11-18: This function is called in two situations
12136 now: for the address of static or global variables (partial symbols
12137 only) and for offsets into structures which are expected to be
12138 (more or less) constant. The partial symbol case should go away,
12139 and only the constant case should remain. That will let this
12140 function complain more accurately. A few special modes are allowed
12141 without complaint for global variables (for instance, global
12142 register values and thread-local values).
12144 A location description containing no operations indicates that the
12145 object is optimized out. The return value is 0 for that case.
12146 FIXME drow/2003-11-16: No callers check for this case any more; soon all
12147 callers will only want a very basic result and this can become a
12150 Note that stack[0] is unused except as a default error return.
12151 Note that stack overflow is not yet handled. */
12154 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
12156 struct objfile
*objfile
= cu
->objfile
;
12158 int size
= blk
->size
;
12159 gdb_byte
*data
= blk
->data
;
12160 CORE_ADDR stack
[64];
12162 unsigned int bytes_read
, unsnd
;
12206 stack
[++stacki
] = op
- DW_OP_lit0
;
12241 stack
[++stacki
] = op
- DW_OP_reg0
;
12243 dwarf2_complex_location_expr_complaint ();
12247 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
12249 stack
[++stacki
] = unsnd
;
12251 dwarf2_complex_location_expr_complaint ();
12255 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
12260 case DW_OP_const1u
:
12261 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
12265 case DW_OP_const1s
:
12266 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
12270 case DW_OP_const2u
:
12271 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
12275 case DW_OP_const2s
:
12276 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
12280 case DW_OP_const4u
:
12281 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
12285 case DW_OP_const4s
:
12286 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
12291 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
12297 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
12302 stack
[stacki
+ 1] = stack
[stacki
];
12307 stack
[stacki
- 1] += stack
[stacki
];
12311 case DW_OP_plus_uconst
:
12312 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
12317 stack
[stacki
- 1] -= stack
[stacki
];
12322 /* If we're not the last op, then we definitely can't encode
12323 this using GDB's address_class enum. This is valid for partial
12324 global symbols, although the variable's address will be bogus
12327 dwarf2_complex_location_expr_complaint ();
12330 case DW_OP_GNU_push_tls_address
:
12331 /* The top of the stack has the offset from the beginning
12332 of the thread control block at which the variable is located. */
12333 /* Nothing should follow this operator, so the top of stack would
12335 /* This is valid for partial global symbols, but the variable's
12336 address will be bogus in the psymtab. */
12338 dwarf2_complex_location_expr_complaint ();
12341 case DW_OP_GNU_uninit
:
12345 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
12346 dwarf_stack_op_name (op
, 1));
12347 return (stack
[stacki
]);
12350 return (stack
[stacki
]);
12353 /* memory allocation interface */
12355 static struct dwarf_block
*
12356 dwarf_alloc_block (struct dwarf2_cu
*cu
)
12358 struct dwarf_block
*blk
;
12360 blk
= (struct dwarf_block
*)
12361 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
12365 static struct abbrev_info
*
12366 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
12368 struct abbrev_info
*abbrev
;
12370 abbrev
= (struct abbrev_info
*)
12371 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
12372 memset (abbrev
, 0, sizeof (struct abbrev_info
));
12376 static struct die_info
*
12377 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
12379 struct die_info
*die
;
12380 size_t size
= sizeof (struct die_info
);
12383 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
12385 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
12386 memset (die
, 0, sizeof (struct die_info
));
12391 /* Macro support. */
12394 /* Return the full name of file number I in *LH's file name table.
12395 Use COMP_DIR as the name of the current directory of the
12396 compilation. The result is allocated using xmalloc; the caller is
12397 responsible for freeing it. */
12399 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
12401 /* Is the file number a valid index into the line header's file name
12402 table? Remember that file numbers start with one, not zero. */
12403 if (1 <= file
&& file
<= lh
->num_file_names
)
12405 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12407 if (IS_ABSOLUTE_PATH (fe
->name
))
12408 return xstrdup (fe
->name
);
12416 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12422 dir_len
= strlen (dir
);
12423 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
12424 strcpy (full_name
, dir
);
12425 full_name
[dir_len
] = '/';
12426 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
12430 return xstrdup (fe
->name
);
12435 /* The compiler produced a bogus file number. We can at least
12436 record the macro definitions made in the file, even if we
12437 won't be able to find the file by name. */
12438 char fake_name
[80];
12440 sprintf (fake_name
, "<bad macro file number %d>", file
);
12442 complaint (&symfile_complaints
,
12443 _("bad file number in macro information (%d)"),
12446 return xstrdup (fake_name
);
12451 static struct macro_source_file
*
12452 macro_start_file (int file
, int line
,
12453 struct macro_source_file
*current_file
,
12454 const char *comp_dir
,
12455 struct line_header
*lh
, struct objfile
*objfile
)
12457 /* The full name of this source file. */
12458 char *full_name
= file_full_name (file
, lh
, comp_dir
);
12460 /* We don't create a macro table for this compilation unit
12461 at all until we actually get a filename. */
12462 if (! pending_macros
)
12463 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
12464 objfile
->macro_cache
);
12466 if (! current_file
)
12467 /* If we have no current file, then this must be the start_file
12468 directive for the compilation unit's main source file. */
12469 current_file
= macro_set_main (pending_macros
, full_name
);
12471 current_file
= macro_include (current_file
, line
, full_name
);
12475 return current_file
;
12479 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
12480 followed by a null byte. */
12482 copy_string (const char *buf
, int len
)
12484 char *s
= xmalloc (len
+ 1);
12486 memcpy (s
, buf
, len
);
12492 static const char *
12493 consume_improper_spaces (const char *p
, const char *body
)
12497 complaint (&symfile_complaints
,
12498 _("macro definition contains spaces in formal argument list:\n`%s'"),
12510 parse_macro_definition (struct macro_source_file
*file
, int line
,
12515 /* The body string takes one of two forms. For object-like macro
12516 definitions, it should be:
12518 <macro name> " " <definition>
12520 For function-like macro definitions, it should be:
12522 <macro name> "() " <definition>
12524 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
12526 Spaces may appear only where explicitly indicated, and in the
12529 The Dwarf 2 spec says that an object-like macro's name is always
12530 followed by a space, but versions of GCC around March 2002 omit
12531 the space when the macro's definition is the empty string.
12533 The Dwarf 2 spec says that there should be no spaces between the
12534 formal arguments in a function-like macro's formal argument list,
12535 but versions of GCC around March 2002 include spaces after the
12539 /* Find the extent of the macro name. The macro name is terminated
12540 by either a space or null character (for an object-like macro) or
12541 an opening paren (for a function-like macro). */
12542 for (p
= body
; *p
; p
++)
12543 if (*p
== ' ' || *p
== '(')
12546 if (*p
== ' ' || *p
== '\0')
12548 /* It's an object-like macro. */
12549 int name_len
= p
- body
;
12550 char *name
= copy_string (body
, name_len
);
12551 const char *replacement
;
12554 replacement
= body
+ name_len
+ 1;
12557 dwarf2_macro_malformed_definition_complaint (body
);
12558 replacement
= body
+ name_len
;
12561 macro_define_object (file
, line
, name
, replacement
);
12565 else if (*p
== '(')
12567 /* It's a function-like macro. */
12568 char *name
= copy_string (body
, p
- body
);
12571 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
12575 p
= consume_improper_spaces (p
, body
);
12577 /* Parse the formal argument list. */
12578 while (*p
&& *p
!= ')')
12580 /* Find the extent of the current argument name. */
12581 const char *arg_start
= p
;
12583 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
12586 if (! *p
|| p
== arg_start
)
12587 dwarf2_macro_malformed_definition_complaint (body
);
12590 /* Make sure argv has room for the new argument. */
12591 if (argc
>= argv_size
)
12594 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
12597 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
12600 p
= consume_improper_spaces (p
, body
);
12602 /* Consume the comma, if present. */
12607 p
= consume_improper_spaces (p
, body
);
12616 /* Perfectly formed definition, no complaints. */
12617 macro_define_function (file
, line
, name
,
12618 argc
, (const char **) argv
,
12620 else if (*p
== '\0')
12622 /* Complain, but do define it. */
12623 dwarf2_macro_malformed_definition_complaint (body
);
12624 macro_define_function (file
, line
, name
,
12625 argc
, (const char **) argv
,
12629 /* Just complain. */
12630 dwarf2_macro_malformed_definition_complaint (body
);
12633 /* Just complain. */
12634 dwarf2_macro_malformed_definition_complaint (body
);
12640 for (i
= 0; i
< argc
; i
++)
12646 dwarf2_macro_malformed_definition_complaint (body
);
12651 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
12652 char *comp_dir
, bfd
*abfd
,
12653 struct dwarf2_cu
*cu
)
12655 gdb_byte
*mac_ptr
, *mac_end
;
12656 struct macro_source_file
*current_file
= 0;
12657 enum dwarf_macinfo_record_type macinfo_type
;
12658 int at_commandline
;
12660 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
12661 &dwarf2_per_objfile
->macinfo
);
12662 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
12664 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
12668 /* First pass: Find the name of the base filename.
12669 This filename is needed in order to process all macros whose definition
12670 (or undefinition) comes from the command line. These macros are defined
12671 before the first DW_MACINFO_start_file entry, and yet still need to be
12672 associated to the base file.
12674 To determine the base file name, we scan the macro definitions until we
12675 reach the first DW_MACINFO_start_file entry. We then initialize
12676 CURRENT_FILE accordingly so that any macro definition found before the
12677 first DW_MACINFO_start_file can still be associated to the base file. */
12679 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
12680 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
12681 + dwarf2_per_objfile
->macinfo
.size
;
12685 /* Do we at least have room for a macinfo type byte? */
12686 if (mac_ptr
>= mac_end
)
12688 /* Complaint is printed during the second pass as GDB will probably
12689 stop the first pass earlier upon finding DW_MACINFO_start_file. */
12693 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
12696 switch (macinfo_type
)
12698 /* A zero macinfo type indicates the end of the macro
12703 case DW_MACINFO_define
:
12704 case DW_MACINFO_undef
:
12705 /* Only skip the data by MAC_PTR. */
12707 unsigned int bytes_read
;
12709 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12710 mac_ptr
+= bytes_read
;
12711 read_string (abfd
, mac_ptr
, &bytes_read
);
12712 mac_ptr
+= bytes_read
;
12716 case DW_MACINFO_start_file
:
12718 unsigned int bytes_read
;
12721 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12722 mac_ptr
+= bytes_read
;
12723 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12724 mac_ptr
+= bytes_read
;
12726 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
12731 case DW_MACINFO_end_file
:
12732 /* No data to skip by MAC_PTR. */
12735 case DW_MACINFO_vendor_ext
:
12736 /* Only skip the data by MAC_PTR. */
12738 unsigned int bytes_read
;
12740 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12741 mac_ptr
+= bytes_read
;
12742 read_string (abfd
, mac_ptr
, &bytes_read
);
12743 mac_ptr
+= bytes_read
;
12750 } while (macinfo_type
!= 0 && current_file
== NULL
);
12752 /* Second pass: Process all entries.
12754 Use the AT_COMMAND_LINE flag to determine whether we are still processing
12755 command-line macro definitions/undefinitions. This flag is unset when we
12756 reach the first DW_MACINFO_start_file entry. */
12758 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
12760 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
12761 GDB is still reading the definitions from command line. First
12762 DW_MACINFO_start_file will need to be ignored as it was already executed
12763 to create CURRENT_FILE for the main source holding also the command line
12764 definitions. On first met DW_MACINFO_start_file this flag is reset to
12765 normally execute all the remaining DW_MACINFO_start_file macinfos. */
12767 at_commandline
= 1;
12771 /* Do we at least have room for a macinfo type byte? */
12772 if (mac_ptr
>= mac_end
)
12774 dwarf2_macros_too_long_complaint ();
12778 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
12781 switch (macinfo_type
)
12783 /* A zero macinfo type indicates the end of the macro
12788 case DW_MACINFO_define
:
12789 case DW_MACINFO_undef
:
12791 unsigned int bytes_read
;
12795 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12796 mac_ptr
+= bytes_read
;
12797 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
12798 mac_ptr
+= bytes_read
;
12800 if (! current_file
)
12802 /* DWARF violation as no main source is present. */
12803 complaint (&symfile_complaints
,
12804 _("debug info with no main source gives macro %s "
12806 macinfo_type
== DW_MACINFO_define
?
12808 macinfo_type
== DW_MACINFO_undef
?
12809 _("undefinition") :
12810 _("something-or-other"), line
, body
);
12813 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
12814 complaint (&symfile_complaints
,
12815 _("debug info gives %s macro %s with %s line %d: %s"),
12816 at_commandline
? _("command-line") : _("in-file"),
12817 macinfo_type
== DW_MACINFO_define
?
12819 macinfo_type
== DW_MACINFO_undef
?
12820 _("undefinition") :
12821 _("something-or-other"),
12822 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
12824 if (macinfo_type
== DW_MACINFO_define
)
12825 parse_macro_definition (current_file
, line
, body
);
12826 else if (macinfo_type
== DW_MACINFO_undef
)
12827 macro_undef (current_file
, line
, body
);
12831 case DW_MACINFO_start_file
:
12833 unsigned int bytes_read
;
12836 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12837 mac_ptr
+= bytes_read
;
12838 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12839 mac_ptr
+= bytes_read
;
12841 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
12842 complaint (&symfile_complaints
,
12843 _("debug info gives source %d included "
12844 "from %s at %s line %d"),
12845 file
, at_commandline
? _("command-line") : _("file"),
12846 line
== 0 ? _("zero") : _("non-zero"), line
);
12848 if (at_commandline
)
12850 /* This DW_MACINFO_start_file was executed in the pass one. */
12851 at_commandline
= 0;
12854 current_file
= macro_start_file (file
, line
,
12855 current_file
, comp_dir
,
12860 case DW_MACINFO_end_file
:
12861 if (! current_file
)
12862 complaint (&symfile_complaints
,
12863 _("macro debug info has an unmatched `close_file' directive"));
12866 current_file
= current_file
->included_by
;
12867 if (! current_file
)
12869 enum dwarf_macinfo_record_type next_type
;
12871 /* GCC circa March 2002 doesn't produce the zero
12872 type byte marking the end of the compilation
12873 unit. Complain if it's not there, but exit no
12876 /* Do we at least have room for a macinfo type byte? */
12877 if (mac_ptr
>= mac_end
)
12879 dwarf2_macros_too_long_complaint ();
12883 /* We don't increment mac_ptr here, so this is just
12885 next_type
= read_1_byte (abfd
, mac_ptr
);
12886 if (next_type
!= 0)
12887 complaint (&symfile_complaints
,
12888 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
12895 case DW_MACINFO_vendor_ext
:
12897 unsigned int bytes_read
;
12901 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12902 mac_ptr
+= bytes_read
;
12903 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
12904 mac_ptr
+= bytes_read
;
12906 /* We don't recognize any vendor extensions. */
12910 } while (macinfo_type
!= 0);
12913 /* Check if the attribute's form is a DW_FORM_block*
12914 if so return true else false. */
12916 attr_form_is_block (struct attribute
*attr
)
12918 return (attr
== NULL
? 0 :
12919 attr
->form
== DW_FORM_block1
12920 || attr
->form
== DW_FORM_block2
12921 || attr
->form
== DW_FORM_block4
12922 || attr
->form
== DW_FORM_block
12923 || attr
->form
== DW_FORM_exprloc
);
12926 /* Return non-zero if ATTR's value is a section offset --- classes
12927 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
12928 You may use DW_UNSND (attr) to retrieve such offsets.
12930 Section 7.5.4, "Attribute Encodings", explains that no attribute
12931 may have a value that belongs to more than one of these classes; it
12932 would be ambiguous if we did, because we use the same forms for all
12935 attr_form_is_section_offset (struct attribute
*attr
)
12937 return (attr
->form
== DW_FORM_data4
12938 || attr
->form
== DW_FORM_data8
12939 || attr
->form
== DW_FORM_sec_offset
);
12943 /* Return non-zero if ATTR's value falls in the 'constant' class, or
12944 zero otherwise. When this function returns true, you can apply
12945 dwarf2_get_attr_constant_value to it.
12947 However, note that for some attributes you must check
12948 attr_form_is_section_offset before using this test. DW_FORM_data4
12949 and DW_FORM_data8 are members of both the constant class, and of
12950 the classes that contain offsets into other debug sections
12951 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
12952 that, if an attribute's can be either a constant or one of the
12953 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
12954 taken as section offsets, not constants. */
12956 attr_form_is_constant (struct attribute
*attr
)
12958 switch (attr
->form
)
12960 case DW_FORM_sdata
:
12961 case DW_FORM_udata
:
12962 case DW_FORM_data1
:
12963 case DW_FORM_data2
:
12964 case DW_FORM_data4
:
12965 case DW_FORM_data8
:
12973 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
12974 struct dwarf2_cu
*cu
)
12976 if (attr_form_is_section_offset (attr
)
12977 /* ".debug_loc" may not exist at all, or the offset may be outside
12978 the section. If so, fall through to the complaint in the
12980 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
12982 struct dwarf2_loclist_baton
*baton
;
12984 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
12985 sizeof (struct dwarf2_loclist_baton
));
12986 baton
->per_cu
= cu
->per_cu
;
12987 gdb_assert (baton
->per_cu
);
12989 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
12990 &dwarf2_per_objfile
->loc
);
12992 /* We don't know how long the location list is, but make sure we
12993 don't run off the edge of the section. */
12994 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
12995 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
12996 baton
->base_address
= cu
->base_address
;
12997 if (cu
->base_known
== 0)
12998 complaint (&symfile_complaints
,
12999 _("Location list used without specifying the CU base address."));
13001 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
13002 SYMBOL_LOCATION_BATON (sym
) = baton
;
13006 struct dwarf2_locexpr_baton
*baton
;
13008 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13009 sizeof (struct dwarf2_locexpr_baton
));
13010 baton
->per_cu
= cu
->per_cu
;
13011 gdb_assert (baton
->per_cu
);
13013 if (attr_form_is_block (attr
))
13015 /* Note that we're just copying the block's data pointer
13016 here, not the actual data. We're still pointing into the
13017 info_buffer for SYM's objfile; right now we never release
13018 that buffer, but when we do clean up properly this may
13020 baton
->size
= DW_BLOCK (attr
)->size
;
13021 baton
->data
= DW_BLOCK (attr
)->data
;
13025 dwarf2_invalid_attrib_class_complaint ("location description",
13026 SYMBOL_NATURAL_NAME (sym
));
13028 baton
->data
= NULL
;
13031 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13032 SYMBOL_LOCATION_BATON (sym
) = baton
;
13036 /* Return the OBJFILE associated with the compilation unit CU. If CU
13037 came from a separate debuginfo file, then the master objfile is
13041 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
13043 struct objfile
*objfile
= per_cu
->objfile
;
13045 /* Return the master objfile, so that we can report and look up the
13046 correct file containing this variable. */
13047 if (objfile
->separate_debug_objfile_backlink
)
13048 objfile
= objfile
->separate_debug_objfile_backlink
;
13053 /* Return the address size given in the compilation unit header for CU. */
13056 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
13059 return per_cu
->cu
->header
.addr_size
;
13062 /* If the CU is not currently read in, we re-read its header. */
13063 struct objfile
*objfile
= per_cu
->objfile
;
13064 struct dwarf2_per_objfile
*per_objfile
13065 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13066 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13067 struct comp_unit_head cu_header
;
13069 memset (&cu_header
, 0, sizeof cu_header
);
13070 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13071 return cu_header
.addr_size
;
13075 /* Return the offset size given in the compilation unit header for CU. */
13078 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
13081 return per_cu
->cu
->header
.offset_size
;
13084 /* If the CU is not currently read in, we re-read its header. */
13085 struct objfile
*objfile
= per_cu
->objfile
;
13086 struct dwarf2_per_objfile
*per_objfile
13087 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13088 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13089 struct comp_unit_head cu_header
;
13091 memset (&cu_header
, 0, sizeof cu_header
);
13092 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13093 return cu_header
.offset_size
;
13097 /* Return the text offset of the CU. The returned offset comes from
13098 this CU's objfile. If this objfile came from a separate debuginfo
13099 file, then the offset may be different from the corresponding
13100 offset in the parent objfile. */
13103 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
13105 struct objfile
*objfile
= per_cu
->objfile
;
13107 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13110 /* Locate the .debug_info compilation unit from CU's objfile which contains
13111 the DIE at OFFSET. Raises an error on failure. */
13113 static struct dwarf2_per_cu_data
*
13114 dwarf2_find_containing_comp_unit (unsigned int offset
,
13115 struct objfile
*objfile
)
13117 struct dwarf2_per_cu_data
*this_cu
;
13121 high
= dwarf2_per_objfile
->n_comp_units
- 1;
13124 int mid
= low
+ (high
- low
) / 2;
13126 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
13131 gdb_assert (low
== high
);
13132 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
13135 error (_("Dwarf Error: could not find partial DIE containing "
13136 "offset 0x%lx [in module %s]"),
13137 (long) offset
, bfd_get_filename (objfile
->obfd
));
13139 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
13140 return dwarf2_per_objfile
->all_comp_units
[low
-1];
13144 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
13145 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
13146 && offset
>= this_cu
->offset
+ this_cu
->length
)
13147 error (_("invalid dwarf2 offset %u"), offset
);
13148 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
13153 /* Locate the compilation unit from OBJFILE which is located at exactly
13154 OFFSET. Raises an error on failure. */
13156 static struct dwarf2_per_cu_data
*
13157 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
13159 struct dwarf2_per_cu_data
*this_cu
;
13161 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
13162 if (this_cu
->offset
!= offset
)
13163 error (_("no compilation unit with offset %u."), offset
);
13167 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
13169 static struct dwarf2_cu
*
13170 alloc_one_comp_unit (struct objfile
*objfile
)
13172 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
13173 cu
->objfile
= objfile
;
13174 obstack_init (&cu
->comp_unit_obstack
);
13178 /* Release one cached compilation unit, CU. We unlink it from the tree
13179 of compilation units, but we don't remove it from the read_in_chain;
13180 the caller is responsible for that.
13181 NOTE: DATA is a void * because this function is also used as a
13182 cleanup routine. */
13185 free_one_comp_unit (void *data
)
13187 struct dwarf2_cu
*cu
= data
;
13189 if (cu
->per_cu
!= NULL
)
13190 cu
->per_cu
->cu
= NULL
;
13193 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13198 /* This cleanup function is passed the address of a dwarf2_cu on the stack
13199 when we're finished with it. We can't free the pointer itself, but be
13200 sure to unlink it from the cache. Also release any associated storage
13201 and perform cache maintenance.
13203 Only used during partial symbol parsing. */
13206 free_stack_comp_unit (void *data
)
13208 struct dwarf2_cu
*cu
= data
;
13210 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13211 cu
->partial_dies
= NULL
;
13213 if (cu
->per_cu
!= NULL
)
13215 /* This compilation unit is on the stack in our caller, so we
13216 should not xfree it. Just unlink it. */
13217 cu
->per_cu
->cu
= NULL
;
13220 /* If we had a per-cu pointer, then we may have other compilation
13221 units loaded, so age them now. */
13222 age_cached_comp_units ();
13226 /* Free all cached compilation units. */
13229 free_cached_comp_units (void *data
)
13231 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13233 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13234 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13235 while (per_cu
!= NULL
)
13237 struct dwarf2_per_cu_data
*next_cu
;
13239 next_cu
= per_cu
->cu
->read_in_chain
;
13241 free_one_comp_unit (per_cu
->cu
);
13242 *last_chain
= next_cu
;
13248 /* Increase the age counter on each cached compilation unit, and free
13249 any that are too old. */
13252 age_cached_comp_units (void)
13254 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13256 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
13257 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13258 while (per_cu
!= NULL
)
13260 per_cu
->cu
->last_used
++;
13261 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
13262 dwarf2_mark (per_cu
->cu
);
13263 per_cu
= per_cu
->cu
->read_in_chain
;
13266 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13267 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13268 while (per_cu
!= NULL
)
13270 struct dwarf2_per_cu_data
*next_cu
;
13272 next_cu
= per_cu
->cu
->read_in_chain
;
13274 if (!per_cu
->cu
->mark
)
13276 free_one_comp_unit (per_cu
->cu
);
13277 *last_chain
= next_cu
;
13280 last_chain
= &per_cu
->cu
->read_in_chain
;
13286 /* Remove a single compilation unit from the cache. */
13289 free_one_cached_comp_unit (void *target_cu
)
13291 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13293 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13294 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13295 while (per_cu
!= NULL
)
13297 struct dwarf2_per_cu_data
*next_cu
;
13299 next_cu
= per_cu
->cu
->read_in_chain
;
13301 if (per_cu
->cu
== target_cu
)
13303 free_one_comp_unit (per_cu
->cu
);
13304 *last_chain
= next_cu
;
13308 last_chain
= &per_cu
->cu
->read_in_chain
;
13314 /* Release all extra memory associated with OBJFILE. */
13317 dwarf2_free_objfile (struct objfile
*objfile
)
13319 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
13321 if (dwarf2_per_objfile
== NULL
)
13324 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
13325 free_cached_comp_units (NULL
);
13327 if (dwarf2_per_objfile
->using_index
)
13331 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
13334 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
13336 if (!cu
->v
.quick
->lines
)
13339 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
13341 if (cu
->v
.quick
->file_names
)
13342 xfree ((void *) cu
->v
.quick
->file_names
[j
]);
13343 if (cu
->v
.quick
->full_names
)
13344 xfree ((void *) cu
->v
.quick
->full_names
[j
]);
13347 free_line_header (cu
->v
.quick
->lines
);
13351 /* Everything else should be on the objfile obstack. */
13354 /* A pair of DIE offset and GDB type pointer. We store these
13355 in a hash table separate from the DIEs, and preserve them
13356 when the DIEs are flushed out of cache. */
13358 struct dwarf2_offset_and_type
13360 unsigned int offset
;
13364 /* Hash function for a dwarf2_offset_and_type. */
13367 offset_and_type_hash (const void *item
)
13369 const struct dwarf2_offset_and_type
*ofs
= item
;
13371 return ofs
->offset
;
13374 /* Equality function for a dwarf2_offset_and_type. */
13377 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
13379 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
13380 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
13382 return ofs_lhs
->offset
== ofs_rhs
->offset
;
13385 /* Set the type associated with DIE to TYPE. Save it in CU's hash
13386 table if necessary. For convenience, return TYPE.
13388 The DIEs reading must have careful ordering to:
13389 * Not cause infite loops trying to read in DIEs as a prerequisite for
13390 reading current DIE.
13391 * Not trying to dereference contents of still incompletely read in types
13392 while reading in other DIEs.
13393 * Enable referencing still incompletely read in types just by a pointer to
13394 the type without accessing its fields.
13396 Therefore caller should follow these rules:
13397 * Try to fetch any prerequisite types we may need to build this DIE type
13398 before building the type and calling set_die_type.
13399 * After building typer call set_die_type for current DIE as soon as
13400 possible before fetching more types to complete the current type.
13401 * Make the type as complete as possible before fetching more types. */
13403 static struct type
*
13404 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13406 struct dwarf2_offset_and_type
**slot
, ofs
;
13408 /* For Ada types, make sure that the gnat-specific data is always
13409 initialized (if not already set). There are a few types where
13410 we should not be doing so, because the type-specific area is
13411 already used to hold some other piece of info (eg: TYPE_CODE_FLT
13412 where the type-specific area is used to store the floatformat).
13413 But this is not a problem, because the gnat-specific information
13414 is actually not needed for these types. */
13415 if (need_gnat_info (cu
)
13416 && TYPE_CODE (type
) != TYPE_CODE_FUNC
13417 && TYPE_CODE (type
) != TYPE_CODE_FLT
13418 && !HAVE_GNAT_AUX_INFO (type
))
13419 INIT_GNAT_SPECIFIC (type
);
13421 if (cu
->type_hash
== NULL
)
13423 gdb_assert (cu
->per_cu
!= NULL
);
13424 cu
->per_cu
->type_hash
13425 = htab_create_alloc_ex (cu
->header
.length
/ 24,
13426 offset_and_type_hash
,
13427 offset_and_type_eq
,
13429 &cu
->objfile
->objfile_obstack
,
13430 hashtab_obstack_allocate
,
13431 dummy_obstack_deallocate
);
13432 cu
->type_hash
= cu
->per_cu
->type_hash
;
13435 ofs
.offset
= die
->offset
;
13437 slot
= (struct dwarf2_offset_and_type
**)
13438 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
13440 complaint (&symfile_complaints
,
13441 _("A problem internal to GDB: DIE 0x%x has type already set"),
13443 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
13448 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
13449 not have a saved type. */
13451 static struct type
*
13452 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13454 struct dwarf2_offset_and_type
*slot
, ofs
;
13455 htab_t type_hash
= cu
->type_hash
;
13457 if (type_hash
== NULL
)
13460 ofs
.offset
= die
->offset
;
13461 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
13468 /* Add a dependence relationship from CU to REF_PER_CU. */
13471 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
13472 struct dwarf2_per_cu_data
*ref_per_cu
)
13476 if (cu
->dependencies
== NULL
)
13478 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
13479 NULL
, &cu
->comp_unit_obstack
,
13480 hashtab_obstack_allocate
,
13481 dummy_obstack_deallocate
);
13483 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
13485 *slot
= ref_per_cu
;
13488 /* Subroutine of dwarf2_mark to pass to htab_traverse.
13489 Set the mark field in every compilation unit in the
13490 cache that we must keep because we are keeping CU. */
13493 dwarf2_mark_helper (void **slot
, void *data
)
13495 struct dwarf2_per_cu_data
*per_cu
;
13497 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
13498 if (per_cu
->cu
->mark
)
13500 per_cu
->cu
->mark
= 1;
13502 if (per_cu
->cu
->dependencies
!= NULL
)
13503 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
13508 /* Set the mark field in CU and in every other compilation unit in the
13509 cache that we must keep because we are keeping CU. */
13512 dwarf2_mark (struct dwarf2_cu
*cu
)
13517 if (cu
->dependencies
!= NULL
)
13518 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
13522 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
13526 per_cu
->cu
->mark
= 0;
13527 per_cu
= per_cu
->cu
->read_in_chain
;
13531 /* Trivial hash function for partial_die_info: the hash value of a DIE
13532 is its offset in .debug_info for this objfile. */
13535 partial_die_hash (const void *item
)
13537 const struct partial_die_info
*part_die
= item
;
13539 return part_die
->offset
;
13542 /* Trivial comparison function for partial_die_info structures: two DIEs
13543 are equal if they have the same offset. */
13546 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
13548 const struct partial_die_info
*part_die_lhs
= item_lhs
;
13549 const struct partial_die_info
*part_die_rhs
= item_rhs
;
13551 return part_die_lhs
->offset
== part_die_rhs
->offset
;
13554 static struct cmd_list_element
*set_dwarf2_cmdlist
;
13555 static struct cmd_list_element
*show_dwarf2_cmdlist
;
13558 set_dwarf2_cmd (char *args
, int from_tty
)
13560 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
13564 show_dwarf2_cmd (char *args
, int from_tty
)
13566 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
13569 /* If section described by INFO was mmapped, munmap it now. */
13572 munmap_section_buffer (struct dwarf2_section_info
*info
)
13574 if (info
->was_mmapped
)
13577 intptr_t begin
= (intptr_t) info
->buffer
;
13578 intptr_t map_begin
= begin
& ~(pagesize
- 1);
13579 size_t map_length
= info
->size
+ begin
- map_begin
;
13581 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
13583 /* Without HAVE_MMAP, we should never be here to begin with. */
13589 /* munmap debug sections for OBJFILE, if necessary. */
13592 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
13594 struct dwarf2_per_objfile
*data
= d
;
13596 munmap_section_buffer (&data
->info
);
13597 munmap_section_buffer (&data
->abbrev
);
13598 munmap_section_buffer (&data
->line
);
13599 munmap_section_buffer (&data
->str
);
13600 munmap_section_buffer (&data
->macinfo
);
13601 munmap_section_buffer (&data
->ranges
);
13602 munmap_section_buffer (&data
->loc
);
13603 munmap_section_buffer (&data
->frame
);
13604 munmap_section_buffer (&data
->eh_frame
);
13605 munmap_section_buffer (&data
->gdb_index
);
13610 /* The contents of the hash table we create when building the string
13612 struct strtab_entry
13614 offset_type offset
;
13618 /* Hash function for a strtab_entry. */
13620 hash_strtab_entry (const void *e
)
13622 const struct strtab_entry
*entry
= e
;
13623 return mapped_index_string_hash (entry
->str
);
13626 /* Equality function for a strtab_entry. */
13628 eq_strtab_entry (const void *a
, const void *b
)
13630 const struct strtab_entry
*ea
= a
;
13631 const struct strtab_entry
*eb
= b
;
13632 return !strcmp (ea
->str
, eb
->str
);
13635 /* Create a strtab_entry hash table. */
13637 create_strtab (void)
13639 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
13640 xfree
, xcalloc
, xfree
);
13643 /* Add a string to the constant pool. Return the string's offset in
13646 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
13649 struct strtab_entry entry
;
13650 struct strtab_entry
*result
;
13653 slot
= htab_find_slot (table
, &entry
, INSERT
);
13658 result
= XNEW (struct strtab_entry
);
13659 result
->offset
= obstack_object_size (cpool
);
13661 obstack_grow_str0 (cpool
, str
);
13664 return result
->offset
;
13667 /* An entry in the symbol table. */
13668 struct symtab_index_entry
13670 /* The name of the symbol. */
13672 /* The offset of the name in the constant pool. */
13673 offset_type index_offset
;
13674 /* A sorted vector of the indices of all the CUs that hold an object
13676 VEC (offset_type
) *cu_indices
;
13679 /* The symbol table. This is a power-of-2-sized hash table. */
13680 struct mapped_symtab
13682 offset_type n_elements
;
13684 struct symtab_index_entry
**data
;
13687 /* Hash function for a symtab_index_entry. */
13689 hash_symtab_entry (const void *e
)
13691 const struct symtab_index_entry
*entry
= e
;
13692 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
13693 sizeof (offset_type
) * VEC_length (offset_type
,
13694 entry
->cu_indices
),
13698 /* Equality function for a symtab_index_entry. */
13700 eq_symtab_entry (const void *a
, const void *b
)
13702 const struct symtab_index_entry
*ea
= a
;
13703 const struct symtab_index_entry
*eb
= b
;
13704 int len
= VEC_length (offset_type
, ea
->cu_indices
);
13705 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
13707 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
13708 VEC_address (offset_type
, eb
->cu_indices
),
13709 sizeof (offset_type
) * len
);
13712 /* Destroy a symtab_index_entry. */
13714 delete_symtab_entry (void *p
)
13716 struct symtab_index_entry
*entry
= p
;
13717 VEC_free (offset_type
, entry
->cu_indices
);
13721 /* Create a hash table holding symtab_index_entry objects. */
13723 create_index_table (void)
13725 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
13726 delete_symtab_entry
, xcalloc
, xfree
);
13729 /* Create a new mapped symtab object. */
13730 static struct mapped_symtab
*
13731 create_mapped_symtab (void)
13733 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
13734 symtab
->n_elements
= 0;
13735 symtab
->size
= 1024;
13736 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
13740 /* Destroy a mapped_symtab. */
13742 cleanup_mapped_symtab (void *p
)
13744 struct mapped_symtab
*symtab
= p
;
13745 /* The contents of the array are freed when the other hash table is
13747 xfree (symtab
->data
);
13751 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
13753 static struct symtab_index_entry
**
13754 find_slot (struct mapped_symtab
*symtab
, const char *name
)
13756 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
13758 index
= hash
& (symtab
->size
- 1);
13759 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
13763 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
13764 return &symtab
->data
[index
];
13765 index
= (index
+ step
) & (symtab
->size
- 1);
13769 /* Expand SYMTAB's hash table. */
13771 hash_expand (struct mapped_symtab
*symtab
)
13773 offset_type old_size
= symtab
->size
;
13775 struct symtab_index_entry
**old_entries
= symtab
->data
;
13778 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
13780 for (i
= 0; i
< old_size
; ++i
)
13782 if (old_entries
[i
])
13784 struct symtab_index_entry
**slot
= find_slot (symtab
,
13785 old_entries
[i
]->name
);
13786 *slot
= old_entries
[i
];
13790 xfree (old_entries
);
13793 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
13794 is the index of the CU in which the symbol appears. */
13796 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
13797 offset_type cu_index
)
13799 struct symtab_index_entry
**slot
;
13801 ++symtab
->n_elements
;
13802 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
13803 hash_expand (symtab
);
13805 slot
= find_slot (symtab
, name
);
13808 *slot
= XNEW (struct symtab_index_entry
);
13809 (*slot
)->name
= name
;
13810 (*slot
)->cu_indices
= NULL
;
13812 /* Don't push an index twice. Due to how we add entries we only
13813 have to check the last one. */
13814 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
13815 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
13816 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
13819 /* Add a vector of indices to the constant pool. */
13821 add_indices_to_cpool (htab_t index_table
, struct obstack
*cpool
,
13822 struct symtab_index_entry
*entry
)
13826 slot
= htab_find_slot (index_table
, entry
, INSERT
);
13829 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
13830 offset_type val
= MAYBE_SWAP (len
);
13835 entry
->index_offset
= obstack_object_size (cpool
);
13837 obstack_grow (cpool
, &val
, sizeof (val
));
13839 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
13842 val
= MAYBE_SWAP (iter
);
13843 obstack_grow (cpool
, &val
, sizeof (val
));
13848 struct symtab_index_entry
*old_entry
= *slot
;
13849 entry
->index_offset
= old_entry
->index_offset
;
13852 return entry
->index_offset
;
13855 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
13856 constant pool entries going into the obstack CPOOL. */
13858 write_hash_table (struct mapped_symtab
*symtab
,
13859 struct obstack
*output
, struct obstack
*cpool
)
13862 htab_t index_table
;
13865 index_table
= create_index_table ();
13866 str_table
= create_strtab ();
13867 /* We add all the index vectors to the constant pool first, to
13868 ensure alignment is ok. */
13869 for (i
= 0; i
< symtab
->size
; ++i
)
13871 if (symtab
->data
[i
])
13872 add_indices_to_cpool (index_table
, cpool
, symtab
->data
[i
]);
13875 /* Now write out the hash table. */
13876 for (i
= 0; i
< symtab
->size
; ++i
)
13878 offset_type str_off
, vec_off
;
13880 if (symtab
->data
[i
])
13882 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
13883 vec_off
= symtab
->data
[i
]->index_offset
;
13887 /* While 0 is a valid constant pool index, it is not valid
13888 to have 0 for both offsets. */
13893 str_off
= MAYBE_SWAP (str_off
);
13894 vec_off
= MAYBE_SWAP (vec_off
);
13896 obstack_grow (output
, &str_off
, sizeof (str_off
));
13897 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
13900 htab_delete (str_table
);
13901 htab_delete (index_table
);
13904 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
13905 from PST; CU_INDEX is the index of the CU in the vector of all
13908 add_address_entry (struct objfile
*objfile
,
13909 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
13910 unsigned int cu_index
)
13912 offset_type offset
;
13914 CORE_ADDR baseaddr
;
13916 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13918 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
13919 obstack_grow (addr_obstack
, addr
, 8);
13920 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
13921 obstack_grow (addr_obstack
, addr
, 8);
13922 offset
= MAYBE_SWAP (cu_index
);
13923 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
13926 /* Add a list of partial symbols to SYMTAB. */
13928 write_psymbols (struct mapped_symtab
*symtab
,
13929 struct partial_symbol
**psymp
,
13931 offset_type cu_index
)
13933 for (; count
-- > 0; ++psymp
)
13935 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
13936 error (_("Ada is not currently supported by the index"));
13937 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
13941 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
13942 exception if there is an error. */
13944 write_obstack (FILE *file
, struct obstack
*obstack
)
13946 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
13948 != obstack_object_size (obstack
))
13949 error (_("couldn't data write to file"));
13952 /* Unlink a file if the argument is not NULL. */
13954 unlink_if_set (void *p
)
13956 char **filename
= p
;
13958 unlink (*filename
);
13961 /* Create an index file for OBJFILE in the directory DIR. */
13963 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
13965 struct cleanup
*cleanup
;
13966 char *filename
, *cleanup_filename
;
13967 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
, cu_list
;
13970 struct mapped_symtab
*symtab
;
13971 offset_type val
, size_of_contents
, total_len
;
13975 if (!objfile
->psymtabs
)
13977 if (dwarf2_per_objfile
->using_index
)
13978 error (_("Cannot use an index to create the index"));
13980 if (stat (objfile
->name
, &st
) < 0)
13981 perror_with_name (_("Could not stat"));
13983 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
13984 INDEX_SUFFIX
, (char *) NULL
);
13985 cleanup
= make_cleanup (xfree
, filename
);
13987 out_file
= fopen (filename
, "wb");
13989 error (_("Can't open `%s' for writing"), filename
);
13991 cleanup_filename
= filename
;
13992 make_cleanup (unlink_if_set
, &cleanup_filename
);
13994 symtab
= create_mapped_symtab ();
13995 make_cleanup (cleanup_mapped_symtab
, symtab
);
13997 obstack_init (&addr_obstack
);
13998 make_cleanup_obstack_free (&addr_obstack
);
14000 obstack_init (&cu_list
);
14001 make_cleanup_obstack_free (&cu_list
);
14003 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14005 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
14006 struct partial_symtab
*psymtab
= cu
->v
.psymtab
;
14009 write_psymbols (symtab
,
14010 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
14011 psymtab
->n_global_syms
, i
);
14012 write_psymbols (symtab
,
14013 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
14014 psymtab
->n_static_syms
, i
);
14016 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
14018 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->offset
);
14019 obstack_grow (&cu_list
, val
, 8);
14020 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->length
);
14021 obstack_grow (&cu_list
, val
, 8);
14024 obstack_init (&constant_pool
);
14025 make_cleanup_obstack_free (&constant_pool
);
14026 obstack_init (&symtab_obstack
);
14027 make_cleanup_obstack_free (&symtab_obstack
);
14028 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
14030 obstack_init (&contents
);
14031 make_cleanup_obstack_free (&contents
);
14032 size_of_contents
= 5 * sizeof (offset_type
);
14033 total_len
= size_of_contents
;
14035 /* The version number. */
14036 val
= MAYBE_SWAP (1);
14037 obstack_grow (&contents
, &val
, sizeof (val
));
14039 /* The offset of the CU list from the start of the file. */
14040 val
= MAYBE_SWAP (total_len
);
14041 obstack_grow (&contents
, &val
, sizeof (val
));
14042 total_len
+= obstack_object_size (&cu_list
);
14044 /* The offset of the address table from the start of the file. */
14045 val
= MAYBE_SWAP (total_len
);
14046 obstack_grow (&contents
, &val
, sizeof (val
));
14047 total_len
+= obstack_object_size (&addr_obstack
);
14049 /* The offset of the symbol table from the start of the file. */
14050 val
= MAYBE_SWAP (total_len
);
14051 obstack_grow (&contents
, &val
, sizeof (val
));
14052 total_len
+= obstack_object_size (&symtab_obstack
);
14054 /* The offset of the constant pool from the start of the file. */
14055 val
= MAYBE_SWAP (total_len
);
14056 obstack_grow (&contents
, &val
, sizeof (val
));
14057 total_len
+= obstack_object_size (&constant_pool
);
14059 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
14061 write_obstack (out_file
, &contents
);
14062 write_obstack (out_file
, &cu_list
);
14063 write_obstack (out_file
, &addr_obstack
);
14064 write_obstack (out_file
, &symtab_obstack
);
14065 write_obstack (out_file
, &constant_pool
);
14069 /* We want to keep the file, so we set cleanup_filename to NULL
14070 here. See unlink_if_set. */
14071 cleanup_filename
= NULL
;
14073 do_cleanups (cleanup
);
14076 /* The mapped index file format is designed to be directly mmap()able
14077 on any architecture. In most cases, a datum is represented using a
14078 little-endian 32-bit integer value, called an offset_type. Big
14079 endian machines must byte-swap the values before using them.
14080 Exceptions to this rule are noted. The data is laid out such that
14081 alignment is always respected.
14083 A mapped index consists of several sections.
14085 1. The file header. This is a sequence of values, of offset_type
14086 unless otherwise noted:
14087 [0] The version number. Currently 1.
14088 [1] The offset, from the start of the file, of the CU list.
14089 [2] The offset, from the start of the file, of the address section.
14090 [3] The offset, from the start of the file, of the symbol table.
14091 [4] The offset, from the start of the file, of the constant pool.
14093 2. The CU list. This is a sequence of pairs of 64-bit
14094 little-endian values. The first element in each pair is the offset
14095 of a CU in the .debug_info section. The second element in each
14096 pair is the length of that CU. References to a CU elsewhere in the
14097 map are done using a CU index, which is just the 0-based index into
14100 3. The address section. The address section consists of a sequence
14101 of address entries. Each address entry has three elements.
14102 [0] The low address. This is a 64-bit little-endian value.
14103 [1] The high address. This is a 64-bit little-endian value.
14104 [2] The CU index. This is an offset_type value.
14106 4. The symbol table. This is a hash table. The size of the hash
14107 table is always a power of 2. The initial hash and the step are
14108 currently defined by the `find_slot' function.
14110 Each slot in the hash table consists of a pair of offset_type
14111 values. The first value is the offset of the symbol's name in the
14112 constant pool. The second value is the offset of the CU vector in
14115 If both values are 0, then this slot in the hash table is empty.
14116 This is ok because while 0 is a valid constant pool index, it
14117 cannot be a valid index for both a string and a CU vector.
14119 A string in the constant pool is stored as a \0-terminated string,
14122 A CU vector in the constant pool is a sequence of offset_type
14123 values. The first value is the number of CU indices in the vector.
14124 Each subsequent value is the index of a CU in the CU list. This
14125 element in the hash table is used to indicate which CUs define the
14128 5. The constant pool. This is simply a bunch of bytes. It is
14129 organized so that alignment is correct: CU vectors are stored
14130 first, followed by strings. */
14132 save_gdb_index_command (char *arg
, int from_tty
)
14134 struct objfile
*objfile
;
14137 error (_("usage: maintenance save-gdb-index DIRECTORY"));
14139 ALL_OBJFILES (objfile
)
14143 /* If the objfile does not correspond to an actual file, skip it. */
14144 if (stat (objfile
->name
, &st
) < 0)
14147 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14148 if (dwarf2_per_objfile
)
14150 volatile struct gdb_exception except
;
14152 TRY_CATCH (except
, RETURN_MASK_ERROR
)
14154 write_psymtabs_to_index (objfile
, arg
);
14156 if (except
.reason
< 0)
14157 exception_fprintf (gdb_stderr
, except
,
14158 _("Error while writing index for `%s': "),
14166 int dwarf2_always_disassemble
;
14169 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
14170 struct cmd_list_element
*c
, const char *value
)
14172 fprintf_filtered (file
, _("\
14173 Whether to always disassemble DWARF expressions is %s.\n"),
14177 void _initialize_dwarf2_read (void);
14180 _initialize_dwarf2_read (void)
14182 dwarf2_objfile_data_key
14183 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
14185 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
14186 Set DWARF 2 specific variables.\n\
14187 Configure DWARF 2 variables such as the cache size"),
14188 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
14189 0/*allow-unknown*/, &maintenance_set_cmdlist
);
14191 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
14192 Show DWARF 2 specific variables\n\
14193 Show DWARF 2 variables such as the cache size"),
14194 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
14195 0/*allow-unknown*/, &maintenance_show_cmdlist
);
14197 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
14198 &dwarf2_max_cache_age
, _("\
14199 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
14200 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
14201 A higher limit means that cached compilation units will be stored\n\
14202 in memory longer, and more total memory will be used. Zero disables\n\
14203 caching, which can slow down startup."),
14205 show_dwarf2_max_cache_age
,
14206 &set_dwarf2_cmdlist
,
14207 &show_dwarf2_cmdlist
);
14209 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
14210 &dwarf2_always_disassemble
, _("\
14211 Set whether `info address' always disassembles DWARF expressions."), _("\
14212 Show whether `info address' always disassembles DWARF expressions."), _("\
14213 When enabled, DWARF expressions are always printed in an assembly-like\n\
14214 syntax. When disabled, expressions will be printed in a more\n\
14215 conversational style, when possible."),
14217 show_dwarf2_always_disassemble
,
14218 &set_dwarf2_cmdlist
,
14219 &show_dwarf2_cmdlist
);
14221 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
14222 Set debugging of the dwarf2 DIE reader."), _("\
14223 Show debugging of the dwarf2 DIE reader."), _("\
14224 When enabled (non-zero), DIEs are dumped after they are read in.\n\
14225 The value is the maximum depth to print."),
14228 &setdebuglist
, &showdebuglist
);
14230 add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
14231 _("Save a .gdb-index file"),