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
;
1401 /* We may see an objfile without any DWARF, in which case we just
1410 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1411 info
= &data
->eh_frame
;
1412 else if (section_is_p (section_name
, FRAME_SECTION
))
1413 info
= &data
->frame
;
1417 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1418 /* We haven't read this section in yet. Do it now. */
1419 dwarf2_read_section (objfile
, info
);
1421 *sectp
= info
->asection
;
1422 *bufp
= info
->buffer
;
1423 *sizep
= info
->size
;
1426 /* Build a partial symbol table. */
1429 dwarf2_build_psymtabs (struct objfile
*objfile
)
1431 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
1433 init_psymbol_list (objfile
, 1024);
1436 dwarf2_build_psymtabs_hard (objfile
);
1439 /* Return TRUE if OFFSET is within CU_HEADER. */
1442 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1444 unsigned int bottom
= cu_header
->offset
;
1445 unsigned int top
= (cu_header
->offset
1447 + cu_header
->initial_length_size
);
1448 return (offset
>= bottom
&& offset
< top
);
1451 /* Read in the comp unit header information from the debug_info at info_ptr.
1452 NOTE: This leaves members offset, first_die_offset to be filled in
1456 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1457 gdb_byte
*info_ptr
, bfd
*abfd
)
1460 unsigned int bytes_read
;
1462 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1463 cu_header
->initial_length_size
= bytes_read
;
1464 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1465 info_ptr
+= bytes_read
;
1466 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1468 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1470 info_ptr
+= bytes_read
;
1471 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1473 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1474 if (signed_addr
< 0)
1475 internal_error (__FILE__
, __LINE__
,
1476 _("read_comp_unit_head: dwarf from non elf file"));
1477 cu_header
->signed_addr_p
= signed_addr
;
1483 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1484 gdb_byte
*buffer
, unsigned int buffer_size
,
1487 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1489 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1491 if (header
->version
!= 2 && header
->version
!= 3)
1492 error (_("Dwarf Error: wrong version in compilation unit header "
1493 "(is %d, should be %d) [in module %s]"), header
->version
,
1494 2, bfd_get_filename (abfd
));
1496 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1497 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1498 "(offset 0x%lx + 6) [in module %s]"),
1499 (long) header
->abbrev_offset
,
1500 (long) (beg_of_comp_unit
- buffer
),
1501 bfd_get_filename (abfd
));
1503 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1504 > buffer
+ buffer_size
)
1505 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1506 "(offset 0x%lx + 0) [in module %s]"),
1507 (long) header
->length
,
1508 (long) (beg_of_comp_unit
- buffer
),
1509 bfd_get_filename (abfd
));
1514 /* Read in the types comp unit header information from .debug_types entry at
1515 types_ptr. The result is a pointer to one past the end of the header. */
1518 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
1519 ULONGEST
*signature
,
1520 gdb_byte
*types_ptr
, bfd
*abfd
)
1522 unsigned int bytes_read
;
1523 gdb_byte
*initial_types_ptr
= types_ptr
;
1525 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->types
);
1526 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
1528 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
1530 *signature
= read_8_bytes (abfd
, types_ptr
);
1532 types_ptr
+= cu_header
->offset_size
;
1533 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
1538 /* Allocate a new partial symtab for file named NAME and mark this new
1539 partial symtab as being an include of PST. */
1542 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1543 struct objfile
*objfile
)
1545 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1547 subpst
->section_offsets
= pst
->section_offsets
;
1548 subpst
->textlow
= 0;
1549 subpst
->texthigh
= 0;
1551 subpst
->dependencies
= (struct partial_symtab
**)
1552 obstack_alloc (&objfile
->objfile_obstack
,
1553 sizeof (struct partial_symtab
*));
1554 subpst
->dependencies
[0] = pst
;
1555 subpst
->number_of_dependencies
= 1;
1557 subpst
->globals_offset
= 0;
1558 subpst
->n_global_syms
= 0;
1559 subpst
->statics_offset
= 0;
1560 subpst
->n_static_syms
= 0;
1561 subpst
->symtab
= NULL
;
1562 subpst
->read_symtab
= pst
->read_symtab
;
1565 /* No private part is necessary for include psymtabs. This property
1566 can be used to differentiate between such include psymtabs and
1567 the regular ones. */
1568 subpst
->read_symtab_private
= NULL
;
1571 /* Read the Line Number Program data and extract the list of files
1572 included by the source file represented by PST. Build an include
1573 partial symtab for each of these included files. */
1576 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1577 struct die_info
*die
,
1578 struct partial_symtab
*pst
)
1580 struct objfile
*objfile
= cu
->objfile
;
1581 bfd
*abfd
= objfile
->obfd
;
1582 struct line_header
*lh
= NULL
;
1583 struct attribute
*attr
;
1585 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
1588 unsigned int line_offset
= DW_UNSND (attr
);
1589 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
1592 return; /* No linetable, so no includes. */
1594 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1596 free_line_header (lh
);
1600 hash_type_signature (const void *item
)
1602 const struct signatured_type
*type_sig
= item
;
1603 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1604 return type_sig
->signature
;
1608 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
1610 const struct signatured_type
*lhs
= item_lhs
;
1611 const struct signatured_type
*rhs
= item_rhs
;
1612 return lhs
->signature
== rhs
->signature
;
1615 /* Create the hash table of all entries in the .debug_types section.
1616 The result is zero if there is an error (e.g. missing .debug_types section),
1617 otherwise non-zero. */
1620 create_debug_types_hash_table (struct objfile
*objfile
)
1625 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
1626 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
1628 if (info_ptr
== NULL
)
1630 dwarf2_per_objfile
->signatured_types
= NULL
;
1634 types_htab
= htab_create_alloc_ex (41,
1635 hash_type_signature
,
1638 &objfile
->objfile_obstack
,
1639 hashtab_obstack_allocate
,
1640 dummy_obstack_deallocate
);
1642 if (dwarf2_die_debug
)
1643 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
1645 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1647 unsigned int offset
;
1648 unsigned int offset_size
;
1649 unsigned int type_offset
;
1650 unsigned int length
, initial_length_size
;
1651 unsigned short version
;
1653 struct signatured_type
*type_sig
;
1655 gdb_byte
*ptr
= info_ptr
;
1657 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
1659 /* We need to read the type's signature in order to build the hash
1660 table, but we don't need to read anything else just yet. */
1662 /* Sanity check to ensure entire cu is present. */
1663 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
1664 if (ptr
+ length
+ initial_length_size
1665 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1667 complaint (&symfile_complaints
,
1668 _("debug type entry runs off end of `.debug_types' section, ignored"));
1672 offset_size
= initial_length_size
== 4 ? 4 : 8;
1673 ptr
+= initial_length_size
;
1674 version
= bfd_get_16 (objfile
->obfd
, ptr
);
1676 ptr
+= offset_size
; /* abbrev offset */
1677 ptr
+= 1; /* address size */
1678 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
1680 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
1682 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
1683 memset (type_sig
, 0, sizeof (*type_sig
));
1684 type_sig
->signature
= signature
;
1685 type_sig
->offset
= offset
;
1686 type_sig
->type_offset
= type_offset
;
1688 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
1689 gdb_assert (slot
!= NULL
);
1692 if (dwarf2_die_debug
)
1693 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
1694 offset
, phex (signature
, sizeof (signature
)));
1696 info_ptr
= info_ptr
+ initial_length_size
+ length
;
1699 dwarf2_per_objfile
->signatured_types
= types_htab
;
1704 /* Lookup a signature based type.
1705 Returns NULL if SIG is not present in the table. */
1707 static struct signatured_type
*
1708 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
1710 struct signatured_type find_entry
, *entry
;
1712 if (dwarf2_per_objfile
->signatured_types
== NULL
)
1714 complaint (&symfile_complaints
,
1715 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1719 find_entry
.signature
= sig
;
1720 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
1724 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1727 init_cu_die_reader (struct die_reader_specs
*reader
,
1728 struct dwarf2_cu
*cu
)
1730 reader
->abfd
= cu
->objfile
->obfd
;
1732 if (cu
->per_cu
->from_debug_types
)
1734 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1735 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
1739 gdb_assert (dwarf2_per_objfile
->info
.readin
);
1740 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
1744 /* Find the base address of the compilation unit for range lists and
1745 location lists. It will normally be specified by DW_AT_low_pc.
1746 In DWARF-3 draft 4, the base address could be overridden by
1747 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1748 compilation units with discontinuous ranges. */
1751 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
1753 struct attribute
*attr
;
1756 cu
->base_address
= 0;
1758 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
1761 cu
->base_address
= DW_ADDR (attr
);
1766 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
1769 cu
->base_address
= DW_ADDR (attr
);
1775 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1776 to combine the common parts.
1777 Process a compilation unit for a psymtab.
1778 BUFFER is a pointer to the beginning of the dwarf section buffer,
1779 either .debug_info or debug_types.
1780 INFO_PTR is a pointer to the start of the CU.
1781 Returns a pointer to the next CU. */
1784 process_psymtab_comp_unit (struct objfile
*objfile
,
1785 struct dwarf2_per_cu_data
*this_cu
,
1786 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1787 unsigned int buffer_size
)
1789 bfd
*abfd
= objfile
->obfd
;
1790 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1791 struct die_info
*comp_unit_die
;
1792 struct partial_symtab
*pst
;
1794 struct cleanup
*back_to_inner
;
1795 struct dwarf2_cu cu
;
1796 unsigned int bytes_read
;
1797 int has_children
, has_pc_info
;
1798 struct attribute
*attr
;
1800 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
1801 struct die_reader_specs reader_specs
;
1803 memset (&cu
, 0, sizeof (cu
));
1804 cu
.objfile
= objfile
;
1805 obstack_init (&cu
.comp_unit_obstack
);
1807 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1809 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1810 buffer
, buffer_size
,
1813 /* Complete the cu_header. */
1814 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1815 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1817 cu
.list_in_scope
= &file_symbols
;
1819 /* If this compilation unit was already read in, free the
1820 cached copy in order to read it in again. This is
1821 necessary because we skipped some symbols when we first
1822 read in the compilation unit (see load_partial_dies).
1823 This problem could be avoided, but the benefit is
1825 if (this_cu
->cu
!= NULL
)
1826 free_one_cached_comp_unit (this_cu
->cu
);
1828 /* Note that this is a pointer to our stack frame, being
1829 added to a global data structure. It will be cleaned up
1830 in free_stack_comp_unit when we finish with this
1831 compilation unit. */
1833 cu
.per_cu
= this_cu
;
1835 /* Read the abbrevs for this compilation unit into a table. */
1836 dwarf2_read_abbrevs (abfd
, &cu
);
1837 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1839 /* Read the compilation unit die. */
1840 if (this_cu
->from_debug_types
)
1841 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1842 init_cu_die_reader (&reader_specs
, &cu
);
1843 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1846 if (this_cu
->from_debug_types
)
1848 /* offset,length haven't been set yet for type units. */
1849 this_cu
->offset
= cu
.header
.offset
;
1850 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
1852 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
1854 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1855 + cu
.header
.initial_length_size
);
1856 do_cleanups (back_to_inner
);
1860 /* Set the language we're debugging. */
1861 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
1863 set_cu_language (DW_UNSND (attr
), &cu
);
1865 set_cu_language (language_minimal
, &cu
);
1867 /* Allocate a new partial symbol table structure. */
1868 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
1869 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1870 (attr
!= NULL
) ? DW_STRING (attr
) : "",
1871 /* TEXTLOW and TEXTHIGH are set below. */
1873 objfile
->global_psymbols
.next
,
1874 objfile
->static_psymbols
.next
);
1876 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
1878 pst
->dirname
= DW_STRING (attr
);
1880 pst
->read_symtab_private
= this_cu
;
1882 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1884 /* Store the function that reads in the rest of the symbol table */
1885 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1887 this_cu
->psymtab
= pst
;
1889 dwarf2_find_base_address (comp_unit_die
, &cu
);
1891 /* Possibly set the default values of LOWPC and HIGHPC from
1893 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
1894 &best_highpc
, &cu
, pst
);
1895 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
1896 /* Store the contiguous range if it is not empty; it can be empty for
1897 CUs with no code. */
1898 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1899 best_lowpc
+ baseaddr
,
1900 best_highpc
+ baseaddr
- 1, pst
);
1902 /* Check if comp unit has_children.
1903 If so, read the rest of the partial symbols from this comp unit.
1904 If not, there's no more debug_info for this comp unit. */
1907 struct partial_die_info
*first_die
;
1908 CORE_ADDR lowpc
, highpc
;
1910 lowpc
= ((CORE_ADDR
) -1);
1911 highpc
= ((CORE_ADDR
) 0);
1913 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
1915 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1916 ! has_pc_info
, &cu
);
1918 /* If we didn't find a lowpc, set it to highpc to avoid
1919 complaints from `maint check'. */
1920 if (lowpc
== ((CORE_ADDR
) -1))
1923 /* If the compilation unit didn't have an explicit address range,
1924 then use the information extracted from its child dies. */
1928 best_highpc
= highpc
;
1931 pst
->textlow
= best_lowpc
+ baseaddr
;
1932 pst
->texthigh
= best_highpc
+ baseaddr
;
1934 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1935 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1936 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1937 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1938 sort_pst_symbols (pst
);
1940 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1941 + cu
.header
.initial_length_size
);
1943 if (this_cu
->from_debug_types
)
1945 /* It's not clear we want to do anything with stmt lists here.
1946 Waiting to see what gcc ultimately does. */
1950 /* Get the list of files included in the current compilation unit,
1951 and build a psymtab for each of them. */
1952 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
1955 do_cleanups (back_to_inner
);
1960 /* Traversal function for htab_traverse_noresize.
1961 Process one .debug_types comp-unit. */
1964 process_type_comp_unit (void **slot
, void *info
)
1966 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
1967 struct objfile
*objfile
= (struct objfile
*) info
;
1968 struct dwarf2_per_cu_data
*this_cu
;
1970 this_cu
= &entry
->per_cu
;
1971 this_cu
->from_debug_types
= 1;
1973 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1974 process_psymtab_comp_unit (objfile
, this_cu
,
1975 dwarf2_per_objfile
->types
.buffer
,
1976 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
1977 dwarf2_per_objfile
->types
.size
);
1982 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
1983 Build partial symbol tables for the .debug_types comp-units. */
1986 build_type_psymtabs (struct objfile
*objfile
)
1988 if (! create_debug_types_hash_table (objfile
))
1991 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
1992 process_type_comp_unit
, objfile
);
1995 /* Build the partial symbol table by doing a quick pass through the
1996 .debug_info and .debug_abbrev sections. */
1999 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
2001 bfd
*abfd
= objfile
->obfd
;
2003 struct cleanup
*back_to
;
2005 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2006 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2008 /* Any cached compilation units will be linked by the per-objfile
2009 read_in_chain. Make sure to free them when we're done. */
2010 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2012 build_type_psymtabs (objfile
);
2014 create_all_comp_units (objfile
);
2016 objfile
->psymtabs_addrmap
=
2017 addrmap_create_mutable (&objfile
->objfile_obstack
);
2019 /* Since the objects we're extracting from .debug_info vary in
2020 length, only the individual functions to extract them (like
2021 read_comp_unit_head and load_partial_die) can really know whether
2022 the buffer is large enough to hold another complete object.
2024 At the moment, they don't actually check that. If .debug_info
2025 holds just one extra byte after the last compilation unit's dies,
2026 then read_comp_unit_head will happily read off the end of the
2027 buffer. read_partial_die is similarly casual. Those functions
2030 For this loop condition, simply checking whether there's any data
2031 left at all should be sufficient. */
2033 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
2034 + dwarf2_per_objfile
->info
.size
))
2036 struct dwarf2_per_cu_data
*this_cu
;
2038 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
2041 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
2042 dwarf2_per_objfile
->info
.buffer
,
2044 dwarf2_per_objfile
->info
.size
);
2047 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
2048 &objfile
->objfile_obstack
);
2050 do_cleanups (back_to
);
2053 /* Load the partial DIEs for a secondary CU into memory. */
2056 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
2057 struct objfile
*objfile
)
2059 bfd
*abfd
= objfile
->obfd
;
2060 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
2061 struct die_info
*comp_unit_die
;
2062 struct dwarf2_cu
*cu
;
2063 unsigned int bytes_read
;
2064 struct cleanup
*back_to
;
2065 struct attribute
*attr
;
2067 struct die_reader_specs reader_specs
;
2069 gdb_assert (! this_cu
->from_debug_types
);
2071 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2072 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
2073 beg_of_comp_unit
= info_ptr
;
2075 cu
= alloc_one_comp_unit (objfile
);
2077 /* ??? Missing cleanup for CU? */
2079 /* Link this compilation unit into the compilation unit tree. */
2081 cu
->per_cu
= this_cu
;
2082 cu
->type_hash
= this_cu
->type_hash
;
2084 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
2085 dwarf2_per_objfile
->info
.buffer
,
2086 dwarf2_per_objfile
->info
.size
,
2089 /* Complete the cu_header. */
2090 cu
->header
.offset
= this_cu
->offset
;
2091 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2093 /* Read the abbrevs for this compilation unit into a table. */
2094 dwarf2_read_abbrevs (abfd
, cu
);
2095 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2097 /* Read the compilation unit die. */
2098 init_cu_die_reader (&reader_specs
, cu
);
2099 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2102 /* Set the language we're debugging. */
2103 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
2105 set_cu_language (DW_UNSND (attr
), cu
);
2107 set_cu_language (language_minimal
, cu
);
2109 /* Check if comp unit has_children.
2110 If so, read the rest of the partial symbols from this comp unit.
2111 If not, there's no more debug_info for this comp unit. */
2113 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
2115 do_cleanups (back_to
);
2118 /* Create a list of all compilation units in OBJFILE. We do this only
2119 if an inter-comp-unit reference is found; presumably if there is one,
2120 there will be many, and one will occur early in the .debug_info section.
2121 So there's no point in building this list incrementally. */
2124 create_all_comp_units (struct objfile
*objfile
)
2128 struct dwarf2_per_cu_data
**all_comp_units
;
2131 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2132 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2136 all_comp_units
= xmalloc (n_allocated
2137 * sizeof (struct dwarf2_per_cu_data
*));
2139 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
2141 unsigned int length
, initial_length_size
;
2142 gdb_byte
*beg_of_comp_unit
;
2143 struct dwarf2_per_cu_data
*this_cu
;
2144 unsigned int offset
;
2146 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
2148 /* Read just enough information to find out where the next
2149 compilation unit is. */
2150 length
= read_initial_length (objfile
->obfd
, info_ptr
,
2151 &initial_length_size
);
2153 /* Save the compilation unit for later lookup. */
2154 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
2155 sizeof (struct dwarf2_per_cu_data
));
2156 memset (this_cu
, 0, sizeof (*this_cu
));
2157 this_cu
->offset
= offset
;
2158 this_cu
->length
= length
+ initial_length_size
;
2160 if (n_comp_units
== n_allocated
)
2163 all_comp_units
= xrealloc (all_comp_units
,
2165 * sizeof (struct dwarf2_per_cu_data
*));
2167 all_comp_units
[n_comp_units
++] = this_cu
;
2169 info_ptr
= info_ptr
+ this_cu
->length
;
2172 dwarf2_per_objfile
->all_comp_units
2173 = obstack_alloc (&objfile
->objfile_obstack
,
2174 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2175 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
2176 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2177 xfree (all_comp_units
);
2178 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
2181 /* Process all loaded DIEs for compilation unit CU, starting at
2182 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2183 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2184 DW_AT_ranges). If NEED_PC is set, then this function will set
2185 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2186 and record the covered ranges in the addrmap. */
2189 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
2190 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2192 struct objfile
*objfile
= cu
->objfile
;
2193 bfd
*abfd
= objfile
->obfd
;
2194 struct partial_die_info
*pdi
;
2196 /* Now, march along the PDI's, descending into ones which have
2197 interesting children but skipping the children of the other ones,
2198 until we reach the end of the compilation unit. */
2204 fixup_partial_die (pdi
, cu
);
2206 /* Anonymous namespaces have no name but have interesting
2207 children, so we need to look at them. Ditto for anonymous
2210 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
2211 || pdi
->tag
== DW_TAG_enumeration_type
)
2215 case DW_TAG_subprogram
:
2216 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2218 case DW_TAG_variable
:
2219 case DW_TAG_typedef
:
2220 case DW_TAG_union_type
:
2221 if (!pdi
->is_declaration
)
2223 add_partial_symbol (pdi
, cu
);
2226 case DW_TAG_class_type
:
2227 case DW_TAG_interface_type
:
2228 case DW_TAG_structure_type
:
2229 if (!pdi
->is_declaration
)
2231 add_partial_symbol (pdi
, cu
);
2234 case DW_TAG_enumeration_type
:
2235 if (!pdi
->is_declaration
)
2236 add_partial_enumeration (pdi
, cu
);
2238 case DW_TAG_base_type
:
2239 case DW_TAG_subrange_type
:
2240 /* File scope base type definitions are added to the partial
2242 add_partial_symbol (pdi
, cu
);
2244 case DW_TAG_namespace
:
2245 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
2248 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
2255 /* If the die has a sibling, skip to the sibling. */
2257 pdi
= pdi
->die_sibling
;
2261 /* Functions used to compute the fully scoped name of a partial DIE.
2263 Normally, this is simple. For C++, the parent DIE's fully scoped
2264 name is concatenated with "::" and the partial DIE's name. For
2265 Java, the same thing occurs except that "." is used instead of "::".
2266 Enumerators are an exception; they use the scope of their parent
2267 enumeration type, i.e. the name of the enumeration type is not
2268 prepended to the enumerator.
2270 There are two complexities. One is DW_AT_specification; in this
2271 case "parent" means the parent of the target of the specification,
2272 instead of the direct parent of the DIE. The other is compilers
2273 which do not emit DW_TAG_namespace; in this case we try to guess
2274 the fully qualified name of structure types from their members'
2275 linkage names. This must be done using the DIE's children rather
2276 than the children of any DW_AT_specification target. We only need
2277 to do this for structures at the top level, i.e. if the target of
2278 any DW_AT_specification (if any; otherwise the DIE itself) does not
2281 /* Compute the scope prefix associated with PDI's parent, in
2282 compilation unit CU. The result will be allocated on CU's
2283 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2284 field. NULL is returned if no prefix is necessary. */
2286 partial_die_parent_scope (struct partial_die_info
*pdi
,
2287 struct dwarf2_cu
*cu
)
2289 char *grandparent_scope
;
2290 struct partial_die_info
*parent
, *real_pdi
;
2292 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2293 then this means the parent of the specification DIE. */
2296 while (real_pdi
->has_specification
)
2297 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2299 parent
= real_pdi
->die_parent
;
2303 if (parent
->scope_set
)
2304 return parent
->scope
;
2306 fixup_partial_die (parent
, cu
);
2308 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2310 if (parent
->tag
== DW_TAG_namespace
2311 || parent
->tag
== DW_TAG_structure_type
2312 || parent
->tag
== DW_TAG_class_type
2313 || parent
->tag
== DW_TAG_interface_type
2314 || parent
->tag
== DW_TAG_union_type
2315 || parent
->tag
== DW_TAG_enumeration_type
)
2317 if (grandparent_scope
== NULL
)
2318 parent
->scope
= parent
->name
;
2320 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2323 else if (parent
->tag
== DW_TAG_enumerator
)
2324 /* Enumerators should not get the name of the enumeration as a prefix. */
2325 parent
->scope
= grandparent_scope
;
2328 /* FIXME drow/2004-04-01: What should we be doing with
2329 function-local names? For partial symbols, we should probably be
2331 complaint (&symfile_complaints
,
2332 _("unhandled containing DIE tag %d for DIE at %d"),
2333 parent
->tag
, pdi
->offset
);
2334 parent
->scope
= grandparent_scope
;
2337 parent
->scope_set
= 1;
2338 return parent
->scope
;
2341 /* Return the fully scoped name associated with PDI, from compilation unit
2342 CU. The result will be allocated with malloc. */
2344 partial_die_full_name (struct partial_die_info
*pdi
,
2345 struct dwarf2_cu
*cu
)
2349 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2350 if (parent_scope
== NULL
)
2353 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2357 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2359 struct objfile
*objfile
= cu
->objfile
;
2361 char *actual_name
= NULL
;
2362 const char *my_prefix
;
2363 const struct partial_symbol
*psym
= NULL
;
2365 int built_actual_name
= 0;
2367 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2369 actual_name
= partial_die_full_name (pdi
, cu
);
2371 built_actual_name
= 1;
2373 if (actual_name
== NULL
)
2374 actual_name
= pdi
->name
;
2378 case DW_TAG_subprogram
:
2379 if (pdi
->is_external
|| cu
->language
== language_ada
)
2381 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2382 of the global scope. But in Ada, we want to be able to access
2383 nested procedures globally. So all Ada subprograms are stored
2384 in the global scope. */
2385 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2386 mst_text, objfile); */
2387 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2389 VAR_DOMAIN
, LOC_BLOCK
,
2390 &objfile
->global_psymbols
,
2391 0, pdi
->lowpc
+ baseaddr
,
2392 cu
->language
, objfile
);
2396 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2397 mst_file_text, objfile); */
2398 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2400 VAR_DOMAIN
, LOC_BLOCK
,
2401 &objfile
->static_psymbols
,
2402 0, pdi
->lowpc
+ baseaddr
,
2403 cu
->language
, objfile
);
2406 case DW_TAG_variable
:
2407 if (pdi
->is_external
)
2410 Don't enter into the minimal symbol tables as there is
2411 a minimal symbol table entry from the ELF symbols already.
2412 Enter into partial symbol table if it has a location
2413 descriptor or a type.
2414 If the location descriptor is missing, new_symbol will create
2415 a LOC_UNRESOLVED symbol, the address of the variable will then
2416 be determined from the minimal symbol table whenever the variable
2418 The address for the partial symbol table entry is not
2419 used by GDB, but it comes in handy for debugging partial symbol
2423 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2424 if (pdi
->locdesc
|| pdi
->has_type
)
2425 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2427 VAR_DOMAIN
, LOC_STATIC
,
2428 &objfile
->global_psymbols
,
2430 cu
->language
, objfile
);
2434 /* Static Variable. Skip symbols without location descriptors. */
2435 if (pdi
->locdesc
== NULL
)
2437 if (built_actual_name
)
2438 xfree (actual_name
);
2441 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2442 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2443 mst_file_data, objfile); */
2444 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2446 VAR_DOMAIN
, LOC_STATIC
,
2447 &objfile
->static_psymbols
,
2449 cu
->language
, objfile
);
2452 case DW_TAG_typedef
:
2453 case DW_TAG_base_type
:
2454 case DW_TAG_subrange_type
:
2455 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2457 VAR_DOMAIN
, LOC_TYPEDEF
,
2458 &objfile
->static_psymbols
,
2459 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2461 case DW_TAG_namespace
:
2462 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2464 VAR_DOMAIN
, LOC_TYPEDEF
,
2465 &objfile
->global_psymbols
,
2466 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2468 case DW_TAG_class_type
:
2469 case DW_TAG_interface_type
:
2470 case DW_TAG_structure_type
:
2471 case DW_TAG_union_type
:
2472 case DW_TAG_enumeration_type
:
2473 /* Skip external references. The DWARF standard says in the section
2474 about "Structure, Union, and Class Type Entries": "An incomplete
2475 structure, union or class type is represented by a structure,
2476 union or class entry that does not have a byte size attribute
2477 and that has a DW_AT_declaration attribute." */
2478 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2480 if (built_actual_name
)
2481 xfree (actual_name
);
2485 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2486 static vs. global. */
2487 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2489 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2490 (cu
->language
== language_cplus
2491 || cu
->language
== language_java
)
2492 ? &objfile
->global_psymbols
2493 : &objfile
->static_psymbols
,
2494 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2497 case DW_TAG_enumerator
:
2498 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2500 VAR_DOMAIN
, LOC_CONST
,
2501 (cu
->language
== language_cplus
2502 || cu
->language
== language_java
)
2503 ? &objfile
->global_psymbols
2504 : &objfile
->static_psymbols
,
2505 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2511 if (built_actual_name
)
2512 xfree (actual_name
);
2515 /* Read a partial die corresponding to a namespace; also, add a symbol
2516 corresponding to that namespace to the symbol table. NAMESPACE is
2517 the name of the enclosing namespace. */
2520 add_partial_namespace (struct partial_die_info
*pdi
,
2521 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2522 int need_pc
, struct dwarf2_cu
*cu
)
2524 struct objfile
*objfile
= cu
->objfile
;
2526 /* Add a symbol for the namespace. */
2528 add_partial_symbol (pdi
, cu
);
2530 /* Now scan partial symbols in that namespace. */
2532 if (pdi
->has_children
)
2533 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2536 /* Read a partial die corresponding to a Fortran module. */
2539 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2540 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2542 /* Now scan partial symbols in that module.
2544 FIXME: Support the separate Fortran module namespaces. */
2546 if (pdi
->has_children
)
2547 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2550 /* Read a partial die corresponding to a subprogram and create a partial
2551 symbol for that subprogram. When the CU language allows it, this
2552 routine also defines a partial symbol for each nested subprogram
2553 that this subprogram contains.
2555 DIE my also be a lexical block, in which case we simply search
2556 recursively for suprograms defined inside that lexical block.
2557 Again, this is only performed when the CU language allows this
2558 type of definitions. */
2561 add_partial_subprogram (struct partial_die_info
*pdi
,
2562 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2563 int need_pc
, struct dwarf2_cu
*cu
)
2565 if (pdi
->tag
== DW_TAG_subprogram
)
2567 if (pdi
->has_pc_info
)
2569 if (pdi
->lowpc
< *lowpc
)
2570 *lowpc
= pdi
->lowpc
;
2571 if (pdi
->highpc
> *highpc
)
2572 *highpc
= pdi
->highpc
;
2576 struct objfile
*objfile
= cu
->objfile
;
2578 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2579 SECT_OFF_TEXT (objfile
));
2580 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2581 pdi
->lowpc
+ baseaddr
,
2582 pdi
->highpc
- 1 + baseaddr
,
2583 cu
->per_cu
->psymtab
);
2585 if (!pdi
->is_declaration
)
2586 /* Ignore subprogram DIEs that do not have a name, they are
2587 illegal. Do not emit a complaint at this point, we will
2588 do so when we convert this psymtab into a symtab. */
2590 add_partial_symbol (pdi
, cu
);
2594 if (! pdi
->has_children
)
2597 if (cu
->language
== language_ada
)
2599 pdi
= pdi
->die_child
;
2602 fixup_partial_die (pdi
, cu
);
2603 if (pdi
->tag
== DW_TAG_subprogram
2604 || pdi
->tag
== DW_TAG_lexical_block
)
2605 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2606 pdi
= pdi
->die_sibling
;
2611 /* See if we can figure out if the class lives in a namespace. We do
2612 this by looking for a member function; its demangled name will
2613 contain namespace info, if there is any. */
2616 guess_structure_name (struct partial_die_info
*struct_pdi
,
2617 struct dwarf2_cu
*cu
)
2619 if ((cu
->language
== language_cplus
2620 || cu
->language
== language_java
)
2621 && cu
->has_namespace_info
== 0
2622 && struct_pdi
->has_children
)
2624 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2625 what template types look like, because the demangler
2626 frequently doesn't give the same name as the debug info. We
2627 could fix this by only using the demangled name to get the
2628 prefix (but see comment in read_structure_type). */
2630 struct partial_die_info
*real_pdi
;
2632 /* If this DIE (this DIE's specification, if any) has a parent, then
2633 we should not do this. We'll prepend the parent's fully qualified
2634 name when we create the partial symbol. */
2636 real_pdi
= struct_pdi
;
2637 while (real_pdi
->has_specification
)
2638 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2640 if (real_pdi
->die_parent
!= NULL
)
2645 /* Read a partial die corresponding to an enumeration type. */
2648 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2649 struct dwarf2_cu
*cu
)
2651 struct objfile
*objfile
= cu
->objfile
;
2652 bfd
*abfd
= objfile
->obfd
;
2653 struct partial_die_info
*pdi
;
2655 if (enum_pdi
->name
!= NULL
)
2656 add_partial_symbol (enum_pdi
, cu
);
2658 pdi
= enum_pdi
->die_child
;
2661 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2662 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2664 add_partial_symbol (pdi
, cu
);
2665 pdi
= pdi
->die_sibling
;
2669 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2670 Return the corresponding abbrev, or NULL if the number is zero (indicating
2671 an empty DIE). In either case *BYTES_READ will be set to the length of
2672 the initial number. */
2674 static struct abbrev_info
*
2675 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2676 struct dwarf2_cu
*cu
)
2678 bfd
*abfd
= cu
->objfile
->obfd
;
2679 unsigned int abbrev_number
;
2680 struct abbrev_info
*abbrev
;
2682 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2684 if (abbrev_number
== 0)
2687 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2690 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2691 bfd_get_filename (abfd
));
2697 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2698 Returns a pointer to the end of a series of DIEs, terminated by an empty
2699 DIE. Any children of the skipped DIEs will also be skipped. */
2702 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2704 struct abbrev_info
*abbrev
;
2705 unsigned int bytes_read
;
2709 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2711 return info_ptr
+ bytes_read
;
2713 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
2717 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2718 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2719 abbrev corresponding to that skipped uleb128 should be passed in
2720 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2724 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2725 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
2727 unsigned int bytes_read
;
2728 struct attribute attr
;
2729 bfd
*abfd
= cu
->objfile
->obfd
;
2730 unsigned int form
, i
;
2732 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2734 /* The only abbrev we care about is DW_AT_sibling. */
2735 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2737 read_attribute (&attr
, &abbrev
->attrs
[i
],
2738 abfd
, info_ptr
, cu
);
2739 if (attr
.form
== DW_FORM_ref_addr
)
2740 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2742 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
2745 /* If it isn't DW_AT_sibling, skip this attribute. */
2746 form
= abbrev
->attrs
[i
].form
;
2750 case DW_FORM_ref_addr
:
2751 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2752 and later it is offset sized. */
2753 if (cu
->header
.version
== 2)
2754 info_ptr
+= cu
->header
.addr_size
;
2756 info_ptr
+= cu
->header
.offset_size
;
2759 info_ptr
+= cu
->header
.addr_size
;
2779 case DW_FORM_string
:
2780 read_string (abfd
, info_ptr
, &bytes_read
);
2781 info_ptr
+= bytes_read
;
2784 info_ptr
+= cu
->header
.offset_size
;
2787 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2788 info_ptr
+= bytes_read
;
2790 case DW_FORM_block1
:
2791 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2793 case DW_FORM_block2
:
2794 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2796 case DW_FORM_block4
:
2797 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2801 case DW_FORM_ref_udata
:
2802 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2804 case DW_FORM_indirect
:
2805 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2806 info_ptr
+= bytes_read
;
2807 /* We need to continue parsing from here, so just go back to
2809 goto skip_attribute
;
2812 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2813 dwarf_form_name (form
),
2814 bfd_get_filename (abfd
));
2818 if (abbrev
->has_children
)
2819 return skip_children (buffer
, info_ptr
, cu
);
2824 /* Locate ORIG_PDI's sibling.
2825 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2829 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
2830 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2831 bfd
*abfd
, struct dwarf2_cu
*cu
)
2833 /* Do we know the sibling already? */
2835 if (orig_pdi
->sibling
)
2836 return orig_pdi
->sibling
;
2838 /* Are there any children to deal with? */
2840 if (!orig_pdi
->has_children
)
2843 /* Skip the children the long way. */
2845 return skip_children (buffer
, info_ptr
, cu
);
2848 /* Expand this partial symbol table into a full symbol table. */
2851 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2853 /* FIXME: This is barely more than a stub. */
2858 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2864 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2865 gdb_flush (gdb_stdout
);
2868 /* Restore our global data. */
2869 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2870 dwarf2_objfile_data_key
);
2872 /* If this psymtab is constructed from a debug-only objfile, the
2873 has_section_at_zero flag will not necessarily be correct. We
2874 can get the correct value for this flag by looking at the data
2875 associated with the (presumably stripped) associated objfile. */
2876 if (pst
->objfile
->separate_debug_objfile_backlink
)
2878 struct dwarf2_per_objfile
*dpo_backlink
2879 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2880 dwarf2_objfile_data_key
);
2881 dwarf2_per_objfile
->has_section_at_zero
2882 = dpo_backlink
->has_section_at_zero
;
2885 psymtab_to_symtab_1 (pst
);
2887 /* Finish up the debug error message. */
2889 printf_filtered (_("done.\n"));
2894 /* Add PER_CU to the queue. */
2897 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2899 struct dwarf2_queue_item
*item
;
2902 item
= xmalloc (sizeof (*item
));
2903 item
->per_cu
= per_cu
;
2906 if (dwarf2_queue
== NULL
)
2907 dwarf2_queue
= item
;
2909 dwarf2_queue_tail
->next
= item
;
2911 dwarf2_queue_tail
= item
;
2914 /* Process the queue. */
2917 process_queue (struct objfile
*objfile
)
2919 struct dwarf2_queue_item
*item
, *next_item
;
2921 /* The queue starts out with one item, but following a DIE reference
2922 may load a new CU, adding it to the end of the queue. */
2923 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2925 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2926 process_full_comp_unit (item
->per_cu
);
2928 item
->per_cu
->queued
= 0;
2929 next_item
= item
->next
;
2933 dwarf2_queue_tail
= NULL
;
2936 /* Free all allocated queue entries. This function only releases anything if
2937 an error was thrown; if the queue was processed then it would have been
2938 freed as we went along. */
2941 dwarf2_release_queue (void *dummy
)
2943 struct dwarf2_queue_item
*item
, *last
;
2945 item
= dwarf2_queue
;
2948 /* Anything still marked queued is likely to be in an
2949 inconsistent state, so discard it. */
2950 if (item
->per_cu
->queued
)
2952 if (item
->per_cu
->cu
!= NULL
)
2953 free_one_cached_comp_unit (item
->per_cu
->cu
);
2954 item
->per_cu
->queued
= 0;
2962 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2965 /* Read in full symbols for PST, and anything it depends on. */
2968 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2970 struct dwarf2_per_cu_data
*per_cu
;
2971 struct cleanup
*back_to
;
2974 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2975 if (!pst
->dependencies
[i
]->readin
)
2977 /* Inform about additional files that need to be read in. */
2980 /* FIXME: i18n: Need to make this a single string. */
2981 fputs_filtered (" ", gdb_stdout
);
2983 fputs_filtered ("and ", gdb_stdout
);
2985 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2986 wrap_here (""); /* Flush output */
2987 gdb_flush (gdb_stdout
);
2989 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2992 per_cu
= pst
->read_symtab_private
;
2996 /* It's an include file, no symbols to read for it.
2997 Everything is in the parent symtab. */
3002 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
3004 queue_comp_unit (per_cu
, pst
->objfile
);
3006 if (per_cu
->from_debug_types
)
3007 read_signatured_type_at_offset (pst
->objfile
, per_cu
->offset
);
3009 load_full_comp_unit (per_cu
, pst
->objfile
);
3011 process_queue (pst
->objfile
);
3013 /* Age the cache, releasing compilation units that have not
3014 been used recently. */
3015 age_cached_comp_units ();
3017 do_cleanups (back_to
);
3020 /* Load the DIEs associated with PER_CU into memory. */
3023 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3025 bfd
*abfd
= objfile
->obfd
;
3026 struct dwarf2_cu
*cu
;
3027 unsigned int offset
;
3028 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3029 struct cleanup
*back_to
, *free_cu_cleanup
;
3030 struct attribute
*attr
;
3033 gdb_assert (! per_cu
->from_debug_types
);
3035 /* Set local variables from the partial symbol table info. */
3036 offset
= per_cu
->offset
;
3038 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3039 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
3040 beg_of_comp_unit
= info_ptr
;
3042 cu
= alloc_one_comp_unit (objfile
);
3044 /* If an error occurs while loading, release our storage. */
3045 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3047 /* Read in the comp_unit header. */
3048 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
3050 /* Complete the cu_header. */
3051 cu
->header
.offset
= offset
;
3052 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3054 /* Read the abbrevs for this compilation unit. */
3055 dwarf2_read_abbrevs (abfd
, cu
);
3056 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3058 /* Link this compilation unit into the compilation unit tree. */
3060 cu
->per_cu
= per_cu
;
3061 cu
->type_hash
= per_cu
->type_hash
;
3063 cu
->dies
= read_comp_unit (info_ptr
, cu
);
3065 /* We try not to read any attributes in this function, because not
3066 all objfiles needed for references have been loaded yet, and symbol
3067 table processing isn't initialized. But we have to set the CU language,
3068 or we won't be able to build types correctly. */
3069 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
3071 set_cu_language (DW_UNSND (attr
), cu
);
3073 set_cu_language (language_minimal
, cu
);
3075 /* Link this CU into read_in_chain. */
3076 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3077 dwarf2_per_objfile
->read_in_chain
= per_cu
;
3079 do_cleanups (back_to
);
3081 /* We've successfully allocated this compilation unit. Let our caller
3082 clean it up when finished with it. */
3083 discard_cleanups (free_cu_cleanup
);
3086 /* Generate full symbol information for PST and CU, whose DIEs have
3087 already been loaded into memory. */
3090 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
3092 struct partial_symtab
*pst
= per_cu
->psymtab
;
3093 struct dwarf2_cu
*cu
= per_cu
->cu
;
3094 struct objfile
*objfile
= pst
->objfile
;
3095 bfd
*abfd
= objfile
->obfd
;
3096 CORE_ADDR lowpc
, highpc
;
3097 struct symtab
*symtab
;
3098 struct cleanup
*back_to
;
3101 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3104 back_to
= make_cleanup (really_free_pendings
, NULL
);
3106 cu
->list_in_scope
= &file_symbols
;
3108 dwarf2_find_base_address (cu
->dies
, cu
);
3110 /* Do line number decoding in read_file_scope () */
3111 process_die (cu
->dies
, cu
);
3113 /* Some compilers don't define a DW_AT_high_pc attribute for the
3114 compilation unit. If the DW_AT_high_pc is missing, synthesize
3115 it, by scanning the DIE's below the compilation unit. */
3116 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
3118 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
3120 /* Set symtab language to language from DW_AT_language.
3121 If the compilation is from a C file generated by language preprocessors,
3122 do not set the language if it was already deduced by start_subfile. */
3124 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
3126 symtab
->language
= cu
->language
;
3128 pst
->symtab
= symtab
;
3131 do_cleanups (back_to
);
3134 /* Process a die and its children. */
3137 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
3141 case DW_TAG_padding
:
3143 case DW_TAG_compile_unit
:
3144 read_file_scope (die
, cu
);
3146 case DW_TAG_type_unit
:
3147 read_type_unit_scope (die
, cu
);
3149 case DW_TAG_subprogram
:
3150 case DW_TAG_inlined_subroutine
:
3151 read_func_scope (die
, cu
);
3153 case DW_TAG_lexical_block
:
3154 case DW_TAG_try_block
:
3155 case DW_TAG_catch_block
:
3156 read_lexical_block_scope (die
, cu
);
3158 case DW_TAG_class_type
:
3159 case DW_TAG_interface_type
:
3160 case DW_TAG_structure_type
:
3161 case DW_TAG_union_type
:
3162 process_structure_scope (die
, cu
);
3164 case DW_TAG_enumeration_type
:
3165 process_enumeration_scope (die
, cu
);
3168 /* These dies have a type, but processing them does not create
3169 a symbol or recurse to process the children. Therefore we can
3170 read them on-demand through read_type_die. */
3171 case DW_TAG_subroutine_type
:
3172 case DW_TAG_set_type
:
3173 case DW_TAG_array_type
:
3174 case DW_TAG_pointer_type
:
3175 case DW_TAG_ptr_to_member_type
:
3176 case DW_TAG_reference_type
:
3177 case DW_TAG_string_type
:
3180 case DW_TAG_base_type
:
3181 case DW_TAG_subrange_type
:
3182 case DW_TAG_typedef
:
3183 /* Add a typedef symbol for the type definition, if it has a
3185 new_symbol (die
, read_type_die (die
, cu
), cu
);
3187 case DW_TAG_common_block
:
3188 read_common_block (die
, cu
);
3190 case DW_TAG_common_inclusion
:
3192 case DW_TAG_namespace
:
3193 processing_has_namespace_info
= 1;
3194 read_namespace (die
, cu
);
3197 read_module (die
, cu
);
3199 case DW_TAG_imported_declaration
:
3200 case DW_TAG_imported_module
:
3201 processing_has_namespace_info
= 1;
3202 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
3203 || cu
->language
!= language_fortran
))
3204 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
3205 dwarf_tag_name (die
->tag
));
3206 read_import_statement (die
, cu
);
3209 new_symbol (die
, NULL
, cu
);
3214 /* A helper function for dwarf2_compute_name which determines whether DIE
3215 needs to have the name of the scope prepended to the name listed in the
3219 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3221 struct attribute
*attr
;
3225 case DW_TAG_namespace
:
3226 case DW_TAG_typedef
:
3227 case DW_TAG_class_type
:
3228 case DW_TAG_interface_type
:
3229 case DW_TAG_structure_type
:
3230 case DW_TAG_union_type
:
3231 case DW_TAG_enumeration_type
:
3232 case DW_TAG_enumerator
:
3233 case DW_TAG_subprogram
:
3237 case DW_TAG_variable
:
3238 /* We only need to prefix "globally" visible variables. These include
3239 any variable marked with DW_AT_external or any variable that
3240 lives in a namespace. [Variables in anonymous namespaces
3241 require prefixing, but they are not DW_AT_external.] */
3243 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
3245 struct dwarf2_cu
*spec_cu
= cu
;
3246 return die_needs_namespace (die_specification (die
, &spec_cu
),
3250 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
3251 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
)
3253 /* A variable in a lexical block of some kind does not need a
3254 namespace, even though in C++ such variables may be external
3255 and have a mangled name. */
3256 if (die
->parent
->tag
== DW_TAG_lexical_block
3257 || die
->parent
->tag
== DW_TAG_try_block
3258 || die
->parent
->tag
== DW_TAG_catch_block
3259 || die
->parent
->tag
== DW_TAG_subprogram
)
3268 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3269 compute the physname for the object, which include a method's
3270 formal parameters (C++/Java) and return type (Java).
3272 For Ada, return the DIE's linkage name rather than the fully qualified
3273 name. PHYSNAME is ignored..
3275 The result is allocated on the objfile_obstack and canonicalized. */
3278 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
3282 name
= dwarf2_name (die
, cu
);
3284 /* These are the only languages we know how to qualify names in. */
3286 && (cu
->language
== language_cplus
|| cu
->language
== language_java
))
3288 if (die_needs_namespace (die
, cu
))
3292 struct ui_file
*buf
;
3294 prefix
= determine_prefix (die
, cu
);
3295 buf
= mem_fileopen ();
3296 if (*prefix
!= '\0')
3298 char *prefixed_name
= typename_concat (NULL
, prefix
, name
, cu
);
3299 fputs_unfiltered (prefixed_name
, buf
);
3300 xfree (prefixed_name
);
3303 fputs_unfiltered (name
? name
: "", buf
);
3305 /* For Java and C++ methods, append formal parameter type
3306 information, if PHYSNAME. */
3308 if (physname
&& die
->tag
== DW_TAG_subprogram
3309 && (cu
->language
== language_cplus
3310 || cu
->language
== language_java
))
3312 struct type
*type
= read_type_die (die
, cu
);
3314 c_type_print_args (type
, buf
, 0, cu
->language
);
3316 if (cu
->language
== language_java
)
3318 /* For java, we must append the return type to method
3320 if (die
->tag
== DW_TAG_subprogram
)
3321 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
3324 else if (cu
->language
== language_cplus
)
3326 if (TYPE_NFIELDS (type
) > 0
3327 && TYPE_FIELD_ARTIFICIAL (type
, 0)
3328 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
3329 fputs_unfiltered (" const", buf
);
3333 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
3335 ui_file_delete (buf
);
3337 if (cu
->language
== language_cplus
)
3340 = dwarf2_canonicalize_name (name
, cu
,
3341 &cu
->objfile
->objfile_obstack
);
3347 else if (cu
->language
== language_ada
)
3349 /* For Ada unit, we prefer the linkage name over the name, as
3350 the former contains the exported name, which the user expects
3351 to be able to reference. Ideally, we want the user to be able
3352 to reference this entity using either natural or linkage name,
3353 but we haven't started looking at this enhancement yet. */
3354 struct attribute
*attr
;
3356 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
3357 if (attr
&& DW_STRING (attr
))
3358 name
= DW_STRING (attr
);
3364 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3365 If scope qualifiers are appropriate they will be added. The result
3366 will be allocated on the objfile_obstack, or NULL if the DIE does
3367 not have a name. NAME may either be from a previous call to
3368 dwarf2_name or NULL.
3370 The output string will be canonicalized (if C++/Java). */
3373 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3375 return dwarf2_compute_name (name
, die
, cu
, 0);
3378 /* Construct a physname for the given DIE in CU. NAME may either be
3379 from a previous call to dwarf2_name or NULL. The result will be
3380 allocated on the objfile_objstack or NULL if the DIE does not have a
3383 The output string will be canonicalized (if C++/Java). */
3386 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3388 return dwarf2_compute_name (name
, die
, cu
, 1);
3391 /* Read the import statement specified by the given die and record it. */
3394 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3396 struct attribute
*import_attr
;
3397 struct die_info
*imported_die
;
3398 struct dwarf2_cu
*imported_cu
;
3399 const char *imported_name
;
3400 const char *imported_name_prefix
;
3401 const char *canonical_name
;
3402 const char *import_alias
;
3403 const char *imported_declaration
= NULL
;
3404 const char *import_prefix
;
3408 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3409 if (import_attr
== NULL
)
3411 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3412 dwarf_tag_name (die
->tag
));
3417 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
3418 imported_name
= dwarf2_name (imported_die
, imported_cu
);
3419 if (imported_name
== NULL
)
3421 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3423 The import in the following code:
3437 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3438 <52> DW_AT_decl_file : 1
3439 <53> DW_AT_decl_line : 6
3440 <54> DW_AT_import : <0x75>
3441 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3443 <5b> DW_AT_decl_file : 1
3444 <5c> DW_AT_decl_line : 2
3445 <5d> DW_AT_type : <0x6e>
3447 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3448 <76> DW_AT_byte_size : 4
3449 <77> DW_AT_encoding : 5 (signed)
3451 imports the wrong die ( 0x75 instead of 0x58 ).
3452 This case will be ignored until the gcc bug is fixed. */
3456 /* Figure out the local name after import. */
3457 import_alias
= dwarf2_name (die
, cu
);
3459 /* Figure out where the statement is being imported to. */
3460 import_prefix
= determine_prefix (die
, cu
);
3462 /* Figure out what the scope of the imported die is and prepend it
3463 to the name of the imported die. */
3464 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
3466 if (imported_die
->tag
!= DW_TAG_namespace
)
3468 imported_declaration
= imported_name
;
3469 canonical_name
= imported_name_prefix
;
3471 else if (strlen (imported_name_prefix
) > 0)
3473 temp
= alloca (strlen (imported_name_prefix
)
3474 + 2 + strlen (imported_name
) + 1);
3475 strcpy (temp
, imported_name_prefix
);
3476 strcat (temp
, "::");
3477 strcat (temp
, imported_name
);
3478 canonical_name
= temp
;
3481 canonical_name
= imported_name
;
3483 cp_add_using_directive (import_prefix
,
3486 imported_declaration
,
3487 &cu
->objfile
->objfile_obstack
);
3491 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3493 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3497 free_cu_line_header (void *arg
)
3499 struct dwarf2_cu
*cu
= arg
;
3501 free_line_header (cu
->line_header
);
3502 cu
->line_header
= NULL
;
3506 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3508 struct objfile
*objfile
= cu
->objfile
;
3509 struct comp_unit_head
*cu_header
= &cu
->header
;
3510 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3511 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3512 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3513 struct attribute
*attr
;
3515 char *comp_dir
= NULL
;
3516 struct die_info
*child_die
;
3517 bfd
*abfd
= objfile
->obfd
;
3518 struct line_header
*line_header
= 0;
3521 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3523 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3525 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3526 from finish_block. */
3527 if (lowpc
== ((CORE_ADDR
) -1))
3532 /* Find the filename. Do not use dwarf2_name here, since the filename
3533 is not a source language identifier. */
3534 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3537 name
= DW_STRING (attr
);
3540 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3542 comp_dir
= DW_STRING (attr
);
3543 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3545 comp_dir
= ldirname (name
);
3546 if (comp_dir
!= NULL
)
3547 make_cleanup (xfree
, comp_dir
);
3549 if (comp_dir
!= NULL
)
3551 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3552 directory, get rid of it. */
3553 char *cp
= strchr (comp_dir
, ':');
3555 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3562 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3565 set_cu_language (DW_UNSND (attr
), cu
);
3568 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3570 cu
->producer
= DW_STRING (attr
);
3572 /* We assume that we're processing GCC output. */
3573 processing_gcc_compilation
= 2;
3575 processing_has_namespace_info
= 0;
3577 start_symtab (name
, comp_dir
, lowpc
);
3578 record_debugformat ("DWARF 2");
3579 record_producer (cu
->producer
);
3581 initialize_cu_func_list (cu
);
3583 /* Decode line number information if present. We do this before
3584 processing child DIEs, so that the line header table is available
3585 for DW_AT_decl_file. */
3586 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3589 unsigned int line_offset
= DW_UNSND (attr
);
3590 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3593 cu
->line_header
= line_header
;
3594 make_cleanup (free_cu_line_header
, cu
);
3595 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3599 /* Process all dies in compilation unit. */
3600 if (die
->child
!= NULL
)
3602 child_die
= die
->child
;
3603 while (child_die
&& child_die
->tag
)
3605 process_die (child_die
, cu
);
3606 child_die
= sibling_die (child_die
);
3610 /* Decode macro information, if present. Dwarf 2 macro information
3611 refers to information in the line number info statement program
3612 header, so we can only read it if we've read the header
3614 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3615 if (attr
&& line_header
)
3617 unsigned int macro_offset
= DW_UNSND (attr
);
3618 dwarf_decode_macros (line_header
, macro_offset
,
3619 comp_dir
, abfd
, cu
);
3621 do_cleanups (back_to
);
3624 /* For TUs we want to skip the first top level sibling if it's not the
3625 actual type being defined by this TU. In this case the first top
3626 level sibling is there to provide context only. */
3629 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3631 struct objfile
*objfile
= cu
->objfile
;
3632 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3634 struct attribute
*attr
;
3636 char *comp_dir
= NULL
;
3637 struct die_info
*child_die
;
3638 bfd
*abfd
= objfile
->obfd
;
3639 struct line_header
*line_header
= 0;
3641 /* start_symtab needs a low pc, but we don't really have one.
3642 Do what read_file_scope would do in the absence of such info. */
3643 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3645 /* Find the filename. Do not use dwarf2_name here, since the filename
3646 is not a source language identifier. */
3647 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3649 name
= DW_STRING (attr
);
3651 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3653 comp_dir
= DW_STRING (attr
);
3654 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3656 comp_dir
= ldirname (name
);
3657 if (comp_dir
!= NULL
)
3658 make_cleanup (xfree
, comp_dir
);
3664 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3666 set_cu_language (DW_UNSND (attr
), cu
);
3668 /* This isn't technically needed today. It is done for symmetry
3669 with read_file_scope. */
3670 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3672 cu
->producer
= DW_STRING (attr
);
3674 /* We assume that we're processing GCC output. */
3675 processing_gcc_compilation
= 2;
3677 processing_has_namespace_info
= 0;
3679 start_symtab (name
, comp_dir
, lowpc
);
3680 record_debugformat ("DWARF 2");
3681 record_producer (cu
->producer
);
3683 /* Process the dies in the type unit. */
3684 if (die
->child
== NULL
)
3686 dump_die_for_error (die
);
3687 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3688 bfd_get_filename (abfd
));
3691 child_die
= die
->child
;
3693 while (child_die
&& child_die
->tag
)
3695 process_die (child_die
, cu
);
3697 child_die
= sibling_die (child_die
);
3700 do_cleanups (back_to
);
3704 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3705 struct dwarf2_cu
*cu
)
3707 struct function_range
*thisfn
;
3709 thisfn
= (struct function_range
*)
3710 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3711 thisfn
->name
= name
;
3712 thisfn
->lowpc
= lowpc
;
3713 thisfn
->highpc
= highpc
;
3714 thisfn
->seen_line
= 0;
3715 thisfn
->next
= NULL
;
3717 if (cu
->last_fn
== NULL
)
3718 cu
->first_fn
= thisfn
;
3720 cu
->last_fn
->next
= thisfn
;
3722 cu
->last_fn
= thisfn
;
3725 /* qsort helper for inherit_abstract_dies. */
3728 unsigned_int_compar (const void *ap
, const void *bp
)
3730 unsigned int a
= *(unsigned int *) ap
;
3731 unsigned int b
= *(unsigned int *) bp
;
3733 return (a
> b
) - (b
> a
);
3736 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3737 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3738 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3741 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3743 struct die_info
*child_die
;
3744 unsigned die_children_count
;
3745 /* CU offsets which were referenced by children of the current DIE. */
3747 unsigned *offsets_end
, *offsetp
;
3748 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3749 struct die_info
*origin_die
;
3750 /* Iterator of the ORIGIN_DIE children. */
3751 struct die_info
*origin_child_die
;
3752 struct cleanup
*cleanups
;
3753 struct attribute
*attr
;
3755 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3759 origin_die
= follow_die_ref (die
, attr
, &cu
);
3760 if (die
->tag
!= origin_die
->tag
3761 && !(die
->tag
== DW_TAG_inlined_subroutine
3762 && origin_die
->tag
== DW_TAG_subprogram
))
3763 complaint (&symfile_complaints
,
3764 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3765 die
->offset
, origin_die
->offset
);
3767 child_die
= die
->child
;
3768 die_children_count
= 0;
3769 while (child_die
&& child_die
->tag
)
3771 child_die
= sibling_die (child_die
);
3772 die_children_count
++;
3774 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3775 cleanups
= make_cleanup (xfree
, offsets
);
3777 offsets_end
= offsets
;
3778 child_die
= die
->child
;
3779 while (child_die
&& child_die
->tag
)
3781 /* For each CHILD_DIE, find the corresponding child of
3782 ORIGIN_DIE. If there is more than one layer of
3783 DW_AT_abstract_origin, follow them all; there shouldn't be,
3784 but GCC versions at least through 4.4 generate this (GCC PR
3786 struct die_info
*child_origin_die
= child_die
;
3789 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
3792 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
3795 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3796 counterpart may exist. */
3797 if (child_origin_die
!= child_die
)
3799 if (child_die
->tag
!= child_origin_die
->tag
3800 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3801 && child_origin_die
->tag
== DW_TAG_subprogram
))
3802 complaint (&symfile_complaints
,
3803 _("Child DIE 0x%x and its abstract origin 0x%x have "
3804 "different tags"), child_die
->offset
,
3805 child_origin_die
->offset
);
3806 if (child_origin_die
->parent
!= origin_die
)
3807 complaint (&symfile_complaints
,
3808 _("Child DIE 0x%x and its abstract origin 0x%x have "
3809 "different parents"), child_die
->offset
,
3810 child_origin_die
->offset
);
3812 *offsets_end
++ = child_origin_die
->offset
;
3814 child_die
= sibling_die (child_die
);
3816 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3817 unsigned_int_compar
);
3818 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3819 if (offsetp
[-1] == *offsetp
)
3820 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3821 "to DIE 0x%x as their abstract origin"),
3822 die
->offset
, *offsetp
);
3825 origin_child_die
= origin_die
->child
;
3826 while (origin_child_die
&& origin_child_die
->tag
)
3828 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3829 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3831 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3833 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3834 process_die (origin_child_die
, cu
);
3836 origin_child_die
= sibling_die (origin_child_die
);
3839 do_cleanups (cleanups
);
3843 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3845 struct objfile
*objfile
= cu
->objfile
;
3846 struct context_stack
*new;
3849 struct die_info
*child_die
;
3850 struct attribute
*attr
, *call_line
, *call_file
;
3853 struct block
*block
;
3854 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3858 /* If we do not have call site information, we can't show the
3859 caller of this inlined function. That's too confusing, so
3860 only use the scope for local variables. */
3861 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3862 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3863 if (call_line
== NULL
|| call_file
== NULL
)
3865 read_lexical_block_scope (die
, cu
);
3870 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3872 name
= dwarf2_name (die
, cu
);
3874 /* Ignore functions with missing or empty names. These are actually
3875 illegal according to the DWARF standard. */
3878 complaint (&symfile_complaints
,
3879 _("missing name for subprogram DIE at %d"), die
->offset
);
3883 /* Ignore functions with missing or invalid low and high pc attributes. */
3884 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3886 complaint (&symfile_complaints
,
3887 _("cannot get low and high bounds for subprogram DIE at %d"),
3895 /* Record the function range for dwarf_decode_lines. */
3896 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3898 new = push_context (0, lowpc
);
3899 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3901 /* If there is a location expression for DW_AT_frame_base, record
3903 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3905 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3906 expression is being recorded directly in the function's symbol
3907 and not in a separate frame-base object. I guess this hack is
3908 to avoid adding some sort of frame-base adjunct/annex to the
3909 function's symbol :-(. The problem with doing this is that it
3910 results in a function symbol with a location expression that
3911 has nothing to do with the location of the function, ouch! The
3912 relationship should be: a function's symbol has-a frame base; a
3913 frame-base has-a location expression. */
3914 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3916 cu
->list_in_scope
= &local_symbols
;
3918 if (die
->child
!= NULL
)
3920 child_die
= die
->child
;
3921 while (child_die
&& child_die
->tag
)
3923 process_die (child_die
, cu
);
3924 child_die
= sibling_die (child_die
);
3928 inherit_abstract_dies (die
, cu
);
3930 new = pop_context ();
3931 /* Make a block for the local symbols within. */
3932 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3933 lowpc
, highpc
, objfile
);
3935 /* For C++, set the block's scope. */
3936 if (cu
->language
== language_cplus
)
3937 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3938 determine_prefix (die
, cu
),
3939 processing_has_namespace_info
);
3941 /* If we have address ranges, record them. */
3942 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3944 /* In C++, we can have functions nested inside functions (e.g., when
3945 a function declares a class that has methods). This means that
3946 when we finish processing a function scope, we may need to go
3947 back to building a containing block's symbol lists. */
3948 local_symbols
= new->locals
;
3949 param_symbols
= new->params
;
3950 using_directives
= new->using_directives
;
3952 /* If we've finished processing a top-level function, subsequent
3953 symbols go in the file symbol list. */
3954 if (outermost_context_p ())
3955 cu
->list_in_scope
= &file_symbols
;
3958 /* Process all the DIES contained within a lexical block scope. Start
3959 a new scope, process the dies, and then close the scope. */
3962 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3964 struct objfile
*objfile
= cu
->objfile
;
3965 struct context_stack
*new;
3966 CORE_ADDR lowpc
, highpc
;
3967 struct die_info
*child_die
;
3970 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3972 /* Ignore blocks with missing or invalid low and high pc attributes. */
3973 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3974 as multiple lexical blocks? Handling children in a sane way would
3975 be nasty. Might be easier to properly extend generic blocks to
3977 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3982 push_context (0, lowpc
);
3983 if (die
->child
!= NULL
)
3985 child_die
= die
->child
;
3986 while (child_die
&& child_die
->tag
)
3988 process_die (child_die
, cu
);
3989 child_die
= sibling_die (child_die
);
3992 new = pop_context ();
3994 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
3997 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
4000 /* Note that recording ranges after traversing children, as we
4001 do here, means that recording a parent's ranges entails
4002 walking across all its children's ranges as they appear in
4003 the address map, which is quadratic behavior.
4005 It would be nicer to record the parent's ranges before
4006 traversing its children, simply overriding whatever you find
4007 there. But since we don't even decide whether to create a
4008 block until after we've traversed its children, that's hard
4010 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
4012 local_symbols
= new->locals
;
4013 using_directives
= new->using_directives
;
4016 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
4017 Return 1 if the attributes are present and valid, otherwise, return 0.
4018 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
4021 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
4022 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
4023 struct partial_symtab
*ranges_pst
)
4025 struct objfile
*objfile
= cu
->objfile
;
4026 struct comp_unit_head
*cu_header
= &cu
->header
;
4027 bfd
*obfd
= objfile
->obfd
;
4028 unsigned int addr_size
= cu_header
->addr_size
;
4029 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4030 /* Base address selection entry. */
4041 found_base
= cu
->base_known
;
4042 base
= cu
->base_address
;
4044 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
4045 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4047 complaint (&symfile_complaints
,
4048 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4052 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4054 /* Read in the largest possible address. */
4055 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
4056 if ((marker
& mask
) == mask
)
4058 /* If we found the largest possible address, then
4059 read the base address. */
4060 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4061 buffer
+= 2 * addr_size
;
4062 offset
+= 2 * addr_size
;
4068 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4072 CORE_ADDR range_beginning
, range_end
;
4074 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
4075 buffer
+= addr_size
;
4076 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
4077 buffer
+= addr_size
;
4078 offset
+= 2 * addr_size
;
4080 /* An end of list marker is a pair of zero addresses. */
4081 if (range_beginning
== 0 && range_end
== 0)
4082 /* Found the end of list entry. */
4085 /* Each base address selection entry is a pair of 2 values.
4086 The first is the largest possible address, the second is
4087 the base address. Check for a base address here. */
4088 if ((range_beginning
& mask
) == mask
)
4090 /* If we found the largest possible address, then
4091 read the base address. */
4092 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4099 /* We have no valid base address for the ranges
4101 complaint (&symfile_complaints
,
4102 _("Invalid .debug_ranges data (no base address)"));
4106 range_beginning
+= base
;
4109 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
4110 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4111 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
4114 /* FIXME: This is recording everything as a low-high
4115 segment of consecutive addresses. We should have a
4116 data structure for discontiguous block ranges
4120 low
= range_beginning
;
4126 if (range_beginning
< low
)
4127 low
= range_beginning
;
4128 if (range_end
> high
)
4134 /* If the first entry is an end-of-list marker, the range
4135 describes an empty scope, i.e. no instructions. */
4141 *high_return
= high
;
4145 /* Get low and high pc attributes from a die. Return 1 if the attributes
4146 are present and valid, otherwise, return 0. Return -1 if the range is
4147 discontinuous, i.e. derived from DW_AT_ranges information. */
4149 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
4150 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
4151 struct partial_symtab
*pst
)
4153 struct attribute
*attr
;
4158 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4161 high
= DW_ADDR (attr
);
4162 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4164 low
= DW_ADDR (attr
);
4166 /* Found high w/o low attribute. */
4169 /* Found consecutive range of addresses. */
4174 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4177 /* Value of the DW_AT_ranges attribute is the offset in the
4178 .debug_ranges section. */
4179 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
4181 /* Found discontinuous range of addresses. */
4189 /* When using the GNU linker, .gnu.linkonce. sections are used to
4190 eliminate duplicate copies of functions and vtables and such.
4191 The linker will arbitrarily choose one and discard the others.
4192 The AT_*_pc values for such functions refer to local labels in
4193 these sections. If the section from that file was discarded, the
4194 labels are not in the output, so the relocs get a value of 0.
4195 If this is a discarded function, mark the pc bounds as invalid,
4196 so that GDB will ignore it. */
4197 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
4205 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4206 its low and high PC addresses. Do nothing if these addresses could not
4207 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4208 and HIGHPC to the high address if greater than HIGHPC. */
4211 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
4212 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4213 struct dwarf2_cu
*cu
)
4215 CORE_ADDR low
, high
;
4216 struct die_info
*child
= die
->child
;
4218 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
4220 *lowpc
= min (*lowpc
, low
);
4221 *highpc
= max (*highpc
, high
);
4224 /* If the language does not allow nested subprograms (either inside
4225 subprograms or lexical blocks), we're done. */
4226 if (cu
->language
!= language_ada
)
4229 /* Check all the children of the given DIE. If it contains nested
4230 subprograms, then check their pc bounds. Likewise, we need to
4231 check lexical blocks as well, as they may also contain subprogram
4233 while (child
&& child
->tag
)
4235 if (child
->tag
== DW_TAG_subprogram
4236 || child
->tag
== DW_TAG_lexical_block
)
4237 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
4238 child
= sibling_die (child
);
4242 /* Get the low and high pc's represented by the scope DIE, and store
4243 them in *LOWPC and *HIGHPC. If the correct values can't be
4244 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4247 get_scope_pc_bounds (struct die_info
*die
,
4248 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4249 struct dwarf2_cu
*cu
)
4251 CORE_ADDR best_low
= (CORE_ADDR
) -1;
4252 CORE_ADDR best_high
= (CORE_ADDR
) 0;
4253 CORE_ADDR current_low
, current_high
;
4255 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
4257 best_low
= current_low
;
4258 best_high
= current_high
;
4262 struct die_info
*child
= die
->child
;
4264 while (child
&& child
->tag
)
4266 switch (child
->tag
) {
4267 case DW_TAG_subprogram
:
4268 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
4270 case DW_TAG_namespace
:
4271 /* FIXME: carlton/2004-01-16: Should we do this for
4272 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4273 that current GCC's always emit the DIEs corresponding
4274 to definitions of methods of classes as children of a
4275 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4276 the DIEs giving the declarations, which could be
4277 anywhere). But I don't see any reason why the
4278 standards says that they have to be there. */
4279 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
4281 if (current_low
!= ((CORE_ADDR
) -1))
4283 best_low
= min (best_low
, current_low
);
4284 best_high
= max (best_high
, current_high
);
4292 child
= sibling_die (child
);
4297 *highpc
= best_high
;
4300 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4303 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
4304 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
4306 struct attribute
*attr
;
4308 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4311 CORE_ADDR high
= DW_ADDR (attr
);
4312 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4315 CORE_ADDR low
= DW_ADDR (attr
);
4316 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
4320 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4323 bfd
*obfd
= cu
->objfile
->obfd
;
4325 /* The value of the DW_AT_ranges attribute is the offset of the
4326 address range list in the .debug_ranges section. */
4327 unsigned long offset
= DW_UNSND (attr
);
4328 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4330 /* For some target architectures, but not others, the
4331 read_address function sign-extends the addresses it returns.
4332 To recognize base address selection entries, we need a
4334 unsigned int addr_size
= cu
->header
.addr_size
;
4335 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4337 /* The base address, to which the next pair is relative. Note
4338 that this 'base' is a DWARF concept: most entries in a range
4339 list are relative, to reduce the number of relocs against the
4340 debugging information. This is separate from this function's
4341 'baseaddr' argument, which GDB uses to relocate debugging
4342 information from a shared library based on the address at
4343 which the library was loaded. */
4344 CORE_ADDR base
= cu
->base_address
;
4345 int base_known
= cu
->base_known
;
4347 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
4348 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4350 complaint (&symfile_complaints
,
4351 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4358 unsigned int bytes_read
;
4359 CORE_ADDR start
, end
;
4361 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4362 buffer
+= bytes_read
;
4363 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4364 buffer
+= bytes_read
;
4366 /* Did we find the end of the range list? */
4367 if (start
== 0 && end
== 0)
4370 /* Did we find a base address selection entry? */
4371 else if ((start
& base_select_mask
) == base_select_mask
)
4377 /* We found an ordinary address range. */
4382 complaint (&symfile_complaints
,
4383 _("Invalid .debug_ranges data (no base address)"));
4387 record_block_range (block
,
4388 baseaddr
+ base
+ start
,
4389 baseaddr
+ base
+ end
- 1);
4395 /* Add an aggregate field to the field list. */
4398 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
4399 struct dwarf2_cu
*cu
)
4401 struct objfile
*objfile
= cu
->objfile
;
4402 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4403 struct nextfield
*new_field
;
4404 struct attribute
*attr
;
4406 char *fieldname
= "";
4408 /* Allocate a new field list entry and link it in. */
4409 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
4410 make_cleanup (xfree
, new_field
);
4411 memset (new_field
, 0, sizeof (struct nextfield
));
4413 if (die
->tag
== DW_TAG_inheritance
)
4415 new_field
->next
= fip
->baseclasses
;
4416 fip
->baseclasses
= new_field
;
4420 new_field
->next
= fip
->fields
;
4421 fip
->fields
= new_field
;
4425 /* Handle accessibility and virtuality of field.
4426 The default accessibility for members is public, the default
4427 accessibility for inheritance is private. */
4428 if (die
->tag
!= DW_TAG_inheritance
)
4429 new_field
->accessibility
= DW_ACCESS_public
;
4431 new_field
->accessibility
= DW_ACCESS_private
;
4432 new_field
->virtuality
= DW_VIRTUALITY_none
;
4434 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4436 new_field
->accessibility
= DW_UNSND (attr
);
4437 if (new_field
->accessibility
!= DW_ACCESS_public
)
4438 fip
->non_public_fields
= 1;
4439 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4441 new_field
->virtuality
= DW_UNSND (attr
);
4443 fp
= &new_field
->field
;
4445 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
4447 /* Data member other than a C++ static data member. */
4449 /* Get type of field. */
4450 fp
->type
= die_type (die
, cu
);
4452 SET_FIELD_BITPOS (*fp
, 0);
4454 /* Get bit size of field (zero if none). */
4455 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
4458 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
4462 FIELD_BITSIZE (*fp
) = 0;
4465 /* Get bit offset of field. */
4466 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4469 int byte_offset
= 0;
4471 if (attr_form_is_section_offset (attr
))
4472 dwarf2_complex_location_expr_complaint ();
4473 else if (attr_form_is_constant (attr
))
4474 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4475 else if (attr_form_is_block (attr
))
4476 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4478 dwarf2_complex_location_expr_complaint ();
4480 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4482 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
4485 if (gdbarch_bits_big_endian (gdbarch
))
4487 /* For big endian bits, the DW_AT_bit_offset gives the
4488 additional bit offset from the MSB of the containing
4489 anonymous object to the MSB of the field. We don't
4490 have to do anything special since we don't need to
4491 know the size of the anonymous object. */
4492 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
4496 /* For little endian bits, compute the bit offset to the
4497 MSB of the anonymous object, subtract off the number of
4498 bits from the MSB of the field to the MSB of the
4499 object, and then subtract off the number of bits of
4500 the field itself. The result is the bit offset of
4501 the LSB of the field. */
4503 int bit_offset
= DW_UNSND (attr
);
4505 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4508 /* The size of the anonymous object containing
4509 the bit field is explicit, so use the
4510 indicated size (in bytes). */
4511 anonymous_size
= DW_UNSND (attr
);
4515 /* The size of the anonymous object containing
4516 the bit field must be inferred from the type
4517 attribute of the data member containing the
4519 anonymous_size
= TYPE_LENGTH (fp
->type
);
4521 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4522 - bit_offset
- FIELD_BITSIZE (*fp
);
4526 /* Get name of field. */
4527 fieldname
= dwarf2_name (die
, cu
);
4528 if (fieldname
== NULL
)
4531 /* The name is already allocated along with this objfile, so we don't
4532 need to duplicate it for the type. */
4533 fp
->name
= fieldname
;
4535 /* Change accessibility for artificial fields (e.g. virtual table
4536 pointer or virtual base class pointer) to private. */
4537 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4539 FIELD_ARTIFICIAL (*fp
) = 1;
4540 new_field
->accessibility
= DW_ACCESS_private
;
4541 fip
->non_public_fields
= 1;
4544 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4546 /* C++ static member. */
4548 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4549 is a declaration, but all versions of G++ as of this writing
4550 (so through at least 3.2.1) incorrectly generate
4551 DW_TAG_variable tags. */
4555 /* Get name of field. */
4556 fieldname
= dwarf2_name (die
, cu
);
4557 if (fieldname
== NULL
)
4560 /* Get physical name. */
4561 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4563 /* The name is already allocated along with this objfile, so we don't
4564 need to duplicate it for the type. */
4565 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4566 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4567 FIELD_NAME (*fp
) = fieldname
;
4569 else if (die
->tag
== DW_TAG_inheritance
)
4571 /* C++ base class field. */
4572 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4575 int byte_offset
= 0;
4577 if (attr_form_is_section_offset (attr
))
4578 dwarf2_complex_location_expr_complaint ();
4579 else if (attr_form_is_constant (attr
))
4580 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4581 else if (attr_form_is_block (attr
))
4582 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4584 dwarf2_complex_location_expr_complaint ();
4586 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4588 FIELD_BITSIZE (*fp
) = 0;
4589 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4590 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4591 fip
->nbaseclasses
++;
4595 /* Create the vector of fields, and attach it to the type. */
4598 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4599 struct dwarf2_cu
*cu
)
4601 int nfields
= fip
->nfields
;
4603 /* Record the field count, allocate space for the array of fields,
4604 and create blank accessibility bitfields if necessary. */
4605 TYPE_NFIELDS (type
) = nfields
;
4606 TYPE_FIELDS (type
) = (struct field
*)
4607 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4608 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4610 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
4612 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4614 TYPE_FIELD_PRIVATE_BITS (type
) =
4615 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4616 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4618 TYPE_FIELD_PROTECTED_BITS (type
) =
4619 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4620 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4622 TYPE_FIELD_IGNORE_BITS (type
) =
4623 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4624 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4627 /* If the type has baseclasses, allocate and clear a bit vector for
4628 TYPE_FIELD_VIRTUAL_BITS. */
4629 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
4631 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4632 unsigned char *pointer
;
4634 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4635 pointer
= TYPE_ALLOC (type
, num_bytes
);
4636 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4637 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4638 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4641 /* Copy the saved-up fields into the field vector. Start from the head
4642 of the list, adding to the tail of the field array, so that they end
4643 up in the same order in the array in which they were added to the list. */
4644 while (nfields
-- > 0)
4646 struct nextfield
*fieldp
;
4650 fieldp
= fip
->fields
;
4651 fip
->fields
= fieldp
->next
;
4655 fieldp
= fip
->baseclasses
;
4656 fip
->baseclasses
= fieldp
->next
;
4659 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
4660 switch (fieldp
->accessibility
)
4662 case DW_ACCESS_private
:
4663 if (cu
->language
!= language_ada
)
4664 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4667 case DW_ACCESS_protected
:
4668 if (cu
->language
!= language_ada
)
4669 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4672 case DW_ACCESS_public
:
4676 /* Unknown accessibility. Complain and treat it as public. */
4678 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4679 fieldp
->accessibility
);
4683 if (nfields
< fip
->nbaseclasses
)
4685 switch (fieldp
->virtuality
)
4687 case DW_VIRTUALITY_virtual
:
4688 case DW_VIRTUALITY_pure_virtual
:
4689 if (cu
->language
== language_ada
)
4690 error ("unexpected virtuality in component of Ada type");
4691 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4698 /* Add a member function to the proper fieldlist. */
4701 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4702 struct type
*type
, struct dwarf2_cu
*cu
)
4704 struct objfile
*objfile
= cu
->objfile
;
4705 struct attribute
*attr
;
4706 struct fnfieldlist
*flp
;
4708 struct fn_field
*fnp
;
4711 struct nextfnfield
*new_fnfield
;
4712 struct type
*this_type
;
4714 if (cu
->language
== language_ada
)
4715 error ("unexpected member function in Ada type");
4717 /* Get name of member function. */
4718 fieldname
= dwarf2_name (die
, cu
);
4719 if (fieldname
== NULL
)
4722 /* Get the mangled name. */
4723 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4725 /* Look up member function name in fieldlist. */
4726 for (i
= 0; i
< fip
->nfnfields
; i
++)
4728 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4732 /* Create new list element if necessary. */
4733 if (i
< fip
->nfnfields
)
4734 flp
= &fip
->fnfieldlists
[i
];
4737 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4739 fip
->fnfieldlists
= (struct fnfieldlist
*)
4740 xrealloc (fip
->fnfieldlists
,
4741 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4742 * sizeof (struct fnfieldlist
));
4743 if (fip
->nfnfields
== 0)
4744 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4746 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4747 flp
->name
= fieldname
;
4753 /* Create a new member function field and chain it to the field list
4755 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4756 make_cleanup (xfree
, new_fnfield
);
4757 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4758 new_fnfield
->next
= flp
->head
;
4759 flp
->head
= new_fnfield
;
4762 /* Fill in the member function field info. */
4763 fnp
= &new_fnfield
->fnfield
;
4764 /* The name is already allocated along with this objfile, so we don't
4765 need to duplicate it for the type. */
4766 fnp
->physname
= physname
? physname
: "";
4767 fnp
->type
= alloc_type (objfile
);
4768 this_type
= read_type_die (die
, cu
);
4769 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4771 int nparams
= TYPE_NFIELDS (this_type
);
4773 /* TYPE is the domain of this method, and THIS_TYPE is the type
4774 of the method itself (TYPE_CODE_METHOD). */
4775 smash_to_method_type (fnp
->type
, type
,
4776 TYPE_TARGET_TYPE (this_type
),
4777 TYPE_FIELDS (this_type
),
4778 TYPE_NFIELDS (this_type
),
4779 TYPE_VARARGS (this_type
));
4781 /* Handle static member functions.
4782 Dwarf2 has no clean way to discern C++ static and non-static
4783 member functions. G++ helps GDB by marking the first
4784 parameter for non-static member functions (which is the
4785 this pointer) as artificial. We obtain this information
4786 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4787 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4788 fnp
->voffset
= VOFFSET_STATIC
;
4791 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4794 /* Get fcontext from DW_AT_containing_type if present. */
4795 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4796 fnp
->fcontext
= die_containing_type (die
, cu
);
4798 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4799 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4801 /* Get accessibility. */
4802 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4805 switch (DW_UNSND (attr
))
4807 case DW_ACCESS_private
:
4808 fnp
->is_private
= 1;
4810 case DW_ACCESS_protected
:
4811 fnp
->is_protected
= 1;
4816 /* Check for artificial methods. */
4817 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4818 if (attr
&& DW_UNSND (attr
) != 0)
4819 fnp
->is_artificial
= 1;
4821 /* Get index in virtual function table if it is a virtual member
4822 function. For GCC, this is an offset in the appropriate
4823 virtual table, as specified by DW_AT_containing_type. For
4824 everyone else, it is an expression to be evaluated relative
4825 to the object address. */
4827 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4828 if (attr
&& fnp
->fcontext
)
4830 /* Support the .debug_loc offsets */
4831 if (attr_form_is_block (attr
))
4833 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4835 else if (attr_form_is_section_offset (attr
))
4837 dwarf2_complex_location_expr_complaint ();
4841 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4847 /* We only support trivial expressions here. This hack will work
4848 for v3 classes, which always start with the vtable pointer. */
4849 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0
4850 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref
)
4852 struct dwarf_block blk
;
4853 blk
.size
= DW_BLOCK (attr
)->size
- 1;
4854 blk
.data
= DW_BLOCK (attr
)->data
+ 1;
4855 fnp
->voffset
= decode_locdesc (&blk
, cu
);
4856 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
4857 dwarf2_complex_location_expr_complaint ();
4859 fnp
->voffset
/= cu
->header
.addr_size
;
4861 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
4864 dwarf2_complex_location_expr_complaint ();
4868 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4869 if (attr
&& DW_UNSND (attr
))
4871 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4872 complaint (&symfile_complaints
,
4873 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4874 fieldname
, die
->offset
);
4875 TYPE_CPLUS_DYNAMIC (type
) = 1;
4880 /* Create the vector of member function fields, and attach it to the type. */
4883 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4884 struct dwarf2_cu
*cu
)
4886 struct fnfieldlist
*flp
;
4887 int total_length
= 0;
4890 if (cu
->language
== language_ada
)
4891 error ("unexpected member functions in Ada type");
4893 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4894 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4895 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4897 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4899 struct nextfnfield
*nfp
= flp
->head
;
4900 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4903 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4904 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4905 fn_flp
->fn_fields
= (struct fn_field
*)
4906 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4907 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4908 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4910 total_length
+= flp
->length
;
4913 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4914 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4917 /* Returns non-zero if NAME is the name of a vtable member in CU's
4918 language, zero otherwise. */
4920 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4922 static const char vptr
[] = "_vptr";
4923 static const char vtable
[] = "vtable";
4925 /* Look for the C++ and Java forms of the vtable. */
4926 if ((cu
->language
== language_java
4927 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4928 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4929 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4935 /* GCC outputs unnamed structures that are really pointers to member
4936 functions, with the ABI-specified layout. If TYPE describes
4937 such a structure, smash it into a member function type.
4939 GCC shouldn't do this; it should just output pointer to member DIEs.
4940 This is GCC PR debug/28767. */
4943 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
4945 struct type
*pfn_type
, *domain_type
, *new_type
;
4947 /* Check for a structure with no name and two children. */
4948 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
4951 /* Check for __pfn and __delta members. */
4952 if (TYPE_FIELD_NAME (type
, 0) == NULL
4953 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
4954 || TYPE_FIELD_NAME (type
, 1) == NULL
4955 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
4958 /* Find the type of the method. */
4959 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
4960 if (pfn_type
== NULL
4961 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4962 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4965 /* Look for the "this" argument. */
4966 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4967 if (TYPE_NFIELDS (pfn_type
) == 0
4968 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
4969 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4972 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4973 new_type
= alloc_type (objfile
);
4974 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4975 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4976 TYPE_VARARGS (pfn_type
));
4977 smash_to_methodptr_type (type
, new_type
);
4980 /* Called when we find the DIE that starts a structure or union scope
4981 (definition) to process all dies that define the members of the
4984 NOTE: we need to call struct_type regardless of whether or not the
4985 DIE has an at_name attribute, since it might be an anonymous
4986 structure or union. This gets the type entered into our set of
4989 However, if the structure is incomplete (an opaque struct/union)
4990 then suppress creating a symbol table entry for it since gdb only
4991 wants to find the one with the complete definition. Note that if
4992 it is complete, we just call new_symbol, which does it's own
4993 checking about whether the struct/union is anonymous or not (and
4994 suppresses creating a symbol table entry itself). */
4996 static struct type
*
4997 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4999 struct objfile
*objfile
= cu
->objfile
;
5001 struct attribute
*attr
;
5003 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5005 /* If the definition of this type lives in .debug_types, read that type.
5006 Don't follow DW_AT_specification though, that will take us back up
5007 the chain and we want to go down. */
5008 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5011 struct dwarf2_cu
*type_cu
= cu
;
5012 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5013 /* We could just recurse on read_structure_type, but we need to call
5014 get_die_type to ensure only one type for this DIE is created.
5015 This is important, for example, because for c++ classes we need
5016 TYPE_NAME set which is only done by new_symbol. Blech. */
5017 type
= read_type_die (type_die
, type_cu
);
5018 return set_die_type (die
, type
, cu
);
5021 type
= alloc_type (objfile
);
5022 INIT_CPLUS_SPECIFIC (type
);
5024 name
= dwarf2_name (die
, cu
);
5027 if (cu
->language
== language_cplus
5028 || cu
->language
== language_java
)
5030 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
5031 if (die
->tag
== DW_TAG_structure_type
5032 || die
->tag
== DW_TAG_class_type
)
5033 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5037 /* The name is already allocated along with this objfile, so
5038 we don't need to duplicate it for the type. */
5039 TYPE_TAG_NAME (type
) = (char *) name
;
5040 if (die
->tag
== DW_TAG_class_type
)
5041 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5045 if (die
->tag
== DW_TAG_structure_type
)
5047 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
5049 else if (die
->tag
== DW_TAG_union_type
)
5051 TYPE_CODE (type
) = TYPE_CODE_UNION
;
5055 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
5058 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
5059 TYPE_DECLARED_CLASS (type
) = 1;
5061 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5064 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5068 TYPE_LENGTH (type
) = 0;
5071 TYPE_STUB_SUPPORTED (type
) = 1;
5072 if (die_is_declaration (die
, cu
))
5073 TYPE_STUB (type
) = 1;
5075 set_descriptive_type (type
, die
, cu
);
5077 /* We need to add the type field to the die immediately so we don't
5078 infinitely recurse when dealing with pointers to the structure
5079 type within the structure itself. */
5080 set_die_type (die
, type
, cu
);
5082 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
5084 struct field_info fi
;
5085 struct die_info
*child_die
;
5087 memset (&fi
, 0, sizeof (struct field_info
));
5089 child_die
= die
->child
;
5091 while (child_die
&& child_die
->tag
)
5093 if (child_die
->tag
== DW_TAG_member
5094 || child_die
->tag
== DW_TAG_variable
)
5096 /* NOTE: carlton/2002-11-05: A C++ static data member
5097 should be a DW_TAG_member that is a declaration, but
5098 all versions of G++ as of this writing (so through at
5099 least 3.2.1) incorrectly generate DW_TAG_variable
5100 tags for them instead. */
5101 dwarf2_add_field (&fi
, child_die
, cu
);
5103 else if (child_die
->tag
== DW_TAG_subprogram
)
5105 /* C++ member function. */
5106 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
5108 else if (child_die
->tag
== DW_TAG_inheritance
)
5110 /* C++ base class field. */
5111 dwarf2_add_field (&fi
, child_die
, cu
);
5113 child_die
= sibling_die (child_die
);
5116 /* Attach fields and member functions to the type. */
5118 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
5121 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
5123 /* Get the type which refers to the base class (possibly this
5124 class itself) which contains the vtable pointer for the current
5125 class from the DW_AT_containing_type attribute. This use of
5126 DW_AT_containing_type is a GNU extension. */
5128 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5130 struct type
*t
= die_containing_type (die
, cu
);
5132 TYPE_VPTR_BASETYPE (type
) = t
;
5137 /* Our own class provides vtbl ptr. */
5138 for (i
= TYPE_NFIELDS (t
) - 1;
5139 i
>= TYPE_N_BASECLASSES (t
);
5142 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
5144 if (is_vtable_name (fieldname
, cu
))
5146 TYPE_VPTR_FIELDNO (type
) = i
;
5151 /* Complain if virtual function table field not found. */
5152 if (i
< TYPE_N_BASECLASSES (t
))
5153 complaint (&symfile_complaints
,
5154 _("virtual function table pointer not found when defining class '%s'"),
5155 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
5160 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
5163 else if (cu
->producer
5164 && strncmp (cu
->producer
,
5165 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5167 /* The IBM XLC compiler does not provide direct indication
5168 of the containing type, but the vtable pointer is
5169 always named __vfp. */
5173 for (i
= TYPE_NFIELDS (type
) - 1;
5174 i
>= TYPE_N_BASECLASSES (type
);
5177 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
5179 TYPE_VPTR_FIELDNO (type
) = i
;
5180 TYPE_VPTR_BASETYPE (type
) = type
;
5188 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
5190 do_cleanups (back_to
);
5195 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5197 struct objfile
*objfile
= cu
->objfile
;
5198 struct die_info
*child_die
= die
->child
;
5199 struct type
*this_type
;
5201 this_type
= get_die_type (die
, cu
);
5202 if (this_type
== NULL
)
5203 this_type
= read_structure_type (die
, cu
);
5205 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5206 snapshots) has been known to create a die giving a declaration
5207 for a class that has, as a child, a die giving a definition for a
5208 nested class. So we have to process our children even if the
5209 current die is a declaration. Normally, of course, a declaration
5210 won't have any children at all. */
5212 while (child_die
!= NULL
&& child_die
->tag
)
5214 if (child_die
->tag
== DW_TAG_member
5215 || child_die
->tag
== DW_TAG_variable
5216 || child_die
->tag
== DW_TAG_inheritance
)
5221 process_die (child_die
, cu
);
5223 child_die
= sibling_die (child_die
);
5226 /* Do not consider external references. According to the DWARF standard,
5227 these DIEs are identified by the fact that they have no byte_size
5228 attribute, and a declaration attribute. */
5229 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
5230 || !die_is_declaration (die
, cu
))
5231 new_symbol (die
, this_type
, cu
);
5234 /* Given a DW_AT_enumeration_type die, set its type. We do not
5235 complete the type's fields yet, or create any symbols. */
5237 static struct type
*
5238 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5240 struct objfile
*objfile
= cu
->objfile
;
5242 struct attribute
*attr
;
5245 /* If the definition of this type lives in .debug_types, read that type.
5246 Don't follow DW_AT_specification though, that will take us back up
5247 the chain and we want to go down. */
5248 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5251 struct dwarf2_cu
*type_cu
= cu
;
5252 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5253 type
= read_type_die (type_die
, type_cu
);
5254 return set_die_type (die
, type
, cu
);
5257 type
= alloc_type (objfile
);
5259 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
5260 name
= dwarf2_full_name (NULL
, die
, cu
);
5262 TYPE_TAG_NAME (type
) = (char *) name
;
5264 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5267 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5271 TYPE_LENGTH (type
) = 0;
5274 /* The enumeration DIE can be incomplete. In Ada, any type can be
5275 declared as private in the package spec, and then defined only
5276 inside the package body. Such types are known as Taft Amendment
5277 Types. When another package uses such a type, an incomplete DIE
5278 may be generated by the compiler. */
5279 if (die_is_declaration (die
, cu
))
5280 TYPE_STUB (type
) = 1;
5282 return set_die_type (die
, type
, cu
);
5285 /* Given a pointer to a die which begins an enumeration, process all
5286 the dies that define the members of the enumeration, and create the
5287 symbol for the enumeration type.
5289 NOTE: We reverse the order of the element list. */
5292 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5294 struct objfile
*objfile
= cu
->objfile
;
5295 struct die_info
*child_die
;
5296 struct field
*fields
;
5299 int unsigned_enum
= 1;
5301 struct type
*this_type
;
5305 this_type
= get_die_type (die
, cu
);
5306 if (this_type
== NULL
)
5307 this_type
= read_enumeration_type (die
, cu
);
5308 if (die
->child
!= NULL
)
5310 child_die
= die
->child
;
5311 while (child_die
&& child_die
->tag
)
5313 if (child_die
->tag
!= DW_TAG_enumerator
)
5315 process_die (child_die
, cu
);
5319 name
= dwarf2_name (child_die
, cu
);
5322 sym
= new_symbol (child_die
, this_type
, cu
);
5323 if (SYMBOL_VALUE (sym
) < 0)
5326 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5328 fields
= (struct field
*)
5330 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
5331 * sizeof (struct field
));
5334 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
5335 FIELD_TYPE (fields
[num_fields
]) = NULL
;
5336 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
5337 FIELD_BITSIZE (fields
[num_fields
]) = 0;
5343 child_die
= sibling_die (child_die
);
5348 TYPE_NFIELDS (this_type
) = num_fields
;
5349 TYPE_FIELDS (this_type
) = (struct field
*)
5350 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
5351 memcpy (TYPE_FIELDS (this_type
), fields
,
5352 sizeof (struct field
) * num_fields
);
5356 TYPE_UNSIGNED (this_type
) = 1;
5359 new_symbol (die
, this_type
, cu
);
5362 /* Extract all information from a DW_TAG_array_type DIE and put it in
5363 the DIE's type field. For now, this only handles one dimensional
5366 static struct type
*
5367 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5369 struct objfile
*objfile
= cu
->objfile
;
5370 struct die_info
*child_die
;
5371 struct type
*type
= NULL
;
5372 struct type
*element_type
, *range_type
, *index_type
;
5373 struct type
**range_types
= NULL
;
5374 struct attribute
*attr
;
5376 struct cleanup
*back_to
;
5379 element_type
= die_type (die
, cu
);
5381 /* Irix 6.2 native cc creates array types without children for
5382 arrays with unspecified length. */
5383 if (die
->child
== NULL
)
5385 index_type
= objfile_type (objfile
)->builtin_int
;
5386 range_type
= create_range_type (NULL
, index_type
, 0, -1);
5387 type
= create_array_type (NULL
, element_type
, range_type
);
5388 return set_die_type (die
, type
, cu
);
5391 back_to
= make_cleanup (null_cleanup
, NULL
);
5392 child_die
= die
->child
;
5393 while (child_die
&& child_die
->tag
)
5395 if (child_die
->tag
== DW_TAG_subrange_type
)
5397 struct type
*child_type
= read_type_die (child_die
, cu
);
5398 if (child_type
!= NULL
)
5400 /* The range type was succesfully read. Save it for
5401 the array type creation. */
5402 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
5404 range_types
= (struct type
**)
5405 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
5406 * sizeof (struct type
*));
5408 make_cleanup (free_current_contents
, &range_types
);
5410 range_types
[ndim
++] = child_type
;
5413 child_die
= sibling_die (child_die
);
5416 /* Dwarf2 dimensions are output from left to right, create the
5417 necessary array types in backwards order. */
5419 type
= element_type
;
5421 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
5425 type
= create_array_type (NULL
, type
, range_types
[i
++]);
5430 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
5433 /* Understand Dwarf2 support for vector types (like they occur on
5434 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5435 array type. This is not part of the Dwarf2/3 standard yet, but a
5436 custom vendor extension. The main difference between a regular
5437 array and the vector variant is that vectors are passed by value
5439 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
5441 make_vector_type (type
);
5443 name
= dwarf2_name (die
, cu
);
5445 TYPE_NAME (type
) = name
;
5447 set_descriptive_type (type
, die
, cu
);
5449 do_cleanups (back_to
);
5451 /* Install the type in the die. */
5452 return set_die_type (die
, type
, cu
);
5455 static enum dwarf_array_dim_ordering
5456 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
5458 struct attribute
*attr
;
5460 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
5462 if (attr
) return DW_SND (attr
);
5465 GNU F77 is a special case, as at 08/2004 array type info is the
5466 opposite order to the dwarf2 specification, but data is still
5467 laid out as per normal fortran.
5469 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5473 if (cu
->language
== language_fortran
5474 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
5476 return DW_ORD_row_major
;
5479 switch (cu
->language_defn
->la_array_ordering
)
5481 case array_column_major
:
5482 return DW_ORD_col_major
;
5483 case array_row_major
:
5485 return DW_ORD_row_major
;
5489 /* Extract all information from a DW_TAG_set_type DIE and put it in
5490 the DIE's type field. */
5492 static struct type
*
5493 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5495 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
5497 return set_die_type (die
, set_type
, cu
);
5500 /* First cut: install each common block member as a global variable. */
5503 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
5505 struct die_info
*child_die
;
5506 struct attribute
*attr
;
5508 CORE_ADDR base
= (CORE_ADDR
) 0;
5510 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5513 /* Support the .debug_loc offsets */
5514 if (attr_form_is_block (attr
))
5516 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
5518 else if (attr_form_is_section_offset (attr
))
5520 dwarf2_complex_location_expr_complaint ();
5524 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5525 "common block member");
5528 if (die
->child
!= NULL
)
5530 child_die
= die
->child
;
5531 while (child_die
&& child_die
->tag
)
5533 sym
= new_symbol (child_die
, NULL
, cu
);
5534 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
5537 CORE_ADDR byte_offset
= 0;
5539 if (attr_form_is_section_offset (attr
))
5540 dwarf2_complex_location_expr_complaint ();
5541 else if (attr_form_is_constant (attr
))
5542 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5543 else if (attr_form_is_block (attr
))
5544 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5546 dwarf2_complex_location_expr_complaint ();
5548 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
5549 add_symbol_to_list (sym
, &global_symbols
);
5551 child_die
= sibling_die (child_die
);
5556 /* Create a type for a C++ namespace. */
5558 static struct type
*
5559 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5561 struct objfile
*objfile
= cu
->objfile
;
5562 const char *previous_prefix
, *name
;
5566 /* For extensions, reuse the type of the original namespace. */
5567 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5569 struct die_info
*ext_die
;
5570 struct dwarf2_cu
*ext_cu
= cu
;
5571 ext_die
= dwarf2_extension (die
, &ext_cu
);
5572 type
= read_type_die (ext_die
, ext_cu
);
5573 return set_die_type (die
, type
, cu
);
5576 name
= namespace_name (die
, &is_anonymous
, cu
);
5578 /* Now build the name of the current namespace. */
5580 previous_prefix
= determine_prefix (die
, cu
);
5581 if (previous_prefix
[0] != '\0')
5582 name
= typename_concat (&objfile
->objfile_obstack
,
5583 previous_prefix
, name
, cu
);
5585 /* Create the type. */
5586 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5588 TYPE_NAME (type
) = (char *) name
;
5589 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5591 set_die_type (die
, type
, cu
);
5596 /* Read a C++ namespace. */
5599 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5601 struct objfile
*objfile
= cu
->objfile
;
5605 /* Add a symbol associated to this if we haven't seen the namespace
5606 before. Also, add a using directive if it's an anonymous
5609 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5613 type
= read_type_die (die
, cu
);
5614 new_symbol (die
, type
, cu
);
5616 name
= namespace_name (die
, &is_anonymous
, cu
);
5619 const char *previous_prefix
= determine_prefix (die
, cu
);
5620 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
5621 NULL
, &objfile
->objfile_obstack
);
5625 if (die
->child
!= NULL
)
5627 struct die_info
*child_die
= die
->child
;
5629 while (child_die
&& child_die
->tag
)
5631 process_die (child_die
, cu
);
5632 child_die
= sibling_die (child_die
);
5637 /* Read a Fortran module. */
5640 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5642 struct die_info
*child_die
= die
->child
;
5644 /* FIXME: Support the separate Fortran module namespaces. */
5646 while (child_die
&& child_die
->tag
)
5648 process_die (child_die
, cu
);
5649 child_die
= sibling_die (child_die
);
5653 /* Return the name of the namespace represented by DIE. Set
5654 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5658 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5660 struct die_info
*current_die
;
5661 const char *name
= NULL
;
5663 /* Loop through the extensions until we find a name. */
5665 for (current_die
= die
;
5666 current_die
!= NULL
;
5667 current_die
= dwarf2_extension (die
, &cu
))
5669 name
= dwarf2_name (current_die
, cu
);
5674 /* Is it an anonymous namespace? */
5676 *is_anonymous
= (name
== NULL
);
5678 name
= "(anonymous namespace)";
5683 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5684 the user defined type vector. */
5686 static struct type
*
5687 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5689 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5690 struct comp_unit_head
*cu_header
= &cu
->header
;
5692 struct attribute
*attr_byte_size
;
5693 struct attribute
*attr_address_class
;
5694 int byte_size
, addr_class
;
5696 type
= lookup_pointer_type (die_type (die
, cu
));
5698 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5700 byte_size
= DW_UNSND (attr_byte_size
);
5702 byte_size
= cu_header
->addr_size
;
5704 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5705 if (attr_address_class
)
5706 addr_class
= DW_UNSND (attr_address_class
);
5708 addr_class
= DW_ADDR_none
;
5710 /* If the pointer size or address class is different than the
5711 default, create a type variant marked as such and set the
5712 length accordingly. */
5713 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5715 if (gdbarch_address_class_type_flags_p (gdbarch
))
5719 type_flags
= gdbarch_address_class_type_flags
5720 (gdbarch
, byte_size
, addr_class
);
5721 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5723 type
= make_type_with_address_space (type
, type_flags
);
5725 else if (TYPE_LENGTH (type
) != byte_size
)
5727 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5730 /* Should we also complain about unhandled address classes? */
5734 TYPE_LENGTH (type
) = byte_size
;
5735 return set_die_type (die
, type
, cu
);
5738 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5739 the user defined type vector. */
5741 static struct type
*
5742 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5744 struct objfile
*objfile
= cu
->objfile
;
5746 struct type
*to_type
;
5747 struct type
*domain
;
5749 to_type
= die_type (die
, cu
);
5750 domain
= die_containing_type (die
, cu
);
5752 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5753 type
= lookup_methodptr_type (to_type
);
5755 type
= lookup_memberptr_type (to_type
, domain
);
5757 return set_die_type (die
, type
, cu
);
5760 /* Extract all information from a DW_TAG_reference_type DIE and add to
5761 the user defined type vector. */
5763 static struct type
*
5764 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5766 struct comp_unit_head
*cu_header
= &cu
->header
;
5768 struct attribute
*attr
;
5770 type
= lookup_reference_type (die_type (die
, cu
));
5771 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5774 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5778 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5780 return set_die_type (die
, type
, cu
);
5783 static struct type
*
5784 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5786 struct type
*base_type
, *cv_type
;
5788 base_type
= die_type (die
, cu
);
5789 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5790 return set_die_type (die
, cv_type
, cu
);
5793 static struct type
*
5794 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5796 struct type
*base_type
, *cv_type
;
5798 base_type
= die_type (die
, cu
);
5799 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5800 return set_die_type (die
, cv_type
, cu
);
5803 /* Extract all information from a DW_TAG_string_type DIE and add to
5804 the user defined type vector. It isn't really a user defined type,
5805 but it behaves like one, with other DIE's using an AT_user_def_type
5806 attribute to reference it. */
5808 static struct type
*
5809 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5811 struct objfile
*objfile
= cu
->objfile
;
5812 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5813 struct type
*type
, *range_type
, *index_type
, *char_type
;
5814 struct attribute
*attr
;
5815 unsigned int length
;
5817 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5820 length
= DW_UNSND (attr
);
5824 /* check for the DW_AT_byte_size attribute */
5825 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5828 length
= DW_UNSND (attr
);
5836 index_type
= objfile_type (objfile
)->builtin_int
;
5837 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5838 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5839 type
= create_string_type (NULL
, char_type
, range_type
);
5841 return set_die_type (die
, type
, cu
);
5844 /* Handle DIES due to C code like:
5848 int (*funcp)(int a, long l);
5852 ('funcp' generates a DW_TAG_subroutine_type DIE)
5855 static struct type
*
5856 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5858 struct type
*type
; /* Type that this function returns */
5859 struct type
*ftype
; /* Function that returns above type */
5860 struct attribute
*attr
;
5862 type
= die_type (die
, cu
);
5863 ftype
= lookup_function_type (type
);
5865 /* All functions in C++, Pascal and Java have prototypes. */
5866 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5867 if ((attr
&& (DW_UNSND (attr
) != 0))
5868 || cu
->language
== language_cplus
5869 || cu
->language
== language_java
5870 || cu
->language
== language_pascal
)
5871 TYPE_PROTOTYPED (ftype
) = 1;
5873 /* Store the calling convention in the type if it's available in
5874 the subroutine die. Otherwise set the calling convention to
5875 the default value DW_CC_normal. */
5876 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5877 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5879 /* We need to add the subroutine type to the die immediately so
5880 we don't infinitely recurse when dealing with parameters
5881 declared as the same subroutine type. */
5882 set_die_type (die
, ftype
, cu
);
5884 if (die
->child
!= NULL
)
5886 struct die_info
*child_die
;
5890 /* Count the number of parameters.
5891 FIXME: GDB currently ignores vararg functions, but knows about
5892 vararg member functions. */
5893 child_die
= die
->child
;
5894 while (child_die
&& child_die
->tag
)
5896 if (child_die
->tag
== DW_TAG_formal_parameter
)
5898 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5899 TYPE_VARARGS (ftype
) = 1;
5900 child_die
= sibling_die (child_die
);
5903 /* Allocate storage for parameters and fill them in. */
5904 TYPE_NFIELDS (ftype
) = nparams
;
5905 TYPE_FIELDS (ftype
) = (struct field
*)
5906 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5908 child_die
= die
->child
;
5909 while (child_die
&& child_die
->tag
)
5911 if (child_die
->tag
== DW_TAG_formal_parameter
)
5913 /* Dwarf2 has no clean way to discern C++ static and non-static
5914 member functions. G++ helps GDB by marking the first
5915 parameter for non-static member functions (which is the
5916 this pointer) as artificial. We pass this information
5917 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5918 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5920 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5922 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5923 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5926 child_die
= sibling_die (child_die
);
5933 static struct type
*
5934 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5936 struct objfile
*objfile
= cu
->objfile
;
5937 struct attribute
*attr
;
5938 const char *name
= NULL
;
5939 struct type
*this_type
;
5941 name
= dwarf2_full_name (NULL
, die
, cu
);
5942 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5943 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5944 TYPE_NAME (this_type
) = (char *) name
;
5945 set_die_type (die
, this_type
, cu
);
5946 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5950 /* Find a representation of a given base type and install
5951 it in the TYPE field of the die. */
5953 static struct type
*
5954 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5956 struct objfile
*objfile
= cu
->objfile
;
5958 struct attribute
*attr
;
5959 int encoding
= 0, size
= 0;
5961 enum type_code code
= TYPE_CODE_INT
;
5963 struct type
*target_type
= NULL
;
5965 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5968 encoding
= DW_UNSND (attr
);
5970 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5973 size
= DW_UNSND (attr
);
5975 name
= dwarf2_name (die
, cu
);
5978 complaint (&symfile_complaints
,
5979 _("DW_AT_name missing from DW_TAG_base_type"));
5984 case DW_ATE_address
:
5985 /* Turn DW_ATE_address into a void * pointer. */
5986 code
= TYPE_CODE_PTR
;
5987 type_flags
|= TYPE_FLAG_UNSIGNED
;
5988 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5990 case DW_ATE_boolean
:
5991 code
= TYPE_CODE_BOOL
;
5992 type_flags
|= TYPE_FLAG_UNSIGNED
;
5994 case DW_ATE_complex_float
:
5995 code
= TYPE_CODE_COMPLEX
;
5996 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5998 case DW_ATE_decimal_float
:
5999 code
= TYPE_CODE_DECFLOAT
;
6002 code
= TYPE_CODE_FLT
;
6006 case DW_ATE_unsigned
:
6007 type_flags
|= TYPE_FLAG_UNSIGNED
;
6009 case DW_ATE_signed_char
:
6010 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6011 || cu
->language
== language_pascal
)
6012 code
= TYPE_CODE_CHAR
;
6014 case DW_ATE_unsigned_char
:
6015 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6016 || cu
->language
== language_pascal
)
6017 code
= TYPE_CODE_CHAR
;
6018 type_flags
|= TYPE_FLAG_UNSIGNED
;
6021 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
6022 dwarf_type_encoding_name (encoding
));
6026 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
6027 TYPE_NAME (type
) = name
;
6028 TYPE_TARGET_TYPE (type
) = target_type
;
6030 if (name
&& strcmp (name
, "char") == 0)
6031 TYPE_NOSIGN (type
) = 1;
6033 return set_die_type (die
, type
, cu
);
6036 /* Read the given DW_AT_subrange DIE. */
6038 static struct type
*
6039 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6041 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6042 struct type
*base_type
;
6043 struct type
*range_type
;
6044 struct attribute
*attr
;
6048 LONGEST negative_mask
;
6050 base_type
= die_type (die
, cu
);
6051 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
6053 complaint (&symfile_complaints
,
6054 _("DW_AT_type missing from DW_TAG_subrange_type"));
6056 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
6057 0, NULL
, cu
->objfile
);
6060 if (cu
->language
== language_fortran
)
6062 /* FORTRAN implies a lower bound of 1, if not given. */
6066 /* FIXME: For variable sized arrays either of these could be
6067 a variable rather than a constant value. We'll allow it,
6068 but we don't know how to handle it. */
6069 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
6071 low
= dwarf2_get_attr_constant_value (attr
, 0);
6073 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
6076 if (attr
->form
== DW_FORM_block1
)
6078 /* GCC encodes arrays with unspecified or dynamic length
6079 with a DW_FORM_block1 attribute.
6080 FIXME: GDB does not yet know how to handle dynamic
6081 arrays properly, treat them as arrays with unspecified
6084 FIXME: jimb/2003-09-22: GDB does not really know
6085 how to handle arrays of unspecified length
6086 either; we just represent them as zero-length
6087 arrays. Choose an appropriate upper bound given
6088 the lower bound we've computed above. */
6092 high
= dwarf2_get_attr_constant_value (attr
, 1);
6096 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
6097 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
6098 low
|= negative_mask
;
6099 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
6100 high
|= negative_mask
;
6102 range_type
= create_range_type (NULL
, base_type
, low
, high
);
6104 /* Mark arrays with dynamic length at least as an array of unspecified
6105 length. GDB could check the boundary but before it gets implemented at
6106 least allow accessing the array elements. */
6107 if (attr
&& attr
->form
== DW_FORM_block1
)
6108 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
6110 name
= dwarf2_name (die
, cu
);
6112 TYPE_NAME (range_type
) = name
;
6114 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6116 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
6118 set_descriptive_type (range_type
, die
, cu
);
6120 return set_die_type (die
, range_type
, cu
);
6123 static struct type
*
6124 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6128 /* For now, we only support the C meaning of an unspecified type: void. */
6130 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
6131 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
6133 return set_die_type (die
, type
, cu
);
6136 /* Trivial hash function for die_info: the hash value of a DIE
6137 is its offset in .debug_info for this objfile. */
6140 die_hash (const void *item
)
6142 const struct die_info
*die
= item
;
6146 /* Trivial comparison function for die_info structures: two DIEs
6147 are equal if they have the same offset. */
6150 die_eq (const void *item_lhs
, const void *item_rhs
)
6152 const struct die_info
*die_lhs
= item_lhs
;
6153 const struct die_info
*die_rhs
= item_rhs
;
6154 return die_lhs
->offset
== die_rhs
->offset
;
6157 /* Read a whole compilation unit into a linked list of dies. */
6159 static struct die_info
*
6160 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6162 struct die_reader_specs reader_specs
;
6164 gdb_assert (cu
->die_hash
== NULL
);
6166 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6170 &cu
->comp_unit_obstack
,
6171 hashtab_obstack_allocate
,
6172 dummy_obstack_deallocate
);
6174 init_cu_die_reader (&reader_specs
, cu
);
6176 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
6179 /* Main entry point for reading a DIE and all children.
6180 Read the DIE and dump it if requested. */
6182 static struct die_info
*
6183 read_die_and_children (const struct die_reader_specs
*reader
,
6185 gdb_byte
**new_info_ptr
,
6186 struct die_info
*parent
)
6188 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
6189 new_info_ptr
, parent
);
6191 if (dwarf2_die_debug
)
6193 fprintf_unfiltered (gdb_stdlog
,
6194 "\nRead die from %s of %s:\n",
6195 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
6197 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
6199 : "unknown section",
6200 reader
->abfd
->filename
);
6201 dump_die (result
, dwarf2_die_debug
);
6207 /* Read a single die and all its descendents. Set the die's sibling
6208 field to NULL; set other fields in the die correctly, and set all
6209 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6210 location of the info_ptr after reading all of those dies. PARENT
6211 is the parent of the die in question. */
6213 static struct die_info
*
6214 read_die_and_children_1 (const struct die_reader_specs
*reader
,
6216 gdb_byte
**new_info_ptr
,
6217 struct die_info
*parent
)
6219 struct die_info
*die
;
6223 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
6226 *new_info_ptr
= cur_ptr
;
6229 store_in_ref_table (die
, reader
->cu
);
6232 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
6236 *new_info_ptr
= cur_ptr
;
6239 die
->sibling
= NULL
;
6240 die
->parent
= parent
;
6244 /* Read a die, all of its descendents, and all of its siblings; set
6245 all of the fields of all of the dies correctly. Arguments are as
6246 in read_die_and_children. */
6248 static struct die_info
*
6249 read_die_and_siblings (const struct die_reader_specs
*reader
,
6251 gdb_byte
**new_info_ptr
,
6252 struct die_info
*parent
)
6254 struct die_info
*first_die
, *last_sibling
;
6258 first_die
= last_sibling
= NULL
;
6262 struct die_info
*die
6263 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
6267 *new_info_ptr
= cur_ptr
;
6274 last_sibling
->sibling
= die
;
6280 /* Read the die from the .debug_info section buffer. Set DIEP to
6281 point to a newly allocated die with its information, except for its
6282 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6283 whether the die has children or not. */
6286 read_full_die (const struct die_reader_specs
*reader
,
6287 struct die_info
**diep
, gdb_byte
*info_ptr
,
6290 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6291 struct abbrev_info
*abbrev
;
6292 struct die_info
*die
;
6293 struct dwarf2_cu
*cu
= reader
->cu
;
6294 bfd
*abfd
= reader
->abfd
;
6296 offset
= info_ptr
- reader
->buffer
;
6297 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6298 info_ptr
+= bytes_read
;
6306 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6308 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6310 bfd_get_filename (abfd
));
6312 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6313 die
->offset
= offset
;
6314 die
->tag
= abbrev
->tag
;
6315 die
->abbrev
= abbrev_number
;
6317 die
->num_attrs
= abbrev
->num_attrs
;
6319 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6320 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6321 abfd
, info_ptr
, cu
);
6324 *has_children
= abbrev
->has_children
;
6328 /* In DWARF version 2, the description of the debugging information is
6329 stored in a separate .debug_abbrev section. Before we read any
6330 dies from a section we read in all abbreviations and install them
6331 in a hash table. This function also sets flags in CU describing
6332 the data found in the abbrev table. */
6335 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
6337 struct comp_unit_head
*cu_header
= &cu
->header
;
6338 gdb_byte
*abbrev_ptr
;
6339 struct abbrev_info
*cur_abbrev
;
6340 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
6341 unsigned int abbrev_form
, hash_number
;
6342 struct attr_abbrev
*cur_attrs
;
6343 unsigned int allocated_attrs
;
6345 /* Initialize dwarf2 abbrevs */
6346 obstack_init (&cu
->abbrev_obstack
);
6347 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
6349 * sizeof (struct abbrev_info
*)));
6350 memset (cu
->dwarf2_abbrevs
, 0,
6351 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
6353 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
6354 &dwarf2_per_objfile
->abbrev
);
6355 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
6356 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6357 abbrev_ptr
+= bytes_read
;
6359 allocated_attrs
= ATTR_ALLOC_CHUNK
;
6360 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
6362 /* loop until we reach an abbrev number of 0 */
6363 while (abbrev_number
)
6365 cur_abbrev
= dwarf_alloc_abbrev (cu
);
6367 /* read in abbrev header */
6368 cur_abbrev
->number
= abbrev_number
;
6369 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6370 abbrev_ptr
+= bytes_read
;
6371 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
6374 if (cur_abbrev
->tag
== DW_TAG_namespace
)
6375 cu
->has_namespace_info
= 1;
6377 /* now read in declarations */
6378 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6379 abbrev_ptr
+= bytes_read
;
6380 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6381 abbrev_ptr
+= bytes_read
;
6384 if (cur_abbrev
->num_attrs
== allocated_attrs
)
6386 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
6388 = xrealloc (cur_attrs
, (allocated_attrs
6389 * sizeof (struct attr_abbrev
)));
6392 /* Record whether this compilation unit might have
6393 inter-compilation-unit references. If we don't know what form
6394 this attribute will have, then it might potentially be a
6395 DW_FORM_ref_addr, so we conservatively expect inter-CU
6398 if (abbrev_form
== DW_FORM_ref_addr
6399 || abbrev_form
== DW_FORM_indirect
)
6400 cu
->has_form_ref_addr
= 1;
6402 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
6403 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
6404 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6405 abbrev_ptr
+= bytes_read
;
6406 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6407 abbrev_ptr
+= bytes_read
;
6410 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
6411 (cur_abbrev
->num_attrs
6412 * sizeof (struct attr_abbrev
)));
6413 memcpy (cur_abbrev
->attrs
, cur_attrs
,
6414 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
6416 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
6417 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
6418 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
6420 /* Get next abbreviation.
6421 Under Irix6 the abbreviations for a compilation unit are not
6422 always properly terminated with an abbrev number of 0.
6423 Exit loop if we encounter an abbreviation which we have
6424 already read (which means we are about to read the abbreviations
6425 for the next compile unit) or if the end of the abbreviation
6426 table is reached. */
6427 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
6428 >= dwarf2_per_objfile
->abbrev
.size
)
6430 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6431 abbrev_ptr
+= bytes_read
;
6432 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
6439 /* Release the memory used by the abbrev table for a compilation unit. */
6442 dwarf2_free_abbrev_table (void *ptr_to_cu
)
6444 struct dwarf2_cu
*cu
= ptr_to_cu
;
6446 obstack_free (&cu
->abbrev_obstack
, NULL
);
6447 cu
->dwarf2_abbrevs
= NULL
;
6450 /* Lookup an abbrev_info structure in the abbrev hash table. */
6452 static struct abbrev_info
*
6453 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
6455 unsigned int hash_number
;
6456 struct abbrev_info
*abbrev
;
6458 hash_number
= number
% ABBREV_HASH_SIZE
;
6459 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
6463 if (abbrev
->number
== number
)
6466 abbrev
= abbrev
->next
;
6471 /* Returns nonzero if TAG represents a type that we might generate a partial
6475 is_type_tag_for_partial (int tag
)
6480 /* Some types that would be reasonable to generate partial symbols for,
6481 that we don't at present. */
6482 case DW_TAG_array_type
:
6483 case DW_TAG_file_type
:
6484 case DW_TAG_ptr_to_member_type
:
6485 case DW_TAG_set_type
:
6486 case DW_TAG_string_type
:
6487 case DW_TAG_subroutine_type
:
6489 case DW_TAG_base_type
:
6490 case DW_TAG_class_type
:
6491 case DW_TAG_interface_type
:
6492 case DW_TAG_enumeration_type
:
6493 case DW_TAG_structure_type
:
6494 case DW_TAG_subrange_type
:
6495 case DW_TAG_typedef
:
6496 case DW_TAG_union_type
:
6503 /* Load all DIEs that are interesting for partial symbols into memory. */
6505 static struct partial_die_info
*
6506 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6507 int building_psymtab
, struct dwarf2_cu
*cu
)
6509 struct partial_die_info
*part_die
;
6510 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
6511 struct abbrev_info
*abbrev
;
6512 unsigned int bytes_read
;
6513 unsigned int load_all
= 0;
6515 int nesting_level
= 1;
6520 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
6524 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6528 &cu
->comp_unit_obstack
,
6529 hashtab_obstack_allocate
,
6530 dummy_obstack_deallocate
);
6532 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6533 sizeof (struct partial_die_info
));
6537 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6539 /* A NULL abbrev means the end of a series of children. */
6542 if (--nesting_level
== 0)
6544 /* PART_DIE was probably the last thing allocated on the
6545 comp_unit_obstack, so we could call obstack_free
6546 here. We don't do that because the waste is small,
6547 and will be cleaned up when we're done with this
6548 compilation unit. This way, we're also more robust
6549 against other users of the comp_unit_obstack. */
6552 info_ptr
+= bytes_read
;
6553 last_die
= parent_die
;
6554 parent_die
= parent_die
->die_parent
;
6558 /* Check whether this DIE is interesting enough to save. Normally
6559 we would not be interested in members here, but there may be
6560 later variables referencing them via DW_AT_specification (for
6563 && !is_type_tag_for_partial (abbrev
->tag
)
6564 && abbrev
->tag
!= DW_TAG_enumerator
6565 && abbrev
->tag
!= DW_TAG_subprogram
6566 && abbrev
->tag
!= DW_TAG_lexical_block
6567 && abbrev
->tag
!= DW_TAG_variable
6568 && abbrev
->tag
!= DW_TAG_namespace
6569 && abbrev
->tag
!= DW_TAG_member
)
6571 /* Otherwise we skip to the next sibling, if any. */
6572 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
6576 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
6577 buffer
, info_ptr
, cu
);
6579 /* This two-pass algorithm for processing partial symbols has a
6580 high cost in cache pressure. Thus, handle some simple cases
6581 here which cover the majority of C partial symbols. DIEs
6582 which neither have specification tags in them, nor could have
6583 specification tags elsewhere pointing at them, can simply be
6584 processed and discarded.
6586 This segment is also optional; scan_partial_symbols and
6587 add_partial_symbol will handle these DIEs if we chain
6588 them in normally. When compilers which do not emit large
6589 quantities of duplicate debug information are more common,
6590 this code can probably be removed. */
6592 /* Any complete simple types at the top level (pretty much all
6593 of them, for a language without namespaces), can be processed
6595 if (parent_die
== NULL
6596 && part_die
->has_specification
== 0
6597 && part_die
->is_declaration
== 0
6598 && (part_die
->tag
== DW_TAG_typedef
6599 || part_die
->tag
== DW_TAG_base_type
6600 || part_die
->tag
== DW_TAG_subrange_type
))
6602 if (building_psymtab
&& part_die
->name
!= NULL
)
6603 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6604 VAR_DOMAIN
, LOC_TYPEDEF
,
6605 &cu
->objfile
->static_psymbols
,
6606 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6607 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6611 /* If we're at the second level, and we're an enumerator, and
6612 our parent has no specification (meaning possibly lives in a
6613 namespace elsewhere), then we can add the partial symbol now
6614 instead of queueing it. */
6615 if (part_die
->tag
== DW_TAG_enumerator
6616 && parent_die
!= NULL
6617 && parent_die
->die_parent
== NULL
6618 && parent_die
->tag
== DW_TAG_enumeration_type
6619 && parent_die
->has_specification
== 0)
6621 if (part_die
->name
== NULL
)
6622 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6623 else if (building_psymtab
)
6624 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6625 VAR_DOMAIN
, LOC_CONST
,
6626 (cu
->language
== language_cplus
6627 || cu
->language
== language_java
)
6628 ? &cu
->objfile
->global_psymbols
6629 : &cu
->objfile
->static_psymbols
,
6630 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6632 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6636 /* We'll save this DIE so link it in. */
6637 part_die
->die_parent
= parent_die
;
6638 part_die
->die_sibling
= NULL
;
6639 part_die
->die_child
= NULL
;
6641 if (last_die
&& last_die
== parent_die
)
6642 last_die
->die_child
= part_die
;
6644 last_die
->die_sibling
= part_die
;
6646 last_die
= part_die
;
6648 if (first_die
== NULL
)
6649 first_die
= part_die
;
6651 /* Maybe add the DIE to the hash table. Not all DIEs that we
6652 find interesting need to be in the hash table, because we
6653 also have the parent/sibling/child chains; only those that we
6654 might refer to by offset later during partial symbol reading.
6656 For now this means things that might have be the target of a
6657 DW_AT_specification, DW_AT_abstract_origin, or
6658 DW_AT_extension. DW_AT_extension will refer only to
6659 namespaces; DW_AT_abstract_origin refers to functions (and
6660 many things under the function DIE, but we do not recurse
6661 into function DIEs during partial symbol reading) and
6662 possibly variables as well; DW_AT_specification refers to
6663 declarations. Declarations ought to have the DW_AT_declaration
6664 flag. It happens that GCC forgets to put it in sometimes, but
6665 only for functions, not for types.
6667 Adding more things than necessary to the hash table is harmless
6668 except for the performance cost. Adding too few will result in
6669 wasted time in find_partial_die, when we reread the compilation
6670 unit with load_all_dies set. */
6673 || abbrev
->tag
== DW_TAG_subprogram
6674 || abbrev
->tag
== DW_TAG_variable
6675 || abbrev
->tag
== DW_TAG_namespace
6676 || part_die
->is_declaration
)
6680 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6681 part_die
->offset
, INSERT
);
6685 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6686 sizeof (struct partial_die_info
));
6688 /* For some DIEs we want to follow their children (if any). For C
6689 we have no reason to follow the children of structures; for other
6690 languages we have to, both so that we can get at method physnames
6691 to infer fully qualified class names, and for DW_AT_specification.
6693 For Ada, we need to scan the children of subprograms and lexical
6694 blocks as well because Ada allows the definition of nested
6695 entities that could be interesting for the debugger, such as
6696 nested subprograms for instance. */
6697 if (last_die
->has_children
6699 || last_die
->tag
== DW_TAG_namespace
6700 || last_die
->tag
== DW_TAG_enumeration_type
6701 || (cu
->language
!= language_c
6702 && (last_die
->tag
== DW_TAG_class_type
6703 || last_die
->tag
== DW_TAG_interface_type
6704 || last_die
->tag
== DW_TAG_structure_type
6705 || last_die
->tag
== DW_TAG_union_type
))
6706 || (cu
->language
== language_ada
6707 && (last_die
->tag
== DW_TAG_subprogram
6708 || last_die
->tag
== DW_TAG_lexical_block
))))
6711 parent_die
= last_die
;
6715 /* Otherwise we skip to the next sibling, if any. */
6716 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
6718 /* Back to the top, do it again. */
6722 /* Read a minimal amount of information into the minimal die structure. */
6725 read_partial_die (struct partial_die_info
*part_die
,
6726 struct abbrev_info
*abbrev
,
6727 unsigned int abbrev_len
, bfd
*abfd
,
6728 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6729 struct dwarf2_cu
*cu
)
6731 unsigned int bytes_read
, i
;
6732 struct attribute attr
;
6733 int has_low_pc_attr
= 0;
6734 int has_high_pc_attr
= 0;
6736 memset (part_die
, 0, sizeof (struct partial_die_info
));
6738 part_die
->offset
= info_ptr
- buffer
;
6740 info_ptr
+= abbrev_len
;
6745 part_die
->tag
= abbrev
->tag
;
6746 part_die
->has_children
= abbrev
->has_children
;
6748 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6750 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6752 /* Store the data if it is of an attribute we want to keep in a
6753 partial symbol table. */
6757 switch (part_die
->tag
)
6759 case DW_TAG_compile_unit
:
6760 case DW_TAG_type_unit
:
6761 /* Compilation units have a DW_AT_name that is a filename, not
6762 a source language identifier. */
6763 case DW_TAG_enumeration_type
:
6764 case DW_TAG_enumerator
:
6765 /* These tags always have simple identifiers already; no need
6766 to canonicalize them. */
6767 part_die
->name
= DW_STRING (&attr
);
6771 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6772 &cu
->objfile
->objfile_obstack
);
6776 case DW_AT_MIPS_linkage_name
:
6777 if (cu
->language
== language_ada
)
6778 part_die
->name
= DW_STRING (&attr
);
6781 has_low_pc_attr
= 1;
6782 part_die
->lowpc
= DW_ADDR (&attr
);
6785 has_high_pc_attr
= 1;
6786 part_die
->highpc
= DW_ADDR (&attr
);
6788 case DW_AT_location
:
6789 /* Support the .debug_loc offsets */
6790 if (attr_form_is_block (&attr
))
6792 part_die
->locdesc
= DW_BLOCK (&attr
);
6794 else if (attr_form_is_section_offset (&attr
))
6796 dwarf2_complex_location_expr_complaint ();
6800 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6801 "partial symbol information");
6804 case DW_AT_external
:
6805 part_die
->is_external
= DW_UNSND (&attr
);
6807 case DW_AT_declaration
:
6808 part_die
->is_declaration
= DW_UNSND (&attr
);
6811 part_die
->has_type
= 1;
6813 case DW_AT_abstract_origin
:
6814 case DW_AT_specification
:
6815 case DW_AT_extension
:
6816 part_die
->has_specification
= 1;
6817 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6820 /* Ignore absolute siblings, they might point outside of
6821 the current compile unit. */
6822 if (attr
.form
== DW_FORM_ref_addr
)
6823 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6825 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
6827 case DW_AT_byte_size
:
6828 part_die
->has_byte_size
= 1;
6830 case DW_AT_calling_convention
:
6831 /* DWARF doesn't provide a way to identify a program's source-level
6832 entry point. DW_AT_calling_convention attributes are only meant
6833 to describe functions' calling conventions.
6835 However, because it's a necessary piece of information in
6836 Fortran, and because DW_CC_program is the only piece of debugging
6837 information whose definition refers to a 'main program' at all,
6838 several compilers have begun marking Fortran main programs with
6839 DW_CC_program --- even when those functions use the standard
6840 calling conventions.
6842 So until DWARF specifies a way to provide this information and
6843 compilers pick up the new representation, we'll support this
6845 if (DW_UNSND (&attr
) == DW_CC_program
6846 && cu
->language
== language_fortran
)
6847 set_main_name (part_die
->name
);
6854 /* When using the GNU linker, .gnu.linkonce. sections are used to
6855 eliminate duplicate copies of functions and vtables and such.
6856 The linker will arbitrarily choose one and discard the others.
6857 The AT_*_pc values for such functions refer to local labels in
6858 these sections. If the section from that file was discarded, the
6859 labels are not in the output, so the relocs get a value of 0.
6860 If this is a discarded function, mark the pc bounds as invalid,
6861 so that GDB will ignore it. */
6862 if (has_low_pc_attr
&& has_high_pc_attr
6863 && part_die
->lowpc
< part_die
->highpc
6864 && (part_die
->lowpc
!= 0
6865 || dwarf2_per_objfile
->has_section_at_zero
))
6866 part_die
->has_pc_info
= 1;
6871 /* Find a cached partial DIE at OFFSET in CU. */
6873 static struct partial_die_info
*
6874 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6876 struct partial_die_info
*lookup_die
= NULL
;
6877 struct partial_die_info part_die
;
6879 part_die
.offset
= offset
;
6880 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6885 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6886 except in the case of .debug_types DIEs which do not reference
6887 outside their CU (they do however referencing other types via
6890 static struct partial_die_info
*
6891 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6893 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6894 struct partial_die_info
*pd
= NULL
;
6896 if (cu
->per_cu
->from_debug_types
)
6898 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6904 if (offset_in_cu_p (&cu
->header
, offset
))
6906 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6911 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6913 if (per_cu
->cu
== NULL
)
6915 load_partial_comp_unit (per_cu
, cu
->objfile
);
6916 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6917 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6920 per_cu
->cu
->last_used
= 0;
6921 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6923 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6925 struct cleanup
*back_to
;
6926 struct partial_die_info comp_unit_die
;
6927 struct abbrev_info
*abbrev
;
6928 unsigned int bytes_read
;
6931 per_cu
->load_all_dies
= 1;
6933 /* Re-read the DIEs. */
6934 back_to
= make_cleanup (null_cleanup
, 0);
6935 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6937 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6938 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6940 info_ptr
= (dwarf2_per_objfile
->info
.buffer
6941 + per_cu
->cu
->header
.offset
6942 + per_cu
->cu
->header
.first_die_offset
);
6943 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6944 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6945 per_cu
->cu
->objfile
->obfd
,
6946 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6948 if (comp_unit_die
.has_children
)
6949 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
6950 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6952 do_cleanups (back_to
);
6954 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6960 internal_error (__FILE__
, __LINE__
,
6961 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6962 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6966 /* Adjust PART_DIE before generating a symbol for it. This function
6967 may set the is_external flag or change the DIE's name. */
6970 fixup_partial_die (struct partial_die_info
*part_die
,
6971 struct dwarf2_cu
*cu
)
6973 /* If we found a reference attribute and the DIE has no name, try
6974 to find a name in the referred to DIE. */
6976 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6978 struct partial_die_info
*spec_die
;
6980 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6982 fixup_partial_die (spec_die
, cu
);
6986 part_die
->name
= spec_die
->name
;
6988 /* Copy DW_AT_external attribute if it is set. */
6989 if (spec_die
->is_external
)
6990 part_die
->is_external
= spec_die
->is_external
;
6994 /* Set default names for some unnamed DIEs. */
6995 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6996 || part_die
->tag
== DW_TAG_class_type
))
6997 part_die
->name
= "(anonymous class)";
6999 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
7000 part_die
->name
= "(anonymous namespace)";
7002 if (part_die
->tag
== DW_TAG_structure_type
7003 || part_die
->tag
== DW_TAG_class_type
7004 || part_die
->tag
== DW_TAG_union_type
)
7005 guess_structure_name (part_die
, cu
);
7008 /* Read an attribute value described by an attribute form. */
7011 read_attribute_value (struct attribute
*attr
, unsigned form
,
7012 bfd
*abfd
, gdb_byte
*info_ptr
,
7013 struct dwarf2_cu
*cu
)
7015 struct comp_unit_head
*cu_header
= &cu
->header
;
7016 unsigned int bytes_read
;
7017 struct dwarf_block
*blk
;
7022 case DW_FORM_ref_addr
:
7023 if (cu
->header
.version
== 2)
7024 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7026 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
7027 info_ptr
+= bytes_read
;
7030 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7031 info_ptr
+= bytes_read
;
7033 case DW_FORM_block2
:
7034 blk
= dwarf_alloc_block (cu
);
7035 blk
->size
= read_2_bytes (abfd
, info_ptr
);
7037 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7038 info_ptr
+= blk
->size
;
7039 DW_BLOCK (attr
) = blk
;
7041 case DW_FORM_block4
:
7042 blk
= dwarf_alloc_block (cu
);
7043 blk
->size
= read_4_bytes (abfd
, info_ptr
);
7045 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7046 info_ptr
+= blk
->size
;
7047 DW_BLOCK (attr
) = blk
;
7050 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
7054 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
7058 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
7061 case DW_FORM_string
:
7062 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
7063 DW_STRING_IS_CANONICAL (attr
) = 0;
7064 info_ptr
+= bytes_read
;
7067 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
7069 DW_STRING_IS_CANONICAL (attr
) = 0;
7070 info_ptr
+= bytes_read
;
7073 blk
= dwarf_alloc_block (cu
);
7074 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7075 info_ptr
+= bytes_read
;
7076 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7077 info_ptr
+= blk
->size
;
7078 DW_BLOCK (attr
) = blk
;
7080 case DW_FORM_block1
:
7081 blk
= dwarf_alloc_block (cu
);
7082 blk
->size
= read_1_byte (abfd
, info_ptr
);
7084 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7085 info_ptr
+= blk
->size
;
7086 DW_BLOCK (attr
) = blk
;
7089 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7093 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7097 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
7098 info_ptr
+= bytes_read
;
7101 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7102 info_ptr
+= bytes_read
;
7105 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
7109 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
7113 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
7117 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
7121 /* Convert the signature to something we can record in DW_UNSND
7123 NOTE: This is NULL if the type wasn't found. */
7124 DW_SIGNATURED_TYPE (attr
) =
7125 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
7128 case DW_FORM_ref_udata
:
7129 DW_ADDR (attr
) = (cu
->header
.offset
7130 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
7131 info_ptr
+= bytes_read
;
7133 case DW_FORM_indirect
:
7134 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7135 info_ptr
+= bytes_read
;
7136 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
7139 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7140 dwarf_form_name (form
),
7141 bfd_get_filename (abfd
));
7144 /* We have seen instances where the compiler tried to emit a byte
7145 size attribute of -1 which ended up being encoded as an unsigned
7146 0xffffffff. Although 0xffffffff is technically a valid size value,
7147 an object of this size seems pretty unlikely so we can relatively
7148 safely treat these cases as if the size attribute was invalid and
7149 treat them as zero by default. */
7150 if (attr
->name
== DW_AT_byte_size
7151 && form
== DW_FORM_data4
7152 && DW_UNSND (attr
) >= 0xffffffff)
7155 (&symfile_complaints
,
7156 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7157 hex_string (DW_UNSND (attr
)));
7158 DW_UNSND (attr
) = 0;
7164 /* Read an attribute described by an abbreviated attribute. */
7167 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
7168 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7170 attr
->name
= abbrev
->name
;
7171 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
7174 /* read dwarf information from a buffer */
7177 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
7179 return bfd_get_8 (abfd
, buf
);
7183 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
7185 return bfd_get_signed_8 (abfd
, buf
);
7189 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
7191 return bfd_get_16 (abfd
, buf
);
7195 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7197 return bfd_get_signed_16 (abfd
, buf
);
7201 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
7203 return bfd_get_32 (abfd
, buf
);
7207 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7209 return bfd_get_signed_32 (abfd
, buf
);
7213 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
7215 return bfd_get_64 (abfd
, buf
);
7219 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
7220 unsigned int *bytes_read
)
7222 struct comp_unit_head
*cu_header
= &cu
->header
;
7223 CORE_ADDR retval
= 0;
7225 if (cu_header
->signed_addr_p
)
7227 switch (cu_header
->addr_size
)
7230 retval
= bfd_get_signed_16 (abfd
, buf
);
7233 retval
= bfd_get_signed_32 (abfd
, buf
);
7236 retval
= bfd_get_signed_64 (abfd
, buf
);
7239 internal_error (__FILE__
, __LINE__
,
7240 _("read_address: bad switch, signed [in module %s]"),
7241 bfd_get_filename (abfd
));
7246 switch (cu_header
->addr_size
)
7249 retval
= bfd_get_16 (abfd
, buf
);
7252 retval
= bfd_get_32 (abfd
, buf
);
7255 retval
= bfd_get_64 (abfd
, buf
);
7258 internal_error (__FILE__
, __LINE__
,
7259 _("read_address: bad switch, unsigned [in module %s]"),
7260 bfd_get_filename (abfd
));
7264 *bytes_read
= cu_header
->addr_size
;
7268 /* Read the initial length from a section. The (draft) DWARF 3
7269 specification allows the initial length to take up either 4 bytes
7270 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7271 bytes describe the length and all offsets will be 8 bytes in length
7274 An older, non-standard 64-bit format is also handled by this
7275 function. The older format in question stores the initial length
7276 as an 8-byte quantity without an escape value. Lengths greater
7277 than 2^32 aren't very common which means that the initial 4 bytes
7278 is almost always zero. Since a length value of zero doesn't make
7279 sense for the 32-bit format, this initial zero can be considered to
7280 be an escape value which indicates the presence of the older 64-bit
7281 format. As written, the code can't detect (old format) lengths
7282 greater than 4GB. If it becomes necessary to handle lengths
7283 somewhat larger than 4GB, we could allow other small values (such
7284 as the non-sensical values of 1, 2, and 3) to also be used as
7285 escape values indicating the presence of the old format.
7287 The value returned via bytes_read should be used to increment the
7288 relevant pointer after calling read_initial_length().
7290 [ Note: read_initial_length() and read_offset() are based on the
7291 document entitled "DWARF Debugging Information Format", revision
7292 3, draft 8, dated November 19, 2001. This document was obtained
7295 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7297 This document is only a draft and is subject to change. (So beware.)
7299 Details regarding the older, non-standard 64-bit format were
7300 determined empirically by examining 64-bit ELF files produced by
7301 the SGI toolchain on an IRIX 6.5 machine.
7303 - Kevin, July 16, 2002
7307 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
7309 LONGEST length
= bfd_get_32 (abfd
, buf
);
7311 if (length
== 0xffffffff)
7313 length
= bfd_get_64 (abfd
, buf
+ 4);
7316 else if (length
== 0)
7318 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7319 length
= bfd_get_64 (abfd
, buf
);
7330 /* Cover function for read_initial_length.
7331 Returns the length of the object at BUF, and stores the size of the
7332 initial length in *BYTES_READ and stores the size that offsets will be in
7334 If the initial length size is not equivalent to that specified in
7335 CU_HEADER then issue a complaint.
7336 This is useful when reading non-comp-unit headers. */
7339 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
7340 const struct comp_unit_head
*cu_header
,
7341 unsigned int *bytes_read
,
7342 unsigned int *offset_size
)
7344 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
7346 gdb_assert (cu_header
->initial_length_size
== 4
7347 || cu_header
->initial_length_size
== 8
7348 || cu_header
->initial_length_size
== 12);
7350 if (cu_header
->initial_length_size
!= *bytes_read
)
7351 complaint (&symfile_complaints
,
7352 _("intermixed 32-bit and 64-bit DWARF sections"));
7354 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
7358 /* Read an offset from the data stream. The size of the offset is
7359 given by cu_header->offset_size. */
7362 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
7363 unsigned int *bytes_read
)
7365 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
7366 *bytes_read
= cu_header
->offset_size
;
7370 /* Read an offset from the data stream. */
7373 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
7377 switch (offset_size
)
7380 retval
= bfd_get_32 (abfd
, buf
);
7383 retval
= bfd_get_64 (abfd
, buf
);
7386 internal_error (__FILE__
, __LINE__
,
7387 _("read_offset_1: bad switch [in module %s]"),
7388 bfd_get_filename (abfd
));
7395 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
7397 /* If the size of a host char is 8 bits, we can return a pointer
7398 to the buffer, otherwise we have to copy the data to a buffer
7399 allocated on the temporary obstack. */
7400 gdb_assert (HOST_CHAR_BIT
== 8);
7405 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7407 /* If the size of a host char is 8 bits, we can return a pointer
7408 to the string, otherwise we have to copy the string to a buffer
7409 allocated on the temporary obstack. */
7410 gdb_assert (HOST_CHAR_BIT
== 8);
7413 *bytes_read_ptr
= 1;
7416 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
7417 return (char *) buf
;
7421 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
7422 const struct comp_unit_head
*cu_header
,
7423 unsigned int *bytes_read_ptr
)
7425 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
7427 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
7428 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
7430 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7431 bfd_get_filename (abfd
));
7434 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
7436 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7437 bfd_get_filename (abfd
));
7440 gdb_assert (HOST_CHAR_BIT
== 8);
7441 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
7443 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
7446 static unsigned long
7447 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7449 unsigned long result
;
7450 unsigned int num_read
;
7460 byte
= bfd_get_8 (abfd
, buf
);
7463 result
|= ((unsigned long)(byte
& 127) << shift
);
7464 if ((byte
& 128) == 0)
7470 *bytes_read_ptr
= num_read
;
7475 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7478 int i
, shift
, num_read
;
7487 byte
= bfd_get_8 (abfd
, buf
);
7490 result
|= ((long)(byte
& 127) << shift
);
7492 if ((byte
& 128) == 0)
7497 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
7498 result
|= -(((long)1) << shift
);
7499 *bytes_read_ptr
= num_read
;
7503 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7506 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
7512 byte
= bfd_get_8 (abfd
, buf
);
7514 if ((byte
& 128) == 0)
7520 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
7527 cu
->language
= language_c
;
7529 case DW_LANG_C_plus_plus
:
7530 cu
->language
= language_cplus
;
7532 case DW_LANG_Fortran77
:
7533 case DW_LANG_Fortran90
:
7534 case DW_LANG_Fortran95
:
7535 cu
->language
= language_fortran
;
7537 case DW_LANG_Mips_Assembler
:
7538 cu
->language
= language_asm
;
7541 cu
->language
= language_java
;
7545 cu
->language
= language_ada
;
7547 case DW_LANG_Modula2
:
7548 cu
->language
= language_m2
;
7550 case DW_LANG_Pascal83
:
7551 cu
->language
= language_pascal
;
7554 cu
->language
= language_objc
;
7556 case DW_LANG_Cobol74
:
7557 case DW_LANG_Cobol85
:
7559 cu
->language
= language_minimal
;
7562 cu
->language_defn
= language_def (cu
->language
);
7565 /* Return the named attribute or NULL if not there. */
7567 static struct attribute
*
7568 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
7571 struct attribute
*spec
= NULL
;
7573 for (i
= 0; i
< die
->num_attrs
; ++i
)
7575 if (die
->attrs
[i
].name
== name
)
7576 return &die
->attrs
[i
];
7577 if (die
->attrs
[i
].name
== DW_AT_specification
7578 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
7579 spec
= &die
->attrs
[i
];
7584 die
= follow_die_ref (die
, spec
, &cu
);
7585 return dwarf2_attr (die
, name
, cu
);
7591 /* Return the named attribute or NULL if not there,
7592 but do not follow DW_AT_specification, etc.
7593 This is for use in contexts where we're reading .debug_types dies.
7594 Following DW_AT_specification, DW_AT_abstract_origin will take us
7595 back up the chain, and we want to go down. */
7597 static struct attribute
*
7598 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
7599 struct dwarf2_cu
*cu
)
7603 for (i
= 0; i
< die
->num_attrs
; ++i
)
7604 if (die
->attrs
[i
].name
== name
)
7605 return &die
->attrs
[i
];
7610 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7611 and holds a non-zero value. This function should only be used for
7612 DW_FORM_flag attributes. */
7615 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7617 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7619 return (attr
&& DW_UNSND (attr
));
7623 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7625 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7626 which value is non-zero. However, we have to be careful with
7627 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7628 (via dwarf2_flag_true_p) follows this attribute. So we may
7629 end up accidently finding a declaration attribute that belongs
7630 to a different DIE referenced by the specification attribute,
7631 even though the given DIE does not have a declaration attribute. */
7632 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7633 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7636 /* Return the die giving the specification for DIE, if there is
7637 one. *SPEC_CU is the CU containing DIE on input, and the CU
7638 containing the return value on output. If there is no
7639 specification, but there is an abstract origin, that is
7642 static struct die_info
*
7643 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7645 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7648 if (spec_attr
== NULL
)
7649 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7651 if (spec_attr
== NULL
)
7654 return follow_die_ref (die
, spec_attr
, spec_cu
);
7657 /* Free the line_header structure *LH, and any arrays and strings it
7660 free_line_header (struct line_header
*lh
)
7662 if (lh
->standard_opcode_lengths
)
7663 xfree (lh
->standard_opcode_lengths
);
7665 /* Remember that all the lh->file_names[i].name pointers are
7666 pointers into debug_line_buffer, and don't need to be freed. */
7668 xfree (lh
->file_names
);
7670 /* Similarly for the include directory names. */
7671 if (lh
->include_dirs
)
7672 xfree (lh
->include_dirs
);
7678 /* Add an entry to LH's include directory table. */
7680 add_include_dir (struct line_header
*lh
, char *include_dir
)
7682 /* Grow the array if necessary. */
7683 if (lh
->include_dirs_size
== 0)
7685 lh
->include_dirs_size
= 1; /* for testing */
7686 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7687 * sizeof (*lh
->include_dirs
));
7689 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7691 lh
->include_dirs_size
*= 2;
7692 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7693 (lh
->include_dirs_size
7694 * sizeof (*lh
->include_dirs
)));
7697 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7701 /* Add an entry to LH's file name table. */
7703 add_file_name (struct line_header
*lh
,
7705 unsigned int dir_index
,
7706 unsigned int mod_time
,
7707 unsigned int length
)
7709 struct file_entry
*fe
;
7711 /* Grow the array if necessary. */
7712 if (lh
->file_names_size
== 0)
7714 lh
->file_names_size
= 1; /* for testing */
7715 lh
->file_names
= xmalloc (lh
->file_names_size
7716 * sizeof (*lh
->file_names
));
7718 else if (lh
->num_file_names
>= lh
->file_names_size
)
7720 lh
->file_names_size
*= 2;
7721 lh
->file_names
= xrealloc (lh
->file_names
,
7722 (lh
->file_names_size
7723 * sizeof (*lh
->file_names
)));
7726 fe
= &lh
->file_names
[lh
->num_file_names
++];
7728 fe
->dir_index
= dir_index
;
7729 fe
->mod_time
= mod_time
;
7730 fe
->length
= length
;
7736 /* Read the statement program header starting at OFFSET in
7737 .debug_line, according to the endianness of ABFD. Return a pointer
7738 to a struct line_header, allocated using xmalloc.
7740 NOTE: the strings in the include directory and file name tables of
7741 the returned object point into debug_line_buffer, and must not be
7743 static struct line_header
*
7744 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7745 struct dwarf2_cu
*cu
)
7747 struct cleanup
*back_to
;
7748 struct line_header
*lh
;
7750 unsigned int bytes_read
, offset_size
;
7752 char *cur_dir
, *cur_file
;
7754 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
7755 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7757 complaint (&symfile_complaints
, _("missing .debug_line section"));
7761 /* Make sure that at least there's room for the total_length field.
7762 That could be 12 bytes long, but we're just going to fudge that. */
7763 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7765 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7769 lh
= xmalloc (sizeof (*lh
));
7770 memset (lh
, 0, sizeof (*lh
));
7771 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7774 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7776 /* Read in the header. */
7778 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7779 &bytes_read
, &offset_size
);
7780 line_ptr
+= bytes_read
;
7781 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7782 + dwarf2_per_objfile
->line
.size
))
7784 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7787 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7788 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7790 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7791 line_ptr
+= offset_size
;
7792 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7794 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7796 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7798 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7800 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7802 lh
->standard_opcode_lengths
7803 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7805 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7806 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7808 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7812 /* Read directory table. */
7813 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7815 line_ptr
+= bytes_read
;
7816 add_include_dir (lh
, cur_dir
);
7818 line_ptr
+= bytes_read
;
7820 /* Read file name table. */
7821 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7823 unsigned int dir_index
, mod_time
, length
;
7825 line_ptr
+= bytes_read
;
7826 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7827 line_ptr
+= bytes_read
;
7828 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7829 line_ptr
+= bytes_read
;
7830 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7831 line_ptr
+= bytes_read
;
7833 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7835 line_ptr
+= bytes_read
;
7836 lh
->statement_program_start
= line_ptr
;
7838 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7839 + dwarf2_per_objfile
->line
.size
))
7840 complaint (&symfile_complaints
,
7841 _("line number info header doesn't fit in `.debug_line' section"));
7843 discard_cleanups (back_to
);
7847 /* This function exists to work around a bug in certain compilers
7848 (particularly GCC 2.95), in which the first line number marker of a
7849 function does not show up until after the prologue, right before
7850 the second line number marker. This function shifts ADDRESS down
7851 to the beginning of the function if necessary, and is called on
7852 addresses passed to record_line. */
7855 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7857 struct function_range
*fn
;
7859 /* Find the function_range containing address. */
7864 cu
->cached_fn
= cu
->first_fn
;
7868 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7874 while (fn
&& fn
!= cu
->cached_fn
)
7875 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7885 if (address
!= fn
->lowpc
)
7886 complaint (&symfile_complaints
,
7887 _("misplaced first line number at 0x%lx for '%s'"),
7888 (unsigned long) address
, fn
->name
);
7893 /* Decode the Line Number Program (LNP) for the given line_header
7894 structure and CU. The actual information extracted and the type
7895 of structures created from the LNP depends on the value of PST.
7897 1. If PST is NULL, then this procedure uses the data from the program
7898 to create all necessary symbol tables, and their linetables.
7899 The compilation directory of the file is passed in COMP_DIR,
7900 and must not be NULL.
7902 2. If PST is not NULL, this procedure reads the program to determine
7903 the list of files included by the unit represented by PST, and
7904 builds all the associated partial symbol tables. In this case,
7905 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7906 is not used to compute the full name of the symtab, and therefore
7907 omitting it when building the partial symtab does not introduce
7908 the potential for inconsistency - a partial symtab and its associated
7909 symbtab having a different fullname -). */
7912 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7913 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7915 gdb_byte
*line_ptr
, *extended_end
;
7917 unsigned int bytes_read
, extended_len
;
7918 unsigned char op_code
, extended_op
, adj_opcode
;
7920 struct objfile
*objfile
= cu
->objfile
;
7921 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7922 const int decode_for_pst_p
= (pst
!= NULL
);
7923 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7925 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7927 line_ptr
= lh
->statement_program_start
;
7928 line_end
= lh
->statement_program_end
;
7930 /* Read the statement sequences until there's nothing left. */
7931 while (line_ptr
< line_end
)
7933 /* state machine registers */
7934 CORE_ADDR address
= 0;
7935 unsigned int file
= 1;
7936 unsigned int line
= 1;
7937 unsigned int column
= 0;
7938 int is_stmt
= lh
->default_is_stmt
;
7939 int basic_block
= 0;
7940 int end_sequence
= 0;
7943 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7945 /* Start a subfile for the current file of the state machine. */
7946 /* lh->include_dirs and lh->file_names are 0-based, but the
7947 directory and file name numbers in the statement program
7949 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7953 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7955 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7958 /* Decode the table. */
7959 while (!end_sequence
)
7961 op_code
= read_1_byte (abfd
, line_ptr
);
7963 if (line_ptr
> line_end
)
7965 dwarf2_debug_line_missing_end_sequence_complaint ();
7969 if (op_code
>= lh
->opcode_base
)
7971 /* Special operand. */
7972 adj_opcode
= op_code
- lh
->opcode_base
;
7973 address
+= (adj_opcode
/ lh
->line_range
)
7974 * lh
->minimum_instruction_length
;
7975 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7976 if (lh
->num_file_names
< file
|| file
== 0)
7977 dwarf2_debug_line_missing_file_complaint ();
7980 lh
->file_names
[file
- 1].included_p
= 1;
7981 if (!decode_for_pst_p
&& is_stmt
)
7983 if (last_subfile
!= current_subfile
)
7985 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7987 record_line (last_subfile
, 0, addr
);
7988 last_subfile
= current_subfile
;
7990 /* Append row to matrix using current values. */
7991 addr
= check_cu_functions (address
, cu
);
7992 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7993 record_line (current_subfile
, line
, addr
);
7998 else switch (op_code
)
8000 case DW_LNS_extended_op
:
8001 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8002 line_ptr
+= bytes_read
;
8003 extended_end
= line_ptr
+ extended_len
;
8004 extended_op
= read_1_byte (abfd
, line_ptr
);
8006 switch (extended_op
)
8008 case DW_LNE_end_sequence
:
8011 case DW_LNE_set_address
:
8012 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
8013 line_ptr
+= bytes_read
;
8014 address
+= baseaddr
;
8016 case DW_LNE_define_file
:
8019 unsigned int dir_index
, mod_time
, length
;
8021 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
8022 line_ptr
+= bytes_read
;
8024 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8025 line_ptr
+= bytes_read
;
8027 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8028 line_ptr
+= bytes_read
;
8030 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8031 line_ptr
+= bytes_read
;
8032 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
8035 case DW_LNE_set_discriminator
:
8036 /* The discriminator is not interesting to the debugger;
8038 line_ptr
= extended_end
;
8041 complaint (&symfile_complaints
,
8042 _("mangled .debug_line section"));
8045 /* Make sure that we parsed the extended op correctly. If e.g.
8046 we expected a different address size than the producer used,
8047 we may have read the wrong number of bytes. */
8048 if (line_ptr
!= extended_end
)
8050 complaint (&symfile_complaints
,
8051 _("mangled .debug_line section"));
8056 if (lh
->num_file_names
< file
|| file
== 0)
8057 dwarf2_debug_line_missing_file_complaint ();
8060 lh
->file_names
[file
- 1].included_p
= 1;
8061 if (!decode_for_pst_p
&& is_stmt
)
8063 if (last_subfile
!= current_subfile
)
8065 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8067 record_line (last_subfile
, 0, addr
);
8068 last_subfile
= current_subfile
;
8070 addr
= check_cu_functions (address
, cu
);
8071 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8072 record_line (current_subfile
, line
, addr
);
8077 case DW_LNS_advance_pc
:
8078 address
+= lh
->minimum_instruction_length
8079 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8080 line_ptr
+= bytes_read
;
8082 case DW_LNS_advance_line
:
8083 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
8084 line_ptr
+= bytes_read
;
8086 case DW_LNS_set_file
:
8088 /* The arrays lh->include_dirs and lh->file_names are
8089 0-based, but the directory and file name numbers in
8090 the statement program are 1-based. */
8091 struct file_entry
*fe
;
8094 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8095 line_ptr
+= bytes_read
;
8096 if (lh
->num_file_names
< file
|| file
== 0)
8097 dwarf2_debug_line_missing_file_complaint ();
8100 fe
= &lh
->file_names
[file
- 1];
8102 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8103 if (!decode_for_pst_p
)
8105 last_subfile
= current_subfile
;
8106 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8111 case DW_LNS_set_column
:
8112 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8113 line_ptr
+= bytes_read
;
8115 case DW_LNS_negate_stmt
:
8116 is_stmt
= (!is_stmt
);
8118 case DW_LNS_set_basic_block
:
8121 /* Add to the address register of the state machine the
8122 address increment value corresponding to special opcode
8123 255. I.e., this value is scaled by the minimum
8124 instruction length since special opcode 255 would have
8125 scaled the the increment. */
8126 case DW_LNS_const_add_pc
:
8127 address
+= (lh
->minimum_instruction_length
8128 * ((255 - lh
->opcode_base
) / lh
->line_range
));
8130 case DW_LNS_fixed_advance_pc
:
8131 address
+= read_2_bytes (abfd
, line_ptr
);
8136 /* Unknown standard opcode, ignore it. */
8139 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
8141 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8142 line_ptr
+= bytes_read
;
8147 if (lh
->num_file_names
< file
|| file
== 0)
8148 dwarf2_debug_line_missing_file_complaint ();
8151 lh
->file_names
[file
- 1].included_p
= 1;
8152 if (!decode_for_pst_p
)
8154 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8155 record_line (current_subfile
, 0, addr
);
8160 if (decode_for_pst_p
)
8164 /* Now that we're done scanning the Line Header Program, we can
8165 create the psymtab of each included file. */
8166 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
8167 if (lh
->file_names
[file_index
].included_p
== 1)
8169 const struct file_entry fe
= lh
->file_names
[file_index
];
8170 char *include_name
= fe
.name
;
8171 char *dir_name
= NULL
;
8172 char *pst_filename
= pst
->filename
;
8175 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
8177 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
8179 include_name
= concat (dir_name
, SLASH_STRING
,
8180 include_name
, (char *)NULL
);
8181 make_cleanup (xfree
, include_name
);
8184 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
8186 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
8187 pst_filename
, (char *)NULL
);
8188 make_cleanup (xfree
, pst_filename
);
8191 if (strcmp (include_name
, pst_filename
) != 0)
8192 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
8197 /* Make sure a symtab is created for every file, even files
8198 which contain only variables (i.e. no code with associated
8202 struct file_entry
*fe
;
8204 for (i
= 0; i
< lh
->num_file_names
; i
++)
8207 fe
= &lh
->file_names
[i
];
8209 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8210 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8212 /* Skip the main file; we don't need it, and it must be
8213 allocated last, so that it will show up before the
8214 non-primary symtabs in the objfile's symtab list. */
8215 if (current_subfile
== first_subfile
)
8218 if (current_subfile
->symtab
== NULL
)
8219 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8221 fe
->symtab
= current_subfile
->symtab
;
8226 /* Start a subfile for DWARF. FILENAME is the name of the file and
8227 DIRNAME the name of the source directory which contains FILENAME
8228 or NULL if not known. COMP_DIR is the compilation directory for the
8229 linetable's compilation unit or NULL if not known.
8230 This routine tries to keep line numbers from identical absolute and
8231 relative file names in a common subfile.
8233 Using the `list' example from the GDB testsuite, which resides in
8234 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8235 of /srcdir/list0.c yields the following debugging information for list0.c:
8237 DW_AT_name: /srcdir/list0.c
8238 DW_AT_comp_dir: /compdir
8239 files.files[0].name: list0.h
8240 files.files[0].dir: /srcdir
8241 files.files[1].name: list0.c
8242 files.files[1].dir: /srcdir
8244 The line number information for list0.c has to end up in a single
8245 subfile, so that `break /srcdir/list0.c:1' works as expected.
8246 start_subfile will ensure that this happens provided that we pass the
8247 concatenation of files.files[1].dir and files.files[1].name as the
8251 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
8255 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8256 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8257 second argument to start_subfile. To be consistent, we do the
8258 same here. In order not to lose the line information directory,
8259 we concatenate it to the filename when it makes sense.
8260 Note that the Dwarf3 standard says (speaking of filenames in line
8261 information): ``The directory index is ignored for file names
8262 that represent full path names''. Thus ignoring dirname in the
8263 `else' branch below isn't an issue. */
8265 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
8266 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
8268 fullname
= filename
;
8270 start_subfile (fullname
, comp_dir
);
8272 if (fullname
!= filename
)
8277 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
8278 struct dwarf2_cu
*cu
)
8280 struct objfile
*objfile
= cu
->objfile
;
8281 struct comp_unit_head
*cu_header
= &cu
->header
;
8283 /* NOTE drow/2003-01-30: There used to be a comment and some special
8284 code here to turn a symbol with DW_AT_external and a
8285 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8286 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8287 with some versions of binutils) where shared libraries could have
8288 relocations against symbols in their debug information - the
8289 minimal symbol would have the right address, but the debug info
8290 would not. It's no longer necessary, because we will explicitly
8291 apply relocations when we read in the debug information now. */
8293 /* A DW_AT_location attribute with no contents indicates that a
8294 variable has been optimized away. */
8295 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
8297 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8301 /* Handle one degenerate form of location expression specially, to
8302 preserve GDB's previous behavior when section offsets are
8303 specified. If this is just a DW_OP_addr then mark this symbol
8306 if (attr_form_is_block (attr
)
8307 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
8308 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
8312 SYMBOL_VALUE_ADDRESS (sym
) =
8313 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
8314 SYMBOL_CLASS (sym
) = LOC_STATIC
;
8315 fixup_symbol_section (sym
, objfile
);
8316 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
8317 SYMBOL_SECTION (sym
));
8321 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8322 expression evaluator, and use LOC_COMPUTED only when necessary
8323 (i.e. when the value of a register or memory location is
8324 referenced, or a thread-local block, etc.). Then again, it might
8325 not be worthwhile. I'm assuming that it isn't unless performance
8326 or memory numbers show me otherwise. */
8328 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
8329 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
8332 /* Given a pointer to a DWARF information entry, figure out if we need
8333 to make a symbol table entry for it, and if so, create a new entry
8334 and return a pointer to it.
8335 If TYPE is NULL, determine symbol type from the die, otherwise
8336 used the passed type. */
8338 static struct symbol
*
8339 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
8341 struct objfile
*objfile
= cu
->objfile
;
8342 struct symbol
*sym
= NULL
;
8344 struct attribute
*attr
= NULL
;
8345 struct attribute
*attr2
= NULL
;
8347 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8349 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8351 name
= dwarf2_name (die
, cu
);
8354 const char *linkagename
;
8356 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
8357 sizeof (struct symbol
));
8358 OBJSTAT (objfile
, n_syms
++);
8359 memset (sym
, 0, sizeof (struct symbol
));
8361 /* Cache this symbol's name and the name's demangled form (if any). */
8362 SYMBOL_LANGUAGE (sym
) = cu
->language
;
8363 linkagename
= dwarf2_physname (name
, die
, cu
);
8364 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
8366 /* Default assumptions.
8367 Use the passed type or decode it from the die. */
8368 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8369 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8371 SYMBOL_TYPE (sym
) = type
;
8373 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
8374 attr
= dwarf2_attr (die
,
8375 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
8379 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
8382 attr
= dwarf2_attr (die
,
8383 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
8387 int file_index
= DW_UNSND (attr
);
8388 if (cu
->line_header
== NULL
8389 || file_index
> cu
->line_header
->num_file_names
)
8390 complaint (&symfile_complaints
,
8391 _("file index out of range"));
8392 else if (file_index
> 0)
8394 struct file_entry
*fe
;
8395 fe
= &cu
->line_header
->file_names
[file_index
- 1];
8396 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
8403 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8406 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
8408 SYMBOL_CLASS (sym
) = LOC_LABEL
;
8410 case DW_TAG_subprogram
:
8411 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8413 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8414 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8415 if ((attr2
&& (DW_UNSND (attr2
) != 0))
8416 || cu
->language
== language_ada
)
8418 /* Subprograms marked external are stored as a global symbol.
8419 Ada subprograms, whether marked external or not, are always
8420 stored as a global symbol, because we want to be able to
8421 access them globally. For instance, we want to be able
8422 to break on a nested subprogram without having to
8423 specify the context. */
8424 add_symbol_to_list (sym
, &global_symbols
);
8428 add_symbol_to_list (sym
, cu
->list_in_scope
);
8431 case DW_TAG_inlined_subroutine
:
8432 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8434 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8435 SYMBOL_INLINED (sym
) = 1;
8436 /* Do not add the symbol to any lists. It will be found via
8437 BLOCK_FUNCTION from the blockvector. */
8439 case DW_TAG_variable
:
8440 /* Compilation with minimal debug info may result in variables
8441 with missing type entries. Change the misleading `void' type
8442 to something sensible. */
8443 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
8445 = objfile_type (objfile
)->nodebug_data_symbol
;
8447 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8450 dwarf2_const_value (attr
, sym
, cu
);
8451 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8452 if (attr2
&& (DW_UNSND (attr2
) != 0))
8453 add_symbol_to_list (sym
, &global_symbols
);
8455 add_symbol_to_list (sym
, cu
->list_in_scope
);
8458 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8461 var_decode_location (attr
, sym
, cu
);
8462 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8463 if (attr2
&& (DW_UNSND (attr2
) != 0))
8465 struct pending
**list_to_add
;
8467 /* A variable with DW_AT_external is never static,
8468 but it may be block-scoped. */
8469 list_to_add
= (cu
->list_in_scope
== &file_symbols
8470 ? &global_symbols
: cu
->list_in_scope
);
8471 add_symbol_to_list (sym
, list_to_add
);
8474 add_symbol_to_list (sym
, cu
->list_in_scope
);
8478 /* We do not know the address of this symbol.
8479 If it is an external symbol and we have type information
8480 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8481 The address of the variable will then be determined from
8482 the minimal symbol table whenever the variable is
8484 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8485 if (attr2
&& (DW_UNSND (attr2
) != 0)
8486 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
8488 struct pending
**list_to_add
;
8490 /* A variable with DW_AT_external is never static, but it
8491 may be block-scoped. */
8492 list_to_add
= (cu
->list_in_scope
== &file_symbols
8493 ? &global_symbols
: cu
->list_in_scope
);
8495 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8496 add_symbol_to_list (sym
, list_to_add
);
8498 else if (!die_is_declaration (die
, cu
))
8500 /* Use the default LOC_OPTIMIZED_OUT class. */
8501 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
8502 add_symbol_to_list (sym
, cu
->list_in_scope
);
8506 case DW_TAG_formal_parameter
:
8507 /* If we are inside a function, mark this as an argument. If
8508 not, we might be looking at an argument to an inlined function
8509 when we do not have enough information to show inlined frames;
8510 pretend it's a local variable in that case so that the user can
8512 if (context_stack_depth
> 0
8513 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
8514 SYMBOL_IS_ARGUMENT (sym
) = 1;
8515 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8518 var_decode_location (attr
, sym
, cu
);
8520 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8523 dwarf2_const_value (attr
, sym
, cu
);
8525 add_symbol_to_list (sym
, cu
->list_in_scope
);
8527 case DW_TAG_unspecified_parameters
:
8528 /* From varargs functions; gdb doesn't seem to have any
8529 interest in this information, so just ignore it for now.
8532 case DW_TAG_class_type
:
8533 case DW_TAG_interface_type
:
8534 case DW_TAG_structure_type
:
8535 case DW_TAG_union_type
:
8536 case DW_TAG_set_type
:
8537 case DW_TAG_enumeration_type
:
8538 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8539 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8541 /* Make sure that the symbol includes appropriate enclosing
8542 classes/namespaces in its name. These are calculated in
8543 read_structure_type, and the correct name is saved in
8546 if (cu
->language
== language_cplus
8547 || cu
->language
== language_java
)
8549 struct type
*type
= SYMBOL_TYPE (sym
);
8551 if (TYPE_TAG_NAME (type
) != NULL
)
8553 /* FIXME: carlton/2003-11-10: Should this use
8554 SYMBOL_SET_NAMES instead? (The same problem also
8555 arises further down in this function.) */
8556 /* The type's name is already allocated along with
8557 this objfile, so we don't need to duplicate it
8559 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
8564 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8565 really ever be static objects: otherwise, if you try
8566 to, say, break of a class's method and you're in a file
8567 which doesn't mention that class, it won't work unless
8568 the check for all static symbols in lookup_symbol_aux
8569 saves you. See the OtherFileClass tests in
8570 gdb.c++/namespace.exp. */
8572 struct pending
**list_to_add
;
8574 list_to_add
= (cu
->list_in_scope
== &file_symbols
8575 && (cu
->language
== language_cplus
8576 || cu
->language
== language_java
)
8577 ? &global_symbols
: cu
->list_in_scope
);
8579 add_symbol_to_list (sym
, list_to_add
);
8581 /* The semantics of C++ state that "struct foo { ... }" also
8582 defines a typedef for "foo". A Java class declaration also
8583 defines a typedef for the class. */
8584 if (cu
->language
== language_cplus
8585 || cu
->language
== language_java
8586 || cu
->language
== language_ada
)
8588 /* The symbol's name is already allocated along with
8589 this objfile, so we don't need to duplicate it for
8591 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
8592 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
8596 case DW_TAG_typedef
:
8597 SYMBOL_LINKAGE_NAME (sym
)
8598 = (char *) dwarf2_full_name (name
, die
, cu
);
8599 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8600 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8601 add_symbol_to_list (sym
, cu
->list_in_scope
);
8603 case DW_TAG_base_type
:
8604 case DW_TAG_subrange_type
:
8605 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8606 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8607 add_symbol_to_list (sym
, cu
->list_in_scope
);
8609 case DW_TAG_enumerator
:
8610 SYMBOL_LINKAGE_NAME (sym
)
8611 = (char *) dwarf2_full_name (name
, die
, cu
);
8612 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8615 dwarf2_const_value (attr
, sym
, cu
);
8618 /* NOTE: carlton/2003-11-10: See comment above in the
8619 DW_TAG_class_type, etc. block. */
8621 struct pending
**list_to_add
;
8623 list_to_add
= (cu
->list_in_scope
== &file_symbols
8624 && (cu
->language
== language_cplus
8625 || cu
->language
== language_java
)
8626 ? &global_symbols
: cu
->list_in_scope
);
8628 add_symbol_to_list (sym
, list_to_add
);
8631 case DW_TAG_namespace
:
8632 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8633 add_symbol_to_list (sym
, &global_symbols
);
8636 /* Not a tag we recognize. Hopefully we aren't processing
8637 trash data, but since we must specifically ignore things
8638 we don't recognize, there is nothing else we should do at
8640 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8641 dwarf_tag_name (die
->tag
));
8645 /* For the benefit of old versions of GCC, check for anonymous
8646 namespaces based on the demangled name. */
8647 if (!processing_has_namespace_info
8648 && cu
->language
== language_cplus
)
8649 cp_scan_for_anonymous_namespaces (sym
);
8654 /* Copy constant value from an attribute to a symbol. */
8657 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8658 struct dwarf2_cu
*cu
)
8660 struct objfile
*objfile
= cu
->objfile
;
8661 struct comp_unit_head
*cu_header
= &cu
->header
;
8662 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
8663 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
8664 struct dwarf_block
*blk
;
8669 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8670 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8671 cu_header
->addr_size
,
8672 TYPE_LENGTH (SYMBOL_TYPE
8674 SYMBOL_VALUE_BYTES (sym
) =
8675 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8676 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8677 it's body - store_unsigned_integer. */
8678 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8679 byte_order
, DW_ADDR (attr
));
8680 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8682 case DW_FORM_string
:
8684 /* DW_STRING is already allocated on the obstack, point directly
8686 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8687 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8689 case DW_FORM_block1
:
8690 case DW_FORM_block2
:
8691 case DW_FORM_block4
:
8693 blk
= DW_BLOCK (attr
);
8694 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8695 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8697 TYPE_LENGTH (SYMBOL_TYPE
8699 SYMBOL_VALUE_BYTES (sym
) =
8700 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8701 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8702 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8705 /* The DW_AT_const_value attributes are supposed to carry the
8706 symbol's value "represented as it would be on the target
8707 architecture." By the time we get here, it's already been
8708 converted to host endianness, so we just need to sign- or
8709 zero-extend it as appropriate. */
8711 dwarf2_const_value_data (attr
, sym
, 8);
8714 dwarf2_const_value_data (attr
, sym
, 16);
8717 dwarf2_const_value_data (attr
, sym
, 32);
8720 dwarf2_const_value_data (attr
, sym
, 64);
8724 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8725 SYMBOL_CLASS (sym
) = LOC_CONST
;
8729 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8730 SYMBOL_CLASS (sym
) = LOC_CONST
;
8734 complaint (&symfile_complaints
,
8735 _("unsupported const value attribute form: '%s'"),
8736 dwarf_form_name (attr
->form
));
8737 SYMBOL_VALUE (sym
) = 0;
8738 SYMBOL_CLASS (sym
) = LOC_CONST
;
8744 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8745 or zero-extend it as appropriate for the symbol's type. */
8747 dwarf2_const_value_data (struct attribute
*attr
,
8751 LONGEST l
= DW_UNSND (attr
);
8753 if (bits
< sizeof (l
) * 8)
8755 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8756 l
&= ((LONGEST
) 1 << bits
) - 1;
8758 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8761 SYMBOL_VALUE (sym
) = l
;
8762 SYMBOL_CLASS (sym
) = LOC_CONST
;
8766 /* Return the type of the die in question using its DW_AT_type attribute. */
8768 static struct type
*
8769 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8772 struct attribute
*type_attr
;
8773 struct die_info
*type_die
;
8775 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8778 /* A missing DW_AT_type represents a void type. */
8779 return objfile_type (cu
->objfile
)->builtin_void
;
8782 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8784 type
= tag_type_to_type (type_die
, cu
);
8787 dump_die_for_error (type_die
);
8788 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8794 /* True iff CU's producer generates GNAT Ada auxiliary information
8795 that allows to find parallel types through that information instead
8796 of having to do expensive parallel lookups by type name. */
8799 need_gnat_info (struct dwarf2_cu
*cu
)
8801 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8802 of GNAT produces this auxiliary information, without any indication
8803 that it is produced. Part of enhancing the FSF version of GNAT
8804 to produce that information will be to put in place an indicator
8805 that we can use in order to determine whether the descriptive type
8806 info is available or not. One suggestion that has been made is
8807 to use a new attribute, attached to the CU die. For now, assume
8808 that the descriptive type info is not available. */
8813 /* Return the auxiliary type of the die in question using its
8814 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8815 attribute is not present. */
8817 static struct type
*
8818 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8821 struct attribute
*type_attr
;
8822 struct die_info
*type_die
;
8824 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
8828 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8829 type
= tag_type_to_type (type_die
, cu
);
8832 dump_die_for_error (type_die
);
8833 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8839 /* If DIE has a descriptive_type attribute, then set the TYPE's
8840 descriptive type accordingly. */
8843 set_descriptive_type (struct type
*type
, struct die_info
*die
,
8844 struct dwarf2_cu
*cu
)
8846 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
8848 if (descriptive_type
)
8850 ALLOCATE_GNAT_AUX_TYPE (type
);
8851 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
8855 /* Return the containing type of the die in question using its
8856 DW_AT_containing_type attribute. */
8858 static struct type
*
8859 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8861 struct type
*type
= NULL
;
8862 struct attribute
*type_attr
;
8863 struct die_info
*type_die
= NULL
;
8865 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8868 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8869 type
= tag_type_to_type (type_die
, cu
);
8874 dump_die_for_error (type_die
);
8875 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8881 static struct type
*
8882 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8884 struct type
*this_type
;
8886 this_type
= read_type_die (die
, cu
);
8889 dump_die_for_error (die
);
8890 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8896 static struct type
*
8897 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8899 struct type
*this_type
;
8901 this_type
= get_die_type (die
, cu
);
8907 case DW_TAG_class_type
:
8908 case DW_TAG_interface_type
:
8909 case DW_TAG_structure_type
:
8910 case DW_TAG_union_type
:
8911 this_type
= read_structure_type (die
, cu
);
8913 case DW_TAG_enumeration_type
:
8914 this_type
= read_enumeration_type (die
, cu
);
8916 case DW_TAG_subprogram
:
8917 case DW_TAG_subroutine_type
:
8918 case DW_TAG_inlined_subroutine
:
8919 this_type
= read_subroutine_type (die
, cu
);
8921 case DW_TAG_array_type
:
8922 this_type
= read_array_type (die
, cu
);
8924 case DW_TAG_set_type
:
8925 this_type
= read_set_type (die
, cu
);
8927 case DW_TAG_pointer_type
:
8928 this_type
= read_tag_pointer_type (die
, cu
);
8930 case DW_TAG_ptr_to_member_type
:
8931 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8933 case DW_TAG_reference_type
:
8934 this_type
= read_tag_reference_type (die
, cu
);
8936 case DW_TAG_const_type
:
8937 this_type
= read_tag_const_type (die
, cu
);
8939 case DW_TAG_volatile_type
:
8940 this_type
= read_tag_volatile_type (die
, cu
);
8942 case DW_TAG_string_type
:
8943 this_type
= read_tag_string_type (die
, cu
);
8945 case DW_TAG_typedef
:
8946 this_type
= read_typedef (die
, cu
);
8948 case DW_TAG_subrange_type
:
8949 this_type
= read_subrange_type (die
, cu
);
8951 case DW_TAG_base_type
:
8952 this_type
= read_base_type (die
, cu
);
8954 case DW_TAG_unspecified_type
:
8955 this_type
= read_unspecified_type (die
, cu
);
8957 case DW_TAG_namespace
:
8958 this_type
= read_namespace_type (die
, cu
);
8961 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8962 dwarf_tag_name (die
->tag
));
8969 /* Return the name of the namespace/class that DIE is defined within,
8970 or "" if we can't tell. The caller should not xfree the result.
8972 For example, if we're within the method foo() in the following
8982 then determine_prefix on foo's die will return "N::C". */
8985 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8987 struct die_info
*parent
, *spec_die
;
8988 struct dwarf2_cu
*spec_cu
;
8989 struct type
*parent_type
;
8991 if (cu
->language
!= language_cplus
8992 && cu
->language
!= language_java
)
8995 /* We have to be careful in the presence of DW_AT_specification.
8996 For example, with GCC 3.4, given the code
9000 // Definition of N::foo.
9004 then we'll have a tree of DIEs like this:
9006 1: DW_TAG_compile_unit
9007 2: DW_TAG_namespace // N
9008 3: DW_TAG_subprogram // declaration of N::foo
9009 4: DW_TAG_subprogram // definition of N::foo
9010 DW_AT_specification // refers to die #3
9012 Thus, when processing die #4, we have to pretend that we're in
9013 the context of its DW_AT_specification, namely the contex of die
9016 spec_die
= die_specification (die
, &spec_cu
);
9017 if (spec_die
== NULL
)
9018 parent
= die
->parent
;
9021 parent
= spec_die
->parent
;
9028 switch (parent
->tag
)
9030 case DW_TAG_namespace
:
9031 parent_type
= read_type_die (parent
, cu
);
9032 /* We give a name to even anonymous namespaces. */
9033 return TYPE_TAG_NAME (parent_type
);
9034 case DW_TAG_class_type
:
9035 case DW_TAG_interface_type
:
9036 case DW_TAG_structure_type
:
9037 case DW_TAG_union_type
:
9038 parent_type
= read_type_die (parent
, cu
);
9039 if (TYPE_TAG_NAME (parent_type
) != NULL
)
9040 return TYPE_TAG_NAME (parent_type
);
9042 /* An anonymous structure is only allowed non-static data
9043 members; no typedefs, no member functions, et cetera.
9044 So it does not need a prefix. */
9047 return determine_prefix (parent
, cu
);
9051 /* Return a newly-allocated string formed by concatenating PREFIX and
9052 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9053 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9054 perform an obconcat, otherwise allocate storage for the result. The CU argument
9055 is used to determine the language and hence, the appropriate separator. */
9057 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9060 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9061 struct dwarf2_cu
*cu
)
9065 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9067 else if (cu
->language
== language_java
)
9079 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9080 strcpy (retval
, prefix
);
9081 strcat (retval
, sep
);
9082 strcat (retval
, suffix
);
9087 /* We have an obstack. */
9088 return obconcat (obs
, prefix
, sep
, suffix
);
9092 /* Return sibling of die, NULL if no sibling. */
9094 static struct die_info
*
9095 sibling_die (struct die_info
*die
)
9097 return die
->sibling
;
9100 /* Get name of a die, return NULL if not found. */
9103 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9104 struct obstack
*obstack
)
9106 if (name
&& cu
->language
== language_cplus
)
9108 char *canon_name
= cp_canonicalize_string (name
);
9110 if (canon_name
!= NULL
)
9112 if (strcmp (canon_name
, name
) != 0)
9113 name
= obsavestring (canon_name
, strlen (canon_name
),
9122 /* Get name of a die, return NULL if not found. */
9125 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9127 struct attribute
*attr
;
9129 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9130 if (!attr
|| !DW_STRING (attr
))
9135 case DW_TAG_compile_unit
:
9136 /* Compilation units have a DW_AT_name that is a filename, not
9137 a source language identifier. */
9138 case DW_TAG_enumeration_type
:
9139 case DW_TAG_enumerator
:
9140 /* These tags always have simple identifiers already; no need
9141 to canonicalize them. */
9142 return DW_STRING (attr
);
9144 if (!DW_STRING_IS_CANONICAL (attr
))
9147 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9148 &cu
->objfile
->objfile_obstack
);
9149 DW_STRING_IS_CANONICAL (attr
) = 1;
9151 return DW_STRING (attr
);
9155 /* Return the die that this die in an extension of, or NULL if there
9156 is none. *EXT_CU is the CU containing DIE on input, and the CU
9157 containing the return value on output. */
9159 static struct die_info
*
9160 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9162 struct attribute
*attr
;
9164 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9168 return follow_die_ref (die
, attr
, ext_cu
);
9171 /* Convert a DIE tag into its string name. */
9174 dwarf_tag_name (unsigned tag
)
9178 case DW_TAG_padding
:
9179 return "DW_TAG_padding";
9180 case DW_TAG_array_type
:
9181 return "DW_TAG_array_type";
9182 case DW_TAG_class_type
:
9183 return "DW_TAG_class_type";
9184 case DW_TAG_entry_point
:
9185 return "DW_TAG_entry_point";
9186 case DW_TAG_enumeration_type
:
9187 return "DW_TAG_enumeration_type";
9188 case DW_TAG_formal_parameter
:
9189 return "DW_TAG_formal_parameter";
9190 case DW_TAG_imported_declaration
:
9191 return "DW_TAG_imported_declaration";
9193 return "DW_TAG_label";
9194 case DW_TAG_lexical_block
:
9195 return "DW_TAG_lexical_block";
9197 return "DW_TAG_member";
9198 case DW_TAG_pointer_type
:
9199 return "DW_TAG_pointer_type";
9200 case DW_TAG_reference_type
:
9201 return "DW_TAG_reference_type";
9202 case DW_TAG_compile_unit
:
9203 return "DW_TAG_compile_unit";
9204 case DW_TAG_string_type
:
9205 return "DW_TAG_string_type";
9206 case DW_TAG_structure_type
:
9207 return "DW_TAG_structure_type";
9208 case DW_TAG_subroutine_type
:
9209 return "DW_TAG_subroutine_type";
9210 case DW_TAG_typedef
:
9211 return "DW_TAG_typedef";
9212 case DW_TAG_union_type
:
9213 return "DW_TAG_union_type";
9214 case DW_TAG_unspecified_parameters
:
9215 return "DW_TAG_unspecified_parameters";
9216 case DW_TAG_variant
:
9217 return "DW_TAG_variant";
9218 case DW_TAG_common_block
:
9219 return "DW_TAG_common_block";
9220 case DW_TAG_common_inclusion
:
9221 return "DW_TAG_common_inclusion";
9222 case DW_TAG_inheritance
:
9223 return "DW_TAG_inheritance";
9224 case DW_TAG_inlined_subroutine
:
9225 return "DW_TAG_inlined_subroutine";
9227 return "DW_TAG_module";
9228 case DW_TAG_ptr_to_member_type
:
9229 return "DW_TAG_ptr_to_member_type";
9230 case DW_TAG_set_type
:
9231 return "DW_TAG_set_type";
9232 case DW_TAG_subrange_type
:
9233 return "DW_TAG_subrange_type";
9234 case DW_TAG_with_stmt
:
9235 return "DW_TAG_with_stmt";
9236 case DW_TAG_access_declaration
:
9237 return "DW_TAG_access_declaration";
9238 case DW_TAG_base_type
:
9239 return "DW_TAG_base_type";
9240 case DW_TAG_catch_block
:
9241 return "DW_TAG_catch_block";
9242 case DW_TAG_const_type
:
9243 return "DW_TAG_const_type";
9244 case DW_TAG_constant
:
9245 return "DW_TAG_constant";
9246 case DW_TAG_enumerator
:
9247 return "DW_TAG_enumerator";
9248 case DW_TAG_file_type
:
9249 return "DW_TAG_file_type";
9251 return "DW_TAG_friend";
9252 case DW_TAG_namelist
:
9253 return "DW_TAG_namelist";
9254 case DW_TAG_namelist_item
:
9255 return "DW_TAG_namelist_item";
9256 case DW_TAG_packed_type
:
9257 return "DW_TAG_packed_type";
9258 case DW_TAG_subprogram
:
9259 return "DW_TAG_subprogram";
9260 case DW_TAG_template_type_param
:
9261 return "DW_TAG_template_type_param";
9262 case DW_TAG_template_value_param
:
9263 return "DW_TAG_template_value_param";
9264 case DW_TAG_thrown_type
:
9265 return "DW_TAG_thrown_type";
9266 case DW_TAG_try_block
:
9267 return "DW_TAG_try_block";
9268 case DW_TAG_variant_part
:
9269 return "DW_TAG_variant_part";
9270 case DW_TAG_variable
:
9271 return "DW_TAG_variable";
9272 case DW_TAG_volatile_type
:
9273 return "DW_TAG_volatile_type";
9274 case DW_TAG_dwarf_procedure
:
9275 return "DW_TAG_dwarf_procedure";
9276 case DW_TAG_restrict_type
:
9277 return "DW_TAG_restrict_type";
9278 case DW_TAG_interface_type
:
9279 return "DW_TAG_interface_type";
9280 case DW_TAG_namespace
:
9281 return "DW_TAG_namespace";
9282 case DW_TAG_imported_module
:
9283 return "DW_TAG_imported_module";
9284 case DW_TAG_unspecified_type
:
9285 return "DW_TAG_unspecified_type";
9286 case DW_TAG_partial_unit
:
9287 return "DW_TAG_partial_unit";
9288 case DW_TAG_imported_unit
:
9289 return "DW_TAG_imported_unit";
9290 case DW_TAG_condition
:
9291 return "DW_TAG_condition";
9292 case DW_TAG_shared_type
:
9293 return "DW_TAG_shared_type";
9294 case DW_TAG_type_unit
:
9295 return "DW_TAG_type_unit";
9296 case DW_TAG_MIPS_loop
:
9297 return "DW_TAG_MIPS_loop";
9298 case DW_TAG_HP_array_descriptor
:
9299 return "DW_TAG_HP_array_descriptor";
9300 case DW_TAG_format_label
:
9301 return "DW_TAG_format_label";
9302 case DW_TAG_function_template
:
9303 return "DW_TAG_function_template";
9304 case DW_TAG_class_template
:
9305 return "DW_TAG_class_template";
9306 case DW_TAG_GNU_BINCL
:
9307 return "DW_TAG_GNU_BINCL";
9308 case DW_TAG_GNU_EINCL
:
9309 return "DW_TAG_GNU_EINCL";
9310 case DW_TAG_upc_shared_type
:
9311 return "DW_TAG_upc_shared_type";
9312 case DW_TAG_upc_strict_type
:
9313 return "DW_TAG_upc_strict_type";
9314 case DW_TAG_upc_relaxed_type
:
9315 return "DW_TAG_upc_relaxed_type";
9316 case DW_TAG_PGI_kanji_type
:
9317 return "DW_TAG_PGI_kanji_type";
9318 case DW_TAG_PGI_interface_block
:
9319 return "DW_TAG_PGI_interface_block";
9321 return "DW_TAG_<unknown>";
9325 /* Convert a DWARF attribute code into its string name. */
9328 dwarf_attr_name (unsigned attr
)
9333 return "DW_AT_sibling";
9334 case DW_AT_location
:
9335 return "DW_AT_location";
9337 return "DW_AT_name";
9338 case DW_AT_ordering
:
9339 return "DW_AT_ordering";
9340 case DW_AT_subscr_data
:
9341 return "DW_AT_subscr_data";
9342 case DW_AT_byte_size
:
9343 return "DW_AT_byte_size";
9344 case DW_AT_bit_offset
:
9345 return "DW_AT_bit_offset";
9346 case DW_AT_bit_size
:
9347 return "DW_AT_bit_size";
9348 case DW_AT_element_list
:
9349 return "DW_AT_element_list";
9350 case DW_AT_stmt_list
:
9351 return "DW_AT_stmt_list";
9353 return "DW_AT_low_pc";
9355 return "DW_AT_high_pc";
9356 case DW_AT_language
:
9357 return "DW_AT_language";
9359 return "DW_AT_member";
9361 return "DW_AT_discr";
9362 case DW_AT_discr_value
:
9363 return "DW_AT_discr_value";
9364 case DW_AT_visibility
:
9365 return "DW_AT_visibility";
9367 return "DW_AT_import";
9368 case DW_AT_string_length
:
9369 return "DW_AT_string_length";
9370 case DW_AT_common_reference
:
9371 return "DW_AT_common_reference";
9372 case DW_AT_comp_dir
:
9373 return "DW_AT_comp_dir";
9374 case DW_AT_const_value
:
9375 return "DW_AT_const_value";
9376 case DW_AT_containing_type
:
9377 return "DW_AT_containing_type";
9378 case DW_AT_default_value
:
9379 return "DW_AT_default_value";
9381 return "DW_AT_inline";
9382 case DW_AT_is_optional
:
9383 return "DW_AT_is_optional";
9384 case DW_AT_lower_bound
:
9385 return "DW_AT_lower_bound";
9386 case DW_AT_producer
:
9387 return "DW_AT_producer";
9388 case DW_AT_prototyped
:
9389 return "DW_AT_prototyped";
9390 case DW_AT_return_addr
:
9391 return "DW_AT_return_addr";
9392 case DW_AT_start_scope
:
9393 return "DW_AT_start_scope";
9394 case DW_AT_bit_stride
:
9395 return "DW_AT_bit_stride";
9396 case DW_AT_upper_bound
:
9397 return "DW_AT_upper_bound";
9398 case DW_AT_abstract_origin
:
9399 return "DW_AT_abstract_origin";
9400 case DW_AT_accessibility
:
9401 return "DW_AT_accessibility";
9402 case DW_AT_address_class
:
9403 return "DW_AT_address_class";
9404 case DW_AT_artificial
:
9405 return "DW_AT_artificial";
9406 case DW_AT_base_types
:
9407 return "DW_AT_base_types";
9408 case DW_AT_calling_convention
:
9409 return "DW_AT_calling_convention";
9411 return "DW_AT_count";
9412 case DW_AT_data_member_location
:
9413 return "DW_AT_data_member_location";
9414 case DW_AT_decl_column
:
9415 return "DW_AT_decl_column";
9416 case DW_AT_decl_file
:
9417 return "DW_AT_decl_file";
9418 case DW_AT_decl_line
:
9419 return "DW_AT_decl_line";
9420 case DW_AT_declaration
:
9421 return "DW_AT_declaration";
9422 case DW_AT_discr_list
:
9423 return "DW_AT_discr_list";
9424 case DW_AT_encoding
:
9425 return "DW_AT_encoding";
9426 case DW_AT_external
:
9427 return "DW_AT_external";
9428 case DW_AT_frame_base
:
9429 return "DW_AT_frame_base";
9431 return "DW_AT_friend";
9432 case DW_AT_identifier_case
:
9433 return "DW_AT_identifier_case";
9434 case DW_AT_macro_info
:
9435 return "DW_AT_macro_info";
9436 case DW_AT_namelist_items
:
9437 return "DW_AT_namelist_items";
9438 case DW_AT_priority
:
9439 return "DW_AT_priority";
9441 return "DW_AT_segment";
9442 case DW_AT_specification
:
9443 return "DW_AT_specification";
9444 case DW_AT_static_link
:
9445 return "DW_AT_static_link";
9447 return "DW_AT_type";
9448 case DW_AT_use_location
:
9449 return "DW_AT_use_location";
9450 case DW_AT_variable_parameter
:
9451 return "DW_AT_variable_parameter";
9452 case DW_AT_virtuality
:
9453 return "DW_AT_virtuality";
9454 case DW_AT_vtable_elem_location
:
9455 return "DW_AT_vtable_elem_location";
9456 /* DWARF 3 values. */
9457 case DW_AT_allocated
:
9458 return "DW_AT_allocated";
9459 case DW_AT_associated
:
9460 return "DW_AT_associated";
9461 case DW_AT_data_location
:
9462 return "DW_AT_data_location";
9463 case DW_AT_byte_stride
:
9464 return "DW_AT_byte_stride";
9465 case DW_AT_entry_pc
:
9466 return "DW_AT_entry_pc";
9467 case DW_AT_use_UTF8
:
9468 return "DW_AT_use_UTF8";
9469 case DW_AT_extension
:
9470 return "DW_AT_extension";
9472 return "DW_AT_ranges";
9473 case DW_AT_trampoline
:
9474 return "DW_AT_trampoline";
9475 case DW_AT_call_column
:
9476 return "DW_AT_call_column";
9477 case DW_AT_call_file
:
9478 return "DW_AT_call_file";
9479 case DW_AT_call_line
:
9480 return "DW_AT_call_line";
9481 case DW_AT_description
:
9482 return "DW_AT_description";
9483 case DW_AT_binary_scale
:
9484 return "DW_AT_binary_scale";
9485 case DW_AT_decimal_scale
:
9486 return "DW_AT_decimal_scale";
9488 return "DW_AT_small";
9489 case DW_AT_decimal_sign
:
9490 return "DW_AT_decimal_sign";
9491 case DW_AT_digit_count
:
9492 return "DW_AT_digit_count";
9493 case DW_AT_picture_string
:
9494 return "DW_AT_picture_string";
9496 return "DW_AT_mutable";
9497 case DW_AT_threads_scaled
:
9498 return "DW_AT_threads_scaled";
9499 case DW_AT_explicit
:
9500 return "DW_AT_explicit";
9501 case DW_AT_object_pointer
:
9502 return "DW_AT_object_pointer";
9503 case DW_AT_endianity
:
9504 return "DW_AT_endianity";
9505 case DW_AT_elemental
:
9506 return "DW_AT_elemental";
9508 return "DW_AT_pure";
9509 case DW_AT_recursive
:
9510 return "DW_AT_recursive";
9511 /* DWARF 4 values. */
9512 case DW_AT_signature
:
9513 return "DW_AT_signature";
9514 /* SGI/MIPS extensions. */
9515 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9516 case DW_AT_MIPS_fde
:
9517 return "DW_AT_MIPS_fde";
9519 case DW_AT_MIPS_loop_begin
:
9520 return "DW_AT_MIPS_loop_begin";
9521 case DW_AT_MIPS_tail_loop_begin
:
9522 return "DW_AT_MIPS_tail_loop_begin";
9523 case DW_AT_MIPS_epilog_begin
:
9524 return "DW_AT_MIPS_epilog_begin";
9525 case DW_AT_MIPS_loop_unroll_factor
:
9526 return "DW_AT_MIPS_loop_unroll_factor";
9527 case DW_AT_MIPS_software_pipeline_depth
:
9528 return "DW_AT_MIPS_software_pipeline_depth";
9529 case DW_AT_MIPS_linkage_name
:
9530 return "DW_AT_MIPS_linkage_name";
9531 case DW_AT_MIPS_stride
:
9532 return "DW_AT_MIPS_stride";
9533 case DW_AT_MIPS_abstract_name
:
9534 return "DW_AT_MIPS_abstract_name";
9535 case DW_AT_MIPS_clone_origin
:
9536 return "DW_AT_MIPS_clone_origin";
9537 case DW_AT_MIPS_has_inlines
:
9538 return "DW_AT_MIPS_has_inlines";
9539 /* HP extensions. */
9540 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9541 case DW_AT_HP_block_index
:
9542 return "DW_AT_HP_block_index";
9544 case DW_AT_HP_unmodifiable
:
9545 return "DW_AT_HP_unmodifiable";
9546 case DW_AT_HP_actuals_stmt_list
:
9547 return "DW_AT_HP_actuals_stmt_list";
9548 case DW_AT_HP_proc_per_section
:
9549 return "DW_AT_HP_proc_per_section";
9550 case DW_AT_HP_raw_data_ptr
:
9551 return "DW_AT_HP_raw_data_ptr";
9552 case DW_AT_HP_pass_by_reference
:
9553 return "DW_AT_HP_pass_by_reference";
9554 case DW_AT_HP_opt_level
:
9555 return "DW_AT_HP_opt_level";
9556 case DW_AT_HP_prof_version_id
:
9557 return "DW_AT_HP_prof_version_id";
9558 case DW_AT_HP_opt_flags
:
9559 return "DW_AT_HP_opt_flags";
9560 case DW_AT_HP_cold_region_low_pc
:
9561 return "DW_AT_HP_cold_region_low_pc";
9562 case DW_AT_HP_cold_region_high_pc
:
9563 return "DW_AT_HP_cold_region_high_pc";
9564 case DW_AT_HP_all_variables_modifiable
:
9565 return "DW_AT_HP_all_variables_modifiable";
9566 case DW_AT_HP_linkage_name
:
9567 return "DW_AT_HP_linkage_name";
9568 case DW_AT_HP_prof_flags
:
9569 return "DW_AT_HP_prof_flags";
9570 /* GNU extensions. */
9571 case DW_AT_sf_names
:
9572 return "DW_AT_sf_names";
9573 case DW_AT_src_info
:
9574 return "DW_AT_src_info";
9575 case DW_AT_mac_info
:
9576 return "DW_AT_mac_info";
9577 case DW_AT_src_coords
:
9578 return "DW_AT_src_coords";
9579 case DW_AT_body_begin
:
9580 return "DW_AT_body_begin";
9581 case DW_AT_body_end
:
9582 return "DW_AT_body_end";
9583 case DW_AT_GNU_vector
:
9584 return "DW_AT_GNU_vector";
9585 /* VMS extensions. */
9586 case DW_AT_VMS_rtnbeg_pd_address
:
9587 return "DW_AT_VMS_rtnbeg_pd_address";
9588 /* UPC extension. */
9589 case DW_AT_upc_threads_scaled
:
9590 return "DW_AT_upc_threads_scaled";
9591 /* PGI (STMicroelectronics) extensions. */
9592 case DW_AT_PGI_lbase
:
9593 return "DW_AT_PGI_lbase";
9594 case DW_AT_PGI_soffset
:
9595 return "DW_AT_PGI_soffset";
9596 case DW_AT_PGI_lstride
:
9597 return "DW_AT_PGI_lstride";
9599 return "DW_AT_<unknown>";
9603 /* Convert a DWARF value form code into its string name. */
9606 dwarf_form_name (unsigned form
)
9611 return "DW_FORM_addr";
9612 case DW_FORM_block2
:
9613 return "DW_FORM_block2";
9614 case DW_FORM_block4
:
9615 return "DW_FORM_block4";
9617 return "DW_FORM_data2";
9619 return "DW_FORM_data4";
9621 return "DW_FORM_data8";
9622 case DW_FORM_string
:
9623 return "DW_FORM_string";
9625 return "DW_FORM_block";
9626 case DW_FORM_block1
:
9627 return "DW_FORM_block1";
9629 return "DW_FORM_data1";
9631 return "DW_FORM_flag";
9633 return "DW_FORM_sdata";
9635 return "DW_FORM_strp";
9637 return "DW_FORM_udata";
9638 case DW_FORM_ref_addr
:
9639 return "DW_FORM_ref_addr";
9641 return "DW_FORM_ref1";
9643 return "DW_FORM_ref2";
9645 return "DW_FORM_ref4";
9647 return "DW_FORM_ref8";
9648 case DW_FORM_ref_udata
:
9649 return "DW_FORM_ref_udata";
9650 case DW_FORM_indirect
:
9651 return "DW_FORM_indirect";
9652 case DW_FORM_sec_offset
:
9653 return "DW_FORM_sec_offset";
9654 case DW_FORM_exprloc
:
9655 return "DW_FORM_exprloc";
9656 case DW_FORM_flag_present
:
9657 return "DW_FORM_flag_present";
9659 return "DW_FORM_sig8";
9661 return "DW_FORM_<unknown>";
9665 /* Convert a DWARF stack opcode into its string name. */
9668 dwarf_stack_op_name (unsigned op
)
9673 return "DW_OP_addr";
9675 return "DW_OP_deref";
9677 return "DW_OP_const1u";
9679 return "DW_OP_const1s";
9681 return "DW_OP_const2u";
9683 return "DW_OP_const2s";
9685 return "DW_OP_const4u";
9687 return "DW_OP_const4s";
9689 return "DW_OP_const8u";
9691 return "DW_OP_const8s";
9693 return "DW_OP_constu";
9695 return "DW_OP_consts";
9699 return "DW_OP_drop";
9701 return "DW_OP_over";
9703 return "DW_OP_pick";
9705 return "DW_OP_swap";
9709 return "DW_OP_xderef";
9717 return "DW_OP_minus";
9729 return "DW_OP_plus";
9730 case DW_OP_plus_uconst
:
9731 return "DW_OP_plus_uconst";
9737 return "DW_OP_shra";
9755 return "DW_OP_skip";
9757 return "DW_OP_lit0";
9759 return "DW_OP_lit1";
9761 return "DW_OP_lit2";
9763 return "DW_OP_lit3";
9765 return "DW_OP_lit4";
9767 return "DW_OP_lit5";
9769 return "DW_OP_lit6";
9771 return "DW_OP_lit7";
9773 return "DW_OP_lit8";
9775 return "DW_OP_lit9";
9777 return "DW_OP_lit10";
9779 return "DW_OP_lit11";
9781 return "DW_OP_lit12";
9783 return "DW_OP_lit13";
9785 return "DW_OP_lit14";
9787 return "DW_OP_lit15";
9789 return "DW_OP_lit16";
9791 return "DW_OP_lit17";
9793 return "DW_OP_lit18";
9795 return "DW_OP_lit19";
9797 return "DW_OP_lit20";
9799 return "DW_OP_lit21";
9801 return "DW_OP_lit22";
9803 return "DW_OP_lit23";
9805 return "DW_OP_lit24";
9807 return "DW_OP_lit25";
9809 return "DW_OP_lit26";
9811 return "DW_OP_lit27";
9813 return "DW_OP_lit28";
9815 return "DW_OP_lit29";
9817 return "DW_OP_lit30";
9819 return "DW_OP_lit31";
9821 return "DW_OP_reg0";
9823 return "DW_OP_reg1";
9825 return "DW_OP_reg2";
9827 return "DW_OP_reg3";
9829 return "DW_OP_reg4";
9831 return "DW_OP_reg5";
9833 return "DW_OP_reg6";
9835 return "DW_OP_reg7";
9837 return "DW_OP_reg8";
9839 return "DW_OP_reg9";
9841 return "DW_OP_reg10";
9843 return "DW_OP_reg11";
9845 return "DW_OP_reg12";
9847 return "DW_OP_reg13";
9849 return "DW_OP_reg14";
9851 return "DW_OP_reg15";
9853 return "DW_OP_reg16";
9855 return "DW_OP_reg17";
9857 return "DW_OP_reg18";
9859 return "DW_OP_reg19";
9861 return "DW_OP_reg20";
9863 return "DW_OP_reg21";
9865 return "DW_OP_reg22";
9867 return "DW_OP_reg23";
9869 return "DW_OP_reg24";
9871 return "DW_OP_reg25";
9873 return "DW_OP_reg26";
9875 return "DW_OP_reg27";
9877 return "DW_OP_reg28";
9879 return "DW_OP_reg29";
9881 return "DW_OP_reg30";
9883 return "DW_OP_reg31";
9885 return "DW_OP_breg0";
9887 return "DW_OP_breg1";
9889 return "DW_OP_breg2";
9891 return "DW_OP_breg3";
9893 return "DW_OP_breg4";
9895 return "DW_OP_breg5";
9897 return "DW_OP_breg6";
9899 return "DW_OP_breg7";
9901 return "DW_OP_breg8";
9903 return "DW_OP_breg9";
9905 return "DW_OP_breg10";
9907 return "DW_OP_breg11";
9909 return "DW_OP_breg12";
9911 return "DW_OP_breg13";
9913 return "DW_OP_breg14";
9915 return "DW_OP_breg15";
9917 return "DW_OP_breg16";
9919 return "DW_OP_breg17";
9921 return "DW_OP_breg18";
9923 return "DW_OP_breg19";
9925 return "DW_OP_breg20";
9927 return "DW_OP_breg21";
9929 return "DW_OP_breg22";
9931 return "DW_OP_breg23";
9933 return "DW_OP_breg24";
9935 return "DW_OP_breg25";
9937 return "DW_OP_breg26";
9939 return "DW_OP_breg27";
9941 return "DW_OP_breg28";
9943 return "DW_OP_breg29";
9945 return "DW_OP_breg30";
9947 return "DW_OP_breg31";
9949 return "DW_OP_regx";
9951 return "DW_OP_fbreg";
9953 return "DW_OP_bregx";
9955 return "DW_OP_piece";
9956 case DW_OP_deref_size
:
9957 return "DW_OP_deref_size";
9958 case DW_OP_xderef_size
:
9959 return "DW_OP_xderef_size";
9962 /* DWARF 3 extensions. */
9963 case DW_OP_push_object_address
:
9964 return "DW_OP_push_object_address";
9966 return "DW_OP_call2";
9968 return "DW_OP_call4";
9969 case DW_OP_call_ref
:
9970 return "DW_OP_call_ref";
9971 /* GNU extensions. */
9972 case DW_OP_form_tls_address
:
9973 return "DW_OP_form_tls_address";
9974 case DW_OP_call_frame_cfa
:
9975 return "DW_OP_call_frame_cfa";
9976 case DW_OP_bit_piece
:
9977 return "DW_OP_bit_piece";
9978 case DW_OP_GNU_push_tls_address
:
9979 return "DW_OP_GNU_push_tls_address";
9980 case DW_OP_GNU_uninit
:
9981 return "DW_OP_GNU_uninit";
9982 /* HP extensions. */
9983 case DW_OP_HP_is_value
:
9984 return "DW_OP_HP_is_value";
9985 case DW_OP_HP_fltconst4
:
9986 return "DW_OP_HP_fltconst4";
9987 case DW_OP_HP_fltconst8
:
9988 return "DW_OP_HP_fltconst8";
9989 case DW_OP_HP_mod_range
:
9990 return "DW_OP_HP_mod_range";
9991 case DW_OP_HP_unmod_range
:
9992 return "DW_OP_HP_unmod_range";
9994 return "DW_OP_HP_tls";
9996 return "OP_<unknown>";
10001 dwarf_bool_name (unsigned mybool
)
10009 /* Convert a DWARF type code into its string name. */
10012 dwarf_type_encoding_name (unsigned enc
)
10017 return "DW_ATE_void";
10018 case DW_ATE_address
:
10019 return "DW_ATE_address";
10020 case DW_ATE_boolean
:
10021 return "DW_ATE_boolean";
10022 case DW_ATE_complex_float
:
10023 return "DW_ATE_complex_float";
10025 return "DW_ATE_float";
10026 case DW_ATE_signed
:
10027 return "DW_ATE_signed";
10028 case DW_ATE_signed_char
:
10029 return "DW_ATE_signed_char";
10030 case DW_ATE_unsigned
:
10031 return "DW_ATE_unsigned";
10032 case DW_ATE_unsigned_char
:
10033 return "DW_ATE_unsigned_char";
10035 case DW_ATE_imaginary_float
:
10036 return "DW_ATE_imaginary_float";
10037 case DW_ATE_packed_decimal
:
10038 return "DW_ATE_packed_decimal";
10039 case DW_ATE_numeric_string
:
10040 return "DW_ATE_numeric_string";
10041 case DW_ATE_edited
:
10042 return "DW_ATE_edited";
10043 case DW_ATE_signed_fixed
:
10044 return "DW_ATE_signed_fixed";
10045 case DW_ATE_unsigned_fixed
:
10046 return "DW_ATE_unsigned_fixed";
10047 case DW_ATE_decimal_float
:
10048 return "DW_ATE_decimal_float";
10049 /* HP extensions. */
10050 case DW_ATE_HP_float80
:
10051 return "DW_ATE_HP_float80";
10052 case DW_ATE_HP_complex_float80
:
10053 return "DW_ATE_HP_complex_float80";
10054 case DW_ATE_HP_float128
:
10055 return "DW_ATE_HP_float128";
10056 case DW_ATE_HP_complex_float128
:
10057 return "DW_ATE_HP_complex_float128";
10058 case DW_ATE_HP_floathpintel
:
10059 return "DW_ATE_HP_floathpintel";
10060 case DW_ATE_HP_imaginary_float80
:
10061 return "DW_ATE_HP_imaginary_float80";
10062 case DW_ATE_HP_imaginary_float128
:
10063 return "DW_ATE_HP_imaginary_float128";
10065 return "DW_ATE_<unknown>";
10069 /* Convert a DWARF call frame info operation to its string name. */
10073 dwarf_cfi_name (unsigned cfi_opc
)
10077 case DW_CFA_advance_loc
:
10078 return "DW_CFA_advance_loc";
10079 case DW_CFA_offset
:
10080 return "DW_CFA_offset";
10081 case DW_CFA_restore
:
10082 return "DW_CFA_restore";
10084 return "DW_CFA_nop";
10085 case DW_CFA_set_loc
:
10086 return "DW_CFA_set_loc";
10087 case DW_CFA_advance_loc1
:
10088 return "DW_CFA_advance_loc1";
10089 case DW_CFA_advance_loc2
:
10090 return "DW_CFA_advance_loc2";
10091 case DW_CFA_advance_loc4
:
10092 return "DW_CFA_advance_loc4";
10093 case DW_CFA_offset_extended
:
10094 return "DW_CFA_offset_extended";
10095 case DW_CFA_restore_extended
:
10096 return "DW_CFA_restore_extended";
10097 case DW_CFA_undefined
:
10098 return "DW_CFA_undefined";
10099 case DW_CFA_same_value
:
10100 return "DW_CFA_same_value";
10101 case DW_CFA_register
:
10102 return "DW_CFA_register";
10103 case DW_CFA_remember_state
:
10104 return "DW_CFA_remember_state";
10105 case DW_CFA_restore_state
:
10106 return "DW_CFA_restore_state";
10107 case DW_CFA_def_cfa
:
10108 return "DW_CFA_def_cfa";
10109 case DW_CFA_def_cfa_register
:
10110 return "DW_CFA_def_cfa_register";
10111 case DW_CFA_def_cfa_offset
:
10112 return "DW_CFA_def_cfa_offset";
10114 case DW_CFA_def_cfa_expression
:
10115 return "DW_CFA_def_cfa_expression";
10116 case DW_CFA_expression
:
10117 return "DW_CFA_expression";
10118 case DW_CFA_offset_extended_sf
:
10119 return "DW_CFA_offset_extended_sf";
10120 case DW_CFA_def_cfa_sf
:
10121 return "DW_CFA_def_cfa_sf";
10122 case DW_CFA_def_cfa_offset_sf
:
10123 return "DW_CFA_def_cfa_offset_sf";
10124 case DW_CFA_val_offset
:
10125 return "DW_CFA_val_offset";
10126 case DW_CFA_val_offset_sf
:
10127 return "DW_CFA_val_offset_sf";
10128 case DW_CFA_val_expression
:
10129 return "DW_CFA_val_expression";
10130 /* SGI/MIPS specific. */
10131 case DW_CFA_MIPS_advance_loc8
:
10132 return "DW_CFA_MIPS_advance_loc8";
10133 /* GNU extensions. */
10134 case DW_CFA_GNU_window_save
:
10135 return "DW_CFA_GNU_window_save";
10136 case DW_CFA_GNU_args_size
:
10137 return "DW_CFA_GNU_args_size";
10138 case DW_CFA_GNU_negative_offset_extended
:
10139 return "DW_CFA_GNU_negative_offset_extended";
10141 return "DW_CFA_<unknown>";
10147 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10151 print_spaces (indent
, f
);
10152 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10153 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10155 if (die
->parent
!= NULL
)
10157 print_spaces (indent
, f
);
10158 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10159 die
->parent
->offset
);
10162 print_spaces (indent
, f
);
10163 fprintf_unfiltered (f
, " has children: %s\n",
10164 dwarf_bool_name (die
->child
!= NULL
));
10166 print_spaces (indent
, f
);
10167 fprintf_unfiltered (f
, " attributes:\n");
10169 for (i
= 0; i
< die
->num_attrs
; ++i
)
10171 print_spaces (indent
, f
);
10172 fprintf_unfiltered (f
, " %s (%s) ",
10173 dwarf_attr_name (die
->attrs
[i
].name
),
10174 dwarf_form_name (die
->attrs
[i
].form
));
10176 switch (die
->attrs
[i
].form
)
10178 case DW_FORM_ref_addr
:
10180 fprintf_unfiltered (f
, "address: ");
10181 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10183 case DW_FORM_block2
:
10184 case DW_FORM_block4
:
10185 case DW_FORM_block
:
10186 case DW_FORM_block1
:
10187 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10192 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10193 (long) (DW_ADDR (&die
->attrs
[i
])));
10195 case DW_FORM_data1
:
10196 case DW_FORM_data2
:
10197 case DW_FORM_data4
:
10198 case DW_FORM_data8
:
10199 case DW_FORM_udata
:
10200 case DW_FORM_sdata
:
10201 fprintf_unfiltered (f
, "constant: %s",
10202 pulongest (DW_UNSND (&die
->attrs
[i
])));
10205 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10206 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10207 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10209 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10211 case DW_FORM_string
:
10213 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10214 DW_STRING (&die
->attrs
[i
])
10215 ? DW_STRING (&die
->attrs
[i
]) : "",
10216 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10219 if (DW_UNSND (&die
->attrs
[i
]))
10220 fprintf_unfiltered (f
, "flag: TRUE");
10222 fprintf_unfiltered (f
, "flag: FALSE");
10224 case DW_FORM_indirect
:
10225 /* the reader will have reduced the indirect form to
10226 the "base form" so this form should not occur */
10227 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10230 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10231 die
->attrs
[i
].form
);
10234 fprintf_unfiltered (f
, "\n");
10239 dump_die_for_error (struct die_info
*die
)
10241 dump_die_shallow (gdb_stderr
, 0, die
);
10245 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10247 int indent
= level
* 4;
10249 gdb_assert (die
!= NULL
);
10251 if (level
>= max_level
)
10254 dump_die_shallow (f
, indent
, die
);
10256 if (die
->child
!= NULL
)
10258 print_spaces (indent
, f
);
10259 fprintf_unfiltered (f
, " Children:");
10260 if (level
+ 1 < max_level
)
10262 fprintf_unfiltered (f
, "\n");
10263 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10267 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10271 if (die
->sibling
!= NULL
&& level
> 0)
10273 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10277 /* This is called from the pdie macro in gdbinit.in.
10278 It's not static so gcc will keep a copy callable from gdb. */
10281 dump_die (struct die_info
*die
, int max_level
)
10283 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10287 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10291 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10297 is_ref_attr (struct attribute
*attr
)
10299 switch (attr
->form
)
10301 case DW_FORM_ref_addr
:
10306 case DW_FORM_ref_udata
:
10313 static unsigned int
10314 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10316 if (is_ref_attr (attr
))
10317 return DW_ADDR (attr
);
10319 complaint (&symfile_complaints
,
10320 _("unsupported die ref attribute form: '%s'"),
10321 dwarf_form_name (attr
->form
));
10325 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10326 * the value held by the attribute is not constant. */
10329 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10331 if (attr
->form
== DW_FORM_sdata
)
10332 return DW_SND (attr
);
10333 else if (attr
->form
== DW_FORM_udata
10334 || attr
->form
== DW_FORM_data1
10335 || attr
->form
== DW_FORM_data2
10336 || attr
->form
== DW_FORM_data4
10337 || attr
->form
== DW_FORM_data8
)
10338 return DW_UNSND (attr
);
10341 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10342 dwarf_form_name (attr
->form
));
10343 return default_value
;
10347 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10348 unit and add it to our queue.
10349 The result is non-zero if PER_CU was queued, otherwise the result is zero
10350 meaning either PER_CU is already queued or it is already loaded. */
10353 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10354 struct dwarf2_per_cu_data
*per_cu
)
10356 /* Mark the dependence relation so that we don't flush PER_CU
10358 dwarf2_add_dependence (this_cu
, per_cu
);
10360 /* If it's already on the queue, we have nothing to do. */
10361 if (per_cu
->queued
)
10364 /* If the compilation unit is already loaded, just mark it as
10366 if (per_cu
->cu
!= NULL
)
10368 per_cu
->cu
->last_used
= 0;
10372 /* Add it to the queue. */
10373 queue_comp_unit (per_cu
, this_cu
->objfile
);
10378 /* Follow reference or signature attribute ATTR of SRC_DIE.
10379 On entry *REF_CU is the CU of SRC_DIE.
10380 On exit *REF_CU is the CU of the result. */
10382 static struct die_info
*
10383 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10384 struct dwarf2_cu
**ref_cu
)
10386 struct die_info
*die
;
10388 if (is_ref_attr (attr
))
10389 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10390 else if (attr
->form
== DW_FORM_sig8
)
10391 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10394 dump_die_for_error (src_die
);
10395 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10396 (*ref_cu
)->objfile
->name
);
10402 /* Follow reference attribute ATTR of SRC_DIE.
10403 On entry *REF_CU is the CU of SRC_DIE.
10404 On exit *REF_CU is the CU of the result. */
10406 static struct die_info
*
10407 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10408 struct dwarf2_cu
**ref_cu
)
10410 struct die_info
*die
;
10411 unsigned int offset
;
10412 struct die_info temp_die
;
10413 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10415 gdb_assert (cu
->per_cu
!= NULL
);
10417 offset
= dwarf2_get_ref_die_offset (attr
);
10419 if (cu
->per_cu
->from_debug_types
)
10421 /* .debug_types CUs cannot reference anything outside their CU.
10422 If they need to, they have to reference a signatured type via
10424 if (! offset_in_cu_p (&cu
->header
, offset
))
10428 else if (! offset_in_cu_p (&cu
->header
, offset
))
10430 struct dwarf2_per_cu_data
*per_cu
;
10431 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10433 /* If necessary, add it to the queue and load its DIEs. */
10434 if (maybe_queue_comp_unit (cu
, per_cu
))
10435 load_full_comp_unit (per_cu
, cu
->objfile
);
10437 target_cu
= per_cu
->cu
;
10442 *ref_cu
= target_cu
;
10443 temp_die
.offset
= offset
;
10444 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10450 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10451 "at 0x%x [in module %s]"),
10452 offset
, src_die
->offset
, cu
->objfile
->name
);
10455 /* Follow the signature attribute ATTR in SRC_DIE.
10456 On entry *REF_CU is the CU of SRC_DIE.
10457 On exit *REF_CU is the CU of the result. */
10459 static struct die_info
*
10460 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10461 struct dwarf2_cu
**ref_cu
)
10463 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10464 struct die_info temp_die
;
10465 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10466 struct dwarf2_cu
*sig_cu
;
10467 struct die_info
*die
;
10469 /* sig_type will be NULL if the signatured type is missing from
10471 if (sig_type
== NULL
)
10472 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10473 "at 0x%x [in module %s]"),
10474 src_die
->offset
, objfile
->name
);
10476 /* If necessary, add it to the queue and load its DIEs. */
10478 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10479 read_signatured_type (objfile
, sig_type
);
10481 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10483 sig_cu
= sig_type
->per_cu
.cu
;
10484 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10485 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10492 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10493 "at 0x%x [in module %s]"),
10494 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10497 /* Given an offset of a signatured type, return its signatured_type. */
10499 static struct signatured_type
*
10500 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10502 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10503 unsigned int length
, initial_length_size
;
10504 unsigned int sig_offset
;
10505 struct signatured_type find_entry
, *type_sig
;
10507 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10508 sig_offset
= (initial_length_size
10510 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10511 + 1 /*address_size*/);
10512 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10513 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10515 /* This is only used to lookup previously recorded types.
10516 If we didn't find it, it's our bug. */
10517 gdb_assert (type_sig
!= NULL
);
10518 gdb_assert (offset
== type_sig
->offset
);
10523 /* Read in signatured type at OFFSET and build its CU and die(s). */
10526 read_signatured_type_at_offset (struct objfile
*objfile
,
10527 unsigned int offset
)
10529 struct signatured_type
*type_sig
;
10531 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
10533 /* We have the section offset, but we need the signature to do the
10534 hash table lookup. */
10535 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10537 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10539 read_signatured_type (objfile
, type_sig
);
10541 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10544 /* Read in a signatured type and build its CU and DIEs. */
10547 read_signatured_type (struct objfile
*objfile
,
10548 struct signatured_type
*type_sig
)
10550 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10551 struct die_reader_specs reader_specs
;
10552 struct dwarf2_cu
*cu
;
10553 ULONGEST signature
;
10554 struct cleanup
*back_to
, *free_cu_cleanup
;
10555 struct attribute
*attr
;
10557 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10559 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10560 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10561 obstack_init (&cu
->comp_unit_obstack
);
10562 cu
->objfile
= objfile
;
10563 type_sig
->per_cu
.cu
= cu
;
10564 cu
->per_cu
= &type_sig
->per_cu
;
10566 /* If an error occurs while loading, release our storage. */
10567 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10569 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10570 types_ptr
, objfile
->obfd
);
10571 gdb_assert (signature
== type_sig
->signature
);
10574 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10578 &cu
->comp_unit_obstack
,
10579 hashtab_obstack_allocate
,
10580 dummy_obstack_deallocate
);
10582 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10583 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10585 init_cu_die_reader (&reader_specs
, cu
);
10587 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10590 /* We try not to read any attributes in this function, because not
10591 all objfiles needed for references have been loaded yet, and symbol
10592 table processing isn't initialized. But we have to set the CU language,
10593 or we won't be able to build types correctly. */
10594 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10596 set_cu_language (DW_UNSND (attr
), cu
);
10598 set_cu_language (language_minimal
, cu
);
10600 do_cleanups (back_to
);
10602 /* We've successfully allocated this compilation unit. Let our caller
10603 clean it up when finished with it. */
10604 discard_cleanups (free_cu_cleanup
);
10606 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10607 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10610 /* Decode simple location descriptions.
10611 Given a pointer to a dwarf block that defines a location, compute
10612 the location and return the value.
10614 NOTE drow/2003-11-18: This function is called in two situations
10615 now: for the address of static or global variables (partial symbols
10616 only) and for offsets into structures which are expected to be
10617 (more or less) constant. The partial symbol case should go away,
10618 and only the constant case should remain. That will let this
10619 function complain more accurately. A few special modes are allowed
10620 without complaint for global variables (for instance, global
10621 register values and thread-local values).
10623 A location description containing no operations indicates that the
10624 object is optimized out. The return value is 0 for that case.
10625 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10626 callers will only want a very basic result and this can become a
10629 Note that stack[0] is unused except as a default error return.
10630 Note that stack overflow is not yet handled. */
10633 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10635 struct objfile
*objfile
= cu
->objfile
;
10636 struct comp_unit_head
*cu_header
= &cu
->header
;
10638 int size
= blk
->size
;
10639 gdb_byte
*data
= blk
->data
;
10640 CORE_ADDR stack
[64];
10642 unsigned int bytes_read
, unsnd
;
10686 stack
[++stacki
] = op
- DW_OP_lit0
;
10721 stack
[++stacki
] = op
- DW_OP_reg0
;
10723 dwarf2_complex_location_expr_complaint ();
10727 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10729 stack
[++stacki
] = unsnd
;
10731 dwarf2_complex_location_expr_complaint ();
10735 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
10740 case DW_OP_const1u
:
10741 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
10745 case DW_OP_const1s
:
10746 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
10750 case DW_OP_const2u
:
10751 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
10755 case DW_OP_const2s
:
10756 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
10760 case DW_OP_const4u
:
10761 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
10765 case DW_OP_const4s
:
10766 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
10771 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
10777 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
10782 stack
[stacki
+ 1] = stack
[stacki
];
10787 stack
[stacki
- 1] += stack
[stacki
];
10791 case DW_OP_plus_uconst
:
10792 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10797 stack
[stacki
- 1] -= stack
[stacki
];
10802 /* If we're not the last op, then we definitely can't encode
10803 this using GDB's address_class enum. This is valid for partial
10804 global symbols, although the variable's address will be bogus
10807 dwarf2_complex_location_expr_complaint ();
10810 case DW_OP_GNU_push_tls_address
:
10811 /* The top of the stack has the offset from the beginning
10812 of the thread control block at which the variable is located. */
10813 /* Nothing should follow this operator, so the top of stack would
10815 /* This is valid for partial global symbols, but the variable's
10816 address will be bogus in the psymtab. */
10818 dwarf2_complex_location_expr_complaint ();
10821 case DW_OP_GNU_uninit
:
10825 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
10826 dwarf_stack_op_name (op
));
10827 return (stack
[stacki
]);
10830 return (stack
[stacki
]);
10833 /* memory allocation interface */
10835 static struct dwarf_block
*
10836 dwarf_alloc_block (struct dwarf2_cu
*cu
)
10838 struct dwarf_block
*blk
;
10840 blk
= (struct dwarf_block
*)
10841 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
10845 static struct abbrev_info
*
10846 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
10848 struct abbrev_info
*abbrev
;
10850 abbrev
= (struct abbrev_info
*)
10851 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
10852 memset (abbrev
, 0, sizeof (struct abbrev_info
));
10856 static struct die_info
*
10857 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
10859 struct die_info
*die
;
10860 size_t size
= sizeof (struct die_info
);
10863 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
10865 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
10866 memset (die
, 0, sizeof (struct die_info
));
10871 /* Macro support. */
10874 /* Return the full name of file number I in *LH's file name table.
10875 Use COMP_DIR as the name of the current directory of the
10876 compilation. The result is allocated using xmalloc; the caller is
10877 responsible for freeing it. */
10879 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
10881 /* Is the file number a valid index into the line header's file name
10882 table? Remember that file numbers start with one, not zero. */
10883 if (1 <= file
&& file
<= lh
->num_file_names
)
10885 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10887 if (IS_ABSOLUTE_PATH (fe
->name
))
10888 return xstrdup (fe
->name
);
10896 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10902 dir_len
= strlen (dir
);
10903 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
10904 strcpy (full_name
, dir
);
10905 full_name
[dir_len
] = '/';
10906 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
10910 return xstrdup (fe
->name
);
10915 /* The compiler produced a bogus file number. We can at least
10916 record the macro definitions made in the file, even if we
10917 won't be able to find the file by name. */
10918 char fake_name
[80];
10919 sprintf (fake_name
, "<bad macro file number %d>", file
);
10921 complaint (&symfile_complaints
,
10922 _("bad file number in macro information (%d)"),
10925 return xstrdup (fake_name
);
10930 static struct macro_source_file
*
10931 macro_start_file (int file
, int line
,
10932 struct macro_source_file
*current_file
,
10933 const char *comp_dir
,
10934 struct line_header
*lh
, struct objfile
*objfile
)
10936 /* The full name of this source file. */
10937 char *full_name
= file_full_name (file
, lh
, comp_dir
);
10939 /* We don't create a macro table for this compilation unit
10940 at all until we actually get a filename. */
10941 if (! pending_macros
)
10942 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
10943 objfile
->macro_cache
);
10945 if (! current_file
)
10946 /* If we have no current file, then this must be the start_file
10947 directive for the compilation unit's main source file. */
10948 current_file
= macro_set_main (pending_macros
, full_name
);
10950 current_file
= macro_include (current_file
, line
, full_name
);
10954 return current_file
;
10958 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
10959 followed by a null byte. */
10961 copy_string (const char *buf
, int len
)
10963 char *s
= xmalloc (len
+ 1);
10964 memcpy (s
, buf
, len
);
10971 static const char *
10972 consume_improper_spaces (const char *p
, const char *body
)
10976 complaint (&symfile_complaints
,
10977 _("macro definition contains spaces in formal argument list:\n`%s'"),
10989 parse_macro_definition (struct macro_source_file
*file
, int line
,
10994 /* The body string takes one of two forms. For object-like macro
10995 definitions, it should be:
10997 <macro name> " " <definition>
10999 For function-like macro definitions, it should be:
11001 <macro name> "() " <definition>
11003 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
11005 Spaces may appear only where explicitly indicated, and in the
11008 The Dwarf 2 spec says that an object-like macro's name is always
11009 followed by a space, but versions of GCC around March 2002 omit
11010 the space when the macro's definition is the empty string.
11012 The Dwarf 2 spec says that there should be no spaces between the
11013 formal arguments in a function-like macro's formal argument list,
11014 but versions of GCC around March 2002 include spaces after the
11018 /* Find the extent of the macro name. The macro name is terminated
11019 by either a space or null character (for an object-like macro) or
11020 an opening paren (for a function-like macro). */
11021 for (p
= body
; *p
; p
++)
11022 if (*p
== ' ' || *p
== '(')
11025 if (*p
== ' ' || *p
== '\0')
11027 /* It's an object-like macro. */
11028 int name_len
= p
- body
;
11029 char *name
= copy_string (body
, name_len
);
11030 const char *replacement
;
11033 replacement
= body
+ name_len
+ 1;
11036 dwarf2_macro_malformed_definition_complaint (body
);
11037 replacement
= body
+ name_len
;
11040 macro_define_object (file
, line
, name
, replacement
);
11044 else if (*p
== '(')
11046 /* It's a function-like macro. */
11047 char *name
= copy_string (body
, p
- body
);
11050 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
11054 p
= consume_improper_spaces (p
, body
);
11056 /* Parse the formal argument list. */
11057 while (*p
&& *p
!= ')')
11059 /* Find the extent of the current argument name. */
11060 const char *arg_start
= p
;
11062 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11065 if (! *p
|| p
== arg_start
)
11066 dwarf2_macro_malformed_definition_complaint (body
);
11069 /* Make sure argv has room for the new argument. */
11070 if (argc
>= argv_size
)
11073 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11076 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11079 p
= consume_improper_spaces (p
, body
);
11081 /* Consume the comma, if present. */
11086 p
= consume_improper_spaces (p
, body
);
11095 /* Perfectly formed definition, no complaints. */
11096 macro_define_function (file
, line
, name
,
11097 argc
, (const char **) argv
,
11099 else if (*p
== '\0')
11101 /* Complain, but do define it. */
11102 dwarf2_macro_malformed_definition_complaint (body
);
11103 macro_define_function (file
, line
, name
,
11104 argc
, (const char **) argv
,
11108 /* Just complain. */
11109 dwarf2_macro_malformed_definition_complaint (body
);
11112 /* Just complain. */
11113 dwarf2_macro_malformed_definition_complaint (body
);
11119 for (i
= 0; i
< argc
; i
++)
11125 dwarf2_macro_malformed_definition_complaint (body
);
11130 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11131 char *comp_dir
, bfd
*abfd
,
11132 struct dwarf2_cu
*cu
)
11134 gdb_byte
*mac_ptr
, *mac_end
;
11135 struct macro_source_file
*current_file
= 0;
11136 enum dwarf_macinfo_record_type macinfo_type
;
11137 int at_commandline
;
11139 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11140 &dwarf2_per_objfile
->macinfo
);
11141 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11143 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11147 /* First pass: Find the name of the base filename.
11148 This filename is needed in order to process all macros whose definition
11149 (or undefinition) comes from the command line. These macros are defined
11150 before the first DW_MACINFO_start_file entry, and yet still need to be
11151 associated to the base file.
11153 To determine the base file name, we scan the macro definitions until we
11154 reach the first DW_MACINFO_start_file entry. We then initialize
11155 CURRENT_FILE accordingly so that any macro definition found before the
11156 first DW_MACINFO_start_file can still be associated to the base file. */
11158 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11159 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11160 + dwarf2_per_objfile
->macinfo
.size
;
11164 /* Do we at least have room for a macinfo type byte? */
11165 if (mac_ptr
>= mac_end
)
11167 /* Complaint is printed during the second pass as GDB will probably
11168 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11172 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11175 switch (macinfo_type
)
11177 /* A zero macinfo type indicates the end of the macro
11182 case DW_MACINFO_define
:
11183 case DW_MACINFO_undef
:
11184 /* Only skip the data by MAC_PTR. */
11186 unsigned int bytes_read
;
11188 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11189 mac_ptr
+= bytes_read
;
11190 read_string (abfd
, mac_ptr
, &bytes_read
);
11191 mac_ptr
+= bytes_read
;
11195 case DW_MACINFO_start_file
:
11197 unsigned int bytes_read
;
11200 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11201 mac_ptr
+= bytes_read
;
11202 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11203 mac_ptr
+= bytes_read
;
11205 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11210 case DW_MACINFO_end_file
:
11211 /* No data to skip by MAC_PTR. */
11214 case DW_MACINFO_vendor_ext
:
11215 /* Only skip the data by MAC_PTR. */
11217 unsigned int bytes_read
;
11219 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11220 mac_ptr
+= bytes_read
;
11221 read_string (abfd
, mac_ptr
, &bytes_read
);
11222 mac_ptr
+= bytes_read
;
11229 } while (macinfo_type
!= 0 && current_file
== NULL
);
11231 /* Second pass: Process all entries.
11233 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11234 command-line macro definitions/undefinitions. This flag is unset when we
11235 reach the first DW_MACINFO_start_file entry. */
11237 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11239 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11240 GDB is still reading the definitions from command line. First
11241 DW_MACINFO_start_file will need to be ignored as it was already executed
11242 to create CURRENT_FILE for the main source holding also the command line
11243 definitions. On first met DW_MACINFO_start_file this flag is reset to
11244 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11246 at_commandline
= 1;
11250 /* Do we at least have room for a macinfo type byte? */
11251 if (mac_ptr
>= mac_end
)
11253 dwarf2_macros_too_long_complaint ();
11257 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11260 switch (macinfo_type
)
11262 /* A zero macinfo type indicates the end of the macro
11267 case DW_MACINFO_define
:
11268 case DW_MACINFO_undef
:
11270 unsigned int bytes_read
;
11274 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11275 mac_ptr
+= bytes_read
;
11276 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11277 mac_ptr
+= bytes_read
;
11279 if (! current_file
)
11281 /* DWARF violation as no main source is present. */
11282 complaint (&symfile_complaints
,
11283 _("debug info with no main source gives macro %s "
11285 macinfo_type
== DW_MACINFO_define
?
11287 macinfo_type
== DW_MACINFO_undef
?
11288 _("undefinition") :
11289 _("something-or-other"), line
, body
);
11292 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11293 complaint (&symfile_complaints
,
11294 _("debug info gives %s macro %s with %s line %d: %s"),
11295 at_commandline
? _("command-line") : _("in-file"),
11296 macinfo_type
== DW_MACINFO_define
?
11298 macinfo_type
== DW_MACINFO_undef
?
11299 _("undefinition") :
11300 _("something-or-other"),
11301 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11303 if (macinfo_type
== DW_MACINFO_define
)
11304 parse_macro_definition (current_file
, line
, body
);
11305 else if (macinfo_type
== DW_MACINFO_undef
)
11306 macro_undef (current_file
, line
, body
);
11310 case DW_MACINFO_start_file
:
11312 unsigned int bytes_read
;
11315 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11316 mac_ptr
+= bytes_read
;
11317 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11318 mac_ptr
+= bytes_read
;
11320 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11321 complaint (&symfile_complaints
,
11322 _("debug info gives source %d included "
11323 "from %s at %s line %d"),
11324 file
, at_commandline
? _("command-line") : _("file"),
11325 line
== 0 ? _("zero") : _("non-zero"), line
);
11327 if (at_commandline
)
11329 /* This DW_MACINFO_start_file was executed in the pass one. */
11330 at_commandline
= 0;
11333 current_file
= macro_start_file (file
, line
,
11334 current_file
, comp_dir
,
11339 case DW_MACINFO_end_file
:
11340 if (! current_file
)
11341 complaint (&symfile_complaints
,
11342 _("macro debug info has an unmatched `close_file' directive"));
11345 current_file
= current_file
->included_by
;
11346 if (! current_file
)
11348 enum dwarf_macinfo_record_type next_type
;
11350 /* GCC circa March 2002 doesn't produce the zero
11351 type byte marking the end of the compilation
11352 unit. Complain if it's not there, but exit no
11355 /* Do we at least have room for a macinfo type byte? */
11356 if (mac_ptr
>= mac_end
)
11358 dwarf2_macros_too_long_complaint ();
11362 /* We don't increment mac_ptr here, so this is just
11364 next_type
= read_1_byte (abfd
, mac_ptr
);
11365 if (next_type
!= 0)
11366 complaint (&symfile_complaints
,
11367 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11374 case DW_MACINFO_vendor_ext
:
11376 unsigned int bytes_read
;
11380 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11381 mac_ptr
+= bytes_read
;
11382 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11383 mac_ptr
+= bytes_read
;
11385 /* We don't recognize any vendor extensions. */
11389 } while (macinfo_type
!= 0);
11392 /* Check if the attribute's form is a DW_FORM_block*
11393 if so return true else false. */
11395 attr_form_is_block (struct attribute
*attr
)
11397 return (attr
== NULL
? 0 :
11398 attr
->form
== DW_FORM_block1
11399 || attr
->form
== DW_FORM_block2
11400 || attr
->form
== DW_FORM_block4
11401 || attr
->form
== DW_FORM_block
);
11404 /* Return non-zero if ATTR's value is a section offset --- classes
11405 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11406 You may use DW_UNSND (attr) to retrieve such offsets.
11408 Section 7.5.4, "Attribute Encodings", explains that no attribute
11409 may have a value that belongs to more than one of these classes; it
11410 would be ambiguous if we did, because we use the same forms for all
11413 attr_form_is_section_offset (struct attribute
*attr
)
11415 return (attr
->form
== DW_FORM_data4
11416 || attr
->form
== DW_FORM_data8
);
11420 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11421 zero otherwise. When this function returns true, you can apply
11422 dwarf2_get_attr_constant_value to it.
11424 However, note that for some attributes you must check
11425 attr_form_is_section_offset before using this test. DW_FORM_data4
11426 and DW_FORM_data8 are members of both the constant class, and of
11427 the classes that contain offsets into other debug sections
11428 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11429 that, if an attribute's can be either a constant or one of the
11430 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11431 taken as section offsets, not constants. */
11433 attr_form_is_constant (struct attribute
*attr
)
11435 switch (attr
->form
)
11437 case DW_FORM_sdata
:
11438 case DW_FORM_udata
:
11439 case DW_FORM_data1
:
11440 case DW_FORM_data2
:
11441 case DW_FORM_data4
:
11442 case DW_FORM_data8
:
11450 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11451 struct dwarf2_cu
*cu
)
11453 if (attr_form_is_section_offset (attr
)
11454 /* ".debug_loc" may not exist at all, or the offset may be outside
11455 the section. If so, fall through to the complaint in the
11457 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11459 struct dwarf2_loclist_baton
*baton
;
11461 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11462 sizeof (struct dwarf2_loclist_baton
));
11463 baton
->per_cu
= cu
->per_cu
;
11464 gdb_assert (baton
->per_cu
);
11466 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11467 &dwarf2_per_objfile
->loc
);
11469 /* We don't know how long the location list is, but make sure we
11470 don't run off the edge of the section. */
11471 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11472 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11473 baton
->base_address
= cu
->base_address
;
11474 if (cu
->base_known
== 0)
11475 complaint (&symfile_complaints
,
11476 _("Location list used without specifying the CU base address."));
11478 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11479 SYMBOL_LOCATION_BATON (sym
) = baton
;
11483 struct dwarf2_locexpr_baton
*baton
;
11485 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11486 sizeof (struct dwarf2_locexpr_baton
));
11487 baton
->per_cu
= cu
->per_cu
;
11488 gdb_assert (baton
->per_cu
);
11490 if (attr_form_is_block (attr
))
11492 /* Note that we're just copying the block's data pointer
11493 here, not the actual data. We're still pointing into the
11494 info_buffer for SYM's objfile; right now we never release
11495 that buffer, but when we do clean up properly this may
11497 baton
->size
= DW_BLOCK (attr
)->size
;
11498 baton
->data
= DW_BLOCK (attr
)->data
;
11502 dwarf2_invalid_attrib_class_complaint ("location description",
11503 SYMBOL_NATURAL_NAME (sym
));
11505 baton
->data
= NULL
;
11508 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11509 SYMBOL_LOCATION_BATON (sym
) = baton
;
11513 /* Return the OBJFILE associated with the compilation unit CU. */
11516 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11518 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11520 /* Return the master objfile, so that we can report and look up the
11521 correct file containing this variable. */
11522 if (objfile
->separate_debug_objfile_backlink
)
11523 objfile
= objfile
->separate_debug_objfile_backlink
;
11528 /* Return the address size given in the compilation unit header for CU. */
11531 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11534 return per_cu
->cu
->header
.addr_size
;
11537 /* If the CU is not currently read in, we re-read its header. */
11538 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11539 struct dwarf2_per_objfile
*per_objfile
11540 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11541 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11543 struct comp_unit_head cu_header
;
11544 memset (&cu_header
, 0, sizeof cu_header
);
11545 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11546 return cu_header
.addr_size
;
11550 /* Locate the .debug_info compilation unit from CU's objfile which contains
11551 the DIE at OFFSET. Raises an error on failure. */
11553 static struct dwarf2_per_cu_data
*
11554 dwarf2_find_containing_comp_unit (unsigned int offset
,
11555 struct objfile
*objfile
)
11557 struct dwarf2_per_cu_data
*this_cu
;
11561 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11564 int mid
= low
+ (high
- low
) / 2;
11565 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11570 gdb_assert (low
== high
);
11571 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11574 error (_("Dwarf Error: could not find partial DIE containing "
11575 "offset 0x%lx [in module %s]"),
11576 (long) offset
, bfd_get_filename (objfile
->obfd
));
11578 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11579 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11583 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11584 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11585 && offset
>= this_cu
->offset
+ this_cu
->length
)
11586 error (_("invalid dwarf2 offset %u"), offset
);
11587 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11592 /* Locate the compilation unit from OBJFILE which is located at exactly
11593 OFFSET. Raises an error on failure. */
11595 static struct dwarf2_per_cu_data
*
11596 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11598 struct dwarf2_per_cu_data
*this_cu
;
11599 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11600 if (this_cu
->offset
!= offset
)
11601 error (_("no compilation unit with offset %u."), offset
);
11605 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11607 static struct dwarf2_cu
*
11608 alloc_one_comp_unit (struct objfile
*objfile
)
11610 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11611 cu
->objfile
= objfile
;
11612 obstack_init (&cu
->comp_unit_obstack
);
11616 /* Release one cached compilation unit, CU. We unlink it from the tree
11617 of compilation units, but we don't remove it from the read_in_chain;
11618 the caller is responsible for that.
11619 NOTE: DATA is a void * because this function is also used as a
11620 cleanup routine. */
11623 free_one_comp_unit (void *data
)
11625 struct dwarf2_cu
*cu
= data
;
11627 if (cu
->per_cu
!= NULL
)
11628 cu
->per_cu
->cu
= NULL
;
11631 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11636 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11637 when we're finished with it. We can't free the pointer itself, but be
11638 sure to unlink it from the cache. Also release any associated storage
11639 and perform cache maintenance.
11641 Only used during partial symbol parsing. */
11644 free_stack_comp_unit (void *data
)
11646 struct dwarf2_cu
*cu
= data
;
11648 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11649 cu
->partial_dies
= NULL
;
11651 if (cu
->per_cu
!= NULL
)
11653 /* This compilation unit is on the stack in our caller, so we
11654 should not xfree it. Just unlink it. */
11655 cu
->per_cu
->cu
= NULL
;
11658 /* If we had a per-cu pointer, then we may have other compilation
11659 units loaded, so age them now. */
11660 age_cached_comp_units ();
11664 /* Free all cached compilation units. */
11667 free_cached_comp_units (void *data
)
11669 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11671 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11672 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11673 while (per_cu
!= NULL
)
11675 struct dwarf2_per_cu_data
*next_cu
;
11677 next_cu
= per_cu
->cu
->read_in_chain
;
11679 free_one_comp_unit (per_cu
->cu
);
11680 *last_chain
= next_cu
;
11686 /* Increase the age counter on each cached compilation unit, and free
11687 any that are too old. */
11690 age_cached_comp_units (void)
11692 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11694 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
11695 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11696 while (per_cu
!= NULL
)
11698 per_cu
->cu
->last_used
++;
11699 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
11700 dwarf2_mark (per_cu
->cu
);
11701 per_cu
= per_cu
->cu
->read_in_chain
;
11704 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11705 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11706 while (per_cu
!= NULL
)
11708 struct dwarf2_per_cu_data
*next_cu
;
11710 next_cu
= per_cu
->cu
->read_in_chain
;
11712 if (!per_cu
->cu
->mark
)
11714 free_one_comp_unit (per_cu
->cu
);
11715 *last_chain
= next_cu
;
11718 last_chain
= &per_cu
->cu
->read_in_chain
;
11724 /* Remove a single compilation unit from the cache. */
11727 free_one_cached_comp_unit (void *target_cu
)
11729 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11731 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11732 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11733 while (per_cu
!= NULL
)
11735 struct dwarf2_per_cu_data
*next_cu
;
11737 next_cu
= per_cu
->cu
->read_in_chain
;
11739 if (per_cu
->cu
== target_cu
)
11741 free_one_comp_unit (per_cu
->cu
);
11742 *last_chain
= next_cu
;
11746 last_chain
= &per_cu
->cu
->read_in_chain
;
11752 /* Release all extra memory associated with OBJFILE. */
11755 dwarf2_free_objfile (struct objfile
*objfile
)
11757 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
11759 if (dwarf2_per_objfile
== NULL
)
11762 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11763 free_cached_comp_units (NULL
);
11765 /* Everything else should be on the objfile obstack. */
11768 /* A pair of DIE offset and GDB type pointer. We store these
11769 in a hash table separate from the DIEs, and preserve them
11770 when the DIEs are flushed out of cache. */
11772 struct dwarf2_offset_and_type
11774 unsigned int offset
;
11778 /* Hash function for a dwarf2_offset_and_type. */
11781 offset_and_type_hash (const void *item
)
11783 const struct dwarf2_offset_and_type
*ofs
= item
;
11784 return ofs
->offset
;
11787 /* Equality function for a dwarf2_offset_and_type. */
11790 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
11792 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
11793 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
11794 return ofs_lhs
->offset
== ofs_rhs
->offset
;
11797 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11798 table if necessary. For convenience, return TYPE. */
11800 static struct type
*
11801 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11803 struct dwarf2_offset_and_type
**slot
, ofs
;
11805 /* For Ada types, make sure that the gnat-specific data is always
11806 initialized (if not already set). There are a few types where
11807 we should not be doing so, because the type-specific area is
11808 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11809 where the type-specific area is used to store the floatformat).
11810 But this is not a problem, because the gnat-specific information
11811 is actually not needed for these types. */
11812 if (need_gnat_info (cu
)
11813 && TYPE_CODE (type
) != TYPE_CODE_FUNC
11814 && TYPE_CODE (type
) != TYPE_CODE_FLT
11815 && !HAVE_GNAT_AUX_INFO (type
))
11816 INIT_GNAT_SPECIFIC (type
);
11818 if (cu
->type_hash
== NULL
)
11820 gdb_assert (cu
->per_cu
!= NULL
);
11821 cu
->per_cu
->type_hash
11822 = htab_create_alloc_ex (cu
->header
.length
/ 24,
11823 offset_and_type_hash
,
11824 offset_and_type_eq
,
11826 &cu
->objfile
->objfile_obstack
,
11827 hashtab_obstack_allocate
,
11828 dummy_obstack_deallocate
);
11829 cu
->type_hash
= cu
->per_cu
->type_hash
;
11832 ofs
.offset
= die
->offset
;
11834 slot
= (struct dwarf2_offset_and_type
**)
11835 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
11836 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
11841 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
11842 not have a saved type. */
11844 static struct type
*
11845 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11847 struct dwarf2_offset_and_type
*slot
, ofs
;
11848 htab_t type_hash
= cu
->type_hash
;
11850 if (type_hash
== NULL
)
11853 ofs
.offset
= die
->offset
;
11854 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
11861 /* Add a dependence relationship from CU to REF_PER_CU. */
11864 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
11865 struct dwarf2_per_cu_data
*ref_per_cu
)
11869 if (cu
->dependencies
== NULL
)
11871 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
11872 NULL
, &cu
->comp_unit_obstack
,
11873 hashtab_obstack_allocate
,
11874 dummy_obstack_deallocate
);
11876 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
11878 *slot
= ref_per_cu
;
11881 /* Subroutine of dwarf2_mark to pass to htab_traverse.
11882 Set the mark field in every compilation unit in the
11883 cache that we must keep because we are keeping CU. */
11886 dwarf2_mark_helper (void **slot
, void *data
)
11888 struct dwarf2_per_cu_data
*per_cu
;
11890 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
11891 if (per_cu
->cu
->mark
)
11893 per_cu
->cu
->mark
= 1;
11895 if (per_cu
->cu
->dependencies
!= NULL
)
11896 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11901 /* Set the mark field in CU and in every other compilation unit in the
11902 cache that we must keep because we are keeping CU. */
11905 dwarf2_mark (struct dwarf2_cu
*cu
)
11910 if (cu
->dependencies
!= NULL
)
11911 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11915 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
11919 per_cu
->cu
->mark
= 0;
11920 per_cu
= per_cu
->cu
->read_in_chain
;
11924 /* Trivial hash function for partial_die_info: the hash value of a DIE
11925 is its offset in .debug_info for this objfile. */
11928 partial_die_hash (const void *item
)
11930 const struct partial_die_info
*part_die
= item
;
11931 return part_die
->offset
;
11934 /* Trivial comparison function for partial_die_info structures: two DIEs
11935 are equal if they have the same offset. */
11938 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
11940 const struct partial_die_info
*part_die_lhs
= item_lhs
;
11941 const struct partial_die_info
*part_die_rhs
= item_rhs
;
11942 return part_die_lhs
->offset
== part_die_rhs
->offset
;
11945 static struct cmd_list_element
*set_dwarf2_cmdlist
;
11946 static struct cmd_list_element
*show_dwarf2_cmdlist
;
11949 set_dwarf2_cmd (char *args
, int from_tty
)
11951 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
11955 show_dwarf2_cmd (char *args
, int from_tty
)
11957 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
11960 /* If section described by INFO was mmapped, munmap it now. */
11963 munmap_section_buffer (struct dwarf2_section_info
*info
)
11965 if (info
->was_mmapped
)
11968 intptr_t begin
= (intptr_t) info
->buffer
;
11969 intptr_t map_begin
= begin
& ~(pagesize
- 1);
11970 size_t map_length
= info
->size
+ begin
- map_begin
;
11971 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
11973 /* Without HAVE_MMAP, we should never be here to begin with. */
11979 /* munmap debug sections for OBJFILE, if necessary. */
11982 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
11984 struct dwarf2_per_objfile
*data
= d
;
11985 munmap_section_buffer (&data
->info
);
11986 munmap_section_buffer (&data
->abbrev
);
11987 munmap_section_buffer (&data
->line
);
11988 munmap_section_buffer (&data
->str
);
11989 munmap_section_buffer (&data
->macinfo
);
11990 munmap_section_buffer (&data
->ranges
);
11991 munmap_section_buffer (&data
->loc
);
11992 munmap_section_buffer (&data
->frame
);
11993 munmap_section_buffer (&data
->eh_frame
);
11996 void _initialize_dwarf2_read (void);
11999 _initialize_dwarf2_read (void)
12001 dwarf2_objfile_data_key
12002 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
12004 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
12005 Set DWARF 2 specific variables.\n\
12006 Configure DWARF 2 variables such as the cache size"),
12007 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
12008 0/*allow-unknown*/, &maintenance_set_cmdlist
);
12010 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
12011 Show DWARF 2 specific variables\n\
12012 Show DWARF 2 variables such as the cache size"),
12013 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
12014 0/*allow-unknown*/, &maintenance_show_cmdlist
);
12016 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
12017 &dwarf2_max_cache_age
, _("\
12018 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
12019 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12020 A higher limit means that cached compilation units will be stored\n\
12021 in memory longer, and more total memory will be used. Zero disables\n\
12022 caching, which can slow down startup."),
12024 show_dwarf2_max_cache_age
,
12025 &set_dwarf2_cmdlist
,
12026 &show_dwarf2_cmdlist
);
12028 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
12029 Set debugging of the dwarf2 DIE reader."), _("\
12030 Show debugging of the dwarf2 DIE reader."), _("\
12031 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12032 The value is the maximum depth to print."),
12035 &setdebuglist
, &showdebuglist
);