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"
56 #include "gdb_string.h"
57 #include "gdb_assert.h"
58 #include <sys/types.h>
65 #define MAP_FAILED ((void *) -1)
70 /* .debug_info header for a compilation unit
71 Because of alignment constraints, this structure has padding and cannot
72 be mapped directly onto the beginning of the .debug_info section. */
73 typedef struct comp_unit_header
75 unsigned int length
; /* length of the .debug_info
77 unsigned short version
; /* version number -- 2 for DWARF
79 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
80 unsigned char addr_size
; /* byte size of an address -- 4 */
83 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
86 /* .debug_line statement program prologue
87 Because of alignment constraints, this structure has padding and cannot
88 be mapped directly onto the beginning of the .debug_info section. */
89 typedef struct statement_prologue
91 unsigned int total_length
; /* byte length of the statement
93 unsigned short version
; /* version number -- 2 for DWARF
95 unsigned int prologue_length
; /* # bytes between prologue &
97 unsigned char minimum_instruction_length
; /* byte size of
99 unsigned char default_is_stmt
; /* initial value of is_stmt
102 unsigned char line_range
;
103 unsigned char opcode_base
; /* number assigned to first special
105 unsigned char *standard_opcode_lengths
;
109 /* When non-zero, dump DIEs after they are read in. */
110 static int dwarf2_die_debug
= 0;
114 /* When set, the file that we're processing is known to have debugging
115 info for C++ namespaces. GCC 3.3.x did not produce this information,
116 but later versions do. */
118 static int processing_has_namespace_info
;
120 static const struct objfile_data
*dwarf2_objfile_data_key
;
122 struct dwarf2_section_info
128 /* True if we have tried to read this section. */
132 struct dwarf2_per_objfile
134 struct dwarf2_section_info info
;
135 struct dwarf2_section_info abbrev
;
136 struct dwarf2_section_info line
;
137 struct dwarf2_section_info loc
;
138 struct dwarf2_section_info macinfo
;
139 struct dwarf2_section_info str
;
140 struct dwarf2_section_info ranges
;
141 struct dwarf2_section_info types
;
142 struct dwarf2_section_info frame
;
143 struct dwarf2_section_info eh_frame
;
146 struct objfile
*objfile
;
148 /* A list of all the compilation units. This is used to locate
149 the target compilation unit of a particular reference. */
150 struct dwarf2_per_cu_data
**all_comp_units
;
152 /* The number of compilation units in ALL_COMP_UNITS. */
155 /* A chain of compilation units that are currently read in, so that
156 they can be freed later. */
157 struct dwarf2_per_cu_data
*read_in_chain
;
159 /* A table mapping .debug_types signatures to its signatured_type entry.
160 This is NULL if the .debug_types section hasn't been read in yet. */
161 htab_t signatured_types
;
163 /* A flag indicating wether this objfile has a section loaded at a
165 int has_section_at_zero
;
168 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
170 /* names of the debugging sections */
172 /* Note that if the debugging section has been compressed, it might
173 have a name like .zdebug_info. */
175 #define INFO_SECTION "debug_info"
176 #define ABBREV_SECTION "debug_abbrev"
177 #define LINE_SECTION "debug_line"
178 #define LOC_SECTION "debug_loc"
179 #define MACINFO_SECTION "debug_macinfo"
180 #define STR_SECTION "debug_str"
181 #define RANGES_SECTION "debug_ranges"
182 #define TYPES_SECTION "debug_types"
183 #define FRAME_SECTION "debug_frame"
184 #define EH_FRAME_SECTION "eh_frame"
186 /* local data types */
188 /* We hold several abbreviation tables in memory at the same time. */
189 #ifndef ABBREV_HASH_SIZE
190 #define ABBREV_HASH_SIZE 121
193 /* The data in a compilation unit header, after target2host
194 translation, looks like this. */
195 struct comp_unit_head
199 unsigned char addr_size
;
200 unsigned char signed_addr_p
;
201 unsigned int abbrev_offset
;
203 /* Size of file offsets; either 4 or 8. */
204 unsigned int offset_size
;
206 /* Size of the length field; either 4 or 12. */
207 unsigned int initial_length_size
;
209 /* Offset to the first byte of this compilation unit header in the
210 .debug_info section, for resolving relative reference dies. */
213 /* Offset to first die in this cu from the start of the cu.
214 This will be the first byte following the compilation unit header. */
215 unsigned int first_die_offset
;
218 /* Internal state when decoding a particular compilation unit. */
221 /* The objfile containing this compilation unit. */
222 struct objfile
*objfile
;
224 /* The header of the compilation unit. */
225 struct comp_unit_head header
;
227 /* Base address of this compilation unit. */
228 CORE_ADDR base_address
;
230 /* Non-zero if base_address has been set. */
233 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
235 /* The language we are debugging. */
236 enum language language
;
237 const struct language_defn
*language_defn
;
239 const char *producer
;
241 /* The generic symbol table building routines have separate lists for
242 file scope symbols and all all other scopes (local scopes). So
243 we need to select the right one to pass to add_symbol_to_list().
244 We do it by keeping a pointer to the correct list in list_in_scope.
246 FIXME: The original dwarf code just treated the file scope as the
247 first local scope, and all other local scopes as nested local
248 scopes, and worked fine. Check to see if we really need to
249 distinguish these in buildsym.c. */
250 struct pending
**list_in_scope
;
252 /* DWARF abbreviation table associated with this compilation unit. */
253 struct abbrev_info
**dwarf2_abbrevs
;
255 /* Storage for the abbrev table. */
256 struct obstack abbrev_obstack
;
258 /* Hash table holding all the loaded partial DIEs. */
261 /* Storage for things with the same lifetime as this read-in compilation
262 unit, including partial DIEs. */
263 struct obstack comp_unit_obstack
;
265 /* When multiple dwarf2_cu structures are living in memory, this field
266 chains them all together, so that they can be released efficiently.
267 We will probably also want a generation counter so that most-recently-used
268 compilation units are cached... */
269 struct dwarf2_per_cu_data
*read_in_chain
;
271 /* Backchain to our per_cu entry if the tree has been built. */
272 struct dwarf2_per_cu_data
*per_cu
;
274 /* Pointer to the die -> type map. Although it is stored
275 permanently in per_cu, we copy it here to avoid double
279 /* How many compilation units ago was this CU last referenced? */
282 /* A hash table of die offsets for following references. */
285 /* Full DIEs if read in. */
286 struct die_info
*dies
;
288 /* A set of pointers to dwarf2_per_cu_data objects for compilation
289 units referenced by this one. Only set during full symbol processing;
290 partial symbol tables do not have dependencies. */
293 /* Header data from the line table, during full symbol processing. */
294 struct line_header
*line_header
;
296 /* Mark used when releasing cached dies. */
297 unsigned int mark
: 1;
299 /* This flag will be set if this compilation unit might include
300 inter-compilation-unit references. */
301 unsigned int has_form_ref_addr
: 1;
303 /* This flag will be set if this compilation unit includes any
304 DW_TAG_namespace DIEs. If we know that there are explicit
305 DIEs for namespaces, we don't need to try to infer them
306 from mangled names. */
307 unsigned int has_namespace_info
: 1;
310 /* Persistent data held for a compilation unit, even when not
311 processing it. We put a pointer to this structure in the
312 read_symtab_private field of the psymtab. If we encounter
313 inter-compilation-unit references, we also maintain a sorted
314 list of all compilation units. */
316 struct dwarf2_per_cu_data
318 /* The start offset and length of this compilation unit. 2**29-1
319 bytes should suffice to store the length of any compilation unit
320 - if it doesn't, GDB will fall over anyway.
321 NOTE: Unlike comp_unit_head.length, this length includes
322 initial_length_size. */
324 unsigned int length
: 29;
326 /* Flag indicating this compilation unit will be read in before
327 any of the current compilation units are processed. */
328 unsigned int queued
: 1;
330 /* This flag will be set if we need to load absolutely all DIEs
331 for this compilation unit, instead of just the ones we think
332 are interesting. It gets set if we look for a DIE in the
333 hash table and don't find it. */
334 unsigned int load_all_dies
: 1;
336 /* Non-zero if this CU is from .debug_types.
337 Otherwise it's from .debug_info. */
338 unsigned int from_debug_types
: 1;
340 /* Set iff currently read in. */
341 struct dwarf2_cu
*cu
;
343 /* If full symbols for this CU have been read in, then this field
344 holds a map of DIE offsets to types. It isn't always possible
345 to reconstruct this information later, so we have to preserve
349 /* The partial symbol table associated with this compilation unit,
350 or NULL for partial units (which do not have an associated
352 struct partial_symtab
*psymtab
;
355 /* Entry in the signatured_types hash table. */
357 struct signatured_type
361 /* Offset in .debug_types of the TU (type_unit) for this type. */
364 /* Offset in .debug_types of the type defined by this TU. */
365 unsigned int type_offset
;
367 /* The CU(/TU) of this type. */
368 struct dwarf2_per_cu_data per_cu
;
371 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
372 which are used for both .debug_info and .debug_types dies.
373 All parameters here are unchanging for the life of the call.
374 This struct exists to abstract away the constant parameters of
377 struct die_reader_specs
379 /* The bfd of this objfile. */
382 /* The CU of the DIE we are parsing. */
383 struct dwarf2_cu
*cu
;
385 /* Pointer to start of section buffer.
386 This is either the start of .debug_info or .debug_types. */
387 const gdb_byte
*buffer
;
390 /* The line number information for a compilation unit (found in the
391 .debug_line section) begins with a "statement program header",
392 which contains the following information. */
395 unsigned int total_length
;
396 unsigned short version
;
397 unsigned int header_length
;
398 unsigned char minimum_instruction_length
;
399 unsigned char default_is_stmt
;
401 unsigned char line_range
;
402 unsigned char opcode_base
;
404 /* standard_opcode_lengths[i] is the number of operands for the
405 standard opcode whose value is i. This means that
406 standard_opcode_lengths[0] is unused, and the last meaningful
407 element is standard_opcode_lengths[opcode_base - 1]. */
408 unsigned char *standard_opcode_lengths
;
410 /* The include_directories table. NOTE! These strings are not
411 allocated with xmalloc; instead, they are pointers into
412 debug_line_buffer. If you try to free them, `free' will get
414 unsigned int num_include_dirs
, include_dirs_size
;
417 /* The file_names table. NOTE! These strings are not allocated
418 with xmalloc; instead, they are pointers into debug_line_buffer.
419 Don't try to free them directly. */
420 unsigned int num_file_names
, file_names_size
;
424 unsigned int dir_index
;
425 unsigned int mod_time
;
427 int included_p
; /* Non-zero if referenced by the Line Number Program. */
428 struct symtab
*symtab
; /* The associated symbol table, if any. */
431 /* The start and end of the statement program following this
432 header. These point into dwarf2_per_objfile->line_buffer. */
433 gdb_byte
*statement_program_start
, *statement_program_end
;
436 /* When we construct a partial symbol table entry we only
437 need this much information. */
438 struct partial_die_info
440 /* Offset of this DIE. */
443 /* DWARF-2 tag for this DIE. */
444 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
446 /* Assorted flags describing the data found in this DIE. */
447 unsigned int has_children
: 1;
448 unsigned int is_external
: 1;
449 unsigned int is_declaration
: 1;
450 unsigned int has_type
: 1;
451 unsigned int has_specification
: 1;
452 unsigned int has_pc_info
: 1;
454 /* Flag set if the SCOPE field of this structure has been
456 unsigned int scope_set
: 1;
458 /* Flag set if the DIE has a byte_size attribute. */
459 unsigned int has_byte_size
: 1;
461 /* The name of this DIE. Normally the value of DW_AT_name, but
462 sometimes a default name for unnamed DIEs. */
465 /* The scope to prepend to our children. This is generally
466 allocated on the comp_unit_obstack, so will disappear
467 when this compilation unit leaves the cache. */
470 /* The location description associated with this DIE, if any. */
471 struct dwarf_block
*locdesc
;
473 /* If HAS_PC_INFO, the PC range associated with this DIE. */
477 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
478 DW_AT_sibling, if any. */
481 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
482 DW_AT_specification (or DW_AT_abstract_origin or
484 unsigned int spec_offset
;
486 /* Pointers to this DIE's parent, first child, and next sibling,
488 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
491 /* This data structure holds the information of an abbrev. */
494 unsigned int number
; /* number identifying abbrev */
495 enum dwarf_tag tag
; /* dwarf tag */
496 unsigned short has_children
; /* boolean */
497 unsigned short num_attrs
; /* number of attributes */
498 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
499 struct abbrev_info
*next
; /* next in chain */
504 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
505 ENUM_BITFIELD(dwarf_form
) form
: 16;
508 /* Attributes have a name and a value */
511 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
512 ENUM_BITFIELD(dwarf_form
) form
: 15;
514 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
515 field should be in u.str (existing only for DW_STRING) but it is kept
516 here for better struct attribute alignment. */
517 unsigned int string_is_canonical
: 1;
522 struct dwarf_block
*blk
;
526 struct signatured_type
*signatured_type
;
531 /* This data structure holds a complete die structure. */
534 /* DWARF-2 tag for this DIE. */
535 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
537 /* Number of attributes */
538 unsigned short num_attrs
;
543 /* Offset in .debug_info or .debug_types section. */
546 /* The dies in a compilation unit form an n-ary tree. PARENT
547 points to this die's parent; CHILD points to the first child of
548 this node; and all the children of a given node are chained
549 together via their SIBLING fields, terminated by a die whose
551 struct die_info
*child
; /* Its first child, if any. */
552 struct die_info
*sibling
; /* Its next sibling, if any. */
553 struct die_info
*parent
; /* Its parent, if any. */
555 /* An array of attributes, with NUM_ATTRS elements. There may be
556 zero, but it's not common and zero-sized arrays are not
557 sufficiently portable C. */
558 struct attribute attrs
[1];
561 struct function_range
564 CORE_ADDR lowpc
, highpc
;
566 struct function_range
*next
;
569 /* Get at parts of an attribute structure */
571 #define DW_STRING(attr) ((attr)->u.str)
572 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
573 #define DW_UNSND(attr) ((attr)->u.unsnd)
574 #define DW_BLOCK(attr) ((attr)->u.blk)
575 #define DW_SND(attr) ((attr)->u.snd)
576 #define DW_ADDR(attr) ((attr)->u.addr)
577 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
579 /* Blocks are a bunch of untyped bytes. */
586 #ifndef ATTR_ALLOC_CHUNK
587 #define ATTR_ALLOC_CHUNK 4
590 /* Allocate fields for structs, unions and enums in this size. */
591 #ifndef DW_FIELD_ALLOC_CHUNK
592 #define DW_FIELD_ALLOC_CHUNK 4
595 /* A zeroed version of a partial die for initialization purposes. */
596 static struct partial_die_info zeroed_partial_die
;
598 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
599 but this would require a corresponding change in unpack_field_as_long
601 static int bits_per_byte
= 8;
603 /* The routines that read and process dies for a C struct or C++ class
604 pass lists of data member fields and lists of member function fields
605 in an instance of a field_info structure, as defined below. */
608 /* List of data member and baseclasses fields. */
611 struct nextfield
*next
;
616 *fields
, *baseclasses
;
618 /* Number of fields (including baseclasses). */
621 /* Number of baseclasses. */
624 /* Set if the accesibility of one of the fields is not public. */
625 int non_public_fields
;
627 /* Member function fields array, entries are allocated in the order they
628 are encountered in the object file. */
631 struct nextfnfield
*next
;
632 struct fn_field fnfield
;
636 /* Member function fieldlist array, contains name of possibly overloaded
637 member function, number of overloaded member functions and a pointer
638 to the head of the member function field chain. */
643 struct nextfnfield
*head
;
647 /* Number of entries in the fnfieldlists array. */
651 /* One item on the queue of compilation units to read in full symbols
653 struct dwarf2_queue_item
655 struct dwarf2_per_cu_data
*per_cu
;
656 struct dwarf2_queue_item
*next
;
659 /* The current queue. */
660 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
662 /* Loaded secondary compilation units are kept in memory until they
663 have not been referenced for the processing of this many
664 compilation units. Set this to zero to disable caching. Cache
665 sizes of up to at least twenty will improve startup time for
666 typical inter-CU-reference binaries, at an obvious memory cost. */
667 static int dwarf2_max_cache_age
= 5;
669 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
670 struct cmd_list_element
*c
, const char *value
)
672 fprintf_filtered (file
, _("\
673 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
678 /* Various complaints about symbol reading that don't abort the process */
681 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
683 complaint (&symfile_complaints
,
684 _("statement list doesn't fit in .debug_line section"));
688 dwarf2_debug_line_missing_file_complaint (void)
690 complaint (&symfile_complaints
,
691 _(".debug_line section has line data without a file"));
695 dwarf2_debug_line_missing_end_sequence_complaint (void)
697 complaint (&symfile_complaints
,
698 _(".debug_line section has line program sequence without an end"));
702 dwarf2_complex_location_expr_complaint (void)
704 complaint (&symfile_complaints
, _("location expression too complex"));
708 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
711 complaint (&symfile_complaints
,
712 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
717 dwarf2_macros_too_long_complaint (void)
719 complaint (&symfile_complaints
,
720 _("macro info runs off end of `.debug_macinfo' section"));
724 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
726 complaint (&symfile_complaints
,
727 _("macro debug info contains a malformed macro definition:\n`%s'"),
732 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
734 complaint (&symfile_complaints
,
735 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
738 /* local function prototypes */
740 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
742 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
745 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
747 struct partial_symtab
*);
749 static void dwarf2_build_psymtabs_hard (struct objfile
*);
751 static void scan_partial_symbols (struct partial_die_info
*,
752 CORE_ADDR
*, CORE_ADDR
*,
753 int, struct dwarf2_cu
*);
755 static void add_partial_symbol (struct partial_die_info
*,
758 static void add_partial_namespace (struct partial_die_info
*pdi
,
759 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
760 int need_pc
, struct dwarf2_cu
*cu
);
762 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
763 CORE_ADDR
*highpc
, int need_pc
,
764 struct dwarf2_cu
*cu
);
766 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
767 struct dwarf2_cu
*cu
);
769 static void add_partial_subprogram (struct partial_die_info
*pdi
,
770 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
771 int need_pc
, struct dwarf2_cu
*cu
);
773 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
774 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
775 bfd
*abfd
, struct dwarf2_cu
*cu
);
777 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
779 static void psymtab_to_symtab_1 (struct partial_symtab
*);
781 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
783 static void dwarf2_free_abbrev_table (void *);
785 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
788 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
791 static struct partial_die_info
*load_partial_dies (bfd
*,
792 gdb_byte
*, gdb_byte
*,
793 int, struct dwarf2_cu
*);
795 static gdb_byte
*read_partial_die (struct partial_die_info
*,
796 struct abbrev_info
*abbrev
,
798 gdb_byte
*, gdb_byte
*,
801 static struct partial_die_info
*find_partial_die (unsigned int,
804 static void fixup_partial_die (struct partial_die_info
*,
807 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
808 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
810 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
811 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
813 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
815 static int read_1_signed_byte (bfd
*, gdb_byte
*);
817 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
819 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
821 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
823 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
826 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
828 static LONGEST read_checked_initial_length_and_offset
829 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
830 unsigned int *, unsigned int *);
832 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
835 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
837 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
839 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
841 static char *read_indirect_string (bfd
*, gdb_byte
*,
842 const struct comp_unit_head
*,
845 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
847 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
849 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
851 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
853 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
856 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
860 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
861 struct dwarf2_cu
*cu
);
863 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
865 static struct die_info
*die_specification (struct die_info
*die
,
866 struct dwarf2_cu
**);
868 static void free_line_header (struct line_header
*lh
);
870 static void add_file_name (struct line_header
*, char *, unsigned int,
871 unsigned int, unsigned int);
873 static struct line_header
*(dwarf_decode_line_header
874 (unsigned int offset
,
875 bfd
*abfd
, struct dwarf2_cu
*cu
));
877 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
878 struct dwarf2_cu
*, struct partial_symtab
*);
880 static void dwarf2_start_subfile (char *, char *, char *);
882 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
885 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
888 static void dwarf2_const_value_data (struct attribute
*attr
,
892 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
894 static int need_gnat_info (struct dwarf2_cu
*);
896 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
898 static void set_descriptive_type (struct type
*, struct die_info
*,
901 static struct type
*die_containing_type (struct die_info
*,
904 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
906 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
908 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
910 static char *typename_concat (struct obstack
*,
915 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
917 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
919 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
921 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
923 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
924 struct dwarf2_cu
*, struct partial_symtab
*);
926 static int dwarf2_get_pc_bounds (struct die_info
*,
927 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
928 struct partial_symtab
*);
930 static void get_scope_pc_bounds (struct die_info
*,
931 CORE_ADDR
*, CORE_ADDR
*,
934 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
935 CORE_ADDR
, struct dwarf2_cu
*);
937 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
940 static void dwarf2_attach_fields_to_type (struct field_info
*,
941 struct type
*, struct dwarf2_cu
*);
943 static void dwarf2_add_member_fn (struct field_info
*,
944 struct die_info
*, struct type
*,
947 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
948 struct type
*, struct dwarf2_cu
*);
950 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
952 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
954 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
956 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
958 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
960 static const char *namespace_name (struct die_info
*die
,
961 int *is_anonymous
, struct dwarf2_cu
*);
963 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
965 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
967 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
970 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
972 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
974 gdb_byte
**new_info_ptr
,
975 struct die_info
*parent
);
977 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
979 gdb_byte
**new_info_ptr
,
980 struct die_info
*parent
);
982 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
984 gdb_byte
**new_info_ptr
,
985 struct die_info
*parent
);
987 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
988 struct die_info
**, gdb_byte
*,
991 static void process_die (struct die_info
*, struct dwarf2_cu
*);
993 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
996 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
998 static struct die_info
*dwarf2_extension (struct die_info
*die
,
999 struct dwarf2_cu
**);
1001 static char *dwarf_tag_name (unsigned int);
1003 static char *dwarf_attr_name (unsigned int);
1005 static char *dwarf_form_name (unsigned int);
1007 static char *dwarf_stack_op_name (unsigned int);
1009 static char *dwarf_bool_name (unsigned int);
1011 static char *dwarf_type_encoding_name (unsigned int);
1014 static char *dwarf_cfi_name (unsigned int);
1017 static struct die_info
*sibling_die (struct die_info
*);
1019 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1021 static void dump_die_for_error (struct die_info
*);
1023 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1026 /*static*/ void dump_die (struct die_info
*, int max_level
);
1028 static void store_in_ref_table (struct die_info
*,
1029 struct dwarf2_cu
*);
1031 static int is_ref_attr (struct attribute
*);
1033 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1035 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1037 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1039 struct dwarf2_cu
**);
1041 static struct die_info
*follow_die_ref (struct die_info
*,
1043 struct dwarf2_cu
**);
1045 static struct die_info
*follow_die_sig (struct die_info
*,
1047 struct dwarf2_cu
**);
1049 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1050 unsigned int offset
);
1052 static void read_signatured_type (struct objfile
*,
1053 struct signatured_type
*type_sig
);
1055 /* memory allocation interface */
1057 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1059 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1061 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1063 static void initialize_cu_func_list (struct dwarf2_cu
*);
1065 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1066 struct dwarf2_cu
*);
1068 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1069 char *, bfd
*, struct dwarf2_cu
*);
1071 static int attr_form_is_block (struct attribute
*);
1073 static int attr_form_is_section_offset (struct attribute
*);
1075 static int attr_form_is_constant (struct attribute
*);
1077 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1079 struct dwarf2_cu
*cu
);
1081 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1082 struct abbrev_info
*abbrev
,
1083 struct dwarf2_cu
*cu
);
1085 static void free_stack_comp_unit (void *);
1087 static hashval_t
partial_die_hash (const void *item
);
1089 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1091 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1092 (unsigned int offset
, struct objfile
*objfile
);
1094 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1095 (unsigned int offset
, struct objfile
*objfile
);
1097 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1099 static void free_one_comp_unit (void *);
1101 static void free_cached_comp_units (void *);
1103 static void age_cached_comp_units (void);
1105 static void free_one_cached_comp_unit (void *);
1107 static struct type
*set_die_type (struct die_info
*, struct type
*,
1108 struct dwarf2_cu
*);
1110 static void create_all_comp_units (struct objfile
*);
1112 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1115 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1117 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1118 struct dwarf2_per_cu_data
*);
1120 static void dwarf2_mark (struct dwarf2_cu
*);
1122 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1124 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1126 /* Try to locate the sections we need for DWARF 2 debugging
1127 information and return true if we have enough to do something. */
1130 dwarf2_has_info (struct objfile
*objfile
)
1132 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1133 if (!dwarf2_per_objfile
)
1135 /* Initialize per-objfile state. */
1136 struct dwarf2_per_objfile
*data
1137 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1138 memset (data
, 0, sizeof (*data
));
1139 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1140 dwarf2_per_objfile
= data
;
1142 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1143 dwarf2_per_objfile
->objfile
= objfile
;
1145 return (dwarf2_per_objfile
->info
.asection
!= NULL
1146 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1149 /* When loading sections, we can either look for ".<name>", or for
1150 * ".z<name>", which indicates a compressed section. */
1153 section_is_p (const char *section_name
, const char *name
)
1155 return (section_name
[0] == '.'
1156 && (strcmp (section_name
+ 1, name
) == 0
1157 || (section_name
[1] == 'z'
1158 && strcmp (section_name
+ 2, name
) == 0)));
1161 /* This function is mapped across the sections and remembers the
1162 offset and size of each of the debugging sections we are interested
1166 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1168 if (section_is_p (sectp
->name
, INFO_SECTION
))
1170 dwarf2_per_objfile
->info
.asection
= sectp
;
1171 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1173 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1175 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1176 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1178 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1180 dwarf2_per_objfile
->line
.asection
= sectp
;
1181 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1183 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1185 dwarf2_per_objfile
->loc
.asection
= sectp
;
1186 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1188 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1190 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1191 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1193 else if (section_is_p (sectp
->name
, STR_SECTION
))
1195 dwarf2_per_objfile
->str
.asection
= sectp
;
1196 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1198 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1200 dwarf2_per_objfile
->frame
.asection
= sectp
;
1201 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1203 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1205 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1206 if (aflag
& SEC_HAS_CONTENTS
)
1208 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1209 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1212 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1214 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1215 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1217 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1219 dwarf2_per_objfile
->types
.asection
= sectp
;
1220 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1223 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1224 && bfd_section_vma (abfd
, sectp
) == 0)
1225 dwarf2_per_objfile
->has_section_at_zero
= 1;
1228 /* Decompress a section that was compressed using zlib. Store the
1229 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1232 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1233 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1235 bfd
*abfd
= objfile
->obfd
;
1237 error (_("Support for zlib-compressed DWARF data (from '%s') "
1238 "is disabled in this copy of GDB"),
1239 bfd_get_filename (abfd
));
1241 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1242 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1243 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1244 bfd_size_type uncompressed_size
;
1245 gdb_byte
*uncompressed_buffer
;
1248 int header_size
= 12;
1250 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1251 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1252 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1253 bfd_get_filename (abfd
));
1255 /* Read the zlib header. In this case, it should be "ZLIB" followed
1256 by the uncompressed section size, 8 bytes in big-endian order. */
1257 if (compressed_size
< header_size
1258 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1259 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1260 bfd_get_filename (abfd
));
1261 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1262 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1263 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1264 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1265 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1266 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1267 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1268 uncompressed_size
+= compressed_buffer
[11];
1270 /* It is possible the section consists of several compressed
1271 buffers concatenated together, so we uncompress in a loop. */
1275 strm
.avail_in
= compressed_size
- header_size
;
1276 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1277 strm
.avail_out
= uncompressed_size
;
1278 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1280 rc
= inflateInit (&strm
);
1281 while (strm
.avail_in
> 0)
1284 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1285 bfd_get_filename (abfd
), rc
);
1286 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1287 + (uncompressed_size
- strm
.avail_out
));
1288 rc
= inflate (&strm
, Z_FINISH
);
1289 if (rc
!= Z_STREAM_END
)
1290 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1291 bfd_get_filename (abfd
), rc
);
1292 rc
= inflateReset (&strm
);
1294 rc
= inflateEnd (&strm
);
1296 || strm
.avail_out
!= 0)
1297 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1298 bfd_get_filename (abfd
), rc
);
1300 do_cleanups (cleanup
);
1301 *outbuf
= uncompressed_buffer
;
1302 *outsize
= uncompressed_size
;
1306 /* Read the contents of the section SECTP from object file specified by
1307 OBJFILE, store info about the section into INFO.
1308 If the section is compressed, uncompress it before returning. */
1311 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1313 bfd
*abfd
= objfile
->obfd
;
1314 asection
*sectp
= info
->asection
;
1315 gdb_byte
*buf
, *retbuf
;
1316 unsigned char header
[4];
1320 info
->buffer
= NULL
;
1321 info
->was_mmapped
= 0;
1324 if (info
->asection
== NULL
|| info
->size
== 0)
1327 /* Check if the file has a 4-byte header indicating compression. */
1328 if (info
->size
> sizeof (header
)
1329 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1330 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1332 /* Upon decompression, update the buffer and its size. */
1333 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1335 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1343 pagesize
= getpagesize ();
1345 /* Only try to mmap sections which are large enough: we don't want to
1346 waste space due to fragmentation. Also, only try mmap for sections
1347 without relocations. */
1349 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1351 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1352 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1353 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1354 MAP_PRIVATE
, pg_offset
);
1356 if (retbuf
!= MAP_FAILED
)
1358 info
->was_mmapped
= 1;
1359 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1360 #if HAVE_POSIX_MADVISE
1361 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1368 /* If we get here, we are a normal, not-compressed section. */
1370 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1372 /* When debugging .o files, we may need to apply relocations; see
1373 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1374 We never compress sections in .o files, so we only need to
1375 try this when the section is not compressed. */
1376 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1379 info
->buffer
= retbuf
;
1383 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1384 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1385 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1386 bfd_get_filename (abfd
));
1389 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1393 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1394 asection
**sectp
, gdb_byte
**bufp
,
1395 bfd_size_type
*sizep
)
1397 struct dwarf2_per_objfile
*data
1398 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1399 struct dwarf2_section_info
*info
;
1400 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1401 info
= &data
->eh_frame
;
1402 else if (section_is_p (section_name
, FRAME_SECTION
))
1403 info
= &data
->frame
;
1407 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1408 /* We haven't read this section in yet. Do it now. */
1409 dwarf2_read_section (objfile
, info
);
1411 *sectp
= info
->asection
;
1412 *bufp
= info
->buffer
;
1413 *sizep
= info
->size
;
1416 /* Build a partial symbol table. */
1419 dwarf2_build_psymtabs (struct objfile
*objfile
)
1421 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
1423 init_psymbol_list (objfile
, 1024);
1426 dwarf2_build_psymtabs_hard (objfile
);
1429 /* Return TRUE if OFFSET is within CU_HEADER. */
1432 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1434 unsigned int bottom
= cu_header
->offset
;
1435 unsigned int top
= (cu_header
->offset
1437 + cu_header
->initial_length_size
);
1438 return (offset
>= bottom
&& offset
< top
);
1441 /* Read in the comp unit header information from the debug_info at info_ptr.
1442 NOTE: This leaves members offset, first_die_offset to be filled in
1446 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1447 gdb_byte
*info_ptr
, bfd
*abfd
)
1450 unsigned int bytes_read
;
1452 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1453 cu_header
->initial_length_size
= bytes_read
;
1454 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1455 info_ptr
+= bytes_read
;
1456 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1458 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1460 info_ptr
+= bytes_read
;
1461 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1463 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1464 if (signed_addr
< 0)
1465 internal_error (__FILE__
, __LINE__
,
1466 _("read_comp_unit_head: dwarf from non elf file"));
1467 cu_header
->signed_addr_p
= signed_addr
;
1473 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1474 gdb_byte
*buffer
, unsigned int buffer_size
,
1477 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1479 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1481 if (header
->version
!= 2 && header
->version
!= 3)
1482 error (_("Dwarf Error: wrong version in compilation unit header "
1483 "(is %d, should be %d) [in module %s]"), header
->version
,
1484 2, bfd_get_filename (abfd
));
1486 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1487 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1488 "(offset 0x%lx + 6) [in module %s]"),
1489 (long) header
->abbrev_offset
,
1490 (long) (beg_of_comp_unit
- buffer
),
1491 bfd_get_filename (abfd
));
1493 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1494 > buffer
+ buffer_size
)
1495 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1496 "(offset 0x%lx + 0) [in module %s]"),
1497 (long) header
->length
,
1498 (long) (beg_of_comp_unit
- buffer
),
1499 bfd_get_filename (abfd
));
1504 /* Read in the types comp unit header information from .debug_types entry at
1505 types_ptr. The result is a pointer to one past the end of the header. */
1508 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
1509 ULONGEST
*signature
,
1510 gdb_byte
*types_ptr
, bfd
*abfd
)
1512 unsigned int bytes_read
;
1513 gdb_byte
*initial_types_ptr
= types_ptr
;
1515 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->types
);
1516 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
1518 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
1520 *signature
= read_8_bytes (abfd
, types_ptr
);
1522 types_ptr
+= cu_header
->offset_size
;
1523 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
1528 /* Allocate a new partial symtab for file named NAME and mark this new
1529 partial symtab as being an include of PST. */
1532 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1533 struct objfile
*objfile
)
1535 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1537 subpst
->section_offsets
= pst
->section_offsets
;
1538 subpst
->textlow
= 0;
1539 subpst
->texthigh
= 0;
1541 subpst
->dependencies
= (struct partial_symtab
**)
1542 obstack_alloc (&objfile
->objfile_obstack
,
1543 sizeof (struct partial_symtab
*));
1544 subpst
->dependencies
[0] = pst
;
1545 subpst
->number_of_dependencies
= 1;
1547 subpst
->globals_offset
= 0;
1548 subpst
->n_global_syms
= 0;
1549 subpst
->statics_offset
= 0;
1550 subpst
->n_static_syms
= 0;
1551 subpst
->symtab
= NULL
;
1552 subpst
->read_symtab
= pst
->read_symtab
;
1555 /* No private part is necessary for include psymtabs. This property
1556 can be used to differentiate between such include psymtabs and
1557 the regular ones. */
1558 subpst
->read_symtab_private
= NULL
;
1561 /* Read the Line Number Program data and extract the list of files
1562 included by the source file represented by PST. Build an include
1563 partial symtab for each of these included files. */
1566 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1567 struct die_info
*die
,
1568 struct partial_symtab
*pst
)
1570 struct objfile
*objfile
= cu
->objfile
;
1571 bfd
*abfd
= objfile
->obfd
;
1572 struct line_header
*lh
= NULL
;
1573 struct attribute
*attr
;
1575 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
1578 unsigned int line_offset
= DW_UNSND (attr
);
1579 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
1582 return; /* No linetable, so no includes. */
1584 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1586 free_line_header (lh
);
1590 hash_type_signature (const void *item
)
1592 const struct signatured_type
*type_sig
= item
;
1593 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1594 return type_sig
->signature
;
1598 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
1600 const struct signatured_type
*lhs
= item_lhs
;
1601 const struct signatured_type
*rhs
= item_rhs
;
1602 return lhs
->signature
== rhs
->signature
;
1605 /* Create the hash table of all entries in the .debug_types section.
1606 The result is zero if there is an error (e.g. missing .debug_types section),
1607 otherwise non-zero. */
1610 create_debug_types_hash_table (struct objfile
*objfile
)
1615 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
1616 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
1618 if (info_ptr
== NULL
)
1620 dwarf2_per_objfile
->signatured_types
= NULL
;
1624 types_htab
= htab_create_alloc_ex (41,
1625 hash_type_signature
,
1628 &objfile
->objfile_obstack
,
1629 hashtab_obstack_allocate
,
1630 dummy_obstack_deallocate
);
1632 if (dwarf2_die_debug
)
1633 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
1635 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1637 unsigned int offset
;
1638 unsigned int offset_size
;
1639 unsigned int type_offset
;
1640 unsigned int length
, initial_length_size
;
1641 unsigned short version
;
1643 struct signatured_type
*type_sig
;
1645 gdb_byte
*ptr
= info_ptr
;
1647 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
1649 /* We need to read the type's signature in order to build the hash
1650 table, but we don't need to read anything else just yet. */
1652 /* Sanity check to ensure entire cu is present. */
1653 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
1654 if (ptr
+ length
+ initial_length_size
1655 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1657 complaint (&symfile_complaints
,
1658 _("debug type entry runs off end of `.debug_types' section, ignored"));
1662 offset_size
= initial_length_size
== 4 ? 4 : 8;
1663 ptr
+= initial_length_size
;
1664 version
= bfd_get_16 (objfile
->obfd
, ptr
);
1666 ptr
+= offset_size
; /* abbrev offset */
1667 ptr
+= 1; /* address size */
1668 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
1670 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
1672 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
1673 memset (type_sig
, 0, sizeof (*type_sig
));
1674 type_sig
->signature
= signature
;
1675 type_sig
->offset
= offset
;
1676 type_sig
->type_offset
= type_offset
;
1678 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
1679 gdb_assert (slot
!= NULL
);
1682 if (dwarf2_die_debug
)
1683 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
1684 offset
, phex (signature
, sizeof (signature
)));
1686 info_ptr
= info_ptr
+ initial_length_size
+ length
;
1689 dwarf2_per_objfile
->signatured_types
= types_htab
;
1694 /* Lookup a signature based type.
1695 Returns NULL if SIG is not present in the table. */
1697 static struct signatured_type
*
1698 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
1700 struct signatured_type find_entry
, *entry
;
1702 if (dwarf2_per_objfile
->signatured_types
== NULL
)
1704 complaint (&symfile_complaints
,
1705 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1709 find_entry
.signature
= sig
;
1710 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
1714 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1717 init_cu_die_reader (struct die_reader_specs
*reader
,
1718 struct dwarf2_cu
*cu
)
1720 reader
->abfd
= cu
->objfile
->obfd
;
1722 if (cu
->per_cu
->from_debug_types
)
1724 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1725 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
1729 gdb_assert (dwarf2_per_objfile
->info
.readin
);
1730 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
1734 /* Find the base address of the compilation unit for range lists and
1735 location lists. It will normally be specified by DW_AT_low_pc.
1736 In DWARF-3 draft 4, the base address could be overridden by
1737 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1738 compilation units with discontinuous ranges. */
1741 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
1743 struct attribute
*attr
;
1746 cu
->base_address
= 0;
1748 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
1751 cu
->base_address
= DW_ADDR (attr
);
1756 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
1759 cu
->base_address
= DW_ADDR (attr
);
1765 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1766 to combine the common parts.
1767 Process a compilation unit for a psymtab.
1768 BUFFER is a pointer to the beginning of the dwarf section buffer,
1769 either .debug_info or debug_types.
1770 INFO_PTR is a pointer to the start of the CU.
1771 Returns a pointer to the next CU. */
1774 process_psymtab_comp_unit (struct objfile
*objfile
,
1775 struct dwarf2_per_cu_data
*this_cu
,
1776 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1777 unsigned int buffer_size
)
1779 bfd
*abfd
= objfile
->obfd
;
1780 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1781 struct die_info
*comp_unit_die
;
1782 struct partial_symtab
*pst
;
1784 struct cleanup
*back_to_inner
;
1785 struct dwarf2_cu cu
;
1786 unsigned int bytes_read
;
1787 int has_children
, has_pc_info
;
1788 struct attribute
*attr
;
1790 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
1791 struct die_reader_specs reader_specs
;
1793 memset (&cu
, 0, sizeof (cu
));
1794 cu
.objfile
= objfile
;
1795 obstack_init (&cu
.comp_unit_obstack
);
1797 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1799 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1800 buffer
, buffer_size
,
1803 /* Complete the cu_header. */
1804 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1805 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1807 cu
.list_in_scope
= &file_symbols
;
1809 /* If this compilation unit was already read in, free the
1810 cached copy in order to read it in again. This is
1811 necessary because we skipped some symbols when we first
1812 read in the compilation unit (see load_partial_dies).
1813 This problem could be avoided, but the benefit is
1815 if (this_cu
->cu
!= NULL
)
1816 free_one_cached_comp_unit (this_cu
->cu
);
1818 /* Note that this is a pointer to our stack frame, being
1819 added to a global data structure. It will be cleaned up
1820 in free_stack_comp_unit when we finish with this
1821 compilation unit. */
1823 cu
.per_cu
= this_cu
;
1825 /* Read the abbrevs for this compilation unit into a table. */
1826 dwarf2_read_abbrevs (abfd
, &cu
);
1827 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1829 /* Read the compilation unit die. */
1830 if (this_cu
->from_debug_types
)
1831 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1832 init_cu_die_reader (&reader_specs
, &cu
);
1833 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1836 if (this_cu
->from_debug_types
)
1838 /* offset,length haven't been set yet for type units. */
1839 this_cu
->offset
= cu
.header
.offset
;
1840 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
1842 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
1844 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1845 + cu
.header
.initial_length_size
);
1846 do_cleanups (back_to_inner
);
1850 /* Set the language we're debugging. */
1851 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
1853 set_cu_language (DW_UNSND (attr
), &cu
);
1855 set_cu_language (language_minimal
, &cu
);
1857 /* Allocate a new partial symbol table structure. */
1858 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
1859 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1860 (attr
!= NULL
) ? DW_STRING (attr
) : "",
1861 /* TEXTLOW and TEXTHIGH are set below. */
1863 objfile
->global_psymbols
.next
,
1864 objfile
->static_psymbols
.next
);
1866 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
1868 pst
->dirname
= DW_STRING (attr
);
1870 pst
->read_symtab_private
= this_cu
;
1872 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1874 /* Store the function that reads in the rest of the symbol table */
1875 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1877 this_cu
->psymtab
= pst
;
1879 dwarf2_find_base_address (comp_unit_die
, &cu
);
1881 /* Possibly set the default values of LOWPC and HIGHPC from
1883 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
1884 &best_highpc
, &cu
, pst
);
1885 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
1886 /* Store the contiguous range if it is not empty; it can be empty for
1887 CUs with no code. */
1888 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1889 best_lowpc
+ baseaddr
,
1890 best_highpc
+ baseaddr
- 1, pst
);
1892 /* Check if comp unit has_children.
1893 If so, read the rest of the partial symbols from this comp unit.
1894 If not, there's no more debug_info for this comp unit. */
1897 struct partial_die_info
*first_die
;
1898 CORE_ADDR lowpc
, highpc
;
1900 lowpc
= ((CORE_ADDR
) -1);
1901 highpc
= ((CORE_ADDR
) 0);
1903 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
1905 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1906 ! has_pc_info
, &cu
);
1908 /* If we didn't find a lowpc, set it to highpc to avoid
1909 complaints from `maint check'. */
1910 if (lowpc
== ((CORE_ADDR
) -1))
1913 /* If the compilation unit didn't have an explicit address range,
1914 then use the information extracted from its child dies. */
1918 best_highpc
= highpc
;
1921 pst
->textlow
= best_lowpc
+ baseaddr
;
1922 pst
->texthigh
= best_highpc
+ baseaddr
;
1924 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1925 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1926 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1927 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1928 sort_pst_symbols (pst
);
1930 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1931 + cu
.header
.initial_length_size
);
1933 if (this_cu
->from_debug_types
)
1935 /* It's not clear we want to do anything with stmt lists here.
1936 Waiting to see what gcc ultimately does. */
1940 /* Get the list of files included in the current compilation unit,
1941 and build a psymtab for each of them. */
1942 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
1945 do_cleanups (back_to_inner
);
1950 /* Traversal function for htab_traverse_noresize.
1951 Process one .debug_types comp-unit. */
1954 process_type_comp_unit (void **slot
, void *info
)
1956 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
1957 struct objfile
*objfile
= (struct objfile
*) info
;
1958 struct dwarf2_per_cu_data
*this_cu
;
1960 this_cu
= &entry
->per_cu
;
1961 this_cu
->from_debug_types
= 1;
1963 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1964 process_psymtab_comp_unit (objfile
, this_cu
,
1965 dwarf2_per_objfile
->types
.buffer
,
1966 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
1967 dwarf2_per_objfile
->types
.size
);
1972 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
1973 Build partial symbol tables for the .debug_types comp-units. */
1976 build_type_psymtabs (struct objfile
*objfile
)
1978 if (! create_debug_types_hash_table (objfile
))
1981 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
1982 process_type_comp_unit
, objfile
);
1985 /* Build the partial symbol table by doing a quick pass through the
1986 .debug_info and .debug_abbrev sections. */
1989 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
1991 bfd
*abfd
= objfile
->obfd
;
1993 struct cleanup
*back_to
;
1995 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1996 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
1998 /* Any cached compilation units will be linked by the per-objfile
1999 read_in_chain. Make sure to free them when we're done. */
2000 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2002 build_type_psymtabs (objfile
);
2004 create_all_comp_units (objfile
);
2006 objfile
->psymtabs_addrmap
=
2007 addrmap_create_mutable (&objfile
->objfile_obstack
);
2009 /* Since the objects we're extracting from .debug_info vary in
2010 length, only the individual functions to extract them (like
2011 read_comp_unit_head and load_partial_die) can really know whether
2012 the buffer is large enough to hold another complete object.
2014 At the moment, they don't actually check that. If .debug_info
2015 holds just one extra byte after the last compilation unit's dies,
2016 then read_comp_unit_head will happily read off the end of the
2017 buffer. read_partial_die is similarly casual. Those functions
2020 For this loop condition, simply checking whether there's any data
2021 left at all should be sufficient. */
2023 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
2024 + dwarf2_per_objfile
->info
.size
))
2026 struct dwarf2_per_cu_data
*this_cu
;
2028 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
2031 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
2032 dwarf2_per_objfile
->info
.buffer
,
2034 dwarf2_per_objfile
->info
.size
);
2037 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
2038 &objfile
->objfile_obstack
);
2040 do_cleanups (back_to
);
2043 /* Load the partial DIEs for a secondary CU into memory. */
2046 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
2047 struct objfile
*objfile
)
2049 bfd
*abfd
= objfile
->obfd
;
2050 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
2051 struct die_info
*comp_unit_die
;
2052 struct dwarf2_cu
*cu
;
2053 unsigned int bytes_read
;
2054 struct cleanup
*back_to
;
2055 struct attribute
*attr
;
2057 struct die_reader_specs reader_specs
;
2059 gdb_assert (! this_cu
->from_debug_types
);
2061 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2062 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
2063 beg_of_comp_unit
= info_ptr
;
2065 cu
= alloc_one_comp_unit (objfile
);
2067 /* ??? Missing cleanup for CU? */
2069 /* Link this compilation unit into the compilation unit tree. */
2071 cu
->per_cu
= this_cu
;
2072 cu
->type_hash
= this_cu
->type_hash
;
2074 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
2075 dwarf2_per_objfile
->info
.buffer
,
2076 dwarf2_per_objfile
->info
.size
,
2079 /* Complete the cu_header. */
2080 cu
->header
.offset
= this_cu
->offset
;
2081 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2083 /* Read the abbrevs for this compilation unit into a table. */
2084 dwarf2_read_abbrevs (abfd
, cu
);
2085 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2087 /* Read the compilation unit die. */
2088 init_cu_die_reader (&reader_specs
, cu
);
2089 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2092 /* Set the language we're debugging. */
2093 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
2095 set_cu_language (DW_UNSND (attr
), cu
);
2097 set_cu_language (language_minimal
, cu
);
2099 /* Check if comp unit has_children.
2100 If so, read the rest of the partial symbols from this comp unit.
2101 If not, there's no more debug_info for this comp unit. */
2103 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
2105 do_cleanups (back_to
);
2108 /* Create a list of all compilation units in OBJFILE. We do this only
2109 if an inter-comp-unit reference is found; presumably if there is one,
2110 there will be many, and one will occur early in the .debug_info section.
2111 So there's no point in building this list incrementally. */
2114 create_all_comp_units (struct objfile
*objfile
)
2118 struct dwarf2_per_cu_data
**all_comp_units
;
2121 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2122 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2126 all_comp_units
= xmalloc (n_allocated
2127 * sizeof (struct dwarf2_per_cu_data
*));
2129 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
2131 unsigned int length
, initial_length_size
;
2132 gdb_byte
*beg_of_comp_unit
;
2133 struct dwarf2_per_cu_data
*this_cu
;
2134 unsigned int offset
;
2136 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
2138 /* Read just enough information to find out where the next
2139 compilation unit is. */
2140 length
= read_initial_length (objfile
->obfd
, info_ptr
,
2141 &initial_length_size
);
2143 /* Save the compilation unit for later lookup. */
2144 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
2145 sizeof (struct dwarf2_per_cu_data
));
2146 memset (this_cu
, 0, sizeof (*this_cu
));
2147 this_cu
->offset
= offset
;
2148 this_cu
->length
= length
+ initial_length_size
;
2150 if (n_comp_units
== n_allocated
)
2153 all_comp_units
= xrealloc (all_comp_units
,
2155 * sizeof (struct dwarf2_per_cu_data
*));
2157 all_comp_units
[n_comp_units
++] = this_cu
;
2159 info_ptr
= info_ptr
+ this_cu
->length
;
2162 dwarf2_per_objfile
->all_comp_units
2163 = obstack_alloc (&objfile
->objfile_obstack
,
2164 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2165 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
2166 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2167 xfree (all_comp_units
);
2168 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
2171 /* Process all loaded DIEs for compilation unit CU, starting at
2172 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2173 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2174 DW_AT_ranges). If NEED_PC is set, then this function will set
2175 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2176 and record the covered ranges in the addrmap. */
2179 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
2180 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2182 struct objfile
*objfile
= cu
->objfile
;
2183 bfd
*abfd
= objfile
->obfd
;
2184 struct partial_die_info
*pdi
;
2186 /* Now, march along the PDI's, descending into ones which have
2187 interesting children but skipping the children of the other ones,
2188 until we reach the end of the compilation unit. */
2194 fixup_partial_die (pdi
, cu
);
2196 /* Anonymous namespaces have no name but have interesting
2197 children, so we need to look at them. Ditto for anonymous
2200 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
2201 || pdi
->tag
== DW_TAG_enumeration_type
)
2205 case DW_TAG_subprogram
:
2206 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2208 case DW_TAG_variable
:
2209 case DW_TAG_typedef
:
2210 case DW_TAG_union_type
:
2211 if (!pdi
->is_declaration
)
2213 add_partial_symbol (pdi
, cu
);
2216 case DW_TAG_class_type
:
2217 case DW_TAG_interface_type
:
2218 case DW_TAG_structure_type
:
2219 if (!pdi
->is_declaration
)
2221 add_partial_symbol (pdi
, cu
);
2224 case DW_TAG_enumeration_type
:
2225 if (!pdi
->is_declaration
)
2226 add_partial_enumeration (pdi
, cu
);
2228 case DW_TAG_base_type
:
2229 case DW_TAG_subrange_type
:
2230 /* File scope base type definitions are added to the partial
2232 add_partial_symbol (pdi
, cu
);
2234 case DW_TAG_namespace
:
2235 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
2238 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
2245 /* If the die has a sibling, skip to the sibling. */
2247 pdi
= pdi
->die_sibling
;
2251 /* Functions used to compute the fully scoped name of a partial DIE.
2253 Normally, this is simple. For C++, the parent DIE's fully scoped
2254 name is concatenated with "::" and the partial DIE's name. For
2255 Java, the same thing occurs except that "." is used instead of "::".
2256 Enumerators are an exception; they use the scope of their parent
2257 enumeration type, i.e. the name of the enumeration type is not
2258 prepended to the enumerator.
2260 There are two complexities. One is DW_AT_specification; in this
2261 case "parent" means the parent of the target of the specification,
2262 instead of the direct parent of the DIE. The other is compilers
2263 which do not emit DW_TAG_namespace; in this case we try to guess
2264 the fully qualified name of structure types from their members'
2265 linkage names. This must be done using the DIE's children rather
2266 than the children of any DW_AT_specification target. We only need
2267 to do this for structures at the top level, i.e. if the target of
2268 any DW_AT_specification (if any; otherwise the DIE itself) does not
2271 /* Compute the scope prefix associated with PDI's parent, in
2272 compilation unit CU. The result will be allocated on CU's
2273 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2274 field. NULL is returned if no prefix is necessary. */
2276 partial_die_parent_scope (struct partial_die_info
*pdi
,
2277 struct dwarf2_cu
*cu
)
2279 char *grandparent_scope
;
2280 struct partial_die_info
*parent
, *real_pdi
;
2282 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2283 then this means the parent of the specification DIE. */
2286 while (real_pdi
->has_specification
)
2287 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2289 parent
= real_pdi
->die_parent
;
2293 if (parent
->scope_set
)
2294 return parent
->scope
;
2296 fixup_partial_die (parent
, cu
);
2298 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2300 if (parent
->tag
== DW_TAG_namespace
2301 || parent
->tag
== DW_TAG_structure_type
2302 || parent
->tag
== DW_TAG_class_type
2303 || parent
->tag
== DW_TAG_interface_type
2304 || parent
->tag
== DW_TAG_union_type
2305 || parent
->tag
== DW_TAG_enumeration_type
)
2307 if (grandparent_scope
== NULL
)
2308 parent
->scope
= parent
->name
;
2310 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2313 else if (parent
->tag
== DW_TAG_enumerator
)
2314 /* Enumerators should not get the name of the enumeration as a prefix. */
2315 parent
->scope
= grandparent_scope
;
2318 /* FIXME drow/2004-04-01: What should we be doing with
2319 function-local names? For partial symbols, we should probably be
2321 complaint (&symfile_complaints
,
2322 _("unhandled containing DIE tag %d for DIE at %d"),
2323 parent
->tag
, pdi
->offset
);
2324 parent
->scope
= grandparent_scope
;
2327 parent
->scope_set
= 1;
2328 return parent
->scope
;
2331 /* Return the fully scoped name associated with PDI, from compilation unit
2332 CU. The result will be allocated with malloc. */
2334 partial_die_full_name (struct partial_die_info
*pdi
,
2335 struct dwarf2_cu
*cu
)
2339 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2340 if (parent_scope
== NULL
)
2343 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2347 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2349 struct objfile
*objfile
= cu
->objfile
;
2351 char *actual_name
= NULL
;
2352 const char *my_prefix
;
2353 const struct partial_symbol
*psym
= NULL
;
2355 int built_actual_name
= 0;
2357 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2359 actual_name
= partial_die_full_name (pdi
, cu
);
2361 built_actual_name
= 1;
2363 if (actual_name
== NULL
)
2364 actual_name
= pdi
->name
;
2368 case DW_TAG_subprogram
:
2369 if (pdi
->is_external
|| cu
->language
== language_ada
)
2371 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2372 of the global scope. But in Ada, we want to be able to access
2373 nested procedures globally. So all Ada subprograms are stored
2374 in the global scope. */
2375 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2376 mst_text, objfile); */
2377 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2379 VAR_DOMAIN
, LOC_BLOCK
,
2380 &objfile
->global_psymbols
,
2381 0, pdi
->lowpc
+ baseaddr
,
2382 cu
->language
, objfile
);
2386 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2387 mst_file_text, objfile); */
2388 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2390 VAR_DOMAIN
, LOC_BLOCK
,
2391 &objfile
->static_psymbols
,
2392 0, pdi
->lowpc
+ baseaddr
,
2393 cu
->language
, objfile
);
2396 case DW_TAG_variable
:
2397 if (pdi
->is_external
)
2400 Don't enter into the minimal symbol tables as there is
2401 a minimal symbol table entry from the ELF symbols already.
2402 Enter into partial symbol table if it has a location
2403 descriptor or a type.
2404 If the location descriptor is missing, new_symbol will create
2405 a LOC_UNRESOLVED symbol, the address of the variable will then
2406 be determined from the minimal symbol table whenever the variable
2408 The address for the partial symbol table entry is not
2409 used by GDB, but it comes in handy for debugging partial symbol
2413 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2414 if (pdi
->locdesc
|| pdi
->has_type
)
2415 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2417 VAR_DOMAIN
, LOC_STATIC
,
2418 &objfile
->global_psymbols
,
2420 cu
->language
, objfile
);
2424 /* Static Variable. Skip symbols without location descriptors. */
2425 if (pdi
->locdesc
== NULL
)
2427 if (built_actual_name
)
2428 xfree (actual_name
);
2431 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2432 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2433 mst_file_data, objfile); */
2434 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2436 VAR_DOMAIN
, LOC_STATIC
,
2437 &objfile
->static_psymbols
,
2439 cu
->language
, objfile
);
2442 case DW_TAG_typedef
:
2443 case DW_TAG_base_type
:
2444 case DW_TAG_subrange_type
:
2445 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2447 VAR_DOMAIN
, LOC_TYPEDEF
,
2448 &objfile
->static_psymbols
,
2449 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2451 case DW_TAG_namespace
:
2452 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2454 VAR_DOMAIN
, LOC_TYPEDEF
,
2455 &objfile
->global_psymbols
,
2456 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2458 case DW_TAG_class_type
:
2459 case DW_TAG_interface_type
:
2460 case DW_TAG_structure_type
:
2461 case DW_TAG_union_type
:
2462 case DW_TAG_enumeration_type
:
2463 /* Skip external references. The DWARF standard says in the section
2464 about "Structure, Union, and Class Type Entries": "An incomplete
2465 structure, union or class type is represented by a structure,
2466 union or class entry that does not have a byte size attribute
2467 and that has a DW_AT_declaration attribute." */
2468 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2470 if (built_actual_name
)
2471 xfree (actual_name
);
2475 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2476 static vs. global. */
2477 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2479 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2480 (cu
->language
== language_cplus
2481 || cu
->language
== language_java
)
2482 ? &objfile
->global_psymbols
2483 : &objfile
->static_psymbols
,
2484 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2487 case DW_TAG_enumerator
:
2488 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2490 VAR_DOMAIN
, LOC_CONST
,
2491 (cu
->language
== language_cplus
2492 || cu
->language
== language_java
)
2493 ? &objfile
->global_psymbols
2494 : &objfile
->static_psymbols
,
2495 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2501 if (built_actual_name
)
2502 xfree (actual_name
);
2505 /* Read a partial die corresponding to a namespace; also, add a symbol
2506 corresponding to that namespace to the symbol table. NAMESPACE is
2507 the name of the enclosing namespace. */
2510 add_partial_namespace (struct partial_die_info
*pdi
,
2511 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2512 int need_pc
, struct dwarf2_cu
*cu
)
2514 struct objfile
*objfile
= cu
->objfile
;
2516 /* Add a symbol for the namespace. */
2518 add_partial_symbol (pdi
, cu
);
2520 /* Now scan partial symbols in that namespace. */
2522 if (pdi
->has_children
)
2523 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2526 /* Read a partial die corresponding to a Fortran module. */
2529 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2530 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2532 /* Now scan partial symbols in that module.
2534 FIXME: Support the separate Fortran module namespaces. */
2536 if (pdi
->has_children
)
2537 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2540 /* Read a partial die corresponding to a subprogram and create a partial
2541 symbol for that subprogram. When the CU language allows it, this
2542 routine also defines a partial symbol for each nested subprogram
2543 that this subprogram contains.
2545 DIE my also be a lexical block, in which case we simply search
2546 recursively for suprograms defined inside that lexical block.
2547 Again, this is only performed when the CU language allows this
2548 type of definitions. */
2551 add_partial_subprogram (struct partial_die_info
*pdi
,
2552 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2553 int need_pc
, struct dwarf2_cu
*cu
)
2555 if (pdi
->tag
== DW_TAG_subprogram
)
2557 if (pdi
->has_pc_info
)
2559 if (pdi
->lowpc
< *lowpc
)
2560 *lowpc
= pdi
->lowpc
;
2561 if (pdi
->highpc
> *highpc
)
2562 *highpc
= pdi
->highpc
;
2566 struct objfile
*objfile
= cu
->objfile
;
2568 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2569 SECT_OFF_TEXT (objfile
));
2570 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2571 pdi
->lowpc
+ baseaddr
,
2572 pdi
->highpc
- 1 + baseaddr
,
2573 cu
->per_cu
->psymtab
);
2575 if (!pdi
->is_declaration
)
2576 add_partial_symbol (pdi
, cu
);
2580 if (! pdi
->has_children
)
2583 if (cu
->language
== language_ada
)
2585 pdi
= pdi
->die_child
;
2588 fixup_partial_die (pdi
, cu
);
2589 if (pdi
->tag
== DW_TAG_subprogram
2590 || pdi
->tag
== DW_TAG_lexical_block
)
2591 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2592 pdi
= pdi
->die_sibling
;
2597 /* See if we can figure out if the class lives in a namespace. We do
2598 this by looking for a member function; its demangled name will
2599 contain namespace info, if there is any. */
2602 guess_structure_name (struct partial_die_info
*struct_pdi
,
2603 struct dwarf2_cu
*cu
)
2605 if ((cu
->language
== language_cplus
2606 || cu
->language
== language_java
)
2607 && cu
->has_namespace_info
== 0
2608 && struct_pdi
->has_children
)
2610 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2611 what template types look like, because the demangler
2612 frequently doesn't give the same name as the debug info. We
2613 could fix this by only using the demangled name to get the
2614 prefix (but see comment in read_structure_type). */
2616 struct partial_die_info
*real_pdi
;
2618 /* If this DIE (this DIE's specification, if any) has a parent, then
2619 we should not do this. We'll prepend the parent's fully qualified
2620 name when we create the partial symbol. */
2622 real_pdi
= struct_pdi
;
2623 while (real_pdi
->has_specification
)
2624 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2626 if (real_pdi
->die_parent
!= NULL
)
2631 /* Read a partial die corresponding to an enumeration type. */
2634 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2635 struct dwarf2_cu
*cu
)
2637 struct objfile
*objfile
= cu
->objfile
;
2638 bfd
*abfd
= objfile
->obfd
;
2639 struct partial_die_info
*pdi
;
2641 if (enum_pdi
->name
!= NULL
)
2642 add_partial_symbol (enum_pdi
, cu
);
2644 pdi
= enum_pdi
->die_child
;
2647 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2648 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2650 add_partial_symbol (pdi
, cu
);
2651 pdi
= pdi
->die_sibling
;
2655 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2656 Return the corresponding abbrev, or NULL if the number is zero (indicating
2657 an empty DIE). In either case *BYTES_READ will be set to the length of
2658 the initial number. */
2660 static struct abbrev_info
*
2661 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2662 struct dwarf2_cu
*cu
)
2664 bfd
*abfd
= cu
->objfile
->obfd
;
2665 unsigned int abbrev_number
;
2666 struct abbrev_info
*abbrev
;
2668 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2670 if (abbrev_number
== 0)
2673 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2676 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2677 bfd_get_filename (abfd
));
2683 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2684 Returns a pointer to the end of a series of DIEs, terminated by an empty
2685 DIE. Any children of the skipped DIEs will also be skipped. */
2688 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2690 struct abbrev_info
*abbrev
;
2691 unsigned int bytes_read
;
2695 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2697 return info_ptr
+ bytes_read
;
2699 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
2703 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2704 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2705 abbrev corresponding to that skipped uleb128 should be passed in
2706 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2710 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2711 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
2713 unsigned int bytes_read
;
2714 struct attribute attr
;
2715 bfd
*abfd
= cu
->objfile
->obfd
;
2716 unsigned int form
, i
;
2718 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2720 /* The only abbrev we care about is DW_AT_sibling. */
2721 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2723 read_attribute (&attr
, &abbrev
->attrs
[i
],
2724 abfd
, info_ptr
, cu
);
2725 if (attr
.form
== DW_FORM_ref_addr
)
2726 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2728 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
2731 /* If it isn't DW_AT_sibling, skip this attribute. */
2732 form
= abbrev
->attrs
[i
].form
;
2736 case DW_FORM_ref_addr
:
2737 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2738 and later it is offset sized. */
2739 if (cu
->header
.version
== 2)
2740 info_ptr
+= cu
->header
.addr_size
;
2742 info_ptr
+= cu
->header
.offset_size
;
2745 info_ptr
+= cu
->header
.addr_size
;
2765 case DW_FORM_string
:
2766 read_string (abfd
, info_ptr
, &bytes_read
);
2767 info_ptr
+= bytes_read
;
2770 info_ptr
+= cu
->header
.offset_size
;
2773 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2774 info_ptr
+= bytes_read
;
2776 case DW_FORM_block1
:
2777 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2779 case DW_FORM_block2
:
2780 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2782 case DW_FORM_block4
:
2783 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2787 case DW_FORM_ref_udata
:
2788 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2790 case DW_FORM_indirect
:
2791 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2792 info_ptr
+= bytes_read
;
2793 /* We need to continue parsing from here, so just go back to
2795 goto skip_attribute
;
2798 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2799 dwarf_form_name (form
),
2800 bfd_get_filename (abfd
));
2804 if (abbrev
->has_children
)
2805 return skip_children (buffer
, info_ptr
, cu
);
2810 /* Locate ORIG_PDI's sibling.
2811 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2815 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
2816 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2817 bfd
*abfd
, struct dwarf2_cu
*cu
)
2819 /* Do we know the sibling already? */
2821 if (orig_pdi
->sibling
)
2822 return orig_pdi
->sibling
;
2824 /* Are there any children to deal with? */
2826 if (!orig_pdi
->has_children
)
2829 /* Skip the children the long way. */
2831 return skip_children (buffer
, info_ptr
, cu
);
2834 /* Expand this partial symbol table into a full symbol table. */
2837 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2839 /* FIXME: This is barely more than a stub. */
2844 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2850 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2851 gdb_flush (gdb_stdout
);
2854 /* Restore our global data. */
2855 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2856 dwarf2_objfile_data_key
);
2858 /* If this psymtab is constructed from a debug-only objfile, the
2859 has_section_at_zero flag will not necessarily be correct. We
2860 can get the correct value for this flag by looking at the data
2861 associated with the (presumably stripped) associated objfile. */
2862 if (pst
->objfile
->separate_debug_objfile_backlink
)
2864 struct dwarf2_per_objfile
*dpo_backlink
2865 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2866 dwarf2_objfile_data_key
);
2867 dwarf2_per_objfile
->has_section_at_zero
2868 = dpo_backlink
->has_section_at_zero
;
2871 psymtab_to_symtab_1 (pst
);
2873 /* Finish up the debug error message. */
2875 printf_filtered (_("done.\n"));
2880 /* Add PER_CU to the queue. */
2883 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2885 struct dwarf2_queue_item
*item
;
2888 item
= xmalloc (sizeof (*item
));
2889 item
->per_cu
= per_cu
;
2892 if (dwarf2_queue
== NULL
)
2893 dwarf2_queue
= item
;
2895 dwarf2_queue_tail
->next
= item
;
2897 dwarf2_queue_tail
= item
;
2900 /* Process the queue. */
2903 process_queue (struct objfile
*objfile
)
2905 struct dwarf2_queue_item
*item
, *next_item
;
2907 /* The queue starts out with one item, but following a DIE reference
2908 may load a new CU, adding it to the end of the queue. */
2909 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2911 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2912 process_full_comp_unit (item
->per_cu
);
2914 item
->per_cu
->queued
= 0;
2915 next_item
= item
->next
;
2919 dwarf2_queue_tail
= NULL
;
2922 /* Free all allocated queue entries. This function only releases anything if
2923 an error was thrown; if the queue was processed then it would have been
2924 freed as we went along. */
2927 dwarf2_release_queue (void *dummy
)
2929 struct dwarf2_queue_item
*item
, *last
;
2931 item
= dwarf2_queue
;
2934 /* Anything still marked queued is likely to be in an
2935 inconsistent state, so discard it. */
2936 if (item
->per_cu
->queued
)
2938 if (item
->per_cu
->cu
!= NULL
)
2939 free_one_cached_comp_unit (item
->per_cu
->cu
);
2940 item
->per_cu
->queued
= 0;
2948 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2951 /* Read in full symbols for PST, and anything it depends on. */
2954 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2956 struct dwarf2_per_cu_data
*per_cu
;
2957 struct cleanup
*back_to
;
2960 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2961 if (!pst
->dependencies
[i
]->readin
)
2963 /* Inform about additional files that need to be read in. */
2966 /* FIXME: i18n: Need to make this a single string. */
2967 fputs_filtered (" ", gdb_stdout
);
2969 fputs_filtered ("and ", gdb_stdout
);
2971 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2972 wrap_here (""); /* Flush output */
2973 gdb_flush (gdb_stdout
);
2975 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2978 per_cu
= pst
->read_symtab_private
;
2982 /* It's an include file, no symbols to read for it.
2983 Everything is in the parent symtab. */
2988 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2990 queue_comp_unit (per_cu
, pst
->objfile
);
2992 if (per_cu
->from_debug_types
)
2993 read_signatured_type_at_offset (pst
->objfile
, per_cu
->offset
);
2995 load_full_comp_unit (per_cu
, pst
->objfile
);
2997 process_queue (pst
->objfile
);
2999 /* Age the cache, releasing compilation units that have not
3000 been used recently. */
3001 age_cached_comp_units ();
3003 do_cleanups (back_to
);
3006 /* Load the DIEs associated with PER_CU into memory. */
3009 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3011 bfd
*abfd
= objfile
->obfd
;
3012 struct dwarf2_cu
*cu
;
3013 unsigned int offset
;
3014 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3015 struct cleanup
*back_to
, *free_cu_cleanup
;
3016 struct attribute
*attr
;
3019 gdb_assert (! per_cu
->from_debug_types
);
3021 /* Set local variables from the partial symbol table info. */
3022 offset
= per_cu
->offset
;
3024 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3025 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
3026 beg_of_comp_unit
= info_ptr
;
3028 cu
= alloc_one_comp_unit (objfile
);
3030 /* If an error occurs while loading, release our storage. */
3031 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3033 /* Read in the comp_unit header. */
3034 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
3036 /* Complete the cu_header. */
3037 cu
->header
.offset
= offset
;
3038 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3040 /* Read the abbrevs for this compilation unit. */
3041 dwarf2_read_abbrevs (abfd
, cu
);
3042 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3044 /* Link this compilation unit into the compilation unit tree. */
3046 cu
->per_cu
= per_cu
;
3047 cu
->type_hash
= per_cu
->type_hash
;
3049 cu
->dies
= read_comp_unit (info_ptr
, cu
);
3051 /* We try not to read any attributes in this function, because not
3052 all objfiles needed for references have been loaded yet, and symbol
3053 table processing isn't initialized. But we have to set the CU language,
3054 or we won't be able to build types correctly. */
3055 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
3057 set_cu_language (DW_UNSND (attr
), cu
);
3059 set_cu_language (language_minimal
, cu
);
3061 /* Link this CU into read_in_chain. */
3062 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3063 dwarf2_per_objfile
->read_in_chain
= per_cu
;
3065 do_cleanups (back_to
);
3067 /* We've successfully allocated this compilation unit. Let our caller
3068 clean it up when finished with it. */
3069 discard_cleanups (free_cu_cleanup
);
3072 /* Generate full symbol information for PST and CU, whose DIEs have
3073 already been loaded into memory. */
3076 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
3078 struct partial_symtab
*pst
= per_cu
->psymtab
;
3079 struct dwarf2_cu
*cu
= per_cu
->cu
;
3080 struct objfile
*objfile
= pst
->objfile
;
3081 bfd
*abfd
= objfile
->obfd
;
3082 CORE_ADDR lowpc
, highpc
;
3083 struct symtab
*symtab
;
3084 struct cleanup
*back_to
;
3087 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3090 back_to
= make_cleanup (really_free_pendings
, NULL
);
3092 cu
->list_in_scope
= &file_symbols
;
3094 dwarf2_find_base_address (cu
->dies
, cu
);
3096 /* Do line number decoding in read_file_scope () */
3097 process_die (cu
->dies
, cu
);
3099 /* Some compilers don't define a DW_AT_high_pc attribute for the
3100 compilation unit. If the DW_AT_high_pc is missing, synthesize
3101 it, by scanning the DIE's below the compilation unit. */
3102 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
3104 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
3106 /* Set symtab language to language from DW_AT_language.
3107 If the compilation is from a C file generated by language preprocessors,
3108 do not set the language if it was already deduced by start_subfile. */
3110 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
3112 symtab
->language
= cu
->language
;
3114 pst
->symtab
= symtab
;
3117 do_cleanups (back_to
);
3120 /* Process a die and its children. */
3123 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
3127 case DW_TAG_padding
:
3129 case DW_TAG_compile_unit
:
3130 read_file_scope (die
, cu
);
3132 case DW_TAG_type_unit
:
3133 read_type_unit_scope (die
, cu
);
3135 case DW_TAG_subprogram
:
3136 case DW_TAG_inlined_subroutine
:
3137 read_func_scope (die
, cu
);
3139 case DW_TAG_lexical_block
:
3140 case DW_TAG_try_block
:
3141 case DW_TAG_catch_block
:
3142 read_lexical_block_scope (die
, cu
);
3144 case DW_TAG_class_type
:
3145 case DW_TAG_interface_type
:
3146 case DW_TAG_structure_type
:
3147 case DW_TAG_union_type
:
3148 process_structure_scope (die
, cu
);
3150 case DW_TAG_enumeration_type
:
3151 process_enumeration_scope (die
, cu
);
3154 /* These dies have a type, but processing them does not create
3155 a symbol or recurse to process the children. Therefore we can
3156 read them on-demand through read_type_die. */
3157 case DW_TAG_subroutine_type
:
3158 case DW_TAG_set_type
:
3159 case DW_TAG_array_type
:
3160 case DW_TAG_pointer_type
:
3161 case DW_TAG_ptr_to_member_type
:
3162 case DW_TAG_reference_type
:
3163 case DW_TAG_string_type
:
3166 case DW_TAG_base_type
:
3167 case DW_TAG_subrange_type
:
3168 case DW_TAG_typedef
:
3169 /* Add a typedef symbol for the type definition, if it has a
3171 new_symbol (die
, read_type_die (die
, cu
), cu
);
3173 case DW_TAG_common_block
:
3174 read_common_block (die
, cu
);
3176 case DW_TAG_common_inclusion
:
3178 case DW_TAG_namespace
:
3179 processing_has_namespace_info
= 1;
3180 read_namespace (die
, cu
);
3183 read_module (die
, cu
);
3185 case DW_TAG_imported_declaration
:
3186 case DW_TAG_imported_module
:
3187 processing_has_namespace_info
= 1;
3188 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
3189 || cu
->language
!= language_fortran
))
3190 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
3191 dwarf_tag_name (die
->tag
));
3192 read_import_statement (die
, cu
);
3195 new_symbol (die
, NULL
, cu
);
3200 /* A helper function for dwarf2_compute_name which determines whether DIE
3201 needs to have the name of the scope prepended to the name listed in the
3205 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3207 struct attribute
*attr
;
3211 case DW_TAG_namespace
:
3212 case DW_TAG_typedef
:
3213 case DW_TAG_class_type
:
3214 case DW_TAG_interface_type
:
3215 case DW_TAG_structure_type
:
3216 case DW_TAG_union_type
:
3217 case DW_TAG_enumeration_type
:
3218 case DW_TAG_enumerator
:
3219 case DW_TAG_subprogram
:
3223 case DW_TAG_variable
:
3224 /* We only need to prefix "globally" visible variables. These include
3225 any variable marked with DW_AT_external or any variable that
3226 lives in a namespace. [Variables in anonymous namespaces
3227 require prefixing, but they are not DW_AT_external.] */
3229 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
3231 struct dwarf2_cu
*spec_cu
= cu
;
3232 return die_needs_namespace (die_specification (die
, &spec_cu
),
3236 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
3237 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
)
3239 /* A variable in a lexical block of some kind does not need a
3240 namespace, even though in C++ such variables may be external
3241 and have a mangled name. */
3242 if (die
->parent
->tag
== DW_TAG_lexical_block
3243 || die
->parent
->tag
== DW_TAG_try_block
3244 || die
->parent
->tag
== DW_TAG_catch_block
)
3253 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3254 compute the physname for the object, which include a method's
3255 formal parameters (C++/Java) and return type (Java).
3257 For Ada, return the DIE's linkage name rather than the fully qualified
3258 name. PHYSNAME is ignored..
3260 The result is allocated on the objfile_obstack and canonicalized. */
3263 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
3267 name
= dwarf2_name (die
, cu
);
3269 /* These are the only languages we know how to qualify names in. */
3271 && (cu
->language
== language_cplus
|| cu
->language
== language_java
))
3273 if (die_needs_namespace (die
, cu
))
3277 struct ui_file
*buf
;
3279 prefix
= determine_prefix (die
, cu
);
3280 buf
= mem_fileopen ();
3281 if (*prefix
!= '\0')
3283 char *prefixed_name
= typename_concat (NULL
, prefix
, name
, cu
);
3284 fputs_unfiltered (prefixed_name
, buf
);
3285 xfree (prefixed_name
);
3288 fputs_unfiltered (name
? name
: "", buf
);
3290 /* For Java and C++ methods, append formal parameter type
3291 information, if PHYSNAME. */
3293 if (physname
&& die
->tag
== DW_TAG_subprogram
3294 && (cu
->language
== language_cplus
3295 || cu
->language
== language_java
))
3297 struct type
*type
= read_type_die (die
, cu
);
3299 c_type_print_args (type
, buf
, 0, cu
->language
);
3301 if (cu
->language
== language_java
)
3303 /* For java, we must append the return type to method
3305 if (die
->tag
== DW_TAG_subprogram
)
3306 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
3309 else if (cu
->language
== language_cplus
)
3311 if (TYPE_NFIELDS (type
) > 0
3312 && TYPE_FIELD_ARTIFICIAL (type
, 0)
3313 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
3314 fputs_unfiltered (" const", buf
);
3318 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
3320 ui_file_delete (buf
);
3322 if (cu
->language
== language_cplus
)
3325 = dwarf2_canonicalize_name (name
, cu
,
3326 &cu
->objfile
->objfile_obstack
);
3332 else if (cu
->language
== language_ada
)
3334 /* For Ada unit, we prefer the linkage name over the name, as
3335 the former contains the exported name, which the user expects
3336 to be able to reference. Ideally, we want the user to be able
3337 to reference this entity using either natural or linkage name,
3338 but we haven't started looking at this enhancement yet. */
3339 struct attribute
*attr
;
3341 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
3342 if (attr
&& DW_STRING (attr
))
3343 name
= DW_STRING (attr
);
3349 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3350 If scope qualifiers are appropriate they will be added. The result
3351 will be allocated on the objfile_obstack, or NULL if the DIE does
3352 not have a name. NAME may either be from a previous call to
3353 dwarf2_name or NULL.
3355 The output string will be canonicalized (if C++/Java). */
3358 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3360 return dwarf2_compute_name (name
, die
, cu
, 0);
3363 /* Construct a physname for the given DIE in CU. NAME may either be
3364 from a previous call to dwarf2_name or NULL. The result will be
3365 allocated on the objfile_objstack or NULL if the DIE does not have a
3368 The output string will be canonicalized (if C++/Java). */
3371 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3373 return dwarf2_compute_name (name
, die
, cu
, 1);
3376 /* Read the import statement specified by the given die and record it. */
3379 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3381 struct attribute
*import_attr
;
3382 struct die_info
*imported_die
;
3383 struct dwarf2_cu
*imported_cu
;
3384 const char *imported_name
;
3385 const char *imported_name_prefix
;
3386 const char *canonical_name
;
3387 const char *import_alias
;
3388 const char *imported_declaration
= NULL
;
3389 const char *import_prefix
;
3393 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3394 if (import_attr
== NULL
)
3396 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3397 dwarf_tag_name (die
->tag
));
3402 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
3403 imported_name
= dwarf2_name (imported_die
, imported_cu
);
3404 if (imported_name
== NULL
)
3406 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3408 The import in the following code:
3422 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3423 <52> DW_AT_decl_file : 1
3424 <53> DW_AT_decl_line : 6
3425 <54> DW_AT_import : <0x75>
3426 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3428 <5b> DW_AT_decl_file : 1
3429 <5c> DW_AT_decl_line : 2
3430 <5d> DW_AT_type : <0x6e>
3432 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3433 <76> DW_AT_byte_size : 4
3434 <77> DW_AT_encoding : 5 (signed)
3436 imports the wrong die ( 0x75 instead of 0x58 ).
3437 This case will be ignored until the gcc bug is fixed. */
3441 /* Figure out the local name after import. */
3442 import_alias
= dwarf2_name (die
, cu
);
3444 /* Figure out where the statement is being imported to. */
3445 import_prefix
= determine_prefix (die
, cu
);
3447 /* Figure out what the scope of the imported die is and prepend it
3448 to the name of the imported die. */
3449 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
3451 if (imported_die
->tag
!= DW_TAG_namespace
)
3453 imported_declaration
= imported_name
;
3454 canonical_name
= imported_name_prefix
;
3456 else if (strlen (imported_name_prefix
) > 0)
3458 temp
= alloca (strlen (imported_name_prefix
)
3459 + 2 + strlen (imported_name
) + 1);
3460 strcpy (temp
, imported_name_prefix
);
3461 strcat (temp
, "::");
3462 strcat (temp
, imported_name
);
3463 canonical_name
= temp
;
3466 canonical_name
= imported_name
;
3468 cp_add_using_directive (import_prefix
,
3471 imported_declaration
,
3472 &cu
->objfile
->objfile_obstack
);
3476 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3478 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3482 free_cu_line_header (void *arg
)
3484 struct dwarf2_cu
*cu
= arg
;
3486 free_line_header (cu
->line_header
);
3487 cu
->line_header
= NULL
;
3491 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3493 struct objfile
*objfile
= cu
->objfile
;
3494 struct comp_unit_head
*cu_header
= &cu
->header
;
3495 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3496 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3497 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3498 struct attribute
*attr
;
3500 char *comp_dir
= NULL
;
3501 struct die_info
*child_die
;
3502 bfd
*abfd
= objfile
->obfd
;
3503 struct line_header
*line_header
= 0;
3506 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3508 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3510 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3511 from finish_block. */
3512 if (lowpc
== ((CORE_ADDR
) -1))
3517 /* Find the filename. Do not use dwarf2_name here, since the filename
3518 is not a source language identifier. */
3519 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3522 name
= DW_STRING (attr
);
3525 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3527 comp_dir
= DW_STRING (attr
);
3528 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3530 comp_dir
= ldirname (name
);
3531 if (comp_dir
!= NULL
)
3532 make_cleanup (xfree
, comp_dir
);
3534 if (comp_dir
!= NULL
)
3536 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3537 directory, get rid of it. */
3538 char *cp
= strchr (comp_dir
, ':');
3540 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3547 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3550 set_cu_language (DW_UNSND (attr
), cu
);
3553 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3555 cu
->producer
= DW_STRING (attr
);
3557 /* We assume that we're processing GCC output. */
3558 processing_gcc_compilation
= 2;
3560 processing_has_namespace_info
= 0;
3562 start_symtab (name
, comp_dir
, lowpc
);
3563 record_debugformat ("DWARF 2");
3564 record_producer (cu
->producer
);
3566 initialize_cu_func_list (cu
);
3568 /* Decode line number information if present. We do this before
3569 processing child DIEs, so that the line header table is available
3570 for DW_AT_decl_file. */
3571 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3574 unsigned int line_offset
= DW_UNSND (attr
);
3575 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3578 cu
->line_header
= line_header
;
3579 make_cleanup (free_cu_line_header
, cu
);
3580 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3584 /* Process all dies in compilation unit. */
3585 if (die
->child
!= NULL
)
3587 child_die
= die
->child
;
3588 while (child_die
&& child_die
->tag
)
3590 process_die (child_die
, cu
);
3591 child_die
= sibling_die (child_die
);
3595 /* Decode macro information, if present. Dwarf 2 macro information
3596 refers to information in the line number info statement program
3597 header, so we can only read it if we've read the header
3599 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3600 if (attr
&& line_header
)
3602 unsigned int macro_offset
= DW_UNSND (attr
);
3603 dwarf_decode_macros (line_header
, macro_offset
,
3604 comp_dir
, abfd
, cu
);
3606 do_cleanups (back_to
);
3609 /* For TUs we want to skip the first top level sibling if it's not the
3610 actual type being defined by this TU. In this case the first top
3611 level sibling is there to provide context only. */
3614 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3616 struct objfile
*objfile
= cu
->objfile
;
3617 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3619 struct attribute
*attr
;
3621 char *comp_dir
= NULL
;
3622 struct die_info
*child_die
;
3623 bfd
*abfd
= objfile
->obfd
;
3624 struct line_header
*line_header
= 0;
3626 /* start_symtab needs a low pc, but we don't really have one.
3627 Do what read_file_scope would do in the absence of such info. */
3628 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3630 /* Find the filename. Do not use dwarf2_name here, since the filename
3631 is not a source language identifier. */
3632 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3634 name
= DW_STRING (attr
);
3636 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3638 comp_dir
= DW_STRING (attr
);
3639 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3641 comp_dir
= ldirname (name
);
3642 if (comp_dir
!= NULL
)
3643 make_cleanup (xfree
, comp_dir
);
3649 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3651 set_cu_language (DW_UNSND (attr
), cu
);
3653 /* This isn't technically needed today. It is done for symmetry
3654 with read_file_scope. */
3655 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3657 cu
->producer
= DW_STRING (attr
);
3659 /* We assume that we're processing GCC output. */
3660 processing_gcc_compilation
= 2;
3662 processing_has_namespace_info
= 0;
3664 start_symtab (name
, comp_dir
, lowpc
);
3665 record_debugformat ("DWARF 2");
3666 record_producer (cu
->producer
);
3668 /* Process the dies in the type unit. */
3669 if (die
->child
== NULL
)
3671 dump_die_for_error (die
);
3672 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3673 bfd_get_filename (abfd
));
3676 child_die
= die
->child
;
3678 while (child_die
&& child_die
->tag
)
3680 process_die (child_die
, cu
);
3682 child_die
= sibling_die (child_die
);
3685 do_cleanups (back_to
);
3689 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3690 struct dwarf2_cu
*cu
)
3692 struct function_range
*thisfn
;
3694 thisfn
= (struct function_range
*)
3695 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3696 thisfn
->name
= name
;
3697 thisfn
->lowpc
= lowpc
;
3698 thisfn
->highpc
= highpc
;
3699 thisfn
->seen_line
= 0;
3700 thisfn
->next
= NULL
;
3702 if (cu
->last_fn
== NULL
)
3703 cu
->first_fn
= thisfn
;
3705 cu
->last_fn
->next
= thisfn
;
3707 cu
->last_fn
= thisfn
;
3710 /* qsort helper for inherit_abstract_dies. */
3713 unsigned_int_compar (const void *ap
, const void *bp
)
3715 unsigned int a
= *(unsigned int *) ap
;
3716 unsigned int b
= *(unsigned int *) bp
;
3718 return (a
> b
) - (b
> a
);
3721 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3722 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3723 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3726 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3728 struct die_info
*child_die
;
3729 unsigned die_children_count
;
3730 /* CU offsets which were referenced by children of the current DIE. */
3732 unsigned *offsets_end
, *offsetp
;
3733 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3734 struct die_info
*origin_die
;
3735 /* Iterator of the ORIGIN_DIE children. */
3736 struct die_info
*origin_child_die
;
3737 struct cleanup
*cleanups
;
3738 struct attribute
*attr
;
3740 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3744 origin_die
= follow_die_ref (die
, attr
, &cu
);
3745 if (die
->tag
!= origin_die
->tag
3746 && !(die
->tag
== DW_TAG_inlined_subroutine
3747 && origin_die
->tag
== DW_TAG_subprogram
))
3748 complaint (&symfile_complaints
,
3749 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3750 die
->offset
, origin_die
->offset
);
3752 child_die
= die
->child
;
3753 die_children_count
= 0;
3754 while (child_die
&& child_die
->tag
)
3756 child_die
= sibling_die (child_die
);
3757 die_children_count
++;
3759 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3760 cleanups
= make_cleanup (xfree
, offsets
);
3762 offsets_end
= offsets
;
3763 child_die
= die
->child
;
3764 while (child_die
&& child_die
->tag
)
3766 /* For each CHILD_DIE, find the corresponding child of
3767 ORIGIN_DIE. If there is more than one layer of
3768 DW_AT_abstract_origin, follow them all; there shouldn't be,
3769 but GCC versions at least through 4.4 generate this (GCC PR
3771 struct die_info
*child_origin_die
= child_die
;
3774 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
3777 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
3780 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3781 counterpart may exist. */
3782 if (child_origin_die
!= child_die
)
3784 if (child_die
->tag
!= child_origin_die
->tag
3785 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3786 && child_origin_die
->tag
== DW_TAG_subprogram
))
3787 complaint (&symfile_complaints
,
3788 _("Child DIE 0x%x and its abstract origin 0x%x have "
3789 "different tags"), child_die
->offset
,
3790 child_origin_die
->offset
);
3791 if (child_origin_die
->parent
!= origin_die
)
3792 complaint (&symfile_complaints
,
3793 _("Child DIE 0x%x and its abstract origin 0x%x have "
3794 "different parents"), child_die
->offset
,
3795 child_origin_die
->offset
);
3797 *offsets_end
++ = child_origin_die
->offset
;
3799 child_die
= sibling_die (child_die
);
3801 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3802 unsigned_int_compar
);
3803 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3804 if (offsetp
[-1] == *offsetp
)
3805 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3806 "to DIE 0x%x as their abstract origin"),
3807 die
->offset
, *offsetp
);
3810 origin_child_die
= origin_die
->child
;
3811 while (origin_child_die
&& origin_child_die
->tag
)
3813 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3814 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3816 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3818 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3819 process_die (origin_child_die
, cu
);
3821 origin_child_die
= sibling_die (origin_child_die
);
3824 do_cleanups (cleanups
);
3828 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3830 struct objfile
*objfile
= cu
->objfile
;
3831 struct context_stack
*new;
3834 struct die_info
*child_die
;
3835 struct attribute
*attr
, *call_line
, *call_file
;
3838 struct block
*block
;
3839 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3843 /* If we do not have call site information, we can't show the
3844 caller of this inlined function. That's too confusing, so
3845 only use the scope for local variables. */
3846 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3847 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3848 if (call_line
== NULL
|| call_file
== NULL
)
3850 read_lexical_block_scope (die
, cu
);
3855 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3857 name
= dwarf2_name (die
, cu
);
3859 /* Ignore functions with missing or empty names and functions with
3860 missing or invalid low and high pc attributes. */
3861 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3867 /* Record the function range for dwarf_decode_lines. */
3868 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3870 new = push_context (0, lowpc
);
3871 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3873 /* If there is a location expression for DW_AT_frame_base, record
3875 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3877 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3878 expression is being recorded directly in the function's symbol
3879 and not in a separate frame-base object. I guess this hack is
3880 to avoid adding some sort of frame-base adjunct/annex to the
3881 function's symbol :-(. The problem with doing this is that it
3882 results in a function symbol with a location expression that
3883 has nothing to do with the location of the function, ouch! The
3884 relationship should be: a function's symbol has-a frame base; a
3885 frame-base has-a location expression. */
3886 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3888 cu
->list_in_scope
= &local_symbols
;
3890 if (die
->child
!= NULL
)
3892 child_die
= die
->child
;
3893 while (child_die
&& child_die
->tag
)
3895 process_die (child_die
, cu
);
3896 child_die
= sibling_die (child_die
);
3900 inherit_abstract_dies (die
, cu
);
3902 new = pop_context ();
3903 /* Make a block for the local symbols within. */
3904 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3905 lowpc
, highpc
, objfile
);
3907 /* For C++, set the block's scope. */
3908 if (cu
->language
== language_cplus
)
3909 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3910 determine_prefix (die
, cu
),
3911 processing_has_namespace_info
);
3913 /* If we have address ranges, record them. */
3914 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3916 /* In C++, we can have functions nested inside functions (e.g., when
3917 a function declares a class that has methods). This means that
3918 when we finish processing a function scope, we may need to go
3919 back to building a containing block's symbol lists. */
3920 local_symbols
= new->locals
;
3921 param_symbols
= new->params
;
3922 using_directives
= new->using_directives
;
3924 /* If we've finished processing a top-level function, subsequent
3925 symbols go in the file symbol list. */
3926 if (outermost_context_p ())
3927 cu
->list_in_scope
= &file_symbols
;
3930 /* Process all the DIES contained within a lexical block scope. Start
3931 a new scope, process the dies, and then close the scope. */
3934 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3936 struct objfile
*objfile
= cu
->objfile
;
3937 struct context_stack
*new;
3938 CORE_ADDR lowpc
, highpc
;
3939 struct die_info
*child_die
;
3942 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3944 /* Ignore blocks with missing or invalid low and high pc attributes. */
3945 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3946 as multiple lexical blocks? Handling children in a sane way would
3947 be nasty. Might be easier to properly extend generic blocks to
3949 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3954 push_context (0, lowpc
);
3955 if (die
->child
!= NULL
)
3957 child_die
= die
->child
;
3958 while (child_die
&& child_die
->tag
)
3960 process_die (child_die
, cu
);
3961 child_die
= sibling_die (child_die
);
3964 new = pop_context ();
3966 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
3969 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3972 /* Note that recording ranges after traversing children, as we
3973 do here, means that recording a parent's ranges entails
3974 walking across all its children's ranges as they appear in
3975 the address map, which is quadratic behavior.
3977 It would be nicer to record the parent's ranges before
3978 traversing its children, simply overriding whatever you find
3979 there. But since we don't even decide whether to create a
3980 block until after we've traversed its children, that's hard
3982 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3984 local_symbols
= new->locals
;
3985 using_directives
= new->using_directives
;
3988 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3989 Return 1 if the attributes are present and valid, otherwise, return 0.
3990 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3993 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3994 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3995 struct partial_symtab
*ranges_pst
)
3997 struct objfile
*objfile
= cu
->objfile
;
3998 struct comp_unit_head
*cu_header
= &cu
->header
;
3999 bfd
*obfd
= objfile
->obfd
;
4000 unsigned int addr_size
= cu_header
->addr_size
;
4001 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4002 /* Base address selection entry. */
4013 found_base
= cu
->base_known
;
4014 base
= cu
->base_address
;
4016 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
4017 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4019 complaint (&symfile_complaints
,
4020 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4024 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4026 /* Read in the largest possible address. */
4027 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
4028 if ((marker
& mask
) == mask
)
4030 /* If we found the largest possible address, then
4031 read the base address. */
4032 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4033 buffer
+= 2 * addr_size
;
4034 offset
+= 2 * addr_size
;
4040 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4044 CORE_ADDR range_beginning
, range_end
;
4046 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
4047 buffer
+= addr_size
;
4048 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
4049 buffer
+= addr_size
;
4050 offset
+= 2 * addr_size
;
4052 /* An end of list marker is a pair of zero addresses. */
4053 if (range_beginning
== 0 && range_end
== 0)
4054 /* Found the end of list entry. */
4057 /* Each base address selection entry is a pair of 2 values.
4058 The first is the largest possible address, the second is
4059 the base address. Check for a base address here. */
4060 if ((range_beginning
& mask
) == mask
)
4062 /* If we found the largest possible address, then
4063 read the base address. */
4064 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4071 /* We have no valid base address for the ranges
4073 complaint (&symfile_complaints
,
4074 _("Invalid .debug_ranges data (no base address)"));
4078 range_beginning
+= base
;
4081 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
4082 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4083 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
4086 /* FIXME: This is recording everything as a low-high
4087 segment of consecutive addresses. We should have a
4088 data structure for discontiguous block ranges
4092 low
= range_beginning
;
4098 if (range_beginning
< low
)
4099 low
= range_beginning
;
4100 if (range_end
> high
)
4106 /* If the first entry is an end-of-list marker, the range
4107 describes an empty scope, i.e. no instructions. */
4113 *high_return
= high
;
4117 /* Get low and high pc attributes from a die. Return 1 if the attributes
4118 are present and valid, otherwise, return 0. Return -1 if the range is
4119 discontinuous, i.e. derived from DW_AT_ranges information. */
4121 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
4122 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
4123 struct partial_symtab
*pst
)
4125 struct attribute
*attr
;
4130 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4133 high
= DW_ADDR (attr
);
4134 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4136 low
= DW_ADDR (attr
);
4138 /* Found high w/o low attribute. */
4141 /* Found consecutive range of addresses. */
4146 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4149 /* Value of the DW_AT_ranges attribute is the offset in the
4150 .debug_ranges section. */
4151 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
4153 /* Found discontinuous range of addresses. */
4161 /* When using the GNU linker, .gnu.linkonce. sections are used to
4162 eliminate duplicate copies of functions and vtables and such.
4163 The linker will arbitrarily choose one and discard the others.
4164 The AT_*_pc values for such functions refer to local labels in
4165 these sections. If the section from that file was discarded, the
4166 labels are not in the output, so the relocs get a value of 0.
4167 If this is a discarded function, mark the pc bounds as invalid,
4168 so that GDB will ignore it. */
4169 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
4177 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4178 its low and high PC addresses. Do nothing if these addresses could not
4179 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4180 and HIGHPC to the high address if greater than HIGHPC. */
4183 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
4184 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4185 struct dwarf2_cu
*cu
)
4187 CORE_ADDR low
, high
;
4188 struct die_info
*child
= die
->child
;
4190 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
4192 *lowpc
= min (*lowpc
, low
);
4193 *highpc
= max (*highpc
, high
);
4196 /* If the language does not allow nested subprograms (either inside
4197 subprograms or lexical blocks), we're done. */
4198 if (cu
->language
!= language_ada
)
4201 /* Check all the children of the given DIE. If it contains nested
4202 subprograms, then check their pc bounds. Likewise, we need to
4203 check lexical blocks as well, as they may also contain subprogram
4205 while (child
&& child
->tag
)
4207 if (child
->tag
== DW_TAG_subprogram
4208 || child
->tag
== DW_TAG_lexical_block
)
4209 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
4210 child
= sibling_die (child
);
4214 /* Get the low and high pc's represented by the scope DIE, and store
4215 them in *LOWPC and *HIGHPC. If the correct values can't be
4216 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4219 get_scope_pc_bounds (struct die_info
*die
,
4220 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4221 struct dwarf2_cu
*cu
)
4223 CORE_ADDR best_low
= (CORE_ADDR
) -1;
4224 CORE_ADDR best_high
= (CORE_ADDR
) 0;
4225 CORE_ADDR current_low
, current_high
;
4227 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
4229 best_low
= current_low
;
4230 best_high
= current_high
;
4234 struct die_info
*child
= die
->child
;
4236 while (child
&& child
->tag
)
4238 switch (child
->tag
) {
4239 case DW_TAG_subprogram
:
4240 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
4242 case DW_TAG_namespace
:
4243 /* FIXME: carlton/2004-01-16: Should we do this for
4244 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4245 that current GCC's always emit the DIEs corresponding
4246 to definitions of methods of classes as children of a
4247 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4248 the DIEs giving the declarations, which could be
4249 anywhere). But I don't see any reason why the
4250 standards says that they have to be there. */
4251 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
4253 if (current_low
!= ((CORE_ADDR
) -1))
4255 best_low
= min (best_low
, current_low
);
4256 best_high
= max (best_high
, current_high
);
4264 child
= sibling_die (child
);
4269 *highpc
= best_high
;
4272 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4275 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
4276 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
4278 struct attribute
*attr
;
4280 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4283 CORE_ADDR high
= DW_ADDR (attr
);
4284 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4287 CORE_ADDR low
= DW_ADDR (attr
);
4288 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
4292 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4295 bfd
*obfd
= cu
->objfile
->obfd
;
4297 /* The value of the DW_AT_ranges attribute is the offset of the
4298 address range list in the .debug_ranges section. */
4299 unsigned long offset
= DW_UNSND (attr
);
4300 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4302 /* For some target architectures, but not others, the
4303 read_address function sign-extends the addresses it returns.
4304 To recognize base address selection entries, we need a
4306 unsigned int addr_size
= cu
->header
.addr_size
;
4307 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4309 /* The base address, to which the next pair is relative. Note
4310 that this 'base' is a DWARF concept: most entries in a range
4311 list are relative, to reduce the number of relocs against the
4312 debugging information. This is separate from this function's
4313 'baseaddr' argument, which GDB uses to relocate debugging
4314 information from a shared library based on the address at
4315 which the library was loaded. */
4316 CORE_ADDR base
= cu
->base_address
;
4317 int base_known
= cu
->base_known
;
4319 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
4320 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4322 complaint (&symfile_complaints
,
4323 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4330 unsigned int bytes_read
;
4331 CORE_ADDR start
, end
;
4333 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4334 buffer
+= bytes_read
;
4335 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4336 buffer
+= bytes_read
;
4338 /* Did we find the end of the range list? */
4339 if (start
== 0 && end
== 0)
4342 /* Did we find a base address selection entry? */
4343 else if ((start
& base_select_mask
) == base_select_mask
)
4349 /* We found an ordinary address range. */
4354 complaint (&symfile_complaints
,
4355 _("Invalid .debug_ranges data (no base address)"));
4359 record_block_range (block
,
4360 baseaddr
+ base
+ start
,
4361 baseaddr
+ base
+ end
- 1);
4367 /* Add an aggregate field to the field list. */
4370 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
4371 struct dwarf2_cu
*cu
)
4373 struct objfile
*objfile
= cu
->objfile
;
4374 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4375 struct nextfield
*new_field
;
4376 struct attribute
*attr
;
4378 char *fieldname
= "";
4380 /* Allocate a new field list entry and link it in. */
4381 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
4382 make_cleanup (xfree
, new_field
);
4383 memset (new_field
, 0, sizeof (struct nextfield
));
4385 if (die
->tag
== DW_TAG_inheritance
)
4387 new_field
->next
= fip
->baseclasses
;
4388 fip
->baseclasses
= new_field
;
4392 new_field
->next
= fip
->fields
;
4393 fip
->fields
= new_field
;
4397 /* Handle accessibility and virtuality of field.
4398 The default accessibility for members is public, the default
4399 accessibility for inheritance is private. */
4400 if (die
->tag
!= DW_TAG_inheritance
)
4401 new_field
->accessibility
= DW_ACCESS_public
;
4403 new_field
->accessibility
= DW_ACCESS_private
;
4404 new_field
->virtuality
= DW_VIRTUALITY_none
;
4406 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4408 new_field
->accessibility
= DW_UNSND (attr
);
4409 if (new_field
->accessibility
!= DW_ACCESS_public
)
4410 fip
->non_public_fields
= 1;
4411 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4413 new_field
->virtuality
= DW_UNSND (attr
);
4415 fp
= &new_field
->field
;
4417 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
4419 /* Data member other than a C++ static data member. */
4421 /* Get type of field. */
4422 fp
->type
= die_type (die
, cu
);
4424 SET_FIELD_BITPOS (*fp
, 0);
4426 /* Get bit size of field (zero if none). */
4427 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
4430 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
4434 FIELD_BITSIZE (*fp
) = 0;
4437 /* Get bit offset of field. */
4438 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4441 int byte_offset
= 0;
4443 if (attr_form_is_section_offset (attr
))
4444 dwarf2_complex_location_expr_complaint ();
4445 else if (attr_form_is_constant (attr
))
4446 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4447 else if (attr_form_is_block (attr
))
4448 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4450 dwarf2_complex_location_expr_complaint ();
4452 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4454 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
4457 if (gdbarch_bits_big_endian (gdbarch
))
4459 /* For big endian bits, the DW_AT_bit_offset gives the
4460 additional bit offset from the MSB of the containing
4461 anonymous object to the MSB of the field. We don't
4462 have to do anything special since we don't need to
4463 know the size of the anonymous object. */
4464 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
4468 /* For little endian bits, compute the bit offset to the
4469 MSB of the anonymous object, subtract off the number of
4470 bits from the MSB of the field to the MSB of the
4471 object, and then subtract off the number of bits of
4472 the field itself. The result is the bit offset of
4473 the LSB of the field. */
4475 int bit_offset
= DW_UNSND (attr
);
4477 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4480 /* The size of the anonymous object containing
4481 the bit field is explicit, so use the
4482 indicated size (in bytes). */
4483 anonymous_size
= DW_UNSND (attr
);
4487 /* The size of the anonymous object containing
4488 the bit field must be inferred from the type
4489 attribute of the data member containing the
4491 anonymous_size
= TYPE_LENGTH (fp
->type
);
4493 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4494 - bit_offset
- FIELD_BITSIZE (*fp
);
4498 /* Get name of field. */
4499 fieldname
= dwarf2_name (die
, cu
);
4500 if (fieldname
== NULL
)
4503 /* The name is already allocated along with this objfile, so we don't
4504 need to duplicate it for the type. */
4505 fp
->name
= fieldname
;
4507 /* Change accessibility for artificial fields (e.g. virtual table
4508 pointer or virtual base class pointer) to private. */
4509 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4511 FIELD_ARTIFICIAL (*fp
) = 1;
4512 new_field
->accessibility
= DW_ACCESS_private
;
4513 fip
->non_public_fields
= 1;
4516 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4518 /* C++ static member. */
4520 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4521 is a declaration, but all versions of G++ as of this writing
4522 (so through at least 3.2.1) incorrectly generate
4523 DW_TAG_variable tags. */
4527 /* Get name of field. */
4528 fieldname
= dwarf2_name (die
, cu
);
4529 if (fieldname
== NULL
)
4532 /* Get physical name. */
4533 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4535 /* The name is already allocated along with this objfile, so we don't
4536 need to duplicate it for the type. */
4537 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4538 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4539 FIELD_NAME (*fp
) = fieldname
;
4541 else if (die
->tag
== DW_TAG_inheritance
)
4543 /* C++ base class field. */
4544 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4547 int byte_offset
= 0;
4549 if (attr_form_is_section_offset (attr
))
4550 dwarf2_complex_location_expr_complaint ();
4551 else if (attr_form_is_constant (attr
))
4552 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4553 else if (attr_form_is_block (attr
))
4554 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4556 dwarf2_complex_location_expr_complaint ();
4558 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4560 FIELD_BITSIZE (*fp
) = 0;
4561 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4562 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4563 fip
->nbaseclasses
++;
4567 /* Create the vector of fields, and attach it to the type. */
4570 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4571 struct dwarf2_cu
*cu
)
4573 int nfields
= fip
->nfields
;
4575 /* Record the field count, allocate space for the array of fields,
4576 and create blank accessibility bitfields if necessary. */
4577 TYPE_NFIELDS (type
) = nfields
;
4578 TYPE_FIELDS (type
) = (struct field
*)
4579 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4580 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4582 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
4584 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4586 TYPE_FIELD_PRIVATE_BITS (type
) =
4587 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4588 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4590 TYPE_FIELD_PROTECTED_BITS (type
) =
4591 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4592 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4594 TYPE_FIELD_IGNORE_BITS (type
) =
4595 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4596 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4599 /* If the type has baseclasses, allocate and clear a bit vector for
4600 TYPE_FIELD_VIRTUAL_BITS. */
4601 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
4603 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4604 unsigned char *pointer
;
4606 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4607 pointer
= TYPE_ALLOC (type
, num_bytes
);
4608 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4609 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4610 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4613 /* Copy the saved-up fields into the field vector. Start from the head
4614 of the list, adding to the tail of the field array, so that they end
4615 up in the same order in the array in which they were added to the list. */
4616 while (nfields
-- > 0)
4618 struct nextfield
*fieldp
;
4622 fieldp
= fip
->fields
;
4623 fip
->fields
= fieldp
->next
;
4627 fieldp
= fip
->baseclasses
;
4628 fip
->baseclasses
= fieldp
->next
;
4631 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
4632 switch (fieldp
->accessibility
)
4634 case DW_ACCESS_private
:
4635 if (cu
->language
!= language_ada
)
4636 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4639 case DW_ACCESS_protected
:
4640 if (cu
->language
!= language_ada
)
4641 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4644 case DW_ACCESS_public
:
4648 /* Unknown accessibility. Complain and treat it as public. */
4650 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4651 fieldp
->accessibility
);
4655 if (nfields
< fip
->nbaseclasses
)
4657 switch (fieldp
->virtuality
)
4659 case DW_VIRTUALITY_virtual
:
4660 case DW_VIRTUALITY_pure_virtual
:
4661 if (cu
->language
== language_ada
)
4662 error ("unexpected virtuality in component of Ada type");
4663 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4670 /* Add a member function to the proper fieldlist. */
4673 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4674 struct type
*type
, struct dwarf2_cu
*cu
)
4676 struct objfile
*objfile
= cu
->objfile
;
4677 struct attribute
*attr
;
4678 struct fnfieldlist
*flp
;
4680 struct fn_field
*fnp
;
4683 struct nextfnfield
*new_fnfield
;
4684 struct type
*this_type
;
4686 if (cu
->language
== language_ada
)
4687 error ("unexpected member function in Ada type");
4689 /* Get name of member function. */
4690 fieldname
= dwarf2_name (die
, cu
);
4691 if (fieldname
== NULL
)
4694 /* Get the mangled name. */
4695 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4697 /* Look up member function name in fieldlist. */
4698 for (i
= 0; i
< fip
->nfnfields
; i
++)
4700 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4704 /* Create new list element if necessary. */
4705 if (i
< fip
->nfnfields
)
4706 flp
= &fip
->fnfieldlists
[i
];
4709 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4711 fip
->fnfieldlists
= (struct fnfieldlist
*)
4712 xrealloc (fip
->fnfieldlists
,
4713 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4714 * sizeof (struct fnfieldlist
));
4715 if (fip
->nfnfields
== 0)
4716 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4718 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4719 flp
->name
= fieldname
;
4725 /* Create a new member function field and chain it to the field list
4727 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4728 make_cleanup (xfree
, new_fnfield
);
4729 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4730 new_fnfield
->next
= flp
->head
;
4731 flp
->head
= new_fnfield
;
4734 /* Fill in the member function field info. */
4735 fnp
= &new_fnfield
->fnfield
;
4736 /* The name is already allocated along with this objfile, so we don't
4737 need to duplicate it for the type. */
4738 fnp
->physname
= physname
? physname
: "";
4739 fnp
->type
= alloc_type (objfile
);
4740 this_type
= read_type_die (die
, cu
);
4741 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4743 int nparams
= TYPE_NFIELDS (this_type
);
4745 /* TYPE is the domain of this method, and THIS_TYPE is the type
4746 of the method itself (TYPE_CODE_METHOD). */
4747 smash_to_method_type (fnp
->type
, type
,
4748 TYPE_TARGET_TYPE (this_type
),
4749 TYPE_FIELDS (this_type
),
4750 TYPE_NFIELDS (this_type
),
4751 TYPE_VARARGS (this_type
));
4753 /* Handle static member functions.
4754 Dwarf2 has no clean way to discern C++ static and non-static
4755 member functions. G++ helps GDB by marking the first
4756 parameter for non-static member functions (which is the
4757 this pointer) as artificial. We obtain this information
4758 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4759 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4760 fnp
->voffset
= VOFFSET_STATIC
;
4763 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4766 /* Get fcontext from DW_AT_containing_type if present. */
4767 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4768 fnp
->fcontext
= die_containing_type (die
, cu
);
4770 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4771 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4773 /* Get accessibility. */
4774 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4777 switch (DW_UNSND (attr
))
4779 case DW_ACCESS_private
:
4780 fnp
->is_private
= 1;
4782 case DW_ACCESS_protected
:
4783 fnp
->is_protected
= 1;
4788 /* Check for artificial methods. */
4789 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4790 if (attr
&& DW_UNSND (attr
) != 0)
4791 fnp
->is_artificial
= 1;
4793 /* Get index in virtual function table if it is a virtual member
4794 function. For GCC, this is an offset in the appropriate
4795 virtual table, as specified by DW_AT_containing_type. For
4796 everyone else, it is an expression to be evaluated relative
4797 to the object address. */
4799 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4800 if (attr
&& fnp
->fcontext
)
4802 /* Support the .debug_loc offsets */
4803 if (attr_form_is_block (attr
))
4805 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4807 else if (attr_form_is_section_offset (attr
))
4809 dwarf2_complex_location_expr_complaint ();
4813 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4819 /* We only support trivial expressions here. This hack will work
4820 for v3 classes, which always start with the vtable pointer. */
4821 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0
4822 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref
)
4824 struct dwarf_block blk
;
4825 blk
.size
= DW_BLOCK (attr
)->size
- 1;
4826 blk
.data
= DW_BLOCK (attr
)->data
+ 1;
4827 fnp
->voffset
= decode_locdesc (&blk
, cu
);
4828 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
4829 dwarf2_complex_location_expr_complaint ();
4831 fnp
->voffset
/= cu
->header
.addr_size
;
4833 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
4836 dwarf2_complex_location_expr_complaint ();
4840 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4841 if (attr
&& DW_UNSND (attr
))
4843 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4844 complaint (&symfile_complaints
,
4845 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4846 fieldname
, die
->offset
);
4847 TYPE_CPLUS_DYNAMIC (type
) = 1;
4852 /* Create the vector of member function fields, and attach it to the type. */
4855 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4856 struct dwarf2_cu
*cu
)
4858 struct fnfieldlist
*flp
;
4859 int total_length
= 0;
4862 if (cu
->language
== language_ada
)
4863 error ("unexpected member functions in Ada type");
4865 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4866 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4867 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4869 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4871 struct nextfnfield
*nfp
= flp
->head
;
4872 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4875 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4876 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4877 fn_flp
->fn_fields
= (struct fn_field
*)
4878 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4879 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4880 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4882 total_length
+= flp
->length
;
4885 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4886 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4889 /* Returns non-zero if NAME is the name of a vtable member in CU's
4890 language, zero otherwise. */
4892 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4894 static const char vptr
[] = "_vptr";
4895 static const char vtable
[] = "vtable";
4897 /* Look for the C++ and Java forms of the vtable. */
4898 if ((cu
->language
== language_java
4899 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4900 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4901 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4907 /* GCC outputs unnamed structures that are really pointers to member
4908 functions, with the ABI-specified layout. If TYPE describes
4909 such a structure, smash it into a member function type.
4911 GCC shouldn't do this; it should just output pointer to member DIEs.
4912 This is GCC PR debug/28767. */
4915 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
4917 struct type
*pfn_type
, *domain_type
, *new_type
;
4919 /* Check for a structure with no name and two children. */
4920 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
4923 /* Check for __pfn and __delta members. */
4924 if (TYPE_FIELD_NAME (type
, 0) == NULL
4925 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
4926 || TYPE_FIELD_NAME (type
, 1) == NULL
4927 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
4930 /* Find the type of the method. */
4931 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
4932 if (pfn_type
== NULL
4933 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4934 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4937 /* Look for the "this" argument. */
4938 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4939 if (TYPE_NFIELDS (pfn_type
) == 0
4940 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
4941 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4944 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4945 new_type
= alloc_type (objfile
);
4946 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4947 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4948 TYPE_VARARGS (pfn_type
));
4949 smash_to_methodptr_type (type
, new_type
);
4952 /* Called when we find the DIE that starts a structure or union scope
4953 (definition) to process all dies that define the members of the
4956 NOTE: we need to call struct_type regardless of whether or not the
4957 DIE has an at_name attribute, since it might be an anonymous
4958 structure or union. This gets the type entered into our set of
4961 However, if the structure is incomplete (an opaque struct/union)
4962 then suppress creating a symbol table entry for it since gdb only
4963 wants to find the one with the complete definition. Note that if
4964 it is complete, we just call new_symbol, which does it's own
4965 checking about whether the struct/union is anonymous or not (and
4966 suppresses creating a symbol table entry itself). */
4968 static struct type
*
4969 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4971 struct objfile
*objfile
= cu
->objfile
;
4973 struct attribute
*attr
;
4975 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4977 /* If the definition of this type lives in .debug_types, read that type.
4978 Don't follow DW_AT_specification though, that will take us back up
4979 the chain and we want to go down. */
4980 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
4983 struct dwarf2_cu
*type_cu
= cu
;
4984 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
4985 /* We could just recurse on read_structure_type, but we need to call
4986 get_die_type to ensure only one type for this DIE is created.
4987 This is important, for example, because for c++ classes we need
4988 TYPE_NAME set which is only done by new_symbol. Blech. */
4989 type
= read_type_die (type_die
, type_cu
);
4990 return set_die_type (die
, type
, cu
);
4993 type
= alloc_type (objfile
);
4994 INIT_CPLUS_SPECIFIC (type
);
4996 name
= dwarf2_name (die
, cu
);
4999 if (cu
->language
== language_cplus
5000 || cu
->language
== language_java
)
5002 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
5003 if (die
->tag
== DW_TAG_structure_type
5004 || die
->tag
== DW_TAG_class_type
)
5005 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5009 /* The name is already allocated along with this objfile, so
5010 we don't need to duplicate it for the type. */
5011 TYPE_TAG_NAME (type
) = (char *) name
;
5012 if (die
->tag
== DW_TAG_class_type
)
5013 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5017 if (die
->tag
== DW_TAG_structure_type
)
5019 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
5021 else if (die
->tag
== DW_TAG_union_type
)
5023 TYPE_CODE (type
) = TYPE_CODE_UNION
;
5027 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
5030 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
5031 TYPE_DECLARED_CLASS (type
) = 1;
5033 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5036 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5040 TYPE_LENGTH (type
) = 0;
5043 TYPE_STUB_SUPPORTED (type
) = 1;
5044 if (die_is_declaration (die
, cu
))
5045 TYPE_STUB (type
) = 1;
5047 set_descriptive_type (type
, die
, cu
);
5049 /* We need to add the type field to the die immediately so we don't
5050 infinitely recurse when dealing with pointers to the structure
5051 type within the structure itself. */
5052 set_die_type (die
, type
, cu
);
5054 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
5056 struct field_info fi
;
5057 struct die_info
*child_die
;
5059 memset (&fi
, 0, sizeof (struct field_info
));
5061 child_die
= die
->child
;
5063 while (child_die
&& child_die
->tag
)
5065 if (child_die
->tag
== DW_TAG_member
5066 || child_die
->tag
== DW_TAG_variable
)
5068 /* NOTE: carlton/2002-11-05: A C++ static data member
5069 should be a DW_TAG_member that is a declaration, but
5070 all versions of G++ as of this writing (so through at
5071 least 3.2.1) incorrectly generate DW_TAG_variable
5072 tags for them instead. */
5073 dwarf2_add_field (&fi
, child_die
, cu
);
5075 else if (child_die
->tag
== DW_TAG_subprogram
)
5077 /* C++ member function. */
5078 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
5080 else if (child_die
->tag
== DW_TAG_inheritance
)
5082 /* C++ base class field. */
5083 dwarf2_add_field (&fi
, child_die
, cu
);
5085 child_die
= sibling_die (child_die
);
5088 /* Attach fields and member functions to the type. */
5090 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
5093 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
5095 /* Get the type which refers to the base class (possibly this
5096 class itself) which contains the vtable pointer for the current
5097 class from the DW_AT_containing_type attribute. This use of
5098 DW_AT_containing_type is a GNU extension. */
5100 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5102 struct type
*t
= die_containing_type (die
, cu
);
5104 TYPE_VPTR_BASETYPE (type
) = t
;
5109 /* Our own class provides vtbl ptr. */
5110 for (i
= TYPE_NFIELDS (t
) - 1;
5111 i
>= TYPE_N_BASECLASSES (t
);
5114 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
5116 if (is_vtable_name (fieldname
, cu
))
5118 TYPE_VPTR_FIELDNO (type
) = i
;
5123 /* Complain if virtual function table field not found. */
5124 if (i
< TYPE_N_BASECLASSES (t
))
5125 complaint (&symfile_complaints
,
5126 _("virtual function table pointer not found when defining class '%s'"),
5127 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
5132 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
5135 else if (cu
->producer
5136 && strncmp (cu
->producer
,
5137 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5139 /* The IBM XLC compiler does not provide direct indication
5140 of the containing type, but the vtable pointer is
5141 always named __vfp. */
5145 for (i
= TYPE_NFIELDS (type
) - 1;
5146 i
>= TYPE_N_BASECLASSES (type
);
5149 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
5151 TYPE_VPTR_FIELDNO (type
) = i
;
5152 TYPE_VPTR_BASETYPE (type
) = type
;
5160 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
5162 do_cleanups (back_to
);
5167 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5169 struct objfile
*objfile
= cu
->objfile
;
5170 struct die_info
*child_die
= die
->child
;
5171 struct type
*this_type
;
5173 this_type
= get_die_type (die
, cu
);
5174 if (this_type
== NULL
)
5175 this_type
= read_structure_type (die
, cu
);
5177 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5178 snapshots) has been known to create a die giving a declaration
5179 for a class that has, as a child, a die giving a definition for a
5180 nested class. So we have to process our children even if the
5181 current die is a declaration. Normally, of course, a declaration
5182 won't have any children at all. */
5184 while (child_die
!= NULL
&& child_die
->tag
)
5186 if (child_die
->tag
== DW_TAG_member
5187 || child_die
->tag
== DW_TAG_variable
5188 || child_die
->tag
== DW_TAG_inheritance
)
5193 process_die (child_die
, cu
);
5195 child_die
= sibling_die (child_die
);
5198 /* Do not consider external references. According to the DWARF standard,
5199 these DIEs are identified by the fact that they have no byte_size
5200 attribute, and a declaration attribute. */
5201 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
5202 || !die_is_declaration (die
, cu
))
5203 new_symbol (die
, this_type
, cu
);
5206 /* Given a DW_AT_enumeration_type die, set its type. We do not
5207 complete the type's fields yet, or create any symbols. */
5209 static struct type
*
5210 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5212 struct objfile
*objfile
= cu
->objfile
;
5214 struct attribute
*attr
;
5217 /* If the definition of this type lives in .debug_types, read that type.
5218 Don't follow DW_AT_specification though, that will take us back up
5219 the chain and we want to go down. */
5220 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5223 struct dwarf2_cu
*type_cu
= cu
;
5224 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5225 type
= read_type_die (type_die
, type_cu
);
5226 return set_die_type (die
, type
, cu
);
5229 type
= alloc_type (objfile
);
5231 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
5232 name
= dwarf2_full_name (NULL
, die
, cu
);
5234 TYPE_TAG_NAME (type
) = (char *) name
;
5236 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5239 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5243 TYPE_LENGTH (type
) = 0;
5246 /* The enumeration DIE can be incomplete. In Ada, any type can be
5247 declared as private in the package spec, and then defined only
5248 inside the package body. Such types are known as Taft Amendment
5249 Types. When another package uses such a type, an incomplete DIE
5250 may be generated by the compiler. */
5251 if (die_is_declaration (die
, cu
))
5252 TYPE_STUB (type
) = 1;
5254 return set_die_type (die
, type
, cu
);
5257 /* Given a pointer to a die which begins an enumeration, process all
5258 the dies that define the members of the enumeration, and create the
5259 symbol for the enumeration type.
5261 NOTE: We reverse the order of the element list. */
5264 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5266 struct objfile
*objfile
= cu
->objfile
;
5267 struct die_info
*child_die
;
5268 struct field
*fields
;
5271 int unsigned_enum
= 1;
5273 struct type
*this_type
;
5277 this_type
= get_die_type (die
, cu
);
5278 if (this_type
== NULL
)
5279 this_type
= read_enumeration_type (die
, cu
);
5280 if (die
->child
!= NULL
)
5282 child_die
= die
->child
;
5283 while (child_die
&& child_die
->tag
)
5285 if (child_die
->tag
!= DW_TAG_enumerator
)
5287 process_die (child_die
, cu
);
5291 name
= dwarf2_name (child_die
, cu
);
5294 sym
= new_symbol (child_die
, this_type
, cu
);
5295 if (SYMBOL_VALUE (sym
) < 0)
5298 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5300 fields
= (struct field
*)
5302 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
5303 * sizeof (struct field
));
5306 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
5307 FIELD_TYPE (fields
[num_fields
]) = NULL
;
5308 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
5309 FIELD_BITSIZE (fields
[num_fields
]) = 0;
5315 child_die
= sibling_die (child_die
);
5320 TYPE_NFIELDS (this_type
) = num_fields
;
5321 TYPE_FIELDS (this_type
) = (struct field
*)
5322 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
5323 memcpy (TYPE_FIELDS (this_type
), fields
,
5324 sizeof (struct field
) * num_fields
);
5328 TYPE_UNSIGNED (this_type
) = 1;
5331 new_symbol (die
, this_type
, cu
);
5334 /* Extract all information from a DW_TAG_array_type DIE and put it in
5335 the DIE's type field. For now, this only handles one dimensional
5338 static struct type
*
5339 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5341 struct objfile
*objfile
= cu
->objfile
;
5342 struct die_info
*child_die
;
5343 struct type
*type
= NULL
;
5344 struct type
*element_type
, *range_type
, *index_type
;
5345 struct type
**range_types
= NULL
;
5346 struct attribute
*attr
;
5348 struct cleanup
*back_to
;
5351 element_type
= die_type (die
, cu
);
5353 /* Irix 6.2 native cc creates array types without children for
5354 arrays with unspecified length. */
5355 if (die
->child
== NULL
)
5357 index_type
= objfile_type (objfile
)->builtin_int
;
5358 range_type
= create_range_type (NULL
, index_type
, 0, -1);
5359 type
= create_array_type (NULL
, element_type
, range_type
);
5360 return set_die_type (die
, type
, cu
);
5363 back_to
= make_cleanup (null_cleanup
, NULL
);
5364 child_die
= die
->child
;
5365 while (child_die
&& child_die
->tag
)
5367 if (child_die
->tag
== DW_TAG_subrange_type
)
5369 struct type
*child_type
= read_type_die (child_die
, cu
);
5370 if (child_type
!= NULL
)
5372 /* The range type was succesfully read. Save it for
5373 the array type creation. */
5374 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
5376 range_types
= (struct type
**)
5377 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
5378 * sizeof (struct type
*));
5380 make_cleanup (free_current_contents
, &range_types
);
5382 range_types
[ndim
++] = child_type
;
5385 child_die
= sibling_die (child_die
);
5388 /* Dwarf2 dimensions are output from left to right, create the
5389 necessary array types in backwards order. */
5391 type
= element_type
;
5393 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
5397 type
= create_array_type (NULL
, type
, range_types
[i
++]);
5402 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
5405 /* Understand Dwarf2 support for vector types (like they occur on
5406 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5407 array type. This is not part of the Dwarf2/3 standard yet, but a
5408 custom vendor extension. The main difference between a regular
5409 array and the vector variant is that vectors are passed by value
5411 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
5413 make_vector_type (type
);
5415 name
= dwarf2_name (die
, cu
);
5417 TYPE_NAME (type
) = name
;
5419 set_descriptive_type (type
, die
, cu
);
5421 do_cleanups (back_to
);
5423 /* Install the type in the die. */
5424 return set_die_type (die
, type
, cu
);
5427 static enum dwarf_array_dim_ordering
5428 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
5430 struct attribute
*attr
;
5432 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
5434 if (attr
) return DW_SND (attr
);
5437 GNU F77 is a special case, as at 08/2004 array type info is the
5438 opposite order to the dwarf2 specification, but data is still
5439 laid out as per normal fortran.
5441 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5445 if (cu
->language
== language_fortran
5446 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
5448 return DW_ORD_row_major
;
5451 switch (cu
->language_defn
->la_array_ordering
)
5453 case array_column_major
:
5454 return DW_ORD_col_major
;
5455 case array_row_major
:
5457 return DW_ORD_row_major
;
5461 /* Extract all information from a DW_TAG_set_type DIE and put it in
5462 the DIE's type field. */
5464 static struct type
*
5465 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5467 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
5469 return set_die_type (die
, set_type
, cu
);
5472 /* First cut: install each common block member as a global variable. */
5475 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
5477 struct die_info
*child_die
;
5478 struct attribute
*attr
;
5480 CORE_ADDR base
= (CORE_ADDR
) 0;
5482 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5485 /* Support the .debug_loc offsets */
5486 if (attr_form_is_block (attr
))
5488 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
5490 else if (attr_form_is_section_offset (attr
))
5492 dwarf2_complex_location_expr_complaint ();
5496 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5497 "common block member");
5500 if (die
->child
!= NULL
)
5502 child_die
= die
->child
;
5503 while (child_die
&& child_die
->tag
)
5505 sym
= new_symbol (child_die
, NULL
, cu
);
5506 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
5509 CORE_ADDR byte_offset
= 0;
5511 if (attr_form_is_section_offset (attr
))
5512 dwarf2_complex_location_expr_complaint ();
5513 else if (attr_form_is_constant (attr
))
5514 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5515 else if (attr_form_is_block (attr
))
5516 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5518 dwarf2_complex_location_expr_complaint ();
5520 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
5521 add_symbol_to_list (sym
, &global_symbols
);
5523 child_die
= sibling_die (child_die
);
5528 /* Create a type for a C++ namespace. */
5530 static struct type
*
5531 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5533 struct objfile
*objfile
= cu
->objfile
;
5534 const char *previous_prefix
, *name
;
5538 /* For extensions, reuse the type of the original namespace. */
5539 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5541 struct die_info
*ext_die
;
5542 struct dwarf2_cu
*ext_cu
= cu
;
5543 ext_die
= dwarf2_extension (die
, &ext_cu
);
5544 type
= read_type_die (ext_die
, ext_cu
);
5545 return set_die_type (die
, type
, cu
);
5548 name
= namespace_name (die
, &is_anonymous
, cu
);
5550 /* Now build the name of the current namespace. */
5552 previous_prefix
= determine_prefix (die
, cu
);
5553 if (previous_prefix
[0] != '\0')
5554 name
= typename_concat (&objfile
->objfile_obstack
,
5555 previous_prefix
, name
, cu
);
5557 /* Create the type. */
5558 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5560 TYPE_NAME (type
) = (char *) name
;
5561 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5563 set_die_type (die
, type
, cu
);
5568 /* Read a C++ namespace. */
5571 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5573 struct objfile
*objfile
= cu
->objfile
;
5577 /* Add a symbol associated to this if we haven't seen the namespace
5578 before. Also, add a using directive if it's an anonymous
5581 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5585 type
= read_type_die (die
, cu
);
5586 new_symbol (die
, type
, cu
);
5588 name
= namespace_name (die
, &is_anonymous
, cu
);
5591 const char *previous_prefix
= determine_prefix (die
, cu
);
5592 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
5593 NULL
, &objfile
->objfile_obstack
);
5597 if (die
->child
!= NULL
)
5599 struct die_info
*child_die
= die
->child
;
5601 while (child_die
&& child_die
->tag
)
5603 process_die (child_die
, cu
);
5604 child_die
= sibling_die (child_die
);
5609 /* Read a Fortran module. */
5612 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5614 struct die_info
*child_die
= die
->child
;
5616 /* FIXME: Support the separate Fortran module namespaces. */
5618 while (child_die
&& child_die
->tag
)
5620 process_die (child_die
, cu
);
5621 child_die
= sibling_die (child_die
);
5625 /* Return the name of the namespace represented by DIE. Set
5626 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5630 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5632 struct die_info
*current_die
;
5633 const char *name
= NULL
;
5635 /* Loop through the extensions until we find a name. */
5637 for (current_die
= die
;
5638 current_die
!= NULL
;
5639 current_die
= dwarf2_extension (die
, &cu
))
5641 name
= dwarf2_name (current_die
, cu
);
5646 /* Is it an anonymous namespace? */
5648 *is_anonymous
= (name
== NULL
);
5650 name
= "(anonymous namespace)";
5655 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5656 the user defined type vector. */
5658 static struct type
*
5659 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5661 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5662 struct comp_unit_head
*cu_header
= &cu
->header
;
5664 struct attribute
*attr_byte_size
;
5665 struct attribute
*attr_address_class
;
5666 int byte_size
, addr_class
;
5668 type
= lookup_pointer_type (die_type (die
, cu
));
5670 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5672 byte_size
= DW_UNSND (attr_byte_size
);
5674 byte_size
= cu_header
->addr_size
;
5676 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5677 if (attr_address_class
)
5678 addr_class
= DW_UNSND (attr_address_class
);
5680 addr_class
= DW_ADDR_none
;
5682 /* If the pointer size or address class is different than the
5683 default, create a type variant marked as such and set the
5684 length accordingly. */
5685 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5687 if (gdbarch_address_class_type_flags_p (gdbarch
))
5691 type_flags
= gdbarch_address_class_type_flags
5692 (gdbarch
, byte_size
, addr_class
);
5693 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5695 type
= make_type_with_address_space (type
, type_flags
);
5697 else if (TYPE_LENGTH (type
) != byte_size
)
5699 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5702 /* Should we also complain about unhandled address classes? */
5706 TYPE_LENGTH (type
) = byte_size
;
5707 return set_die_type (die
, type
, cu
);
5710 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5711 the user defined type vector. */
5713 static struct type
*
5714 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5716 struct objfile
*objfile
= cu
->objfile
;
5718 struct type
*to_type
;
5719 struct type
*domain
;
5721 to_type
= die_type (die
, cu
);
5722 domain
= die_containing_type (die
, cu
);
5724 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5725 type
= lookup_methodptr_type (to_type
);
5727 type
= lookup_memberptr_type (to_type
, domain
);
5729 return set_die_type (die
, type
, cu
);
5732 /* Extract all information from a DW_TAG_reference_type DIE and add to
5733 the user defined type vector. */
5735 static struct type
*
5736 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5738 struct comp_unit_head
*cu_header
= &cu
->header
;
5740 struct attribute
*attr
;
5742 type
= lookup_reference_type (die_type (die
, cu
));
5743 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5746 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5750 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5752 return set_die_type (die
, type
, cu
);
5755 static struct type
*
5756 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5758 struct type
*base_type
, *cv_type
;
5760 base_type
= die_type (die
, cu
);
5761 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5762 return set_die_type (die
, cv_type
, cu
);
5765 static struct type
*
5766 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5768 struct type
*base_type
, *cv_type
;
5770 base_type
= die_type (die
, cu
);
5771 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5772 return set_die_type (die
, cv_type
, cu
);
5775 /* Extract all information from a DW_TAG_string_type DIE and add to
5776 the user defined type vector. It isn't really a user defined type,
5777 but it behaves like one, with other DIE's using an AT_user_def_type
5778 attribute to reference it. */
5780 static struct type
*
5781 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5783 struct objfile
*objfile
= cu
->objfile
;
5784 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5785 struct type
*type
, *range_type
, *index_type
, *char_type
;
5786 struct attribute
*attr
;
5787 unsigned int length
;
5789 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5792 length
= DW_UNSND (attr
);
5796 /* check for the DW_AT_byte_size attribute */
5797 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5800 length
= DW_UNSND (attr
);
5808 index_type
= objfile_type (objfile
)->builtin_int
;
5809 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5810 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5811 type
= create_string_type (NULL
, char_type
, range_type
);
5813 return set_die_type (die
, type
, cu
);
5816 /* Handle DIES due to C code like:
5820 int (*funcp)(int a, long l);
5824 ('funcp' generates a DW_TAG_subroutine_type DIE)
5827 static struct type
*
5828 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5830 struct type
*type
; /* Type that this function returns */
5831 struct type
*ftype
; /* Function that returns above type */
5832 struct attribute
*attr
;
5834 type
= die_type (die
, cu
);
5835 ftype
= lookup_function_type (type
);
5837 /* All functions in C++, Pascal and Java have prototypes. */
5838 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5839 if ((attr
&& (DW_UNSND (attr
) != 0))
5840 || cu
->language
== language_cplus
5841 || cu
->language
== language_java
5842 || cu
->language
== language_pascal
)
5843 TYPE_PROTOTYPED (ftype
) = 1;
5845 /* Store the calling convention in the type if it's available in
5846 the subroutine die. Otherwise set the calling convention to
5847 the default value DW_CC_normal. */
5848 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5849 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5851 /* We need to add the subroutine type to the die immediately so
5852 we don't infinitely recurse when dealing with parameters
5853 declared as the same subroutine type. */
5854 set_die_type (die
, ftype
, cu
);
5856 if (die
->child
!= NULL
)
5858 struct die_info
*child_die
;
5862 /* Count the number of parameters.
5863 FIXME: GDB currently ignores vararg functions, but knows about
5864 vararg member functions. */
5865 child_die
= die
->child
;
5866 while (child_die
&& child_die
->tag
)
5868 if (child_die
->tag
== DW_TAG_formal_parameter
)
5870 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5871 TYPE_VARARGS (ftype
) = 1;
5872 child_die
= sibling_die (child_die
);
5875 /* Allocate storage for parameters and fill them in. */
5876 TYPE_NFIELDS (ftype
) = nparams
;
5877 TYPE_FIELDS (ftype
) = (struct field
*)
5878 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5880 child_die
= die
->child
;
5881 while (child_die
&& child_die
->tag
)
5883 if (child_die
->tag
== DW_TAG_formal_parameter
)
5885 /* Dwarf2 has no clean way to discern C++ static and non-static
5886 member functions. G++ helps GDB by marking the first
5887 parameter for non-static member functions (which is the
5888 this pointer) as artificial. We pass this information
5889 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5890 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5892 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5894 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5895 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5898 child_die
= sibling_die (child_die
);
5905 static struct type
*
5906 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5908 struct objfile
*objfile
= cu
->objfile
;
5909 struct attribute
*attr
;
5910 const char *name
= NULL
;
5911 struct type
*this_type
;
5913 name
= dwarf2_full_name (NULL
, die
, cu
);
5914 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5915 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5916 TYPE_NAME (this_type
) = (char *) name
;
5917 set_die_type (die
, this_type
, cu
);
5918 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5922 /* Find a representation of a given base type and install
5923 it in the TYPE field of the die. */
5925 static struct type
*
5926 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5928 struct objfile
*objfile
= cu
->objfile
;
5930 struct attribute
*attr
;
5931 int encoding
= 0, size
= 0;
5933 enum type_code code
= TYPE_CODE_INT
;
5935 struct type
*target_type
= NULL
;
5937 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5940 encoding
= DW_UNSND (attr
);
5942 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5945 size
= DW_UNSND (attr
);
5947 name
= dwarf2_name (die
, cu
);
5950 complaint (&symfile_complaints
,
5951 _("DW_AT_name missing from DW_TAG_base_type"));
5956 case DW_ATE_address
:
5957 /* Turn DW_ATE_address into a void * pointer. */
5958 code
= TYPE_CODE_PTR
;
5959 type_flags
|= TYPE_FLAG_UNSIGNED
;
5960 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5962 case DW_ATE_boolean
:
5963 code
= TYPE_CODE_BOOL
;
5964 type_flags
|= TYPE_FLAG_UNSIGNED
;
5966 case DW_ATE_complex_float
:
5967 code
= TYPE_CODE_COMPLEX
;
5968 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5970 case DW_ATE_decimal_float
:
5971 code
= TYPE_CODE_DECFLOAT
;
5974 code
= TYPE_CODE_FLT
;
5978 case DW_ATE_unsigned
:
5979 type_flags
|= TYPE_FLAG_UNSIGNED
;
5981 case DW_ATE_signed_char
:
5982 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5983 || cu
->language
== language_pascal
)
5984 code
= TYPE_CODE_CHAR
;
5986 case DW_ATE_unsigned_char
:
5987 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5988 || cu
->language
== language_pascal
)
5989 code
= TYPE_CODE_CHAR
;
5990 type_flags
|= TYPE_FLAG_UNSIGNED
;
5993 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5994 dwarf_type_encoding_name (encoding
));
5998 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5999 TYPE_NAME (type
) = name
;
6000 TYPE_TARGET_TYPE (type
) = target_type
;
6002 if (name
&& strcmp (name
, "char") == 0)
6003 TYPE_NOSIGN (type
) = 1;
6005 return set_die_type (die
, type
, cu
);
6008 /* Read the given DW_AT_subrange DIE. */
6010 static struct type
*
6011 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6013 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6014 struct type
*base_type
;
6015 struct type
*range_type
;
6016 struct attribute
*attr
;
6020 LONGEST negative_mask
;
6022 base_type
= die_type (die
, cu
);
6023 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
6025 complaint (&symfile_complaints
,
6026 _("DW_AT_type missing from DW_TAG_subrange_type"));
6028 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
6029 0, NULL
, cu
->objfile
);
6032 if (cu
->language
== language_fortran
)
6034 /* FORTRAN implies a lower bound of 1, if not given. */
6038 /* FIXME: For variable sized arrays either of these could be
6039 a variable rather than a constant value. We'll allow it,
6040 but we don't know how to handle it. */
6041 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
6043 low
= dwarf2_get_attr_constant_value (attr
, 0);
6045 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
6048 if (attr
->form
== DW_FORM_block1
)
6050 /* GCC encodes arrays with unspecified or dynamic length
6051 with a DW_FORM_block1 attribute.
6052 FIXME: GDB does not yet know how to handle dynamic
6053 arrays properly, treat them as arrays with unspecified
6056 FIXME: jimb/2003-09-22: GDB does not really know
6057 how to handle arrays of unspecified length
6058 either; we just represent them as zero-length
6059 arrays. Choose an appropriate upper bound given
6060 the lower bound we've computed above. */
6064 high
= dwarf2_get_attr_constant_value (attr
, 1);
6068 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
6069 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
6070 low
|= negative_mask
;
6071 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
6072 high
|= negative_mask
;
6074 range_type
= create_range_type (NULL
, base_type
, low
, high
);
6076 name
= dwarf2_name (die
, cu
);
6078 TYPE_NAME (range_type
) = name
;
6080 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6082 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
6084 set_descriptive_type (range_type
, die
, cu
);
6086 return set_die_type (die
, range_type
, cu
);
6089 static struct type
*
6090 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6094 /* For now, we only support the C meaning of an unspecified type: void. */
6096 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
6097 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
6099 return set_die_type (die
, type
, cu
);
6102 /* Trivial hash function for die_info: the hash value of a DIE
6103 is its offset in .debug_info for this objfile. */
6106 die_hash (const void *item
)
6108 const struct die_info
*die
= item
;
6112 /* Trivial comparison function for die_info structures: two DIEs
6113 are equal if they have the same offset. */
6116 die_eq (const void *item_lhs
, const void *item_rhs
)
6118 const struct die_info
*die_lhs
= item_lhs
;
6119 const struct die_info
*die_rhs
= item_rhs
;
6120 return die_lhs
->offset
== die_rhs
->offset
;
6123 /* Read a whole compilation unit into a linked list of dies. */
6125 static struct die_info
*
6126 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6128 struct die_reader_specs reader_specs
;
6130 gdb_assert (cu
->die_hash
== NULL
);
6132 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6136 &cu
->comp_unit_obstack
,
6137 hashtab_obstack_allocate
,
6138 dummy_obstack_deallocate
);
6140 init_cu_die_reader (&reader_specs
, cu
);
6142 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
6145 /* Main entry point for reading a DIE and all children.
6146 Read the DIE and dump it if requested. */
6148 static struct die_info
*
6149 read_die_and_children (const struct die_reader_specs
*reader
,
6151 gdb_byte
**new_info_ptr
,
6152 struct die_info
*parent
)
6154 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
6155 new_info_ptr
, parent
);
6157 if (dwarf2_die_debug
)
6159 fprintf_unfiltered (gdb_stdlog
,
6160 "\nRead die from %s of %s:\n",
6161 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
6163 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
6165 : "unknown section",
6166 reader
->abfd
->filename
);
6167 dump_die (result
, dwarf2_die_debug
);
6173 /* Read a single die and all its descendents. Set the die's sibling
6174 field to NULL; set other fields in the die correctly, and set all
6175 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6176 location of the info_ptr after reading all of those dies. PARENT
6177 is the parent of the die in question. */
6179 static struct die_info
*
6180 read_die_and_children_1 (const struct die_reader_specs
*reader
,
6182 gdb_byte
**new_info_ptr
,
6183 struct die_info
*parent
)
6185 struct die_info
*die
;
6189 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
6192 *new_info_ptr
= cur_ptr
;
6195 store_in_ref_table (die
, reader
->cu
);
6198 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
6202 *new_info_ptr
= cur_ptr
;
6205 die
->sibling
= NULL
;
6206 die
->parent
= parent
;
6210 /* Read a die, all of its descendents, and all of its siblings; set
6211 all of the fields of all of the dies correctly. Arguments are as
6212 in read_die_and_children. */
6214 static struct die_info
*
6215 read_die_and_siblings (const struct die_reader_specs
*reader
,
6217 gdb_byte
**new_info_ptr
,
6218 struct die_info
*parent
)
6220 struct die_info
*first_die
, *last_sibling
;
6224 first_die
= last_sibling
= NULL
;
6228 struct die_info
*die
6229 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
6233 *new_info_ptr
= cur_ptr
;
6240 last_sibling
->sibling
= die
;
6246 /* Read the die from the .debug_info section buffer. Set DIEP to
6247 point to a newly allocated die with its information, except for its
6248 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6249 whether the die has children or not. */
6252 read_full_die (const struct die_reader_specs
*reader
,
6253 struct die_info
**diep
, gdb_byte
*info_ptr
,
6256 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6257 struct abbrev_info
*abbrev
;
6258 struct die_info
*die
;
6259 struct dwarf2_cu
*cu
= reader
->cu
;
6260 bfd
*abfd
= reader
->abfd
;
6262 offset
= info_ptr
- reader
->buffer
;
6263 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6264 info_ptr
+= bytes_read
;
6272 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6274 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6276 bfd_get_filename (abfd
));
6278 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6279 die
->offset
= offset
;
6280 die
->tag
= abbrev
->tag
;
6281 die
->abbrev
= abbrev_number
;
6283 die
->num_attrs
= abbrev
->num_attrs
;
6285 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6286 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6287 abfd
, info_ptr
, cu
);
6290 *has_children
= abbrev
->has_children
;
6294 /* In DWARF version 2, the description of the debugging information is
6295 stored in a separate .debug_abbrev section. Before we read any
6296 dies from a section we read in all abbreviations and install them
6297 in a hash table. This function also sets flags in CU describing
6298 the data found in the abbrev table. */
6301 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
6303 struct comp_unit_head
*cu_header
= &cu
->header
;
6304 gdb_byte
*abbrev_ptr
;
6305 struct abbrev_info
*cur_abbrev
;
6306 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
6307 unsigned int abbrev_form
, hash_number
;
6308 struct attr_abbrev
*cur_attrs
;
6309 unsigned int allocated_attrs
;
6311 /* Initialize dwarf2 abbrevs */
6312 obstack_init (&cu
->abbrev_obstack
);
6313 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
6315 * sizeof (struct abbrev_info
*)));
6316 memset (cu
->dwarf2_abbrevs
, 0,
6317 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
6319 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
6320 &dwarf2_per_objfile
->abbrev
);
6321 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
6322 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6323 abbrev_ptr
+= bytes_read
;
6325 allocated_attrs
= ATTR_ALLOC_CHUNK
;
6326 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
6328 /* loop until we reach an abbrev number of 0 */
6329 while (abbrev_number
)
6331 cur_abbrev
= dwarf_alloc_abbrev (cu
);
6333 /* read in abbrev header */
6334 cur_abbrev
->number
= abbrev_number
;
6335 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6336 abbrev_ptr
+= bytes_read
;
6337 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
6340 if (cur_abbrev
->tag
== DW_TAG_namespace
)
6341 cu
->has_namespace_info
= 1;
6343 /* now read in declarations */
6344 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6345 abbrev_ptr
+= bytes_read
;
6346 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6347 abbrev_ptr
+= bytes_read
;
6350 if (cur_abbrev
->num_attrs
== allocated_attrs
)
6352 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
6354 = xrealloc (cur_attrs
, (allocated_attrs
6355 * sizeof (struct attr_abbrev
)));
6358 /* Record whether this compilation unit might have
6359 inter-compilation-unit references. If we don't know what form
6360 this attribute will have, then it might potentially be a
6361 DW_FORM_ref_addr, so we conservatively expect inter-CU
6364 if (abbrev_form
== DW_FORM_ref_addr
6365 || abbrev_form
== DW_FORM_indirect
)
6366 cu
->has_form_ref_addr
= 1;
6368 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
6369 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
6370 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6371 abbrev_ptr
+= bytes_read
;
6372 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6373 abbrev_ptr
+= bytes_read
;
6376 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
6377 (cur_abbrev
->num_attrs
6378 * sizeof (struct attr_abbrev
)));
6379 memcpy (cur_abbrev
->attrs
, cur_attrs
,
6380 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
6382 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
6383 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
6384 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
6386 /* Get next abbreviation.
6387 Under Irix6 the abbreviations for a compilation unit are not
6388 always properly terminated with an abbrev number of 0.
6389 Exit loop if we encounter an abbreviation which we have
6390 already read (which means we are about to read the abbreviations
6391 for the next compile unit) or if the end of the abbreviation
6392 table is reached. */
6393 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
6394 >= dwarf2_per_objfile
->abbrev
.size
)
6396 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6397 abbrev_ptr
+= bytes_read
;
6398 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
6405 /* Release the memory used by the abbrev table for a compilation unit. */
6408 dwarf2_free_abbrev_table (void *ptr_to_cu
)
6410 struct dwarf2_cu
*cu
= ptr_to_cu
;
6412 obstack_free (&cu
->abbrev_obstack
, NULL
);
6413 cu
->dwarf2_abbrevs
= NULL
;
6416 /* Lookup an abbrev_info structure in the abbrev hash table. */
6418 static struct abbrev_info
*
6419 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
6421 unsigned int hash_number
;
6422 struct abbrev_info
*abbrev
;
6424 hash_number
= number
% ABBREV_HASH_SIZE
;
6425 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
6429 if (abbrev
->number
== number
)
6432 abbrev
= abbrev
->next
;
6437 /* Returns nonzero if TAG represents a type that we might generate a partial
6441 is_type_tag_for_partial (int tag
)
6446 /* Some types that would be reasonable to generate partial symbols for,
6447 that we don't at present. */
6448 case DW_TAG_array_type
:
6449 case DW_TAG_file_type
:
6450 case DW_TAG_ptr_to_member_type
:
6451 case DW_TAG_set_type
:
6452 case DW_TAG_string_type
:
6453 case DW_TAG_subroutine_type
:
6455 case DW_TAG_base_type
:
6456 case DW_TAG_class_type
:
6457 case DW_TAG_interface_type
:
6458 case DW_TAG_enumeration_type
:
6459 case DW_TAG_structure_type
:
6460 case DW_TAG_subrange_type
:
6461 case DW_TAG_typedef
:
6462 case DW_TAG_union_type
:
6469 /* Load all DIEs that are interesting for partial symbols into memory. */
6471 static struct partial_die_info
*
6472 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6473 int building_psymtab
, struct dwarf2_cu
*cu
)
6475 struct partial_die_info
*part_die
;
6476 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
6477 struct abbrev_info
*abbrev
;
6478 unsigned int bytes_read
;
6479 unsigned int load_all
= 0;
6481 int nesting_level
= 1;
6486 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
6490 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6494 &cu
->comp_unit_obstack
,
6495 hashtab_obstack_allocate
,
6496 dummy_obstack_deallocate
);
6498 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6499 sizeof (struct partial_die_info
));
6503 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6505 /* A NULL abbrev means the end of a series of children. */
6508 if (--nesting_level
== 0)
6510 /* PART_DIE was probably the last thing allocated on the
6511 comp_unit_obstack, so we could call obstack_free
6512 here. We don't do that because the waste is small,
6513 and will be cleaned up when we're done with this
6514 compilation unit. This way, we're also more robust
6515 against other users of the comp_unit_obstack. */
6518 info_ptr
+= bytes_read
;
6519 last_die
= parent_die
;
6520 parent_die
= parent_die
->die_parent
;
6524 /* Check whether this DIE is interesting enough to save. Normally
6525 we would not be interested in members here, but there may be
6526 later variables referencing them via DW_AT_specification (for
6529 && !is_type_tag_for_partial (abbrev
->tag
)
6530 && abbrev
->tag
!= DW_TAG_enumerator
6531 && abbrev
->tag
!= DW_TAG_subprogram
6532 && abbrev
->tag
!= DW_TAG_lexical_block
6533 && abbrev
->tag
!= DW_TAG_variable
6534 && abbrev
->tag
!= DW_TAG_namespace
6535 && abbrev
->tag
!= DW_TAG_member
)
6537 /* Otherwise we skip to the next sibling, if any. */
6538 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
6542 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
6543 buffer
, info_ptr
, cu
);
6545 /* This two-pass algorithm for processing partial symbols has a
6546 high cost in cache pressure. Thus, handle some simple cases
6547 here which cover the majority of C partial symbols. DIEs
6548 which neither have specification tags in them, nor could have
6549 specification tags elsewhere pointing at them, can simply be
6550 processed and discarded.
6552 This segment is also optional; scan_partial_symbols and
6553 add_partial_symbol will handle these DIEs if we chain
6554 them in normally. When compilers which do not emit large
6555 quantities of duplicate debug information are more common,
6556 this code can probably be removed. */
6558 /* Any complete simple types at the top level (pretty much all
6559 of them, for a language without namespaces), can be processed
6561 if (parent_die
== NULL
6562 && part_die
->has_specification
== 0
6563 && part_die
->is_declaration
== 0
6564 && (part_die
->tag
== DW_TAG_typedef
6565 || part_die
->tag
== DW_TAG_base_type
6566 || part_die
->tag
== DW_TAG_subrange_type
))
6568 if (building_psymtab
&& part_die
->name
!= NULL
)
6569 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6570 VAR_DOMAIN
, LOC_TYPEDEF
,
6571 &cu
->objfile
->static_psymbols
,
6572 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6573 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6577 /* If we're at the second level, and we're an enumerator, and
6578 our parent has no specification (meaning possibly lives in a
6579 namespace elsewhere), then we can add the partial symbol now
6580 instead of queueing it. */
6581 if (part_die
->tag
== DW_TAG_enumerator
6582 && parent_die
!= NULL
6583 && parent_die
->die_parent
== NULL
6584 && parent_die
->tag
== DW_TAG_enumeration_type
6585 && parent_die
->has_specification
== 0)
6587 if (part_die
->name
== NULL
)
6588 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6589 else if (building_psymtab
)
6590 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6591 VAR_DOMAIN
, LOC_CONST
,
6592 (cu
->language
== language_cplus
6593 || cu
->language
== language_java
)
6594 ? &cu
->objfile
->global_psymbols
6595 : &cu
->objfile
->static_psymbols
,
6596 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6598 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6602 /* We'll save this DIE so link it in. */
6603 part_die
->die_parent
= parent_die
;
6604 part_die
->die_sibling
= NULL
;
6605 part_die
->die_child
= NULL
;
6607 if (last_die
&& last_die
== parent_die
)
6608 last_die
->die_child
= part_die
;
6610 last_die
->die_sibling
= part_die
;
6612 last_die
= part_die
;
6614 if (first_die
== NULL
)
6615 first_die
= part_die
;
6617 /* Maybe add the DIE to the hash table. Not all DIEs that we
6618 find interesting need to be in the hash table, because we
6619 also have the parent/sibling/child chains; only those that we
6620 might refer to by offset later during partial symbol reading.
6622 For now this means things that might have be the target of a
6623 DW_AT_specification, DW_AT_abstract_origin, or
6624 DW_AT_extension. DW_AT_extension will refer only to
6625 namespaces; DW_AT_abstract_origin refers to functions (and
6626 many things under the function DIE, but we do not recurse
6627 into function DIEs during partial symbol reading) and
6628 possibly variables as well; DW_AT_specification refers to
6629 declarations. Declarations ought to have the DW_AT_declaration
6630 flag. It happens that GCC forgets to put it in sometimes, but
6631 only for functions, not for types.
6633 Adding more things than necessary to the hash table is harmless
6634 except for the performance cost. Adding too few will result in
6635 wasted time in find_partial_die, when we reread the compilation
6636 unit with load_all_dies set. */
6639 || abbrev
->tag
== DW_TAG_subprogram
6640 || abbrev
->tag
== DW_TAG_variable
6641 || abbrev
->tag
== DW_TAG_namespace
6642 || part_die
->is_declaration
)
6646 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6647 part_die
->offset
, INSERT
);
6651 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6652 sizeof (struct partial_die_info
));
6654 /* For some DIEs we want to follow their children (if any). For C
6655 we have no reason to follow the children of structures; for other
6656 languages we have to, both so that we can get at method physnames
6657 to infer fully qualified class names, and for DW_AT_specification.
6659 For Ada, we need to scan the children of subprograms and lexical
6660 blocks as well because Ada allows the definition of nested
6661 entities that could be interesting for the debugger, such as
6662 nested subprograms for instance. */
6663 if (last_die
->has_children
6665 || last_die
->tag
== DW_TAG_namespace
6666 || last_die
->tag
== DW_TAG_enumeration_type
6667 || (cu
->language
!= language_c
6668 && (last_die
->tag
== DW_TAG_class_type
6669 || last_die
->tag
== DW_TAG_interface_type
6670 || last_die
->tag
== DW_TAG_structure_type
6671 || last_die
->tag
== DW_TAG_union_type
))
6672 || (cu
->language
== language_ada
6673 && (last_die
->tag
== DW_TAG_subprogram
6674 || last_die
->tag
== DW_TAG_lexical_block
))))
6677 parent_die
= last_die
;
6681 /* Otherwise we skip to the next sibling, if any. */
6682 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
6684 /* Back to the top, do it again. */
6688 /* Read a minimal amount of information into the minimal die structure. */
6691 read_partial_die (struct partial_die_info
*part_die
,
6692 struct abbrev_info
*abbrev
,
6693 unsigned int abbrev_len
, bfd
*abfd
,
6694 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6695 struct dwarf2_cu
*cu
)
6697 unsigned int bytes_read
, i
;
6698 struct attribute attr
;
6699 int has_low_pc_attr
= 0;
6700 int has_high_pc_attr
= 0;
6702 memset (part_die
, 0, sizeof (struct partial_die_info
));
6704 part_die
->offset
= info_ptr
- buffer
;
6706 info_ptr
+= abbrev_len
;
6711 part_die
->tag
= abbrev
->tag
;
6712 part_die
->has_children
= abbrev
->has_children
;
6714 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6716 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6718 /* Store the data if it is of an attribute we want to keep in a
6719 partial symbol table. */
6723 switch (part_die
->tag
)
6725 case DW_TAG_compile_unit
:
6726 case DW_TAG_type_unit
:
6727 /* Compilation units have a DW_AT_name that is a filename, not
6728 a source language identifier. */
6729 case DW_TAG_enumeration_type
:
6730 case DW_TAG_enumerator
:
6731 /* These tags always have simple identifiers already; no need
6732 to canonicalize them. */
6733 part_die
->name
= DW_STRING (&attr
);
6737 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6738 &cu
->objfile
->objfile_obstack
);
6742 case DW_AT_MIPS_linkage_name
:
6743 if (cu
->language
== language_ada
)
6744 part_die
->name
= DW_STRING (&attr
);
6747 has_low_pc_attr
= 1;
6748 part_die
->lowpc
= DW_ADDR (&attr
);
6751 has_high_pc_attr
= 1;
6752 part_die
->highpc
= DW_ADDR (&attr
);
6754 case DW_AT_location
:
6755 /* Support the .debug_loc offsets */
6756 if (attr_form_is_block (&attr
))
6758 part_die
->locdesc
= DW_BLOCK (&attr
);
6760 else if (attr_form_is_section_offset (&attr
))
6762 dwarf2_complex_location_expr_complaint ();
6766 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6767 "partial symbol information");
6770 case DW_AT_external
:
6771 part_die
->is_external
= DW_UNSND (&attr
);
6773 case DW_AT_declaration
:
6774 part_die
->is_declaration
= DW_UNSND (&attr
);
6777 part_die
->has_type
= 1;
6779 case DW_AT_abstract_origin
:
6780 case DW_AT_specification
:
6781 case DW_AT_extension
:
6782 part_die
->has_specification
= 1;
6783 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6786 /* Ignore absolute siblings, they might point outside of
6787 the current compile unit. */
6788 if (attr
.form
== DW_FORM_ref_addr
)
6789 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6791 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
6793 case DW_AT_byte_size
:
6794 part_die
->has_byte_size
= 1;
6796 case DW_AT_calling_convention
:
6797 /* DWARF doesn't provide a way to identify a program's source-level
6798 entry point. DW_AT_calling_convention attributes are only meant
6799 to describe functions' calling conventions.
6801 However, because it's a necessary piece of information in
6802 Fortran, and because DW_CC_program is the only piece of debugging
6803 information whose definition refers to a 'main program' at all,
6804 several compilers have begun marking Fortran main programs with
6805 DW_CC_program --- even when those functions use the standard
6806 calling conventions.
6808 So until DWARF specifies a way to provide this information and
6809 compilers pick up the new representation, we'll support this
6811 if (DW_UNSND (&attr
) == DW_CC_program
6812 && cu
->language
== language_fortran
)
6813 set_main_name (part_die
->name
);
6820 /* When using the GNU linker, .gnu.linkonce. sections are used to
6821 eliminate duplicate copies of functions and vtables and such.
6822 The linker will arbitrarily choose one and discard the others.
6823 The AT_*_pc values for such functions refer to local labels in
6824 these sections. If the section from that file was discarded, the
6825 labels are not in the output, so the relocs get a value of 0.
6826 If this is a discarded function, mark the pc bounds as invalid,
6827 so that GDB will ignore it. */
6828 if (has_low_pc_attr
&& has_high_pc_attr
6829 && part_die
->lowpc
< part_die
->highpc
6830 && (part_die
->lowpc
!= 0
6831 || dwarf2_per_objfile
->has_section_at_zero
))
6832 part_die
->has_pc_info
= 1;
6837 /* Find a cached partial DIE at OFFSET in CU. */
6839 static struct partial_die_info
*
6840 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6842 struct partial_die_info
*lookup_die
= NULL
;
6843 struct partial_die_info part_die
;
6845 part_die
.offset
= offset
;
6846 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6851 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6852 except in the case of .debug_types DIEs which do not reference
6853 outside their CU (they do however referencing other types via
6856 static struct partial_die_info
*
6857 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6859 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6860 struct partial_die_info
*pd
= NULL
;
6862 if (cu
->per_cu
->from_debug_types
)
6864 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6870 if (offset_in_cu_p (&cu
->header
, offset
))
6872 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6877 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6879 if (per_cu
->cu
== NULL
)
6881 load_partial_comp_unit (per_cu
, cu
->objfile
);
6882 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6883 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6886 per_cu
->cu
->last_used
= 0;
6887 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6889 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6891 struct cleanup
*back_to
;
6892 struct partial_die_info comp_unit_die
;
6893 struct abbrev_info
*abbrev
;
6894 unsigned int bytes_read
;
6897 per_cu
->load_all_dies
= 1;
6899 /* Re-read the DIEs. */
6900 back_to
= make_cleanup (null_cleanup
, 0);
6901 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6903 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6904 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6906 info_ptr
= (dwarf2_per_objfile
->info
.buffer
6907 + per_cu
->cu
->header
.offset
6908 + per_cu
->cu
->header
.first_die_offset
);
6909 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6910 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6911 per_cu
->cu
->objfile
->obfd
,
6912 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6914 if (comp_unit_die
.has_children
)
6915 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
6916 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6918 do_cleanups (back_to
);
6920 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6926 internal_error (__FILE__
, __LINE__
,
6927 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6928 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6932 /* Adjust PART_DIE before generating a symbol for it. This function
6933 may set the is_external flag or change the DIE's name. */
6936 fixup_partial_die (struct partial_die_info
*part_die
,
6937 struct dwarf2_cu
*cu
)
6939 /* If we found a reference attribute and the DIE has no name, try
6940 to find a name in the referred to DIE. */
6942 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6944 struct partial_die_info
*spec_die
;
6946 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6948 fixup_partial_die (spec_die
, cu
);
6952 part_die
->name
= spec_die
->name
;
6954 /* Copy DW_AT_external attribute if it is set. */
6955 if (spec_die
->is_external
)
6956 part_die
->is_external
= spec_die
->is_external
;
6960 /* Set default names for some unnamed DIEs. */
6961 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6962 || part_die
->tag
== DW_TAG_class_type
))
6963 part_die
->name
= "(anonymous class)";
6965 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6966 part_die
->name
= "(anonymous namespace)";
6968 if (part_die
->tag
== DW_TAG_structure_type
6969 || part_die
->tag
== DW_TAG_class_type
6970 || part_die
->tag
== DW_TAG_union_type
)
6971 guess_structure_name (part_die
, cu
);
6974 /* Read an attribute value described by an attribute form. */
6977 read_attribute_value (struct attribute
*attr
, unsigned form
,
6978 bfd
*abfd
, gdb_byte
*info_ptr
,
6979 struct dwarf2_cu
*cu
)
6981 struct comp_unit_head
*cu_header
= &cu
->header
;
6982 unsigned int bytes_read
;
6983 struct dwarf_block
*blk
;
6988 case DW_FORM_ref_addr
:
6989 if (cu
->header
.version
== 2)
6990 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6992 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
6993 info_ptr
+= bytes_read
;
6996 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6997 info_ptr
+= bytes_read
;
6999 case DW_FORM_block2
:
7000 blk
= dwarf_alloc_block (cu
);
7001 blk
->size
= read_2_bytes (abfd
, info_ptr
);
7003 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7004 info_ptr
+= blk
->size
;
7005 DW_BLOCK (attr
) = blk
;
7007 case DW_FORM_block4
:
7008 blk
= dwarf_alloc_block (cu
);
7009 blk
->size
= read_4_bytes (abfd
, info_ptr
);
7011 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7012 info_ptr
+= blk
->size
;
7013 DW_BLOCK (attr
) = blk
;
7016 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
7020 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
7024 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
7027 case DW_FORM_string
:
7028 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
7029 DW_STRING_IS_CANONICAL (attr
) = 0;
7030 info_ptr
+= bytes_read
;
7033 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
7035 DW_STRING_IS_CANONICAL (attr
) = 0;
7036 info_ptr
+= bytes_read
;
7039 blk
= dwarf_alloc_block (cu
);
7040 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7041 info_ptr
+= bytes_read
;
7042 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7043 info_ptr
+= blk
->size
;
7044 DW_BLOCK (attr
) = blk
;
7046 case DW_FORM_block1
:
7047 blk
= dwarf_alloc_block (cu
);
7048 blk
->size
= read_1_byte (abfd
, info_ptr
);
7050 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7051 info_ptr
+= blk
->size
;
7052 DW_BLOCK (attr
) = blk
;
7055 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7059 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7063 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
7064 info_ptr
+= bytes_read
;
7067 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7068 info_ptr
+= bytes_read
;
7071 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
7075 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
7079 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
7083 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
7087 /* Convert the signature to something we can record in DW_UNSND
7089 NOTE: This is NULL if the type wasn't found. */
7090 DW_SIGNATURED_TYPE (attr
) =
7091 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
7094 case DW_FORM_ref_udata
:
7095 DW_ADDR (attr
) = (cu
->header
.offset
7096 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
7097 info_ptr
+= bytes_read
;
7099 case DW_FORM_indirect
:
7100 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7101 info_ptr
+= bytes_read
;
7102 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
7105 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7106 dwarf_form_name (form
),
7107 bfd_get_filename (abfd
));
7110 /* We have seen instances where the compiler tried to emit a byte
7111 size attribute of -1 which ended up being encoded as an unsigned
7112 0xffffffff. Although 0xffffffff is technically a valid size value,
7113 an object of this size seems pretty unlikely so we can relatively
7114 safely treat these cases as if the size attribute was invalid and
7115 treat them as zero by default. */
7116 if (attr
->name
== DW_AT_byte_size
7117 && form
== DW_FORM_data4
7118 && DW_UNSND (attr
) >= 0xffffffff)
7121 (&symfile_complaints
,
7122 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7123 hex_string (DW_UNSND (attr
)));
7124 DW_UNSND (attr
) = 0;
7130 /* Read an attribute described by an abbreviated attribute. */
7133 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
7134 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7136 attr
->name
= abbrev
->name
;
7137 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
7140 /* read dwarf information from a buffer */
7143 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
7145 return bfd_get_8 (abfd
, buf
);
7149 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
7151 return bfd_get_signed_8 (abfd
, buf
);
7155 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
7157 return bfd_get_16 (abfd
, buf
);
7161 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7163 return bfd_get_signed_16 (abfd
, buf
);
7167 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
7169 return bfd_get_32 (abfd
, buf
);
7173 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7175 return bfd_get_signed_32 (abfd
, buf
);
7179 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
7181 return bfd_get_64 (abfd
, buf
);
7185 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
7186 unsigned int *bytes_read
)
7188 struct comp_unit_head
*cu_header
= &cu
->header
;
7189 CORE_ADDR retval
= 0;
7191 if (cu_header
->signed_addr_p
)
7193 switch (cu_header
->addr_size
)
7196 retval
= bfd_get_signed_16 (abfd
, buf
);
7199 retval
= bfd_get_signed_32 (abfd
, buf
);
7202 retval
= bfd_get_signed_64 (abfd
, buf
);
7205 internal_error (__FILE__
, __LINE__
,
7206 _("read_address: bad switch, signed [in module %s]"),
7207 bfd_get_filename (abfd
));
7212 switch (cu_header
->addr_size
)
7215 retval
= bfd_get_16 (abfd
, buf
);
7218 retval
= bfd_get_32 (abfd
, buf
);
7221 retval
= bfd_get_64 (abfd
, buf
);
7224 internal_error (__FILE__
, __LINE__
,
7225 _("read_address: bad switch, unsigned [in module %s]"),
7226 bfd_get_filename (abfd
));
7230 *bytes_read
= cu_header
->addr_size
;
7234 /* Read the initial length from a section. The (draft) DWARF 3
7235 specification allows the initial length to take up either 4 bytes
7236 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7237 bytes describe the length and all offsets will be 8 bytes in length
7240 An older, non-standard 64-bit format is also handled by this
7241 function. The older format in question stores the initial length
7242 as an 8-byte quantity without an escape value. Lengths greater
7243 than 2^32 aren't very common which means that the initial 4 bytes
7244 is almost always zero. Since a length value of zero doesn't make
7245 sense for the 32-bit format, this initial zero can be considered to
7246 be an escape value which indicates the presence of the older 64-bit
7247 format. As written, the code can't detect (old format) lengths
7248 greater than 4GB. If it becomes necessary to handle lengths
7249 somewhat larger than 4GB, we could allow other small values (such
7250 as the non-sensical values of 1, 2, and 3) to also be used as
7251 escape values indicating the presence of the old format.
7253 The value returned via bytes_read should be used to increment the
7254 relevant pointer after calling read_initial_length().
7256 [ Note: read_initial_length() and read_offset() are based on the
7257 document entitled "DWARF Debugging Information Format", revision
7258 3, draft 8, dated November 19, 2001. This document was obtained
7261 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7263 This document is only a draft and is subject to change. (So beware.)
7265 Details regarding the older, non-standard 64-bit format were
7266 determined empirically by examining 64-bit ELF files produced by
7267 the SGI toolchain on an IRIX 6.5 machine.
7269 - Kevin, July 16, 2002
7273 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
7275 LONGEST length
= bfd_get_32 (abfd
, buf
);
7277 if (length
== 0xffffffff)
7279 length
= bfd_get_64 (abfd
, buf
+ 4);
7282 else if (length
== 0)
7284 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7285 length
= bfd_get_64 (abfd
, buf
);
7296 /* Cover function for read_initial_length.
7297 Returns the length of the object at BUF, and stores the size of the
7298 initial length in *BYTES_READ and stores the size that offsets will be in
7300 If the initial length size is not equivalent to that specified in
7301 CU_HEADER then issue a complaint.
7302 This is useful when reading non-comp-unit headers. */
7305 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
7306 const struct comp_unit_head
*cu_header
,
7307 unsigned int *bytes_read
,
7308 unsigned int *offset_size
)
7310 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
7312 gdb_assert (cu_header
->initial_length_size
== 4
7313 || cu_header
->initial_length_size
== 8
7314 || cu_header
->initial_length_size
== 12);
7316 if (cu_header
->initial_length_size
!= *bytes_read
)
7317 complaint (&symfile_complaints
,
7318 _("intermixed 32-bit and 64-bit DWARF sections"));
7320 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
7324 /* Read an offset from the data stream. The size of the offset is
7325 given by cu_header->offset_size. */
7328 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
7329 unsigned int *bytes_read
)
7331 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
7332 *bytes_read
= cu_header
->offset_size
;
7336 /* Read an offset from the data stream. */
7339 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
7343 switch (offset_size
)
7346 retval
= bfd_get_32 (abfd
, buf
);
7349 retval
= bfd_get_64 (abfd
, buf
);
7352 internal_error (__FILE__
, __LINE__
,
7353 _("read_offset_1: bad switch [in module %s]"),
7354 bfd_get_filename (abfd
));
7361 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
7363 /* If the size of a host char is 8 bits, we can return a pointer
7364 to the buffer, otherwise we have to copy the data to a buffer
7365 allocated on the temporary obstack. */
7366 gdb_assert (HOST_CHAR_BIT
== 8);
7371 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7373 /* If the size of a host char is 8 bits, we can return a pointer
7374 to the string, otherwise we have to copy the string to a buffer
7375 allocated on the temporary obstack. */
7376 gdb_assert (HOST_CHAR_BIT
== 8);
7379 *bytes_read_ptr
= 1;
7382 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
7383 return (char *) buf
;
7387 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
7388 const struct comp_unit_head
*cu_header
,
7389 unsigned int *bytes_read_ptr
)
7391 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
7393 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
7394 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
7396 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7397 bfd_get_filename (abfd
));
7400 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
7402 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7403 bfd_get_filename (abfd
));
7406 gdb_assert (HOST_CHAR_BIT
== 8);
7407 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
7409 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
7412 static unsigned long
7413 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7415 unsigned long result
;
7416 unsigned int num_read
;
7426 byte
= bfd_get_8 (abfd
, buf
);
7429 result
|= ((unsigned long)(byte
& 127) << shift
);
7430 if ((byte
& 128) == 0)
7436 *bytes_read_ptr
= num_read
;
7441 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7444 int i
, shift
, num_read
;
7453 byte
= bfd_get_8 (abfd
, buf
);
7456 result
|= ((long)(byte
& 127) << shift
);
7458 if ((byte
& 128) == 0)
7463 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
7464 result
|= -(((long)1) << shift
);
7465 *bytes_read_ptr
= num_read
;
7469 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7472 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
7478 byte
= bfd_get_8 (abfd
, buf
);
7480 if ((byte
& 128) == 0)
7486 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
7493 cu
->language
= language_c
;
7495 case DW_LANG_C_plus_plus
:
7496 cu
->language
= language_cplus
;
7498 case DW_LANG_Fortran77
:
7499 case DW_LANG_Fortran90
:
7500 case DW_LANG_Fortran95
:
7501 cu
->language
= language_fortran
;
7503 case DW_LANG_Mips_Assembler
:
7504 cu
->language
= language_asm
;
7507 cu
->language
= language_java
;
7511 cu
->language
= language_ada
;
7513 case DW_LANG_Modula2
:
7514 cu
->language
= language_m2
;
7516 case DW_LANG_Pascal83
:
7517 cu
->language
= language_pascal
;
7520 cu
->language
= language_objc
;
7522 case DW_LANG_Cobol74
:
7523 case DW_LANG_Cobol85
:
7525 cu
->language
= language_minimal
;
7528 cu
->language_defn
= language_def (cu
->language
);
7531 /* Return the named attribute or NULL if not there. */
7533 static struct attribute
*
7534 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
7537 struct attribute
*spec
= NULL
;
7539 for (i
= 0; i
< die
->num_attrs
; ++i
)
7541 if (die
->attrs
[i
].name
== name
)
7542 return &die
->attrs
[i
];
7543 if (die
->attrs
[i
].name
== DW_AT_specification
7544 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
7545 spec
= &die
->attrs
[i
];
7550 die
= follow_die_ref (die
, spec
, &cu
);
7551 return dwarf2_attr (die
, name
, cu
);
7557 /* Return the named attribute or NULL if not there,
7558 but do not follow DW_AT_specification, etc.
7559 This is for use in contexts where we're reading .debug_types dies.
7560 Following DW_AT_specification, DW_AT_abstract_origin will take us
7561 back up the chain, and we want to go down. */
7563 static struct attribute
*
7564 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
7565 struct dwarf2_cu
*cu
)
7569 for (i
= 0; i
< die
->num_attrs
; ++i
)
7570 if (die
->attrs
[i
].name
== name
)
7571 return &die
->attrs
[i
];
7576 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7577 and holds a non-zero value. This function should only be used for
7578 DW_FORM_flag attributes. */
7581 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7583 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7585 return (attr
&& DW_UNSND (attr
));
7589 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7591 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7592 which value is non-zero. However, we have to be careful with
7593 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7594 (via dwarf2_flag_true_p) follows this attribute. So we may
7595 end up accidently finding a declaration attribute that belongs
7596 to a different DIE referenced by the specification attribute,
7597 even though the given DIE does not have a declaration attribute. */
7598 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7599 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7602 /* Return the die giving the specification for DIE, if there is
7603 one. *SPEC_CU is the CU containing DIE on input, and the CU
7604 containing the return value on output. If there is no
7605 specification, but there is an abstract origin, that is
7608 static struct die_info
*
7609 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7611 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7614 if (spec_attr
== NULL
)
7615 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7617 if (spec_attr
== NULL
)
7620 return follow_die_ref (die
, spec_attr
, spec_cu
);
7623 /* Free the line_header structure *LH, and any arrays and strings it
7626 free_line_header (struct line_header
*lh
)
7628 if (lh
->standard_opcode_lengths
)
7629 xfree (lh
->standard_opcode_lengths
);
7631 /* Remember that all the lh->file_names[i].name pointers are
7632 pointers into debug_line_buffer, and don't need to be freed. */
7634 xfree (lh
->file_names
);
7636 /* Similarly for the include directory names. */
7637 if (lh
->include_dirs
)
7638 xfree (lh
->include_dirs
);
7644 /* Add an entry to LH's include directory table. */
7646 add_include_dir (struct line_header
*lh
, char *include_dir
)
7648 /* Grow the array if necessary. */
7649 if (lh
->include_dirs_size
== 0)
7651 lh
->include_dirs_size
= 1; /* for testing */
7652 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7653 * sizeof (*lh
->include_dirs
));
7655 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7657 lh
->include_dirs_size
*= 2;
7658 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7659 (lh
->include_dirs_size
7660 * sizeof (*lh
->include_dirs
)));
7663 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7667 /* Add an entry to LH's file name table. */
7669 add_file_name (struct line_header
*lh
,
7671 unsigned int dir_index
,
7672 unsigned int mod_time
,
7673 unsigned int length
)
7675 struct file_entry
*fe
;
7677 /* Grow the array if necessary. */
7678 if (lh
->file_names_size
== 0)
7680 lh
->file_names_size
= 1; /* for testing */
7681 lh
->file_names
= xmalloc (lh
->file_names_size
7682 * sizeof (*lh
->file_names
));
7684 else if (lh
->num_file_names
>= lh
->file_names_size
)
7686 lh
->file_names_size
*= 2;
7687 lh
->file_names
= xrealloc (lh
->file_names
,
7688 (lh
->file_names_size
7689 * sizeof (*lh
->file_names
)));
7692 fe
= &lh
->file_names
[lh
->num_file_names
++];
7694 fe
->dir_index
= dir_index
;
7695 fe
->mod_time
= mod_time
;
7696 fe
->length
= length
;
7702 /* Read the statement program header starting at OFFSET in
7703 .debug_line, according to the endianness of ABFD. Return a pointer
7704 to a struct line_header, allocated using xmalloc.
7706 NOTE: the strings in the include directory and file name tables of
7707 the returned object point into debug_line_buffer, and must not be
7709 static struct line_header
*
7710 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7711 struct dwarf2_cu
*cu
)
7713 struct cleanup
*back_to
;
7714 struct line_header
*lh
;
7716 unsigned int bytes_read
, offset_size
;
7718 char *cur_dir
, *cur_file
;
7720 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
7721 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7723 complaint (&symfile_complaints
, _("missing .debug_line section"));
7727 /* Make sure that at least there's room for the total_length field.
7728 That could be 12 bytes long, but we're just going to fudge that. */
7729 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7731 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7735 lh
= xmalloc (sizeof (*lh
));
7736 memset (lh
, 0, sizeof (*lh
));
7737 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7740 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7742 /* Read in the header. */
7744 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7745 &bytes_read
, &offset_size
);
7746 line_ptr
+= bytes_read
;
7747 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7748 + dwarf2_per_objfile
->line
.size
))
7750 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7753 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7754 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7756 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7757 line_ptr
+= offset_size
;
7758 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7760 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7762 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7764 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7766 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7768 lh
->standard_opcode_lengths
7769 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7771 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7772 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7774 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7778 /* Read directory table. */
7779 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7781 line_ptr
+= bytes_read
;
7782 add_include_dir (lh
, cur_dir
);
7784 line_ptr
+= bytes_read
;
7786 /* Read file name table. */
7787 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7789 unsigned int dir_index
, mod_time
, length
;
7791 line_ptr
+= bytes_read
;
7792 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7793 line_ptr
+= bytes_read
;
7794 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7795 line_ptr
+= bytes_read
;
7796 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7797 line_ptr
+= bytes_read
;
7799 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7801 line_ptr
+= bytes_read
;
7802 lh
->statement_program_start
= line_ptr
;
7804 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7805 + dwarf2_per_objfile
->line
.size
))
7806 complaint (&symfile_complaints
,
7807 _("line number info header doesn't fit in `.debug_line' section"));
7809 discard_cleanups (back_to
);
7813 /* This function exists to work around a bug in certain compilers
7814 (particularly GCC 2.95), in which the first line number marker of a
7815 function does not show up until after the prologue, right before
7816 the second line number marker. This function shifts ADDRESS down
7817 to the beginning of the function if necessary, and is called on
7818 addresses passed to record_line. */
7821 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7823 struct function_range
*fn
;
7825 /* Find the function_range containing address. */
7830 cu
->cached_fn
= cu
->first_fn
;
7834 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7840 while (fn
&& fn
!= cu
->cached_fn
)
7841 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7851 if (address
!= fn
->lowpc
)
7852 complaint (&symfile_complaints
,
7853 _("misplaced first line number at 0x%lx for '%s'"),
7854 (unsigned long) address
, fn
->name
);
7859 /* Decode the Line Number Program (LNP) for the given line_header
7860 structure and CU. The actual information extracted and the type
7861 of structures created from the LNP depends on the value of PST.
7863 1. If PST is NULL, then this procedure uses the data from the program
7864 to create all necessary symbol tables, and their linetables.
7865 The compilation directory of the file is passed in COMP_DIR,
7866 and must not be NULL.
7868 2. If PST is not NULL, this procedure reads the program to determine
7869 the list of files included by the unit represented by PST, and
7870 builds all the associated partial symbol tables. In this case,
7871 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7872 is not used to compute the full name of the symtab, and therefore
7873 omitting it when building the partial symtab does not introduce
7874 the potential for inconsistency - a partial symtab and its associated
7875 symbtab having a different fullname -). */
7878 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7879 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7881 gdb_byte
*line_ptr
, *extended_end
;
7883 unsigned int bytes_read
, extended_len
;
7884 unsigned char op_code
, extended_op
, adj_opcode
;
7886 struct objfile
*objfile
= cu
->objfile
;
7887 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7888 const int decode_for_pst_p
= (pst
!= NULL
);
7889 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7891 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7893 line_ptr
= lh
->statement_program_start
;
7894 line_end
= lh
->statement_program_end
;
7896 /* Read the statement sequences until there's nothing left. */
7897 while (line_ptr
< line_end
)
7899 /* state machine registers */
7900 CORE_ADDR address
= 0;
7901 unsigned int file
= 1;
7902 unsigned int line
= 1;
7903 unsigned int column
= 0;
7904 int is_stmt
= lh
->default_is_stmt
;
7905 int basic_block
= 0;
7906 int end_sequence
= 0;
7909 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7911 /* Start a subfile for the current file of the state machine. */
7912 /* lh->include_dirs and lh->file_names are 0-based, but the
7913 directory and file name numbers in the statement program
7915 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7919 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7921 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7924 /* Decode the table. */
7925 while (!end_sequence
)
7927 op_code
= read_1_byte (abfd
, line_ptr
);
7929 if (line_ptr
> line_end
)
7931 dwarf2_debug_line_missing_end_sequence_complaint ();
7935 if (op_code
>= lh
->opcode_base
)
7937 /* Special operand. */
7938 adj_opcode
= op_code
- lh
->opcode_base
;
7939 address
+= (adj_opcode
/ lh
->line_range
)
7940 * lh
->minimum_instruction_length
;
7941 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7942 if (lh
->num_file_names
< file
|| file
== 0)
7943 dwarf2_debug_line_missing_file_complaint ();
7946 lh
->file_names
[file
- 1].included_p
= 1;
7947 if (!decode_for_pst_p
&& is_stmt
)
7949 if (last_subfile
!= current_subfile
)
7951 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7953 record_line (last_subfile
, 0, addr
);
7954 last_subfile
= current_subfile
;
7956 /* Append row to matrix using current values. */
7957 addr
= check_cu_functions (address
, cu
);
7958 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7959 record_line (current_subfile
, line
, addr
);
7964 else switch (op_code
)
7966 case DW_LNS_extended_op
:
7967 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7968 line_ptr
+= bytes_read
;
7969 extended_end
= line_ptr
+ extended_len
;
7970 extended_op
= read_1_byte (abfd
, line_ptr
);
7972 switch (extended_op
)
7974 case DW_LNE_end_sequence
:
7977 case DW_LNE_set_address
:
7978 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7979 line_ptr
+= bytes_read
;
7980 address
+= baseaddr
;
7982 case DW_LNE_define_file
:
7985 unsigned int dir_index
, mod_time
, length
;
7987 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7988 line_ptr
+= bytes_read
;
7990 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7991 line_ptr
+= bytes_read
;
7993 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7994 line_ptr
+= bytes_read
;
7996 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7997 line_ptr
+= bytes_read
;
7998 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
8001 case DW_LNE_set_discriminator
:
8002 /* The discriminator is not interesting to the debugger;
8004 line_ptr
= extended_end
;
8007 complaint (&symfile_complaints
,
8008 _("mangled .debug_line section"));
8011 /* Make sure that we parsed the extended op correctly. If e.g.
8012 we expected a different address size than the producer used,
8013 we may have read the wrong number of bytes. */
8014 if (line_ptr
!= extended_end
)
8016 complaint (&symfile_complaints
,
8017 _("mangled .debug_line section"));
8022 if (lh
->num_file_names
< file
|| file
== 0)
8023 dwarf2_debug_line_missing_file_complaint ();
8026 lh
->file_names
[file
- 1].included_p
= 1;
8027 if (!decode_for_pst_p
&& is_stmt
)
8029 if (last_subfile
!= current_subfile
)
8031 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8033 record_line (last_subfile
, 0, addr
);
8034 last_subfile
= current_subfile
;
8036 addr
= check_cu_functions (address
, cu
);
8037 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8038 record_line (current_subfile
, line
, addr
);
8043 case DW_LNS_advance_pc
:
8044 address
+= lh
->minimum_instruction_length
8045 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8046 line_ptr
+= bytes_read
;
8048 case DW_LNS_advance_line
:
8049 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
8050 line_ptr
+= bytes_read
;
8052 case DW_LNS_set_file
:
8054 /* The arrays lh->include_dirs and lh->file_names are
8055 0-based, but the directory and file name numbers in
8056 the statement program are 1-based. */
8057 struct file_entry
*fe
;
8060 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8061 line_ptr
+= bytes_read
;
8062 if (lh
->num_file_names
< file
|| file
== 0)
8063 dwarf2_debug_line_missing_file_complaint ();
8066 fe
= &lh
->file_names
[file
- 1];
8068 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8069 if (!decode_for_pst_p
)
8071 last_subfile
= current_subfile
;
8072 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8077 case DW_LNS_set_column
:
8078 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8079 line_ptr
+= bytes_read
;
8081 case DW_LNS_negate_stmt
:
8082 is_stmt
= (!is_stmt
);
8084 case DW_LNS_set_basic_block
:
8087 /* Add to the address register of the state machine the
8088 address increment value corresponding to special opcode
8089 255. I.e., this value is scaled by the minimum
8090 instruction length since special opcode 255 would have
8091 scaled the the increment. */
8092 case DW_LNS_const_add_pc
:
8093 address
+= (lh
->minimum_instruction_length
8094 * ((255 - lh
->opcode_base
) / lh
->line_range
));
8096 case DW_LNS_fixed_advance_pc
:
8097 address
+= read_2_bytes (abfd
, line_ptr
);
8102 /* Unknown standard opcode, ignore it. */
8105 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
8107 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8108 line_ptr
+= bytes_read
;
8113 if (lh
->num_file_names
< file
|| file
== 0)
8114 dwarf2_debug_line_missing_file_complaint ();
8117 lh
->file_names
[file
- 1].included_p
= 1;
8118 if (!decode_for_pst_p
)
8120 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8121 record_line (current_subfile
, 0, addr
);
8126 if (decode_for_pst_p
)
8130 /* Now that we're done scanning the Line Header Program, we can
8131 create the psymtab of each included file. */
8132 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
8133 if (lh
->file_names
[file_index
].included_p
== 1)
8135 const struct file_entry fe
= lh
->file_names
[file_index
];
8136 char *include_name
= fe
.name
;
8137 char *dir_name
= NULL
;
8138 char *pst_filename
= pst
->filename
;
8141 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
8143 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
8145 include_name
= concat (dir_name
, SLASH_STRING
,
8146 include_name
, (char *)NULL
);
8147 make_cleanup (xfree
, include_name
);
8150 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
8152 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
8153 pst_filename
, (char *)NULL
);
8154 make_cleanup (xfree
, pst_filename
);
8157 if (strcmp (include_name
, pst_filename
) != 0)
8158 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
8163 /* Make sure a symtab is created for every file, even files
8164 which contain only variables (i.e. no code with associated
8168 struct file_entry
*fe
;
8170 for (i
= 0; i
< lh
->num_file_names
; i
++)
8173 fe
= &lh
->file_names
[i
];
8175 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8176 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8178 /* Skip the main file; we don't need it, and it must be
8179 allocated last, so that it will show up before the
8180 non-primary symtabs in the objfile's symtab list. */
8181 if (current_subfile
== first_subfile
)
8184 if (current_subfile
->symtab
== NULL
)
8185 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8187 fe
->symtab
= current_subfile
->symtab
;
8192 /* Start a subfile for DWARF. FILENAME is the name of the file and
8193 DIRNAME the name of the source directory which contains FILENAME
8194 or NULL if not known. COMP_DIR is the compilation directory for the
8195 linetable's compilation unit or NULL if not known.
8196 This routine tries to keep line numbers from identical absolute and
8197 relative file names in a common subfile.
8199 Using the `list' example from the GDB testsuite, which resides in
8200 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8201 of /srcdir/list0.c yields the following debugging information for list0.c:
8203 DW_AT_name: /srcdir/list0.c
8204 DW_AT_comp_dir: /compdir
8205 files.files[0].name: list0.h
8206 files.files[0].dir: /srcdir
8207 files.files[1].name: list0.c
8208 files.files[1].dir: /srcdir
8210 The line number information for list0.c has to end up in a single
8211 subfile, so that `break /srcdir/list0.c:1' works as expected.
8212 start_subfile will ensure that this happens provided that we pass the
8213 concatenation of files.files[1].dir and files.files[1].name as the
8217 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
8221 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8222 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8223 second argument to start_subfile. To be consistent, we do the
8224 same here. In order not to lose the line information directory,
8225 we concatenate it to the filename when it makes sense.
8226 Note that the Dwarf3 standard says (speaking of filenames in line
8227 information): ``The directory index is ignored for file names
8228 that represent full path names''. Thus ignoring dirname in the
8229 `else' branch below isn't an issue. */
8231 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
8232 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
8234 fullname
= filename
;
8236 start_subfile (fullname
, comp_dir
);
8238 if (fullname
!= filename
)
8243 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
8244 struct dwarf2_cu
*cu
)
8246 struct objfile
*objfile
= cu
->objfile
;
8247 struct comp_unit_head
*cu_header
= &cu
->header
;
8249 /* NOTE drow/2003-01-30: There used to be a comment and some special
8250 code here to turn a symbol with DW_AT_external and a
8251 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8252 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8253 with some versions of binutils) where shared libraries could have
8254 relocations against symbols in their debug information - the
8255 minimal symbol would have the right address, but the debug info
8256 would not. It's no longer necessary, because we will explicitly
8257 apply relocations when we read in the debug information now. */
8259 /* A DW_AT_location attribute with no contents indicates that a
8260 variable has been optimized away. */
8261 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
8263 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8267 /* Handle one degenerate form of location expression specially, to
8268 preserve GDB's previous behavior when section offsets are
8269 specified. If this is just a DW_OP_addr then mark this symbol
8272 if (attr_form_is_block (attr
)
8273 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
8274 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
8278 SYMBOL_VALUE_ADDRESS (sym
) =
8279 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
8280 SYMBOL_CLASS (sym
) = LOC_STATIC
;
8281 fixup_symbol_section (sym
, objfile
);
8282 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
8283 SYMBOL_SECTION (sym
));
8287 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8288 expression evaluator, and use LOC_COMPUTED only when necessary
8289 (i.e. when the value of a register or memory location is
8290 referenced, or a thread-local block, etc.). Then again, it might
8291 not be worthwhile. I'm assuming that it isn't unless performance
8292 or memory numbers show me otherwise. */
8294 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
8295 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
8298 /* Given a pointer to a DWARF information entry, figure out if we need
8299 to make a symbol table entry for it, and if so, create a new entry
8300 and return a pointer to it.
8301 If TYPE is NULL, determine symbol type from the die, otherwise
8302 used the passed type. */
8304 static struct symbol
*
8305 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
8307 struct objfile
*objfile
= cu
->objfile
;
8308 struct symbol
*sym
= NULL
;
8310 struct attribute
*attr
= NULL
;
8311 struct attribute
*attr2
= NULL
;
8313 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8315 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8317 name
= dwarf2_name (die
, cu
);
8320 const char *linkagename
;
8322 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
8323 sizeof (struct symbol
));
8324 OBJSTAT (objfile
, n_syms
++);
8325 memset (sym
, 0, sizeof (struct symbol
));
8327 /* Cache this symbol's name and the name's demangled form (if any). */
8328 SYMBOL_LANGUAGE (sym
) = cu
->language
;
8329 linkagename
= dwarf2_physname (name
, die
, cu
);
8330 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
8332 /* Default assumptions.
8333 Use the passed type or decode it from the die. */
8334 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8335 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8337 SYMBOL_TYPE (sym
) = type
;
8339 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
8340 attr
= dwarf2_attr (die
,
8341 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
8345 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
8348 attr
= dwarf2_attr (die
,
8349 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
8353 int file_index
= DW_UNSND (attr
);
8354 if (cu
->line_header
== NULL
8355 || file_index
> cu
->line_header
->num_file_names
)
8356 complaint (&symfile_complaints
,
8357 _("file index out of range"));
8358 else if (file_index
> 0)
8360 struct file_entry
*fe
;
8361 fe
= &cu
->line_header
->file_names
[file_index
- 1];
8362 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
8369 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8372 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
8374 SYMBOL_CLASS (sym
) = LOC_LABEL
;
8376 case DW_TAG_subprogram
:
8377 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8379 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8380 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8381 if ((attr2
&& (DW_UNSND (attr2
) != 0))
8382 || cu
->language
== language_ada
)
8384 /* Subprograms marked external are stored as a global symbol.
8385 Ada subprograms, whether marked external or not, are always
8386 stored as a global symbol, because we want to be able to
8387 access them globally. For instance, we want to be able
8388 to break on a nested subprogram without having to
8389 specify the context. */
8390 add_symbol_to_list (sym
, &global_symbols
);
8394 add_symbol_to_list (sym
, cu
->list_in_scope
);
8397 case DW_TAG_inlined_subroutine
:
8398 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8400 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8401 SYMBOL_INLINED (sym
) = 1;
8402 /* Do not add the symbol to any lists. It will be found via
8403 BLOCK_FUNCTION from the blockvector. */
8405 case DW_TAG_variable
:
8406 /* Compilation with minimal debug info may result in variables
8407 with missing type entries. Change the misleading `void' type
8408 to something sensible. */
8409 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
8411 = objfile_type (objfile
)->nodebug_data_symbol
;
8413 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8416 dwarf2_const_value (attr
, sym
, cu
);
8417 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8418 if (attr2
&& (DW_UNSND (attr2
) != 0))
8419 add_symbol_to_list (sym
, &global_symbols
);
8421 add_symbol_to_list (sym
, cu
->list_in_scope
);
8424 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8427 var_decode_location (attr
, sym
, cu
);
8428 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8429 if (attr2
&& (DW_UNSND (attr2
) != 0))
8431 struct pending
**list_to_add
;
8433 /* A variable with DW_AT_external is never static,
8434 but it may be block-scoped. */
8435 list_to_add
= (cu
->list_in_scope
== &file_symbols
8436 ? &global_symbols
: cu
->list_in_scope
);
8437 add_symbol_to_list (sym
, list_to_add
);
8440 add_symbol_to_list (sym
, cu
->list_in_scope
);
8444 /* We do not know the address of this symbol.
8445 If it is an external symbol and we have type information
8446 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8447 The address of the variable will then be determined from
8448 the minimal symbol table whenever the variable is
8450 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8451 if (attr2
&& (DW_UNSND (attr2
) != 0)
8452 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
8454 struct pending
**list_to_add
;
8456 /* A variable with DW_AT_external is never static, but it
8457 may be block-scoped. */
8458 list_to_add
= (cu
->list_in_scope
== &file_symbols
8459 ? &global_symbols
: cu
->list_in_scope
);
8461 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8462 add_symbol_to_list (sym
, list_to_add
);
8464 else if (!die_is_declaration (die
, cu
))
8466 /* Use the default LOC_OPTIMIZED_OUT class. */
8467 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
8468 add_symbol_to_list (sym
, cu
->list_in_scope
);
8472 case DW_TAG_formal_parameter
:
8473 /* If we are inside a function, mark this as an argument. If
8474 not, we might be looking at an argument to an inlined function
8475 when we do not have enough information to show inlined frames;
8476 pretend it's a local variable in that case so that the user can
8478 if (context_stack_depth
> 0
8479 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
8480 SYMBOL_IS_ARGUMENT (sym
) = 1;
8481 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8484 var_decode_location (attr
, sym
, cu
);
8486 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8489 dwarf2_const_value (attr
, sym
, cu
);
8491 add_symbol_to_list (sym
, cu
->list_in_scope
);
8493 case DW_TAG_unspecified_parameters
:
8494 /* From varargs functions; gdb doesn't seem to have any
8495 interest in this information, so just ignore it for now.
8498 case DW_TAG_class_type
:
8499 case DW_TAG_interface_type
:
8500 case DW_TAG_structure_type
:
8501 case DW_TAG_union_type
:
8502 case DW_TAG_set_type
:
8503 case DW_TAG_enumeration_type
:
8504 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8505 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8507 /* Make sure that the symbol includes appropriate enclosing
8508 classes/namespaces in its name. These are calculated in
8509 read_structure_type, and the correct name is saved in
8512 if (cu
->language
== language_cplus
8513 || cu
->language
== language_java
)
8515 struct type
*type
= SYMBOL_TYPE (sym
);
8517 if (TYPE_TAG_NAME (type
) != NULL
)
8519 /* FIXME: carlton/2003-11-10: Should this use
8520 SYMBOL_SET_NAMES instead? (The same problem also
8521 arises further down in this function.) */
8522 /* The type's name is already allocated along with
8523 this objfile, so we don't need to duplicate it
8525 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
8530 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8531 really ever be static objects: otherwise, if you try
8532 to, say, break of a class's method and you're in a file
8533 which doesn't mention that class, it won't work unless
8534 the check for all static symbols in lookup_symbol_aux
8535 saves you. See the OtherFileClass tests in
8536 gdb.c++/namespace.exp. */
8538 struct pending
**list_to_add
;
8540 list_to_add
= (cu
->list_in_scope
== &file_symbols
8541 && (cu
->language
== language_cplus
8542 || cu
->language
== language_java
)
8543 ? &global_symbols
: cu
->list_in_scope
);
8545 add_symbol_to_list (sym
, list_to_add
);
8547 /* The semantics of C++ state that "struct foo { ... }" also
8548 defines a typedef for "foo". A Java class declaration also
8549 defines a typedef for the class. */
8550 if (cu
->language
== language_cplus
8551 || cu
->language
== language_java
8552 || cu
->language
== language_ada
)
8554 /* The symbol's name is already allocated along with
8555 this objfile, so we don't need to duplicate it for
8557 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
8558 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
8562 case DW_TAG_typedef
:
8563 SYMBOL_LINKAGE_NAME (sym
)
8564 = (char *) dwarf2_full_name (name
, die
, cu
);
8565 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8566 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8567 add_symbol_to_list (sym
, cu
->list_in_scope
);
8569 case DW_TAG_base_type
:
8570 case DW_TAG_subrange_type
:
8571 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8572 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8573 add_symbol_to_list (sym
, cu
->list_in_scope
);
8575 case DW_TAG_enumerator
:
8576 SYMBOL_LINKAGE_NAME (sym
)
8577 = (char *) dwarf2_full_name (name
, die
, cu
);
8578 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8581 dwarf2_const_value (attr
, sym
, cu
);
8584 /* NOTE: carlton/2003-11-10: See comment above in the
8585 DW_TAG_class_type, etc. block. */
8587 struct pending
**list_to_add
;
8589 list_to_add
= (cu
->list_in_scope
== &file_symbols
8590 && (cu
->language
== language_cplus
8591 || cu
->language
== language_java
)
8592 ? &global_symbols
: cu
->list_in_scope
);
8594 add_symbol_to_list (sym
, list_to_add
);
8597 case DW_TAG_namespace
:
8598 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8599 add_symbol_to_list (sym
, &global_symbols
);
8602 /* Not a tag we recognize. Hopefully we aren't processing
8603 trash data, but since we must specifically ignore things
8604 we don't recognize, there is nothing else we should do at
8606 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8607 dwarf_tag_name (die
->tag
));
8611 /* For the benefit of old versions of GCC, check for anonymous
8612 namespaces based on the demangled name. */
8613 if (!processing_has_namespace_info
8614 && cu
->language
== language_cplus
)
8615 cp_scan_for_anonymous_namespaces (sym
);
8620 /* Copy constant value from an attribute to a symbol. */
8623 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8624 struct dwarf2_cu
*cu
)
8626 struct objfile
*objfile
= cu
->objfile
;
8627 struct comp_unit_head
*cu_header
= &cu
->header
;
8628 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
8629 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
8630 struct dwarf_block
*blk
;
8635 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8636 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8637 cu_header
->addr_size
,
8638 TYPE_LENGTH (SYMBOL_TYPE
8640 SYMBOL_VALUE_BYTES (sym
) =
8641 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8642 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8643 it's body - store_unsigned_integer. */
8644 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8645 byte_order
, DW_ADDR (attr
));
8646 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8648 case DW_FORM_string
:
8650 /* DW_STRING is already allocated on the obstack, point directly
8652 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8653 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8655 case DW_FORM_block1
:
8656 case DW_FORM_block2
:
8657 case DW_FORM_block4
:
8659 blk
= DW_BLOCK (attr
);
8660 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8661 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8663 TYPE_LENGTH (SYMBOL_TYPE
8665 SYMBOL_VALUE_BYTES (sym
) =
8666 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8667 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8668 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8671 /* The DW_AT_const_value attributes are supposed to carry the
8672 symbol's value "represented as it would be on the target
8673 architecture." By the time we get here, it's already been
8674 converted to host endianness, so we just need to sign- or
8675 zero-extend it as appropriate. */
8677 dwarf2_const_value_data (attr
, sym
, 8);
8680 dwarf2_const_value_data (attr
, sym
, 16);
8683 dwarf2_const_value_data (attr
, sym
, 32);
8686 dwarf2_const_value_data (attr
, sym
, 64);
8690 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8691 SYMBOL_CLASS (sym
) = LOC_CONST
;
8695 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8696 SYMBOL_CLASS (sym
) = LOC_CONST
;
8700 complaint (&symfile_complaints
,
8701 _("unsupported const value attribute form: '%s'"),
8702 dwarf_form_name (attr
->form
));
8703 SYMBOL_VALUE (sym
) = 0;
8704 SYMBOL_CLASS (sym
) = LOC_CONST
;
8710 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8711 or zero-extend it as appropriate for the symbol's type. */
8713 dwarf2_const_value_data (struct attribute
*attr
,
8717 LONGEST l
= DW_UNSND (attr
);
8719 if (bits
< sizeof (l
) * 8)
8721 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8722 l
&= ((LONGEST
) 1 << bits
) - 1;
8724 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8727 SYMBOL_VALUE (sym
) = l
;
8728 SYMBOL_CLASS (sym
) = LOC_CONST
;
8732 /* Return the type of the die in question using its DW_AT_type attribute. */
8734 static struct type
*
8735 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8738 struct attribute
*type_attr
;
8739 struct die_info
*type_die
;
8741 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8744 /* A missing DW_AT_type represents a void type. */
8745 return objfile_type (cu
->objfile
)->builtin_void
;
8748 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8750 type
= tag_type_to_type (type_die
, cu
);
8753 dump_die_for_error (type_die
);
8754 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8760 /* True iff CU's producer generates GNAT Ada auxiliary information
8761 that allows to find parallel types through that information instead
8762 of having to do expensive parallel lookups by type name. */
8765 need_gnat_info (struct dwarf2_cu
*cu
)
8767 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8768 of GNAT produces this auxiliary information, without any indication
8769 that it is produced. Part of enhancing the FSF version of GNAT
8770 to produce that information will be to put in place an indicator
8771 that we can use in order to determine whether the descriptive type
8772 info is available or not. One suggestion that has been made is
8773 to use a new attribute, attached to the CU die. For now, assume
8774 that the descriptive type info is not available. */
8779 /* Return the auxiliary type of the die in question using its
8780 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8781 attribute is not present. */
8783 static struct type
*
8784 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8787 struct attribute
*type_attr
;
8788 struct die_info
*type_die
;
8790 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
8794 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8795 type
= tag_type_to_type (type_die
, cu
);
8798 dump_die_for_error (type_die
);
8799 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8805 /* If DIE has a descriptive_type attribute, then set the TYPE's
8806 descriptive type accordingly. */
8809 set_descriptive_type (struct type
*type
, struct die_info
*die
,
8810 struct dwarf2_cu
*cu
)
8812 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
8814 if (descriptive_type
)
8816 ALLOCATE_GNAT_AUX_TYPE (type
);
8817 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
8821 /* Return the containing type of the die in question using its
8822 DW_AT_containing_type attribute. */
8824 static struct type
*
8825 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8827 struct type
*type
= NULL
;
8828 struct attribute
*type_attr
;
8829 struct die_info
*type_die
= NULL
;
8831 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8834 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8835 type
= tag_type_to_type (type_die
, cu
);
8840 dump_die_for_error (type_die
);
8841 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8847 static struct type
*
8848 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8850 struct type
*this_type
;
8852 this_type
= read_type_die (die
, cu
);
8855 dump_die_for_error (die
);
8856 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8862 static struct type
*
8863 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8865 struct type
*this_type
;
8867 this_type
= get_die_type (die
, cu
);
8873 case DW_TAG_class_type
:
8874 case DW_TAG_interface_type
:
8875 case DW_TAG_structure_type
:
8876 case DW_TAG_union_type
:
8877 this_type
= read_structure_type (die
, cu
);
8879 case DW_TAG_enumeration_type
:
8880 this_type
= read_enumeration_type (die
, cu
);
8882 case DW_TAG_subprogram
:
8883 case DW_TAG_subroutine_type
:
8884 case DW_TAG_inlined_subroutine
:
8885 this_type
= read_subroutine_type (die
, cu
);
8887 case DW_TAG_array_type
:
8888 this_type
= read_array_type (die
, cu
);
8890 case DW_TAG_set_type
:
8891 this_type
= read_set_type (die
, cu
);
8893 case DW_TAG_pointer_type
:
8894 this_type
= read_tag_pointer_type (die
, cu
);
8896 case DW_TAG_ptr_to_member_type
:
8897 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8899 case DW_TAG_reference_type
:
8900 this_type
= read_tag_reference_type (die
, cu
);
8902 case DW_TAG_const_type
:
8903 this_type
= read_tag_const_type (die
, cu
);
8905 case DW_TAG_volatile_type
:
8906 this_type
= read_tag_volatile_type (die
, cu
);
8908 case DW_TAG_string_type
:
8909 this_type
= read_tag_string_type (die
, cu
);
8911 case DW_TAG_typedef
:
8912 this_type
= read_typedef (die
, cu
);
8914 case DW_TAG_subrange_type
:
8915 this_type
= read_subrange_type (die
, cu
);
8917 case DW_TAG_base_type
:
8918 this_type
= read_base_type (die
, cu
);
8920 case DW_TAG_unspecified_type
:
8921 this_type
= read_unspecified_type (die
, cu
);
8923 case DW_TAG_namespace
:
8924 this_type
= read_namespace_type (die
, cu
);
8927 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8928 dwarf_tag_name (die
->tag
));
8935 /* Return the name of the namespace/class that DIE is defined within,
8936 or "" if we can't tell. The caller should not xfree the result.
8938 For example, if we're within the method foo() in the following
8948 then determine_prefix on foo's die will return "N::C". */
8951 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8953 struct die_info
*parent
, *spec_die
;
8954 struct dwarf2_cu
*spec_cu
;
8955 struct type
*parent_type
;
8957 if (cu
->language
!= language_cplus
8958 && cu
->language
!= language_java
)
8961 /* We have to be careful in the presence of DW_AT_specification.
8962 For example, with GCC 3.4, given the code
8966 // Definition of N::foo.
8970 then we'll have a tree of DIEs like this:
8972 1: DW_TAG_compile_unit
8973 2: DW_TAG_namespace // N
8974 3: DW_TAG_subprogram // declaration of N::foo
8975 4: DW_TAG_subprogram // definition of N::foo
8976 DW_AT_specification // refers to die #3
8978 Thus, when processing die #4, we have to pretend that we're in
8979 the context of its DW_AT_specification, namely the contex of die
8982 spec_die
= die_specification (die
, &spec_cu
);
8983 if (spec_die
== NULL
)
8984 parent
= die
->parent
;
8987 parent
= spec_die
->parent
;
8994 switch (parent
->tag
)
8996 case DW_TAG_namespace
:
8997 parent_type
= read_type_die (parent
, cu
);
8998 /* We give a name to even anonymous namespaces. */
8999 return TYPE_TAG_NAME (parent_type
);
9000 case DW_TAG_class_type
:
9001 case DW_TAG_interface_type
:
9002 case DW_TAG_structure_type
:
9003 case DW_TAG_union_type
:
9004 parent_type
= read_type_die (parent
, cu
);
9005 if (TYPE_TAG_NAME (parent_type
) != NULL
)
9006 return TYPE_TAG_NAME (parent_type
);
9008 /* An anonymous structure is only allowed non-static data
9009 members; no typedefs, no member functions, et cetera.
9010 So it does not need a prefix. */
9013 return determine_prefix (parent
, cu
);
9017 /* Return a newly-allocated string formed by concatenating PREFIX and
9018 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9019 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9020 perform an obconcat, otherwise allocate storage for the result. The CU argument
9021 is used to determine the language and hence, the appropriate separator. */
9023 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9026 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9027 struct dwarf2_cu
*cu
)
9031 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9033 else if (cu
->language
== language_java
)
9045 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9046 strcpy (retval
, prefix
);
9047 strcat (retval
, sep
);
9048 strcat (retval
, suffix
);
9053 /* We have an obstack. */
9054 return obconcat (obs
, prefix
, sep
, suffix
);
9058 /* Return sibling of die, NULL if no sibling. */
9060 static struct die_info
*
9061 sibling_die (struct die_info
*die
)
9063 return die
->sibling
;
9066 /* Get name of a die, return NULL if not found. */
9069 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9070 struct obstack
*obstack
)
9072 if (name
&& cu
->language
== language_cplus
)
9074 char *canon_name
= cp_canonicalize_string (name
);
9076 if (canon_name
!= NULL
)
9078 if (strcmp (canon_name
, name
) != 0)
9079 name
= obsavestring (canon_name
, strlen (canon_name
),
9088 /* Get name of a die, return NULL if not found. */
9091 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9093 struct attribute
*attr
;
9095 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9096 if (!attr
|| !DW_STRING (attr
))
9101 case DW_TAG_compile_unit
:
9102 /* Compilation units have a DW_AT_name that is a filename, not
9103 a source language identifier. */
9104 case DW_TAG_enumeration_type
:
9105 case DW_TAG_enumerator
:
9106 /* These tags always have simple identifiers already; no need
9107 to canonicalize them. */
9108 return DW_STRING (attr
);
9110 if (!DW_STRING_IS_CANONICAL (attr
))
9113 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9114 &cu
->objfile
->objfile_obstack
);
9115 DW_STRING_IS_CANONICAL (attr
) = 1;
9117 return DW_STRING (attr
);
9121 /* Return the die that this die in an extension of, or NULL if there
9122 is none. *EXT_CU is the CU containing DIE on input, and the CU
9123 containing the return value on output. */
9125 static struct die_info
*
9126 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9128 struct attribute
*attr
;
9130 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9134 return follow_die_ref (die
, attr
, ext_cu
);
9137 /* Convert a DIE tag into its string name. */
9140 dwarf_tag_name (unsigned tag
)
9144 case DW_TAG_padding
:
9145 return "DW_TAG_padding";
9146 case DW_TAG_array_type
:
9147 return "DW_TAG_array_type";
9148 case DW_TAG_class_type
:
9149 return "DW_TAG_class_type";
9150 case DW_TAG_entry_point
:
9151 return "DW_TAG_entry_point";
9152 case DW_TAG_enumeration_type
:
9153 return "DW_TAG_enumeration_type";
9154 case DW_TAG_formal_parameter
:
9155 return "DW_TAG_formal_parameter";
9156 case DW_TAG_imported_declaration
:
9157 return "DW_TAG_imported_declaration";
9159 return "DW_TAG_label";
9160 case DW_TAG_lexical_block
:
9161 return "DW_TAG_lexical_block";
9163 return "DW_TAG_member";
9164 case DW_TAG_pointer_type
:
9165 return "DW_TAG_pointer_type";
9166 case DW_TAG_reference_type
:
9167 return "DW_TAG_reference_type";
9168 case DW_TAG_compile_unit
:
9169 return "DW_TAG_compile_unit";
9170 case DW_TAG_string_type
:
9171 return "DW_TAG_string_type";
9172 case DW_TAG_structure_type
:
9173 return "DW_TAG_structure_type";
9174 case DW_TAG_subroutine_type
:
9175 return "DW_TAG_subroutine_type";
9176 case DW_TAG_typedef
:
9177 return "DW_TAG_typedef";
9178 case DW_TAG_union_type
:
9179 return "DW_TAG_union_type";
9180 case DW_TAG_unspecified_parameters
:
9181 return "DW_TAG_unspecified_parameters";
9182 case DW_TAG_variant
:
9183 return "DW_TAG_variant";
9184 case DW_TAG_common_block
:
9185 return "DW_TAG_common_block";
9186 case DW_TAG_common_inclusion
:
9187 return "DW_TAG_common_inclusion";
9188 case DW_TAG_inheritance
:
9189 return "DW_TAG_inheritance";
9190 case DW_TAG_inlined_subroutine
:
9191 return "DW_TAG_inlined_subroutine";
9193 return "DW_TAG_module";
9194 case DW_TAG_ptr_to_member_type
:
9195 return "DW_TAG_ptr_to_member_type";
9196 case DW_TAG_set_type
:
9197 return "DW_TAG_set_type";
9198 case DW_TAG_subrange_type
:
9199 return "DW_TAG_subrange_type";
9200 case DW_TAG_with_stmt
:
9201 return "DW_TAG_with_stmt";
9202 case DW_TAG_access_declaration
:
9203 return "DW_TAG_access_declaration";
9204 case DW_TAG_base_type
:
9205 return "DW_TAG_base_type";
9206 case DW_TAG_catch_block
:
9207 return "DW_TAG_catch_block";
9208 case DW_TAG_const_type
:
9209 return "DW_TAG_const_type";
9210 case DW_TAG_constant
:
9211 return "DW_TAG_constant";
9212 case DW_TAG_enumerator
:
9213 return "DW_TAG_enumerator";
9214 case DW_TAG_file_type
:
9215 return "DW_TAG_file_type";
9217 return "DW_TAG_friend";
9218 case DW_TAG_namelist
:
9219 return "DW_TAG_namelist";
9220 case DW_TAG_namelist_item
:
9221 return "DW_TAG_namelist_item";
9222 case DW_TAG_packed_type
:
9223 return "DW_TAG_packed_type";
9224 case DW_TAG_subprogram
:
9225 return "DW_TAG_subprogram";
9226 case DW_TAG_template_type_param
:
9227 return "DW_TAG_template_type_param";
9228 case DW_TAG_template_value_param
:
9229 return "DW_TAG_template_value_param";
9230 case DW_TAG_thrown_type
:
9231 return "DW_TAG_thrown_type";
9232 case DW_TAG_try_block
:
9233 return "DW_TAG_try_block";
9234 case DW_TAG_variant_part
:
9235 return "DW_TAG_variant_part";
9236 case DW_TAG_variable
:
9237 return "DW_TAG_variable";
9238 case DW_TAG_volatile_type
:
9239 return "DW_TAG_volatile_type";
9240 case DW_TAG_dwarf_procedure
:
9241 return "DW_TAG_dwarf_procedure";
9242 case DW_TAG_restrict_type
:
9243 return "DW_TAG_restrict_type";
9244 case DW_TAG_interface_type
:
9245 return "DW_TAG_interface_type";
9246 case DW_TAG_namespace
:
9247 return "DW_TAG_namespace";
9248 case DW_TAG_imported_module
:
9249 return "DW_TAG_imported_module";
9250 case DW_TAG_unspecified_type
:
9251 return "DW_TAG_unspecified_type";
9252 case DW_TAG_partial_unit
:
9253 return "DW_TAG_partial_unit";
9254 case DW_TAG_imported_unit
:
9255 return "DW_TAG_imported_unit";
9256 case DW_TAG_condition
:
9257 return "DW_TAG_condition";
9258 case DW_TAG_shared_type
:
9259 return "DW_TAG_shared_type";
9260 case DW_TAG_type_unit
:
9261 return "DW_TAG_type_unit";
9262 case DW_TAG_MIPS_loop
:
9263 return "DW_TAG_MIPS_loop";
9264 case DW_TAG_HP_array_descriptor
:
9265 return "DW_TAG_HP_array_descriptor";
9266 case DW_TAG_format_label
:
9267 return "DW_TAG_format_label";
9268 case DW_TAG_function_template
:
9269 return "DW_TAG_function_template";
9270 case DW_TAG_class_template
:
9271 return "DW_TAG_class_template";
9272 case DW_TAG_GNU_BINCL
:
9273 return "DW_TAG_GNU_BINCL";
9274 case DW_TAG_GNU_EINCL
:
9275 return "DW_TAG_GNU_EINCL";
9276 case DW_TAG_upc_shared_type
:
9277 return "DW_TAG_upc_shared_type";
9278 case DW_TAG_upc_strict_type
:
9279 return "DW_TAG_upc_strict_type";
9280 case DW_TAG_upc_relaxed_type
:
9281 return "DW_TAG_upc_relaxed_type";
9282 case DW_TAG_PGI_kanji_type
:
9283 return "DW_TAG_PGI_kanji_type";
9284 case DW_TAG_PGI_interface_block
:
9285 return "DW_TAG_PGI_interface_block";
9287 return "DW_TAG_<unknown>";
9291 /* Convert a DWARF attribute code into its string name. */
9294 dwarf_attr_name (unsigned attr
)
9299 return "DW_AT_sibling";
9300 case DW_AT_location
:
9301 return "DW_AT_location";
9303 return "DW_AT_name";
9304 case DW_AT_ordering
:
9305 return "DW_AT_ordering";
9306 case DW_AT_subscr_data
:
9307 return "DW_AT_subscr_data";
9308 case DW_AT_byte_size
:
9309 return "DW_AT_byte_size";
9310 case DW_AT_bit_offset
:
9311 return "DW_AT_bit_offset";
9312 case DW_AT_bit_size
:
9313 return "DW_AT_bit_size";
9314 case DW_AT_element_list
:
9315 return "DW_AT_element_list";
9316 case DW_AT_stmt_list
:
9317 return "DW_AT_stmt_list";
9319 return "DW_AT_low_pc";
9321 return "DW_AT_high_pc";
9322 case DW_AT_language
:
9323 return "DW_AT_language";
9325 return "DW_AT_member";
9327 return "DW_AT_discr";
9328 case DW_AT_discr_value
:
9329 return "DW_AT_discr_value";
9330 case DW_AT_visibility
:
9331 return "DW_AT_visibility";
9333 return "DW_AT_import";
9334 case DW_AT_string_length
:
9335 return "DW_AT_string_length";
9336 case DW_AT_common_reference
:
9337 return "DW_AT_common_reference";
9338 case DW_AT_comp_dir
:
9339 return "DW_AT_comp_dir";
9340 case DW_AT_const_value
:
9341 return "DW_AT_const_value";
9342 case DW_AT_containing_type
:
9343 return "DW_AT_containing_type";
9344 case DW_AT_default_value
:
9345 return "DW_AT_default_value";
9347 return "DW_AT_inline";
9348 case DW_AT_is_optional
:
9349 return "DW_AT_is_optional";
9350 case DW_AT_lower_bound
:
9351 return "DW_AT_lower_bound";
9352 case DW_AT_producer
:
9353 return "DW_AT_producer";
9354 case DW_AT_prototyped
:
9355 return "DW_AT_prototyped";
9356 case DW_AT_return_addr
:
9357 return "DW_AT_return_addr";
9358 case DW_AT_start_scope
:
9359 return "DW_AT_start_scope";
9360 case DW_AT_bit_stride
:
9361 return "DW_AT_bit_stride";
9362 case DW_AT_upper_bound
:
9363 return "DW_AT_upper_bound";
9364 case DW_AT_abstract_origin
:
9365 return "DW_AT_abstract_origin";
9366 case DW_AT_accessibility
:
9367 return "DW_AT_accessibility";
9368 case DW_AT_address_class
:
9369 return "DW_AT_address_class";
9370 case DW_AT_artificial
:
9371 return "DW_AT_artificial";
9372 case DW_AT_base_types
:
9373 return "DW_AT_base_types";
9374 case DW_AT_calling_convention
:
9375 return "DW_AT_calling_convention";
9377 return "DW_AT_count";
9378 case DW_AT_data_member_location
:
9379 return "DW_AT_data_member_location";
9380 case DW_AT_decl_column
:
9381 return "DW_AT_decl_column";
9382 case DW_AT_decl_file
:
9383 return "DW_AT_decl_file";
9384 case DW_AT_decl_line
:
9385 return "DW_AT_decl_line";
9386 case DW_AT_declaration
:
9387 return "DW_AT_declaration";
9388 case DW_AT_discr_list
:
9389 return "DW_AT_discr_list";
9390 case DW_AT_encoding
:
9391 return "DW_AT_encoding";
9392 case DW_AT_external
:
9393 return "DW_AT_external";
9394 case DW_AT_frame_base
:
9395 return "DW_AT_frame_base";
9397 return "DW_AT_friend";
9398 case DW_AT_identifier_case
:
9399 return "DW_AT_identifier_case";
9400 case DW_AT_macro_info
:
9401 return "DW_AT_macro_info";
9402 case DW_AT_namelist_items
:
9403 return "DW_AT_namelist_items";
9404 case DW_AT_priority
:
9405 return "DW_AT_priority";
9407 return "DW_AT_segment";
9408 case DW_AT_specification
:
9409 return "DW_AT_specification";
9410 case DW_AT_static_link
:
9411 return "DW_AT_static_link";
9413 return "DW_AT_type";
9414 case DW_AT_use_location
:
9415 return "DW_AT_use_location";
9416 case DW_AT_variable_parameter
:
9417 return "DW_AT_variable_parameter";
9418 case DW_AT_virtuality
:
9419 return "DW_AT_virtuality";
9420 case DW_AT_vtable_elem_location
:
9421 return "DW_AT_vtable_elem_location";
9422 /* DWARF 3 values. */
9423 case DW_AT_allocated
:
9424 return "DW_AT_allocated";
9425 case DW_AT_associated
:
9426 return "DW_AT_associated";
9427 case DW_AT_data_location
:
9428 return "DW_AT_data_location";
9429 case DW_AT_byte_stride
:
9430 return "DW_AT_byte_stride";
9431 case DW_AT_entry_pc
:
9432 return "DW_AT_entry_pc";
9433 case DW_AT_use_UTF8
:
9434 return "DW_AT_use_UTF8";
9435 case DW_AT_extension
:
9436 return "DW_AT_extension";
9438 return "DW_AT_ranges";
9439 case DW_AT_trampoline
:
9440 return "DW_AT_trampoline";
9441 case DW_AT_call_column
:
9442 return "DW_AT_call_column";
9443 case DW_AT_call_file
:
9444 return "DW_AT_call_file";
9445 case DW_AT_call_line
:
9446 return "DW_AT_call_line";
9447 case DW_AT_description
:
9448 return "DW_AT_description";
9449 case DW_AT_binary_scale
:
9450 return "DW_AT_binary_scale";
9451 case DW_AT_decimal_scale
:
9452 return "DW_AT_decimal_scale";
9454 return "DW_AT_small";
9455 case DW_AT_decimal_sign
:
9456 return "DW_AT_decimal_sign";
9457 case DW_AT_digit_count
:
9458 return "DW_AT_digit_count";
9459 case DW_AT_picture_string
:
9460 return "DW_AT_picture_string";
9462 return "DW_AT_mutable";
9463 case DW_AT_threads_scaled
:
9464 return "DW_AT_threads_scaled";
9465 case DW_AT_explicit
:
9466 return "DW_AT_explicit";
9467 case DW_AT_object_pointer
:
9468 return "DW_AT_object_pointer";
9469 case DW_AT_endianity
:
9470 return "DW_AT_endianity";
9471 case DW_AT_elemental
:
9472 return "DW_AT_elemental";
9474 return "DW_AT_pure";
9475 case DW_AT_recursive
:
9476 return "DW_AT_recursive";
9477 /* DWARF 4 values. */
9478 case DW_AT_signature
:
9479 return "DW_AT_signature";
9480 /* SGI/MIPS extensions. */
9481 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9482 case DW_AT_MIPS_fde
:
9483 return "DW_AT_MIPS_fde";
9485 case DW_AT_MIPS_loop_begin
:
9486 return "DW_AT_MIPS_loop_begin";
9487 case DW_AT_MIPS_tail_loop_begin
:
9488 return "DW_AT_MIPS_tail_loop_begin";
9489 case DW_AT_MIPS_epilog_begin
:
9490 return "DW_AT_MIPS_epilog_begin";
9491 case DW_AT_MIPS_loop_unroll_factor
:
9492 return "DW_AT_MIPS_loop_unroll_factor";
9493 case DW_AT_MIPS_software_pipeline_depth
:
9494 return "DW_AT_MIPS_software_pipeline_depth";
9495 case DW_AT_MIPS_linkage_name
:
9496 return "DW_AT_MIPS_linkage_name";
9497 case DW_AT_MIPS_stride
:
9498 return "DW_AT_MIPS_stride";
9499 case DW_AT_MIPS_abstract_name
:
9500 return "DW_AT_MIPS_abstract_name";
9501 case DW_AT_MIPS_clone_origin
:
9502 return "DW_AT_MIPS_clone_origin";
9503 case DW_AT_MIPS_has_inlines
:
9504 return "DW_AT_MIPS_has_inlines";
9505 /* HP extensions. */
9506 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9507 case DW_AT_HP_block_index
:
9508 return "DW_AT_HP_block_index";
9510 case DW_AT_HP_unmodifiable
:
9511 return "DW_AT_HP_unmodifiable";
9512 case DW_AT_HP_actuals_stmt_list
:
9513 return "DW_AT_HP_actuals_stmt_list";
9514 case DW_AT_HP_proc_per_section
:
9515 return "DW_AT_HP_proc_per_section";
9516 case DW_AT_HP_raw_data_ptr
:
9517 return "DW_AT_HP_raw_data_ptr";
9518 case DW_AT_HP_pass_by_reference
:
9519 return "DW_AT_HP_pass_by_reference";
9520 case DW_AT_HP_opt_level
:
9521 return "DW_AT_HP_opt_level";
9522 case DW_AT_HP_prof_version_id
:
9523 return "DW_AT_HP_prof_version_id";
9524 case DW_AT_HP_opt_flags
:
9525 return "DW_AT_HP_opt_flags";
9526 case DW_AT_HP_cold_region_low_pc
:
9527 return "DW_AT_HP_cold_region_low_pc";
9528 case DW_AT_HP_cold_region_high_pc
:
9529 return "DW_AT_HP_cold_region_high_pc";
9530 case DW_AT_HP_all_variables_modifiable
:
9531 return "DW_AT_HP_all_variables_modifiable";
9532 case DW_AT_HP_linkage_name
:
9533 return "DW_AT_HP_linkage_name";
9534 case DW_AT_HP_prof_flags
:
9535 return "DW_AT_HP_prof_flags";
9536 /* GNU extensions. */
9537 case DW_AT_sf_names
:
9538 return "DW_AT_sf_names";
9539 case DW_AT_src_info
:
9540 return "DW_AT_src_info";
9541 case DW_AT_mac_info
:
9542 return "DW_AT_mac_info";
9543 case DW_AT_src_coords
:
9544 return "DW_AT_src_coords";
9545 case DW_AT_body_begin
:
9546 return "DW_AT_body_begin";
9547 case DW_AT_body_end
:
9548 return "DW_AT_body_end";
9549 case DW_AT_GNU_vector
:
9550 return "DW_AT_GNU_vector";
9551 /* VMS extensions. */
9552 case DW_AT_VMS_rtnbeg_pd_address
:
9553 return "DW_AT_VMS_rtnbeg_pd_address";
9554 /* UPC extension. */
9555 case DW_AT_upc_threads_scaled
:
9556 return "DW_AT_upc_threads_scaled";
9557 /* PGI (STMicroelectronics) extensions. */
9558 case DW_AT_PGI_lbase
:
9559 return "DW_AT_PGI_lbase";
9560 case DW_AT_PGI_soffset
:
9561 return "DW_AT_PGI_soffset";
9562 case DW_AT_PGI_lstride
:
9563 return "DW_AT_PGI_lstride";
9565 return "DW_AT_<unknown>";
9569 /* Convert a DWARF value form code into its string name. */
9572 dwarf_form_name (unsigned form
)
9577 return "DW_FORM_addr";
9578 case DW_FORM_block2
:
9579 return "DW_FORM_block2";
9580 case DW_FORM_block4
:
9581 return "DW_FORM_block4";
9583 return "DW_FORM_data2";
9585 return "DW_FORM_data4";
9587 return "DW_FORM_data8";
9588 case DW_FORM_string
:
9589 return "DW_FORM_string";
9591 return "DW_FORM_block";
9592 case DW_FORM_block1
:
9593 return "DW_FORM_block1";
9595 return "DW_FORM_data1";
9597 return "DW_FORM_flag";
9599 return "DW_FORM_sdata";
9601 return "DW_FORM_strp";
9603 return "DW_FORM_udata";
9604 case DW_FORM_ref_addr
:
9605 return "DW_FORM_ref_addr";
9607 return "DW_FORM_ref1";
9609 return "DW_FORM_ref2";
9611 return "DW_FORM_ref4";
9613 return "DW_FORM_ref8";
9614 case DW_FORM_ref_udata
:
9615 return "DW_FORM_ref_udata";
9616 case DW_FORM_indirect
:
9617 return "DW_FORM_indirect";
9618 case DW_FORM_sec_offset
:
9619 return "DW_FORM_sec_offset";
9620 case DW_FORM_exprloc
:
9621 return "DW_FORM_exprloc";
9622 case DW_FORM_flag_present
:
9623 return "DW_FORM_flag_present";
9625 return "DW_FORM_sig8";
9627 return "DW_FORM_<unknown>";
9631 /* Convert a DWARF stack opcode into its string name. */
9634 dwarf_stack_op_name (unsigned op
)
9639 return "DW_OP_addr";
9641 return "DW_OP_deref";
9643 return "DW_OP_const1u";
9645 return "DW_OP_const1s";
9647 return "DW_OP_const2u";
9649 return "DW_OP_const2s";
9651 return "DW_OP_const4u";
9653 return "DW_OP_const4s";
9655 return "DW_OP_const8u";
9657 return "DW_OP_const8s";
9659 return "DW_OP_constu";
9661 return "DW_OP_consts";
9665 return "DW_OP_drop";
9667 return "DW_OP_over";
9669 return "DW_OP_pick";
9671 return "DW_OP_swap";
9675 return "DW_OP_xderef";
9683 return "DW_OP_minus";
9695 return "DW_OP_plus";
9696 case DW_OP_plus_uconst
:
9697 return "DW_OP_plus_uconst";
9703 return "DW_OP_shra";
9721 return "DW_OP_skip";
9723 return "DW_OP_lit0";
9725 return "DW_OP_lit1";
9727 return "DW_OP_lit2";
9729 return "DW_OP_lit3";
9731 return "DW_OP_lit4";
9733 return "DW_OP_lit5";
9735 return "DW_OP_lit6";
9737 return "DW_OP_lit7";
9739 return "DW_OP_lit8";
9741 return "DW_OP_lit9";
9743 return "DW_OP_lit10";
9745 return "DW_OP_lit11";
9747 return "DW_OP_lit12";
9749 return "DW_OP_lit13";
9751 return "DW_OP_lit14";
9753 return "DW_OP_lit15";
9755 return "DW_OP_lit16";
9757 return "DW_OP_lit17";
9759 return "DW_OP_lit18";
9761 return "DW_OP_lit19";
9763 return "DW_OP_lit20";
9765 return "DW_OP_lit21";
9767 return "DW_OP_lit22";
9769 return "DW_OP_lit23";
9771 return "DW_OP_lit24";
9773 return "DW_OP_lit25";
9775 return "DW_OP_lit26";
9777 return "DW_OP_lit27";
9779 return "DW_OP_lit28";
9781 return "DW_OP_lit29";
9783 return "DW_OP_lit30";
9785 return "DW_OP_lit31";
9787 return "DW_OP_reg0";
9789 return "DW_OP_reg1";
9791 return "DW_OP_reg2";
9793 return "DW_OP_reg3";
9795 return "DW_OP_reg4";
9797 return "DW_OP_reg5";
9799 return "DW_OP_reg6";
9801 return "DW_OP_reg7";
9803 return "DW_OP_reg8";
9805 return "DW_OP_reg9";
9807 return "DW_OP_reg10";
9809 return "DW_OP_reg11";
9811 return "DW_OP_reg12";
9813 return "DW_OP_reg13";
9815 return "DW_OP_reg14";
9817 return "DW_OP_reg15";
9819 return "DW_OP_reg16";
9821 return "DW_OP_reg17";
9823 return "DW_OP_reg18";
9825 return "DW_OP_reg19";
9827 return "DW_OP_reg20";
9829 return "DW_OP_reg21";
9831 return "DW_OP_reg22";
9833 return "DW_OP_reg23";
9835 return "DW_OP_reg24";
9837 return "DW_OP_reg25";
9839 return "DW_OP_reg26";
9841 return "DW_OP_reg27";
9843 return "DW_OP_reg28";
9845 return "DW_OP_reg29";
9847 return "DW_OP_reg30";
9849 return "DW_OP_reg31";
9851 return "DW_OP_breg0";
9853 return "DW_OP_breg1";
9855 return "DW_OP_breg2";
9857 return "DW_OP_breg3";
9859 return "DW_OP_breg4";
9861 return "DW_OP_breg5";
9863 return "DW_OP_breg6";
9865 return "DW_OP_breg7";
9867 return "DW_OP_breg8";
9869 return "DW_OP_breg9";
9871 return "DW_OP_breg10";
9873 return "DW_OP_breg11";
9875 return "DW_OP_breg12";
9877 return "DW_OP_breg13";
9879 return "DW_OP_breg14";
9881 return "DW_OP_breg15";
9883 return "DW_OP_breg16";
9885 return "DW_OP_breg17";
9887 return "DW_OP_breg18";
9889 return "DW_OP_breg19";
9891 return "DW_OP_breg20";
9893 return "DW_OP_breg21";
9895 return "DW_OP_breg22";
9897 return "DW_OP_breg23";
9899 return "DW_OP_breg24";
9901 return "DW_OP_breg25";
9903 return "DW_OP_breg26";
9905 return "DW_OP_breg27";
9907 return "DW_OP_breg28";
9909 return "DW_OP_breg29";
9911 return "DW_OP_breg30";
9913 return "DW_OP_breg31";
9915 return "DW_OP_regx";
9917 return "DW_OP_fbreg";
9919 return "DW_OP_bregx";
9921 return "DW_OP_piece";
9922 case DW_OP_deref_size
:
9923 return "DW_OP_deref_size";
9924 case DW_OP_xderef_size
:
9925 return "DW_OP_xderef_size";
9928 /* DWARF 3 extensions. */
9929 case DW_OP_push_object_address
:
9930 return "DW_OP_push_object_address";
9932 return "DW_OP_call2";
9934 return "DW_OP_call4";
9935 case DW_OP_call_ref
:
9936 return "DW_OP_call_ref";
9937 /* GNU extensions. */
9938 case DW_OP_form_tls_address
:
9939 return "DW_OP_form_tls_address";
9940 case DW_OP_call_frame_cfa
:
9941 return "DW_OP_call_frame_cfa";
9942 case DW_OP_bit_piece
:
9943 return "DW_OP_bit_piece";
9944 case DW_OP_GNU_push_tls_address
:
9945 return "DW_OP_GNU_push_tls_address";
9946 case DW_OP_GNU_uninit
:
9947 return "DW_OP_GNU_uninit";
9948 /* HP extensions. */
9949 case DW_OP_HP_is_value
:
9950 return "DW_OP_HP_is_value";
9951 case DW_OP_HP_fltconst4
:
9952 return "DW_OP_HP_fltconst4";
9953 case DW_OP_HP_fltconst8
:
9954 return "DW_OP_HP_fltconst8";
9955 case DW_OP_HP_mod_range
:
9956 return "DW_OP_HP_mod_range";
9957 case DW_OP_HP_unmod_range
:
9958 return "DW_OP_HP_unmod_range";
9960 return "DW_OP_HP_tls";
9962 return "OP_<unknown>";
9967 dwarf_bool_name (unsigned mybool
)
9975 /* Convert a DWARF type code into its string name. */
9978 dwarf_type_encoding_name (unsigned enc
)
9983 return "DW_ATE_void";
9984 case DW_ATE_address
:
9985 return "DW_ATE_address";
9986 case DW_ATE_boolean
:
9987 return "DW_ATE_boolean";
9988 case DW_ATE_complex_float
:
9989 return "DW_ATE_complex_float";
9991 return "DW_ATE_float";
9993 return "DW_ATE_signed";
9994 case DW_ATE_signed_char
:
9995 return "DW_ATE_signed_char";
9996 case DW_ATE_unsigned
:
9997 return "DW_ATE_unsigned";
9998 case DW_ATE_unsigned_char
:
9999 return "DW_ATE_unsigned_char";
10001 case DW_ATE_imaginary_float
:
10002 return "DW_ATE_imaginary_float";
10003 case DW_ATE_packed_decimal
:
10004 return "DW_ATE_packed_decimal";
10005 case DW_ATE_numeric_string
:
10006 return "DW_ATE_numeric_string";
10007 case DW_ATE_edited
:
10008 return "DW_ATE_edited";
10009 case DW_ATE_signed_fixed
:
10010 return "DW_ATE_signed_fixed";
10011 case DW_ATE_unsigned_fixed
:
10012 return "DW_ATE_unsigned_fixed";
10013 case DW_ATE_decimal_float
:
10014 return "DW_ATE_decimal_float";
10015 /* HP extensions. */
10016 case DW_ATE_HP_float80
:
10017 return "DW_ATE_HP_float80";
10018 case DW_ATE_HP_complex_float80
:
10019 return "DW_ATE_HP_complex_float80";
10020 case DW_ATE_HP_float128
:
10021 return "DW_ATE_HP_float128";
10022 case DW_ATE_HP_complex_float128
:
10023 return "DW_ATE_HP_complex_float128";
10024 case DW_ATE_HP_floathpintel
:
10025 return "DW_ATE_HP_floathpintel";
10026 case DW_ATE_HP_imaginary_float80
:
10027 return "DW_ATE_HP_imaginary_float80";
10028 case DW_ATE_HP_imaginary_float128
:
10029 return "DW_ATE_HP_imaginary_float128";
10031 return "DW_ATE_<unknown>";
10035 /* Convert a DWARF call frame info operation to its string name. */
10039 dwarf_cfi_name (unsigned cfi_opc
)
10043 case DW_CFA_advance_loc
:
10044 return "DW_CFA_advance_loc";
10045 case DW_CFA_offset
:
10046 return "DW_CFA_offset";
10047 case DW_CFA_restore
:
10048 return "DW_CFA_restore";
10050 return "DW_CFA_nop";
10051 case DW_CFA_set_loc
:
10052 return "DW_CFA_set_loc";
10053 case DW_CFA_advance_loc1
:
10054 return "DW_CFA_advance_loc1";
10055 case DW_CFA_advance_loc2
:
10056 return "DW_CFA_advance_loc2";
10057 case DW_CFA_advance_loc4
:
10058 return "DW_CFA_advance_loc4";
10059 case DW_CFA_offset_extended
:
10060 return "DW_CFA_offset_extended";
10061 case DW_CFA_restore_extended
:
10062 return "DW_CFA_restore_extended";
10063 case DW_CFA_undefined
:
10064 return "DW_CFA_undefined";
10065 case DW_CFA_same_value
:
10066 return "DW_CFA_same_value";
10067 case DW_CFA_register
:
10068 return "DW_CFA_register";
10069 case DW_CFA_remember_state
:
10070 return "DW_CFA_remember_state";
10071 case DW_CFA_restore_state
:
10072 return "DW_CFA_restore_state";
10073 case DW_CFA_def_cfa
:
10074 return "DW_CFA_def_cfa";
10075 case DW_CFA_def_cfa_register
:
10076 return "DW_CFA_def_cfa_register";
10077 case DW_CFA_def_cfa_offset
:
10078 return "DW_CFA_def_cfa_offset";
10080 case DW_CFA_def_cfa_expression
:
10081 return "DW_CFA_def_cfa_expression";
10082 case DW_CFA_expression
:
10083 return "DW_CFA_expression";
10084 case DW_CFA_offset_extended_sf
:
10085 return "DW_CFA_offset_extended_sf";
10086 case DW_CFA_def_cfa_sf
:
10087 return "DW_CFA_def_cfa_sf";
10088 case DW_CFA_def_cfa_offset_sf
:
10089 return "DW_CFA_def_cfa_offset_sf";
10090 case DW_CFA_val_offset
:
10091 return "DW_CFA_val_offset";
10092 case DW_CFA_val_offset_sf
:
10093 return "DW_CFA_val_offset_sf";
10094 case DW_CFA_val_expression
:
10095 return "DW_CFA_val_expression";
10096 /* SGI/MIPS specific. */
10097 case DW_CFA_MIPS_advance_loc8
:
10098 return "DW_CFA_MIPS_advance_loc8";
10099 /* GNU extensions. */
10100 case DW_CFA_GNU_window_save
:
10101 return "DW_CFA_GNU_window_save";
10102 case DW_CFA_GNU_args_size
:
10103 return "DW_CFA_GNU_args_size";
10104 case DW_CFA_GNU_negative_offset_extended
:
10105 return "DW_CFA_GNU_negative_offset_extended";
10107 return "DW_CFA_<unknown>";
10113 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10117 print_spaces (indent
, f
);
10118 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10119 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10121 if (die
->parent
!= NULL
)
10123 print_spaces (indent
, f
);
10124 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10125 die
->parent
->offset
);
10128 print_spaces (indent
, f
);
10129 fprintf_unfiltered (f
, " has children: %s\n",
10130 dwarf_bool_name (die
->child
!= NULL
));
10132 print_spaces (indent
, f
);
10133 fprintf_unfiltered (f
, " attributes:\n");
10135 for (i
= 0; i
< die
->num_attrs
; ++i
)
10137 print_spaces (indent
, f
);
10138 fprintf_unfiltered (f
, " %s (%s) ",
10139 dwarf_attr_name (die
->attrs
[i
].name
),
10140 dwarf_form_name (die
->attrs
[i
].form
));
10142 switch (die
->attrs
[i
].form
)
10144 case DW_FORM_ref_addr
:
10146 fprintf_unfiltered (f
, "address: ");
10147 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10149 case DW_FORM_block2
:
10150 case DW_FORM_block4
:
10151 case DW_FORM_block
:
10152 case DW_FORM_block1
:
10153 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10158 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10159 (long) (DW_ADDR (&die
->attrs
[i
])));
10161 case DW_FORM_data1
:
10162 case DW_FORM_data2
:
10163 case DW_FORM_data4
:
10164 case DW_FORM_data8
:
10165 case DW_FORM_udata
:
10166 case DW_FORM_sdata
:
10167 fprintf_unfiltered (f
, "constant: %s",
10168 pulongest (DW_UNSND (&die
->attrs
[i
])));
10171 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10172 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10173 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10175 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10177 case DW_FORM_string
:
10179 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10180 DW_STRING (&die
->attrs
[i
])
10181 ? DW_STRING (&die
->attrs
[i
]) : "",
10182 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10185 if (DW_UNSND (&die
->attrs
[i
]))
10186 fprintf_unfiltered (f
, "flag: TRUE");
10188 fprintf_unfiltered (f
, "flag: FALSE");
10190 case DW_FORM_indirect
:
10191 /* the reader will have reduced the indirect form to
10192 the "base form" so this form should not occur */
10193 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10196 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10197 die
->attrs
[i
].form
);
10200 fprintf_unfiltered (f
, "\n");
10205 dump_die_for_error (struct die_info
*die
)
10207 dump_die_shallow (gdb_stderr
, 0, die
);
10211 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10213 int indent
= level
* 4;
10215 gdb_assert (die
!= NULL
);
10217 if (level
>= max_level
)
10220 dump_die_shallow (f
, indent
, die
);
10222 if (die
->child
!= NULL
)
10224 print_spaces (indent
, f
);
10225 fprintf_unfiltered (f
, " Children:");
10226 if (level
+ 1 < max_level
)
10228 fprintf_unfiltered (f
, "\n");
10229 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10233 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10237 if (die
->sibling
!= NULL
&& level
> 0)
10239 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10243 /* This is called from the pdie macro in gdbinit.in.
10244 It's not static so gcc will keep a copy callable from gdb. */
10247 dump_die (struct die_info
*die
, int max_level
)
10249 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10253 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10257 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10263 is_ref_attr (struct attribute
*attr
)
10265 switch (attr
->form
)
10267 case DW_FORM_ref_addr
:
10272 case DW_FORM_ref_udata
:
10279 static unsigned int
10280 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10282 if (is_ref_attr (attr
))
10283 return DW_ADDR (attr
);
10285 complaint (&symfile_complaints
,
10286 _("unsupported die ref attribute form: '%s'"),
10287 dwarf_form_name (attr
->form
));
10291 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10292 * the value held by the attribute is not constant. */
10295 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10297 if (attr
->form
== DW_FORM_sdata
)
10298 return DW_SND (attr
);
10299 else if (attr
->form
== DW_FORM_udata
10300 || attr
->form
== DW_FORM_data1
10301 || attr
->form
== DW_FORM_data2
10302 || attr
->form
== DW_FORM_data4
10303 || attr
->form
== DW_FORM_data8
)
10304 return DW_UNSND (attr
);
10307 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10308 dwarf_form_name (attr
->form
));
10309 return default_value
;
10313 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10314 unit and add it to our queue.
10315 The result is non-zero if PER_CU was queued, otherwise the result is zero
10316 meaning either PER_CU is already queued or it is already loaded. */
10319 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10320 struct dwarf2_per_cu_data
*per_cu
)
10322 /* Mark the dependence relation so that we don't flush PER_CU
10324 dwarf2_add_dependence (this_cu
, per_cu
);
10326 /* If it's already on the queue, we have nothing to do. */
10327 if (per_cu
->queued
)
10330 /* If the compilation unit is already loaded, just mark it as
10332 if (per_cu
->cu
!= NULL
)
10334 per_cu
->cu
->last_used
= 0;
10338 /* Add it to the queue. */
10339 queue_comp_unit (per_cu
, this_cu
->objfile
);
10344 /* Follow reference or signature attribute ATTR of SRC_DIE.
10345 On entry *REF_CU is the CU of SRC_DIE.
10346 On exit *REF_CU is the CU of the result. */
10348 static struct die_info
*
10349 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10350 struct dwarf2_cu
**ref_cu
)
10352 struct die_info
*die
;
10354 if (is_ref_attr (attr
))
10355 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10356 else if (attr
->form
== DW_FORM_sig8
)
10357 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10360 dump_die_for_error (src_die
);
10361 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10362 (*ref_cu
)->objfile
->name
);
10368 /* Follow reference attribute ATTR of SRC_DIE.
10369 On entry *REF_CU is the CU of SRC_DIE.
10370 On exit *REF_CU is the CU of the result. */
10372 static struct die_info
*
10373 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10374 struct dwarf2_cu
**ref_cu
)
10376 struct die_info
*die
;
10377 unsigned int offset
;
10378 struct die_info temp_die
;
10379 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10381 gdb_assert (cu
->per_cu
!= NULL
);
10383 offset
= dwarf2_get_ref_die_offset (attr
);
10385 if (cu
->per_cu
->from_debug_types
)
10387 /* .debug_types CUs cannot reference anything outside their CU.
10388 If they need to, they have to reference a signatured type via
10390 if (! offset_in_cu_p (&cu
->header
, offset
))
10394 else if (! offset_in_cu_p (&cu
->header
, offset
))
10396 struct dwarf2_per_cu_data
*per_cu
;
10397 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10399 /* If necessary, add it to the queue and load its DIEs. */
10400 if (maybe_queue_comp_unit (cu
, per_cu
))
10401 load_full_comp_unit (per_cu
, cu
->objfile
);
10403 target_cu
= per_cu
->cu
;
10408 *ref_cu
= target_cu
;
10409 temp_die
.offset
= offset
;
10410 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10416 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10417 "at 0x%x [in module %s]"),
10418 offset
, src_die
->offset
, cu
->objfile
->name
);
10421 /* Follow the signature attribute ATTR in SRC_DIE.
10422 On entry *REF_CU is the CU of SRC_DIE.
10423 On exit *REF_CU is the CU of the result. */
10425 static struct die_info
*
10426 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10427 struct dwarf2_cu
**ref_cu
)
10429 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10430 struct die_info temp_die
;
10431 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10432 struct dwarf2_cu
*sig_cu
;
10433 struct die_info
*die
;
10435 /* sig_type will be NULL if the signatured type is missing from
10437 if (sig_type
== NULL
)
10438 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10439 "at 0x%x [in module %s]"),
10440 src_die
->offset
, objfile
->name
);
10442 /* If necessary, add it to the queue and load its DIEs. */
10444 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10445 read_signatured_type (objfile
, sig_type
);
10447 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10449 sig_cu
= sig_type
->per_cu
.cu
;
10450 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10451 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10458 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10459 "at 0x%x [in module %s]"),
10460 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10463 /* Given an offset of a signatured type, return its signatured_type. */
10465 static struct signatured_type
*
10466 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10468 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10469 unsigned int length
, initial_length_size
;
10470 unsigned int sig_offset
;
10471 struct signatured_type find_entry
, *type_sig
;
10473 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10474 sig_offset
= (initial_length_size
10476 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10477 + 1 /*address_size*/);
10478 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10479 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10481 /* This is only used to lookup previously recorded types.
10482 If we didn't find it, it's our bug. */
10483 gdb_assert (type_sig
!= NULL
);
10484 gdb_assert (offset
== type_sig
->offset
);
10489 /* Read in signatured type at OFFSET and build its CU and die(s). */
10492 read_signatured_type_at_offset (struct objfile
*objfile
,
10493 unsigned int offset
)
10495 struct signatured_type
*type_sig
;
10497 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
10499 /* We have the section offset, but we need the signature to do the
10500 hash table lookup. */
10501 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10503 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10505 read_signatured_type (objfile
, type_sig
);
10507 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10510 /* Read in a signatured type and build its CU and DIEs. */
10513 read_signatured_type (struct objfile
*objfile
,
10514 struct signatured_type
*type_sig
)
10516 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10517 struct die_reader_specs reader_specs
;
10518 struct dwarf2_cu
*cu
;
10519 ULONGEST signature
;
10520 struct cleanup
*back_to
, *free_cu_cleanup
;
10521 struct attribute
*attr
;
10523 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10525 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10526 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10527 obstack_init (&cu
->comp_unit_obstack
);
10528 cu
->objfile
= objfile
;
10529 type_sig
->per_cu
.cu
= cu
;
10530 cu
->per_cu
= &type_sig
->per_cu
;
10532 /* If an error occurs while loading, release our storage. */
10533 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10535 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10536 types_ptr
, objfile
->obfd
);
10537 gdb_assert (signature
== type_sig
->signature
);
10540 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10544 &cu
->comp_unit_obstack
,
10545 hashtab_obstack_allocate
,
10546 dummy_obstack_deallocate
);
10548 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10549 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10551 init_cu_die_reader (&reader_specs
, cu
);
10553 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10556 /* We try not to read any attributes in this function, because not
10557 all objfiles needed for references have been loaded yet, and symbol
10558 table processing isn't initialized. But we have to set the CU language,
10559 or we won't be able to build types correctly. */
10560 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10562 set_cu_language (DW_UNSND (attr
), cu
);
10564 set_cu_language (language_minimal
, cu
);
10566 do_cleanups (back_to
);
10568 /* We've successfully allocated this compilation unit. Let our caller
10569 clean it up when finished with it. */
10570 discard_cleanups (free_cu_cleanup
);
10572 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10573 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10576 /* Decode simple location descriptions.
10577 Given a pointer to a dwarf block that defines a location, compute
10578 the location and return the value.
10580 NOTE drow/2003-11-18: This function is called in two situations
10581 now: for the address of static or global variables (partial symbols
10582 only) and for offsets into structures which are expected to be
10583 (more or less) constant. The partial symbol case should go away,
10584 and only the constant case should remain. That will let this
10585 function complain more accurately. A few special modes are allowed
10586 without complaint for global variables (for instance, global
10587 register values and thread-local values).
10589 A location description containing no operations indicates that the
10590 object is optimized out. The return value is 0 for that case.
10591 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10592 callers will only want a very basic result and this can become a
10595 Note that stack[0] is unused except as a default error return.
10596 Note that stack overflow is not yet handled. */
10599 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10601 struct objfile
*objfile
= cu
->objfile
;
10602 struct comp_unit_head
*cu_header
= &cu
->header
;
10604 int size
= blk
->size
;
10605 gdb_byte
*data
= blk
->data
;
10606 CORE_ADDR stack
[64];
10608 unsigned int bytes_read
, unsnd
;
10652 stack
[++stacki
] = op
- DW_OP_lit0
;
10687 stack
[++stacki
] = op
- DW_OP_reg0
;
10689 dwarf2_complex_location_expr_complaint ();
10693 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10695 stack
[++stacki
] = unsnd
;
10697 dwarf2_complex_location_expr_complaint ();
10701 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
10706 case DW_OP_const1u
:
10707 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
10711 case DW_OP_const1s
:
10712 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
10716 case DW_OP_const2u
:
10717 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
10721 case DW_OP_const2s
:
10722 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
10726 case DW_OP_const4u
:
10727 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
10731 case DW_OP_const4s
:
10732 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
10737 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
10743 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
10748 stack
[stacki
+ 1] = stack
[stacki
];
10753 stack
[stacki
- 1] += stack
[stacki
];
10757 case DW_OP_plus_uconst
:
10758 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10763 stack
[stacki
- 1] -= stack
[stacki
];
10768 /* If we're not the last op, then we definitely can't encode
10769 this using GDB's address_class enum. This is valid for partial
10770 global symbols, although the variable's address will be bogus
10773 dwarf2_complex_location_expr_complaint ();
10776 case DW_OP_GNU_push_tls_address
:
10777 /* The top of the stack has the offset from the beginning
10778 of the thread control block at which the variable is located. */
10779 /* Nothing should follow this operator, so the top of stack would
10781 /* This is valid for partial global symbols, but the variable's
10782 address will be bogus in the psymtab. */
10784 dwarf2_complex_location_expr_complaint ();
10787 case DW_OP_GNU_uninit
:
10791 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
10792 dwarf_stack_op_name (op
));
10793 return (stack
[stacki
]);
10796 return (stack
[stacki
]);
10799 /* memory allocation interface */
10801 static struct dwarf_block
*
10802 dwarf_alloc_block (struct dwarf2_cu
*cu
)
10804 struct dwarf_block
*blk
;
10806 blk
= (struct dwarf_block
*)
10807 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
10811 static struct abbrev_info
*
10812 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
10814 struct abbrev_info
*abbrev
;
10816 abbrev
= (struct abbrev_info
*)
10817 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
10818 memset (abbrev
, 0, sizeof (struct abbrev_info
));
10822 static struct die_info
*
10823 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
10825 struct die_info
*die
;
10826 size_t size
= sizeof (struct die_info
);
10829 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
10831 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
10832 memset (die
, 0, sizeof (struct die_info
));
10837 /* Macro support. */
10840 /* Return the full name of file number I in *LH's file name table.
10841 Use COMP_DIR as the name of the current directory of the
10842 compilation. The result is allocated using xmalloc; the caller is
10843 responsible for freeing it. */
10845 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
10847 /* Is the file number a valid index into the line header's file name
10848 table? Remember that file numbers start with one, not zero. */
10849 if (1 <= file
&& file
<= lh
->num_file_names
)
10851 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10853 if (IS_ABSOLUTE_PATH (fe
->name
))
10854 return xstrdup (fe
->name
);
10862 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10868 dir_len
= strlen (dir
);
10869 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
10870 strcpy (full_name
, dir
);
10871 full_name
[dir_len
] = '/';
10872 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
10876 return xstrdup (fe
->name
);
10881 /* The compiler produced a bogus file number. We can at least
10882 record the macro definitions made in the file, even if we
10883 won't be able to find the file by name. */
10884 char fake_name
[80];
10885 sprintf (fake_name
, "<bad macro file number %d>", file
);
10887 complaint (&symfile_complaints
,
10888 _("bad file number in macro information (%d)"),
10891 return xstrdup (fake_name
);
10896 static struct macro_source_file
*
10897 macro_start_file (int file
, int line
,
10898 struct macro_source_file
*current_file
,
10899 const char *comp_dir
,
10900 struct line_header
*lh
, struct objfile
*objfile
)
10902 /* The full name of this source file. */
10903 char *full_name
= file_full_name (file
, lh
, comp_dir
);
10905 /* We don't create a macro table for this compilation unit
10906 at all until we actually get a filename. */
10907 if (! pending_macros
)
10908 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
10909 objfile
->macro_cache
);
10911 if (! current_file
)
10912 /* If we have no current file, then this must be the start_file
10913 directive for the compilation unit's main source file. */
10914 current_file
= macro_set_main (pending_macros
, full_name
);
10916 current_file
= macro_include (current_file
, line
, full_name
);
10920 return current_file
;
10924 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
10925 followed by a null byte. */
10927 copy_string (const char *buf
, int len
)
10929 char *s
= xmalloc (len
+ 1);
10930 memcpy (s
, buf
, len
);
10937 static const char *
10938 consume_improper_spaces (const char *p
, const char *body
)
10942 complaint (&symfile_complaints
,
10943 _("macro definition contains spaces in formal argument list:\n`%s'"),
10955 parse_macro_definition (struct macro_source_file
*file
, int line
,
10960 /* The body string takes one of two forms. For object-like macro
10961 definitions, it should be:
10963 <macro name> " " <definition>
10965 For function-like macro definitions, it should be:
10967 <macro name> "() " <definition>
10969 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
10971 Spaces may appear only where explicitly indicated, and in the
10974 The Dwarf 2 spec says that an object-like macro's name is always
10975 followed by a space, but versions of GCC around March 2002 omit
10976 the space when the macro's definition is the empty string.
10978 The Dwarf 2 spec says that there should be no spaces between the
10979 formal arguments in a function-like macro's formal argument list,
10980 but versions of GCC around March 2002 include spaces after the
10984 /* Find the extent of the macro name. The macro name is terminated
10985 by either a space or null character (for an object-like macro) or
10986 an opening paren (for a function-like macro). */
10987 for (p
= body
; *p
; p
++)
10988 if (*p
== ' ' || *p
== '(')
10991 if (*p
== ' ' || *p
== '\0')
10993 /* It's an object-like macro. */
10994 int name_len
= p
- body
;
10995 char *name
= copy_string (body
, name_len
);
10996 const char *replacement
;
10999 replacement
= body
+ name_len
+ 1;
11002 dwarf2_macro_malformed_definition_complaint (body
);
11003 replacement
= body
+ name_len
;
11006 macro_define_object (file
, line
, name
, replacement
);
11010 else if (*p
== '(')
11012 /* It's a function-like macro. */
11013 char *name
= copy_string (body
, p
- body
);
11016 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
11020 p
= consume_improper_spaces (p
, body
);
11022 /* Parse the formal argument list. */
11023 while (*p
&& *p
!= ')')
11025 /* Find the extent of the current argument name. */
11026 const char *arg_start
= p
;
11028 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11031 if (! *p
|| p
== arg_start
)
11032 dwarf2_macro_malformed_definition_complaint (body
);
11035 /* Make sure argv has room for the new argument. */
11036 if (argc
>= argv_size
)
11039 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11042 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11045 p
= consume_improper_spaces (p
, body
);
11047 /* Consume the comma, if present. */
11052 p
= consume_improper_spaces (p
, body
);
11061 /* Perfectly formed definition, no complaints. */
11062 macro_define_function (file
, line
, name
,
11063 argc
, (const char **) argv
,
11065 else if (*p
== '\0')
11067 /* Complain, but do define it. */
11068 dwarf2_macro_malformed_definition_complaint (body
);
11069 macro_define_function (file
, line
, name
,
11070 argc
, (const char **) argv
,
11074 /* Just complain. */
11075 dwarf2_macro_malformed_definition_complaint (body
);
11078 /* Just complain. */
11079 dwarf2_macro_malformed_definition_complaint (body
);
11085 for (i
= 0; i
< argc
; i
++)
11091 dwarf2_macro_malformed_definition_complaint (body
);
11096 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11097 char *comp_dir
, bfd
*abfd
,
11098 struct dwarf2_cu
*cu
)
11100 gdb_byte
*mac_ptr
, *mac_end
;
11101 struct macro_source_file
*current_file
= 0;
11102 enum dwarf_macinfo_record_type macinfo_type
;
11103 int at_commandline
;
11105 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11106 &dwarf2_per_objfile
->macinfo
);
11107 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11109 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11113 /* First pass: Find the name of the base filename.
11114 This filename is needed in order to process all macros whose definition
11115 (or undefinition) comes from the command line. These macros are defined
11116 before the first DW_MACINFO_start_file entry, and yet still need to be
11117 associated to the base file.
11119 To determine the base file name, we scan the macro definitions until we
11120 reach the first DW_MACINFO_start_file entry. We then initialize
11121 CURRENT_FILE accordingly so that any macro definition found before the
11122 first DW_MACINFO_start_file can still be associated to the base file. */
11124 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11125 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11126 + dwarf2_per_objfile
->macinfo
.size
;
11130 /* Do we at least have room for a macinfo type byte? */
11131 if (mac_ptr
>= mac_end
)
11133 /* Complaint is printed during the second pass as GDB will probably
11134 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11138 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11141 switch (macinfo_type
)
11143 /* A zero macinfo type indicates the end of the macro
11148 case DW_MACINFO_define
:
11149 case DW_MACINFO_undef
:
11150 /* Only skip the data by MAC_PTR. */
11152 unsigned int bytes_read
;
11154 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11155 mac_ptr
+= bytes_read
;
11156 read_string (abfd
, mac_ptr
, &bytes_read
);
11157 mac_ptr
+= bytes_read
;
11161 case DW_MACINFO_start_file
:
11163 unsigned int bytes_read
;
11166 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11167 mac_ptr
+= bytes_read
;
11168 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11169 mac_ptr
+= bytes_read
;
11171 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11176 case DW_MACINFO_end_file
:
11177 /* No data to skip by MAC_PTR. */
11180 case DW_MACINFO_vendor_ext
:
11181 /* Only skip the data by MAC_PTR. */
11183 unsigned int bytes_read
;
11185 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11186 mac_ptr
+= bytes_read
;
11187 read_string (abfd
, mac_ptr
, &bytes_read
);
11188 mac_ptr
+= bytes_read
;
11195 } while (macinfo_type
!= 0 && current_file
== NULL
);
11197 /* Second pass: Process all entries.
11199 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11200 command-line macro definitions/undefinitions. This flag is unset when we
11201 reach the first DW_MACINFO_start_file entry. */
11203 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11205 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11206 GDB is still reading the definitions from command line. First
11207 DW_MACINFO_start_file will need to be ignored as it was already executed
11208 to create CURRENT_FILE for the main source holding also the command line
11209 definitions. On first met DW_MACINFO_start_file this flag is reset to
11210 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11212 at_commandline
= 1;
11216 /* Do we at least have room for a macinfo type byte? */
11217 if (mac_ptr
>= mac_end
)
11219 dwarf2_macros_too_long_complaint ();
11223 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11226 switch (macinfo_type
)
11228 /* A zero macinfo type indicates the end of the macro
11233 case DW_MACINFO_define
:
11234 case DW_MACINFO_undef
:
11236 unsigned int bytes_read
;
11240 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11241 mac_ptr
+= bytes_read
;
11242 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11243 mac_ptr
+= bytes_read
;
11245 if (! current_file
)
11247 /* DWARF violation as no main source is present. */
11248 complaint (&symfile_complaints
,
11249 _("debug info with no main source gives macro %s "
11251 macinfo_type
== DW_MACINFO_define
?
11253 macinfo_type
== DW_MACINFO_undef
?
11254 _("undefinition") :
11255 _("something-or-other"), line
, body
);
11258 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11259 complaint (&symfile_complaints
,
11260 _("debug info gives %s macro %s with %s line %d: %s"),
11261 at_commandline
? _("command-line") : _("in-file"),
11262 macinfo_type
== DW_MACINFO_define
?
11264 macinfo_type
== DW_MACINFO_undef
?
11265 _("undefinition") :
11266 _("something-or-other"),
11267 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11269 if (macinfo_type
== DW_MACINFO_define
)
11270 parse_macro_definition (current_file
, line
, body
);
11271 else if (macinfo_type
== DW_MACINFO_undef
)
11272 macro_undef (current_file
, line
, body
);
11276 case DW_MACINFO_start_file
:
11278 unsigned int bytes_read
;
11281 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11282 mac_ptr
+= bytes_read
;
11283 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11284 mac_ptr
+= bytes_read
;
11286 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11287 complaint (&symfile_complaints
,
11288 _("debug info gives source %d included "
11289 "from %s at %s line %d"),
11290 file
, at_commandline
? _("command-line") : _("file"),
11291 line
== 0 ? _("zero") : _("non-zero"), line
);
11293 if (at_commandline
)
11295 /* This DW_MACINFO_start_file was executed in the pass one. */
11296 at_commandline
= 0;
11299 current_file
= macro_start_file (file
, line
,
11300 current_file
, comp_dir
,
11305 case DW_MACINFO_end_file
:
11306 if (! current_file
)
11307 complaint (&symfile_complaints
,
11308 _("macro debug info has an unmatched `close_file' directive"));
11311 current_file
= current_file
->included_by
;
11312 if (! current_file
)
11314 enum dwarf_macinfo_record_type next_type
;
11316 /* GCC circa March 2002 doesn't produce the zero
11317 type byte marking the end of the compilation
11318 unit. Complain if it's not there, but exit no
11321 /* Do we at least have room for a macinfo type byte? */
11322 if (mac_ptr
>= mac_end
)
11324 dwarf2_macros_too_long_complaint ();
11328 /* We don't increment mac_ptr here, so this is just
11330 next_type
= read_1_byte (abfd
, mac_ptr
);
11331 if (next_type
!= 0)
11332 complaint (&symfile_complaints
,
11333 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11340 case DW_MACINFO_vendor_ext
:
11342 unsigned int bytes_read
;
11346 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11347 mac_ptr
+= bytes_read
;
11348 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11349 mac_ptr
+= bytes_read
;
11351 /* We don't recognize any vendor extensions. */
11355 } while (macinfo_type
!= 0);
11358 /* Check if the attribute's form is a DW_FORM_block*
11359 if so return true else false. */
11361 attr_form_is_block (struct attribute
*attr
)
11363 return (attr
== NULL
? 0 :
11364 attr
->form
== DW_FORM_block1
11365 || attr
->form
== DW_FORM_block2
11366 || attr
->form
== DW_FORM_block4
11367 || attr
->form
== DW_FORM_block
);
11370 /* Return non-zero if ATTR's value is a section offset --- classes
11371 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11372 You may use DW_UNSND (attr) to retrieve such offsets.
11374 Section 7.5.4, "Attribute Encodings", explains that no attribute
11375 may have a value that belongs to more than one of these classes; it
11376 would be ambiguous if we did, because we use the same forms for all
11379 attr_form_is_section_offset (struct attribute
*attr
)
11381 return (attr
->form
== DW_FORM_data4
11382 || attr
->form
== DW_FORM_data8
);
11386 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11387 zero otherwise. When this function returns true, you can apply
11388 dwarf2_get_attr_constant_value to it.
11390 However, note that for some attributes you must check
11391 attr_form_is_section_offset before using this test. DW_FORM_data4
11392 and DW_FORM_data8 are members of both the constant class, and of
11393 the classes that contain offsets into other debug sections
11394 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11395 that, if an attribute's can be either a constant or one of the
11396 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11397 taken as section offsets, not constants. */
11399 attr_form_is_constant (struct attribute
*attr
)
11401 switch (attr
->form
)
11403 case DW_FORM_sdata
:
11404 case DW_FORM_udata
:
11405 case DW_FORM_data1
:
11406 case DW_FORM_data2
:
11407 case DW_FORM_data4
:
11408 case DW_FORM_data8
:
11416 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11417 struct dwarf2_cu
*cu
)
11419 if (attr_form_is_section_offset (attr
)
11420 /* ".debug_loc" may not exist at all, or the offset may be outside
11421 the section. If so, fall through to the complaint in the
11423 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11425 struct dwarf2_loclist_baton
*baton
;
11427 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11428 sizeof (struct dwarf2_loclist_baton
));
11429 baton
->per_cu
= cu
->per_cu
;
11430 gdb_assert (baton
->per_cu
);
11432 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11433 &dwarf2_per_objfile
->loc
);
11435 /* We don't know how long the location list is, but make sure we
11436 don't run off the edge of the section. */
11437 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11438 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11439 baton
->base_address
= cu
->base_address
;
11440 if (cu
->base_known
== 0)
11441 complaint (&symfile_complaints
,
11442 _("Location list used without specifying the CU base address."));
11444 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11445 SYMBOL_LOCATION_BATON (sym
) = baton
;
11449 struct dwarf2_locexpr_baton
*baton
;
11451 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11452 sizeof (struct dwarf2_locexpr_baton
));
11453 baton
->per_cu
= cu
->per_cu
;
11454 gdb_assert (baton
->per_cu
);
11456 if (attr_form_is_block (attr
))
11458 /* Note that we're just copying the block's data pointer
11459 here, not the actual data. We're still pointing into the
11460 info_buffer for SYM's objfile; right now we never release
11461 that buffer, but when we do clean up properly this may
11463 baton
->size
= DW_BLOCK (attr
)->size
;
11464 baton
->data
= DW_BLOCK (attr
)->data
;
11468 dwarf2_invalid_attrib_class_complaint ("location description",
11469 SYMBOL_NATURAL_NAME (sym
));
11471 baton
->data
= NULL
;
11474 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11475 SYMBOL_LOCATION_BATON (sym
) = baton
;
11479 /* Return the OBJFILE associated with the compilation unit CU. */
11482 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11484 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11486 /* Return the master objfile, so that we can report and look up the
11487 correct file containing this variable. */
11488 if (objfile
->separate_debug_objfile_backlink
)
11489 objfile
= objfile
->separate_debug_objfile_backlink
;
11494 /* Return the address size given in the compilation unit header for CU. */
11497 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11500 return per_cu
->cu
->header
.addr_size
;
11503 /* If the CU is not currently read in, we re-read its header. */
11504 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11505 struct dwarf2_per_objfile
*per_objfile
11506 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11507 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11509 struct comp_unit_head cu_header
;
11510 memset (&cu_header
, 0, sizeof cu_header
);
11511 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11512 return cu_header
.addr_size
;
11516 /* Locate the .debug_info compilation unit from CU's objfile which contains
11517 the DIE at OFFSET. Raises an error on failure. */
11519 static struct dwarf2_per_cu_data
*
11520 dwarf2_find_containing_comp_unit (unsigned int offset
,
11521 struct objfile
*objfile
)
11523 struct dwarf2_per_cu_data
*this_cu
;
11527 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11530 int mid
= low
+ (high
- low
) / 2;
11531 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11536 gdb_assert (low
== high
);
11537 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11540 error (_("Dwarf Error: could not find partial DIE containing "
11541 "offset 0x%lx [in module %s]"),
11542 (long) offset
, bfd_get_filename (objfile
->obfd
));
11544 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11545 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11549 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11550 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11551 && offset
>= this_cu
->offset
+ this_cu
->length
)
11552 error (_("invalid dwarf2 offset %u"), offset
);
11553 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11558 /* Locate the compilation unit from OBJFILE which is located at exactly
11559 OFFSET. Raises an error on failure. */
11561 static struct dwarf2_per_cu_data
*
11562 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11564 struct dwarf2_per_cu_data
*this_cu
;
11565 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11566 if (this_cu
->offset
!= offset
)
11567 error (_("no compilation unit with offset %u."), offset
);
11571 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11573 static struct dwarf2_cu
*
11574 alloc_one_comp_unit (struct objfile
*objfile
)
11576 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11577 cu
->objfile
= objfile
;
11578 obstack_init (&cu
->comp_unit_obstack
);
11582 /* Release one cached compilation unit, CU. We unlink it from the tree
11583 of compilation units, but we don't remove it from the read_in_chain;
11584 the caller is responsible for that.
11585 NOTE: DATA is a void * because this function is also used as a
11586 cleanup routine. */
11589 free_one_comp_unit (void *data
)
11591 struct dwarf2_cu
*cu
= data
;
11593 if (cu
->per_cu
!= NULL
)
11594 cu
->per_cu
->cu
= NULL
;
11597 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11602 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11603 when we're finished with it. We can't free the pointer itself, but be
11604 sure to unlink it from the cache. Also release any associated storage
11605 and perform cache maintenance.
11607 Only used during partial symbol parsing. */
11610 free_stack_comp_unit (void *data
)
11612 struct dwarf2_cu
*cu
= data
;
11614 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11615 cu
->partial_dies
= NULL
;
11617 if (cu
->per_cu
!= NULL
)
11619 /* This compilation unit is on the stack in our caller, so we
11620 should not xfree it. Just unlink it. */
11621 cu
->per_cu
->cu
= NULL
;
11624 /* If we had a per-cu pointer, then we may have other compilation
11625 units loaded, so age them now. */
11626 age_cached_comp_units ();
11630 /* Free all cached compilation units. */
11633 free_cached_comp_units (void *data
)
11635 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11637 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11638 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11639 while (per_cu
!= NULL
)
11641 struct dwarf2_per_cu_data
*next_cu
;
11643 next_cu
= per_cu
->cu
->read_in_chain
;
11645 free_one_comp_unit (per_cu
->cu
);
11646 *last_chain
= next_cu
;
11652 /* Increase the age counter on each cached compilation unit, and free
11653 any that are too old. */
11656 age_cached_comp_units (void)
11658 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11660 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
11661 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11662 while (per_cu
!= NULL
)
11664 per_cu
->cu
->last_used
++;
11665 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
11666 dwarf2_mark (per_cu
->cu
);
11667 per_cu
= per_cu
->cu
->read_in_chain
;
11670 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11671 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11672 while (per_cu
!= NULL
)
11674 struct dwarf2_per_cu_data
*next_cu
;
11676 next_cu
= per_cu
->cu
->read_in_chain
;
11678 if (!per_cu
->cu
->mark
)
11680 free_one_comp_unit (per_cu
->cu
);
11681 *last_chain
= next_cu
;
11684 last_chain
= &per_cu
->cu
->read_in_chain
;
11690 /* Remove a single compilation unit from the cache. */
11693 free_one_cached_comp_unit (void *target_cu
)
11695 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11697 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11698 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11699 while (per_cu
!= NULL
)
11701 struct dwarf2_per_cu_data
*next_cu
;
11703 next_cu
= per_cu
->cu
->read_in_chain
;
11705 if (per_cu
->cu
== target_cu
)
11707 free_one_comp_unit (per_cu
->cu
);
11708 *last_chain
= next_cu
;
11712 last_chain
= &per_cu
->cu
->read_in_chain
;
11718 /* Release all extra memory associated with OBJFILE. */
11721 dwarf2_free_objfile (struct objfile
*objfile
)
11723 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
11725 if (dwarf2_per_objfile
== NULL
)
11728 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11729 free_cached_comp_units (NULL
);
11731 /* Everything else should be on the objfile obstack. */
11734 /* A pair of DIE offset and GDB type pointer. We store these
11735 in a hash table separate from the DIEs, and preserve them
11736 when the DIEs are flushed out of cache. */
11738 struct dwarf2_offset_and_type
11740 unsigned int offset
;
11744 /* Hash function for a dwarf2_offset_and_type. */
11747 offset_and_type_hash (const void *item
)
11749 const struct dwarf2_offset_and_type
*ofs
= item
;
11750 return ofs
->offset
;
11753 /* Equality function for a dwarf2_offset_and_type. */
11756 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
11758 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
11759 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
11760 return ofs_lhs
->offset
== ofs_rhs
->offset
;
11763 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11764 table if necessary. For convenience, return TYPE. */
11766 static struct type
*
11767 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11769 struct dwarf2_offset_and_type
**slot
, ofs
;
11771 /* For Ada types, make sure that the gnat-specific data is always
11772 initialized (if not already set). There are a few types where
11773 we should not be doing so, because the type-specific area is
11774 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11775 where the type-specific area is used to store the floatformat).
11776 But this is not a problem, because the gnat-specific information
11777 is actually not needed for these types. */
11778 if (need_gnat_info (cu
)
11779 && TYPE_CODE (type
) != TYPE_CODE_FUNC
11780 && TYPE_CODE (type
) != TYPE_CODE_FLT
11781 && !HAVE_GNAT_AUX_INFO (type
))
11782 INIT_GNAT_SPECIFIC (type
);
11784 if (cu
->type_hash
== NULL
)
11786 gdb_assert (cu
->per_cu
!= NULL
);
11787 cu
->per_cu
->type_hash
11788 = htab_create_alloc_ex (cu
->header
.length
/ 24,
11789 offset_and_type_hash
,
11790 offset_and_type_eq
,
11792 &cu
->objfile
->objfile_obstack
,
11793 hashtab_obstack_allocate
,
11794 dummy_obstack_deallocate
);
11795 cu
->type_hash
= cu
->per_cu
->type_hash
;
11798 ofs
.offset
= die
->offset
;
11800 slot
= (struct dwarf2_offset_and_type
**)
11801 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
11802 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
11807 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
11808 not have a saved type. */
11810 static struct type
*
11811 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11813 struct dwarf2_offset_and_type
*slot
, ofs
;
11814 htab_t type_hash
= cu
->type_hash
;
11816 if (type_hash
== NULL
)
11819 ofs
.offset
= die
->offset
;
11820 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
11827 /* Add a dependence relationship from CU to REF_PER_CU. */
11830 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
11831 struct dwarf2_per_cu_data
*ref_per_cu
)
11835 if (cu
->dependencies
== NULL
)
11837 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
11838 NULL
, &cu
->comp_unit_obstack
,
11839 hashtab_obstack_allocate
,
11840 dummy_obstack_deallocate
);
11842 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
11844 *slot
= ref_per_cu
;
11847 /* Subroutine of dwarf2_mark to pass to htab_traverse.
11848 Set the mark field in every compilation unit in the
11849 cache that we must keep because we are keeping CU. */
11852 dwarf2_mark_helper (void **slot
, void *data
)
11854 struct dwarf2_per_cu_data
*per_cu
;
11856 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
11857 if (per_cu
->cu
->mark
)
11859 per_cu
->cu
->mark
= 1;
11861 if (per_cu
->cu
->dependencies
!= NULL
)
11862 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11867 /* Set the mark field in CU and in every other compilation unit in the
11868 cache that we must keep because we are keeping CU. */
11871 dwarf2_mark (struct dwarf2_cu
*cu
)
11876 if (cu
->dependencies
!= NULL
)
11877 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11881 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
11885 per_cu
->cu
->mark
= 0;
11886 per_cu
= per_cu
->cu
->read_in_chain
;
11890 /* Trivial hash function for partial_die_info: the hash value of a DIE
11891 is its offset in .debug_info for this objfile. */
11894 partial_die_hash (const void *item
)
11896 const struct partial_die_info
*part_die
= item
;
11897 return part_die
->offset
;
11900 /* Trivial comparison function for partial_die_info structures: two DIEs
11901 are equal if they have the same offset. */
11904 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
11906 const struct partial_die_info
*part_die_lhs
= item_lhs
;
11907 const struct partial_die_info
*part_die_rhs
= item_rhs
;
11908 return part_die_lhs
->offset
== part_die_rhs
->offset
;
11911 static struct cmd_list_element
*set_dwarf2_cmdlist
;
11912 static struct cmd_list_element
*show_dwarf2_cmdlist
;
11915 set_dwarf2_cmd (char *args
, int from_tty
)
11917 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
11921 show_dwarf2_cmd (char *args
, int from_tty
)
11923 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
11926 /* If section described by INFO was mmapped, munmap it now. */
11929 munmap_section_buffer (struct dwarf2_section_info
*info
)
11931 if (info
->was_mmapped
)
11934 intptr_t begin
= (intptr_t) info
->buffer
;
11935 intptr_t map_begin
= begin
& ~(pagesize
- 1);
11936 size_t map_length
= info
->size
+ begin
- map_begin
;
11937 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
11939 /* Without HAVE_MMAP, we should never be here to begin with. */
11945 /* munmap debug sections for OBJFILE, if necessary. */
11948 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
11950 struct dwarf2_per_objfile
*data
= d
;
11951 munmap_section_buffer (&data
->info
);
11952 munmap_section_buffer (&data
->abbrev
);
11953 munmap_section_buffer (&data
->line
);
11954 munmap_section_buffer (&data
->str
);
11955 munmap_section_buffer (&data
->macinfo
);
11956 munmap_section_buffer (&data
->ranges
);
11957 munmap_section_buffer (&data
->loc
);
11958 munmap_section_buffer (&data
->frame
);
11959 munmap_section_buffer (&data
->eh_frame
);
11962 void _initialize_dwarf2_read (void);
11965 _initialize_dwarf2_read (void)
11967 dwarf2_objfile_data_key
11968 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
11970 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
11971 Set DWARF 2 specific variables.\n\
11972 Configure DWARF 2 variables such as the cache size"),
11973 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
11974 0/*allow-unknown*/, &maintenance_set_cmdlist
);
11976 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
11977 Show DWARF 2 specific variables\n\
11978 Show DWARF 2 variables such as the cache size"),
11979 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
11980 0/*allow-unknown*/, &maintenance_show_cmdlist
);
11982 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
11983 &dwarf2_max_cache_age
, _("\
11984 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
11985 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
11986 A higher limit means that cached compilation units will be stored\n\
11987 in memory longer, and more total memory will be used. Zero disables\n\
11988 caching, which can slow down startup."),
11990 show_dwarf2_max_cache_age
,
11991 &set_dwarf2_cmdlist
,
11992 &show_dwarf2_cmdlist
);
11994 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
11995 Set debugging of the dwarf2 DIE reader."), _("\
11996 Show debugging of the dwarf2 DIE reader."), _("\
11997 When enabled (non-zero), DIEs are dumped after they are read in.\n\
11998 The value is the maximum depth to print."),
12001 &setdebuglist
, &showdebuglist
);