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
)
1764 struct stat st
, obstat
;
1767 struct mapped_index
*map
;
1768 offset_type val
, *metadata
;
1769 char buf1
[8], buf2
[8];
1770 const gdb_byte
*cu_list
;
1771 offset_type cu_list_elements
;
1773 if (dwarf2_per_objfile
->gdb_index
.asection
== NULL
1774 || dwarf2_per_objfile
->gdb_index
.size
== 0)
1776 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->gdb_index
);
1778 addr
= dwarf2_per_objfile
->gdb_index
.buffer
;
1779 /* Version check. */
1780 if (MAYBE_SWAP (*(offset_type
*) addr
) != 1)
1783 map
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
, struct mapped_index
);
1784 map
->total_size
= st
.st_size
;
1786 metadata
= (offset_type
*) (addr
+ sizeof (offset_type
));
1787 cu_list
= addr
+ MAYBE_SWAP (metadata
[0]);
1788 cu_list_elements
= ((MAYBE_SWAP (metadata
[1]) - MAYBE_SWAP (metadata
[0]))
1790 map
->address_table
= addr
+ MAYBE_SWAP (metadata
[1]);
1791 map
->address_table_size
= (MAYBE_SWAP (metadata
[2])
1792 - MAYBE_SWAP (metadata
[1]));
1793 map
->index_table
= (offset_type
*) (addr
+ MAYBE_SWAP (metadata
[2]));
1794 map
->index_table_slots
= ((MAYBE_SWAP (metadata
[3])
1795 - MAYBE_SWAP (metadata
[2]))
1796 / (2 * sizeof (offset_type
)));
1797 map
->constant_pool
= addr
+ MAYBE_SWAP (metadata
[3]);
1799 if (!create_cus_from_index (objfile
, map
, cu_list
, cu_list_elements
))
1802 create_addrmap_from_index (objfile
, map
);
1804 dwarf2_per_objfile
->index_table
= map
;
1805 dwarf2_per_objfile
->using_index
= 1;
1810 /* A helper for the "quick" functions which sets the global
1811 dwarf2_per_objfile according to OBJFILE. */
1813 dw2_setup (struct objfile
*objfile
)
1815 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1816 gdb_assert (dwarf2_per_objfile
);
1819 /* A helper for the "quick" functions which attempts to read the line
1820 table for THIS_CU. */
1822 dw2_require_line_header (struct objfile
*objfile
,
1823 struct dwarf2_per_cu_data
*this_cu
)
1825 bfd
*abfd
= objfile
->obfd
;
1826 struct line_header
*lh
= NULL
;
1827 struct attribute
*attr
;
1828 struct cleanup
*cleanups
;
1829 struct die_info
*comp_unit_die
;
1830 gdb_byte
*beg_of_comp_unit
, *info_ptr
, *buffer
;
1831 int has_children
, i
;
1832 struct dwarf2_cu cu
;
1833 unsigned int bytes_read
, buffer_size
;
1834 struct die_reader_specs reader_specs
;
1835 char *name
, *comp_dir
;
1837 if (this_cu
->v
.quick
->read_lines
)
1839 this_cu
->v
.quick
->read_lines
= 1;
1841 memset (&cu
, 0, sizeof (cu
));
1842 cu
.objfile
= objfile
;
1843 obstack_init (&cu
.comp_unit_obstack
);
1845 cleanups
= make_cleanup (free_stack_comp_unit
, &cu
);
1847 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1848 buffer_size
= dwarf2_per_objfile
->info
.size
;
1849 buffer
= dwarf2_per_objfile
->info
.buffer
;
1850 info_ptr
= buffer
+ this_cu
->offset
;
1851 beg_of_comp_unit
= info_ptr
;
1853 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1854 buffer
, buffer_size
,
1857 /* Complete the cu_header. */
1858 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1859 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1862 cu
.per_cu
= this_cu
;
1864 dwarf2_read_abbrevs (abfd
, &cu
);
1865 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1867 if (this_cu
->from_debug_types
)
1868 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1869 init_cu_die_reader (&reader_specs
, &cu
);
1870 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1873 attr
= dwarf2_attr (comp_unit_die
, DW_AT_stmt_list
, &cu
);
1876 unsigned int line_offset
= DW_UNSND (attr
);
1877 lh
= dwarf_decode_line_header (line_offset
, abfd
, &cu
);
1881 do_cleanups (cleanups
);
1885 find_file_and_directory (comp_unit_die
, &cu
, &name
, &comp_dir
);
1887 this_cu
->v
.quick
->lines
= lh
;
1889 this_cu
->v
.quick
->file_names
1890 = obstack_alloc (&objfile
->objfile_obstack
,
1891 lh
->num_file_names
* sizeof (char *));
1892 for (i
= 0; i
< lh
->num_file_names
; ++i
)
1893 this_cu
->v
.quick
->file_names
[i
] = file_full_name (i
+ 1, lh
, comp_dir
);
1895 do_cleanups (cleanups
);
1898 /* A helper for the "quick" functions which computes and caches the
1899 real path for a given file name from the line table.
1900 dw2_require_line_header must have been called before this is
1903 dw2_require_full_path (struct objfile
*objfile
,
1904 struct dwarf2_per_cu_data
*cu
,
1907 if (!cu
->v
.quick
->full_names
)
1908 cu
->v
.quick
->full_names
1909 = OBSTACK_CALLOC (&objfile
->objfile_obstack
,
1910 cu
->v
.quick
->lines
->num_file_names
,
1913 if (!cu
->v
.quick
->full_names
[index
])
1914 cu
->v
.quick
->full_names
[index
]
1915 = gdb_realpath (cu
->v
.quick
->file_names
[index
]);
1917 return cu
->v
.quick
->full_names
[index
];
1920 static struct symtab
*
1921 dw2_find_last_source_symtab (struct objfile
*objfile
)
1924 dw2_setup (objfile
);
1925 index
= dwarf2_per_objfile
->n_comp_units
- 1;
1926 return dw2_instantiate_symtab (objfile
,
1927 dwarf2_per_objfile
->all_comp_units
[index
]);
1931 dw2_forget_cached_source_info (struct objfile
*objfile
)
1935 dw2_setup (objfile
);
1936 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
1938 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
1940 if (cu
->v
.quick
->full_names
)
1944 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
1945 xfree ((void *) cu
->v
.quick
->full_names
[j
]);
1951 dw2_lookup_symtab (struct objfile
*objfile
, const char *name
,
1952 const char *full_path
, const char *real_path
,
1953 struct symtab
**result
)
1956 int check_basename
= lbasename (name
) == name
;
1957 struct dwarf2_per_cu_data
*base_cu
= NULL
;
1959 dw2_setup (objfile
);
1960 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
1963 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
1965 if (cu
->v
.quick
->symtab
)
1968 dw2_require_line_header (objfile
, cu
);
1969 if (!cu
->v
.quick
->lines
)
1972 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
1974 const char *this_name
= cu
->v
.quick
->file_names
[j
];
1976 if (FILENAME_CMP (name
, this_name
) == 0)
1978 *result
= dw2_instantiate_symtab (objfile
, cu
);
1982 if (check_basename
&& ! base_cu
1983 && FILENAME_CMP (lbasename (this_name
), name
) == 0)
1986 if (full_path
!= NULL
)
1988 const char *this_full_name
= dw2_require_full_path (objfile
,
1992 && FILENAME_CMP (full_path
, this_full_name
) == 0)
1994 *result
= dw2_instantiate_symtab (objfile
, cu
);
1999 if (real_path
!= NULL
)
2001 const char *this_full_name
= dw2_require_full_path (objfile
,
2004 if (this_full_name
!= NULL
)
2006 char *rp
= gdb_realpath (this_full_name
);
2007 if (rp
!= NULL
&& FILENAME_CMP (real_path
, rp
) == 0)
2010 *result
= dw2_instantiate_symtab (objfile
, cu
);
2021 *result
= dw2_instantiate_symtab (objfile
, base_cu
);
2028 static struct symtab
*
2029 dw2_lookup_symbol (struct objfile
*objfile
, int block_index
,
2030 const char *name
, domain_enum domain
)
2032 /* We do all the work in the pre_expand_symtabs_matching hook
2037 /* A helper function that expands all symtabs that hold an object
2040 dw2_do_expand_symtabs_matching (struct objfile
*objfile
, const char *name
)
2042 dw2_setup (objfile
);
2044 if (dwarf2_per_objfile
->index_table
)
2048 if (find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2051 offset_type i
, len
= MAYBE_SWAP (*vec
);
2052 for (i
= 0; i
< len
; ++i
)
2054 offset_type cu_index
= MAYBE_SWAP (vec
[i
+ 1]);
2055 struct dwarf2_per_cu_data
*cu
;
2056 cu
= dwarf2_per_objfile
->all_comp_units
[cu_index
];
2057 dw2_instantiate_symtab (objfile
, cu
);
2064 dw2_pre_expand_symtabs_matching (struct objfile
*objfile
,
2065 int kind
, const char *name
,
2068 dw2_do_expand_symtabs_matching (objfile
, name
);
2072 dw2_print_stats (struct objfile
*objfile
)
2076 dw2_setup (objfile
);
2078 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2080 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2082 if (!cu
->v
.quick
->symtab
)
2085 printf_filtered (_(" Number of unread CUs: %d\n"), count
);
2089 dw2_dump (struct objfile
*objfile
)
2091 /* Nothing worth printing. */
2095 dw2_relocate (struct objfile
*objfile
, struct section_offsets
*new_offsets
,
2096 struct section_offsets
*delta
)
2098 /* There's nothing to relocate here. */
2102 dw2_expand_symtabs_for_function (struct objfile
*objfile
,
2103 const char *func_name
)
2105 dw2_do_expand_symtabs_matching (objfile
, func_name
);
2109 dw2_expand_all_symtabs (struct objfile
*objfile
)
2113 dw2_setup (objfile
);
2114 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2116 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2118 dw2_instantiate_symtab (objfile
, cu
);
2123 dw2_expand_symtabs_with_filename (struct objfile
*objfile
,
2124 const char *filename
)
2128 dw2_setup (objfile
);
2129 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2132 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2134 if (cu
->v
.quick
->symtab
)
2137 dw2_require_line_header (objfile
, cu
);
2138 if (!cu
->v
.quick
->lines
)
2141 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2143 const char *this_name
= cu
->v
.quick
->file_names
[j
];
2144 if (strcmp (this_name
, filename
) == 0)
2146 dw2_instantiate_symtab (objfile
, cu
);
2154 dw2_find_symbol_file (struct objfile
*objfile
, const char *name
)
2156 struct dwarf2_per_cu_data
*cu
;
2159 dw2_setup (objfile
);
2161 if (!dwarf2_per_objfile
->index_table
)
2164 if (!find_slot_in_mapped_hash (dwarf2_per_objfile
->index_table
,
2168 /* Note that this just looks at the very first one named NAME -- but
2169 actually we are looking for a function. find_main_filename
2170 should be rewritten so that it doesn't require a custom hook. It
2171 could just use the ordinary symbol tables. */
2172 /* vec[0] is the length, which must always be >0. */
2173 cu
= dwarf2_per_objfile
->all_comp_units
[MAYBE_SWAP (vec
[1])];
2175 dw2_require_line_header (objfile
, cu
);
2176 if (!cu
->v
.quick
->lines
)
2179 return (char *) cu
->v
.quick
->file_names
[cu
->v
.quick
->lines
->num_file_names
2184 dw2_map_ada_symtabs (struct objfile
*objfile
,
2185 int (*wild_match
) (const char *, int, const char *),
2186 int (*is_name_suffix
) (const char *),
2187 void (*callback
) (struct objfile
*,
2188 struct symtab
*, void *),
2189 const char *name
, int global
,
2190 domain_enum
namespace, int wild
,
2193 /* For now, we don't support Ada, so this function can't be
2195 internal_error (__FILE__
, __LINE__
,
2196 _("map_ada_symtabs called via index method"));
2200 dw2_expand_symtabs_matching (struct objfile
*objfile
,
2201 int (*file_matcher
) (const char *, void *),
2202 int (*name_matcher
) (const char *, void *),
2209 dw2_setup (objfile
);
2210 if (!dwarf2_per_objfile
->index_table
)
2213 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2216 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2218 cu
->v
.quick
->mark
= 0;
2219 if (cu
->v
.quick
->symtab
)
2222 dw2_require_line_header (objfile
, cu
);
2223 if (!cu
->v
.quick
->lines
)
2226 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2228 if (file_matcher (cu
->v
.quick
->file_names
[j
], data
))
2230 cu
->v
.quick
->mark
= 1;
2237 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2240 offset_type idx
= 2 * iter
;
2242 offset_type
*vec
, vec_len
, vec_idx
;
2244 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2245 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2248 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2249 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2251 if (! (*name_matcher
) (name
, data
))
2254 /* The name was matched, now expand corresponding CUs that were
2256 vec
= (offset_type
*) (dwarf2_per_objfile
->index_table
->constant_pool
2257 + dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1]);
2258 vec_len
= MAYBE_SWAP (vec
[0]);
2259 for (vec_idx
= 0; vec_idx
< vec_len
; ++vec_idx
)
2261 struct dwarf2_per_cu_data
*cu
2262 = dwarf2_per_objfile
->all_comp_units
[MAYBE_SWAP (vec
[vec_idx
+ 1])];
2263 if (cu
->v
.quick
->mark
)
2264 dw2_instantiate_symtab (objfile
, cu
);
2269 static struct symtab
*
2270 dw2_find_pc_sect_symtab (struct objfile
*objfile
,
2271 struct minimal_symbol
*msymbol
,
2273 struct obj_section
*section
,
2276 struct dwarf2_per_cu_data
*data
;
2278 dw2_setup (objfile
);
2280 if (!objfile
->psymtabs_addrmap
)
2283 data
= addrmap_find (objfile
->psymtabs_addrmap
, pc
);
2287 if (warn_if_readin
&& data
->v
.quick
->symtab
)
2288 warning (_("(Internal error: pc %s in read in CU, but not in symtab.)\n"),
2289 paddress (get_objfile_arch (objfile
), pc
));
2291 return dw2_instantiate_symtab (objfile
, data
);
2295 dw2_map_symbol_names (struct objfile
*objfile
,
2296 void (*fun
) (const char *, void *),
2300 dw2_setup (objfile
);
2302 if (!dwarf2_per_objfile
->index_table
)
2306 iter
< dwarf2_per_objfile
->index_table
->index_table_slots
;
2309 offset_type idx
= 2 * iter
;
2311 offset_type
*vec
, vec_len
, vec_idx
;
2313 if (dwarf2_per_objfile
->index_table
->index_table
[idx
] == 0
2314 && dwarf2_per_objfile
->index_table
->index_table
[idx
+ 1] == 0)
2317 name
= (dwarf2_per_objfile
->index_table
->constant_pool
2318 + dwarf2_per_objfile
->index_table
->index_table
[idx
]);
2320 (*fun
) (name
, data
);
2325 dw2_map_symbol_filenames (struct objfile
*objfile
,
2326 void (*fun
) (const char *, const char *, void *),
2331 dw2_setup (objfile
);
2332 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2335 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2337 if (cu
->v
.quick
->symtab
)
2340 dw2_require_line_header (objfile
, cu
);
2341 if (!cu
->v
.quick
->lines
)
2344 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
2346 const char *this_full_name
= dw2_require_full_path (objfile
, cu
, j
);
2347 (*fun
) (cu
->v
.quick
->file_names
[j
], this_full_name
, data
);
2353 dw2_has_symbols (struct objfile
*objfile
)
2358 const struct quick_symbol_functions dwarf2_gdb_index_functions
=
2361 dw2_find_last_source_symtab
,
2362 dw2_forget_cached_source_info
,
2365 dw2_pre_expand_symtabs_matching
,
2369 dw2_expand_symtabs_for_function
,
2370 dw2_expand_all_symtabs
,
2371 dw2_expand_symtabs_with_filename
,
2372 dw2_find_symbol_file
,
2373 dw2_map_ada_symtabs
,
2374 dw2_expand_symtabs_matching
,
2375 dw2_find_pc_sect_symtab
,
2376 dw2_map_symbol_names
,
2377 dw2_map_symbol_filenames
2380 /* Initialize for reading DWARF for this objfile. Return 0 if this
2381 file will use psymtabs, or 1 if using the GNU index. */
2384 dwarf2_initialize_objfile (struct objfile
*objfile
)
2386 /* If we're about to read full symbols, don't bother with the
2387 indices. In this case we also don't care if some other debug
2388 format is making psymtabs, because they are all about to be
2390 if ((objfile
->flags
& OBJF_READNOW
))
2394 dwarf2_per_objfile
->using_index
= 1;
2395 create_all_comp_units (objfile
);
2397 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
2399 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
2401 cu
->v
.quick
= OBSTACK_ZALLOC (&objfile
->objfile_obstack
,
2402 struct dwarf2_per_cu_quick_data
);
2405 /* Return 1 so that gdb sees the "quick" functions. However,
2406 these functions will be no-ops because we will have expanded
2411 if (dwarf2_read_index (objfile
))
2414 dwarf2_build_psymtabs (objfile
);
2420 /* Build a partial symbol table. */
2423 dwarf2_build_psymtabs (struct objfile
*objfile
)
2425 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
2427 init_psymbol_list (objfile
, 1024);
2430 dwarf2_build_psymtabs_hard (objfile
);
2433 /* Return TRUE if OFFSET is within CU_HEADER. */
2436 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
2438 unsigned int bottom
= cu_header
->offset
;
2439 unsigned int top
= (cu_header
->offset
2441 + cu_header
->initial_length_size
);
2443 return (offset
>= bottom
&& offset
< top
);
2446 /* Read in the comp unit header information from the debug_info at info_ptr.
2447 NOTE: This leaves members offset, first_die_offset to be filled in
2451 read_comp_unit_head (struct comp_unit_head
*cu_header
,
2452 gdb_byte
*info_ptr
, bfd
*abfd
)
2455 unsigned int bytes_read
;
2457 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
2458 cu_header
->initial_length_size
= bytes_read
;
2459 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
2460 info_ptr
+= bytes_read
;
2461 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
2463 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
2465 info_ptr
+= bytes_read
;
2466 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
2468 signed_addr
= bfd_get_sign_extend_vma (abfd
);
2469 if (signed_addr
< 0)
2470 internal_error (__FILE__
, __LINE__
,
2471 _("read_comp_unit_head: dwarf from non elf file"));
2472 cu_header
->signed_addr_p
= signed_addr
;
2478 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
2479 gdb_byte
*buffer
, unsigned int buffer_size
,
2482 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2484 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
2486 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
2487 error (_("Dwarf Error: wrong version in compilation unit header "
2488 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
2489 bfd_get_filename (abfd
));
2491 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
2492 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
2493 "(offset 0x%lx + 6) [in module %s]"),
2494 (long) header
->abbrev_offset
,
2495 (long) (beg_of_comp_unit
- buffer
),
2496 bfd_get_filename (abfd
));
2498 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
2499 > buffer
+ buffer_size
)
2500 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
2501 "(offset 0x%lx + 0) [in module %s]"),
2502 (long) header
->length
,
2503 (long) (beg_of_comp_unit
- buffer
),
2504 bfd_get_filename (abfd
));
2509 /* Read in the types comp unit header information from .debug_types entry at
2510 types_ptr. The result is a pointer to one past the end of the header. */
2513 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
2514 ULONGEST
*signature
,
2515 gdb_byte
*types_ptr
, bfd
*abfd
)
2517 gdb_byte
*initial_types_ptr
= types_ptr
;
2519 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
2520 &dwarf2_per_objfile
->types
);
2521 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
2523 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
2525 *signature
= read_8_bytes (abfd
, types_ptr
);
2527 types_ptr
+= cu_header
->offset_size
;
2528 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
2533 /* Allocate a new partial symtab for file named NAME and mark this new
2534 partial symtab as being an include of PST. */
2537 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
2538 struct objfile
*objfile
)
2540 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
2542 subpst
->section_offsets
= pst
->section_offsets
;
2543 subpst
->textlow
= 0;
2544 subpst
->texthigh
= 0;
2546 subpst
->dependencies
= (struct partial_symtab
**)
2547 obstack_alloc (&objfile
->objfile_obstack
,
2548 sizeof (struct partial_symtab
*));
2549 subpst
->dependencies
[0] = pst
;
2550 subpst
->number_of_dependencies
= 1;
2552 subpst
->globals_offset
= 0;
2553 subpst
->n_global_syms
= 0;
2554 subpst
->statics_offset
= 0;
2555 subpst
->n_static_syms
= 0;
2556 subpst
->symtab
= NULL
;
2557 subpst
->read_symtab
= pst
->read_symtab
;
2560 /* No private part is necessary for include psymtabs. This property
2561 can be used to differentiate between such include psymtabs and
2562 the regular ones. */
2563 subpst
->read_symtab_private
= NULL
;
2566 /* Read the Line Number Program data and extract the list of files
2567 included by the source file represented by PST. Build an include
2568 partial symtab for each of these included files. */
2571 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
2572 struct die_info
*die
,
2573 struct partial_symtab
*pst
)
2575 struct objfile
*objfile
= cu
->objfile
;
2576 bfd
*abfd
= objfile
->obfd
;
2577 struct line_header
*lh
= NULL
;
2578 struct attribute
*attr
;
2580 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2583 unsigned int line_offset
= DW_UNSND (attr
);
2585 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2588 return; /* No linetable, so no includes. */
2590 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
2592 free_line_header (lh
);
2596 hash_type_signature (const void *item
)
2598 const struct signatured_type
*type_sig
= item
;
2600 /* This drops the top 32 bits of the signature, but is ok for a hash. */
2601 return type_sig
->signature
;
2605 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
2607 const struct signatured_type
*lhs
= item_lhs
;
2608 const struct signatured_type
*rhs
= item_rhs
;
2610 return lhs
->signature
== rhs
->signature
;
2613 /* Create the hash table of all entries in the .debug_types section.
2614 The result is zero if there is an error (e.g. missing .debug_types section),
2615 otherwise non-zero. */
2618 create_debug_types_hash_table (struct objfile
*objfile
)
2623 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
2624 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
2626 if (info_ptr
== NULL
)
2628 dwarf2_per_objfile
->signatured_types
= NULL
;
2632 types_htab
= htab_create_alloc_ex (41,
2633 hash_type_signature
,
2636 &objfile
->objfile_obstack
,
2637 hashtab_obstack_allocate
,
2638 dummy_obstack_deallocate
);
2640 if (dwarf2_die_debug
)
2641 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
2643 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2645 unsigned int offset
;
2646 unsigned int offset_size
;
2647 unsigned int type_offset
;
2648 unsigned int length
, initial_length_size
;
2649 unsigned short version
;
2651 struct signatured_type
*type_sig
;
2653 gdb_byte
*ptr
= info_ptr
;
2655 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
2657 /* We need to read the type's signature in order to build the hash
2658 table, but we don't need to read anything else just yet. */
2660 /* Sanity check to ensure entire cu is present. */
2661 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
2662 if (ptr
+ length
+ initial_length_size
2663 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
2665 complaint (&symfile_complaints
,
2666 _("debug type entry runs off end of `.debug_types' section, ignored"));
2670 offset_size
= initial_length_size
== 4 ? 4 : 8;
2671 ptr
+= initial_length_size
;
2672 version
= bfd_get_16 (objfile
->obfd
, ptr
);
2674 ptr
+= offset_size
; /* abbrev offset */
2675 ptr
+= 1; /* address size */
2676 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
2678 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
2680 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
2681 memset (type_sig
, 0, sizeof (*type_sig
));
2682 type_sig
->signature
= signature
;
2683 type_sig
->offset
= offset
;
2684 type_sig
->type_offset
= type_offset
;
2686 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
2687 gdb_assert (slot
!= NULL
);
2690 if (dwarf2_die_debug
)
2691 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
2692 offset
, phex (signature
, sizeof (signature
)));
2694 info_ptr
= info_ptr
+ initial_length_size
+ length
;
2697 dwarf2_per_objfile
->signatured_types
= types_htab
;
2702 /* Lookup a signature based type.
2703 Returns NULL if SIG is not present in the table. */
2705 static struct signatured_type
*
2706 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
2708 struct signatured_type find_entry
, *entry
;
2710 if (dwarf2_per_objfile
->signatured_types
== NULL
)
2712 complaint (&symfile_complaints
,
2713 _("missing `.debug_types' section for DW_FORM_sig8 die"));
2717 find_entry
.signature
= sig
;
2718 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
2722 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
2725 init_cu_die_reader (struct die_reader_specs
*reader
,
2726 struct dwarf2_cu
*cu
)
2728 reader
->abfd
= cu
->objfile
->obfd
;
2730 if (cu
->per_cu
->from_debug_types
)
2732 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2733 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
2737 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2738 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
2742 /* Find the base address of the compilation unit for range lists and
2743 location lists. It will normally be specified by DW_AT_low_pc.
2744 In DWARF-3 draft 4, the base address could be overridden by
2745 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2746 compilation units with discontinuous ranges. */
2749 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
2751 struct attribute
*attr
;
2754 cu
->base_address
= 0;
2756 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
2759 cu
->base_address
= DW_ADDR (attr
);
2764 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2767 cu
->base_address
= DW_ADDR (attr
);
2773 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
2774 to combine the common parts.
2775 Process a compilation unit for a psymtab.
2776 BUFFER is a pointer to the beginning of the dwarf section buffer,
2777 either .debug_info or debug_types.
2778 INFO_PTR is a pointer to the start of the CU.
2779 Returns a pointer to the next CU. */
2782 process_psymtab_comp_unit (struct objfile
*objfile
,
2783 struct dwarf2_per_cu_data
*this_cu
,
2784 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2785 unsigned int buffer_size
)
2787 bfd
*abfd
= objfile
->obfd
;
2788 gdb_byte
*beg_of_comp_unit
= info_ptr
;
2789 struct die_info
*comp_unit_die
;
2790 struct partial_symtab
*pst
;
2792 struct cleanup
*back_to_inner
;
2793 struct dwarf2_cu cu
;
2794 int has_children
, has_pc_info
;
2795 struct attribute
*attr
;
2796 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
2797 struct die_reader_specs reader_specs
;
2799 memset (&cu
, 0, sizeof (cu
));
2800 cu
.objfile
= objfile
;
2801 obstack_init (&cu
.comp_unit_obstack
);
2803 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
2805 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
2806 buffer
, buffer_size
,
2809 /* Complete the cu_header. */
2810 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
2811 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2813 cu
.list_in_scope
= &file_symbols
;
2815 /* If this compilation unit was already read in, free the
2816 cached copy in order to read it in again. This is
2817 necessary because we skipped some symbols when we first
2818 read in the compilation unit (see load_partial_dies).
2819 This problem could be avoided, but the benefit is
2821 if (this_cu
->cu
!= NULL
)
2822 free_one_cached_comp_unit (this_cu
->cu
);
2824 /* Note that this is a pointer to our stack frame, being
2825 added to a global data structure. It will be cleaned up
2826 in free_stack_comp_unit when we finish with this
2827 compilation unit. */
2829 cu
.per_cu
= this_cu
;
2831 /* Read the abbrevs for this compilation unit into a table. */
2832 dwarf2_read_abbrevs (abfd
, &cu
);
2833 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2835 /* Read the compilation unit die. */
2836 if (this_cu
->from_debug_types
)
2837 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
2838 init_cu_die_reader (&reader_specs
, &cu
);
2839 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2842 if (this_cu
->from_debug_types
)
2844 /* offset,length haven't been set yet for type units. */
2845 this_cu
->offset
= cu
.header
.offset
;
2846 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
2848 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
2850 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
2851 + cu
.header
.initial_length_size
);
2852 do_cleanups (back_to_inner
);
2856 /* Set the language we're debugging. */
2857 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
2859 set_cu_language (DW_UNSND (attr
), &cu
);
2861 set_cu_language (language_minimal
, &cu
);
2863 /* Allocate a new partial symbol table structure. */
2864 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
2865 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
2866 (attr
!= NULL
) ? DW_STRING (attr
) : "",
2867 /* TEXTLOW and TEXTHIGH are set below. */
2869 objfile
->global_psymbols
.next
,
2870 objfile
->static_psymbols
.next
);
2872 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
2874 pst
->dirname
= DW_STRING (attr
);
2876 pst
->read_symtab_private
= this_cu
;
2878 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2880 /* Store the function that reads in the rest of the symbol table */
2881 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
2883 this_cu
->v
.psymtab
= pst
;
2885 dwarf2_find_base_address (comp_unit_die
, &cu
);
2887 /* Possibly set the default values of LOWPC and HIGHPC from
2889 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
2890 &best_highpc
, &cu
, pst
);
2891 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
2892 /* Store the contiguous range if it is not empty; it can be empty for
2893 CUs with no code. */
2894 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2895 best_lowpc
+ baseaddr
,
2896 best_highpc
+ baseaddr
- 1, pst
);
2898 /* Check if comp unit has_children.
2899 If so, read the rest of the partial symbols from this comp unit.
2900 If not, there's no more debug_info for this comp unit. */
2903 struct partial_die_info
*first_die
;
2904 CORE_ADDR lowpc
, highpc
;
2906 lowpc
= ((CORE_ADDR
) -1);
2907 highpc
= ((CORE_ADDR
) 0);
2909 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
2911 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
2912 ! has_pc_info
, &cu
);
2914 /* If we didn't find a lowpc, set it to highpc to avoid
2915 complaints from `maint check'. */
2916 if (lowpc
== ((CORE_ADDR
) -1))
2919 /* If the compilation unit didn't have an explicit address range,
2920 then use the information extracted from its child dies. */
2924 best_highpc
= highpc
;
2927 pst
->textlow
= best_lowpc
+ baseaddr
;
2928 pst
->texthigh
= best_highpc
+ baseaddr
;
2930 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
2931 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2932 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
2933 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2934 sort_pst_symbols (pst
);
2936 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
2937 + cu
.header
.initial_length_size
);
2939 if (this_cu
->from_debug_types
)
2941 /* It's not clear we want to do anything with stmt lists here.
2942 Waiting to see what gcc ultimately does. */
2946 /* Get the list of files included in the current compilation unit,
2947 and build a psymtab for each of them. */
2948 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
2951 do_cleanups (back_to_inner
);
2956 /* Traversal function for htab_traverse_noresize.
2957 Process one .debug_types comp-unit. */
2960 process_type_comp_unit (void **slot
, void *info
)
2962 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
2963 struct objfile
*objfile
= (struct objfile
*) info
;
2964 struct dwarf2_per_cu_data
*this_cu
;
2966 this_cu
= &entry
->per_cu
;
2967 this_cu
->from_debug_types
= 1;
2969 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2970 process_psymtab_comp_unit (objfile
, this_cu
,
2971 dwarf2_per_objfile
->types
.buffer
,
2972 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
2973 dwarf2_per_objfile
->types
.size
);
2978 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
2979 Build partial symbol tables for the .debug_types comp-units. */
2982 build_type_psymtabs (struct objfile
*objfile
)
2984 if (! create_debug_types_hash_table (objfile
))
2987 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
2988 process_type_comp_unit
, objfile
);
2991 /* A cleanup function that clears objfile's psymtabs_addrmap field. */
2994 psymtabs_addrmap_cleanup (void *o
)
2996 struct objfile
*objfile
= o
;
2998 objfile
->psymtabs_addrmap
= NULL
;
3001 /* Build the partial symbol table by doing a quick pass through the
3002 .debug_info and .debug_abbrev sections. */
3005 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
3008 struct cleanup
*back_to
, *addrmap_cleanup
;
3009 struct obstack temp_obstack
;
3011 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3012 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3014 /* Any cached compilation units will be linked by the per-objfile
3015 read_in_chain. Make sure to free them when we're done. */
3016 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
3018 build_type_psymtabs (objfile
);
3020 create_all_comp_units (objfile
);
3022 /* Create a temporary address map on a temporary obstack. We later
3023 copy this to the final obstack. */
3024 obstack_init (&temp_obstack
);
3025 make_cleanup_obstack_free (&temp_obstack
);
3026 objfile
->psymtabs_addrmap
= addrmap_create_mutable (&temp_obstack
);
3027 addrmap_cleanup
= make_cleanup (psymtabs_addrmap_cleanup
, objfile
);
3029 /* Since the objects we're extracting from .debug_info vary in
3030 length, only the individual functions to extract them (like
3031 read_comp_unit_head and load_partial_die) can really know whether
3032 the buffer is large enough to hold another complete object.
3034 At the moment, they don't actually check that. If .debug_info
3035 holds just one extra byte after the last compilation unit's dies,
3036 then read_comp_unit_head will happily read off the end of the
3037 buffer. read_partial_die is similarly casual. Those functions
3040 For this loop condition, simply checking whether there's any data
3041 left at all should be sufficient. */
3043 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
3044 + dwarf2_per_objfile
->info
.size
))
3046 struct dwarf2_per_cu_data
*this_cu
;
3048 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
3051 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
3052 dwarf2_per_objfile
->info
.buffer
,
3054 dwarf2_per_objfile
->info
.size
);
3057 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
3058 &objfile
->objfile_obstack
);
3059 discard_cleanups (addrmap_cleanup
);
3061 do_cleanups (back_to
);
3064 /* Load the partial DIEs for a secondary CU into memory. */
3067 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
3068 struct objfile
*objfile
)
3070 bfd
*abfd
= objfile
->obfd
;
3071 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3072 struct die_info
*comp_unit_die
;
3073 struct dwarf2_cu
*cu
;
3074 struct cleanup
*back_to
;
3075 struct attribute
*attr
;
3077 struct die_reader_specs reader_specs
;
3079 gdb_assert (! this_cu
->from_debug_types
);
3081 gdb_assert (dwarf2_per_objfile
->info
.readin
);
3082 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
3083 beg_of_comp_unit
= info_ptr
;
3085 cu
= alloc_one_comp_unit (objfile
);
3087 /* ??? Missing cleanup for CU? */
3089 /* Link this compilation unit into the compilation unit tree. */
3091 cu
->per_cu
= this_cu
;
3092 cu
->type_hash
= this_cu
->type_hash
;
3094 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
3095 dwarf2_per_objfile
->info
.buffer
,
3096 dwarf2_per_objfile
->info
.size
,
3099 /* Complete the cu_header. */
3100 cu
->header
.offset
= this_cu
->offset
;
3101 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3103 /* Read the abbrevs for this compilation unit into a table. */
3104 dwarf2_read_abbrevs (abfd
, cu
);
3105 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3107 /* Read the compilation unit die. */
3108 init_cu_die_reader (&reader_specs
, cu
);
3109 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
3112 /* Set the language we're debugging. */
3113 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
3115 set_cu_language (DW_UNSND (attr
), cu
);
3117 set_cu_language (language_minimal
, cu
);
3119 /* Check if comp unit has_children.
3120 If so, read the rest of the partial symbols from this comp unit.
3121 If not, there's no more debug_info for this comp unit. */
3123 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
3125 do_cleanups (back_to
);
3128 /* Create a list of all compilation units in OBJFILE. We do this only
3129 if an inter-comp-unit reference is found; presumably if there is one,
3130 there will be many, and one will occur early in the .debug_info section.
3131 So there's no point in building this list incrementally. */
3134 create_all_comp_units (struct objfile
*objfile
)
3138 struct dwarf2_per_cu_data
**all_comp_units
;
3141 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3142 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
3146 all_comp_units
= xmalloc (n_allocated
3147 * sizeof (struct dwarf2_per_cu_data
*));
3149 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
3151 unsigned int length
, initial_length_size
;
3152 struct dwarf2_per_cu_data
*this_cu
;
3153 unsigned int offset
;
3155 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
3157 /* Read just enough information to find out where the next
3158 compilation unit is. */
3159 length
= read_initial_length (objfile
->obfd
, info_ptr
,
3160 &initial_length_size
);
3162 /* Save the compilation unit for later lookup. */
3163 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
3164 sizeof (struct dwarf2_per_cu_data
));
3165 memset (this_cu
, 0, sizeof (*this_cu
));
3166 this_cu
->offset
= offset
;
3167 this_cu
->length
= length
+ initial_length_size
;
3168 this_cu
->objfile
= objfile
;
3170 if (n_comp_units
== n_allocated
)
3173 all_comp_units
= xrealloc (all_comp_units
,
3175 * sizeof (struct dwarf2_per_cu_data
*));
3177 all_comp_units
[n_comp_units
++] = this_cu
;
3179 info_ptr
= info_ptr
+ this_cu
->length
;
3182 dwarf2_per_objfile
->all_comp_units
3183 = obstack_alloc (&objfile
->objfile_obstack
,
3184 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3185 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
3186 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
3187 xfree (all_comp_units
);
3188 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
3191 /* Process all loaded DIEs for compilation unit CU, starting at
3192 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
3193 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
3194 DW_AT_ranges). If NEED_PC is set, then this function will set
3195 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
3196 and record the covered ranges in the addrmap. */
3199 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
3200 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3202 struct partial_die_info
*pdi
;
3204 /* Now, march along the PDI's, descending into ones which have
3205 interesting children but skipping the children of the other ones,
3206 until we reach the end of the compilation unit. */
3212 fixup_partial_die (pdi
, cu
);
3214 /* Anonymous namespaces or modules have no name but have interesting
3215 children, so we need to look at them. Ditto for anonymous
3218 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
3219 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
3223 case DW_TAG_subprogram
:
3224 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3226 case DW_TAG_variable
:
3227 case DW_TAG_typedef
:
3228 case DW_TAG_union_type
:
3229 if (!pdi
->is_declaration
)
3231 add_partial_symbol (pdi
, cu
);
3234 case DW_TAG_class_type
:
3235 case DW_TAG_interface_type
:
3236 case DW_TAG_structure_type
:
3237 if (!pdi
->is_declaration
)
3239 add_partial_symbol (pdi
, cu
);
3242 case DW_TAG_enumeration_type
:
3243 if (!pdi
->is_declaration
)
3244 add_partial_enumeration (pdi
, cu
);
3246 case DW_TAG_base_type
:
3247 case DW_TAG_subrange_type
:
3248 /* File scope base type definitions are added to the partial
3250 add_partial_symbol (pdi
, cu
);
3252 case DW_TAG_namespace
:
3253 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
3256 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
3263 /* If the die has a sibling, skip to the sibling. */
3265 pdi
= pdi
->die_sibling
;
3269 /* Functions used to compute the fully scoped name of a partial DIE.
3271 Normally, this is simple. For C++, the parent DIE's fully scoped
3272 name is concatenated with "::" and the partial DIE's name. For
3273 Java, the same thing occurs except that "." is used instead of "::".
3274 Enumerators are an exception; they use the scope of their parent
3275 enumeration type, i.e. the name of the enumeration type is not
3276 prepended to the enumerator.
3278 There are two complexities. One is DW_AT_specification; in this
3279 case "parent" means the parent of the target of the specification,
3280 instead of the direct parent of the DIE. The other is compilers
3281 which do not emit DW_TAG_namespace; in this case we try to guess
3282 the fully qualified name of structure types from their members'
3283 linkage names. This must be done using the DIE's children rather
3284 than the children of any DW_AT_specification target. We only need
3285 to do this for structures at the top level, i.e. if the target of
3286 any DW_AT_specification (if any; otherwise the DIE itself) does not
3289 /* Compute the scope prefix associated with PDI's parent, in
3290 compilation unit CU. The result will be allocated on CU's
3291 comp_unit_obstack, or a copy of the already allocated PDI->NAME
3292 field. NULL is returned if no prefix is necessary. */
3294 partial_die_parent_scope (struct partial_die_info
*pdi
,
3295 struct dwarf2_cu
*cu
)
3297 char *grandparent_scope
;
3298 struct partial_die_info
*parent
, *real_pdi
;
3300 /* We need to look at our parent DIE; if we have a DW_AT_specification,
3301 then this means the parent of the specification DIE. */
3304 while (real_pdi
->has_specification
)
3305 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3307 parent
= real_pdi
->die_parent
;
3311 if (parent
->scope_set
)
3312 return parent
->scope
;
3314 fixup_partial_die (parent
, cu
);
3316 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
3318 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
3319 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
3320 Work around this problem here. */
3321 if (cu
->language
== language_cplus
3322 && parent
->tag
== DW_TAG_namespace
3323 && strcmp (parent
->name
, "::") == 0
3324 && grandparent_scope
== NULL
)
3326 parent
->scope
= NULL
;
3327 parent
->scope_set
= 1;
3331 if (parent
->tag
== DW_TAG_namespace
3332 || parent
->tag
== DW_TAG_module
3333 || parent
->tag
== DW_TAG_structure_type
3334 || parent
->tag
== DW_TAG_class_type
3335 || parent
->tag
== DW_TAG_interface_type
3336 || parent
->tag
== DW_TAG_union_type
3337 || parent
->tag
== DW_TAG_enumeration_type
)
3339 if (grandparent_scope
== NULL
)
3340 parent
->scope
= parent
->name
;
3342 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
3343 parent
->name
, 0, cu
);
3345 else if (parent
->tag
== DW_TAG_enumerator
)
3346 /* Enumerators should not get the name of the enumeration as a prefix. */
3347 parent
->scope
= grandparent_scope
;
3350 /* FIXME drow/2004-04-01: What should we be doing with
3351 function-local names? For partial symbols, we should probably be
3353 complaint (&symfile_complaints
,
3354 _("unhandled containing DIE tag %d for DIE at %d"),
3355 parent
->tag
, pdi
->offset
);
3356 parent
->scope
= grandparent_scope
;
3359 parent
->scope_set
= 1;
3360 return parent
->scope
;
3363 /* Return the fully scoped name associated with PDI, from compilation unit
3364 CU. The result will be allocated with malloc. */
3366 partial_die_full_name (struct partial_die_info
*pdi
,
3367 struct dwarf2_cu
*cu
)
3371 parent_scope
= partial_die_parent_scope (pdi
, cu
);
3372 if (parent_scope
== NULL
)
3375 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
3379 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
3381 struct objfile
*objfile
= cu
->objfile
;
3383 char *actual_name
= NULL
;
3384 const struct partial_symbol
*psym
= NULL
;
3386 int built_actual_name
= 0;
3388 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3390 actual_name
= partial_die_full_name (pdi
, cu
);
3392 built_actual_name
= 1;
3394 if (actual_name
== NULL
)
3395 actual_name
= pdi
->name
;
3399 case DW_TAG_subprogram
:
3400 if (pdi
->is_external
|| cu
->language
== language_ada
)
3402 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
3403 of the global scope. But in Ada, we want to be able to access
3404 nested procedures globally. So all Ada subprograms are stored
3405 in the global scope. */
3406 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3407 mst_text, objfile); */
3408 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3410 VAR_DOMAIN
, LOC_BLOCK
,
3411 &objfile
->global_psymbols
,
3412 0, pdi
->lowpc
+ baseaddr
,
3413 cu
->language
, objfile
);
3417 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
3418 mst_file_text, objfile); */
3419 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3421 VAR_DOMAIN
, LOC_BLOCK
,
3422 &objfile
->static_psymbols
,
3423 0, pdi
->lowpc
+ baseaddr
,
3424 cu
->language
, objfile
);
3427 case DW_TAG_variable
:
3428 if (pdi
->is_external
)
3431 Don't enter into the minimal symbol tables as there is
3432 a minimal symbol table entry from the ELF symbols already.
3433 Enter into partial symbol table if it has a location
3434 descriptor or a type.
3435 If the location descriptor is missing, new_symbol will create
3436 a LOC_UNRESOLVED symbol, the address of the variable will then
3437 be determined from the minimal symbol table whenever the variable
3439 The address for the partial symbol table entry is not
3440 used by GDB, but it comes in handy for debugging partial symbol
3444 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3445 if (pdi
->locdesc
|| pdi
->has_type
)
3446 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3448 VAR_DOMAIN
, LOC_STATIC
,
3449 &objfile
->global_psymbols
,
3451 cu
->language
, objfile
);
3455 /* Static Variable. Skip symbols without location descriptors. */
3456 if (pdi
->locdesc
== NULL
)
3458 if (built_actual_name
)
3459 xfree (actual_name
);
3462 addr
= decode_locdesc (pdi
->locdesc
, cu
);
3463 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
3464 mst_file_data, objfile); */
3465 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
3467 VAR_DOMAIN
, LOC_STATIC
,
3468 &objfile
->static_psymbols
,
3470 cu
->language
, objfile
);
3473 case DW_TAG_typedef
:
3474 case DW_TAG_base_type
:
3475 case DW_TAG_subrange_type
:
3476 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3478 VAR_DOMAIN
, LOC_TYPEDEF
,
3479 &objfile
->static_psymbols
,
3480 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3482 case DW_TAG_namespace
:
3483 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3485 VAR_DOMAIN
, LOC_TYPEDEF
,
3486 &objfile
->global_psymbols
,
3487 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3489 case DW_TAG_class_type
:
3490 case DW_TAG_interface_type
:
3491 case DW_TAG_structure_type
:
3492 case DW_TAG_union_type
:
3493 case DW_TAG_enumeration_type
:
3494 /* Skip external references. The DWARF standard says in the section
3495 about "Structure, Union, and Class Type Entries": "An incomplete
3496 structure, union or class type is represented by a structure,
3497 union or class entry that does not have a byte size attribute
3498 and that has a DW_AT_declaration attribute." */
3499 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
3501 if (built_actual_name
)
3502 xfree (actual_name
);
3506 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
3507 static vs. global. */
3508 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3510 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3511 (cu
->language
== language_cplus
3512 || cu
->language
== language_java
)
3513 ? &objfile
->global_psymbols
3514 : &objfile
->static_psymbols
,
3515 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3518 case DW_TAG_enumerator
:
3519 add_psymbol_to_list (actual_name
, strlen (actual_name
),
3521 VAR_DOMAIN
, LOC_CONST
,
3522 (cu
->language
== language_cplus
3523 || cu
->language
== language_java
)
3524 ? &objfile
->global_psymbols
3525 : &objfile
->static_psymbols
,
3526 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
3532 if (built_actual_name
)
3533 xfree (actual_name
);
3536 /* Read a partial die corresponding to a namespace; also, add a symbol
3537 corresponding to that namespace to the symbol table. NAMESPACE is
3538 the name of the enclosing namespace. */
3541 add_partial_namespace (struct partial_die_info
*pdi
,
3542 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3543 int need_pc
, struct dwarf2_cu
*cu
)
3545 /* Add a symbol for the namespace. */
3547 add_partial_symbol (pdi
, cu
);
3549 /* Now scan partial symbols in that namespace. */
3551 if (pdi
->has_children
)
3552 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3555 /* Read a partial die corresponding to a Fortran module. */
3558 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
3559 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
3561 /* Now scan partial symbols in that module. */
3563 if (pdi
->has_children
)
3564 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
3567 /* Read a partial die corresponding to a subprogram and create a partial
3568 symbol for that subprogram. When the CU language allows it, this
3569 routine also defines a partial symbol for each nested subprogram
3570 that this subprogram contains.
3572 DIE my also be a lexical block, in which case we simply search
3573 recursively for suprograms defined inside that lexical block.
3574 Again, this is only performed when the CU language allows this
3575 type of definitions. */
3578 add_partial_subprogram (struct partial_die_info
*pdi
,
3579 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3580 int need_pc
, struct dwarf2_cu
*cu
)
3582 if (pdi
->tag
== DW_TAG_subprogram
)
3584 if (pdi
->has_pc_info
)
3586 if (pdi
->lowpc
< *lowpc
)
3587 *lowpc
= pdi
->lowpc
;
3588 if (pdi
->highpc
> *highpc
)
3589 *highpc
= pdi
->highpc
;
3593 struct objfile
*objfile
= cu
->objfile
;
3595 baseaddr
= ANOFFSET (objfile
->section_offsets
,
3596 SECT_OFF_TEXT (objfile
));
3597 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3598 pdi
->lowpc
+ baseaddr
,
3599 pdi
->highpc
- 1 + baseaddr
,
3600 cu
->per_cu
->v
.psymtab
);
3602 if (!pdi
->is_declaration
)
3603 /* Ignore subprogram DIEs that do not have a name, they are
3604 illegal. Do not emit a complaint at this point, we will
3605 do so when we convert this psymtab into a symtab. */
3607 add_partial_symbol (pdi
, cu
);
3611 if (! pdi
->has_children
)
3614 if (cu
->language
== language_ada
)
3616 pdi
= pdi
->die_child
;
3619 fixup_partial_die (pdi
, cu
);
3620 if (pdi
->tag
== DW_TAG_subprogram
3621 || pdi
->tag
== DW_TAG_lexical_block
)
3622 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
3623 pdi
= pdi
->die_sibling
;
3628 /* See if we can figure out if the class lives in a namespace. We do
3629 this by looking for a member function; its demangled name will
3630 contain namespace info, if there is any. */
3633 guess_structure_name (struct partial_die_info
*struct_pdi
,
3634 struct dwarf2_cu
*cu
)
3636 if ((cu
->language
== language_cplus
3637 || cu
->language
== language_java
)
3638 && cu
->has_namespace_info
== 0
3639 && struct_pdi
->has_children
)
3641 /* NOTE: carlton/2003-10-07: Getting the info this way changes
3642 what template types look like, because the demangler
3643 frequently doesn't give the same name as the debug info. We
3644 could fix this by only using the demangled name to get the
3645 prefix (but see comment in read_structure_type). */
3647 struct partial_die_info
*real_pdi
;
3649 /* If this DIE (this DIE's specification, if any) has a parent, then
3650 we should not do this. We'll prepend the parent's fully qualified
3651 name when we create the partial symbol. */
3653 real_pdi
= struct_pdi
;
3654 while (real_pdi
->has_specification
)
3655 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
3657 if (real_pdi
->die_parent
!= NULL
)
3662 /* Read a partial die corresponding to an enumeration type. */
3665 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
3666 struct dwarf2_cu
*cu
)
3668 struct partial_die_info
*pdi
;
3670 if (enum_pdi
->name
!= NULL
)
3671 add_partial_symbol (enum_pdi
, cu
);
3673 pdi
= enum_pdi
->die_child
;
3676 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
3677 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
3679 add_partial_symbol (pdi
, cu
);
3680 pdi
= pdi
->die_sibling
;
3684 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
3685 Return the corresponding abbrev, or NULL if the number is zero (indicating
3686 an empty DIE). In either case *BYTES_READ will be set to the length of
3687 the initial number. */
3689 static struct abbrev_info
*
3690 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
3691 struct dwarf2_cu
*cu
)
3693 bfd
*abfd
= cu
->objfile
->obfd
;
3694 unsigned int abbrev_number
;
3695 struct abbrev_info
*abbrev
;
3697 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
3699 if (abbrev_number
== 0)
3702 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
3705 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
3706 bfd_get_filename (abfd
));
3712 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3713 Returns a pointer to the end of a series of DIEs, terminated by an empty
3714 DIE. Any children of the skipped DIEs will also be skipped. */
3717 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
3719 struct abbrev_info
*abbrev
;
3720 unsigned int bytes_read
;
3724 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
3726 return info_ptr
+ bytes_read
;
3728 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
3732 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
3733 INFO_PTR should point just after the initial uleb128 of a DIE, and the
3734 abbrev corresponding to that skipped uleb128 should be passed in
3735 ABBREV. Returns a pointer to this DIE's sibling, skipping any
3739 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3740 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
3742 unsigned int bytes_read
;
3743 struct attribute attr
;
3744 bfd
*abfd
= cu
->objfile
->obfd
;
3745 unsigned int form
, i
;
3747 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
3749 /* The only abbrev we care about is DW_AT_sibling. */
3750 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
3752 read_attribute (&attr
, &abbrev
->attrs
[i
],
3753 abfd
, info_ptr
, cu
);
3754 if (attr
.form
== DW_FORM_ref_addr
)
3755 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
3757 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
3760 /* If it isn't DW_AT_sibling, skip this attribute. */
3761 form
= abbrev
->attrs
[i
].form
;
3765 case DW_FORM_ref_addr
:
3766 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
3767 and later it is offset sized. */
3768 if (cu
->header
.version
== 2)
3769 info_ptr
+= cu
->header
.addr_size
;
3771 info_ptr
+= cu
->header
.offset_size
;
3774 info_ptr
+= cu
->header
.addr_size
;
3781 case DW_FORM_flag_present
:
3796 case DW_FORM_string
:
3797 read_string (abfd
, info_ptr
, &bytes_read
);
3798 info_ptr
+= bytes_read
;
3800 case DW_FORM_sec_offset
:
3802 info_ptr
+= cu
->header
.offset_size
;
3804 case DW_FORM_exprloc
:
3806 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3807 info_ptr
+= bytes_read
;
3809 case DW_FORM_block1
:
3810 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
3812 case DW_FORM_block2
:
3813 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
3815 case DW_FORM_block4
:
3816 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
3820 case DW_FORM_ref_udata
:
3821 info_ptr
= skip_leb128 (abfd
, info_ptr
);
3823 case DW_FORM_indirect
:
3824 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3825 info_ptr
+= bytes_read
;
3826 /* We need to continue parsing from here, so just go back to
3828 goto skip_attribute
;
3831 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
3832 dwarf_form_name (form
),
3833 bfd_get_filename (abfd
));
3837 if (abbrev
->has_children
)
3838 return skip_children (buffer
, info_ptr
, cu
);
3843 /* Locate ORIG_PDI's sibling.
3844 INFO_PTR should point to the start of the next DIE after ORIG_PDI
3848 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
3849 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
3850 bfd
*abfd
, struct dwarf2_cu
*cu
)
3852 /* Do we know the sibling already? */
3854 if (orig_pdi
->sibling
)
3855 return orig_pdi
->sibling
;
3857 /* Are there any children to deal with? */
3859 if (!orig_pdi
->has_children
)
3862 /* Skip the children the long way. */
3864 return skip_children (buffer
, info_ptr
, cu
);
3867 /* Expand this partial symbol table into a full symbol table. */
3870 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
3876 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
3882 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
3883 gdb_flush (gdb_stdout
);
3886 /* Restore our global data. */
3887 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
3888 dwarf2_objfile_data_key
);
3890 /* If this psymtab is constructed from a debug-only objfile, the
3891 has_section_at_zero flag will not necessarily be correct. We
3892 can get the correct value for this flag by looking at the data
3893 associated with the (presumably stripped) associated objfile. */
3894 if (pst
->objfile
->separate_debug_objfile_backlink
)
3896 struct dwarf2_per_objfile
*dpo_backlink
3897 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
3898 dwarf2_objfile_data_key
);
3900 dwarf2_per_objfile
->has_section_at_zero
3901 = dpo_backlink
->has_section_at_zero
;
3904 psymtab_to_symtab_1 (pst
);
3906 /* Finish up the debug error message. */
3908 printf_filtered (_("done.\n"));
3913 /* Add PER_CU to the queue. */
3916 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3918 struct dwarf2_queue_item
*item
;
3921 item
= xmalloc (sizeof (*item
));
3922 item
->per_cu
= per_cu
;
3925 if (dwarf2_queue
== NULL
)
3926 dwarf2_queue
= item
;
3928 dwarf2_queue_tail
->next
= item
;
3930 dwarf2_queue_tail
= item
;
3933 /* Process the queue. */
3936 process_queue (struct objfile
*objfile
)
3938 struct dwarf2_queue_item
*item
, *next_item
;
3940 /* The queue starts out with one item, but following a DIE reference
3941 may load a new CU, adding it to the end of the queue. */
3942 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
3944 if (dwarf2_per_objfile
->using_index
3945 ? !item
->per_cu
->v
.quick
->symtab
3946 : (item
->per_cu
->v
.psymtab
&& !item
->per_cu
->v
.psymtab
->readin
))
3947 process_full_comp_unit (item
->per_cu
);
3949 item
->per_cu
->queued
= 0;
3950 next_item
= item
->next
;
3954 dwarf2_queue_tail
= NULL
;
3957 /* Free all allocated queue entries. This function only releases anything if
3958 an error was thrown; if the queue was processed then it would have been
3959 freed as we went along. */
3962 dwarf2_release_queue (void *dummy
)
3964 struct dwarf2_queue_item
*item
, *last
;
3966 item
= dwarf2_queue
;
3969 /* Anything still marked queued is likely to be in an
3970 inconsistent state, so discard it. */
3971 if (item
->per_cu
->queued
)
3973 if (item
->per_cu
->cu
!= NULL
)
3974 free_one_cached_comp_unit (item
->per_cu
->cu
);
3975 item
->per_cu
->queued
= 0;
3983 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
3986 /* Read in full symbols for PST, and anything it depends on. */
3989 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
3991 struct dwarf2_per_cu_data
*per_cu
;
3992 struct cleanup
*back_to
;
3995 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
3996 if (!pst
->dependencies
[i
]->readin
)
3998 /* Inform about additional files that need to be read in. */
4001 /* FIXME: i18n: Need to make this a single string. */
4002 fputs_filtered (" ", gdb_stdout
);
4004 fputs_filtered ("and ", gdb_stdout
);
4006 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
4007 wrap_here (""); /* Flush output */
4008 gdb_flush (gdb_stdout
);
4010 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
4013 per_cu
= pst
->read_symtab_private
;
4017 /* It's an include file, no symbols to read for it.
4018 Everything is in the parent symtab. */
4023 dw2_do_instantiate_symtab (pst
->objfile
, per_cu
);
4026 /* Load the DIEs associated with PER_CU into memory. */
4029 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
4031 bfd
*abfd
= objfile
->obfd
;
4032 struct dwarf2_cu
*cu
;
4033 unsigned int offset
;
4034 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
4035 struct cleanup
*back_to
, *free_cu_cleanup
;
4036 struct attribute
*attr
;
4038 gdb_assert (! per_cu
->from_debug_types
);
4040 /* Set local variables from the partial symbol table info. */
4041 offset
= per_cu
->offset
;
4043 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
4044 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
4045 beg_of_comp_unit
= info_ptr
;
4047 cu
= alloc_one_comp_unit (objfile
);
4049 /* If an error occurs while loading, release our storage. */
4050 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
4052 /* Read in the comp_unit header. */
4053 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
4055 /* Complete the cu_header. */
4056 cu
->header
.offset
= offset
;
4057 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
4059 /* Read the abbrevs for this compilation unit. */
4060 dwarf2_read_abbrevs (abfd
, cu
);
4061 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
4063 /* Link this compilation unit into the compilation unit tree. */
4065 cu
->per_cu
= per_cu
;
4066 cu
->type_hash
= per_cu
->type_hash
;
4068 cu
->dies
= read_comp_unit (info_ptr
, cu
);
4070 /* We try not to read any attributes in this function, because not
4071 all objfiles needed for references have been loaded yet, and symbol
4072 table processing isn't initialized. But we have to set the CU language,
4073 or we won't be able to build types correctly. */
4074 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
4076 set_cu_language (DW_UNSND (attr
), cu
);
4078 set_cu_language (language_minimal
, cu
);
4080 /* Similarly, if we do not read the producer, we can not apply
4081 producer-specific interpretation. */
4082 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
4084 cu
->producer
= DW_STRING (attr
);
4086 /* Link this CU into read_in_chain. */
4087 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
4088 dwarf2_per_objfile
->read_in_chain
= per_cu
;
4090 do_cleanups (back_to
);
4092 /* We've successfully allocated this compilation unit. Let our caller
4093 clean it up when finished with it. */
4094 discard_cleanups (free_cu_cleanup
);
4097 /* Generate full symbol information for PST and CU, whose DIEs have
4098 already been loaded into memory. */
4101 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
4103 struct dwarf2_cu
*cu
= per_cu
->cu
;
4104 struct objfile
*objfile
= per_cu
->objfile
;
4105 CORE_ADDR lowpc
, highpc
;
4106 struct symtab
*symtab
;
4107 struct cleanup
*back_to
;
4110 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4113 back_to
= make_cleanup (really_free_pendings
, NULL
);
4115 cu
->list_in_scope
= &file_symbols
;
4117 dwarf2_find_base_address (cu
->dies
, cu
);
4119 /* Do line number decoding in read_file_scope () */
4120 process_die (cu
->dies
, cu
);
4122 /* Some compilers don't define a DW_AT_high_pc attribute for the
4123 compilation unit. If the DW_AT_high_pc is missing, synthesize
4124 it, by scanning the DIE's below the compilation unit. */
4125 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
4127 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
4129 /* Set symtab language to language from DW_AT_language.
4130 If the compilation is from a C file generated by language preprocessors,
4131 do not set the language if it was already deduced by start_subfile. */
4133 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
4135 symtab
->language
= cu
->language
;
4138 if (dwarf2_per_objfile
->using_index
)
4139 per_cu
->v
.quick
->symtab
= symtab
;
4142 struct partial_symtab
*pst
= per_cu
->v
.psymtab
;
4143 pst
->symtab
= symtab
;
4147 do_cleanups (back_to
);
4150 /* Process a die and its children. */
4153 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
4157 case DW_TAG_padding
:
4159 case DW_TAG_compile_unit
:
4160 read_file_scope (die
, cu
);
4162 case DW_TAG_type_unit
:
4163 read_type_unit_scope (die
, cu
);
4165 case DW_TAG_subprogram
:
4166 case DW_TAG_inlined_subroutine
:
4167 read_func_scope (die
, cu
);
4169 case DW_TAG_lexical_block
:
4170 case DW_TAG_try_block
:
4171 case DW_TAG_catch_block
:
4172 read_lexical_block_scope (die
, cu
);
4174 case DW_TAG_class_type
:
4175 case DW_TAG_interface_type
:
4176 case DW_TAG_structure_type
:
4177 case DW_TAG_union_type
:
4178 process_structure_scope (die
, cu
);
4180 case DW_TAG_enumeration_type
:
4181 process_enumeration_scope (die
, cu
);
4184 /* These dies have a type, but processing them does not create
4185 a symbol or recurse to process the children. Therefore we can
4186 read them on-demand through read_type_die. */
4187 case DW_TAG_subroutine_type
:
4188 case DW_TAG_set_type
:
4189 case DW_TAG_array_type
:
4190 case DW_TAG_pointer_type
:
4191 case DW_TAG_ptr_to_member_type
:
4192 case DW_TAG_reference_type
:
4193 case DW_TAG_string_type
:
4196 case DW_TAG_base_type
:
4197 case DW_TAG_subrange_type
:
4198 case DW_TAG_typedef
:
4199 case DW_TAG_const_type
:
4200 case DW_TAG_volatile_type
:
4201 /* Add a typedef symbol for the type definition, if it has a
4203 new_symbol (die
, read_type_die (die
, cu
), cu
);
4205 case DW_TAG_common_block
:
4206 read_common_block (die
, cu
);
4208 case DW_TAG_common_inclusion
:
4210 case DW_TAG_namespace
:
4211 processing_has_namespace_info
= 1;
4212 read_namespace (die
, cu
);
4215 processing_has_namespace_info
= 1;
4216 read_module (die
, cu
);
4218 case DW_TAG_imported_declaration
:
4219 case DW_TAG_imported_module
:
4220 processing_has_namespace_info
= 1;
4221 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
4222 || cu
->language
!= language_fortran
))
4223 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
4224 dwarf_tag_name (die
->tag
));
4225 read_import_statement (die
, cu
);
4228 new_symbol (die
, NULL
, cu
);
4233 /* A helper function for dwarf2_compute_name which determines whether DIE
4234 needs to have the name of the scope prepended to the name listed in the
4238 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4240 struct attribute
*attr
;
4244 case DW_TAG_namespace
:
4245 case DW_TAG_typedef
:
4246 case DW_TAG_class_type
:
4247 case DW_TAG_interface_type
:
4248 case DW_TAG_structure_type
:
4249 case DW_TAG_union_type
:
4250 case DW_TAG_enumeration_type
:
4251 case DW_TAG_enumerator
:
4252 case DW_TAG_subprogram
:
4256 case DW_TAG_variable
:
4257 /* We only need to prefix "globally" visible variables. These include
4258 any variable marked with DW_AT_external or any variable that
4259 lives in a namespace. [Variables in anonymous namespaces
4260 require prefixing, but they are not DW_AT_external.] */
4262 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
4264 struct dwarf2_cu
*spec_cu
= cu
;
4266 return die_needs_namespace (die_specification (die
, &spec_cu
),
4270 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4271 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
4272 && die
->parent
->tag
!= DW_TAG_module
)
4274 /* A variable in a lexical block of some kind does not need a
4275 namespace, even though in C++ such variables may be external
4276 and have a mangled name. */
4277 if (die
->parent
->tag
== DW_TAG_lexical_block
4278 || die
->parent
->tag
== DW_TAG_try_block
4279 || die
->parent
->tag
== DW_TAG_catch_block
4280 || die
->parent
->tag
== DW_TAG_subprogram
)
4289 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
4290 compute the physname for the object, which include a method's
4291 formal parameters (C++/Java) and return type (Java).
4293 For Ada, return the DIE's linkage name rather than the fully qualified
4294 name. PHYSNAME is ignored..
4296 The result is allocated on the objfile_obstack and canonicalized. */
4299 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
4303 name
= dwarf2_name (die
, cu
);
4305 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
4306 compute it by typename_concat inside GDB. */
4307 if (cu
->language
== language_ada
4308 || (cu
->language
== language_fortran
&& physname
))
4310 /* For Ada unit, we prefer the linkage name over the name, as
4311 the former contains the exported name, which the user expects
4312 to be able to reference. Ideally, we want the user to be able
4313 to reference this entity using either natural or linkage name,
4314 but we haven't started looking at this enhancement yet. */
4315 struct attribute
*attr
;
4317 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
4319 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
4320 if (attr
&& DW_STRING (attr
))
4321 return DW_STRING (attr
);
4324 /* These are the only languages we know how to qualify names in. */
4326 && (cu
->language
== language_cplus
|| cu
->language
== language_java
4327 || cu
->language
== language_fortran
))
4329 if (die_needs_namespace (die
, cu
))
4333 struct ui_file
*buf
;
4335 prefix
= determine_prefix (die
, cu
);
4336 buf
= mem_fileopen ();
4337 if (*prefix
!= '\0')
4339 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
4342 fputs_unfiltered (prefixed_name
, buf
);
4343 xfree (prefixed_name
);
4346 fputs_unfiltered (name
? name
: "", buf
);
4348 /* For Java and C++ methods, append formal parameter type
4349 information, if PHYSNAME. */
4351 if (physname
&& die
->tag
== DW_TAG_subprogram
4352 && (cu
->language
== language_cplus
4353 || cu
->language
== language_java
))
4355 struct type
*type
= read_type_die (die
, cu
);
4357 c_type_print_args (type
, buf
, 0, cu
->language
);
4359 if (cu
->language
== language_java
)
4361 /* For java, we must append the return type to method
4363 if (die
->tag
== DW_TAG_subprogram
)
4364 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
4367 else if (cu
->language
== language_cplus
)
4369 if (TYPE_NFIELDS (type
) > 0
4370 && TYPE_FIELD_ARTIFICIAL (type
, 0)
4371 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
4372 fputs_unfiltered (" const", buf
);
4376 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
4378 ui_file_delete (buf
);
4380 if (cu
->language
== language_cplus
)
4383 = dwarf2_canonicalize_name (name
, cu
,
4384 &cu
->objfile
->objfile_obstack
);
4395 /* Return the fully qualified name of DIE, based on its DW_AT_name.
4396 If scope qualifiers are appropriate they will be added. The result
4397 will be allocated on the objfile_obstack, or NULL if the DIE does
4398 not have a name. NAME may either be from a previous call to
4399 dwarf2_name or NULL.
4401 The output string will be canonicalized (if C++/Java). */
4404 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4406 return dwarf2_compute_name (name
, die
, cu
, 0);
4409 /* Construct a physname for the given DIE in CU. NAME may either be
4410 from a previous call to dwarf2_name or NULL. The result will be
4411 allocated on the objfile_objstack or NULL if the DIE does not have a
4414 The output string will be canonicalized (if C++/Java). */
4417 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
4419 return dwarf2_compute_name (name
, die
, cu
, 1);
4422 /* Read the import statement specified by the given die and record it. */
4425 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
4427 struct attribute
*import_attr
;
4428 struct die_info
*imported_die
;
4429 struct dwarf2_cu
*imported_cu
;
4430 const char *imported_name
;
4431 const char *imported_name_prefix
;
4432 const char *canonical_name
;
4433 const char *import_alias
;
4434 const char *imported_declaration
= NULL
;
4435 const char *import_prefix
;
4439 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
4440 if (import_attr
== NULL
)
4442 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
4443 dwarf_tag_name (die
->tag
));
4448 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
4449 imported_name
= dwarf2_name (imported_die
, imported_cu
);
4450 if (imported_name
== NULL
)
4452 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
4454 The import in the following code:
4468 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
4469 <52> DW_AT_decl_file : 1
4470 <53> DW_AT_decl_line : 6
4471 <54> DW_AT_import : <0x75>
4472 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
4474 <5b> DW_AT_decl_file : 1
4475 <5c> DW_AT_decl_line : 2
4476 <5d> DW_AT_type : <0x6e>
4478 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
4479 <76> DW_AT_byte_size : 4
4480 <77> DW_AT_encoding : 5 (signed)
4482 imports the wrong die ( 0x75 instead of 0x58 ).
4483 This case will be ignored until the gcc bug is fixed. */
4487 /* Figure out the local name after import. */
4488 import_alias
= dwarf2_name (die
, cu
);
4490 /* Figure out where the statement is being imported to. */
4491 import_prefix
= determine_prefix (die
, cu
);
4493 /* Figure out what the scope of the imported die is and prepend it
4494 to the name of the imported die. */
4495 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
4497 if (imported_die
->tag
!= DW_TAG_namespace
4498 && imported_die
->tag
!= DW_TAG_module
)
4500 imported_declaration
= imported_name
;
4501 canonical_name
= imported_name_prefix
;
4503 else if (strlen (imported_name_prefix
) > 0)
4505 temp
= alloca (strlen (imported_name_prefix
)
4506 + 2 + strlen (imported_name
) + 1);
4507 strcpy (temp
, imported_name_prefix
);
4508 strcat (temp
, "::");
4509 strcat (temp
, imported_name
);
4510 canonical_name
= temp
;
4513 canonical_name
= imported_name
;
4515 cp_add_using_directive (import_prefix
,
4518 imported_declaration
,
4519 &cu
->objfile
->objfile_obstack
);
4523 initialize_cu_func_list (struct dwarf2_cu
*cu
)
4525 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
4529 free_cu_line_header (void *arg
)
4531 struct dwarf2_cu
*cu
= arg
;
4533 free_line_header (cu
->line_header
);
4534 cu
->line_header
= NULL
;
4538 find_file_and_directory (struct die_info
*die
, struct dwarf2_cu
*cu
,
4539 char **name
, char **comp_dir
)
4541 struct attribute
*attr
;
4546 /* Find the filename. Do not use dwarf2_name here, since the filename
4547 is not a source language identifier. */
4548 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4551 *name
= DW_STRING (attr
);
4554 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
4556 *comp_dir
= DW_STRING (attr
);
4557 else if (*name
!= NULL
&& IS_ABSOLUTE_PATH (*name
))
4559 *comp_dir
= ldirname (*name
);
4560 if (*comp_dir
!= NULL
)
4561 make_cleanup (xfree
, *comp_dir
);
4563 if (*comp_dir
!= NULL
)
4565 /* Irix 6.2 native cc prepends <machine>.: to the compilation
4566 directory, get rid of it. */
4567 char *cp
= strchr (*comp_dir
, ':');
4569 if (cp
&& cp
!= *comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
4574 *name
= "<unknown>";
4578 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4580 struct objfile
*objfile
= cu
->objfile
;
4581 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4582 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
4583 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
4584 struct attribute
*attr
;
4586 char *comp_dir
= NULL
;
4587 struct die_info
*child_die
;
4588 bfd
*abfd
= objfile
->obfd
;
4589 struct line_header
*line_header
= 0;
4592 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4594 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
4596 /* If we didn't find a lowpc, set it to highpc to avoid complaints
4597 from finish_block. */
4598 if (lowpc
== ((CORE_ADDR
) -1))
4603 find_file_and_directory (die
, cu
, &name
, &comp_dir
);
4605 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
4608 set_cu_language (DW_UNSND (attr
), cu
);
4611 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
4613 cu
->producer
= DW_STRING (attr
);
4615 /* We assume that we're processing GCC output. */
4616 processing_gcc_compilation
= 2;
4618 processing_has_namespace_info
= 0;
4620 start_symtab (name
, comp_dir
, lowpc
);
4621 record_debugformat ("DWARF 2");
4622 record_producer (cu
->producer
);
4624 initialize_cu_func_list (cu
);
4626 /* Decode line number information if present. We do this before
4627 processing child DIEs, so that the line header table is available
4628 for DW_AT_decl_file. */
4629 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
4632 unsigned int line_offset
= DW_UNSND (attr
);
4633 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
4636 cu
->line_header
= line_header
;
4637 make_cleanup (free_cu_line_header
, cu
);
4638 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
4642 /* Process all dies in compilation unit. */
4643 if (die
->child
!= NULL
)
4645 child_die
= die
->child
;
4646 while (child_die
&& child_die
->tag
)
4648 process_die (child_die
, cu
);
4649 child_die
= sibling_die (child_die
);
4653 /* Decode macro information, if present. Dwarf 2 macro information
4654 refers to information in the line number info statement program
4655 header, so we can only read it if we've read the header
4657 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
4658 if (attr
&& line_header
)
4660 unsigned int macro_offset
= DW_UNSND (attr
);
4662 dwarf_decode_macros (line_header
, macro_offset
,
4663 comp_dir
, abfd
, cu
);
4665 do_cleanups (back_to
);
4668 /* For TUs we want to skip the first top level sibling if it's not the
4669 actual type being defined by this TU. In this case the first top
4670 level sibling is there to provide context only. */
4673 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4675 struct objfile
*objfile
= cu
->objfile
;
4676 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4678 struct attribute
*attr
;
4680 char *comp_dir
= NULL
;
4681 struct die_info
*child_die
;
4682 bfd
*abfd
= objfile
->obfd
;
4684 /* start_symtab needs a low pc, but we don't really have one.
4685 Do what read_file_scope would do in the absence of such info. */
4686 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4688 /* Find the filename. Do not use dwarf2_name here, since the filename
4689 is not a source language identifier. */
4690 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4692 name
= DW_STRING (attr
);
4694 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
4696 comp_dir
= DW_STRING (attr
);
4697 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
4699 comp_dir
= ldirname (name
);
4700 if (comp_dir
!= NULL
)
4701 make_cleanup (xfree
, comp_dir
);
4707 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
4709 set_cu_language (DW_UNSND (attr
), cu
);
4711 /* This isn't technically needed today. It is done for symmetry
4712 with read_file_scope. */
4713 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
4715 cu
->producer
= DW_STRING (attr
);
4717 /* We assume that we're processing GCC output. */
4718 processing_gcc_compilation
= 2;
4720 processing_has_namespace_info
= 0;
4722 start_symtab (name
, comp_dir
, lowpc
);
4723 record_debugformat ("DWARF 2");
4724 record_producer (cu
->producer
);
4726 /* Process the dies in the type unit. */
4727 if (die
->child
== NULL
)
4729 dump_die_for_error (die
);
4730 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
4731 bfd_get_filename (abfd
));
4734 child_die
= die
->child
;
4736 while (child_die
&& child_die
->tag
)
4738 process_die (child_die
, cu
);
4740 child_die
= sibling_die (child_die
);
4743 do_cleanups (back_to
);
4747 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
4748 struct dwarf2_cu
*cu
)
4750 struct function_range
*thisfn
;
4752 thisfn
= (struct function_range
*)
4753 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
4754 thisfn
->name
= name
;
4755 thisfn
->lowpc
= lowpc
;
4756 thisfn
->highpc
= highpc
;
4757 thisfn
->seen_line
= 0;
4758 thisfn
->next
= NULL
;
4760 if (cu
->last_fn
== NULL
)
4761 cu
->first_fn
= thisfn
;
4763 cu
->last_fn
->next
= thisfn
;
4765 cu
->last_fn
= thisfn
;
4768 /* qsort helper for inherit_abstract_dies. */
4771 unsigned_int_compar (const void *ap
, const void *bp
)
4773 unsigned int a
= *(unsigned int *) ap
;
4774 unsigned int b
= *(unsigned int *) bp
;
4776 return (a
> b
) - (b
> a
);
4779 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
4780 Inherit only the children of the DW_AT_abstract_origin DIE not being already
4781 referenced by DW_AT_abstract_origin from the children of the current DIE. */
4784 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
4786 struct die_info
*child_die
;
4787 unsigned die_children_count
;
4788 /* CU offsets which were referenced by children of the current DIE. */
4790 unsigned *offsets_end
, *offsetp
;
4791 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
4792 struct die_info
*origin_die
;
4793 /* Iterator of the ORIGIN_DIE children. */
4794 struct die_info
*origin_child_die
;
4795 struct cleanup
*cleanups
;
4796 struct attribute
*attr
;
4798 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
4802 origin_die
= follow_die_ref (die
, attr
, &cu
);
4803 if (die
->tag
!= origin_die
->tag
4804 && !(die
->tag
== DW_TAG_inlined_subroutine
4805 && origin_die
->tag
== DW_TAG_subprogram
))
4806 complaint (&symfile_complaints
,
4807 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
4808 die
->offset
, origin_die
->offset
);
4810 child_die
= die
->child
;
4811 die_children_count
= 0;
4812 while (child_die
&& child_die
->tag
)
4814 child_die
= sibling_die (child_die
);
4815 die_children_count
++;
4817 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
4818 cleanups
= make_cleanup (xfree
, offsets
);
4820 offsets_end
= offsets
;
4821 child_die
= die
->child
;
4822 while (child_die
&& child_die
->tag
)
4824 /* For each CHILD_DIE, find the corresponding child of
4825 ORIGIN_DIE. If there is more than one layer of
4826 DW_AT_abstract_origin, follow them all; there shouldn't be,
4827 but GCC versions at least through 4.4 generate this (GCC PR
4829 struct die_info
*child_origin_die
= child_die
;
4833 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
4836 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
4839 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
4840 counterpart may exist. */
4841 if (child_origin_die
!= child_die
)
4843 if (child_die
->tag
!= child_origin_die
->tag
4844 && !(child_die
->tag
== DW_TAG_inlined_subroutine
4845 && child_origin_die
->tag
== DW_TAG_subprogram
))
4846 complaint (&symfile_complaints
,
4847 _("Child DIE 0x%x and its abstract origin 0x%x have "
4848 "different tags"), child_die
->offset
,
4849 child_origin_die
->offset
);
4850 if (child_origin_die
->parent
!= origin_die
)
4851 complaint (&symfile_complaints
,
4852 _("Child DIE 0x%x and its abstract origin 0x%x have "
4853 "different parents"), child_die
->offset
,
4854 child_origin_die
->offset
);
4856 *offsets_end
++ = child_origin_die
->offset
;
4858 child_die
= sibling_die (child_die
);
4860 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
4861 unsigned_int_compar
);
4862 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
4863 if (offsetp
[-1] == *offsetp
)
4864 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
4865 "to DIE 0x%x as their abstract origin"),
4866 die
->offset
, *offsetp
);
4869 origin_child_die
= origin_die
->child
;
4870 while (origin_child_die
&& origin_child_die
->tag
)
4872 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
4873 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
4875 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
4877 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
4878 process_die (origin_child_die
, cu
);
4880 origin_child_die
= sibling_die (origin_child_die
);
4883 do_cleanups (cleanups
);
4887 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4889 struct objfile
*objfile
= cu
->objfile
;
4890 struct context_stack
*new;
4893 struct die_info
*child_die
;
4894 struct attribute
*attr
, *call_line
, *call_file
;
4897 struct block
*block
;
4898 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
4902 /* If we do not have call site information, we can't show the
4903 caller of this inlined function. That's too confusing, so
4904 only use the scope for local variables. */
4905 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
4906 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
4907 if (call_line
== NULL
|| call_file
== NULL
)
4909 read_lexical_block_scope (die
, cu
);
4914 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4916 name
= dwarf2_name (die
, cu
);
4918 /* Ignore functions with missing or empty names. These are actually
4919 illegal according to the DWARF standard. */
4922 complaint (&symfile_complaints
,
4923 _("missing name for subprogram DIE at %d"), die
->offset
);
4927 /* Ignore functions with missing or invalid low and high pc attributes. */
4928 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
4930 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
4931 if (!attr
|| !DW_UNSND (attr
))
4932 complaint (&symfile_complaints
,
4933 _("cannot get low and high bounds for subprogram DIE at %d"),
4941 /* Record the function range for dwarf_decode_lines. */
4942 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
4944 new = push_context (0, lowpc
);
4945 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
4947 /* If there is a location expression for DW_AT_frame_base, record
4949 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
4951 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
4952 expression is being recorded directly in the function's symbol
4953 and not in a separate frame-base object. I guess this hack is
4954 to avoid adding some sort of frame-base adjunct/annex to the
4955 function's symbol :-(. The problem with doing this is that it
4956 results in a function symbol with a location expression that
4957 has nothing to do with the location of the function, ouch! The
4958 relationship should be: a function's symbol has-a frame base; a
4959 frame-base has-a location expression. */
4960 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
4962 cu
->list_in_scope
= &local_symbols
;
4964 if (die
->child
!= NULL
)
4966 child_die
= die
->child
;
4967 while (child_die
&& child_die
->tag
)
4969 process_die (child_die
, cu
);
4970 child_die
= sibling_die (child_die
);
4974 inherit_abstract_dies (die
, cu
);
4976 /* If we have a DW_AT_specification, we might need to import using
4977 directives from the context of the specification DIE. See the
4978 comment in determine_prefix. */
4979 if (cu
->language
== language_cplus
4980 && dwarf2_attr (die
, DW_AT_specification
, cu
))
4982 struct dwarf2_cu
*spec_cu
= cu
;
4983 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
4987 child_die
= spec_die
->child
;
4988 while (child_die
&& child_die
->tag
)
4990 if (child_die
->tag
== DW_TAG_imported_module
)
4991 process_die (child_die
, spec_cu
);
4992 child_die
= sibling_die (child_die
);
4995 /* In some cases, GCC generates specification DIEs that
4996 themselves contain DW_AT_specification attributes. */
4997 spec_die
= die_specification (spec_die
, &spec_cu
);
5001 new = pop_context ();
5002 /* Make a block for the local symbols within. */
5003 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
5004 lowpc
, highpc
, objfile
);
5006 /* For C++, set the block's scope. */
5007 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
5008 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
5009 determine_prefix (die
, cu
),
5010 processing_has_namespace_info
);
5012 /* If we have address ranges, record them. */
5013 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5015 /* In C++, we can have functions nested inside functions (e.g., when
5016 a function declares a class that has methods). This means that
5017 when we finish processing a function scope, we may need to go
5018 back to building a containing block's symbol lists. */
5019 local_symbols
= new->locals
;
5020 param_symbols
= new->params
;
5021 using_directives
= new->using_directives
;
5023 /* If we've finished processing a top-level function, subsequent
5024 symbols go in the file symbol list. */
5025 if (outermost_context_p ())
5026 cu
->list_in_scope
= &file_symbols
;
5029 /* Process all the DIES contained within a lexical block scope. Start
5030 a new scope, process the dies, and then close the scope. */
5033 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5035 struct objfile
*objfile
= cu
->objfile
;
5036 struct context_stack
*new;
5037 CORE_ADDR lowpc
, highpc
;
5038 struct die_info
*child_die
;
5041 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5043 /* Ignore blocks with missing or invalid low and high pc attributes. */
5044 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
5045 as multiple lexical blocks? Handling children in a sane way would
5046 be nasty. Might be easier to properly extend generic blocks to
5048 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
5053 push_context (0, lowpc
);
5054 if (die
->child
!= NULL
)
5056 child_die
= die
->child
;
5057 while (child_die
&& child_die
->tag
)
5059 process_die (child_die
, cu
);
5060 child_die
= sibling_die (child_die
);
5063 new = pop_context ();
5065 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
5068 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
5071 /* Note that recording ranges after traversing children, as we
5072 do here, means that recording a parent's ranges entails
5073 walking across all its children's ranges as they appear in
5074 the address map, which is quadratic behavior.
5076 It would be nicer to record the parent's ranges before
5077 traversing its children, simply overriding whatever you find
5078 there. But since we don't even decide whether to create a
5079 block until after we've traversed its children, that's hard
5081 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
5083 local_symbols
= new->locals
;
5084 using_directives
= new->using_directives
;
5087 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
5088 Return 1 if the attributes are present and valid, otherwise, return 0.
5089 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
5092 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
5093 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
5094 struct partial_symtab
*ranges_pst
)
5096 struct objfile
*objfile
= cu
->objfile
;
5097 struct comp_unit_head
*cu_header
= &cu
->header
;
5098 bfd
*obfd
= objfile
->obfd
;
5099 unsigned int addr_size
= cu_header
->addr_size
;
5100 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5101 /* Base address selection entry. */
5112 found_base
= cu
->base_known
;
5113 base
= cu
->base_address
;
5115 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
5116 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5118 complaint (&symfile_complaints
,
5119 _("Offset %d out of bounds for DW_AT_ranges attribute"),
5123 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5125 /* Read in the largest possible address. */
5126 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
5127 if ((marker
& mask
) == mask
)
5129 /* If we found the largest possible address, then
5130 read the base address. */
5131 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5132 buffer
+= 2 * addr_size
;
5133 offset
+= 2 * addr_size
;
5139 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
5143 CORE_ADDR range_beginning
, range_end
;
5145 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
5146 buffer
+= addr_size
;
5147 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
5148 buffer
+= addr_size
;
5149 offset
+= 2 * addr_size
;
5151 /* An end of list marker is a pair of zero addresses. */
5152 if (range_beginning
== 0 && range_end
== 0)
5153 /* Found the end of list entry. */
5156 /* Each base address selection entry is a pair of 2 values.
5157 The first is the largest possible address, the second is
5158 the base address. Check for a base address here. */
5159 if ((range_beginning
& mask
) == mask
)
5161 /* If we found the largest possible address, then
5162 read the base address. */
5163 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
5170 /* We have no valid base address for the ranges
5172 complaint (&symfile_complaints
,
5173 _("Invalid .debug_ranges data (no base address)"));
5177 range_beginning
+= base
;
5180 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
5181 addrmap_set_empty (objfile
->psymtabs_addrmap
,
5182 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
5185 /* FIXME: This is recording everything as a low-high
5186 segment of consecutive addresses. We should have a
5187 data structure for discontiguous block ranges
5191 low
= range_beginning
;
5197 if (range_beginning
< low
)
5198 low
= range_beginning
;
5199 if (range_end
> high
)
5205 /* If the first entry is an end-of-list marker, the range
5206 describes an empty scope, i.e. no instructions. */
5212 *high_return
= high
;
5216 /* Get low and high pc attributes from a die. Return 1 if the attributes
5217 are present and valid, otherwise, return 0. Return -1 if the range is
5218 discontinuous, i.e. derived from DW_AT_ranges information. */
5220 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
5221 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
5222 struct partial_symtab
*pst
)
5224 struct attribute
*attr
;
5229 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5232 high
= DW_ADDR (attr
);
5233 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5235 low
= DW_ADDR (attr
);
5237 /* Found high w/o low attribute. */
5240 /* Found consecutive range of addresses. */
5245 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5248 /* Value of the DW_AT_ranges attribute is the offset in the
5249 .debug_ranges section. */
5250 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
5252 /* Found discontinuous range of addresses. */
5260 /* When using the GNU linker, .gnu.linkonce. sections are used to
5261 eliminate duplicate copies of functions and vtables and such.
5262 The linker will arbitrarily choose one and discard the others.
5263 The AT_*_pc values for such functions refer to local labels in
5264 these sections. If the section from that file was discarded, the
5265 labels are not in the output, so the relocs get a value of 0.
5266 If this is a discarded function, mark the pc bounds as invalid,
5267 so that GDB will ignore it. */
5268 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
5276 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
5277 its low and high PC addresses. Do nothing if these addresses could not
5278 be determined. Otherwise, set LOWPC to the low address if it is smaller,
5279 and HIGHPC to the high address if greater than HIGHPC. */
5282 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
5283 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5284 struct dwarf2_cu
*cu
)
5286 CORE_ADDR low
, high
;
5287 struct die_info
*child
= die
->child
;
5289 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
5291 *lowpc
= min (*lowpc
, low
);
5292 *highpc
= max (*highpc
, high
);
5295 /* If the language does not allow nested subprograms (either inside
5296 subprograms or lexical blocks), we're done. */
5297 if (cu
->language
!= language_ada
)
5300 /* Check all the children of the given DIE. If it contains nested
5301 subprograms, then check their pc bounds. Likewise, we need to
5302 check lexical blocks as well, as they may also contain subprogram
5304 while (child
&& child
->tag
)
5306 if (child
->tag
== DW_TAG_subprogram
5307 || child
->tag
== DW_TAG_lexical_block
)
5308 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
5309 child
= sibling_die (child
);
5313 /* Get the low and high pc's represented by the scope DIE, and store
5314 them in *LOWPC and *HIGHPC. If the correct values can't be
5315 determined, set *LOWPC to -1 and *HIGHPC to 0. */
5318 get_scope_pc_bounds (struct die_info
*die
,
5319 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
5320 struct dwarf2_cu
*cu
)
5322 CORE_ADDR best_low
= (CORE_ADDR
) -1;
5323 CORE_ADDR best_high
= (CORE_ADDR
) 0;
5324 CORE_ADDR current_low
, current_high
;
5326 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
5328 best_low
= current_low
;
5329 best_high
= current_high
;
5333 struct die_info
*child
= die
->child
;
5335 while (child
&& child
->tag
)
5337 switch (child
->tag
) {
5338 case DW_TAG_subprogram
:
5339 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
5341 case DW_TAG_namespace
:
5343 /* FIXME: carlton/2004-01-16: Should we do this for
5344 DW_TAG_class_type/DW_TAG_structure_type, too? I think
5345 that current GCC's always emit the DIEs corresponding
5346 to definitions of methods of classes as children of a
5347 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
5348 the DIEs giving the declarations, which could be
5349 anywhere). But I don't see any reason why the
5350 standards says that they have to be there. */
5351 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
5353 if (current_low
!= ((CORE_ADDR
) -1))
5355 best_low
= min (best_low
, current_low
);
5356 best_high
= max (best_high
, current_high
);
5364 child
= sibling_die (child
);
5369 *highpc
= best_high
;
5372 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
5375 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
5376 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
5378 struct attribute
*attr
;
5380 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
5383 CORE_ADDR high
= DW_ADDR (attr
);
5385 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
5388 CORE_ADDR low
= DW_ADDR (attr
);
5390 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
5394 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
5397 bfd
*obfd
= cu
->objfile
->obfd
;
5399 /* The value of the DW_AT_ranges attribute is the offset of the
5400 address range list in the .debug_ranges section. */
5401 unsigned long offset
= DW_UNSND (attr
);
5402 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
5404 /* For some target architectures, but not others, the
5405 read_address function sign-extends the addresses it returns.
5406 To recognize base address selection entries, we need a
5408 unsigned int addr_size
= cu
->header
.addr_size
;
5409 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
5411 /* The base address, to which the next pair is relative. Note
5412 that this 'base' is a DWARF concept: most entries in a range
5413 list are relative, to reduce the number of relocs against the
5414 debugging information. This is separate from this function's
5415 'baseaddr' argument, which GDB uses to relocate debugging
5416 information from a shared library based on the address at
5417 which the library was loaded. */
5418 CORE_ADDR base
= cu
->base_address
;
5419 int base_known
= cu
->base_known
;
5421 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
5422 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
5424 complaint (&symfile_complaints
,
5425 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
5432 unsigned int bytes_read
;
5433 CORE_ADDR start
, end
;
5435 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5436 buffer
+= bytes_read
;
5437 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
5438 buffer
+= bytes_read
;
5440 /* Did we find the end of the range list? */
5441 if (start
== 0 && end
== 0)
5444 /* Did we find a base address selection entry? */
5445 else if ((start
& base_select_mask
) == base_select_mask
)
5451 /* We found an ordinary address range. */
5456 complaint (&symfile_complaints
,
5457 _("Invalid .debug_ranges data (no base address)"));
5461 record_block_range (block
,
5462 baseaddr
+ base
+ start
,
5463 baseaddr
+ base
+ end
- 1);
5469 /* Add an aggregate field to the field list. */
5472 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
5473 struct dwarf2_cu
*cu
)
5475 struct objfile
*objfile
= cu
->objfile
;
5476 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5477 struct nextfield
*new_field
;
5478 struct attribute
*attr
;
5480 char *fieldname
= "";
5482 /* Allocate a new field list entry and link it in. */
5483 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
5484 make_cleanup (xfree
, new_field
);
5485 memset (new_field
, 0, sizeof (struct nextfield
));
5487 if (die
->tag
== DW_TAG_inheritance
)
5489 new_field
->next
= fip
->baseclasses
;
5490 fip
->baseclasses
= new_field
;
5494 new_field
->next
= fip
->fields
;
5495 fip
->fields
= new_field
;
5499 /* Handle accessibility and virtuality of field.
5500 The default accessibility for members is public, the default
5501 accessibility for inheritance is private. */
5502 if (die
->tag
!= DW_TAG_inheritance
)
5503 new_field
->accessibility
= DW_ACCESS_public
;
5505 new_field
->accessibility
= DW_ACCESS_private
;
5506 new_field
->virtuality
= DW_VIRTUALITY_none
;
5508 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
5510 new_field
->accessibility
= DW_UNSND (attr
);
5511 if (new_field
->accessibility
!= DW_ACCESS_public
)
5512 fip
->non_public_fields
= 1;
5513 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
5515 new_field
->virtuality
= DW_UNSND (attr
);
5517 fp
= &new_field
->field
;
5519 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
5521 /* Data member other than a C++ static data member. */
5523 /* Get type of field. */
5524 fp
->type
= die_type (die
, cu
);
5526 SET_FIELD_BITPOS (*fp
, 0);
5528 /* Get bit size of field (zero if none). */
5529 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
5532 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
5536 FIELD_BITSIZE (*fp
) = 0;
5539 /* Get bit offset of field. */
5540 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
5543 int byte_offset
= 0;
5545 if (attr_form_is_section_offset (attr
))
5546 dwarf2_complex_location_expr_complaint ();
5547 else if (attr_form_is_constant (attr
))
5548 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5549 else if (attr_form_is_block (attr
))
5550 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5552 dwarf2_complex_location_expr_complaint ();
5554 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
5556 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
5559 if (gdbarch_bits_big_endian (gdbarch
))
5561 /* For big endian bits, the DW_AT_bit_offset gives the
5562 additional bit offset from the MSB of the containing
5563 anonymous object to the MSB of the field. We don't
5564 have to do anything special since we don't need to
5565 know the size of the anonymous object. */
5566 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
5570 /* For little endian bits, compute the bit offset to the
5571 MSB of the anonymous object, subtract off the number of
5572 bits from the MSB of the field to the MSB of the
5573 object, and then subtract off the number of bits of
5574 the field itself. The result is the bit offset of
5575 the LSB of the field. */
5577 int bit_offset
= DW_UNSND (attr
);
5579 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5582 /* The size of the anonymous object containing
5583 the bit field is explicit, so use the
5584 indicated size (in bytes). */
5585 anonymous_size
= DW_UNSND (attr
);
5589 /* The size of the anonymous object containing
5590 the bit field must be inferred from the type
5591 attribute of the data member containing the
5593 anonymous_size
= TYPE_LENGTH (fp
->type
);
5595 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
5596 - bit_offset
- FIELD_BITSIZE (*fp
);
5600 /* Get name of field. */
5601 fieldname
= dwarf2_name (die
, cu
);
5602 if (fieldname
== NULL
)
5605 /* The name is already allocated along with this objfile, so we don't
5606 need to duplicate it for the type. */
5607 fp
->name
= fieldname
;
5609 /* Change accessibility for artificial fields (e.g. virtual table
5610 pointer or virtual base class pointer) to private. */
5611 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
5613 FIELD_ARTIFICIAL (*fp
) = 1;
5614 new_field
->accessibility
= DW_ACCESS_private
;
5615 fip
->non_public_fields
= 1;
5618 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
5620 /* C++ static member. */
5622 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
5623 is a declaration, but all versions of G++ as of this writing
5624 (so through at least 3.2.1) incorrectly generate
5625 DW_TAG_variable tags. */
5629 /* Get name of field. */
5630 fieldname
= dwarf2_name (die
, cu
);
5631 if (fieldname
== NULL
)
5634 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
5636 /* Only create a symbol if this is an external value.
5637 new_symbol checks this and puts the value in the global symbol
5638 table, which we want. If it is not external, new_symbol
5639 will try to put the value in cu->list_in_scope which is wrong. */
5640 && dwarf2_flag_true_p (die
, DW_AT_external
, cu
))
5642 /* A static const member, not much different than an enum as far as
5643 we're concerned, except that we can support more types. */
5644 new_symbol (die
, NULL
, cu
);
5647 /* Get physical name. */
5648 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
5650 /* The name is already allocated along with this objfile, so we don't
5651 need to duplicate it for the type. */
5652 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
5653 FIELD_TYPE (*fp
) = die_type (die
, cu
);
5654 FIELD_NAME (*fp
) = fieldname
;
5656 else if (die
->tag
== DW_TAG_inheritance
)
5658 /* C++ base class field. */
5659 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
5662 int byte_offset
= 0;
5664 if (attr_form_is_section_offset (attr
))
5665 dwarf2_complex_location_expr_complaint ();
5666 else if (attr_form_is_constant (attr
))
5667 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5668 else if (attr_form_is_block (attr
))
5669 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5671 dwarf2_complex_location_expr_complaint ();
5673 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
5675 FIELD_BITSIZE (*fp
) = 0;
5676 FIELD_TYPE (*fp
) = die_type (die
, cu
);
5677 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
5678 fip
->nbaseclasses
++;
5682 /* Add a typedef defined in the scope of the FIP's class. */
5685 dwarf2_add_typedef (struct field_info
*fip
, struct die_info
*die
,
5686 struct dwarf2_cu
*cu
)
5688 struct objfile
*objfile
= cu
->objfile
;
5689 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5690 struct typedef_field_list
*new_field
;
5691 struct attribute
*attr
;
5692 struct typedef_field
*fp
;
5693 char *fieldname
= "";
5695 /* Allocate a new field list entry and link it in. */
5696 new_field
= xzalloc (sizeof (*new_field
));
5697 make_cleanup (xfree
, new_field
);
5699 gdb_assert (die
->tag
== DW_TAG_typedef
);
5701 fp
= &new_field
->field
;
5703 /* Get name of field. */
5704 fp
->name
= dwarf2_name (die
, cu
);
5705 if (fp
->name
== NULL
)
5708 fp
->type
= read_type_die (die
, cu
);
5710 new_field
->next
= fip
->typedef_field_list
;
5711 fip
->typedef_field_list
= new_field
;
5712 fip
->typedef_field_list_count
++;
5715 /* Create the vector of fields, and attach it to the type. */
5718 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
5719 struct dwarf2_cu
*cu
)
5721 int nfields
= fip
->nfields
;
5723 /* Record the field count, allocate space for the array of fields,
5724 and create blank accessibility bitfields if necessary. */
5725 TYPE_NFIELDS (type
) = nfields
;
5726 TYPE_FIELDS (type
) = (struct field
*)
5727 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
5728 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
5730 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
5732 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
5734 TYPE_FIELD_PRIVATE_BITS (type
) =
5735 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
5736 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
5738 TYPE_FIELD_PROTECTED_BITS (type
) =
5739 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
5740 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
5742 TYPE_FIELD_IGNORE_BITS (type
) =
5743 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
5744 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
5747 /* If the type has baseclasses, allocate and clear a bit vector for
5748 TYPE_FIELD_VIRTUAL_BITS. */
5749 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
5751 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
5752 unsigned char *pointer
;
5754 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
5755 pointer
= TYPE_ALLOC (type
, num_bytes
);
5756 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
5757 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
5758 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
5761 /* Copy the saved-up fields into the field vector. Start from the head
5762 of the list, adding to the tail of the field array, so that they end
5763 up in the same order in the array in which they were added to the list. */
5764 while (nfields
-- > 0)
5766 struct nextfield
*fieldp
;
5770 fieldp
= fip
->fields
;
5771 fip
->fields
= fieldp
->next
;
5775 fieldp
= fip
->baseclasses
;
5776 fip
->baseclasses
= fieldp
->next
;
5779 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
5780 switch (fieldp
->accessibility
)
5782 case DW_ACCESS_private
:
5783 if (cu
->language
!= language_ada
)
5784 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
5787 case DW_ACCESS_protected
:
5788 if (cu
->language
!= language_ada
)
5789 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
5792 case DW_ACCESS_public
:
5796 /* Unknown accessibility. Complain and treat it as public. */
5798 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
5799 fieldp
->accessibility
);
5803 if (nfields
< fip
->nbaseclasses
)
5805 switch (fieldp
->virtuality
)
5807 case DW_VIRTUALITY_virtual
:
5808 case DW_VIRTUALITY_pure_virtual
:
5809 if (cu
->language
== language_ada
)
5810 error ("unexpected virtuality in component of Ada type");
5811 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
5818 /* Add a member function to the proper fieldlist. */
5821 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
5822 struct type
*type
, struct dwarf2_cu
*cu
)
5824 struct objfile
*objfile
= cu
->objfile
;
5825 struct attribute
*attr
;
5826 struct fnfieldlist
*flp
;
5828 struct fn_field
*fnp
;
5831 struct nextfnfield
*new_fnfield
;
5832 struct type
*this_type
;
5834 if (cu
->language
== language_ada
)
5835 error ("unexpected member function in Ada type");
5837 /* Get name of member function. */
5838 fieldname
= dwarf2_name (die
, cu
);
5839 if (fieldname
== NULL
)
5842 /* Get the mangled name. */
5843 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
5845 /* Look up member function name in fieldlist. */
5846 for (i
= 0; i
< fip
->nfnfields
; i
++)
5848 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
5852 /* Create new list element if necessary. */
5853 if (i
< fip
->nfnfields
)
5854 flp
= &fip
->fnfieldlists
[i
];
5857 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5859 fip
->fnfieldlists
= (struct fnfieldlist
*)
5860 xrealloc (fip
->fnfieldlists
,
5861 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
5862 * sizeof (struct fnfieldlist
));
5863 if (fip
->nfnfields
== 0)
5864 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
5866 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
5867 flp
->name
= fieldname
;
5873 /* Create a new member function field and chain it to the field list
5875 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
5876 make_cleanup (xfree
, new_fnfield
);
5877 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
5878 new_fnfield
->next
= flp
->head
;
5879 flp
->head
= new_fnfield
;
5882 /* Fill in the member function field info. */
5883 fnp
= &new_fnfield
->fnfield
;
5884 /* The name is already allocated along with this objfile, so we don't
5885 need to duplicate it for the type. */
5886 fnp
->physname
= physname
? physname
: "";
5887 fnp
->type
= alloc_type (objfile
);
5888 this_type
= read_type_die (die
, cu
);
5889 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
5891 int nparams
= TYPE_NFIELDS (this_type
);
5893 /* TYPE is the domain of this method, and THIS_TYPE is the type
5894 of the method itself (TYPE_CODE_METHOD). */
5895 smash_to_method_type (fnp
->type
, type
,
5896 TYPE_TARGET_TYPE (this_type
),
5897 TYPE_FIELDS (this_type
),
5898 TYPE_NFIELDS (this_type
),
5899 TYPE_VARARGS (this_type
));
5901 /* Handle static member functions.
5902 Dwarf2 has no clean way to discern C++ static and non-static
5903 member functions. G++ helps GDB by marking the first
5904 parameter for non-static member functions (which is the
5905 this pointer) as artificial. We obtain this information
5906 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
5907 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
5908 fnp
->voffset
= VOFFSET_STATIC
;
5911 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
5914 /* Get fcontext from DW_AT_containing_type if present. */
5915 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5916 fnp
->fcontext
= die_containing_type (die
, cu
);
5918 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
5919 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
5921 /* Get accessibility. */
5922 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
5925 switch (DW_UNSND (attr
))
5927 case DW_ACCESS_private
:
5928 fnp
->is_private
= 1;
5930 case DW_ACCESS_protected
:
5931 fnp
->is_protected
= 1;
5936 /* Check for artificial methods. */
5937 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
5938 if (attr
&& DW_UNSND (attr
) != 0)
5939 fnp
->is_artificial
= 1;
5941 /* Get index in virtual function table if it is a virtual member
5942 function. For older versions of GCC, this is an offset in the
5943 appropriate virtual table, as specified by DW_AT_containing_type.
5944 For everyone else, it is an expression to be evaluated relative
5945 to the object address. */
5947 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
5950 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0)
5952 if (DW_BLOCK (attr
)->data
[0] == DW_OP_constu
)
5954 /* Old-style GCC. */
5955 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
5957 else if (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
5958 || (DW_BLOCK (attr
)->size
> 1
5959 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref_size
5960 && DW_BLOCK (attr
)->data
[1] == cu
->header
.addr_size
))
5962 struct dwarf_block blk
;
5965 offset
= (DW_BLOCK (attr
)->data
[0] == DW_OP_deref
5967 blk
.size
= DW_BLOCK (attr
)->size
- offset
;
5968 blk
.data
= DW_BLOCK (attr
)->data
+ offset
;
5969 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5970 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
5971 dwarf2_complex_location_expr_complaint ();
5973 fnp
->voffset
/= cu
->header
.addr_size
;
5977 dwarf2_complex_location_expr_complaint ();
5980 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
5982 else if (attr_form_is_section_offset (attr
))
5984 dwarf2_complex_location_expr_complaint ();
5988 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
5994 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
5995 if (attr
&& DW_UNSND (attr
))
5997 /* GCC does this, as of 2008-08-25; PR debug/37237. */
5998 complaint (&symfile_complaints
,
5999 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
6000 fieldname
, die
->offset
);
6001 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6002 TYPE_CPLUS_DYNAMIC (type
) = 1;
6007 /* Create the vector of member function fields, and attach it to the type. */
6010 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
6011 struct dwarf2_cu
*cu
)
6013 struct fnfieldlist
*flp
;
6014 int total_length
= 0;
6017 if (cu
->language
== language_ada
)
6018 error ("unexpected member functions in Ada type");
6020 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6021 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
6022 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
6024 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
6026 struct nextfnfield
*nfp
= flp
->head
;
6027 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
6030 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
6031 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
6032 fn_flp
->fn_fields
= (struct fn_field
*)
6033 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
6034 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
6035 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
6037 total_length
+= flp
->length
;
6040 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
6041 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
6044 /* Returns non-zero if NAME is the name of a vtable member in CU's
6045 language, zero otherwise. */
6047 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
6049 static const char vptr
[] = "_vptr";
6050 static const char vtable
[] = "vtable";
6052 /* Look for the C++ and Java forms of the vtable. */
6053 if ((cu
->language
== language_java
6054 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
6055 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
6056 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
6062 /* GCC outputs unnamed structures that are really pointers to member
6063 functions, with the ABI-specified layout. If TYPE describes
6064 such a structure, smash it into a member function type.
6066 GCC shouldn't do this; it should just output pointer to member DIEs.
6067 This is GCC PR debug/28767. */
6070 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
6072 struct type
*pfn_type
, *domain_type
, *new_type
;
6074 /* Check for a structure with no name and two children. */
6075 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
6078 /* Check for __pfn and __delta members. */
6079 if (TYPE_FIELD_NAME (type
, 0) == NULL
6080 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
6081 || TYPE_FIELD_NAME (type
, 1) == NULL
6082 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
6085 /* Find the type of the method. */
6086 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
6087 if (pfn_type
== NULL
6088 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
6089 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
6092 /* Look for the "this" argument. */
6093 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
6094 if (TYPE_NFIELDS (pfn_type
) == 0
6095 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
6096 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
6099 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
6100 new_type
= alloc_type (objfile
);
6101 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
6102 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
6103 TYPE_VARARGS (pfn_type
));
6104 smash_to_methodptr_type (type
, new_type
);
6107 /* Called when we find the DIE that starts a structure or union scope
6108 (definition) to process all dies that define the members of the
6111 NOTE: we need to call struct_type regardless of whether or not the
6112 DIE has an at_name attribute, since it might be an anonymous
6113 structure or union. This gets the type entered into our set of
6116 However, if the structure is incomplete (an opaque struct/union)
6117 then suppress creating a symbol table entry for it since gdb only
6118 wants to find the one with the complete definition. Note that if
6119 it is complete, we just call new_symbol, which does it's own
6120 checking about whether the struct/union is anonymous or not (and
6121 suppresses creating a symbol table entry itself). */
6123 static struct type
*
6124 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6126 struct objfile
*objfile
= cu
->objfile
;
6128 struct attribute
*attr
;
6130 struct cleanup
*back_to
;
6132 /* If the definition of this type lives in .debug_types, read that type.
6133 Don't follow DW_AT_specification though, that will take us back up
6134 the chain and we want to go down. */
6135 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6138 struct dwarf2_cu
*type_cu
= cu
;
6139 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6141 /* We could just recurse on read_structure_type, but we need to call
6142 get_die_type to ensure only one type for this DIE is created.
6143 This is important, for example, because for c++ classes we need
6144 TYPE_NAME set which is only done by new_symbol. Blech. */
6145 type
= read_type_die (type_die
, type_cu
);
6146 return set_die_type (die
, type
, cu
);
6149 back_to
= make_cleanup (null_cleanup
, 0);
6151 type
= alloc_type (objfile
);
6152 INIT_CPLUS_SPECIFIC (type
);
6154 name
= dwarf2_name (die
, cu
);
6157 if (cu
->language
== language_cplus
6158 || cu
->language
== language_java
)
6160 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
6161 if (die
->tag
== DW_TAG_structure_type
6162 || die
->tag
== DW_TAG_class_type
)
6163 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6167 /* The name is already allocated along with this objfile, so
6168 we don't need to duplicate it for the type. */
6169 TYPE_TAG_NAME (type
) = (char *) name
;
6170 if (die
->tag
== DW_TAG_class_type
)
6171 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
6175 if (die
->tag
== DW_TAG_structure_type
)
6177 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
6179 else if (die
->tag
== DW_TAG_union_type
)
6181 TYPE_CODE (type
) = TYPE_CODE_UNION
;
6185 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
6188 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
6189 TYPE_DECLARED_CLASS (type
) = 1;
6191 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6194 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6198 TYPE_LENGTH (type
) = 0;
6201 TYPE_STUB_SUPPORTED (type
) = 1;
6202 if (die_is_declaration (die
, cu
))
6203 TYPE_STUB (type
) = 1;
6204 else if (attr
== NULL
&& die
->child
== NULL
6205 && producer_is_realview (cu
->producer
))
6206 /* RealView does not output the required DW_AT_declaration
6207 on incomplete types. */
6208 TYPE_STUB (type
) = 1;
6210 /* We need to add the type field to the die immediately so we don't
6211 infinitely recurse when dealing with pointers to the structure
6212 type within the structure itself. */
6213 set_die_type (die
, type
, cu
);
6215 /* set_die_type should be already done. */
6216 set_descriptive_type (type
, die
, cu
);
6218 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
6220 struct field_info fi
;
6221 struct die_info
*child_die
;
6223 memset (&fi
, 0, sizeof (struct field_info
));
6225 child_die
= die
->child
;
6227 while (child_die
&& child_die
->tag
)
6229 if (child_die
->tag
== DW_TAG_member
6230 || child_die
->tag
== DW_TAG_variable
)
6232 /* NOTE: carlton/2002-11-05: A C++ static data member
6233 should be a DW_TAG_member that is a declaration, but
6234 all versions of G++ as of this writing (so through at
6235 least 3.2.1) incorrectly generate DW_TAG_variable
6236 tags for them instead. */
6237 dwarf2_add_field (&fi
, child_die
, cu
);
6239 else if (child_die
->tag
== DW_TAG_subprogram
)
6241 /* C++ member function. */
6242 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
6244 else if (child_die
->tag
== DW_TAG_inheritance
)
6246 /* C++ base class field. */
6247 dwarf2_add_field (&fi
, child_die
, cu
);
6249 else if (child_die
->tag
== DW_TAG_typedef
)
6250 dwarf2_add_typedef (&fi
, child_die
, cu
);
6251 child_die
= sibling_die (child_die
);
6254 /* Attach fields and member functions to the type. */
6256 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
6259 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
6261 /* Get the type which refers to the base class (possibly this
6262 class itself) which contains the vtable pointer for the current
6263 class from the DW_AT_containing_type attribute. This use of
6264 DW_AT_containing_type is a GNU extension. */
6266 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
6268 struct type
*t
= die_containing_type (die
, cu
);
6270 TYPE_VPTR_BASETYPE (type
) = t
;
6275 /* Our own class provides vtbl ptr. */
6276 for (i
= TYPE_NFIELDS (t
) - 1;
6277 i
>= TYPE_N_BASECLASSES (t
);
6280 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
6282 if (is_vtable_name (fieldname
, cu
))
6284 TYPE_VPTR_FIELDNO (type
) = i
;
6289 /* Complain if virtual function table field not found. */
6290 if (i
< TYPE_N_BASECLASSES (t
))
6291 complaint (&symfile_complaints
,
6292 _("virtual function table pointer not found when defining class '%s'"),
6293 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
6298 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
6301 else if (cu
->producer
6302 && strncmp (cu
->producer
,
6303 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
6305 /* The IBM XLC compiler does not provide direct indication
6306 of the containing type, but the vtable pointer is
6307 always named __vfp. */
6311 for (i
= TYPE_NFIELDS (type
) - 1;
6312 i
>= TYPE_N_BASECLASSES (type
);
6315 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
6317 TYPE_VPTR_FIELDNO (type
) = i
;
6318 TYPE_VPTR_BASETYPE (type
) = type
;
6325 /* Copy fi.typedef_field_list linked list elements content into the
6326 allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */
6327 if (fi
.typedef_field_list
)
6329 int i
= fi
.typedef_field_list_count
;
6331 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
6332 TYPE_TYPEDEF_FIELD_ARRAY (type
)
6333 = TYPE_ALLOC (type
, sizeof (TYPE_TYPEDEF_FIELD (type
, 0)) * i
);
6334 TYPE_TYPEDEF_FIELD_COUNT (type
) = i
;
6336 /* Reverse the list order to keep the debug info elements order. */
6339 struct typedef_field
*dest
, *src
;
6341 dest
= &TYPE_TYPEDEF_FIELD (type
, i
);
6342 src
= &fi
.typedef_field_list
->field
;
6343 fi
.typedef_field_list
= fi
.typedef_field_list
->next
;
6349 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
6351 do_cleanups (back_to
);
6356 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6358 struct die_info
*child_die
= die
->child
;
6359 struct type
*this_type
;
6361 this_type
= get_die_type (die
, cu
);
6362 if (this_type
== NULL
)
6363 this_type
= read_structure_type (die
, cu
);
6365 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
6366 snapshots) has been known to create a die giving a declaration
6367 for a class that has, as a child, a die giving a definition for a
6368 nested class. So we have to process our children even if the
6369 current die is a declaration. Normally, of course, a declaration
6370 won't have any children at all. */
6372 while (child_die
!= NULL
&& child_die
->tag
)
6374 if (child_die
->tag
== DW_TAG_member
6375 || child_die
->tag
== DW_TAG_variable
6376 || child_die
->tag
== DW_TAG_inheritance
)
6381 process_die (child_die
, cu
);
6383 child_die
= sibling_die (child_die
);
6386 /* Do not consider external references. According to the DWARF standard,
6387 these DIEs are identified by the fact that they have no byte_size
6388 attribute, and a declaration attribute. */
6389 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
6390 || !die_is_declaration (die
, cu
))
6391 new_symbol (die
, this_type
, cu
);
6394 /* Given a DW_AT_enumeration_type die, set its type. We do not
6395 complete the type's fields yet, or create any symbols. */
6397 static struct type
*
6398 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6400 struct objfile
*objfile
= cu
->objfile
;
6402 struct attribute
*attr
;
6405 /* If the definition of this type lives in .debug_types, read that type.
6406 Don't follow DW_AT_specification though, that will take us back up
6407 the chain and we want to go down. */
6408 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
6411 struct dwarf2_cu
*type_cu
= cu
;
6412 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
6414 type
= read_type_die (type_die
, type_cu
);
6415 return set_die_type (die
, type
, cu
);
6418 type
= alloc_type (objfile
);
6420 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
6421 name
= dwarf2_full_name (NULL
, die
, cu
);
6423 TYPE_TAG_NAME (type
) = (char *) name
;
6425 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6428 TYPE_LENGTH (type
) = DW_UNSND (attr
);
6432 TYPE_LENGTH (type
) = 0;
6435 /* The enumeration DIE can be incomplete. In Ada, any type can be
6436 declared as private in the package spec, and then defined only
6437 inside the package body. Such types are known as Taft Amendment
6438 Types. When another package uses such a type, an incomplete DIE
6439 may be generated by the compiler. */
6440 if (die_is_declaration (die
, cu
))
6441 TYPE_STUB (type
) = 1;
6443 return set_die_type (die
, type
, cu
);
6446 /* Given a pointer to a die which begins an enumeration, process all
6447 the dies that define the members of the enumeration, and create the
6448 symbol for the enumeration type.
6450 NOTE: We reverse the order of the element list. */
6453 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
6455 struct die_info
*child_die
;
6456 struct field
*fields
;
6459 int unsigned_enum
= 1;
6461 struct type
*this_type
;
6465 this_type
= get_die_type (die
, cu
);
6466 if (this_type
== NULL
)
6467 this_type
= read_enumeration_type (die
, cu
);
6468 if (die
->child
!= NULL
)
6470 child_die
= die
->child
;
6471 while (child_die
&& child_die
->tag
)
6473 if (child_die
->tag
!= DW_TAG_enumerator
)
6475 process_die (child_die
, cu
);
6479 name
= dwarf2_name (child_die
, cu
);
6482 sym
= new_symbol (child_die
, this_type
, cu
);
6483 if (SYMBOL_VALUE (sym
) < 0)
6486 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
6488 fields
= (struct field
*)
6490 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
6491 * sizeof (struct field
));
6494 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
6495 FIELD_TYPE (fields
[num_fields
]) = NULL
;
6496 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
6497 FIELD_BITSIZE (fields
[num_fields
]) = 0;
6503 child_die
= sibling_die (child_die
);
6508 TYPE_NFIELDS (this_type
) = num_fields
;
6509 TYPE_FIELDS (this_type
) = (struct field
*)
6510 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
6511 memcpy (TYPE_FIELDS (this_type
), fields
,
6512 sizeof (struct field
) * num_fields
);
6516 TYPE_UNSIGNED (this_type
) = 1;
6519 new_symbol (die
, this_type
, cu
);
6522 /* Extract all information from a DW_TAG_array_type DIE and put it in
6523 the DIE's type field. For now, this only handles one dimensional
6526 static struct type
*
6527 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6529 struct objfile
*objfile
= cu
->objfile
;
6530 struct die_info
*child_die
;
6532 struct type
*element_type
, *range_type
, *index_type
;
6533 struct type
**range_types
= NULL
;
6534 struct attribute
*attr
;
6536 struct cleanup
*back_to
;
6539 element_type
= die_type (die
, cu
);
6541 /* The die_type call above may have already set the type for this DIE. */
6542 type
= get_die_type (die
, cu
);
6546 /* Irix 6.2 native cc creates array types without children for
6547 arrays with unspecified length. */
6548 if (die
->child
== NULL
)
6550 index_type
= objfile_type (objfile
)->builtin_int
;
6551 range_type
= create_range_type (NULL
, index_type
, 0, -1);
6552 type
= create_array_type (NULL
, element_type
, range_type
);
6553 return set_die_type (die
, type
, cu
);
6556 back_to
= make_cleanup (null_cleanup
, NULL
);
6557 child_die
= die
->child
;
6558 while (child_die
&& child_die
->tag
)
6560 if (child_die
->tag
== DW_TAG_subrange_type
)
6562 struct type
*child_type
= read_type_die (child_die
, cu
);
6564 if (child_type
!= NULL
)
6566 /* The range type was succesfully read. Save it for
6567 the array type creation. */
6568 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
6570 range_types
= (struct type
**)
6571 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
6572 * sizeof (struct type
*));
6574 make_cleanup (free_current_contents
, &range_types
);
6576 range_types
[ndim
++] = child_type
;
6579 child_die
= sibling_die (child_die
);
6582 /* Dwarf2 dimensions are output from left to right, create the
6583 necessary array types in backwards order. */
6585 type
= element_type
;
6587 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
6592 type
= create_array_type (NULL
, type
, range_types
[i
++]);
6597 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
6600 /* Understand Dwarf2 support for vector types (like they occur on
6601 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
6602 array type. This is not part of the Dwarf2/3 standard yet, but a
6603 custom vendor extension. The main difference between a regular
6604 array and the vector variant is that vectors are passed by value
6606 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
6608 make_vector_type (type
);
6610 name
= dwarf2_name (die
, cu
);
6612 TYPE_NAME (type
) = name
;
6614 /* Install the type in the die. */
6615 set_die_type (die
, type
, cu
);
6617 /* set_die_type should be already done. */
6618 set_descriptive_type (type
, die
, cu
);
6620 do_cleanups (back_to
);
6625 static enum dwarf_array_dim_ordering
6626 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
6628 struct attribute
*attr
;
6630 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
6632 if (attr
) return DW_SND (attr
);
6635 GNU F77 is a special case, as at 08/2004 array type info is the
6636 opposite order to the dwarf2 specification, but data is still
6637 laid out as per normal fortran.
6639 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
6643 if (cu
->language
== language_fortran
6644 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
6646 return DW_ORD_row_major
;
6649 switch (cu
->language_defn
->la_array_ordering
)
6651 case array_column_major
:
6652 return DW_ORD_col_major
;
6653 case array_row_major
:
6655 return DW_ORD_row_major
;
6659 /* Extract all information from a DW_TAG_set_type DIE and put it in
6660 the DIE's type field. */
6662 static struct type
*
6663 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6665 struct type
*domain_type
, *set_type
;
6666 struct attribute
*attr
;
6668 domain_type
= die_type (die
, cu
);
6670 /* The die_type call above may have already set the type for this DIE. */
6671 set_type
= get_die_type (die
, cu
);
6675 set_type
= create_set_type (NULL
, domain_type
);
6677 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6679 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
6681 return set_die_type (die
, set_type
, cu
);
6684 /* First cut: install each common block member as a global variable. */
6687 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
6689 struct die_info
*child_die
;
6690 struct attribute
*attr
;
6692 CORE_ADDR base
= (CORE_ADDR
) 0;
6694 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6697 /* Support the .debug_loc offsets */
6698 if (attr_form_is_block (attr
))
6700 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
6702 else if (attr_form_is_section_offset (attr
))
6704 dwarf2_complex_location_expr_complaint ();
6708 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6709 "common block member");
6712 if (die
->child
!= NULL
)
6714 child_die
= die
->child
;
6715 while (child_die
&& child_die
->tag
)
6717 sym
= new_symbol (child_die
, NULL
, cu
);
6718 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
6721 CORE_ADDR byte_offset
= 0;
6723 if (attr_form_is_section_offset (attr
))
6724 dwarf2_complex_location_expr_complaint ();
6725 else if (attr_form_is_constant (attr
))
6726 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
6727 else if (attr_form_is_block (attr
))
6728 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
6730 dwarf2_complex_location_expr_complaint ();
6732 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
6733 add_symbol_to_list (sym
, &global_symbols
);
6735 child_die
= sibling_die (child_die
);
6740 /* Create a type for a C++ namespace. */
6742 static struct type
*
6743 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6745 struct objfile
*objfile
= cu
->objfile
;
6746 const char *previous_prefix
, *name
;
6750 /* For extensions, reuse the type of the original namespace. */
6751 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
6753 struct die_info
*ext_die
;
6754 struct dwarf2_cu
*ext_cu
= cu
;
6756 ext_die
= dwarf2_extension (die
, &ext_cu
);
6757 type
= read_type_die (ext_die
, ext_cu
);
6758 return set_die_type (die
, type
, cu
);
6761 name
= namespace_name (die
, &is_anonymous
, cu
);
6763 /* Now build the name of the current namespace. */
6765 previous_prefix
= determine_prefix (die
, cu
);
6766 if (previous_prefix
[0] != '\0')
6767 name
= typename_concat (&objfile
->objfile_obstack
,
6768 previous_prefix
, name
, 0, cu
);
6770 /* Create the type. */
6771 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
6773 TYPE_NAME (type
) = (char *) name
;
6774 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6776 return set_die_type (die
, type
, cu
);
6779 /* Read a C++ namespace. */
6782 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
6784 struct objfile
*objfile
= cu
->objfile
;
6788 /* Add a symbol associated to this if we haven't seen the namespace
6789 before. Also, add a using directive if it's an anonymous
6792 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
6796 type
= read_type_die (die
, cu
);
6797 new_symbol (die
, type
, cu
);
6799 name
= namespace_name (die
, &is_anonymous
, cu
);
6802 const char *previous_prefix
= determine_prefix (die
, cu
);
6804 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
6805 NULL
, &objfile
->objfile_obstack
);
6809 if (die
->child
!= NULL
)
6811 struct die_info
*child_die
= die
->child
;
6813 while (child_die
&& child_die
->tag
)
6815 process_die (child_die
, cu
);
6816 child_die
= sibling_die (child_die
);
6821 /* Read a Fortran module as type. This DIE can be only a declaration used for
6822 imported module. Still we need that type as local Fortran "use ... only"
6823 declaration imports depend on the created type in determine_prefix. */
6825 static struct type
*
6826 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6828 struct objfile
*objfile
= cu
->objfile
;
6832 module_name
= dwarf2_name (die
, cu
);
6834 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
6836 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
6838 /* determine_prefix uses TYPE_TAG_NAME. */
6839 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
6841 return set_die_type (die
, type
, cu
);
6844 /* Read a Fortran module. */
6847 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
6849 struct die_info
*child_die
= die
->child
;
6851 while (child_die
&& child_die
->tag
)
6853 process_die (child_die
, cu
);
6854 child_die
= sibling_die (child_die
);
6858 /* Return the name of the namespace represented by DIE. Set
6859 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
6863 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
6865 struct die_info
*current_die
;
6866 const char *name
= NULL
;
6868 /* Loop through the extensions until we find a name. */
6870 for (current_die
= die
;
6871 current_die
!= NULL
;
6872 current_die
= dwarf2_extension (die
, &cu
))
6874 name
= dwarf2_name (current_die
, cu
);
6879 /* Is it an anonymous namespace? */
6881 *is_anonymous
= (name
== NULL
);
6883 name
= "(anonymous namespace)";
6888 /* Extract all information from a DW_TAG_pointer_type DIE and add to
6889 the user defined type vector. */
6891 static struct type
*
6892 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6894 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6895 struct comp_unit_head
*cu_header
= &cu
->header
;
6897 struct attribute
*attr_byte_size
;
6898 struct attribute
*attr_address_class
;
6899 int byte_size
, addr_class
;
6900 struct type
*target_type
;
6902 target_type
= die_type (die
, cu
);
6904 /* The die_type call above may have already set the type for this DIE. */
6905 type
= get_die_type (die
, cu
);
6909 type
= lookup_pointer_type (target_type
);
6911 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6913 byte_size
= DW_UNSND (attr_byte_size
);
6915 byte_size
= cu_header
->addr_size
;
6917 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
6918 if (attr_address_class
)
6919 addr_class
= DW_UNSND (attr_address_class
);
6921 addr_class
= DW_ADDR_none
;
6923 /* If the pointer size or address class is different than the
6924 default, create a type variant marked as such and set the
6925 length accordingly. */
6926 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
6928 if (gdbarch_address_class_type_flags_p (gdbarch
))
6932 type_flags
= gdbarch_address_class_type_flags
6933 (gdbarch
, byte_size
, addr_class
);
6934 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
6936 type
= make_type_with_address_space (type
, type_flags
);
6938 else if (TYPE_LENGTH (type
) != byte_size
)
6940 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
6944 /* Should we also complain about unhandled address classes? */
6948 TYPE_LENGTH (type
) = byte_size
;
6949 return set_die_type (die
, type
, cu
);
6952 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
6953 the user defined type vector. */
6955 static struct type
*
6956 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6959 struct type
*to_type
;
6960 struct type
*domain
;
6962 to_type
= die_type (die
, cu
);
6963 domain
= die_containing_type (die
, cu
);
6965 /* The calls above may have already set the type for this DIE. */
6966 type
= get_die_type (die
, cu
);
6970 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
6971 type
= lookup_methodptr_type (to_type
);
6973 type
= lookup_memberptr_type (to_type
, domain
);
6975 return set_die_type (die
, type
, cu
);
6978 /* Extract all information from a DW_TAG_reference_type DIE and add to
6979 the user defined type vector. */
6981 static struct type
*
6982 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6984 struct comp_unit_head
*cu_header
= &cu
->header
;
6985 struct type
*type
, *target_type
;
6986 struct attribute
*attr
;
6988 target_type
= die_type (die
, cu
);
6990 /* The die_type call above may have already set the type for this DIE. */
6991 type
= get_die_type (die
, cu
);
6995 type
= lookup_reference_type (target_type
);
6996 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6999 TYPE_LENGTH (type
) = DW_UNSND (attr
);
7003 TYPE_LENGTH (type
) = cu_header
->addr_size
;
7005 return set_die_type (die
, type
, cu
);
7008 static struct type
*
7009 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7011 struct type
*base_type
, *cv_type
;
7013 base_type
= die_type (die
, cu
);
7015 /* The die_type call above may have already set the type for this DIE. */
7016 cv_type
= get_die_type (die
, cu
);
7020 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
7021 return set_die_type (die
, cv_type
, cu
);
7024 static struct type
*
7025 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7027 struct type
*base_type
, *cv_type
;
7029 base_type
= die_type (die
, cu
);
7031 /* The die_type call above may have already set the type for this DIE. */
7032 cv_type
= get_die_type (die
, cu
);
7036 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
7037 return set_die_type (die
, cv_type
, cu
);
7040 /* Extract all information from a DW_TAG_string_type DIE and add to
7041 the user defined type vector. It isn't really a user defined type,
7042 but it behaves like one, with other DIE's using an AT_user_def_type
7043 attribute to reference it. */
7045 static struct type
*
7046 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7048 struct objfile
*objfile
= cu
->objfile
;
7049 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7050 struct type
*type
, *range_type
, *index_type
, *char_type
;
7051 struct attribute
*attr
;
7052 unsigned int length
;
7054 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
7057 length
= DW_UNSND (attr
);
7061 /* check for the DW_AT_byte_size attribute */
7062 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7065 length
= DW_UNSND (attr
);
7073 index_type
= objfile_type (objfile
)->builtin_int
;
7074 range_type
= create_range_type (NULL
, index_type
, 1, length
);
7075 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
7076 type
= create_string_type (NULL
, char_type
, range_type
);
7078 return set_die_type (die
, type
, cu
);
7081 /* Handle DIES due to C code like:
7085 int (*funcp)(int a, long l);
7089 ('funcp' generates a DW_TAG_subroutine_type DIE)
7092 static struct type
*
7093 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7095 struct type
*type
; /* Type that this function returns */
7096 struct type
*ftype
; /* Function that returns above type */
7097 struct attribute
*attr
;
7099 type
= die_type (die
, cu
);
7101 /* The die_type call above may have already set the type for this DIE. */
7102 ftype
= get_die_type (die
, cu
);
7106 ftype
= lookup_function_type (type
);
7108 /* All functions in C++, Pascal and Java have prototypes. */
7109 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
7110 if ((attr
&& (DW_UNSND (attr
) != 0))
7111 || cu
->language
== language_cplus
7112 || cu
->language
== language_java
7113 || cu
->language
== language_pascal
)
7114 TYPE_PROTOTYPED (ftype
) = 1;
7115 else if (producer_is_realview (cu
->producer
))
7116 /* RealView does not emit DW_AT_prototyped. We can not
7117 distinguish prototyped and unprototyped functions; default to
7118 prototyped, since that is more common in modern code (and
7119 RealView warns about unprototyped functions). */
7120 TYPE_PROTOTYPED (ftype
) = 1;
7122 /* Store the calling convention in the type if it's available in
7123 the subroutine die. Otherwise set the calling convention to
7124 the default value DW_CC_normal. */
7125 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
7126 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
7128 /* We need to add the subroutine type to the die immediately so
7129 we don't infinitely recurse when dealing with parameters
7130 declared as the same subroutine type. */
7131 set_die_type (die
, ftype
, cu
);
7133 if (die
->child
!= NULL
)
7135 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
7136 struct die_info
*child_die
;
7137 int nparams
, iparams
;
7139 /* Count the number of parameters.
7140 FIXME: GDB currently ignores vararg functions, but knows about
7141 vararg member functions. */
7143 child_die
= die
->child
;
7144 while (child_die
&& child_die
->tag
)
7146 if (child_die
->tag
== DW_TAG_formal_parameter
)
7148 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
7149 TYPE_VARARGS (ftype
) = 1;
7150 child_die
= sibling_die (child_die
);
7153 /* Allocate storage for parameters and fill them in. */
7154 TYPE_NFIELDS (ftype
) = nparams
;
7155 TYPE_FIELDS (ftype
) = (struct field
*)
7156 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
7158 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
7159 even if we error out during the parameters reading below. */
7160 for (iparams
= 0; iparams
< nparams
; iparams
++)
7161 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
7164 child_die
= die
->child
;
7165 while (child_die
&& child_die
->tag
)
7167 if (child_die
->tag
== DW_TAG_formal_parameter
)
7169 /* Dwarf2 has no clean way to discern C++ static and non-static
7170 member functions. G++ helps GDB by marking the first
7171 parameter for non-static member functions (which is the
7172 this pointer) as artificial. We pass this information
7173 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
7174 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
7176 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
7179 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
7181 /* GCC/43521: In java, the formal parameter
7182 "this" is sometimes not marked with DW_AT_artificial. */
7183 if (cu
->language
== language_java
)
7185 const char *name
= dwarf2_name (child_die
, cu
);
7187 if (name
&& !strcmp (name
, "this"))
7188 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
7191 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
7194 child_die
= sibling_die (child_die
);
7201 static struct type
*
7202 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
7204 struct objfile
*objfile
= cu
->objfile
;
7205 const char *name
= NULL
;
7206 struct type
*this_type
;
7208 name
= dwarf2_full_name (NULL
, die
, cu
);
7209 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
7210 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
7211 TYPE_NAME (this_type
) = (char *) name
;
7212 set_die_type (die
, this_type
, cu
);
7213 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
7217 /* Find a representation of a given base type and install
7218 it in the TYPE field of the die. */
7220 static struct type
*
7221 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7223 struct objfile
*objfile
= cu
->objfile
;
7225 struct attribute
*attr
;
7226 int encoding
= 0, size
= 0;
7228 enum type_code code
= TYPE_CODE_INT
;
7230 struct type
*target_type
= NULL
;
7232 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
7235 encoding
= DW_UNSND (attr
);
7237 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7240 size
= DW_UNSND (attr
);
7242 name
= dwarf2_name (die
, cu
);
7245 complaint (&symfile_complaints
,
7246 _("DW_AT_name missing from DW_TAG_base_type"));
7251 case DW_ATE_address
:
7252 /* Turn DW_ATE_address into a void * pointer. */
7253 code
= TYPE_CODE_PTR
;
7254 type_flags
|= TYPE_FLAG_UNSIGNED
;
7255 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
7257 case DW_ATE_boolean
:
7258 code
= TYPE_CODE_BOOL
;
7259 type_flags
|= TYPE_FLAG_UNSIGNED
;
7261 case DW_ATE_complex_float
:
7262 code
= TYPE_CODE_COMPLEX
;
7263 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
7265 case DW_ATE_decimal_float
:
7266 code
= TYPE_CODE_DECFLOAT
;
7269 code
= TYPE_CODE_FLT
;
7273 case DW_ATE_unsigned
:
7274 type_flags
|= TYPE_FLAG_UNSIGNED
;
7276 case DW_ATE_signed_char
:
7277 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7278 || cu
->language
== language_pascal
)
7279 code
= TYPE_CODE_CHAR
;
7281 case DW_ATE_unsigned_char
:
7282 if (cu
->language
== language_ada
|| cu
->language
== language_m2
7283 || cu
->language
== language_pascal
)
7284 code
= TYPE_CODE_CHAR
;
7285 type_flags
|= TYPE_FLAG_UNSIGNED
;
7288 /* We just treat this as an integer and then recognize the
7289 type by name elsewhere. */
7293 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
7294 dwarf_type_encoding_name (encoding
));
7298 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
7299 TYPE_NAME (type
) = name
;
7300 TYPE_TARGET_TYPE (type
) = target_type
;
7302 if (name
&& strcmp (name
, "char") == 0)
7303 TYPE_NOSIGN (type
) = 1;
7305 return set_die_type (die
, type
, cu
);
7308 /* Read the given DW_AT_subrange DIE. */
7310 static struct type
*
7311 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7313 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
7314 struct type
*base_type
;
7315 struct type
*range_type
;
7316 struct attribute
*attr
;
7320 LONGEST negative_mask
;
7322 base_type
= die_type (die
, cu
);
7323 /* Preserve BASE_TYPE's original type, just set its LENGTH. */
7324 check_typedef (base_type
);
7326 /* The die_type call above may have already set the type for this DIE. */
7327 range_type
= get_die_type (die
, cu
);
7331 if (cu
->language
== language_fortran
)
7333 /* FORTRAN implies a lower bound of 1, if not given. */
7337 /* FIXME: For variable sized arrays either of these could be
7338 a variable rather than a constant value. We'll allow it,
7339 but we don't know how to handle it. */
7340 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
7342 low
= dwarf2_get_attr_constant_value (attr
, 0);
7344 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
7347 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
7349 /* GCC encodes arrays with unspecified or dynamic length
7350 with a DW_FORM_block1 attribute or a reference attribute.
7351 FIXME: GDB does not yet know how to handle dynamic
7352 arrays properly, treat them as arrays with unspecified
7355 FIXME: jimb/2003-09-22: GDB does not really know
7356 how to handle arrays of unspecified length
7357 either; we just represent them as zero-length
7358 arrays. Choose an appropriate upper bound given
7359 the lower bound we've computed above. */
7363 high
= dwarf2_get_attr_constant_value (attr
, 1);
7367 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
7370 int count
= dwarf2_get_attr_constant_value (attr
, 1);
7371 high
= low
+ count
- 1;
7375 /* Dwarf-2 specifications explicitly allows to create subrange types
7376 without specifying a base type.
7377 In that case, the base type must be set to the type of
7378 the lower bound, upper bound or count, in that order, if any of these
7379 three attributes references an object that has a type.
7380 If no base type is found, the Dwarf-2 specifications say that
7381 a signed integer type of size equal to the size of an address should
7383 For the following C code: `extern char gdb_int [];'
7384 GCC produces an empty range DIE.
7385 FIXME: muller/2010-05-28: Possible references to object for low bound,
7386 high bound or count are not yet handled by this code.
7388 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
7390 struct objfile
*objfile
= cu
->objfile
;
7391 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7392 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
7393 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
7395 /* Test "int", "long int", and "long long int" objfile types,
7396 and select the first one having a size above or equal to the
7397 architecture address size. */
7398 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7399 base_type
= int_type
;
7402 int_type
= objfile_type (objfile
)->builtin_long
;
7403 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7404 base_type
= int_type
;
7407 int_type
= objfile_type (objfile
)->builtin_long_long
;
7408 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
7409 base_type
= int_type
;
7415 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
7416 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
7417 low
|= negative_mask
;
7418 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
7419 high
|= negative_mask
;
7421 range_type
= create_range_type (NULL
, base_type
, low
, high
);
7423 /* Mark arrays with dynamic length at least as an array of unspecified
7424 length. GDB could check the boundary but before it gets implemented at
7425 least allow accessing the array elements. */
7426 if (attr
&& attr
->form
== DW_FORM_block1
)
7427 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
7429 name
= dwarf2_name (die
, cu
);
7431 TYPE_NAME (range_type
) = name
;
7433 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
7435 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
7437 set_die_type (die
, range_type
, cu
);
7439 /* set_die_type should be already done. */
7440 set_descriptive_type (range_type
, die
, cu
);
7445 static struct type
*
7446 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7450 /* For now, we only support the C meaning of an unspecified type: void. */
7452 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
7453 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
7455 return set_die_type (die
, type
, cu
);
7458 /* Trivial hash function for die_info: the hash value of a DIE
7459 is its offset in .debug_info for this objfile. */
7462 die_hash (const void *item
)
7464 const struct die_info
*die
= item
;
7469 /* Trivial comparison function for die_info structures: two DIEs
7470 are equal if they have the same offset. */
7473 die_eq (const void *item_lhs
, const void *item_rhs
)
7475 const struct die_info
*die_lhs
= item_lhs
;
7476 const struct die_info
*die_rhs
= item_rhs
;
7478 return die_lhs
->offset
== die_rhs
->offset
;
7481 /* Read a whole compilation unit into a linked list of dies. */
7483 static struct die_info
*
7484 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7486 struct die_reader_specs reader_specs
;
7488 gdb_assert (cu
->die_hash
== NULL
);
7490 = htab_create_alloc_ex (cu
->header
.length
/ 12,
7494 &cu
->comp_unit_obstack
,
7495 hashtab_obstack_allocate
,
7496 dummy_obstack_deallocate
);
7498 init_cu_die_reader (&reader_specs
, cu
);
7500 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
7503 /* Main entry point for reading a DIE and all children.
7504 Read the DIE and dump it if requested. */
7506 static struct die_info
*
7507 read_die_and_children (const struct die_reader_specs
*reader
,
7509 gdb_byte
**new_info_ptr
,
7510 struct die_info
*parent
)
7512 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
7513 new_info_ptr
, parent
);
7515 if (dwarf2_die_debug
)
7517 fprintf_unfiltered (gdb_stdlog
,
7518 "\nRead die from %s of %s:\n",
7519 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
7521 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
7523 : "unknown section",
7524 reader
->abfd
->filename
);
7525 dump_die (result
, dwarf2_die_debug
);
7531 /* Read a single die and all its descendents. Set the die's sibling
7532 field to NULL; set other fields in the die correctly, and set all
7533 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
7534 location of the info_ptr after reading all of those dies. PARENT
7535 is the parent of the die in question. */
7537 static struct die_info
*
7538 read_die_and_children_1 (const struct die_reader_specs
*reader
,
7540 gdb_byte
**new_info_ptr
,
7541 struct die_info
*parent
)
7543 struct die_info
*die
;
7547 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
7550 *new_info_ptr
= cur_ptr
;
7553 store_in_ref_table (die
, reader
->cu
);
7556 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
7560 *new_info_ptr
= cur_ptr
;
7563 die
->sibling
= NULL
;
7564 die
->parent
= parent
;
7568 /* Read a die, all of its descendents, and all of its siblings; set
7569 all of the fields of all of the dies correctly. Arguments are as
7570 in read_die_and_children. */
7572 static struct die_info
*
7573 read_die_and_siblings (const struct die_reader_specs
*reader
,
7575 gdb_byte
**new_info_ptr
,
7576 struct die_info
*parent
)
7578 struct die_info
*first_die
, *last_sibling
;
7582 first_die
= last_sibling
= NULL
;
7586 struct die_info
*die
7587 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
7591 *new_info_ptr
= cur_ptr
;
7598 last_sibling
->sibling
= die
;
7604 /* Read the die from the .debug_info section buffer. Set DIEP to
7605 point to a newly allocated die with its information, except for its
7606 child, sibling, and parent fields. Set HAS_CHILDREN to tell
7607 whether the die has children or not. */
7610 read_full_die (const struct die_reader_specs
*reader
,
7611 struct die_info
**diep
, gdb_byte
*info_ptr
,
7614 unsigned int abbrev_number
, bytes_read
, i
, offset
;
7615 struct abbrev_info
*abbrev
;
7616 struct die_info
*die
;
7617 struct dwarf2_cu
*cu
= reader
->cu
;
7618 bfd
*abfd
= reader
->abfd
;
7620 offset
= info_ptr
- reader
->buffer
;
7621 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7622 info_ptr
+= bytes_read
;
7630 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
7632 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
7634 bfd_get_filename (abfd
));
7636 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
7637 die
->offset
= offset
;
7638 die
->tag
= abbrev
->tag
;
7639 die
->abbrev
= abbrev_number
;
7641 die
->num_attrs
= abbrev
->num_attrs
;
7643 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
7644 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
7645 abfd
, info_ptr
, cu
);
7648 *has_children
= abbrev
->has_children
;
7652 /* In DWARF version 2, the description of the debugging information is
7653 stored in a separate .debug_abbrev section. Before we read any
7654 dies from a section we read in all abbreviations and install them
7655 in a hash table. This function also sets flags in CU describing
7656 the data found in the abbrev table. */
7659 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
7661 struct comp_unit_head
*cu_header
= &cu
->header
;
7662 gdb_byte
*abbrev_ptr
;
7663 struct abbrev_info
*cur_abbrev
;
7664 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
7665 unsigned int abbrev_form
, hash_number
;
7666 struct attr_abbrev
*cur_attrs
;
7667 unsigned int allocated_attrs
;
7669 /* Initialize dwarf2 abbrevs */
7670 obstack_init (&cu
->abbrev_obstack
);
7671 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
7673 * sizeof (struct abbrev_info
*)));
7674 memset (cu
->dwarf2_abbrevs
, 0,
7675 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
7677 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
7678 &dwarf2_per_objfile
->abbrev
);
7679 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
7680 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7681 abbrev_ptr
+= bytes_read
;
7683 allocated_attrs
= ATTR_ALLOC_CHUNK
;
7684 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
7686 /* loop until we reach an abbrev number of 0 */
7687 while (abbrev_number
)
7689 cur_abbrev
= dwarf_alloc_abbrev (cu
);
7691 /* read in abbrev header */
7692 cur_abbrev
->number
= abbrev_number
;
7693 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7694 abbrev_ptr
+= bytes_read
;
7695 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
7698 if (cur_abbrev
->tag
== DW_TAG_namespace
)
7699 cu
->has_namespace_info
= 1;
7701 /* now read in declarations */
7702 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7703 abbrev_ptr
+= bytes_read
;
7704 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7705 abbrev_ptr
+= bytes_read
;
7708 if (cur_abbrev
->num_attrs
== allocated_attrs
)
7710 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
7712 = xrealloc (cur_attrs
, (allocated_attrs
7713 * sizeof (struct attr_abbrev
)));
7716 /* Record whether this compilation unit might have
7717 inter-compilation-unit references. If we don't know what form
7718 this attribute will have, then it might potentially be a
7719 DW_FORM_ref_addr, so we conservatively expect inter-CU
7722 if (abbrev_form
== DW_FORM_ref_addr
7723 || abbrev_form
== DW_FORM_indirect
)
7724 cu
->has_form_ref_addr
= 1;
7726 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
7727 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
7728 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7729 abbrev_ptr
+= bytes_read
;
7730 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7731 abbrev_ptr
+= bytes_read
;
7734 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
7735 (cur_abbrev
->num_attrs
7736 * sizeof (struct attr_abbrev
)));
7737 memcpy (cur_abbrev
->attrs
, cur_attrs
,
7738 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
7740 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
7741 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
7742 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
7744 /* Get next abbreviation.
7745 Under Irix6 the abbreviations for a compilation unit are not
7746 always properly terminated with an abbrev number of 0.
7747 Exit loop if we encounter an abbreviation which we have
7748 already read (which means we are about to read the abbreviations
7749 for the next compile unit) or if the end of the abbreviation
7750 table is reached. */
7751 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
7752 >= dwarf2_per_objfile
->abbrev
.size
)
7754 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
7755 abbrev_ptr
+= bytes_read
;
7756 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
7763 /* Release the memory used by the abbrev table for a compilation unit. */
7766 dwarf2_free_abbrev_table (void *ptr_to_cu
)
7768 struct dwarf2_cu
*cu
= ptr_to_cu
;
7770 obstack_free (&cu
->abbrev_obstack
, NULL
);
7771 cu
->dwarf2_abbrevs
= NULL
;
7774 /* Lookup an abbrev_info structure in the abbrev hash table. */
7776 static struct abbrev_info
*
7777 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
7779 unsigned int hash_number
;
7780 struct abbrev_info
*abbrev
;
7782 hash_number
= number
% ABBREV_HASH_SIZE
;
7783 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
7787 if (abbrev
->number
== number
)
7790 abbrev
= abbrev
->next
;
7795 /* Returns nonzero if TAG represents a type that we might generate a partial
7799 is_type_tag_for_partial (int tag
)
7804 /* Some types that would be reasonable to generate partial symbols for,
7805 that we don't at present. */
7806 case DW_TAG_array_type
:
7807 case DW_TAG_file_type
:
7808 case DW_TAG_ptr_to_member_type
:
7809 case DW_TAG_set_type
:
7810 case DW_TAG_string_type
:
7811 case DW_TAG_subroutine_type
:
7813 case DW_TAG_base_type
:
7814 case DW_TAG_class_type
:
7815 case DW_TAG_interface_type
:
7816 case DW_TAG_enumeration_type
:
7817 case DW_TAG_structure_type
:
7818 case DW_TAG_subrange_type
:
7819 case DW_TAG_typedef
:
7820 case DW_TAG_union_type
:
7827 /* Load all DIEs that are interesting for partial symbols into memory. */
7829 static struct partial_die_info
*
7830 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
7831 int building_psymtab
, struct dwarf2_cu
*cu
)
7833 struct partial_die_info
*part_die
;
7834 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
7835 struct abbrev_info
*abbrev
;
7836 unsigned int bytes_read
;
7837 unsigned int load_all
= 0;
7839 int nesting_level
= 1;
7844 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
7848 = htab_create_alloc_ex (cu
->header
.length
/ 12,
7852 &cu
->comp_unit_obstack
,
7853 hashtab_obstack_allocate
,
7854 dummy_obstack_deallocate
);
7856 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
7857 sizeof (struct partial_die_info
));
7861 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
7863 /* A NULL abbrev means the end of a series of children. */
7866 if (--nesting_level
== 0)
7868 /* PART_DIE was probably the last thing allocated on the
7869 comp_unit_obstack, so we could call obstack_free
7870 here. We don't do that because the waste is small,
7871 and will be cleaned up when we're done with this
7872 compilation unit. This way, we're also more robust
7873 against other users of the comp_unit_obstack. */
7876 info_ptr
+= bytes_read
;
7877 last_die
= parent_die
;
7878 parent_die
= parent_die
->die_parent
;
7882 /* Check whether this DIE is interesting enough to save. Normally
7883 we would not be interested in members here, but there may be
7884 later variables referencing them via DW_AT_specification (for
7887 && !is_type_tag_for_partial (abbrev
->tag
)
7888 && abbrev
->tag
!= DW_TAG_enumerator
7889 && abbrev
->tag
!= DW_TAG_subprogram
7890 && abbrev
->tag
!= DW_TAG_lexical_block
7891 && abbrev
->tag
!= DW_TAG_variable
7892 && abbrev
->tag
!= DW_TAG_namespace
7893 && abbrev
->tag
!= DW_TAG_module
7894 && abbrev
->tag
!= DW_TAG_member
)
7896 /* Otherwise we skip to the next sibling, if any. */
7897 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
7901 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
7902 buffer
, info_ptr
, cu
);
7904 /* This two-pass algorithm for processing partial symbols has a
7905 high cost in cache pressure. Thus, handle some simple cases
7906 here which cover the majority of C partial symbols. DIEs
7907 which neither have specification tags in them, nor could have
7908 specification tags elsewhere pointing at them, can simply be
7909 processed and discarded.
7911 This segment is also optional; scan_partial_symbols and
7912 add_partial_symbol will handle these DIEs if we chain
7913 them in normally. When compilers which do not emit large
7914 quantities of duplicate debug information are more common,
7915 this code can probably be removed. */
7917 /* Any complete simple types at the top level (pretty much all
7918 of them, for a language without namespaces), can be processed
7920 if (parent_die
== NULL
7921 && part_die
->has_specification
== 0
7922 && part_die
->is_declaration
== 0
7923 && (part_die
->tag
== DW_TAG_typedef
7924 || part_die
->tag
== DW_TAG_base_type
7925 || part_die
->tag
== DW_TAG_subrange_type
))
7927 if (building_psymtab
&& part_die
->name
!= NULL
)
7928 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
7929 VAR_DOMAIN
, LOC_TYPEDEF
,
7930 &cu
->objfile
->static_psymbols
,
7931 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
7932 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
7936 /* If we're at the second level, and we're an enumerator, and
7937 our parent has no specification (meaning possibly lives in a
7938 namespace elsewhere), then we can add the partial symbol now
7939 instead of queueing it. */
7940 if (part_die
->tag
== DW_TAG_enumerator
7941 && parent_die
!= NULL
7942 && parent_die
->die_parent
== NULL
7943 && parent_die
->tag
== DW_TAG_enumeration_type
7944 && parent_die
->has_specification
== 0)
7946 if (part_die
->name
== NULL
)
7947 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
7948 else if (building_psymtab
)
7949 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
7950 VAR_DOMAIN
, LOC_CONST
,
7951 (cu
->language
== language_cplus
7952 || cu
->language
== language_java
)
7953 ? &cu
->objfile
->global_psymbols
7954 : &cu
->objfile
->static_psymbols
,
7955 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
7957 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
7961 /* We'll save this DIE so link it in. */
7962 part_die
->die_parent
= parent_die
;
7963 part_die
->die_sibling
= NULL
;
7964 part_die
->die_child
= NULL
;
7966 if (last_die
&& last_die
== parent_die
)
7967 last_die
->die_child
= part_die
;
7969 last_die
->die_sibling
= part_die
;
7971 last_die
= part_die
;
7973 if (first_die
== NULL
)
7974 first_die
= part_die
;
7976 /* Maybe add the DIE to the hash table. Not all DIEs that we
7977 find interesting need to be in the hash table, because we
7978 also have the parent/sibling/child chains; only those that we
7979 might refer to by offset later during partial symbol reading.
7981 For now this means things that might have be the target of a
7982 DW_AT_specification, DW_AT_abstract_origin, or
7983 DW_AT_extension. DW_AT_extension will refer only to
7984 namespaces; DW_AT_abstract_origin refers to functions (and
7985 many things under the function DIE, but we do not recurse
7986 into function DIEs during partial symbol reading) and
7987 possibly variables as well; DW_AT_specification refers to
7988 declarations. Declarations ought to have the DW_AT_declaration
7989 flag. It happens that GCC forgets to put it in sometimes, but
7990 only for functions, not for types.
7992 Adding more things than necessary to the hash table is harmless
7993 except for the performance cost. Adding too few will result in
7994 wasted time in find_partial_die, when we reread the compilation
7995 unit with load_all_dies set. */
7998 || abbrev
->tag
== DW_TAG_subprogram
7999 || abbrev
->tag
== DW_TAG_variable
8000 || abbrev
->tag
== DW_TAG_namespace
8001 || part_die
->is_declaration
)
8005 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
8006 part_die
->offset
, INSERT
);
8010 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
8011 sizeof (struct partial_die_info
));
8013 /* For some DIEs we want to follow their children (if any). For C
8014 we have no reason to follow the children of structures; for other
8015 languages we have to, both so that we can get at method physnames
8016 to infer fully qualified class names, and for DW_AT_specification.
8018 For Ada, we need to scan the children of subprograms and lexical
8019 blocks as well because Ada allows the definition of nested
8020 entities that could be interesting for the debugger, such as
8021 nested subprograms for instance. */
8022 if (last_die
->has_children
8024 || last_die
->tag
== DW_TAG_namespace
8025 || last_die
->tag
== DW_TAG_module
8026 || last_die
->tag
== DW_TAG_enumeration_type
8027 || (cu
->language
!= language_c
8028 && (last_die
->tag
== DW_TAG_class_type
8029 || last_die
->tag
== DW_TAG_interface_type
8030 || last_die
->tag
== DW_TAG_structure_type
8031 || last_die
->tag
== DW_TAG_union_type
))
8032 || (cu
->language
== language_ada
8033 && (last_die
->tag
== DW_TAG_subprogram
8034 || last_die
->tag
== DW_TAG_lexical_block
))))
8037 parent_die
= last_die
;
8041 /* Otherwise we skip to the next sibling, if any. */
8042 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
8044 /* Back to the top, do it again. */
8048 /* Read a minimal amount of information into the minimal die structure. */
8051 read_partial_die (struct partial_die_info
*part_die
,
8052 struct abbrev_info
*abbrev
,
8053 unsigned int abbrev_len
, bfd
*abfd
,
8054 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
8055 struct dwarf2_cu
*cu
)
8058 struct attribute attr
;
8059 int has_low_pc_attr
= 0;
8060 int has_high_pc_attr
= 0;
8062 memset (part_die
, 0, sizeof (struct partial_die_info
));
8064 part_die
->offset
= info_ptr
- buffer
;
8066 info_ptr
+= abbrev_len
;
8071 part_die
->tag
= abbrev
->tag
;
8072 part_die
->has_children
= abbrev
->has_children
;
8074 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
8076 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
8078 /* Store the data if it is of an attribute we want to keep in a
8079 partial symbol table. */
8083 switch (part_die
->tag
)
8085 case DW_TAG_compile_unit
:
8086 case DW_TAG_type_unit
:
8087 /* Compilation units have a DW_AT_name that is a filename, not
8088 a source language identifier. */
8089 case DW_TAG_enumeration_type
:
8090 case DW_TAG_enumerator
:
8091 /* These tags always have simple identifiers already; no need
8092 to canonicalize them. */
8093 part_die
->name
= DW_STRING (&attr
);
8097 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
8098 &cu
->objfile
->objfile_obstack
);
8102 case DW_AT_linkage_name
:
8103 case DW_AT_MIPS_linkage_name
:
8104 /* Note that both forms of linkage name might appear. We
8105 assume they will be the same, and we only store the last
8107 if (cu
->language
== language_ada
)
8108 part_die
->name
= DW_STRING (&attr
);
8111 has_low_pc_attr
= 1;
8112 part_die
->lowpc
= DW_ADDR (&attr
);
8115 has_high_pc_attr
= 1;
8116 part_die
->highpc
= DW_ADDR (&attr
);
8118 case DW_AT_location
:
8119 /* Support the .debug_loc offsets */
8120 if (attr_form_is_block (&attr
))
8122 part_die
->locdesc
= DW_BLOCK (&attr
);
8124 else if (attr_form_is_section_offset (&attr
))
8126 dwarf2_complex_location_expr_complaint ();
8130 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
8131 "partial symbol information");
8134 case DW_AT_external
:
8135 part_die
->is_external
= DW_UNSND (&attr
);
8137 case DW_AT_declaration
:
8138 part_die
->is_declaration
= DW_UNSND (&attr
);
8141 part_die
->has_type
= 1;
8143 case DW_AT_abstract_origin
:
8144 case DW_AT_specification
:
8145 case DW_AT_extension
:
8146 part_die
->has_specification
= 1;
8147 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
8150 /* Ignore absolute siblings, they might point outside of
8151 the current compile unit. */
8152 if (attr
.form
== DW_FORM_ref_addr
)
8153 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
8155 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
8157 case DW_AT_byte_size
:
8158 part_die
->has_byte_size
= 1;
8160 case DW_AT_calling_convention
:
8161 /* DWARF doesn't provide a way to identify a program's source-level
8162 entry point. DW_AT_calling_convention attributes are only meant
8163 to describe functions' calling conventions.
8165 However, because it's a necessary piece of information in
8166 Fortran, and because DW_CC_program is the only piece of debugging
8167 information whose definition refers to a 'main program' at all,
8168 several compilers have begun marking Fortran main programs with
8169 DW_CC_program --- even when those functions use the standard
8170 calling conventions.
8172 So until DWARF specifies a way to provide this information and
8173 compilers pick up the new representation, we'll support this
8175 if (DW_UNSND (&attr
) == DW_CC_program
8176 && cu
->language
== language_fortran
)
8177 set_main_name (part_die
->name
);
8184 /* When using the GNU linker, .gnu.linkonce. sections are used to
8185 eliminate duplicate copies of functions and vtables and such.
8186 The linker will arbitrarily choose one and discard the others.
8187 The AT_*_pc values for such functions refer to local labels in
8188 these sections. If the section from that file was discarded, the
8189 labels are not in the output, so the relocs get a value of 0.
8190 If this is a discarded function, mark the pc bounds as invalid,
8191 so that GDB will ignore it. */
8192 if (has_low_pc_attr
&& has_high_pc_attr
8193 && part_die
->lowpc
< part_die
->highpc
8194 && (part_die
->lowpc
!= 0
8195 || dwarf2_per_objfile
->has_section_at_zero
))
8196 part_die
->has_pc_info
= 1;
8201 /* Find a cached partial DIE at OFFSET in CU. */
8203 static struct partial_die_info
*
8204 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
8206 struct partial_die_info
*lookup_die
= NULL
;
8207 struct partial_die_info part_die
;
8209 part_die
.offset
= offset
;
8210 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
8215 /* Find a partial DIE at OFFSET, which may or may not be in CU,
8216 except in the case of .debug_types DIEs which do not reference
8217 outside their CU (they do however referencing other types via
8220 static struct partial_die_info
*
8221 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
8223 struct dwarf2_per_cu_data
*per_cu
= NULL
;
8224 struct partial_die_info
*pd
= NULL
;
8226 if (cu
->per_cu
->from_debug_types
)
8228 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8234 if (offset_in_cu_p (&cu
->header
, offset
))
8236 pd
= find_partial_die_in_comp_unit (offset
, cu
);
8241 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
8243 if (per_cu
->cu
== NULL
)
8245 load_partial_comp_unit (per_cu
, cu
->objfile
);
8246 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
8247 dwarf2_per_objfile
->read_in_chain
= per_cu
;
8250 per_cu
->cu
->last_used
= 0;
8251 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8253 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
8255 struct cleanup
*back_to
;
8256 struct partial_die_info comp_unit_die
;
8257 struct abbrev_info
*abbrev
;
8258 unsigned int bytes_read
;
8261 per_cu
->load_all_dies
= 1;
8263 /* Re-read the DIEs. */
8264 back_to
= make_cleanup (null_cleanup
, 0);
8265 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
8267 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
8268 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
8270 info_ptr
= (dwarf2_per_objfile
->info
.buffer
8271 + per_cu
->cu
->header
.offset
8272 + per_cu
->cu
->header
.first_die_offset
);
8273 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
8274 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
8275 per_cu
->cu
->objfile
->obfd
,
8276 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8278 if (comp_unit_die
.has_children
)
8279 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
8280 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
8282 do_cleanups (back_to
);
8284 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
8290 internal_error (__FILE__
, __LINE__
,
8291 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
8292 offset
, bfd_get_filename (cu
->objfile
->obfd
));
8296 /* Adjust PART_DIE before generating a symbol for it. This function
8297 may set the is_external flag or change the DIE's name. */
8300 fixup_partial_die (struct partial_die_info
*part_die
,
8301 struct dwarf2_cu
*cu
)
8303 /* If we found a reference attribute and the DIE has no name, try
8304 to find a name in the referred to DIE. */
8306 if (part_die
->name
== NULL
&& part_die
->has_specification
)
8308 struct partial_die_info
*spec_die
;
8310 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
8312 fixup_partial_die (spec_die
, cu
);
8316 part_die
->name
= spec_die
->name
;
8318 /* Copy DW_AT_external attribute if it is set. */
8319 if (spec_die
->is_external
)
8320 part_die
->is_external
= spec_die
->is_external
;
8324 /* Set default names for some unnamed DIEs. */
8325 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
8326 || part_die
->tag
== DW_TAG_class_type
))
8327 part_die
->name
= "(anonymous class)";
8329 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
8330 part_die
->name
= "(anonymous namespace)";
8332 if (part_die
->tag
== DW_TAG_structure_type
8333 || part_die
->tag
== DW_TAG_class_type
8334 || part_die
->tag
== DW_TAG_union_type
)
8335 guess_structure_name (part_die
, cu
);
8338 /* Read an attribute value described by an attribute form. */
8341 read_attribute_value (struct attribute
*attr
, unsigned form
,
8342 bfd
*abfd
, gdb_byte
*info_ptr
,
8343 struct dwarf2_cu
*cu
)
8345 struct comp_unit_head
*cu_header
= &cu
->header
;
8346 unsigned int bytes_read
;
8347 struct dwarf_block
*blk
;
8352 case DW_FORM_ref_addr
:
8353 if (cu
->header
.version
== 2)
8354 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8356 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
8357 info_ptr
+= bytes_read
;
8360 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
8361 info_ptr
+= bytes_read
;
8363 case DW_FORM_block2
:
8364 blk
= dwarf_alloc_block (cu
);
8365 blk
->size
= read_2_bytes (abfd
, info_ptr
);
8367 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8368 info_ptr
+= blk
->size
;
8369 DW_BLOCK (attr
) = blk
;
8371 case DW_FORM_block4
:
8372 blk
= dwarf_alloc_block (cu
);
8373 blk
->size
= read_4_bytes (abfd
, info_ptr
);
8375 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8376 info_ptr
+= blk
->size
;
8377 DW_BLOCK (attr
) = blk
;
8380 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
8384 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
8388 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
8391 case DW_FORM_sec_offset
:
8392 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
8393 info_ptr
+= bytes_read
;
8395 case DW_FORM_string
:
8396 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
8397 DW_STRING_IS_CANONICAL (attr
) = 0;
8398 info_ptr
+= bytes_read
;
8401 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
8403 DW_STRING_IS_CANONICAL (attr
) = 0;
8404 info_ptr
+= bytes_read
;
8406 case DW_FORM_exprloc
:
8408 blk
= dwarf_alloc_block (cu
);
8409 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8410 info_ptr
+= bytes_read
;
8411 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8412 info_ptr
+= blk
->size
;
8413 DW_BLOCK (attr
) = blk
;
8415 case DW_FORM_block1
:
8416 blk
= dwarf_alloc_block (cu
);
8417 blk
->size
= read_1_byte (abfd
, info_ptr
);
8419 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
8420 info_ptr
+= blk
->size
;
8421 DW_BLOCK (attr
) = blk
;
8424 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
8428 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
8431 case DW_FORM_flag_present
:
8432 DW_UNSND (attr
) = 1;
8435 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
8436 info_ptr
+= bytes_read
;
8439 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8440 info_ptr
+= bytes_read
;
8443 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
8447 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
8451 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
8455 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
8459 /* Convert the signature to something we can record in DW_UNSND
8461 NOTE: This is NULL if the type wasn't found. */
8462 DW_SIGNATURED_TYPE (attr
) =
8463 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
8466 case DW_FORM_ref_udata
:
8467 DW_ADDR (attr
) = (cu
->header
.offset
8468 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
8469 info_ptr
+= bytes_read
;
8471 case DW_FORM_indirect
:
8472 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
8473 info_ptr
+= bytes_read
;
8474 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
8477 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
8478 dwarf_form_name (form
),
8479 bfd_get_filename (abfd
));
8482 /* We have seen instances where the compiler tried to emit a byte
8483 size attribute of -1 which ended up being encoded as an unsigned
8484 0xffffffff. Although 0xffffffff is technically a valid size value,
8485 an object of this size seems pretty unlikely so we can relatively
8486 safely treat these cases as if the size attribute was invalid and
8487 treat them as zero by default. */
8488 if (attr
->name
== DW_AT_byte_size
8489 && form
== DW_FORM_data4
8490 && DW_UNSND (attr
) >= 0xffffffff)
8493 (&symfile_complaints
,
8494 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
8495 hex_string (DW_UNSND (attr
)));
8496 DW_UNSND (attr
) = 0;
8502 /* Read an attribute described by an abbreviated attribute. */
8505 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
8506 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
8508 attr
->name
= abbrev
->name
;
8509 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
8512 /* read dwarf information from a buffer */
8515 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
8517 return bfd_get_8 (abfd
, buf
);
8521 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
8523 return bfd_get_signed_8 (abfd
, buf
);
8527 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
8529 return bfd_get_16 (abfd
, buf
);
8533 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
8535 return bfd_get_signed_16 (abfd
, buf
);
8539 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
8541 return bfd_get_32 (abfd
, buf
);
8545 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
8547 return bfd_get_signed_32 (abfd
, buf
);
8551 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
8553 return bfd_get_64 (abfd
, buf
);
8557 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
8558 unsigned int *bytes_read
)
8560 struct comp_unit_head
*cu_header
= &cu
->header
;
8561 CORE_ADDR retval
= 0;
8563 if (cu_header
->signed_addr_p
)
8565 switch (cu_header
->addr_size
)
8568 retval
= bfd_get_signed_16 (abfd
, buf
);
8571 retval
= bfd_get_signed_32 (abfd
, buf
);
8574 retval
= bfd_get_signed_64 (abfd
, buf
);
8577 internal_error (__FILE__
, __LINE__
,
8578 _("read_address: bad switch, signed [in module %s]"),
8579 bfd_get_filename (abfd
));
8584 switch (cu_header
->addr_size
)
8587 retval
= bfd_get_16 (abfd
, buf
);
8590 retval
= bfd_get_32 (abfd
, buf
);
8593 retval
= bfd_get_64 (abfd
, buf
);
8596 internal_error (__FILE__
, __LINE__
,
8597 _("read_address: bad switch, unsigned [in module %s]"),
8598 bfd_get_filename (abfd
));
8602 *bytes_read
= cu_header
->addr_size
;
8606 /* Read the initial length from a section. The (draft) DWARF 3
8607 specification allows the initial length to take up either 4 bytes
8608 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
8609 bytes describe the length and all offsets will be 8 bytes in length
8612 An older, non-standard 64-bit format is also handled by this
8613 function. The older format in question stores the initial length
8614 as an 8-byte quantity without an escape value. Lengths greater
8615 than 2^32 aren't very common which means that the initial 4 bytes
8616 is almost always zero. Since a length value of zero doesn't make
8617 sense for the 32-bit format, this initial zero can be considered to
8618 be an escape value which indicates the presence of the older 64-bit
8619 format. As written, the code can't detect (old format) lengths
8620 greater than 4GB. If it becomes necessary to handle lengths
8621 somewhat larger than 4GB, we could allow other small values (such
8622 as the non-sensical values of 1, 2, and 3) to also be used as
8623 escape values indicating the presence of the old format.
8625 The value returned via bytes_read should be used to increment the
8626 relevant pointer after calling read_initial_length().
8628 [ Note: read_initial_length() and read_offset() are based on the
8629 document entitled "DWARF Debugging Information Format", revision
8630 3, draft 8, dated November 19, 2001. This document was obtained
8633 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
8635 This document is only a draft and is subject to change. (So beware.)
8637 Details regarding the older, non-standard 64-bit format were
8638 determined empirically by examining 64-bit ELF files produced by
8639 the SGI toolchain on an IRIX 6.5 machine.
8641 - Kevin, July 16, 2002
8645 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
8647 LONGEST length
= bfd_get_32 (abfd
, buf
);
8649 if (length
== 0xffffffff)
8651 length
= bfd_get_64 (abfd
, buf
+ 4);
8654 else if (length
== 0)
8656 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
8657 length
= bfd_get_64 (abfd
, buf
);
8668 /* Cover function for read_initial_length.
8669 Returns the length of the object at BUF, and stores the size of the
8670 initial length in *BYTES_READ and stores the size that offsets will be in
8672 If the initial length size is not equivalent to that specified in
8673 CU_HEADER then issue a complaint.
8674 This is useful when reading non-comp-unit headers. */
8677 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
8678 const struct comp_unit_head
*cu_header
,
8679 unsigned int *bytes_read
,
8680 unsigned int *offset_size
)
8682 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
8684 gdb_assert (cu_header
->initial_length_size
== 4
8685 || cu_header
->initial_length_size
== 8
8686 || cu_header
->initial_length_size
== 12);
8688 if (cu_header
->initial_length_size
!= *bytes_read
)
8689 complaint (&symfile_complaints
,
8690 _("intermixed 32-bit and 64-bit DWARF sections"));
8692 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
8696 /* Read an offset from the data stream. The size of the offset is
8697 given by cu_header->offset_size. */
8700 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
8701 unsigned int *bytes_read
)
8703 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
8705 *bytes_read
= cu_header
->offset_size
;
8709 /* Read an offset from the data stream. */
8712 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
8716 switch (offset_size
)
8719 retval
= bfd_get_32 (abfd
, buf
);
8722 retval
= bfd_get_64 (abfd
, buf
);
8725 internal_error (__FILE__
, __LINE__
,
8726 _("read_offset_1: bad switch [in module %s]"),
8727 bfd_get_filename (abfd
));
8734 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
8736 /* If the size of a host char is 8 bits, we can return a pointer
8737 to the buffer, otherwise we have to copy the data to a buffer
8738 allocated on the temporary obstack. */
8739 gdb_assert (HOST_CHAR_BIT
== 8);
8744 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
8746 /* If the size of a host char is 8 bits, we can return a pointer
8747 to the string, otherwise we have to copy the string to a buffer
8748 allocated on the temporary obstack. */
8749 gdb_assert (HOST_CHAR_BIT
== 8);
8752 *bytes_read_ptr
= 1;
8755 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
8756 return (char *) buf
;
8760 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
8761 const struct comp_unit_head
*cu_header
,
8762 unsigned int *bytes_read_ptr
)
8764 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
8766 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
8767 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
8769 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
8770 bfd_get_filename (abfd
));
8773 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
8775 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
8776 bfd_get_filename (abfd
));
8779 gdb_assert (HOST_CHAR_BIT
== 8);
8780 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
8782 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
8785 static unsigned long
8786 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
8788 unsigned long result
;
8789 unsigned int num_read
;
8799 byte
= bfd_get_8 (abfd
, buf
);
8802 result
|= ((unsigned long)(byte
& 127) << shift
);
8803 if ((byte
& 128) == 0)
8809 *bytes_read_ptr
= num_read
;
8814 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
8817 int i
, shift
, num_read
;
8826 byte
= bfd_get_8 (abfd
, buf
);
8829 result
|= ((long)(byte
& 127) << shift
);
8831 if ((byte
& 128) == 0)
8836 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
8837 result
|= -(((long)1) << shift
);
8838 *bytes_read_ptr
= num_read
;
8842 /* Return a pointer to just past the end of an LEB128 number in BUF. */
8845 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
8851 byte
= bfd_get_8 (abfd
, buf
);
8853 if ((byte
& 128) == 0)
8859 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
8866 cu
->language
= language_c
;
8868 case DW_LANG_C_plus_plus
:
8869 cu
->language
= language_cplus
;
8872 cu
->language
= language_d
;
8874 case DW_LANG_Fortran77
:
8875 case DW_LANG_Fortran90
:
8876 case DW_LANG_Fortran95
:
8877 cu
->language
= language_fortran
;
8879 case DW_LANG_Mips_Assembler
:
8880 cu
->language
= language_asm
;
8883 cu
->language
= language_java
;
8887 cu
->language
= language_ada
;
8889 case DW_LANG_Modula2
:
8890 cu
->language
= language_m2
;
8892 case DW_LANG_Pascal83
:
8893 cu
->language
= language_pascal
;
8896 cu
->language
= language_objc
;
8898 case DW_LANG_Cobol74
:
8899 case DW_LANG_Cobol85
:
8901 cu
->language
= language_minimal
;
8904 cu
->language_defn
= language_def (cu
->language
);
8907 /* Return the named attribute or NULL if not there. */
8909 static struct attribute
*
8910 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
8913 struct attribute
*spec
= NULL
;
8915 for (i
= 0; i
< die
->num_attrs
; ++i
)
8917 if (die
->attrs
[i
].name
== name
)
8918 return &die
->attrs
[i
];
8919 if (die
->attrs
[i
].name
== DW_AT_specification
8920 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
8921 spec
= &die
->attrs
[i
];
8926 die
= follow_die_ref (die
, spec
, &cu
);
8927 return dwarf2_attr (die
, name
, cu
);
8933 /* Return the named attribute or NULL if not there,
8934 but do not follow DW_AT_specification, etc.
8935 This is for use in contexts where we're reading .debug_types dies.
8936 Following DW_AT_specification, DW_AT_abstract_origin will take us
8937 back up the chain, and we want to go down. */
8939 static struct attribute
*
8940 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
8941 struct dwarf2_cu
*cu
)
8945 for (i
= 0; i
< die
->num_attrs
; ++i
)
8946 if (die
->attrs
[i
].name
== name
)
8947 return &die
->attrs
[i
];
8952 /* Return non-zero iff the attribute NAME is defined for the given DIE,
8953 and holds a non-zero value. This function should only be used for
8954 DW_FORM_flag or DW_FORM_flag_present attributes. */
8957 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
8959 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
8961 return (attr
&& DW_UNSND (attr
));
8965 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
8967 /* A DIE is a declaration if it has a DW_AT_declaration attribute
8968 which value is non-zero. However, we have to be careful with
8969 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
8970 (via dwarf2_flag_true_p) follows this attribute. So we may
8971 end up accidently finding a declaration attribute that belongs
8972 to a different DIE referenced by the specification attribute,
8973 even though the given DIE does not have a declaration attribute. */
8974 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
8975 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
8978 /* Return the die giving the specification for DIE, if there is
8979 one. *SPEC_CU is the CU containing DIE on input, and the CU
8980 containing the return value on output. If there is no
8981 specification, but there is an abstract origin, that is
8984 static struct die_info
*
8985 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
8987 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
8990 if (spec_attr
== NULL
)
8991 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
8993 if (spec_attr
== NULL
)
8996 return follow_die_ref (die
, spec_attr
, spec_cu
);
8999 /* Free the line_header structure *LH, and any arrays and strings it
9002 free_line_header (struct line_header
*lh
)
9004 if (lh
->standard_opcode_lengths
)
9005 xfree (lh
->standard_opcode_lengths
);
9007 /* Remember that all the lh->file_names[i].name pointers are
9008 pointers into debug_line_buffer, and don't need to be freed. */
9010 xfree (lh
->file_names
);
9012 /* Similarly for the include directory names. */
9013 if (lh
->include_dirs
)
9014 xfree (lh
->include_dirs
);
9020 /* Add an entry to LH's include directory table. */
9022 add_include_dir (struct line_header
*lh
, char *include_dir
)
9024 /* Grow the array if necessary. */
9025 if (lh
->include_dirs_size
== 0)
9027 lh
->include_dirs_size
= 1; /* for testing */
9028 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
9029 * sizeof (*lh
->include_dirs
));
9031 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
9033 lh
->include_dirs_size
*= 2;
9034 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
9035 (lh
->include_dirs_size
9036 * sizeof (*lh
->include_dirs
)));
9039 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
9043 /* Add an entry to LH's file name table. */
9045 add_file_name (struct line_header
*lh
,
9047 unsigned int dir_index
,
9048 unsigned int mod_time
,
9049 unsigned int length
)
9051 struct file_entry
*fe
;
9053 /* Grow the array if necessary. */
9054 if (lh
->file_names_size
== 0)
9056 lh
->file_names_size
= 1; /* for testing */
9057 lh
->file_names
= xmalloc (lh
->file_names_size
9058 * sizeof (*lh
->file_names
));
9060 else if (lh
->num_file_names
>= lh
->file_names_size
)
9062 lh
->file_names_size
*= 2;
9063 lh
->file_names
= xrealloc (lh
->file_names
,
9064 (lh
->file_names_size
9065 * sizeof (*lh
->file_names
)));
9068 fe
= &lh
->file_names
[lh
->num_file_names
++];
9070 fe
->dir_index
= dir_index
;
9071 fe
->mod_time
= mod_time
;
9072 fe
->length
= length
;
9078 /* Read the statement program header starting at OFFSET in
9079 .debug_line, according to the endianness of ABFD. Return a pointer
9080 to a struct line_header, allocated using xmalloc.
9082 NOTE: the strings in the include directory and file name tables of
9083 the returned object point into debug_line_buffer, and must not be
9085 static struct line_header
*
9086 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
9087 struct dwarf2_cu
*cu
)
9089 struct cleanup
*back_to
;
9090 struct line_header
*lh
;
9092 unsigned int bytes_read
, offset_size
;
9094 char *cur_dir
, *cur_file
;
9096 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
9097 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
9099 complaint (&symfile_complaints
, _("missing .debug_line section"));
9103 /* Make sure that at least there's room for the total_length field.
9104 That could be 12 bytes long, but we're just going to fudge that. */
9105 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
9107 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9111 lh
= xmalloc (sizeof (*lh
));
9112 memset (lh
, 0, sizeof (*lh
));
9113 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
9116 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
9118 /* Read in the header. */
9120 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
9121 &bytes_read
, &offset_size
);
9122 line_ptr
+= bytes_read
;
9123 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
9124 + dwarf2_per_objfile
->line
.size
))
9126 dwarf2_statement_list_fits_in_line_number_section_complaint ();
9129 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
9130 lh
->version
= read_2_bytes (abfd
, line_ptr
);
9132 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
9133 line_ptr
+= offset_size
;
9134 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
9136 if (lh
->version
>= 4)
9138 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
9142 lh
->maximum_ops_per_instruction
= 1;
9144 if (lh
->maximum_ops_per_instruction
== 0)
9146 lh
->maximum_ops_per_instruction
= 1;
9147 complaint (&symfile_complaints
,
9148 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
9151 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
9153 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
9155 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
9157 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
9159 lh
->standard_opcode_lengths
9160 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
9162 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
9163 for (i
= 1; i
< lh
->opcode_base
; ++i
)
9165 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
9169 /* Read directory table. */
9170 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9172 line_ptr
+= bytes_read
;
9173 add_include_dir (lh
, cur_dir
);
9175 line_ptr
+= bytes_read
;
9177 /* Read file name table. */
9178 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
9180 unsigned int dir_index
, mod_time
, length
;
9182 line_ptr
+= bytes_read
;
9183 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9184 line_ptr
+= bytes_read
;
9185 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9186 line_ptr
+= bytes_read
;
9187 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9188 line_ptr
+= bytes_read
;
9190 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9192 line_ptr
+= bytes_read
;
9193 lh
->statement_program_start
= line_ptr
;
9195 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
9196 + dwarf2_per_objfile
->line
.size
))
9197 complaint (&symfile_complaints
,
9198 _("line number info header doesn't fit in `.debug_line' section"));
9200 discard_cleanups (back_to
);
9204 /* This function exists to work around a bug in certain compilers
9205 (particularly GCC 2.95), in which the first line number marker of a
9206 function does not show up until after the prologue, right before
9207 the second line number marker. This function shifts ADDRESS down
9208 to the beginning of the function if necessary, and is called on
9209 addresses passed to record_line. */
9212 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
9214 struct function_range
*fn
;
9216 /* Find the function_range containing address. */
9221 cu
->cached_fn
= cu
->first_fn
;
9225 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9231 while (fn
&& fn
!= cu
->cached_fn
)
9232 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
9242 if (address
!= fn
->lowpc
)
9243 complaint (&symfile_complaints
,
9244 _("misplaced first line number at 0x%lx for '%s'"),
9245 (unsigned long) address
, fn
->name
);
9250 /* Decode the Line Number Program (LNP) for the given line_header
9251 structure and CU. The actual information extracted and the type
9252 of structures created from the LNP depends on the value of PST.
9254 1. If PST is NULL, then this procedure uses the data from the program
9255 to create all necessary symbol tables, and their linetables.
9256 The compilation directory of the file is passed in COMP_DIR,
9257 and must not be NULL.
9259 2. If PST is not NULL, this procedure reads the program to determine
9260 the list of files included by the unit represented by PST, and
9261 builds all the associated partial symbol tables. In this case,
9262 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
9263 is not used to compute the full name of the symtab, and therefore
9264 omitting it when building the partial symtab does not introduce
9265 the potential for inconsistency - a partial symtab and its associated
9266 symbtab having a different fullname -). */
9269 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
9270 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
9272 gdb_byte
*line_ptr
, *extended_end
;
9274 unsigned int bytes_read
, extended_len
;
9275 unsigned char op_code
, extended_op
, adj_opcode
;
9277 struct objfile
*objfile
= cu
->objfile
;
9278 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
9279 const int decode_for_pst_p
= (pst
!= NULL
);
9280 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
9282 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9284 line_ptr
= lh
->statement_program_start
;
9285 line_end
= lh
->statement_program_end
;
9287 /* Read the statement sequences until there's nothing left. */
9288 while (line_ptr
< line_end
)
9290 /* state machine registers */
9291 CORE_ADDR address
= 0;
9292 unsigned int file
= 1;
9293 unsigned int line
= 1;
9294 unsigned int column
= 0;
9295 int is_stmt
= lh
->default_is_stmt
;
9296 int basic_block
= 0;
9297 int end_sequence
= 0;
9299 unsigned char op_index
= 0;
9301 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
9303 /* Start a subfile for the current file of the state machine. */
9304 /* lh->include_dirs and lh->file_names are 0-based, but the
9305 directory and file name numbers in the statement program
9307 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9311 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9313 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9316 /* Decode the table. */
9317 while (!end_sequence
)
9319 op_code
= read_1_byte (abfd
, line_ptr
);
9321 if (line_ptr
> line_end
)
9323 dwarf2_debug_line_missing_end_sequence_complaint ();
9327 if (op_code
>= lh
->opcode_base
)
9329 /* Special operand. */
9330 adj_opcode
= op_code
- lh
->opcode_base
;
9331 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
9332 / lh
->maximum_ops_per_instruction
)
9333 * lh
->minimum_instruction_length
);
9334 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
9335 % lh
->maximum_ops_per_instruction
);
9336 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
9337 if (lh
->num_file_names
< file
|| file
== 0)
9338 dwarf2_debug_line_missing_file_complaint ();
9339 /* For now we ignore lines not starting on an
9340 instruction boundary. */
9341 else if (op_index
== 0)
9343 lh
->file_names
[file
- 1].included_p
= 1;
9344 if (!decode_for_pst_p
&& is_stmt
)
9346 if (last_subfile
!= current_subfile
)
9348 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9350 record_line (last_subfile
, 0, addr
);
9351 last_subfile
= current_subfile
;
9353 /* Append row to matrix using current values. */
9354 addr
= check_cu_functions (address
, cu
);
9355 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
9356 record_line (current_subfile
, line
, addr
);
9361 else switch (op_code
)
9363 case DW_LNS_extended_op
:
9364 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9365 line_ptr
+= bytes_read
;
9366 extended_end
= line_ptr
+ extended_len
;
9367 extended_op
= read_1_byte (abfd
, line_ptr
);
9369 switch (extended_op
)
9371 case DW_LNE_end_sequence
:
9374 case DW_LNE_set_address
:
9375 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
9377 line_ptr
+= bytes_read
;
9378 address
+= baseaddr
;
9380 case DW_LNE_define_file
:
9383 unsigned int dir_index
, mod_time
, length
;
9385 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
9386 line_ptr
+= bytes_read
;
9388 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9389 line_ptr
+= bytes_read
;
9391 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9392 line_ptr
+= bytes_read
;
9394 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9395 line_ptr
+= bytes_read
;
9396 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
9399 case DW_LNE_set_discriminator
:
9400 /* The discriminator is not interesting to the debugger;
9402 line_ptr
= extended_end
;
9405 complaint (&symfile_complaints
,
9406 _("mangled .debug_line section"));
9409 /* Make sure that we parsed the extended op correctly. If e.g.
9410 we expected a different address size than the producer used,
9411 we may have read the wrong number of bytes. */
9412 if (line_ptr
!= extended_end
)
9414 complaint (&symfile_complaints
,
9415 _("mangled .debug_line section"));
9420 if (lh
->num_file_names
< file
|| file
== 0)
9421 dwarf2_debug_line_missing_file_complaint ();
9424 lh
->file_names
[file
- 1].included_p
= 1;
9425 if (!decode_for_pst_p
&& is_stmt
)
9427 if (last_subfile
!= current_subfile
)
9429 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9431 record_line (last_subfile
, 0, addr
);
9432 last_subfile
= current_subfile
;
9434 addr
= check_cu_functions (address
, cu
);
9435 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
9436 record_line (current_subfile
, line
, addr
);
9441 case DW_LNS_advance_pc
:
9444 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9446 address
+= (((op_index
+ adjust
)
9447 / lh
->maximum_ops_per_instruction
)
9448 * lh
->minimum_instruction_length
);
9449 op_index
= ((op_index
+ adjust
)
9450 % lh
->maximum_ops_per_instruction
);
9451 line_ptr
+= bytes_read
;
9454 case DW_LNS_advance_line
:
9455 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
9456 line_ptr
+= bytes_read
;
9458 case DW_LNS_set_file
:
9460 /* The arrays lh->include_dirs and lh->file_names are
9461 0-based, but the directory and file name numbers in
9462 the statement program are 1-based. */
9463 struct file_entry
*fe
;
9466 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9467 line_ptr
+= bytes_read
;
9468 if (lh
->num_file_names
< file
|| file
== 0)
9469 dwarf2_debug_line_missing_file_complaint ();
9472 fe
= &lh
->file_names
[file
- 1];
9474 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9475 if (!decode_for_pst_p
)
9477 last_subfile
= current_subfile
;
9478 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9483 case DW_LNS_set_column
:
9484 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9485 line_ptr
+= bytes_read
;
9487 case DW_LNS_negate_stmt
:
9488 is_stmt
= (!is_stmt
);
9490 case DW_LNS_set_basic_block
:
9493 /* Add to the address register of the state machine the
9494 address increment value corresponding to special opcode
9495 255. I.e., this value is scaled by the minimum
9496 instruction length since special opcode 255 would have
9497 scaled the the increment. */
9498 case DW_LNS_const_add_pc
:
9500 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
9502 address
+= (((op_index
+ adjust
)
9503 / lh
->maximum_ops_per_instruction
)
9504 * lh
->minimum_instruction_length
);
9505 op_index
= ((op_index
+ adjust
)
9506 % lh
->maximum_ops_per_instruction
);
9509 case DW_LNS_fixed_advance_pc
:
9510 address
+= read_2_bytes (abfd
, line_ptr
);
9516 /* Unknown standard opcode, ignore it. */
9519 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
9521 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
9522 line_ptr
+= bytes_read
;
9527 if (lh
->num_file_names
< file
|| file
== 0)
9528 dwarf2_debug_line_missing_file_complaint ();
9531 lh
->file_names
[file
- 1].included_p
= 1;
9532 if (!decode_for_pst_p
)
9534 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
9535 record_line (current_subfile
, 0, addr
);
9540 if (decode_for_pst_p
)
9544 /* Now that we're done scanning the Line Header Program, we can
9545 create the psymtab of each included file. */
9546 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
9547 if (lh
->file_names
[file_index
].included_p
== 1)
9549 const struct file_entry fe
= lh
->file_names
[file_index
];
9550 char *include_name
= fe
.name
;
9551 char *dir_name
= NULL
;
9552 char *pst_filename
= pst
->filename
;
9555 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
9557 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
9559 include_name
= concat (dir_name
, SLASH_STRING
,
9560 include_name
, (char *)NULL
);
9561 make_cleanup (xfree
, include_name
);
9564 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
9566 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
9567 pst_filename
, (char *)NULL
);
9568 make_cleanup (xfree
, pst_filename
);
9571 if (strcmp (include_name
, pst_filename
) != 0)
9572 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
9577 /* Make sure a symtab is created for every file, even files
9578 which contain only variables (i.e. no code with associated
9582 struct file_entry
*fe
;
9584 for (i
= 0; i
< lh
->num_file_names
; i
++)
9588 fe
= &lh
->file_names
[i
];
9590 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
9591 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
9593 /* Skip the main file; we don't need it, and it must be
9594 allocated last, so that it will show up before the
9595 non-primary symtabs in the objfile's symtab list. */
9596 if (current_subfile
== first_subfile
)
9599 if (current_subfile
->symtab
== NULL
)
9600 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
9602 fe
->symtab
= current_subfile
->symtab
;
9607 /* Start a subfile for DWARF. FILENAME is the name of the file and
9608 DIRNAME the name of the source directory which contains FILENAME
9609 or NULL if not known. COMP_DIR is the compilation directory for the
9610 linetable's compilation unit or NULL if not known.
9611 This routine tries to keep line numbers from identical absolute and
9612 relative file names in a common subfile.
9614 Using the `list' example from the GDB testsuite, which resides in
9615 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
9616 of /srcdir/list0.c yields the following debugging information for list0.c:
9618 DW_AT_name: /srcdir/list0.c
9619 DW_AT_comp_dir: /compdir
9620 files.files[0].name: list0.h
9621 files.files[0].dir: /srcdir
9622 files.files[1].name: list0.c
9623 files.files[1].dir: /srcdir
9625 The line number information for list0.c has to end up in a single
9626 subfile, so that `break /srcdir/list0.c:1' works as expected.
9627 start_subfile will ensure that this happens provided that we pass the
9628 concatenation of files.files[1].dir and files.files[1].name as the
9632 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
9636 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
9637 `start_symtab' will always pass the contents of DW_AT_comp_dir as
9638 second argument to start_subfile. To be consistent, we do the
9639 same here. In order not to lose the line information directory,
9640 we concatenate it to the filename when it makes sense.
9641 Note that the Dwarf3 standard says (speaking of filenames in line
9642 information): ``The directory index is ignored for file names
9643 that represent full path names''. Thus ignoring dirname in the
9644 `else' branch below isn't an issue. */
9646 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
9647 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
9649 fullname
= filename
;
9651 start_subfile (fullname
, comp_dir
);
9653 if (fullname
!= filename
)
9658 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
9659 struct dwarf2_cu
*cu
)
9661 struct objfile
*objfile
= cu
->objfile
;
9662 struct comp_unit_head
*cu_header
= &cu
->header
;
9664 /* NOTE drow/2003-01-30: There used to be a comment and some special
9665 code here to turn a symbol with DW_AT_external and a
9666 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
9667 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
9668 with some versions of binutils) where shared libraries could have
9669 relocations against symbols in their debug information - the
9670 minimal symbol would have the right address, but the debug info
9671 would not. It's no longer necessary, because we will explicitly
9672 apply relocations when we read in the debug information now. */
9674 /* A DW_AT_location attribute with no contents indicates that a
9675 variable has been optimized away. */
9676 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
9678 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
9682 /* Handle one degenerate form of location expression specially, to
9683 preserve GDB's previous behavior when section offsets are
9684 specified. If this is just a DW_OP_addr then mark this symbol
9687 if (attr_form_is_block (attr
)
9688 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
9689 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
9693 SYMBOL_VALUE_ADDRESS (sym
) =
9694 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
9695 SYMBOL_CLASS (sym
) = LOC_STATIC
;
9696 fixup_symbol_section (sym
, objfile
);
9697 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
9698 SYMBOL_SECTION (sym
));
9702 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
9703 expression evaluator, and use LOC_COMPUTED only when necessary
9704 (i.e. when the value of a register or memory location is
9705 referenced, or a thread-local block, etc.). Then again, it might
9706 not be worthwhile. I'm assuming that it isn't unless performance
9707 or memory numbers show me otherwise. */
9709 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
9710 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
9713 /* Given a pointer to a DWARF information entry, figure out if we need
9714 to make a symbol table entry for it, and if so, create a new entry
9715 and return a pointer to it.
9716 If TYPE is NULL, determine symbol type from the die, otherwise
9717 used the passed type. */
9719 static struct symbol
*
9720 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
9722 struct objfile
*objfile
= cu
->objfile
;
9723 struct symbol
*sym
= NULL
;
9725 struct attribute
*attr
= NULL
;
9726 struct attribute
*attr2
= NULL
;
9728 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
9730 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
9732 name
= dwarf2_name (die
, cu
);
9735 const char *linkagename
;
9737 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
9738 sizeof (struct symbol
));
9739 OBJSTAT (objfile
, n_syms
++);
9740 memset (sym
, 0, sizeof (struct symbol
));
9742 /* Cache this symbol's name and the name's demangled form (if any). */
9743 SYMBOL_LANGUAGE (sym
) = cu
->language
;
9744 linkagename
= dwarf2_physname (name
, die
, cu
);
9745 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
9747 /* Fortran does not have mangling standard and the mangling does differ
9748 between gfortran, iFort etc. */
9749 if (cu
->language
== language_fortran
9750 && sym
->ginfo
.language_specific
.cplus_specific
.demangled_name
== NULL
)
9751 sym
->ginfo
.language_specific
.cplus_specific
.demangled_name
9752 = (char *) dwarf2_full_name (name
, die
, cu
);
9754 /* Default assumptions.
9755 Use the passed type or decode it from the die. */
9756 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
9757 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
9759 SYMBOL_TYPE (sym
) = type
;
9761 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
9762 attr
= dwarf2_attr (die
,
9763 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
9767 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
9770 attr
= dwarf2_attr (die
,
9771 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
9775 int file_index
= DW_UNSND (attr
);
9777 if (cu
->line_header
== NULL
9778 || file_index
> cu
->line_header
->num_file_names
)
9779 complaint (&symfile_complaints
,
9780 _("file index out of range"));
9781 else if (file_index
> 0)
9783 struct file_entry
*fe
;
9785 fe
= &cu
->line_header
->file_names
[file_index
- 1];
9786 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
9793 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
9796 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
9798 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_core_addr
;
9799 SYMBOL_DOMAIN (sym
) = LABEL_DOMAIN
;
9800 SYMBOL_CLASS (sym
) = LOC_LABEL
;
9801 add_symbol_to_list (sym
, cu
->list_in_scope
);
9803 case DW_TAG_subprogram
:
9804 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9806 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
9807 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9808 if ((attr2
&& (DW_UNSND (attr2
) != 0))
9809 || cu
->language
== language_ada
)
9811 /* Subprograms marked external are stored as a global symbol.
9812 Ada subprograms, whether marked external or not, are always
9813 stored as a global symbol, because we want to be able to
9814 access them globally. For instance, we want to be able
9815 to break on a nested subprogram without having to
9816 specify the context. */
9817 add_symbol_to_list (sym
, &global_symbols
);
9821 add_symbol_to_list (sym
, cu
->list_in_scope
);
9824 case DW_TAG_inlined_subroutine
:
9825 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
9827 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
9828 SYMBOL_INLINED (sym
) = 1;
9829 /* Do not add the symbol to any lists. It will be found via
9830 BLOCK_FUNCTION from the blockvector. */
9832 case DW_TAG_variable
:
9834 /* Compilation with minimal debug info may result in variables
9835 with missing type entries. Change the misleading `void' type
9836 to something sensible. */
9837 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
9839 = objfile_type (objfile
)->nodebug_data_symbol
;
9841 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9842 /* In the case of DW_TAG_member, we should only be called for
9843 static const members. */
9844 if (die
->tag
== DW_TAG_member
)
9846 /* dwarf2_add_field uses die_is_declaration,
9847 so we do the same. */
9848 gdb_assert (die_is_declaration (die
, cu
));
9853 dwarf2_const_value (attr
, sym
, cu
);
9854 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9855 if (attr2
&& (DW_UNSND (attr2
) != 0))
9856 add_symbol_to_list (sym
, &global_symbols
);
9858 add_symbol_to_list (sym
, cu
->list_in_scope
);
9861 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9864 var_decode_location (attr
, sym
, cu
);
9865 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9866 if (attr2
&& (DW_UNSND (attr2
) != 0))
9868 struct pending
**list_to_add
;
9870 /* Workaround gfortran PR debug/40040 - it uses
9871 DW_AT_location for variables in -fPIC libraries which may
9872 get overriden by other libraries/executable and get
9873 a different address. Resolve it by the minimal symbol
9874 which may come from inferior's executable using copy
9875 relocation. Make this workaround only for gfortran as for
9876 other compilers GDB cannot guess the minimal symbol
9877 Fortran mangling kind. */
9878 if (cu
->language
== language_fortran
&& die
->parent
9879 && die
->parent
->tag
== DW_TAG_module
9881 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
9882 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
9884 /* A variable with DW_AT_external is never static,
9885 but it may be block-scoped. */
9886 list_to_add
= (cu
->list_in_scope
== &file_symbols
9887 ? &global_symbols
: cu
->list_in_scope
);
9888 add_symbol_to_list (sym
, list_to_add
);
9891 add_symbol_to_list (sym
, cu
->list_in_scope
);
9895 /* We do not know the address of this symbol.
9896 If it is an external symbol and we have type information
9897 for it, enter the symbol as a LOC_UNRESOLVED symbol.
9898 The address of the variable will then be determined from
9899 the minimal symbol table whenever the variable is
9901 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
9902 if (attr2
&& (DW_UNSND (attr2
) != 0)
9903 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
9905 struct pending
**list_to_add
;
9907 /* A variable with DW_AT_external is never static, but it
9908 may be block-scoped. */
9909 list_to_add
= (cu
->list_in_scope
== &file_symbols
9910 ? &global_symbols
: cu
->list_in_scope
);
9912 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
9913 add_symbol_to_list (sym
, list_to_add
);
9915 else if (!die_is_declaration (die
, cu
))
9917 /* Use the default LOC_OPTIMIZED_OUT class. */
9918 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
9919 add_symbol_to_list (sym
, cu
->list_in_scope
);
9923 case DW_TAG_formal_parameter
:
9924 /* If we are inside a function, mark this as an argument. If
9925 not, we might be looking at an argument to an inlined function
9926 when we do not have enough information to show inlined frames;
9927 pretend it's a local variable in that case so that the user can
9929 if (context_stack_depth
> 0
9930 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
9931 SYMBOL_IS_ARGUMENT (sym
) = 1;
9932 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
9935 var_decode_location (attr
, sym
, cu
);
9937 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
9940 dwarf2_const_value (attr
, sym
, cu
);
9942 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
9943 if (attr
&& DW_UNSND (attr
))
9945 struct type
*ref_type
;
9947 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
9948 SYMBOL_TYPE (sym
) = ref_type
;
9951 add_symbol_to_list (sym
, cu
->list_in_scope
);
9953 case DW_TAG_unspecified_parameters
:
9954 /* From varargs functions; gdb doesn't seem to have any
9955 interest in this information, so just ignore it for now.
9958 case DW_TAG_class_type
:
9959 case DW_TAG_interface_type
:
9960 case DW_TAG_structure_type
:
9961 case DW_TAG_union_type
:
9962 case DW_TAG_set_type
:
9963 case DW_TAG_enumeration_type
:
9964 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
9965 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
9968 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
9969 really ever be static objects: otherwise, if you try
9970 to, say, break of a class's method and you're in a file
9971 which doesn't mention that class, it won't work unless
9972 the check for all static symbols in lookup_symbol_aux
9973 saves you. See the OtherFileClass tests in
9974 gdb.c++/namespace.exp. */
9976 struct pending
**list_to_add
;
9978 list_to_add
= (cu
->list_in_scope
== &file_symbols
9979 && (cu
->language
== language_cplus
9980 || cu
->language
== language_java
)
9981 ? &global_symbols
: cu
->list_in_scope
);
9983 add_symbol_to_list (sym
, list_to_add
);
9985 /* The semantics of C++ state that "struct foo { ... }" also
9986 defines a typedef for "foo". A Java class declaration also
9987 defines a typedef for the class. */
9988 if (cu
->language
== language_cplus
9989 || cu
->language
== language_java
9990 || cu
->language
== language_ada
)
9992 /* The symbol's name is already allocated along with
9993 this objfile, so we don't need to duplicate it for
9995 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
9996 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
10000 case DW_TAG_typedef
:
10001 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10002 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10003 add_symbol_to_list (sym
, cu
->list_in_scope
);
10005 case DW_TAG_base_type
:
10006 case DW_TAG_subrange_type
:
10007 case DW_TAG_const_type
:
10008 case DW_TAG_volatile_type
:
10009 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10010 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
10011 add_symbol_to_list (sym
, cu
->list_in_scope
);
10013 case DW_TAG_enumerator
:
10014 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
10017 dwarf2_const_value (attr
, sym
, cu
);
10020 /* NOTE: carlton/2003-11-10: See comment above in the
10021 DW_TAG_class_type, etc. block. */
10023 struct pending
**list_to_add
;
10025 list_to_add
= (cu
->list_in_scope
== &file_symbols
10026 && (cu
->language
== language_cplus
10027 || cu
->language
== language_java
)
10028 ? &global_symbols
: cu
->list_in_scope
);
10030 add_symbol_to_list (sym
, list_to_add
);
10033 case DW_TAG_namespace
:
10034 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
10035 add_symbol_to_list (sym
, &global_symbols
);
10038 /* Not a tag we recognize. Hopefully we aren't processing
10039 trash data, but since we must specifically ignore things
10040 we don't recognize, there is nothing else we should do at
10042 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
10043 dwarf_tag_name (die
->tag
));
10047 /* For the benefit of old versions of GCC, check for anonymous
10048 namespaces based on the demangled name. */
10049 if (!processing_has_namespace_info
10050 && cu
->language
== language_cplus
)
10051 cp_scan_for_anonymous_namespaces (sym
);
10056 /* Copy constant value from an attribute to a symbol. */
10059 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
10060 struct dwarf2_cu
*cu
)
10062 struct objfile
*objfile
= cu
->objfile
;
10063 struct comp_unit_head
*cu_header
= &cu
->header
;
10064 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
10065 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
10066 struct dwarf_block
*blk
;
10068 switch (attr
->form
)
10072 struct dwarf2_locexpr_baton
*baton
;
10075 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
10076 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
10077 cu_header
->addr_size
,
10078 TYPE_LENGTH (SYMBOL_TYPE
10080 /* Symbols of this form are reasonably rare, so we just
10081 piggyback on the existing location code rather than writing
10082 a new implementation of symbol_computed_ops. */
10083 baton
= obstack_alloc (&objfile
->objfile_obstack
,
10084 sizeof (struct dwarf2_locexpr_baton
));
10085 baton
->per_cu
= cu
->per_cu
;
10086 gdb_assert (baton
->per_cu
);
10088 baton
->size
= 2 + cu_header
->addr_size
;
10089 data
= obstack_alloc (&objfile
->objfile_obstack
, baton
->size
);
10090 baton
->data
= data
;
10092 data
[0] = DW_OP_addr
;
10093 store_unsigned_integer (&data
[1], cu_header
->addr_size
,
10094 byte_order
, DW_ADDR (attr
));
10095 data
[cu_header
->addr_size
+ 1] = DW_OP_stack_value
;
10097 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10098 SYMBOL_LOCATION_BATON (sym
) = baton
;
10099 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
10102 case DW_FORM_string
:
10104 /* DW_STRING is already allocated on the obstack, point directly
10106 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
10107 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
10109 case DW_FORM_block1
:
10110 case DW_FORM_block2
:
10111 case DW_FORM_block4
:
10112 case DW_FORM_block
:
10113 case DW_FORM_exprloc
:
10114 blk
= DW_BLOCK (attr
);
10115 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
10116 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
10118 TYPE_LENGTH (SYMBOL_TYPE
10120 SYMBOL_VALUE_BYTES (sym
) =
10121 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
10122 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
10123 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
10126 /* The DW_AT_const_value attributes are supposed to carry the
10127 symbol's value "represented as it would be on the target
10128 architecture." By the time we get here, it's already been
10129 converted to host endianness, so we just need to sign- or
10130 zero-extend it as appropriate. */
10131 case DW_FORM_data1
:
10132 dwarf2_const_value_data (attr
, sym
, 8);
10134 case DW_FORM_data2
:
10135 dwarf2_const_value_data (attr
, sym
, 16);
10137 case DW_FORM_data4
:
10138 dwarf2_const_value_data (attr
, sym
, 32);
10140 case DW_FORM_data8
:
10141 dwarf2_const_value_data (attr
, sym
, 64);
10144 case DW_FORM_sdata
:
10145 SYMBOL_VALUE (sym
) = DW_SND (attr
);
10146 SYMBOL_CLASS (sym
) = LOC_CONST
;
10149 case DW_FORM_udata
:
10150 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
10151 SYMBOL_CLASS (sym
) = LOC_CONST
;
10155 complaint (&symfile_complaints
,
10156 _("unsupported const value attribute form: '%s'"),
10157 dwarf_form_name (attr
->form
));
10158 SYMBOL_VALUE (sym
) = 0;
10159 SYMBOL_CLASS (sym
) = LOC_CONST
;
10165 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
10166 or zero-extend it as appropriate for the symbol's type. */
10168 dwarf2_const_value_data (struct attribute
*attr
,
10169 struct symbol
*sym
,
10172 LONGEST l
= DW_UNSND (attr
);
10174 if (bits
< sizeof (l
) * 8)
10176 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
10177 l
&= ((LONGEST
) 1 << bits
) - 1;
10179 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
10182 SYMBOL_VALUE (sym
) = l
;
10183 SYMBOL_CLASS (sym
) = LOC_CONST
;
10187 /* Return the type of the die in question using its DW_AT_type attribute. */
10189 static struct type
*
10190 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10192 struct attribute
*type_attr
;
10193 struct die_info
*type_die
;
10195 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
10198 /* A missing DW_AT_type represents a void type. */
10199 return objfile_type (cu
->objfile
)->builtin_void
;
10202 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10204 return tag_type_to_type (type_die
, cu
);
10207 /* True iff CU's producer generates GNAT Ada auxiliary information
10208 that allows to find parallel types through that information instead
10209 of having to do expensive parallel lookups by type name. */
10212 need_gnat_info (struct dwarf2_cu
*cu
)
10214 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
10215 of GNAT produces this auxiliary information, without any indication
10216 that it is produced. Part of enhancing the FSF version of GNAT
10217 to produce that information will be to put in place an indicator
10218 that we can use in order to determine whether the descriptive type
10219 info is available or not. One suggestion that has been made is
10220 to use a new attribute, attached to the CU die. For now, assume
10221 that the descriptive type info is not available. */
10226 /* Return the auxiliary type of the die in question using its
10227 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
10228 attribute is not present. */
10230 static struct type
*
10231 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10233 struct attribute
*type_attr
;
10234 struct die_info
*type_die
;
10236 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
10240 type_die
= follow_die_ref (die
, type_attr
, &cu
);
10241 return tag_type_to_type (type_die
, cu
);
10244 /* If DIE has a descriptive_type attribute, then set the TYPE's
10245 descriptive type accordingly. */
10248 set_descriptive_type (struct type
*type
, struct die_info
*die
,
10249 struct dwarf2_cu
*cu
)
10251 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
10253 if (descriptive_type
)
10255 ALLOCATE_GNAT_AUX_TYPE (type
);
10256 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
10260 /* Return the containing type of the die in question using its
10261 DW_AT_containing_type attribute. */
10263 static struct type
*
10264 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10266 struct attribute
*type_attr
;
10267 struct die_info
*type_die
;
10269 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
10271 error (_("Dwarf Error: Problem turning containing type into gdb type "
10272 "[in module %s]"), cu
->objfile
->name
);
10274 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
10275 return tag_type_to_type (type_die
, cu
);
10278 static struct type
*
10279 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10281 struct type
*this_type
;
10283 this_type
= read_type_die (die
, cu
);
10286 char *message
, *saved
;
10288 /* read_type_die already issued a complaint. */
10289 message
= xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"),
10293 saved
= obstack_copy0 (&cu
->objfile
->objfile_obstack
,
10294 message
, strlen (message
));
10297 this_type
= init_type (TYPE_CODE_ERROR
, 0, 0, saved
, cu
->objfile
);
10302 static struct type
*
10303 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
10305 struct type
*this_type
;
10307 this_type
= get_die_type (die
, cu
);
10313 case DW_TAG_class_type
:
10314 case DW_TAG_interface_type
:
10315 case DW_TAG_structure_type
:
10316 case DW_TAG_union_type
:
10317 this_type
= read_structure_type (die
, cu
);
10319 case DW_TAG_enumeration_type
:
10320 this_type
= read_enumeration_type (die
, cu
);
10322 case DW_TAG_subprogram
:
10323 case DW_TAG_subroutine_type
:
10324 case DW_TAG_inlined_subroutine
:
10325 this_type
= read_subroutine_type (die
, cu
);
10327 case DW_TAG_array_type
:
10328 this_type
= read_array_type (die
, cu
);
10330 case DW_TAG_set_type
:
10331 this_type
= read_set_type (die
, cu
);
10333 case DW_TAG_pointer_type
:
10334 this_type
= read_tag_pointer_type (die
, cu
);
10336 case DW_TAG_ptr_to_member_type
:
10337 this_type
= read_tag_ptr_to_member_type (die
, cu
);
10339 case DW_TAG_reference_type
:
10340 this_type
= read_tag_reference_type (die
, cu
);
10342 case DW_TAG_const_type
:
10343 this_type
= read_tag_const_type (die
, cu
);
10345 case DW_TAG_volatile_type
:
10346 this_type
= read_tag_volatile_type (die
, cu
);
10348 case DW_TAG_string_type
:
10349 this_type
= read_tag_string_type (die
, cu
);
10351 case DW_TAG_typedef
:
10352 this_type
= read_typedef (die
, cu
);
10354 case DW_TAG_subrange_type
:
10355 this_type
= read_subrange_type (die
, cu
);
10357 case DW_TAG_base_type
:
10358 this_type
= read_base_type (die
, cu
);
10360 case DW_TAG_unspecified_type
:
10361 this_type
= read_unspecified_type (die
, cu
);
10363 case DW_TAG_namespace
:
10364 this_type
= read_namespace_type (die
, cu
);
10366 case DW_TAG_module
:
10367 this_type
= read_module_type (die
, cu
);
10370 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
10371 dwarf_tag_name (die
->tag
));
10378 /* Return the name of the namespace/class that DIE is defined within,
10379 or "" if we can't tell. The caller should not xfree the result.
10381 For example, if we're within the method foo() in the following
10391 then determine_prefix on foo's die will return "N::C". */
10394 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
10396 struct die_info
*parent
, *spec_die
;
10397 struct dwarf2_cu
*spec_cu
;
10398 struct type
*parent_type
;
10400 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
10401 && cu
->language
!= language_fortran
)
10404 /* We have to be careful in the presence of DW_AT_specification.
10405 For example, with GCC 3.4, given the code
10409 // Definition of N::foo.
10413 then we'll have a tree of DIEs like this:
10415 1: DW_TAG_compile_unit
10416 2: DW_TAG_namespace // N
10417 3: DW_TAG_subprogram // declaration of N::foo
10418 4: DW_TAG_subprogram // definition of N::foo
10419 DW_AT_specification // refers to die #3
10421 Thus, when processing die #4, we have to pretend that we're in
10422 the context of its DW_AT_specification, namely the contex of die
10425 spec_die
= die_specification (die
, &spec_cu
);
10426 if (spec_die
== NULL
)
10427 parent
= die
->parent
;
10430 parent
= spec_die
->parent
;
10434 if (parent
== NULL
)
10437 switch (parent
->tag
)
10439 case DW_TAG_namespace
:
10440 parent_type
= read_type_die (parent
, cu
);
10441 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
10442 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
10443 Work around this problem here. */
10444 if (cu
->language
== language_cplus
10445 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
10447 /* We give a name to even anonymous namespaces. */
10448 return TYPE_TAG_NAME (parent_type
);
10449 case DW_TAG_class_type
:
10450 case DW_TAG_interface_type
:
10451 case DW_TAG_structure_type
:
10452 case DW_TAG_union_type
:
10453 case DW_TAG_module
:
10454 parent_type
= read_type_die (parent
, cu
);
10455 if (TYPE_TAG_NAME (parent_type
) != NULL
)
10456 return TYPE_TAG_NAME (parent_type
);
10458 /* An anonymous structure is only allowed non-static data
10459 members; no typedefs, no member functions, et cetera.
10460 So it does not need a prefix. */
10463 return determine_prefix (parent
, cu
);
10467 /* Return a newly-allocated string formed by concatenating PREFIX and
10468 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
10469 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
10470 perform an obconcat, otherwise allocate storage for the result. The CU argument
10471 is used to determine the language and hence, the appropriate separator. */
10473 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
10476 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
10477 int physname
, struct dwarf2_cu
*cu
)
10479 const char *lead
= "";
10482 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
10484 else if (cu
->language
== language_java
)
10486 else if (cu
->language
== language_fortran
&& physname
)
10488 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
10489 DW_AT_MIPS_linkage_name is preferred and used instead. */
10497 if (prefix
== NULL
)
10499 if (suffix
== NULL
)
10504 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
10506 strcpy (retval
, lead
);
10507 strcat (retval
, prefix
);
10508 strcat (retval
, sep
);
10509 strcat (retval
, suffix
);
10514 /* We have an obstack. */
10515 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
10519 /* Return sibling of die, NULL if no sibling. */
10521 static struct die_info
*
10522 sibling_die (struct die_info
*die
)
10524 return die
->sibling
;
10527 /* Get name of a die, return NULL if not found. */
10530 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
10531 struct obstack
*obstack
)
10533 if (name
&& cu
->language
== language_cplus
)
10535 char *canon_name
= cp_canonicalize_string (name
);
10537 if (canon_name
!= NULL
)
10539 if (strcmp (canon_name
, name
) != 0)
10540 name
= obsavestring (canon_name
, strlen (canon_name
),
10542 xfree (canon_name
);
10549 /* Get name of a die, return NULL if not found. */
10552 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
10554 struct attribute
*attr
;
10556 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
10557 if (!attr
|| !DW_STRING (attr
))
10562 case DW_TAG_compile_unit
:
10563 /* Compilation units have a DW_AT_name that is a filename, not
10564 a source language identifier. */
10565 case DW_TAG_enumeration_type
:
10566 case DW_TAG_enumerator
:
10567 /* These tags always have simple identifiers already; no need
10568 to canonicalize them. */
10569 return DW_STRING (attr
);
10571 case DW_TAG_subprogram
:
10572 /* Java constructors will all be named "<init>", so return
10573 the class name when we see this special case. */
10574 if (cu
->language
== language_java
10575 && DW_STRING (attr
) != NULL
10576 && strcmp (DW_STRING (attr
), "<init>") == 0)
10578 struct dwarf2_cu
*spec_cu
= cu
;
10579 struct die_info
*spec_die
;
10581 /* GCJ will output '<init>' for Java constructor names.
10582 For this special case, return the name of the parent class. */
10584 /* GCJ may output suprogram DIEs with AT_specification set.
10585 If so, use the name of the specified DIE. */
10586 spec_die
= die_specification (die
, &spec_cu
);
10587 if (spec_die
!= NULL
)
10588 return dwarf2_name (spec_die
, spec_cu
);
10593 if (die
->tag
== DW_TAG_class_type
)
10594 return dwarf2_name (die
, cu
);
10596 while (die
->tag
!= DW_TAG_compile_unit
);
10600 case DW_TAG_class_type
:
10601 case DW_TAG_interface_type
:
10602 case DW_TAG_structure_type
:
10603 case DW_TAG_union_type
:
10604 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
10605 structures or unions. These were of the form "._%d" in GCC 4.1,
10606 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
10607 and GCC 4.4. We work around this problem by ignoring these. */
10608 if (strncmp (DW_STRING (attr
), "._", 2) == 0
10609 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
10617 if (!DW_STRING_IS_CANONICAL (attr
))
10620 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
10621 &cu
->objfile
->objfile_obstack
);
10622 DW_STRING_IS_CANONICAL (attr
) = 1;
10624 return DW_STRING (attr
);
10627 /* Return the die that this die in an extension of, or NULL if there
10628 is none. *EXT_CU is the CU containing DIE on input, and the CU
10629 containing the return value on output. */
10631 static struct die_info
*
10632 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
10634 struct attribute
*attr
;
10636 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
10640 return follow_die_ref (die
, attr
, ext_cu
);
10643 /* Convert a DIE tag into its string name. */
10646 dwarf_tag_name (unsigned tag
)
10650 case DW_TAG_padding
:
10651 return "DW_TAG_padding";
10652 case DW_TAG_array_type
:
10653 return "DW_TAG_array_type";
10654 case DW_TAG_class_type
:
10655 return "DW_TAG_class_type";
10656 case DW_TAG_entry_point
:
10657 return "DW_TAG_entry_point";
10658 case DW_TAG_enumeration_type
:
10659 return "DW_TAG_enumeration_type";
10660 case DW_TAG_formal_parameter
:
10661 return "DW_TAG_formal_parameter";
10662 case DW_TAG_imported_declaration
:
10663 return "DW_TAG_imported_declaration";
10665 return "DW_TAG_label";
10666 case DW_TAG_lexical_block
:
10667 return "DW_TAG_lexical_block";
10668 case DW_TAG_member
:
10669 return "DW_TAG_member";
10670 case DW_TAG_pointer_type
:
10671 return "DW_TAG_pointer_type";
10672 case DW_TAG_reference_type
:
10673 return "DW_TAG_reference_type";
10674 case DW_TAG_compile_unit
:
10675 return "DW_TAG_compile_unit";
10676 case DW_TAG_string_type
:
10677 return "DW_TAG_string_type";
10678 case DW_TAG_structure_type
:
10679 return "DW_TAG_structure_type";
10680 case DW_TAG_subroutine_type
:
10681 return "DW_TAG_subroutine_type";
10682 case DW_TAG_typedef
:
10683 return "DW_TAG_typedef";
10684 case DW_TAG_union_type
:
10685 return "DW_TAG_union_type";
10686 case DW_TAG_unspecified_parameters
:
10687 return "DW_TAG_unspecified_parameters";
10688 case DW_TAG_variant
:
10689 return "DW_TAG_variant";
10690 case DW_TAG_common_block
:
10691 return "DW_TAG_common_block";
10692 case DW_TAG_common_inclusion
:
10693 return "DW_TAG_common_inclusion";
10694 case DW_TAG_inheritance
:
10695 return "DW_TAG_inheritance";
10696 case DW_TAG_inlined_subroutine
:
10697 return "DW_TAG_inlined_subroutine";
10698 case DW_TAG_module
:
10699 return "DW_TAG_module";
10700 case DW_TAG_ptr_to_member_type
:
10701 return "DW_TAG_ptr_to_member_type";
10702 case DW_TAG_set_type
:
10703 return "DW_TAG_set_type";
10704 case DW_TAG_subrange_type
:
10705 return "DW_TAG_subrange_type";
10706 case DW_TAG_with_stmt
:
10707 return "DW_TAG_with_stmt";
10708 case DW_TAG_access_declaration
:
10709 return "DW_TAG_access_declaration";
10710 case DW_TAG_base_type
:
10711 return "DW_TAG_base_type";
10712 case DW_TAG_catch_block
:
10713 return "DW_TAG_catch_block";
10714 case DW_TAG_const_type
:
10715 return "DW_TAG_const_type";
10716 case DW_TAG_constant
:
10717 return "DW_TAG_constant";
10718 case DW_TAG_enumerator
:
10719 return "DW_TAG_enumerator";
10720 case DW_TAG_file_type
:
10721 return "DW_TAG_file_type";
10722 case DW_TAG_friend
:
10723 return "DW_TAG_friend";
10724 case DW_TAG_namelist
:
10725 return "DW_TAG_namelist";
10726 case DW_TAG_namelist_item
:
10727 return "DW_TAG_namelist_item";
10728 case DW_TAG_packed_type
:
10729 return "DW_TAG_packed_type";
10730 case DW_TAG_subprogram
:
10731 return "DW_TAG_subprogram";
10732 case DW_TAG_template_type_param
:
10733 return "DW_TAG_template_type_param";
10734 case DW_TAG_template_value_param
:
10735 return "DW_TAG_template_value_param";
10736 case DW_TAG_thrown_type
:
10737 return "DW_TAG_thrown_type";
10738 case DW_TAG_try_block
:
10739 return "DW_TAG_try_block";
10740 case DW_TAG_variant_part
:
10741 return "DW_TAG_variant_part";
10742 case DW_TAG_variable
:
10743 return "DW_TAG_variable";
10744 case DW_TAG_volatile_type
:
10745 return "DW_TAG_volatile_type";
10746 case DW_TAG_dwarf_procedure
:
10747 return "DW_TAG_dwarf_procedure";
10748 case DW_TAG_restrict_type
:
10749 return "DW_TAG_restrict_type";
10750 case DW_TAG_interface_type
:
10751 return "DW_TAG_interface_type";
10752 case DW_TAG_namespace
:
10753 return "DW_TAG_namespace";
10754 case DW_TAG_imported_module
:
10755 return "DW_TAG_imported_module";
10756 case DW_TAG_unspecified_type
:
10757 return "DW_TAG_unspecified_type";
10758 case DW_TAG_partial_unit
:
10759 return "DW_TAG_partial_unit";
10760 case DW_TAG_imported_unit
:
10761 return "DW_TAG_imported_unit";
10762 case DW_TAG_condition
:
10763 return "DW_TAG_condition";
10764 case DW_TAG_shared_type
:
10765 return "DW_TAG_shared_type";
10766 case DW_TAG_type_unit
:
10767 return "DW_TAG_type_unit";
10768 case DW_TAG_MIPS_loop
:
10769 return "DW_TAG_MIPS_loop";
10770 case DW_TAG_HP_array_descriptor
:
10771 return "DW_TAG_HP_array_descriptor";
10772 case DW_TAG_format_label
:
10773 return "DW_TAG_format_label";
10774 case DW_TAG_function_template
:
10775 return "DW_TAG_function_template";
10776 case DW_TAG_class_template
:
10777 return "DW_TAG_class_template";
10778 case DW_TAG_GNU_BINCL
:
10779 return "DW_TAG_GNU_BINCL";
10780 case DW_TAG_GNU_EINCL
:
10781 return "DW_TAG_GNU_EINCL";
10782 case DW_TAG_upc_shared_type
:
10783 return "DW_TAG_upc_shared_type";
10784 case DW_TAG_upc_strict_type
:
10785 return "DW_TAG_upc_strict_type";
10786 case DW_TAG_upc_relaxed_type
:
10787 return "DW_TAG_upc_relaxed_type";
10788 case DW_TAG_PGI_kanji_type
:
10789 return "DW_TAG_PGI_kanji_type";
10790 case DW_TAG_PGI_interface_block
:
10791 return "DW_TAG_PGI_interface_block";
10793 return "DW_TAG_<unknown>";
10797 /* Convert a DWARF attribute code into its string name. */
10800 dwarf_attr_name (unsigned attr
)
10804 case DW_AT_sibling
:
10805 return "DW_AT_sibling";
10806 case DW_AT_location
:
10807 return "DW_AT_location";
10809 return "DW_AT_name";
10810 case DW_AT_ordering
:
10811 return "DW_AT_ordering";
10812 case DW_AT_subscr_data
:
10813 return "DW_AT_subscr_data";
10814 case DW_AT_byte_size
:
10815 return "DW_AT_byte_size";
10816 case DW_AT_bit_offset
:
10817 return "DW_AT_bit_offset";
10818 case DW_AT_bit_size
:
10819 return "DW_AT_bit_size";
10820 case DW_AT_element_list
:
10821 return "DW_AT_element_list";
10822 case DW_AT_stmt_list
:
10823 return "DW_AT_stmt_list";
10825 return "DW_AT_low_pc";
10826 case DW_AT_high_pc
:
10827 return "DW_AT_high_pc";
10828 case DW_AT_language
:
10829 return "DW_AT_language";
10831 return "DW_AT_member";
10833 return "DW_AT_discr";
10834 case DW_AT_discr_value
:
10835 return "DW_AT_discr_value";
10836 case DW_AT_visibility
:
10837 return "DW_AT_visibility";
10839 return "DW_AT_import";
10840 case DW_AT_string_length
:
10841 return "DW_AT_string_length";
10842 case DW_AT_common_reference
:
10843 return "DW_AT_common_reference";
10844 case DW_AT_comp_dir
:
10845 return "DW_AT_comp_dir";
10846 case DW_AT_const_value
:
10847 return "DW_AT_const_value";
10848 case DW_AT_containing_type
:
10849 return "DW_AT_containing_type";
10850 case DW_AT_default_value
:
10851 return "DW_AT_default_value";
10853 return "DW_AT_inline";
10854 case DW_AT_is_optional
:
10855 return "DW_AT_is_optional";
10856 case DW_AT_lower_bound
:
10857 return "DW_AT_lower_bound";
10858 case DW_AT_producer
:
10859 return "DW_AT_producer";
10860 case DW_AT_prototyped
:
10861 return "DW_AT_prototyped";
10862 case DW_AT_return_addr
:
10863 return "DW_AT_return_addr";
10864 case DW_AT_start_scope
:
10865 return "DW_AT_start_scope";
10866 case DW_AT_bit_stride
:
10867 return "DW_AT_bit_stride";
10868 case DW_AT_upper_bound
:
10869 return "DW_AT_upper_bound";
10870 case DW_AT_abstract_origin
:
10871 return "DW_AT_abstract_origin";
10872 case DW_AT_accessibility
:
10873 return "DW_AT_accessibility";
10874 case DW_AT_address_class
:
10875 return "DW_AT_address_class";
10876 case DW_AT_artificial
:
10877 return "DW_AT_artificial";
10878 case DW_AT_base_types
:
10879 return "DW_AT_base_types";
10880 case DW_AT_calling_convention
:
10881 return "DW_AT_calling_convention";
10883 return "DW_AT_count";
10884 case DW_AT_data_member_location
:
10885 return "DW_AT_data_member_location";
10886 case DW_AT_decl_column
:
10887 return "DW_AT_decl_column";
10888 case DW_AT_decl_file
:
10889 return "DW_AT_decl_file";
10890 case DW_AT_decl_line
:
10891 return "DW_AT_decl_line";
10892 case DW_AT_declaration
:
10893 return "DW_AT_declaration";
10894 case DW_AT_discr_list
:
10895 return "DW_AT_discr_list";
10896 case DW_AT_encoding
:
10897 return "DW_AT_encoding";
10898 case DW_AT_external
:
10899 return "DW_AT_external";
10900 case DW_AT_frame_base
:
10901 return "DW_AT_frame_base";
10903 return "DW_AT_friend";
10904 case DW_AT_identifier_case
:
10905 return "DW_AT_identifier_case";
10906 case DW_AT_macro_info
:
10907 return "DW_AT_macro_info";
10908 case DW_AT_namelist_items
:
10909 return "DW_AT_namelist_items";
10910 case DW_AT_priority
:
10911 return "DW_AT_priority";
10912 case DW_AT_segment
:
10913 return "DW_AT_segment";
10914 case DW_AT_specification
:
10915 return "DW_AT_specification";
10916 case DW_AT_static_link
:
10917 return "DW_AT_static_link";
10919 return "DW_AT_type";
10920 case DW_AT_use_location
:
10921 return "DW_AT_use_location";
10922 case DW_AT_variable_parameter
:
10923 return "DW_AT_variable_parameter";
10924 case DW_AT_virtuality
:
10925 return "DW_AT_virtuality";
10926 case DW_AT_vtable_elem_location
:
10927 return "DW_AT_vtable_elem_location";
10928 /* DWARF 3 values. */
10929 case DW_AT_allocated
:
10930 return "DW_AT_allocated";
10931 case DW_AT_associated
:
10932 return "DW_AT_associated";
10933 case DW_AT_data_location
:
10934 return "DW_AT_data_location";
10935 case DW_AT_byte_stride
:
10936 return "DW_AT_byte_stride";
10937 case DW_AT_entry_pc
:
10938 return "DW_AT_entry_pc";
10939 case DW_AT_use_UTF8
:
10940 return "DW_AT_use_UTF8";
10941 case DW_AT_extension
:
10942 return "DW_AT_extension";
10944 return "DW_AT_ranges";
10945 case DW_AT_trampoline
:
10946 return "DW_AT_trampoline";
10947 case DW_AT_call_column
:
10948 return "DW_AT_call_column";
10949 case DW_AT_call_file
:
10950 return "DW_AT_call_file";
10951 case DW_AT_call_line
:
10952 return "DW_AT_call_line";
10953 case DW_AT_description
:
10954 return "DW_AT_description";
10955 case DW_AT_binary_scale
:
10956 return "DW_AT_binary_scale";
10957 case DW_AT_decimal_scale
:
10958 return "DW_AT_decimal_scale";
10960 return "DW_AT_small";
10961 case DW_AT_decimal_sign
:
10962 return "DW_AT_decimal_sign";
10963 case DW_AT_digit_count
:
10964 return "DW_AT_digit_count";
10965 case DW_AT_picture_string
:
10966 return "DW_AT_picture_string";
10967 case DW_AT_mutable
:
10968 return "DW_AT_mutable";
10969 case DW_AT_threads_scaled
:
10970 return "DW_AT_threads_scaled";
10971 case DW_AT_explicit
:
10972 return "DW_AT_explicit";
10973 case DW_AT_object_pointer
:
10974 return "DW_AT_object_pointer";
10975 case DW_AT_endianity
:
10976 return "DW_AT_endianity";
10977 case DW_AT_elemental
:
10978 return "DW_AT_elemental";
10980 return "DW_AT_pure";
10981 case DW_AT_recursive
:
10982 return "DW_AT_recursive";
10983 /* DWARF 4 values. */
10984 case DW_AT_signature
:
10985 return "DW_AT_signature";
10986 case DW_AT_linkage_name
:
10987 return "DW_AT_linkage_name";
10988 /* SGI/MIPS extensions. */
10989 #ifdef MIPS /* collides with DW_AT_HP_block_index */
10990 case DW_AT_MIPS_fde
:
10991 return "DW_AT_MIPS_fde";
10993 case DW_AT_MIPS_loop_begin
:
10994 return "DW_AT_MIPS_loop_begin";
10995 case DW_AT_MIPS_tail_loop_begin
:
10996 return "DW_AT_MIPS_tail_loop_begin";
10997 case DW_AT_MIPS_epilog_begin
:
10998 return "DW_AT_MIPS_epilog_begin";
10999 case DW_AT_MIPS_loop_unroll_factor
:
11000 return "DW_AT_MIPS_loop_unroll_factor";
11001 case DW_AT_MIPS_software_pipeline_depth
:
11002 return "DW_AT_MIPS_software_pipeline_depth";
11003 case DW_AT_MIPS_linkage_name
:
11004 return "DW_AT_MIPS_linkage_name";
11005 case DW_AT_MIPS_stride
:
11006 return "DW_AT_MIPS_stride";
11007 case DW_AT_MIPS_abstract_name
:
11008 return "DW_AT_MIPS_abstract_name";
11009 case DW_AT_MIPS_clone_origin
:
11010 return "DW_AT_MIPS_clone_origin";
11011 case DW_AT_MIPS_has_inlines
:
11012 return "DW_AT_MIPS_has_inlines";
11013 /* HP extensions. */
11014 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
11015 case DW_AT_HP_block_index
:
11016 return "DW_AT_HP_block_index";
11018 case DW_AT_HP_unmodifiable
:
11019 return "DW_AT_HP_unmodifiable";
11020 case DW_AT_HP_actuals_stmt_list
:
11021 return "DW_AT_HP_actuals_stmt_list";
11022 case DW_AT_HP_proc_per_section
:
11023 return "DW_AT_HP_proc_per_section";
11024 case DW_AT_HP_raw_data_ptr
:
11025 return "DW_AT_HP_raw_data_ptr";
11026 case DW_AT_HP_pass_by_reference
:
11027 return "DW_AT_HP_pass_by_reference";
11028 case DW_AT_HP_opt_level
:
11029 return "DW_AT_HP_opt_level";
11030 case DW_AT_HP_prof_version_id
:
11031 return "DW_AT_HP_prof_version_id";
11032 case DW_AT_HP_opt_flags
:
11033 return "DW_AT_HP_opt_flags";
11034 case DW_AT_HP_cold_region_low_pc
:
11035 return "DW_AT_HP_cold_region_low_pc";
11036 case DW_AT_HP_cold_region_high_pc
:
11037 return "DW_AT_HP_cold_region_high_pc";
11038 case DW_AT_HP_all_variables_modifiable
:
11039 return "DW_AT_HP_all_variables_modifiable";
11040 case DW_AT_HP_linkage_name
:
11041 return "DW_AT_HP_linkage_name";
11042 case DW_AT_HP_prof_flags
:
11043 return "DW_AT_HP_prof_flags";
11044 /* GNU extensions. */
11045 case DW_AT_sf_names
:
11046 return "DW_AT_sf_names";
11047 case DW_AT_src_info
:
11048 return "DW_AT_src_info";
11049 case DW_AT_mac_info
:
11050 return "DW_AT_mac_info";
11051 case DW_AT_src_coords
:
11052 return "DW_AT_src_coords";
11053 case DW_AT_body_begin
:
11054 return "DW_AT_body_begin";
11055 case DW_AT_body_end
:
11056 return "DW_AT_body_end";
11057 case DW_AT_GNU_vector
:
11058 return "DW_AT_GNU_vector";
11059 /* VMS extensions. */
11060 case DW_AT_VMS_rtnbeg_pd_address
:
11061 return "DW_AT_VMS_rtnbeg_pd_address";
11062 /* UPC extension. */
11063 case DW_AT_upc_threads_scaled
:
11064 return "DW_AT_upc_threads_scaled";
11065 /* PGI (STMicroelectronics) extensions. */
11066 case DW_AT_PGI_lbase
:
11067 return "DW_AT_PGI_lbase";
11068 case DW_AT_PGI_soffset
:
11069 return "DW_AT_PGI_soffset";
11070 case DW_AT_PGI_lstride
:
11071 return "DW_AT_PGI_lstride";
11073 return "DW_AT_<unknown>";
11077 /* Convert a DWARF value form code into its string name. */
11080 dwarf_form_name (unsigned form
)
11085 return "DW_FORM_addr";
11086 case DW_FORM_block2
:
11087 return "DW_FORM_block2";
11088 case DW_FORM_block4
:
11089 return "DW_FORM_block4";
11090 case DW_FORM_data2
:
11091 return "DW_FORM_data2";
11092 case DW_FORM_data4
:
11093 return "DW_FORM_data4";
11094 case DW_FORM_data8
:
11095 return "DW_FORM_data8";
11096 case DW_FORM_string
:
11097 return "DW_FORM_string";
11098 case DW_FORM_block
:
11099 return "DW_FORM_block";
11100 case DW_FORM_block1
:
11101 return "DW_FORM_block1";
11102 case DW_FORM_data1
:
11103 return "DW_FORM_data1";
11105 return "DW_FORM_flag";
11106 case DW_FORM_sdata
:
11107 return "DW_FORM_sdata";
11109 return "DW_FORM_strp";
11110 case DW_FORM_udata
:
11111 return "DW_FORM_udata";
11112 case DW_FORM_ref_addr
:
11113 return "DW_FORM_ref_addr";
11115 return "DW_FORM_ref1";
11117 return "DW_FORM_ref2";
11119 return "DW_FORM_ref4";
11121 return "DW_FORM_ref8";
11122 case DW_FORM_ref_udata
:
11123 return "DW_FORM_ref_udata";
11124 case DW_FORM_indirect
:
11125 return "DW_FORM_indirect";
11126 case DW_FORM_sec_offset
:
11127 return "DW_FORM_sec_offset";
11128 case DW_FORM_exprloc
:
11129 return "DW_FORM_exprloc";
11130 case DW_FORM_flag_present
:
11131 return "DW_FORM_flag_present";
11133 return "DW_FORM_sig8";
11135 return "DW_FORM_<unknown>";
11139 /* Convert a DWARF stack opcode into its string name. */
11142 dwarf_stack_op_name (unsigned op
, int def
)
11147 return "DW_OP_addr";
11149 return "DW_OP_deref";
11150 case DW_OP_const1u
:
11151 return "DW_OP_const1u";
11152 case DW_OP_const1s
:
11153 return "DW_OP_const1s";
11154 case DW_OP_const2u
:
11155 return "DW_OP_const2u";
11156 case DW_OP_const2s
:
11157 return "DW_OP_const2s";
11158 case DW_OP_const4u
:
11159 return "DW_OP_const4u";
11160 case DW_OP_const4s
:
11161 return "DW_OP_const4s";
11162 case DW_OP_const8u
:
11163 return "DW_OP_const8u";
11164 case DW_OP_const8s
:
11165 return "DW_OP_const8s";
11167 return "DW_OP_constu";
11169 return "DW_OP_consts";
11171 return "DW_OP_dup";
11173 return "DW_OP_drop";
11175 return "DW_OP_over";
11177 return "DW_OP_pick";
11179 return "DW_OP_swap";
11181 return "DW_OP_rot";
11183 return "DW_OP_xderef";
11185 return "DW_OP_abs";
11187 return "DW_OP_and";
11189 return "DW_OP_div";
11191 return "DW_OP_minus";
11193 return "DW_OP_mod";
11195 return "DW_OP_mul";
11197 return "DW_OP_neg";
11199 return "DW_OP_not";
11203 return "DW_OP_plus";
11204 case DW_OP_plus_uconst
:
11205 return "DW_OP_plus_uconst";
11207 return "DW_OP_shl";
11209 return "DW_OP_shr";
11211 return "DW_OP_shra";
11213 return "DW_OP_xor";
11215 return "DW_OP_bra";
11229 return "DW_OP_skip";
11231 return "DW_OP_lit0";
11233 return "DW_OP_lit1";
11235 return "DW_OP_lit2";
11237 return "DW_OP_lit3";
11239 return "DW_OP_lit4";
11241 return "DW_OP_lit5";
11243 return "DW_OP_lit6";
11245 return "DW_OP_lit7";
11247 return "DW_OP_lit8";
11249 return "DW_OP_lit9";
11251 return "DW_OP_lit10";
11253 return "DW_OP_lit11";
11255 return "DW_OP_lit12";
11257 return "DW_OP_lit13";
11259 return "DW_OP_lit14";
11261 return "DW_OP_lit15";
11263 return "DW_OP_lit16";
11265 return "DW_OP_lit17";
11267 return "DW_OP_lit18";
11269 return "DW_OP_lit19";
11271 return "DW_OP_lit20";
11273 return "DW_OP_lit21";
11275 return "DW_OP_lit22";
11277 return "DW_OP_lit23";
11279 return "DW_OP_lit24";
11281 return "DW_OP_lit25";
11283 return "DW_OP_lit26";
11285 return "DW_OP_lit27";
11287 return "DW_OP_lit28";
11289 return "DW_OP_lit29";
11291 return "DW_OP_lit30";
11293 return "DW_OP_lit31";
11295 return "DW_OP_reg0";
11297 return "DW_OP_reg1";
11299 return "DW_OP_reg2";
11301 return "DW_OP_reg3";
11303 return "DW_OP_reg4";
11305 return "DW_OP_reg5";
11307 return "DW_OP_reg6";
11309 return "DW_OP_reg7";
11311 return "DW_OP_reg8";
11313 return "DW_OP_reg9";
11315 return "DW_OP_reg10";
11317 return "DW_OP_reg11";
11319 return "DW_OP_reg12";
11321 return "DW_OP_reg13";
11323 return "DW_OP_reg14";
11325 return "DW_OP_reg15";
11327 return "DW_OP_reg16";
11329 return "DW_OP_reg17";
11331 return "DW_OP_reg18";
11333 return "DW_OP_reg19";
11335 return "DW_OP_reg20";
11337 return "DW_OP_reg21";
11339 return "DW_OP_reg22";
11341 return "DW_OP_reg23";
11343 return "DW_OP_reg24";
11345 return "DW_OP_reg25";
11347 return "DW_OP_reg26";
11349 return "DW_OP_reg27";
11351 return "DW_OP_reg28";
11353 return "DW_OP_reg29";
11355 return "DW_OP_reg30";
11357 return "DW_OP_reg31";
11359 return "DW_OP_breg0";
11361 return "DW_OP_breg1";
11363 return "DW_OP_breg2";
11365 return "DW_OP_breg3";
11367 return "DW_OP_breg4";
11369 return "DW_OP_breg5";
11371 return "DW_OP_breg6";
11373 return "DW_OP_breg7";
11375 return "DW_OP_breg8";
11377 return "DW_OP_breg9";
11379 return "DW_OP_breg10";
11381 return "DW_OP_breg11";
11383 return "DW_OP_breg12";
11385 return "DW_OP_breg13";
11387 return "DW_OP_breg14";
11389 return "DW_OP_breg15";
11391 return "DW_OP_breg16";
11393 return "DW_OP_breg17";
11395 return "DW_OP_breg18";
11397 return "DW_OP_breg19";
11399 return "DW_OP_breg20";
11401 return "DW_OP_breg21";
11403 return "DW_OP_breg22";
11405 return "DW_OP_breg23";
11407 return "DW_OP_breg24";
11409 return "DW_OP_breg25";
11411 return "DW_OP_breg26";
11413 return "DW_OP_breg27";
11415 return "DW_OP_breg28";
11417 return "DW_OP_breg29";
11419 return "DW_OP_breg30";
11421 return "DW_OP_breg31";
11423 return "DW_OP_regx";
11425 return "DW_OP_fbreg";
11427 return "DW_OP_bregx";
11429 return "DW_OP_piece";
11430 case DW_OP_deref_size
:
11431 return "DW_OP_deref_size";
11432 case DW_OP_xderef_size
:
11433 return "DW_OP_xderef_size";
11435 return "DW_OP_nop";
11436 /* DWARF 3 extensions. */
11437 case DW_OP_push_object_address
:
11438 return "DW_OP_push_object_address";
11440 return "DW_OP_call2";
11442 return "DW_OP_call4";
11443 case DW_OP_call_ref
:
11444 return "DW_OP_call_ref";
11445 case DW_OP_form_tls_address
:
11446 return "DW_OP_form_tls_address";
11447 case DW_OP_call_frame_cfa
:
11448 return "DW_OP_call_frame_cfa";
11449 case DW_OP_bit_piece
:
11450 return "DW_OP_bit_piece";
11451 /* DWARF 4 extensions. */
11452 case DW_OP_implicit_value
:
11453 return "DW_OP_implicit_value";
11454 case DW_OP_stack_value
:
11455 return "DW_OP_stack_value";
11456 /* GNU extensions. */
11457 case DW_OP_GNU_push_tls_address
:
11458 return "DW_OP_GNU_push_tls_address";
11459 case DW_OP_GNU_uninit
:
11460 return "DW_OP_GNU_uninit";
11462 return def
? "OP_<unknown>" : NULL
;
11467 dwarf_bool_name (unsigned mybool
)
11475 /* Convert a DWARF type code into its string name. */
11478 dwarf_type_encoding_name (unsigned enc
)
11483 return "DW_ATE_void";
11484 case DW_ATE_address
:
11485 return "DW_ATE_address";
11486 case DW_ATE_boolean
:
11487 return "DW_ATE_boolean";
11488 case DW_ATE_complex_float
:
11489 return "DW_ATE_complex_float";
11491 return "DW_ATE_float";
11492 case DW_ATE_signed
:
11493 return "DW_ATE_signed";
11494 case DW_ATE_signed_char
:
11495 return "DW_ATE_signed_char";
11496 case DW_ATE_unsigned
:
11497 return "DW_ATE_unsigned";
11498 case DW_ATE_unsigned_char
:
11499 return "DW_ATE_unsigned_char";
11501 case DW_ATE_imaginary_float
:
11502 return "DW_ATE_imaginary_float";
11503 case DW_ATE_packed_decimal
:
11504 return "DW_ATE_packed_decimal";
11505 case DW_ATE_numeric_string
:
11506 return "DW_ATE_numeric_string";
11507 case DW_ATE_edited
:
11508 return "DW_ATE_edited";
11509 case DW_ATE_signed_fixed
:
11510 return "DW_ATE_signed_fixed";
11511 case DW_ATE_unsigned_fixed
:
11512 return "DW_ATE_unsigned_fixed";
11513 case DW_ATE_decimal_float
:
11514 return "DW_ATE_decimal_float";
11517 return "DW_ATE_UTF";
11518 /* HP extensions. */
11519 case DW_ATE_HP_float80
:
11520 return "DW_ATE_HP_float80";
11521 case DW_ATE_HP_complex_float80
:
11522 return "DW_ATE_HP_complex_float80";
11523 case DW_ATE_HP_float128
:
11524 return "DW_ATE_HP_float128";
11525 case DW_ATE_HP_complex_float128
:
11526 return "DW_ATE_HP_complex_float128";
11527 case DW_ATE_HP_floathpintel
:
11528 return "DW_ATE_HP_floathpintel";
11529 case DW_ATE_HP_imaginary_float80
:
11530 return "DW_ATE_HP_imaginary_float80";
11531 case DW_ATE_HP_imaginary_float128
:
11532 return "DW_ATE_HP_imaginary_float128";
11534 return "DW_ATE_<unknown>";
11538 /* Convert a DWARF call frame info operation to its string name. */
11542 dwarf_cfi_name (unsigned cfi_opc
)
11546 case DW_CFA_advance_loc
:
11547 return "DW_CFA_advance_loc";
11548 case DW_CFA_offset
:
11549 return "DW_CFA_offset";
11550 case DW_CFA_restore
:
11551 return "DW_CFA_restore";
11553 return "DW_CFA_nop";
11554 case DW_CFA_set_loc
:
11555 return "DW_CFA_set_loc";
11556 case DW_CFA_advance_loc1
:
11557 return "DW_CFA_advance_loc1";
11558 case DW_CFA_advance_loc2
:
11559 return "DW_CFA_advance_loc2";
11560 case DW_CFA_advance_loc4
:
11561 return "DW_CFA_advance_loc4";
11562 case DW_CFA_offset_extended
:
11563 return "DW_CFA_offset_extended";
11564 case DW_CFA_restore_extended
:
11565 return "DW_CFA_restore_extended";
11566 case DW_CFA_undefined
:
11567 return "DW_CFA_undefined";
11568 case DW_CFA_same_value
:
11569 return "DW_CFA_same_value";
11570 case DW_CFA_register
:
11571 return "DW_CFA_register";
11572 case DW_CFA_remember_state
:
11573 return "DW_CFA_remember_state";
11574 case DW_CFA_restore_state
:
11575 return "DW_CFA_restore_state";
11576 case DW_CFA_def_cfa
:
11577 return "DW_CFA_def_cfa";
11578 case DW_CFA_def_cfa_register
:
11579 return "DW_CFA_def_cfa_register";
11580 case DW_CFA_def_cfa_offset
:
11581 return "DW_CFA_def_cfa_offset";
11583 case DW_CFA_def_cfa_expression
:
11584 return "DW_CFA_def_cfa_expression";
11585 case DW_CFA_expression
:
11586 return "DW_CFA_expression";
11587 case DW_CFA_offset_extended_sf
:
11588 return "DW_CFA_offset_extended_sf";
11589 case DW_CFA_def_cfa_sf
:
11590 return "DW_CFA_def_cfa_sf";
11591 case DW_CFA_def_cfa_offset_sf
:
11592 return "DW_CFA_def_cfa_offset_sf";
11593 case DW_CFA_val_offset
:
11594 return "DW_CFA_val_offset";
11595 case DW_CFA_val_offset_sf
:
11596 return "DW_CFA_val_offset_sf";
11597 case DW_CFA_val_expression
:
11598 return "DW_CFA_val_expression";
11599 /* SGI/MIPS specific. */
11600 case DW_CFA_MIPS_advance_loc8
:
11601 return "DW_CFA_MIPS_advance_loc8";
11602 /* GNU extensions. */
11603 case DW_CFA_GNU_window_save
:
11604 return "DW_CFA_GNU_window_save";
11605 case DW_CFA_GNU_args_size
:
11606 return "DW_CFA_GNU_args_size";
11607 case DW_CFA_GNU_negative_offset_extended
:
11608 return "DW_CFA_GNU_negative_offset_extended";
11610 return "DW_CFA_<unknown>";
11616 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
11620 print_spaces (indent
, f
);
11621 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
11622 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
11624 if (die
->parent
!= NULL
)
11626 print_spaces (indent
, f
);
11627 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
11628 die
->parent
->offset
);
11631 print_spaces (indent
, f
);
11632 fprintf_unfiltered (f
, " has children: %s\n",
11633 dwarf_bool_name (die
->child
!= NULL
));
11635 print_spaces (indent
, f
);
11636 fprintf_unfiltered (f
, " attributes:\n");
11638 for (i
= 0; i
< die
->num_attrs
; ++i
)
11640 print_spaces (indent
, f
);
11641 fprintf_unfiltered (f
, " %s (%s) ",
11642 dwarf_attr_name (die
->attrs
[i
].name
),
11643 dwarf_form_name (die
->attrs
[i
].form
));
11645 switch (die
->attrs
[i
].form
)
11647 case DW_FORM_ref_addr
:
11649 fprintf_unfiltered (f
, "address: ");
11650 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
11652 case DW_FORM_block2
:
11653 case DW_FORM_block4
:
11654 case DW_FORM_block
:
11655 case DW_FORM_block1
:
11656 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
11658 case DW_FORM_exprloc
:
11659 fprintf_unfiltered (f
, "expression: size %u",
11660 DW_BLOCK (&die
->attrs
[i
])->size
);
11665 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
11666 (long) (DW_ADDR (&die
->attrs
[i
])));
11668 case DW_FORM_data1
:
11669 case DW_FORM_data2
:
11670 case DW_FORM_data4
:
11671 case DW_FORM_data8
:
11672 case DW_FORM_udata
:
11673 case DW_FORM_sdata
:
11674 fprintf_unfiltered (f
, "constant: %s",
11675 pulongest (DW_UNSND (&die
->attrs
[i
])));
11677 case DW_FORM_sec_offset
:
11678 fprintf_unfiltered (f
, "section offset: %s",
11679 pulongest (DW_UNSND (&die
->attrs
[i
])));
11682 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
11683 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
11684 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
11686 fprintf_unfiltered (f
, "signatured type, offset: unknown");
11688 case DW_FORM_string
:
11690 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
11691 DW_STRING (&die
->attrs
[i
])
11692 ? DW_STRING (&die
->attrs
[i
]) : "",
11693 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
11696 if (DW_UNSND (&die
->attrs
[i
]))
11697 fprintf_unfiltered (f
, "flag: TRUE");
11699 fprintf_unfiltered (f
, "flag: FALSE");
11701 case DW_FORM_flag_present
:
11702 fprintf_unfiltered (f
, "flag: TRUE");
11704 case DW_FORM_indirect
:
11705 /* the reader will have reduced the indirect form to
11706 the "base form" so this form should not occur */
11707 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
11710 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
11711 die
->attrs
[i
].form
);
11714 fprintf_unfiltered (f
, "\n");
11719 dump_die_for_error (struct die_info
*die
)
11721 dump_die_shallow (gdb_stderr
, 0, die
);
11725 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
11727 int indent
= level
* 4;
11729 gdb_assert (die
!= NULL
);
11731 if (level
>= max_level
)
11734 dump_die_shallow (f
, indent
, die
);
11736 if (die
->child
!= NULL
)
11738 print_spaces (indent
, f
);
11739 fprintf_unfiltered (f
, " Children:");
11740 if (level
+ 1 < max_level
)
11742 fprintf_unfiltered (f
, "\n");
11743 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
11747 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
11751 if (die
->sibling
!= NULL
&& level
> 0)
11753 dump_die_1 (f
, level
, max_level
, die
->sibling
);
11757 /* This is called from the pdie macro in gdbinit.in.
11758 It's not static so gcc will keep a copy callable from gdb. */
11761 dump_die (struct die_info
*die
, int max_level
)
11763 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
11767 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
11771 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
11777 is_ref_attr (struct attribute
*attr
)
11779 switch (attr
->form
)
11781 case DW_FORM_ref_addr
:
11786 case DW_FORM_ref_udata
:
11793 static unsigned int
11794 dwarf2_get_ref_die_offset (struct attribute
*attr
)
11796 if (is_ref_attr (attr
))
11797 return DW_ADDR (attr
);
11799 complaint (&symfile_complaints
,
11800 _("unsupported die ref attribute form: '%s'"),
11801 dwarf_form_name (attr
->form
));
11805 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
11806 * the value held by the attribute is not constant. */
11809 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
11811 if (attr
->form
== DW_FORM_sdata
)
11812 return DW_SND (attr
);
11813 else if (attr
->form
== DW_FORM_udata
11814 || attr
->form
== DW_FORM_data1
11815 || attr
->form
== DW_FORM_data2
11816 || attr
->form
== DW_FORM_data4
11817 || attr
->form
== DW_FORM_data8
)
11818 return DW_UNSND (attr
);
11821 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
11822 dwarf_form_name (attr
->form
));
11823 return default_value
;
11827 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
11828 unit and add it to our queue.
11829 The result is non-zero if PER_CU was queued, otherwise the result is zero
11830 meaning either PER_CU is already queued or it is already loaded. */
11833 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
11834 struct dwarf2_per_cu_data
*per_cu
)
11836 /* Mark the dependence relation so that we don't flush PER_CU
11838 dwarf2_add_dependence (this_cu
, per_cu
);
11840 /* If it's already on the queue, we have nothing to do. */
11841 if (per_cu
->queued
)
11844 /* If the compilation unit is already loaded, just mark it as
11846 if (per_cu
->cu
!= NULL
)
11848 per_cu
->cu
->last_used
= 0;
11852 /* Add it to the queue. */
11853 queue_comp_unit (per_cu
, this_cu
->objfile
);
11858 /* Follow reference or signature attribute ATTR of SRC_DIE.
11859 On entry *REF_CU is the CU of SRC_DIE.
11860 On exit *REF_CU is the CU of the result. */
11862 static struct die_info
*
11863 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
11864 struct dwarf2_cu
**ref_cu
)
11866 struct die_info
*die
;
11868 if (is_ref_attr (attr
))
11869 die
= follow_die_ref (src_die
, attr
, ref_cu
);
11870 else if (attr
->form
== DW_FORM_sig8
)
11871 die
= follow_die_sig (src_die
, attr
, ref_cu
);
11874 dump_die_for_error (src_die
);
11875 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
11876 (*ref_cu
)->objfile
->name
);
11882 /* Follow reference OFFSET.
11883 On entry *REF_CU is the CU of source DIE referencing OFFSET.
11884 On exit *REF_CU is the CU of the result. */
11886 static struct die_info
*
11887 follow_die_offset (unsigned int offset
, struct dwarf2_cu
**ref_cu
)
11889 struct die_info temp_die
;
11890 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
11892 gdb_assert (cu
->per_cu
!= NULL
);
11894 if (cu
->per_cu
->from_debug_types
)
11896 /* .debug_types CUs cannot reference anything outside their CU.
11897 If they need to, they have to reference a signatured type via
11899 if (! offset_in_cu_p (&cu
->header
, offset
))
11903 else if (! offset_in_cu_p (&cu
->header
, offset
))
11905 struct dwarf2_per_cu_data
*per_cu
;
11907 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
11909 /* If necessary, add it to the queue and load its DIEs. */
11910 if (maybe_queue_comp_unit (cu
, per_cu
))
11911 load_full_comp_unit (per_cu
, cu
->objfile
);
11913 target_cu
= per_cu
->cu
;
11918 *ref_cu
= target_cu
;
11919 temp_die
.offset
= offset
;
11920 return htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
11923 /* Follow reference attribute ATTR of SRC_DIE.
11924 On entry *REF_CU is the CU of SRC_DIE.
11925 On exit *REF_CU is the CU of the result. */
11927 static struct die_info
*
11928 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
11929 struct dwarf2_cu
**ref_cu
)
11931 unsigned int offset
= dwarf2_get_ref_die_offset (attr
);
11932 struct dwarf2_cu
*cu
= *ref_cu
;
11933 struct die_info
*die
;
11935 die
= follow_die_offset (offset
, ref_cu
);
11937 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
11938 "at 0x%x [in module %s]"),
11939 offset
, src_die
->offset
, cu
->objfile
->name
);
11944 /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned
11945 value is intended for DW_OP_call*. */
11947 struct dwarf2_locexpr_baton
11948 dwarf2_fetch_die_location_block (unsigned int offset
,
11949 struct dwarf2_per_cu_data
*per_cu
)
11951 struct dwarf2_cu
*cu
= per_cu
->cu
;
11952 struct die_info
*die
;
11953 struct attribute
*attr
;
11954 struct dwarf2_locexpr_baton retval
;
11956 die
= follow_die_offset (offset
, &cu
);
11958 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"),
11959 offset
, per_cu
->cu
->objfile
->name
);
11961 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
11964 /* DWARF: "If there is no such attribute, then there is no effect.". */
11966 retval
.data
= NULL
;
11971 if (!attr_form_is_block (attr
))
11972 error (_("Dwarf Error: DIE at 0x%x referenced in module %s "
11973 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
11974 offset
, per_cu
->cu
->objfile
->name
);
11976 retval
.data
= DW_BLOCK (attr
)->data
;
11977 retval
.size
= DW_BLOCK (attr
)->size
;
11979 retval
.per_cu
= cu
->per_cu
;
11983 /* Follow the signature attribute ATTR in SRC_DIE.
11984 On entry *REF_CU is the CU of SRC_DIE.
11985 On exit *REF_CU is the CU of the result. */
11987 static struct die_info
*
11988 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
11989 struct dwarf2_cu
**ref_cu
)
11991 struct objfile
*objfile
= (*ref_cu
)->objfile
;
11992 struct die_info temp_die
;
11993 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
11994 struct dwarf2_cu
*sig_cu
;
11995 struct die_info
*die
;
11997 /* sig_type will be NULL if the signatured type is missing from
11999 if (sig_type
== NULL
)
12000 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
12001 "at 0x%x [in module %s]"),
12002 src_die
->offset
, objfile
->name
);
12004 /* If necessary, add it to the queue and load its DIEs. */
12006 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
12007 read_signatured_type (objfile
, sig_type
);
12009 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
12011 sig_cu
= sig_type
->per_cu
.cu
;
12012 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
12013 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
12020 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
12021 "at 0x%x [in module %s]"),
12022 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
12025 /* Given an offset of a signatured type, return its signatured_type. */
12027 static struct signatured_type
*
12028 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
12030 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
12031 unsigned int length
, initial_length_size
;
12032 unsigned int sig_offset
;
12033 struct signatured_type find_entry
, *type_sig
;
12035 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
12036 sig_offset
= (initial_length_size
12038 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
12039 + 1 /*address_size*/);
12040 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
12041 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
12043 /* This is only used to lookup previously recorded types.
12044 If we didn't find it, it's our bug. */
12045 gdb_assert (type_sig
!= NULL
);
12046 gdb_assert (offset
== type_sig
->offset
);
12051 /* Read in signatured type at OFFSET and build its CU and die(s). */
12054 read_signatured_type_at_offset (struct objfile
*objfile
,
12055 unsigned int offset
)
12057 struct signatured_type
*type_sig
;
12059 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
12061 /* We have the section offset, but we need the signature to do the
12062 hash table lookup. */
12063 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
12065 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12067 read_signatured_type (objfile
, type_sig
);
12069 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
12072 /* Read in a signatured type and build its CU and DIEs. */
12075 read_signatured_type (struct objfile
*objfile
,
12076 struct signatured_type
*type_sig
)
12078 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
12079 struct die_reader_specs reader_specs
;
12080 struct dwarf2_cu
*cu
;
12081 ULONGEST signature
;
12082 struct cleanup
*back_to
, *free_cu_cleanup
;
12083 struct attribute
*attr
;
12085 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
12087 cu
= xmalloc (sizeof (struct dwarf2_cu
));
12088 memset (cu
, 0, sizeof (struct dwarf2_cu
));
12089 obstack_init (&cu
->comp_unit_obstack
);
12090 cu
->objfile
= objfile
;
12091 type_sig
->per_cu
.cu
= cu
;
12092 cu
->per_cu
= &type_sig
->per_cu
;
12094 /* If an error occurs while loading, release our storage. */
12095 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
12097 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
12098 types_ptr
, objfile
->obfd
);
12099 gdb_assert (signature
== type_sig
->signature
);
12102 = htab_create_alloc_ex (cu
->header
.length
/ 12,
12106 &cu
->comp_unit_obstack
,
12107 hashtab_obstack_allocate
,
12108 dummy_obstack_deallocate
);
12110 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
12111 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
12113 init_cu_die_reader (&reader_specs
, cu
);
12115 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
12118 /* We try not to read any attributes in this function, because not
12119 all objfiles needed for references have been loaded yet, and symbol
12120 table processing isn't initialized. But we have to set the CU language,
12121 or we won't be able to build types correctly. */
12122 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
12124 set_cu_language (DW_UNSND (attr
), cu
);
12126 set_cu_language (language_minimal
, cu
);
12128 do_cleanups (back_to
);
12130 /* We've successfully allocated this compilation unit. Let our caller
12131 clean it up when finished with it. */
12132 discard_cleanups (free_cu_cleanup
);
12134 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
12135 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
12138 /* Decode simple location descriptions.
12139 Given a pointer to a dwarf block that defines a location, compute
12140 the location and return the value.
12142 NOTE drow/2003-11-18: This function is called in two situations
12143 now: for the address of static or global variables (partial symbols
12144 only) and for offsets into structures which are expected to be
12145 (more or less) constant. The partial symbol case should go away,
12146 and only the constant case should remain. That will let this
12147 function complain more accurately. A few special modes are allowed
12148 without complaint for global variables (for instance, global
12149 register values and thread-local values).
12151 A location description containing no operations indicates that the
12152 object is optimized out. The return value is 0 for that case.
12153 FIXME drow/2003-11-16: No callers check for this case any more; soon all
12154 callers will only want a very basic result and this can become a
12157 Note that stack[0] is unused except as a default error return.
12158 Note that stack overflow is not yet handled. */
12161 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
12163 struct objfile
*objfile
= cu
->objfile
;
12165 int size
= blk
->size
;
12166 gdb_byte
*data
= blk
->data
;
12167 CORE_ADDR stack
[64];
12169 unsigned int bytes_read
, unsnd
;
12213 stack
[++stacki
] = op
- DW_OP_lit0
;
12248 stack
[++stacki
] = op
- DW_OP_reg0
;
12250 dwarf2_complex_location_expr_complaint ();
12254 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
12256 stack
[++stacki
] = unsnd
;
12258 dwarf2_complex_location_expr_complaint ();
12262 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
12267 case DW_OP_const1u
:
12268 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
12272 case DW_OP_const1s
:
12273 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
12277 case DW_OP_const2u
:
12278 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
12282 case DW_OP_const2s
:
12283 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
12287 case DW_OP_const4u
:
12288 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
12292 case DW_OP_const4s
:
12293 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
12298 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
12304 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
12309 stack
[stacki
+ 1] = stack
[stacki
];
12314 stack
[stacki
- 1] += stack
[stacki
];
12318 case DW_OP_plus_uconst
:
12319 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
12324 stack
[stacki
- 1] -= stack
[stacki
];
12329 /* If we're not the last op, then we definitely can't encode
12330 this using GDB's address_class enum. This is valid for partial
12331 global symbols, although the variable's address will be bogus
12334 dwarf2_complex_location_expr_complaint ();
12337 case DW_OP_GNU_push_tls_address
:
12338 /* The top of the stack has the offset from the beginning
12339 of the thread control block at which the variable is located. */
12340 /* Nothing should follow this operator, so the top of stack would
12342 /* This is valid for partial global symbols, but the variable's
12343 address will be bogus in the psymtab. */
12345 dwarf2_complex_location_expr_complaint ();
12348 case DW_OP_GNU_uninit
:
12352 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
12353 dwarf_stack_op_name (op
, 1));
12354 return (stack
[stacki
]);
12357 return (stack
[stacki
]);
12360 /* memory allocation interface */
12362 static struct dwarf_block
*
12363 dwarf_alloc_block (struct dwarf2_cu
*cu
)
12365 struct dwarf_block
*blk
;
12367 blk
= (struct dwarf_block
*)
12368 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
12372 static struct abbrev_info
*
12373 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
12375 struct abbrev_info
*abbrev
;
12377 abbrev
= (struct abbrev_info
*)
12378 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
12379 memset (abbrev
, 0, sizeof (struct abbrev_info
));
12383 static struct die_info
*
12384 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
12386 struct die_info
*die
;
12387 size_t size
= sizeof (struct die_info
);
12390 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
12392 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
12393 memset (die
, 0, sizeof (struct die_info
));
12398 /* Macro support. */
12401 /* Return the full name of file number I in *LH's file name table.
12402 Use COMP_DIR as the name of the current directory of the
12403 compilation. The result is allocated using xmalloc; the caller is
12404 responsible for freeing it. */
12406 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
12408 /* Is the file number a valid index into the line header's file name
12409 table? Remember that file numbers start with one, not zero. */
12410 if (1 <= file
&& file
<= lh
->num_file_names
)
12412 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
12414 if (IS_ABSOLUTE_PATH (fe
->name
))
12415 return xstrdup (fe
->name
);
12423 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
12429 dir_len
= strlen (dir
);
12430 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
12431 strcpy (full_name
, dir
);
12432 full_name
[dir_len
] = '/';
12433 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
12437 return xstrdup (fe
->name
);
12442 /* The compiler produced a bogus file number. We can at least
12443 record the macro definitions made in the file, even if we
12444 won't be able to find the file by name. */
12445 char fake_name
[80];
12447 sprintf (fake_name
, "<bad macro file number %d>", file
);
12449 complaint (&symfile_complaints
,
12450 _("bad file number in macro information (%d)"),
12453 return xstrdup (fake_name
);
12458 static struct macro_source_file
*
12459 macro_start_file (int file
, int line
,
12460 struct macro_source_file
*current_file
,
12461 const char *comp_dir
,
12462 struct line_header
*lh
, struct objfile
*objfile
)
12464 /* The full name of this source file. */
12465 char *full_name
= file_full_name (file
, lh
, comp_dir
);
12467 /* We don't create a macro table for this compilation unit
12468 at all until we actually get a filename. */
12469 if (! pending_macros
)
12470 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
12471 objfile
->macro_cache
);
12473 if (! current_file
)
12474 /* If we have no current file, then this must be the start_file
12475 directive for the compilation unit's main source file. */
12476 current_file
= macro_set_main (pending_macros
, full_name
);
12478 current_file
= macro_include (current_file
, line
, full_name
);
12482 return current_file
;
12486 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
12487 followed by a null byte. */
12489 copy_string (const char *buf
, int len
)
12491 char *s
= xmalloc (len
+ 1);
12493 memcpy (s
, buf
, len
);
12499 static const char *
12500 consume_improper_spaces (const char *p
, const char *body
)
12504 complaint (&symfile_complaints
,
12505 _("macro definition contains spaces in formal argument list:\n`%s'"),
12517 parse_macro_definition (struct macro_source_file
*file
, int line
,
12522 /* The body string takes one of two forms. For object-like macro
12523 definitions, it should be:
12525 <macro name> " " <definition>
12527 For function-like macro definitions, it should be:
12529 <macro name> "() " <definition>
12531 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
12533 Spaces may appear only where explicitly indicated, and in the
12536 The Dwarf 2 spec says that an object-like macro's name is always
12537 followed by a space, but versions of GCC around March 2002 omit
12538 the space when the macro's definition is the empty string.
12540 The Dwarf 2 spec says that there should be no spaces between the
12541 formal arguments in a function-like macro's formal argument list,
12542 but versions of GCC around March 2002 include spaces after the
12546 /* Find the extent of the macro name. The macro name is terminated
12547 by either a space or null character (for an object-like macro) or
12548 an opening paren (for a function-like macro). */
12549 for (p
= body
; *p
; p
++)
12550 if (*p
== ' ' || *p
== '(')
12553 if (*p
== ' ' || *p
== '\0')
12555 /* It's an object-like macro. */
12556 int name_len
= p
- body
;
12557 char *name
= copy_string (body
, name_len
);
12558 const char *replacement
;
12561 replacement
= body
+ name_len
+ 1;
12564 dwarf2_macro_malformed_definition_complaint (body
);
12565 replacement
= body
+ name_len
;
12568 macro_define_object (file
, line
, name
, replacement
);
12572 else if (*p
== '(')
12574 /* It's a function-like macro. */
12575 char *name
= copy_string (body
, p
- body
);
12578 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
12582 p
= consume_improper_spaces (p
, body
);
12584 /* Parse the formal argument list. */
12585 while (*p
&& *p
!= ')')
12587 /* Find the extent of the current argument name. */
12588 const char *arg_start
= p
;
12590 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
12593 if (! *p
|| p
== arg_start
)
12594 dwarf2_macro_malformed_definition_complaint (body
);
12597 /* Make sure argv has room for the new argument. */
12598 if (argc
>= argv_size
)
12601 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
12604 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
12607 p
= consume_improper_spaces (p
, body
);
12609 /* Consume the comma, if present. */
12614 p
= consume_improper_spaces (p
, body
);
12623 /* Perfectly formed definition, no complaints. */
12624 macro_define_function (file
, line
, name
,
12625 argc
, (const char **) argv
,
12627 else if (*p
== '\0')
12629 /* Complain, but do define it. */
12630 dwarf2_macro_malformed_definition_complaint (body
);
12631 macro_define_function (file
, line
, name
,
12632 argc
, (const char **) argv
,
12636 /* Just complain. */
12637 dwarf2_macro_malformed_definition_complaint (body
);
12640 /* Just complain. */
12641 dwarf2_macro_malformed_definition_complaint (body
);
12647 for (i
= 0; i
< argc
; i
++)
12653 dwarf2_macro_malformed_definition_complaint (body
);
12658 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
12659 char *comp_dir
, bfd
*abfd
,
12660 struct dwarf2_cu
*cu
)
12662 gdb_byte
*mac_ptr
, *mac_end
;
12663 struct macro_source_file
*current_file
= 0;
12664 enum dwarf_macinfo_record_type macinfo_type
;
12665 int at_commandline
;
12667 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
12668 &dwarf2_per_objfile
->macinfo
);
12669 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
12671 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
12675 /* First pass: Find the name of the base filename.
12676 This filename is needed in order to process all macros whose definition
12677 (or undefinition) comes from the command line. These macros are defined
12678 before the first DW_MACINFO_start_file entry, and yet still need to be
12679 associated to the base file.
12681 To determine the base file name, we scan the macro definitions until we
12682 reach the first DW_MACINFO_start_file entry. We then initialize
12683 CURRENT_FILE accordingly so that any macro definition found before the
12684 first DW_MACINFO_start_file can still be associated to the base file. */
12686 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
12687 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
12688 + dwarf2_per_objfile
->macinfo
.size
;
12692 /* Do we at least have room for a macinfo type byte? */
12693 if (mac_ptr
>= mac_end
)
12695 /* Complaint is printed during the second pass as GDB will probably
12696 stop the first pass earlier upon finding DW_MACINFO_start_file. */
12700 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
12703 switch (macinfo_type
)
12705 /* A zero macinfo type indicates the end of the macro
12710 case DW_MACINFO_define
:
12711 case DW_MACINFO_undef
:
12712 /* Only skip the data by MAC_PTR. */
12714 unsigned int bytes_read
;
12716 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12717 mac_ptr
+= bytes_read
;
12718 read_string (abfd
, mac_ptr
, &bytes_read
);
12719 mac_ptr
+= bytes_read
;
12723 case DW_MACINFO_start_file
:
12725 unsigned int bytes_read
;
12728 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12729 mac_ptr
+= bytes_read
;
12730 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12731 mac_ptr
+= bytes_read
;
12733 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
12738 case DW_MACINFO_end_file
:
12739 /* No data to skip by MAC_PTR. */
12742 case DW_MACINFO_vendor_ext
:
12743 /* Only skip the data by MAC_PTR. */
12745 unsigned int bytes_read
;
12747 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12748 mac_ptr
+= bytes_read
;
12749 read_string (abfd
, mac_ptr
, &bytes_read
);
12750 mac_ptr
+= bytes_read
;
12757 } while (macinfo_type
!= 0 && current_file
== NULL
);
12759 /* Second pass: Process all entries.
12761 Use the AT_COMMAND_LINE flag to determine whether we are still processing
12762 command-line macro definitions/undefinitions. This flag is unset when we
12763 reach the first DW_MACINFO_start_file entry. */
12765 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
12767 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
12768 GDB is still reading the definitions from command line. First
12769 DW_MACINFO_start_file will need to be ignored as it was already executed
12770 to create CURRENT_FILE for the main source holding also the command line
12771 definitions. On first met DW_MACINFO_start_file this flag is reset to
12772 normally execute all the remaining DW_MACINFO_start_file macinfos. */
12774 at_commandline
= 1;
12778 /* Do we at least have room for a macinfo type byte? */
12779 if (mac_ptr
>= mac_end
)
12781 dwarf2_macros_too_long_complaint ();
12785 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
12788 switch (macinfo_type
)
12790 /* A zero macinfo type indicates the end of the macro
12795 case DW_MACINFO_define
:
12796 case DW_MACINFO_undef
:
12798 unsigned int bytes_read
;
12802 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12803 mac_ptr
+= bytes_read
;
12804 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
12805 mac_ptr
+= bytes_read
;
12807 if (! current_file
)
12809 /* DWARF violation as no main source is present. */
12810 complaint (&symfile_complaints
,
12811 _("debug info with no main source gives macro %s "
12813 macinfo_type
== DW_MACINFO_define
?
12815 macinfo_type
== DW_MACINFO_undef
?
12816 _("undefinition") :
12817 _("something-or-other"), line
, body
);
12820 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
12821 complaint (&symfile_complaints
,
12822 _("debug info gives %s macro %s with %s line %d: %s"),
12823 at_commandline
? _("command-line") : _("in-file"),
12824 macinfo_type
== DW_MACINFO_define
?
12826 macinfo_type
== DW_MACINFO_undef
?
12827 _("undefinition") :
12828 _("something-or-other"),
12829 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
12831 if (macinfo_type
== DW_MACINFO_define
)
12832 parse_macro_definition (current_file
, line
, body
);
12833 else if (macinfo_type
== DW_MACINFO_undef
)
12834 macro_undef (current_file
, line
, body
);
12838 case DW_MACINFO_start_file
:
12840 unsigned int bytes_read
;
12843 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12844 mac_ptr
+= bytes_read
;
12845 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12846 mac_ptr
+= bytes_read
;
12848 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
12849 complaint (&symfile_complaints
,
12850 _("debug info gives source %d included "
12851 "from %s at %s line %d"),
12852 file
, at_commandline
? _("command-line") : _("file"),
12853 line
== 0 ? _("zero") : _("non-zero"), line
);
12855 if (at_commandline
)
12857 /* This DW_MACINFO_start_file was executed in the pass one. */
12858 at_commandline
= 0;
12861 current_file
= macro_start_file (file
, line
,
12862 current_file
, comp_dir
,
12867 case DW_MACINFO_end_file
:
12868 if (! current_file
)
12869 complaint (&symfile_complaints
,
12870 _("macro debug info has an unmatched `close_file' directive"));
12873 current_file
= current_file
->included_by
;
12874 if (! current_file
)
12876 enum dwarf_macinfo_record_type next_type
;
12878 /* GCC circa March 2002 doesn't produce the zero
12879 type byte marking the end of the compilation
12880 unit. Complain if it's not there, but exit no
12883 /* Do we at least have room for a macinfo type byte? */
12884 if (mac_ptr
>= mac_end
)
12886 dwarf2_macros_too_long_complaint ();
12890 /* We don't increment mac_ptr here, so this is just
12892 next_type
= read_1_byte (abfd
, mac_ptr
);
12893 if (next_type
!= 0)
12894 complaint (&symfile_complaints
,
12895 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
12902 case DW_MACINFO_vendor_ext
:
12904 unsigned int bytes_read
;
12908 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
12909 mac_ptr
+= bytes_read
;
12910 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
12911 mac_ptr
+= bytes_read
;
12913 /* We don't recognize any vendor extensions. */
12917 } while (macinfo_type
!= 0);
12920 /* Check if the attribute's form is a DW_FORM_block*
12921 if so return true else false. */
12923 attr_form_is_block (struct attribute
*attr
)
12925 return (attr
== NULL
? 0 :
12926 attr
->form
== DW_FORM_block1
12927 || attr
->form
== DW_FORM_block2
12928 || attr
->form
== DW_FORM_block4
12929 || attr
->form
== DW_FORM_block
12930 || attr
->form
== DW_FORM_exprloc
);
12933 /* Return non-zero if ATTR's value is a section offset --- classes
12934 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
12935 You may use DW_UNSND (attr) to retrieve such offsets.
12937 Section 7.5.4, "Attribute Encodings", explains that no attribute
12938 may have a value that belongs to more than one of these classes; it
12939 would be ambiguous if we did, because we use the same forms for all
12942 attr_form_is_section_offset (struct attribute
*attr
)
12944 return (attr
->form
== DW_FORM_data4
12945 || attr
->form
== DW_FORM_data8
12946 || attr
->form
== DW_FORM_sec_offset
);
12950 /* Return non-zero if ATTR's value falls in the 'constant' class, or
12951 zero otherwise. When this function returns true, you can apply
12952 dwarf2_get_attr_constant_value to it.
12954 However, note that for some attributes you must check
12955 attr_form_is_section_offset before using this test. DW_FORM_data4
12956 and DW_FORM_data8 are members of both the constant class, and of
12957 the classes that contain offsets into other debug sections
12958 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
12959 that, if an attribute's can be either a constant or one of the
12960 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
12961 taken as section offsets, not constants. */
12963 attr_form_is_constant (struct attribute
*attr
)
12965 switch (attr
->form
)
12967 case DW_FORM_sdata
:
12968 case DW_FORM_udata
:
12969 case DW_FORM_data1
:
12970 case DW_FORM_data2
:
12971 case DW_FORM_data4
:
12972 case DW_FORM_data8
:
12980 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
12981 struct dwarf2_cu
*cu
)
12983 if (attr_form_is_section_offset (attr
)
12984 /* ".debug_loc" may not exist at all, or the offset may be outside
12985 the section. If so, fall through to the complaint in the
12987 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
12989 struct dwarf2_loclist_baton
*baton
;
12991 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
12992 sizeof (struct dwarf2_loclist_baton
));
12993 baton
->per_cu
= cu
->per_cu
;
12994 gdb_assert (baton
->per_cu
);
12996 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
12997 &dwarf2_per_objfile
->loc
);
12999 /* We don't know how long the location list is, but make sure we
13000 don't run off the edge of the section. */
13001 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
13002 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
13003 baton
->base_address
= cu
->base_address
;
13004 if (cu
->base_known
== 0)
13005 complaint (&symfile_complaints
,
13006 _("Location list used without specifying the CU base address."));
13008 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
13009 SYMBOL_LOCATION_BATON (sym
) = baton
;
13013 struct dwarf2_locexpr_baton
*baton
;
13015 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
13016 sizeof (struct dwarf2_locexpr_baton
));
13017 baton
->per_cu
= cu
->per_cu
;
13018 gdb_assert (baton
->per_cu
);
13020 if (attr_form_is_block (attr
))
13022 /* Note that we're just copying the block's data pointer
13023 here, not the actual data. We're still pointing into the
13024 info_buffer for SYM's objfile; right now we never release
13025 that buffer, but when we do clean up properly this may
13027 baton
->size
= DW_BLOCK (attr
)->size
;
13028 baton
->data
= DW_BLOCK (attr
)->data
;
13032 dwarf2_invalid_attrib_class_complaint ("location description",
13033 SYMBOL_NATURAL_NAME (sym
));
13035 baton
->data
= NULL
;
13038 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
13039 SYMBOL_LOCATION_BATON (sym
) = baton
;
13043 /* Return the OBJFILE associated with the compilation unit CU. If CU
13044 came from a separate debuginfo file, then the master objfile is
13048 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
13050 struct objfile
*objfile
= per_cu
->objfile
;
13052 /* Return the master objfile, so that we can report and look up the
13053 correct file containing this variable. */
13054 if (objfile
->separate_debug_objfile_backlink
)
13055 objfile
= objfile
->separate_debug_objfile_backlink
;
13060 /* Return the address size given in the compilation unit header for CU. */
13063 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
13066 return per_cu
->cu
->header
.addr_size
;
13069 /* If the CU is not currently read in, we re-read its header. */
13070 struct objfile
*objfile
= per_cu
->objfile
;
13071 struct dwarf2_per_objfile
*per_objfile
13072 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13073 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13074 struct comp_unit_head cu_header
;
13076 memset (&cu_header
, 0, sizeof cu_header
);
13077 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13078 return cu_header
.addr_size
;
13082 /* Return the offset size given in the compilation unit header for CU. */
13085 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
13088 return per_cu
->cu
->header
.offset_size
;
13091 /* If the CU is not currently read in, we re-read its header. */
13092 struct objfile
*objfile
= per_cu
->objfile
;
13093 struct dwarf2_per_objfile
*per_objfile
13094 = objfile_data (objfile
, dwarf2_objfile_data_key
);
13095 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
13096 struct comp_unit_head cu_header
;
13098 memset (&cu_header
, 0, sizeof cu_header
);
13099 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
13100 return cu_header
.offset_size
;
13104 /* Return the text offset of the CU. The returned offset comes from
13105 this CU's objfile. If this objfile came from a separate debuginfo
13106 file, then the offset may be different from the corresponding
13107 offset in the parent objfile. */
13110 dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data
*per_cu
)
13112 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
13114 return ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13117 /* Locate the .debug_info compilation unit from CU's objfile which contains
13118 the DIE at OFFSET. Raises an error on failure. */
13120 static struct dwarf2_per_cu_data
*
13121 dwarf2_find_containing_comp_unit (unsigned int offset
,
13122 struct objfile
*objfile
)
13124 struct dwarf2_per_cu_data
*this_cu
;
13128 high
= dwarf2_per_objfile
->n_comp_units
- 1;
13131 int mid
= low
+ (high
- low
) / 2;
13133 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
13138 gdb_assert (low
== high
);
13139 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
13142 error (_("Dwarf Error: could not find partial DIE containing "
13143 "offset 0x%lx [in module %s]"),
13144 (long) offset
, bfd_get_filename (objfile
->obfd
));
13146 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
13147 return dwarf2_per_objfile
->all_comp_units
[low
-1];
13151 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
13152 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
13153 && offset
>= this_cu
->offset
+ this_cu
->length
)
13154 error (_("invalid dwarf2 offset %u"), offset
);
13155 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
13160 /* Locate the compilation unit from OBJFILE which is located at exactly
13161 OFFSET. Raises an error on failure. */
13163 static struct dwarf2_per_cu_data
*
13164 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
13166 struct dwarf2_per_cu_data
*this_cu
;
13168 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
13169 if (this_cu
->offset
!= offset
)
13170 error (_("no compilation unit with offset %u."), offset
);
13174 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
13176 static struct dwarf2_cu
*
13177 alloc_one_comp_unit (struct objfile
*objfile
)
13179 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
13180 cu
->objfile
= objfile
;
13181 obstack_init (&cu
->comp_unit_obstack
);
13185 /* Release one cached compilation unit, CU. We unlink it from the tree
13186 of compilation units, but we don't remove it from the read_in_chain;
13187 the caller is responsible for that.
13188 NOTE: DATA is a void * because this function is also used as a
13189 cleanup routine. */
13192 free_one_comp_unit (void *data
)
13194 struct dwarf2_cu
*cu
= data
;
13196 if (cu
->per_cu
!= NULL
)
13197 cu
->per_cu
->cu
= NULL
;
13200 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13205 /* This cleanup function is passed the address of a dwarf2_cu on the stack
13206 when we're finished with it. We can't free the pointer itself, but be
13207 sure to unlink it from the cache. Also release any associated storage
13208 and perform cache maintenance.
13210 Only used during partial symbol parsing. */
13213 free_stack_comp_unit (void *data
)
13215 struct dwarf2_cu
*cu
= data
;
13217 obstack_free (&cu
->comp_unit_obstack
, NULL
);
13218 cu
->partial_dies
= NULL
;
13220 if (cu
->per_cu
!= NULL
)
13222 /* This compilation unit is on the stack in our caller, so we
13223 should not xfree it. Just unlink it. */
13224 cu
->per_cu
->cu
= NULL
;
13227 /* If we had a per-cu pointer, then we may have other compilation
13228 units loaded, so age them now. */
13229 age_cached_comp_units ();
13233 /* Free all cached compilation units. */
13236 free_cached_comp_units (void *data
)
13238 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13240 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13241 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13242 while (per_cu
!= NULL
)
13244 struct dwarf2_per_cu_data
*next_cu
;
13246 next_cu
= per_cu
->cu
->read_in_chain
;
13248 free_one_comp_unit (per_cu
->cu
);
13249 *last_chain
= next_cu
;
13255 /* Increase the age counter on each cached compilation unit, and free
13256 any that are too old. */
13259 age_cached_comp_units (void)
13261 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13263 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
13264 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13265 while (per_cu
!= NULL
)
13267 per_cu
->cu
->last_used
++;
13268 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
13269 dwarf2_mark (per_cu
->cu
);
13270 per_cu
= per_cu
->cu
->read_in_chain
;
13273 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13274 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13275 while (per_cu
!= NULL
)
13277 struct dwarf2_per_cu_data
*next_cu
;
13279 next_cu
= per_cu
->cu
->read_in_chain
;
13281 if (!per_cu
->cu
->mark
)
13283 free_one_comp_unit (per_cu
->cu
);
13284 *last_chain
= next_cu
;
13287 last_chain
= &per_cu
->cu
->read_in_chain
;
13293 /* Remove a single compilation unit from the cache. */
13296 free_one_cached_comp_unit (void *target_cu
)
13298 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
13300 per_cu
= dwarf2_per_objfile
->read_in_chain
;
13301 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
13302 while (per_cu
!= NULL
)
13304 struct dwarf2_per_cu_data
*next_cu
;
13306 next_cu
= per_cu
->cu
->read_in_chain
;
13308 if (per_cu
->cu
== target_cu
)
13310 free_one_comp_unit (per_cu
->cu
);
13311 *last_chain
= next_cu
;
13315 last_chain
= &per_cu
->cu
->read_in_chain
;
13321 /* Release all extra memory associated with OBJFILE. */
13324 dwarf2_free_objfile (struct objfile
*objfile
)
13326 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
13328 if (dwarf2_per_objfile
== NULL
)
13331 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
13332 free_cached_comp_units (NULL
);
13334 if (dwarf2_per_objfile
->using_index
)
13338 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
13341 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
13343 if (!cu
->v
.quick
->lines
)
13346 for (j
= 0; j
< cu
->v
.quick
->lines
->num_file_names
; ++j
)
13348 if (cu
->v
.quick
->file_names
)
13349 xfree ((void *) cu
->v
.quick
->file_names
[j
]);
13350 if (cu
->v
.quick
->full_names
)
13351 xfree ((void *) cu
->v
.quick
->full_names
[j
]);
13354 free_line_header (cu
->v
.quick
->lines
);
13358 /* Everything else should be on the objfile obstack. */
13361 /* A pair of DIE offset and GDB type pointer. We store these
13362 in a hash table separate from the DIEs, and preserve them
13363 when the DIEs are flushed out of cache. */
13365 struct dwarf2_offset_and_type
13367 unsigned int offset
;
13371 /* Hash function for a dwarf2_offset_and_type. */
13374 offset_and_type_hash (const void *item
)
13376 const struct dwarf2_offset_and_type
*ofs
= item
;
13378 return ofs
->offset
;
13381 /* Equality function for a dwarf2_offset_and_type. */
13384 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
13386 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
13387 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
13389 return ofs_lhs
->offset
== ofs_rhs
->offset
;
13392 /* Set the type associated with DIE to TYPE. Save it in CU's hash
13393 table if necessary. For convenience, return TYPE.
13395 The DIEs reading must have careful ordering to:
13396 * Not cause infite loops trying to read in DIEs as a prerequisite for
13397 reading current DIE.
13398 * Not trying to dereference contents of still incompletely read in types
13399 while reading in other DIEs.
13400 * Enable referencing still incompletely read in types just by a pointer to
13401 the type without accessing its fields.
13403 Therefore caller should follow these rules:
13404 * Try to fetch any prerequisite types we may need to build this DIE type
13405 before building the type and calling set_die_type.
13406 * After building typer call set_die_type for current DIE as soon as
13407 possible before fetching more types to complete the current type.
13408 * Make the type as complete as possible before fetching more types. */
13410 static struct type
*
13411 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
13413 struct dwarf2_offset_and_type
**slot
, ofs
;
13415 /* For Ada types, make sure that the gnat-specific data is always
13416 initialized (if not already set). There are a few types where
13417 we should not be doing so, because the type-specific area is
13418 already used to hold some other piece of info (eg: TYPE_CODE_FLT
13419 where the type-specific area is used to store the floatformat).
13420 But this is not a problem, because the gnat-specific information
13421 is actually not needed for these types. */
13422 if (need_gnat_info (cu
)
13423 && TYPE_CODE (type
) != TYPE_CODE_FUNC
13424 && TYPE_CODE (type
) != TYPE_CODE_FLT
13425 && !HAVE_GNAT_AUX_INFO (type
))
13426 INIT_GNAT_SPECIFIC (type
);
13428 if (cu
->type_hash
== NULL
)
13430 gdb_assert (cu
->per_cu
!= NULL
);
13431 cu
->per_cu
->type_hash
13432 = htab_create_alloc_ex (cu
->header
.length
/ 24,
13433 offset_and_type_hash
,
13434 offset_and_type_eq
,
13436 &cu
->objfile
->objfile_obstack
,
13437 hashtab_obstack_allocate
,
13438 dummy_obstack_deallocate
);
13439 cu
->type_hash
= cu
->per_cu
->type_hash
;
13442 ofs
.offset
= die
->offset
;
13444 slot
= (struct dwarf2_offset_and_type
**)
13445 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
13447 complaint (&symfile_complaints
,
13448 _("A problem internal to GDB: DIE 0x%x has type already set"),
13450 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
13455 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
13456 not have a saved type. */
13458 static struct type
*
13459 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
13461 struct dwarf2_offset_and_type
*slot
, ofs
;
13462 htab_t type_hash
= cu
->type_hash
;
13464 if (type_hash
== NULL
)
13467 ofs
.offset
= die
->offset
;
13468 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
13475 /* Add a dependence relationship from CU to REF_PER_CU. */
13478 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
13479 struct dwarf2_per_cu_data
*ref_per_cu
)
13483 if (cu
->dependencies
== NULL
)
13485 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
13486 NULL
, &cu
->comp_unit_obstack
,
13487 hashtab_obstack_allocate
,
13488 dummy_obstack_deallocate
);
13490 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
13492 *slot
= ref_per_cu
;
13495 /* Subroutine of dwarf2_mark to pass to htab_traverse.
13496 Set the mark field in every compilation unit in the
13497 cache that we must keep because we are keeping CU. */
13500 dwarf2_mark_helper (void **slot
, void *data
)
13502 struct dwarf2_per_cu_data
*per_cu
;
13504 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
13505 if (per_cu
->cu
->mark
)
13507 per_cu
->cu
->mark
= 1;
13509 if (per_cu
->cu
->dependencies
!= NULL
)
13510 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
13515 /* Set the mark field in CU and in every other compilation unit in the
13516 cache that we must keep because we are keeping CU. */
13519 dwarf2_mark (struct dwarf2_cu
*cu
)
13524 if (cu
->dependencies
!= NULL
)
13525 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
13529 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
13533 per_cu
->cu
->mark
= 0;
13534 per_cu
= per_cu
->cu
->read_in_chain
;
13538 /* Trivial hash function for partial_die_info: the hash value of a DIE
13539 is its offset in .debug_info for this objfile. */
13542 partial_die_hash (const void *item
)
13544 const struct partial_die_info
*part_die
= item
;
13546 return part_die
->offset
;
13549 /* Trivial comparison function for partial_die_info structures: two DIEs
13550 are equal if they have the same offset. */
13553 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
13555 const struct partial_die_info
*part_die_lhs
= item_lhs
;
13556 const struct partial_die_info
*part_die_rhs
= item_rhs
;
13558 return part_die_lhs
->offset
== part_die_rhs
->offset
;
13561 static struct cmd_list_element
*set_dwarf2_cmdlist
;
13562 static struct cmd_list_element
*show_dwarf2_cmdlist
;
13565 set_dwarf2_cmd (char *args
, int from_tty
)
13567 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
13571 show_dwarf2_cmd (char *args
, int from_tty
)
13573 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
13576 /* If section described by INFO was mmapped, munmap it now. */
13579 munmap_section_buffer (struct dwarf2_section_info
*info
)
13581 if (info
->was_mmapped
)
13584 intptr_t begin
= (intptr_t) info
->buffer
;
13585 intptr_t map_begin
= begin
& ~(pagesize
- 1);
13586 size_t map_length
= info
->size
+ begin
- map_begin
;
13588 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
13590 /* Without HAVE_MMAP, we should never be here to begin with. */
13596 /* munmap debug sections for OBJFILE, if necessary. */
13599 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
13601 struct dwarf2_per_objfile
*data
= d
;
13603 munmap_section_buffer (&data
->info
);
13604 munmap_section_buffer (&data
->abbrev
);
13605 munmap_section_buffer (&data
->line
);
13606 munmap_section_buffer (&data
->str
);
13607 munmap_section_buffer (&data
->macinfo
);
13608 munmap_section_buffer (&data
->ranges
);
13609 munmap_section_buffer (&data
->loc
);
13610 munmap_section_buffer (&data
->frame
);
13611 munmap_section_buffer (&data
->eh_frame
);
13612 munmap_section_buffer (&data
->gdb_index
);
13617 /* The contents of the hash table we create when building the string
13619 struct strtab_entry
13621 offset_type offset
;
13625 /* Hash function for a strtab_entry. */
13627 hash_strtab_entry (const void *e
)
13629 const struct strtab_entry
*entry
= e
;
13630 return mapped_index_string_hash (entry
->str
);
13633 /* Equality function for a strtab_entry. */
13635 eq_strtab_entry (const void *a
, const void *b
)
13637 const struct strtab_entry
*ea
= a
;
13638 const struct strtab_entry
*eb
= b
;
13639 return !strcmp (ea
->str
, eb
->str
);
13642 /* Create a strtab_entry hash table. */
13644 create_strtab (void)
13646 return htab_create_alloc (100, hash_strtab_entry
, eq_strtab_entry
,
13647 xfree
, xcalloc
, xfree
);
13650 /* Add a string to the constant pool. Return the string's offset in
13653 add_string (htab_t table
, struct obstack
*cpool
, const char *str
)
13656 struct strtab_entry entry
;
13657 struct strtab_entry
*result
;
13660 slot
= htab_find_slot (table
, &entry
, INSERT
);
13665 result
= XNEW (struct strtab_entry
);
13666 result
->offset
= obstack_object_size (cpool
);
13668 obstack_grow_str0 (cpool
, str
);
13671 return result
->offset
;
13674 /* An entry in the symbol table. */
13675 struct symtab_index_entry
13677 /* The name of the symbol. */
13679 /* The offset of the name in the constant pool. */
13680 offset_type index_offset
;
13681 /* A sorted vector of the indices of all the CUs that hold an object
13683 VEC (offset_type
) *cu_indices
;
13686 /* The symbol table. This is a power-of-2-sized hash table. */
13687 struct mapped_symtab
13689 offset_type n_elements
;
13691 struct symtab_index_entry
**data
;
13694 /* Hash function for a symtab_index_entry. */
13696 hash_symtab_entry (const void *e
)
13698 const struct symtab_index_entry
*entry
= e
;
13699 return iterative_hash (VEC_address (offset_type
, entry
->cu_indices
),
13700 sizeof (offset_type
) * VEC_length (offset_type
,
13701 entry
->cu_indices
),
13705 /* Equality function for a symtab_index_entry. */
13707 eq_symtab_entry (const void *a
, const void *b
)
13709 const struct symtab_index_entry
*ea
= a
;
13710 const struct symtab_index_entry
*eb
= b
;
13711 int len
= VEC_length (offset_type
, ea
->cu_indices
);
13712 if (len
!= VEC_length (offset_type
, eb
->cu_indices
))
13714 return !memcmp (VEC_address (offset_type
, ea
->cu_indices
),
13715 VEC_address (offset_type
, eb
->cu_indices
),
13716 sizeof (offset_type
) * len
);
13719 /* Destroy a symtab_index_entry. */
13721 delete_symtab_entry (void *p
)
13723 struct symtab_index_entry
*entry
= p
;
13724 VEC_free (offset_type
, entry
->cu_indices
);
13728 /* Create a hash table holding symtab_index_entry objects. */
13730 create_index_table (void)
13732 return htab_create_alloc (100, hash_symtab_entry
, eq_symtab_entry
,
13733 delete_symtab_entry
, xcalloc
, xfree
);
13736 /* Create a new mapped symtab object. */
13737 static struct mapped_symtab
*
13738 create_mapped_symtab (void)
13740 struct mapped_symtab
*symtab
= XNEW (struct mapped_symtab
);
13741 symtab
->n_elements
= 0;
13742 symtab
->size
= 1024;
13743 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
13747 /* Destroy a mapped_symtab. */
13749 cleanup_mapped_symtab (void *p
)
13751 struct mapped_symtab
*symtab
= p
;
13752 /* The contents of the array are freed when the other hash table is
13754 xfree (symtab
->data
);
13758 /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to
13760 static struct symtab_index_entry
**
13761 find_slot (struct mapped_symtab
*symtab
, const char *name
)
13763 offset_type index
, step
, hash
= mapped_index_string_hash (name
);
13765 index
= hash
& (symtab
->size
- 1);
13766 step
= ((hash
* 17) & (symtab
->size
- 1)) | 1;
13770 if (!symtab
->data
[index
] || !strcmp (name
, symtab
->data
[index
]->name
))
13771 return &symtab
->data
[index
];
13772 index
= (index
+ step
) & (symtab
->size
- 1);
13776 /* Expand SYMTAB's hash table. */
13778 hash_expand (struct mapped_symtab
*symtab
)
13780 offset_type old_size
= symtab
->size
;
13782 struct symtab_index_entry
**old_entries
= symtab
->data
;
13785 symtab
->data
= XCNEWVEC (struct symtab_index_entry
*, symtab
->size
);
13787 for (i
= 0; i
< old_size
; ++i
)
13789 if (old_entries
[i
])
13791 struct symtab_index_entry
**slot
= find_slot (symtab
,
13792 old_entries
[i
]->name
);
13793 *slot
= old_entries
[i
];
13797 xfree (old_entries
);
13800 /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX
13801 is the index of the CU in which the symbol appears. */
13803 add_index_entry (struct mapped_symtab
*symtab
, const char *name
,
13804 offset_type cu_index
)
13806 struct symtab_index_entry
**slot
;
13808 ++symtab
->n_elements
;
13809 if (4 * symtab
->n_elements
/ 3 >= symtab
->size
)
13810 hash_expand (symtab
);
13812 slot
= find_slot (symtab
, name
);
13815 *slot
= XNEW (struct symtab_index_entry
);
13816 (*slot
)->name
= name
;
13817 (*slot
)->cu_indices
= NULL
;
13819 /* Don't push an index twice. Due to how we add entries we only
13820 have to check the last one. */
13821 if (VEC_empty (offset_type
, (*slot
)->cu_indices
)
13822 || VEC_length (offset_type
, (*slot
)->cu_indices
) != cu_index
)
13823 VEC_safe_push (offset_type
, (*slot
)->cu_indices
, cu_index
);
13826 /* Add a vector of indices to the constant pool. */
13828 add_indices_to_cpool (htab_t index_table
, struct obstack
*cpool
,
13829 struct symtab_index_entry
*entry
)
13833 slot
= htab_find_slot (index_table
, entry
, INSERT
);
13836 offset_type len
= VEC_length (offset_type
, entry
->cu_indices
);
13837 offset_type val
= MAYBE_SWAP (len
);
13842 entry
->index_offset
= obstack_object_size (cpool
);
13844 obstack_grow (cpool
, &val
, sizeof (val
));
13846 VEC_iterate (offset_type
, entry
->cu_indices
, i
, iter
);
13849 val
= MAYBE_SWAP (iter
);
13850 obstack_grow (cpool
, &val
, sizeof (val
));
13855 struct symtab_index_entry
*old_entry
= *slot
;
13856 entry
->index_offset
= old_entry
->index_offset
;
13859 return entry
->index_offset
;
13862 /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with
13863 constant pool entries going into the obstack CPOOL. */
13865 write_hash_table (struct mapped_symtab
*symtab
,
13866 struct obstack
*output
, struct obstack
*cpool
)
13869 htab_t index_table
;
13872 index_table
= create_index_table ();
13873 str_table
= create_strtab ();
13874 /* We add all the index vectors to the constant pool first, to
13875 ensure alignment is ok. */
13876 for (i
= 0; i
< symtab
->size
; ++i
)
13878 if (symtab
->data
[i
])
13879 add_indices_to_cpool (index_table
, cpool
, symtab
->data
[i
]);
13882 /* Now write out the hash table. */
13883 for (i
= 0; i
< symtab
->size
; ++i
)
13885 offset_type str_off
, vec_off
;
13887 if (symtab
->data
[i
])
13889 str_off
= add_string (str_table
, cpool
, symtab
->data
[i
]->name
);
13890 vec_off
= symtab
->data
[i
]->index_offset
;
13894 /* While 0 is a valid constant pool index, it is not valid
13895 to have 0 for both offsets. */
13900 str_off
= MAYBE_SWAP (str_off
);
13901 vec_off
= MAYBE_SWAP (vec_off
);
13903 obstack_grow (output
, &str_off
, sizeof (str_off
));
13904 obstack_grow (output
, &vec_off
, sizeof (vec_off
));
13907 htab_delete (str_table
);
13908 htab_delete (index_table
);
13911 /* Write an address entry to ADDR_OBSTACK. The addresses are taken
13912 from PST; CU_INDEX is the index of the CU in the vector of all
13915 add_address_entry (struct objfile
*objfile
,
13916 struct obstack
*addr_obstack
, struct partial_symtab
*pst
,
13917 unsigned int cu_index
)
13919 offset_type offset
;
13921 CORE_ADDR baseaddr
;
13923 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
13925 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->textlow
- baseaddr
);
13926 obstack_grow (addr_obstack
, addr
, 8);
13927 store_unsigned_integer (addr
, 8, BFD_ENDIAN_LITTLE
, pst
->texthigh
- baseaddr
);
13928 obstack_grow (addr_obstack
, addr
, 8);
13929 offset
= MAYBE_SWAP (cu_index
);
13930 obstack_grow (addr_obstack
, &offset
, sizeof (offset_type
));
13933 /* Add a list of partial symbols to SYMTAB. */
13935 write_psymbols (struct mapped_symtab
*symtab
,
13936 struct partial_symbol
**psymp
,
13938 offset_type cu_index
)
13940 for (; count
-- > 0; ++psymp
)
13942 if (SYMBOL_LANGUAGE (*psymp
) == language_ada
)
13943 error (_("Ada is not currently supported by the index"));
13944 add_index_entry (symtab
, SYMBOL_NATURAL_NAME (*psymp
), cu_index
);
13948 /* Write the contents of an ("unfinished") obstack to FILE. Throw an
13949 exception if there is an error. */
13951 write_obstack (FILE *file
, struct obstack
*obstack
)
13953 if (fwrite (obstack_base (obstack
), 1, obstack_object_size (obstack
),
13955 != obstack_object_size (obstack
))
13956 error (_("couldn't data write to file"));
13959 /* Unlink a file if the argument is not NULL. */
13961 unlink_if_set (void *p
)
13963 char **filename
= p
;
13965 unlink (*filename
);
13968 /* Create an index file for OBJFILE in the directory DIR. */
13970 write_psymtabs_to_index (struct objfile
*objfile
, const char *dir
)
13972 struct cleanup
*cleanup
;
13973 char *filename
, *cleanup_filename
;
13974 struct obstack contents
, addr_obstack
, constant_pool
, symtab_obstack
, cu_list
;
13977 struct mapped_symtab
*symtab
;
13978 offset_type val
, size_of_contents
, total_len
;
13982 if (!objfile
->psymtabs
)
13984 if (dwarf2_per_objfile
->using_index
)
13985 error (_("Cannot use an index to create the index"));
13987 if (stat (objfile
->name
, &st
) < 0)
13988 perror_with_name (_("Could not stat"));
13990 filename
= concat (dir
, SLASH_STRING
, lbasename (objfile
->name
),
13991 INDEX_SUFFIX
, (char *) NULL
);
13992 cleanup
= make_cleanup (xfree
, filename
);
13994 out_file
= fopen (filename
, "wb");
13996 error (_("Can't open `%s' for writing"), filename
);
13998 cleanup_filename
= filename
;
13999 make_cleanup (unlink_if_set
, &cleanup_filename
);
14001 symtab
= create_mapped_symtab ();
14002 make_cleanup (cleanup_mapped_symtab
, symtab
);
14004 obstack_init (&addr_obstack
);
14005 make_cleanup_obstack_free (&addr_obstack
);
14007 obstack_init (&cu_list
);
14008 make_cleanup_obstack_free (&cu_list
);
14010 for (i
= 0; i
< dwarf2_per_objfile
->n_comp_units
; ++i
)
14012 struct dwarf2_per_cu_data
*cu
= dwarf2_per_objfile
->all_comp_units
[i
];
14013 struct partial_symtab
*psymtab
= cu
->v
.psymtab
;
14016 write_psymbols (symtab
,
14017 objfile
->global_psymbols
.list
+ psymtab
->globals_offset
,
14018 psymtab
->n_global_syms
, i
);
14019 write_psymbols (symtab
,
14020 objfile
->static_psymbols
.list
+ psymtab
->statics_offset
,
14021 psymtab
->n_static_syms
, i
);
14023 add_address_entry (objfile
, &addr_obstack
, psymtab
, i
);
14025 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->offset
);
14026 obstack_grow (&cu_list
, val
, 8);
14027 store_unsigned_integer (val
, 8, BFD_ENDIAN_LITTLE
, cu
->length
);
14028 obstack_grow (&cu_list
, val
, 8);
14031 obstack_init (&constant_pool
);
14032 make_cleanup_obstack_free (&constant_pool
);
14033 obstack_init (&symtab_obstack
);
14034 make_cleanup_obstack_free (&symtab_obstack
);
14035 write_hash_table (symtab
, &symtab_obstack
, &constant_pool
);
14037 obstack_init (&contents
);
14038 make_cleanup_obstack_free (&contents
);
14039 size_of_contents
= 5 * sizeof (offset_type
);
14040 total_len
= size_of_contents
;
14042 /* The version number. */
14043 val
= MAYBE_SWAP (1);
14044 obstack_grow (&contents
, &val
, sizeof (val
));
14046 /* The offset of the CU list from the start of the file. */
14047 val
= MAYBE_SWAP (total_len
);
14048 obstack_grow (&contents
, &val
, sizeof (val
));
14049 total_len
+= obstack_object_size (&cu_list
);
14051 /* The offset of the address table from the start of the file. */
14052 val
= MAYBE_SWAP (total_len
);
14053 obstack_grow (&contents
, &val
, sizeof (val
));
14054 total_len
+= obstack_object_size (&addr_obstack
);
14056 /* The offset of the symbol table from the start of the file. */
14057 val
= MAYBE_SWAP (total_len
);
14058 obstack_grow (&contents
, &val
, sizeof (val
));
14059 total_len
+= obstack_object_size (&symtab_obstack
);
14061 /* The offset of the constant pool from the start of the file. */
14062 val
= MAYBE_SWAP (total_len
);
14063 obstack_grow (&contents
, &val
, sizeof (val
));
14064 total_len
+= obstack_object_size (&constant_pool
);
14066 gdb_assert (obstack_object_size (&contents
) == size_of_contents
);
14068 write_obstack (out_file
, &contents
);
14069 write_obstack (out_file
, &cu_list
);
14070 write_obstack (out_file
, &addr_obstack
);
14071 write_obstack (out_file
, &symtab_obstack
);
14072 write_obstack (out_file
, &constant_pool
);
14076 /* We want to keep the file, so we set cleanup_filename to NULL
14077 here. See unlink_if_set. */
14078 cleanup_filename
= NULL
;
14080 do_cleanups (cleanup
);
14083 /* The mapped index file format is designed to be directly mmap()able
14084 on any architecture. In most cases, a datum is represented using a
14085 little-endian 32-bit integer value, called an offset_type. Big
14086 endian machines must byte-swap the values before using them.
14087 Exceptions to this rule are noted. The data is laid out such that
14088 alignment is always respected.
14090 A mapped index consists of several sections.
14092 1. The file header. This is a sequence of values, of offset_type
14093 unless otherwise noted:
14094 [0] The version number. Currently 1.
14095 [1] The offset, from the start of the file, of the CU list.
14096 [2] The offset, from the start of the file, of the address section.
14097 [3] The offset, from the start of the file, of the symbol table.
14098 [4] The offset, from the start of the file, of the constant pool.
14100 2. The CU list. This is a sequence of pairs of 64-bit
14101 little-endian values. The first element in each pair is the offset
14102 of a CU in the .debug_info section. The second element in each
14103 pair is the length of that CU. References to a CU elsewhere in the
14104 map are done using a CU index, which is just the 0-based index into
14107 3. The address section. The address section consists of a sequence
14108 of address entries. Each address entry has three elements.
14109 [0] The low address. This is a 64-bit little-endian value.
14110 [1] The high address. This is a 64-bit little-endian value.
14111 [2] The CU index. This is an offset_type value.
14113 4. The symbol table. This is a hash table. The size of the hash
14114 table is always a power of 2. The initial hash and the step are
14115 currently defined by the `find_slot' function.
14117 Each slot in the hash table consists of a pair of offset_type
14118 values. The first value is the offset of the symbol's name in the
14119 constant pool. The second value is the offset of the CU vector in
14122 If both values are 0, then this slot in the hash table is empty.
14123 This is ok because while 0 is a valid constant pool index, it
14124 cannot be a valid index for both a string and a CU vector.
14126 A string in the constant pool is stored as a \0-terminated string,
14129 A CU vector in the constant pool is a sequence of offset_type
14130 values. The first value is the number of CU indices in the vector.
14131 Each subsequent value is the index of a CU in the CU list. This
14132 element in the hash table is used to indicate which CUs define the
14135 5. The constant pool. This is simply a bunch of bytes. It is
14136 organized so that alignment is correct: CU vectors are stored
14137 first, followed by strings. */
14139 save_gdb_index_command (char *arg
, int from_tty
)
14141 struct objfile
*objfile
;
14144 error (_("usage: maintenance save-gdb-index DIRECTORY"));
14146 ALL_OBJFILES (objfile
)
14150 /* If the objfile does not correspond to an actual file, skip it. */
14151 if (stat (objfile
->name
, &st
) < 0)
14154 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
14155 if (dwarf2_per_objfile
)
14157 volatile struct gdb_exception except
;
14159 TRY_CATCH (except
, RETURN_MASK_ERROR
)
14161 write_psymtabs_to_index (objfile
, arg
);
14163 if (except
.reason
< 0)
14164 exception_fprintf (gdb_stderr
, except
,
14165 _("Error while writing index for `%s': "),
14173 int dwarf2_always_disassemble
;
14176 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
14177 struct cmd_list_element
*c
, const char *value
)
14179 fprintf_filtered (file
, _("\
14180 Whether to always disassemble DWARF expressions is %s.\n"),
14184 void _initialize_dwarf2_read (void);
14187 _initialize_dwarf2_read (void)
14189 dwarf2_objfile_data_key
14190 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
14192 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
14193 Set DWARF 2 specific variables.\n\
14194 Configure DWARF 2 variables such as the cache size"),
14195 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
14196 0/*allow-unknown*/, &maintenance_set_cmdlist
);
14198 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
14199 Show DWARF 2 specific variables\n\
14200 Show DWARF 2 variables such as the cache size"),
14201 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
14202 0/*allow-unknown*/, &maintenance_show_cmdlist
);
14204 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
14205 &dwarf2_max_cache_age
, _("\
14206 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
14207 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
14208 A higher limit means that cached compilation units will be stored\n\
14209 in memory longer, and more total memory will be used. Zero disables\n\
14210 caching, which can slow down startup."),
14212 show_dwarf2_max_cache_age
,
14213 &set_dwarf2_cmdlist
,
14214 &show_dwarf2_cmdlist
);
14216 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
14217 &dwarf2_always_disassemble
, _("\
14218 Set whether `info address' always disassembles DWARF expressions."), _("\
14219 Show whether `info address' always disassembles DWARF expressions."), _("\
14220 When enabled, DWARF expressions are always printed in an assembly-like\n\
14221 syntax. When disabled, expressions will be printed in a more\n\
14222 conversational style, when possible."),
14224 show_dwarf2_always_disassemble
,
14225 &set_dwarf2_cmdlist
,
14226 &show_dwarf2_cmdlist
);
14228 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
14229 Set debugging of the dwarf2 DIE reader."), _("\
14230 Show debugging of the dwarf2 DIE reader."), _("\
14231 When enabled (non-zero), DIEs are dumped after they are read in.\n\
14232 The value is the maximum depth to print."),
14235 &setdebuglist
, &showdebuglist
);
14237 add_cmd ("gdb-index", class_files
, save_gdb_index_command
,
14238 _("Save a .gdb-index file"),