1 /* DWARF 2 debugging format support for GDB.
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
8 Inc. with support from Florida State University (under contract
9 with the Ada Joint Program Office), and Silicon Graphics, Inc.
10 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
11 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
14 This file is part of GDB.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 3 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>. */
37 #include "expression.h"
38 #include "filenames.h" /* for DOSish file names */
41 #include "complaints.h"
43 #include "dwarf2expr.h"
44 #include "dwarf2loc.h"
45 #include "cp-support.h"
51 #include "typeprint.h"
56 #include "gdb_string.h"
57 #include "gdb_assert.h"
58 #include <sys/types.h>
65 #define MAP_FAILED ((void *) -1)
70 /* .debug_info header for a compilation unit
71 Because of alignment constraints, this structure has padding and cannot
72 be mapped directly onto the beginning of the .debug_info section. */
73 typedef struct comp_unit_header
75 unsigned int length
; /* length of the .debug_info
77 unsigned short version
; /* version number -- 2 for DWARF
79 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
80 unsigned char addr_size
; /* byte size of an address -- 4 */
83 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
86 /* .debug_line statement program prologue
87 Because of alignment constraints, this structure has padding and cannot
88 be mapped directly onto the beginning of the .debug_info section. */
89 typedef struct statement_prologue
91 unsigned int total_length
; /* byte length of the statement
93 unsigned short version
; /* version number -- 2 for DWARF
95 unsigned int prologue_length
; /* # bytes between prologue &
97 unsigned char minimum_instruction_length
; /* byte size of
99 unsigned char default_is_stmt
; /* initial value of is_stmt
102 unsigned char line_range
;
103 unsigned char opcode_base
; /* number assigned to first special
105 unsigned char *standard_opcode_lengths
;
109 /* When non-zero, dump DIEs after they are read in. */
110 static int dwarf2_die_debug
= 0;
114 /* When set, the file that we're processing is known to have debugging
115 info for C++ namespaces. GCC 3.3.x did not produce this information,
116 but later versions do. */
118 static int processing_has_namespace_info
;
120 static const struct objfile_data
*dwarf2_objfile_data_key
;
122 struct dwarf2_section_info
128 /* True if we have tried to read this section. */
132 struct dwarf2_per_objfile
134 struct dwarf2_section_info info
;
135 struct dwarf2_section_info abbrev
;
136 struct dwarf2_section_info line
;
137 struct dwarf2_section_info loc
;
138 struct dwarf2_section_info macinfo
;
139 struct dwarf2_section_info str
;
140 struct dwarf2_section_info ranges
;
141 struct dwarf2_section_info types
;
142 struct dwarf2_section_info frame
;
143 struct dwarf2_section_info eh_frame
;
146 struct objfile
*objfile
;
148 /* A list of all the compilation units. This is used to locate
149 the target compilation unit of a particular reference. */
150 struct dwarf2_per_cu_data
**all_comp_units
;
152 /* The number of compilation units in ALL_COMP_UNITS. */
155 /* A chain of compilation units that are currently read in, so that
156 they can be freed later. */
157 struct dwarf2_per_cu_data
*read_in_chain
;
159 /* A table mapping .debug_types signatures to its signatured_type entry.
160 This is NULL if the .debug_types section hasn't been read in yet. */
161 htab_t signatured_types
;
163 /* A flag indicating wether this objfile has a section loaded at a
165 int has_section_at_zero
;
168 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
170 /* names of the debugging sections */
172 /* Note that if the debugging section has been compressed, it might
173 have a name like .zdebug_info. */
175 #define INFO_SECTION "debug_info"
176 #define ABBREV_SECTION "debug_abbrev"
177 #define LINE_SECTION "debug_line"
178 #define LOC_SECTION "debug_loc"
179 #define MACINFO_SECTION "debug_macinfo"
180 #define STR_SECTION "debug_str"
181 #define RANGES_SECTION "debug_ranges"
182 #define TYPES_SECTION "debug_types"
183 #define FRAME_SECTION "debug_frame"
184 #define EH_FRAME_SECTION "eh_frame"
186 /* local data types */
188 /* We hold several abbreviation tables in memory at the same time. */
189 #ifndef ABBREV_HASH_SIZE
190 #define ABBREV_HASH_SIZE 121
193 /* The data in a compilation unit header, after target2host
194 translation, looks like this. */
195 struct comp_unit_head
199 unsigned char addr_size
;
200 unsigned char signed_addr_p
;
201 unsigned int abbrev_offset
;
203 /* Size of file offsets; either 4 or 8. */
204 unsigned int offset_size
;
206 /* Size of the length field; either 4 or 12. */
207 unsigned int initial_length_size
;
209 /* Offset to the first byte of this compilation unit header in the
210 .debug_info section, for resolving relative reference dies. */
213 /* Offset to first die in this cu from the start of the cu.
214 This will be the first byte following the compilation unit header. */
215 unsigned int first_die_offset
;
218 /* Internal state when decoding a particular compilation unit. */
221 /* The objfile containing this compilation unit. */
222 struct objfile
*objfile
;
224 /* The header of the compilation unit. */
225 struct comp_unit_head header
;
227 /* Base address of this compilation unit. */
228 CORE_ADDR base_address
;
230 /* Non-zero if base_address has been set. */
233 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
235 /* The language we are debugging. */
236 enum language language
;
237 const struct language_defn
*language_defn
;
239 const char *producer
;
241 /* The generic symbol table building routines have separate lists for
242 file scope symbols and all all other scopes (local scopes). So
243 we need to select the right one to pass to add_symbol_to_list().
244 We do it by keeping a pointer to the correct list in list_in_scope.
246 FIXME: The original dwarf code just treated the file scope as the
247 first local scope, and all other local scopes as nested local
248 scopes, and worked fine. Check to see if we really need to
249 distinguish these in buildsym.c. */
250 struct pending
**list_in_scope
;
252 /* DWARF abbreviation table associated with this compilation unit. */
253 struct abbrev_info
**dwarf2_abbrevs
;
255 /* Storage for the abbrev table. */
256 struct obstack abbrev_obstack
;
258 /* Hash table holding all the loaded partial DIEs. */
261 /* Storage for things with the same lifetime as this read-in compilation
262 unit, including partial DIEs. */
263 struct obstack comp_unit_obstack
;
265 /* When multiple dwarf2_cu structures are living in memory, this field
266 chains them all together, so that they can be released efficiently.
267 We will probably also want a generation counter so that most-recently-used
268 compilation units are cached... */
269 struct dwarf2_per_cu_data
*read_in_chain
;
271 /* Backchain to our per_cu entry if the tree has been built. */
272 struct dwarf2_per_cu_data
*per_cu
;
274 /* Pointer to the die -> type map. Although it is stored
275 permanently in per_cu, we copy it here to avoid double
279 /* How many compilation units ago was this CU last referenced? */
282 /* A hash table of die offsets for following references. */
285 /* Full DIEs if read in. */
286 struct die_info
*dies
;
288 /* A set of pointers to dwarf2_per_cu_data objects for compilation
289 units referenced by this one. Only set during full symbol processing;
290 partial symbol tables do not have dependencies. */
293 /* Header data from the line table, during full symbol processing. */
294 struct line_header
*line_header
;
296 /* Mark used when releasing cached dies. */
297 unsigned int mark
: 1;
299 /* This flag will be set if this compilation unit might include
300 inter-compilation-unit references. */
301 unsigned int has_form_ref_addr
: 1;
303 /* This flag will be set if this compilation unit includes any
304 DW_TAG_namespace DIEs. If we know that there are explicit
305 DIEs for namespaces, we don't need to try to infer them
306 from mangled names. */
307 unsigned int has_namespace_info
: 1;
310 /* Persistent data held for a compilation unit, even when not
311 processing it. We put a pointer to this structure in the
312 read_symtab_private field of the psymtab. If we encounter
313 inter-compilation-unit references, we also maintain a sorted
314 list of all compilation units. */
316 struct dwarf2_per_cu_data
318 /* The start offset and length of this compilation unit. 2**29-1
319 bytes should suffice to store the length of any compilation unit
320 - if it doesn't, GDB will fall over anyway.
321 NOTE: Unlike comp_unit_head.length, this length includes
322 initial_length_size. */
324 unsigned int length
: 29;
326 /* Flag indicating this compilation unit will be read in before
327 any of the current compilation units are processed. */
328 unsigned int queued
: 1;
330 /* This flag will be set if we need to load absolutely all DIEs
331 for this compilation unit, instead of just the ones we think
332 are interesting. It gets set if we look for a DIE in the
333 hash table and don't find it. */
334 unsigned int load_all_dies
: 1;
336 /* Non-zero if this CU is from .debug_types.
337 Otherwise it's from .debug_info. */
338 unsigned int from_debug_types
: 1;
340 /* Set iff currently read in. */
341 struct dwarf2_cu
*cu
;
343 /* If full symbols for this CU have been read in, then this field
344 holds a map of DIE offsets to types. It isn't always possible
345 to reconstruct this information later, so we have to preserve
349 /* The partial symbol table associated with this compilation unit,
350 or NULL for partial units (which do not have an associated
352 struct partial_symtab
*psymtab
;
355 /* Entry in the signatured_types hash table. */
357 struct signatured_type
361 /* Offset in .debug_types of the TU (type_unit) for this type. */
364 /* Offset in .debug_types of the type defined by this TU. */
365 unsigned int type_offset
;
367 /* The CU(/TU) of this type. */
368 struct dwarf2_per_cu_data per_cu
;
371 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
372 which are used for both .debug_info and .debug_types dies.
373 All parameters here are unchanging for the life of the call.
374 This struct exists to abstract away the constant parameters of
377 struct die_reader_specs
379 /* The bfd of this objfile. */
382 /* The CU of the DIE we are parsing. */
383 struct dwarf2_cu
*cu
;
385 /* Pointer to start of section buffer.
386 This is either the start of .debug_info or .debug_types. */
387 const gdb_byte
*buffer
;
390 /* The line number information for a compilation unit (found in the
391 .debug_line section) begins with a "statement program header",
392 which contains the following information. */
395 unsigned int total_length
;
396 unsigned short version
;
397 unsigned int header_length
;
398 unsigned char minimum_instruction_length
;
399 unsigned char default_is_stmt
;
401 unsigned char line_range
;
402 unsigned char opcode_base
;
404 /* standard_opcode_lengths[i] is the number of operands for the
405 standard opcode whose value is i. This means that
406 standard_opcode_lengths[0] is unused, and the last meaningful
407 element is standard_opcode_lengths[opcode_base - 1]. */
408 unsigned char *standard_opcode_lengths
;
410 /* The include_directories table. NOTE! These strings are not
411 allocated with xmalloc; instead, they are pointers into
412 debug_line_buffer. If you try to free them, `free' will get
414 unsigned int num_include_dirs
, include_dirs_size
;
417 /* The file_names table. NOTE! These strings are not allocated
418 with xmalloc; instead, they are pointers into debug_line_buffer.
419 Don't try to free them directly. */
420 unsigned int num_file_names
, file_names_size
;
424 unsigned int dir_index
;
425 unsigned int mod_time
;
427 int included_p
; /* Non-zero if referenced by the Line Number Program. */
428 struct symtab
*symtab
; /* The associated symbol table, if any. */
431 /* The start and end of the statement program following this
432 header. These point into dwarf2_per_objfile->line_buffer. */
433 gdb_byte
*statement_program_start
, *statement_program_end
;
436 /* When we construct a partial symbol table entry we only
437 need this much information. */
438 struct partial_die_info
440 /* Offset of this DIE. */
443 /* DWARF-2 tag for this DIE. */
444 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
446 /* Assorted flags describing the data found in this DIE. */
447 unsigned int has_children
: 1;
448 unsigned int is_external
: 1;
449 unsigned int is_declaration
: 1;
450 unsigned int has_type
: 1;
451 unsigned int has_specification
: 1;
452 unsigned int has_pc_info
: 1;
454 /* Flag set if the SCOPE field of this structure has been
456 unsigned int scope_set
: 1;
458 /* Flag set if the DIE has a byte_size attribute. */
459 unsigned int has_byte_size
: 1;
461 /* The name of this DIE. Normally the value of DW_AT_name, but
462 sometimes a default name for unnamed DIEs. */
465 /* The scope to prepend to our children. This is generally
466 allocated on the comp_unit_obstack, so will disappear
467 when this compilation unit leaves the cache. */
470 /* The location description associated with this DIE, if any. */
471 struct dwarf_block
*locdesc
;
473 /* If HAS_PC_INFO, the PC range associated with this DIE. */
477 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
478 DW_AT_sibling, if any. */
481 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
482 DW_AT_specification (or DW_AT_abstract_origin or
484 unsigned int spec_offset
;
486 /* Pointers to this DIE's parent, first child, and next sibling,
488 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
491 /* This data structure holds the information of an abbrev. */
494 unsigned int number
; /* number identifying abbrev */
495 enum dwarf_tag tag
; /* dwarf tag */
496 unsigned short has_children
; /* boolean */
497 unsigned short num_attrs
; /* number of attributes */
498 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
499 struct abbrev_info
*next
; /* next in chain */
504 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
505 ENUM_BITFIELD(dwarf_form
) form
: 16;
508 /* Attributes have a name and a value */
511 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
512 ENUM_BITFIELD(dwarf_form
) form
: 15;
514 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
515 field should be in u.str (existing only for DW_STRING) but it is kept
516 here for better struct attribute alignment. */
517 unsigned int string_is_canonical
: 1;
522 struct dwarf_block
*blk
;
526 struct signatured_type
*signatured_type
;
531 /* This data structure holds a complete die structure. */
534 /* DWARF-2 tag for this DIE. */
535 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
537 /* Number of attributes */
538 unsigned short num_attrs
;
543 /* Offset in .debug_info or .debug_types section. */
546 /* The dies in a compilation unit form an n-ary tree. PARENT
547 points to this die's parent; CHILD points to the first child of
548 this node; and all the children of a given node are chained
549 together via their SIBLING fields, terminated by a die whose
551 struct die_info
*child
; /* Its first child, if any. */
552 struct die_info
*sibling
; /* Its next sibling, if any. */
553 struct die_info
*parent
; /* Its parent, if any. */
555 /* An array of attributes, with NUM_ATTRS elements. There may be
556 zero, but it's not common and zero-sized arrays are not
557 sufficiently portable C. */
558 struct attribute attrs
[1];
561 struct function_range
564 CORE_ADDR lowpc
, highpc
;
566 struct function_range
*next
;
569 /* Get at parts of an attribute structure */
571 #define DW_STRING(attr) ((attr)->u.str)
572 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
573 #define DW_UNSND(attr) ((attr)->u.unsnd)
574 #define DW_BLOCK(attr) ((attr)->u.blk)
575 #define DW_SND(attr) ((attr)->u.snd)
576 #define DW_ADDR(attr) ((attr)->u.addr)
577 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
579 /* Blocks are a bunch of untyped bytes. */
586 #ifndef ATTR_ALLOC_CHUNK
587 #define ATTR_ALLOC_CHUNK 4
590 /* Allocate fields for structs, unions and enums in this size. */
591 #ifndef DW_FIELD_ALLOC_CHUNK
592 #define DW_FIELD_ALLOC_CHUNK 4
595 /* A zeroed version of a partial die for initialization purposes. */
596 static struct partial_die_info zeroed_partial_die
;
598 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
599 but this would require a corresponding change in unpack_field_as_long
601 static int bits_per_byte
= 8;
603 /* The routines that read and process dies for a C struct or C++ class
604 pass lists of data member fields and lists of member function fields
605 in an instance of a field_info structure, as defined below. */
608 /* List of data member and baseclasses fields. */
611 struct nextfield
*next
;
616 *fields
, *baseclasses
;
618 /* Number of fields (including baseclasses). */
621 /* Number of baseclasses. */
624 /* Set if the accesibility of one of the fields is not public. */
625 int non_public_fields
;
627 /* Member function fields array, entries are allocated in the order they
628 are encountered in the object file. */
631 struct nextfnfield
*next
;
632 struct fn_field fnfield
;
636 /* Member function fieldlist array, contains name of possibly overloaded
637 member function, number of overloaded member functions and a pointer
638 to the head of the member function field chain. */
643 struct nextfnfield
*head
;
647 /* Number of entries in the fnfieldlists array. */
651 /* One item on the queue of compilation units to read in full symbols
653 struct dwarf2_queue_item
655 struct dwarf2_per_cu_data
*per_cu
;
656 struct dwarf2_queue_item
*next
;
659 /* The current queue. */
660 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
662 /* Loaded secondary compilation units are kept in memory until they
663 have not been referenced for the processing of this many
664 compilation units. Set this to zero to disable caching. Cache
665 sizes of up to at least twenty will improve startup time for
666 typical inter-CU-reference binaries, at an obvious memory cost. */
667 static int dwarf2_max_cache_age
= 5;
669 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
670 struct cmd_list_element
*c
, const char *value
)
672 fprintf_filtered (file
, _("\
673 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
678 /* Various complaints about symbol reading that don't abort the process */
681 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
683 complaint (&symfile_complaints
,
684 _("statement list doesn't fit in .debug_line section"));
688 dwarf2_debug_line_missing_file_complaint (void)
690 complaint (&symfile_complaints
,
691 _(".debug_line section has line data without a file"));
695 dwarf2_debug_line_missing_end_sequence_complaint (void)
697 complaint (&symfile_complaints
,
698 _(".debug_line section has line program sequence without an end"));
702 dwarf2_complex_location_expr_complaint (void)
704 complaint (&symfile_complaints
, _("location expression too complex"));
708 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
711 complaint (&symfile_complaints
,
712 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
717 dwarf2_macros_too_long_complaint (void)
719 complaint (&symfile_complaints
,
720 _("macro info runs off end of `.debug_macinfo' section"));
724 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
726 complaint (&symfile_complaints
,
727 _("macro debug info contains a malformed macro definition:\n`%s'"),
732 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
734 complaint (&symfile_complaints
,
735 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
738 /* local function prototypes */
740 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
742 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
745 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
747 struct partial_symtab
*);
749 static void dwarf2_build_psymtabs_hard (struct objfile
*);
751 static void scan_partial_symbols (struct partial_die_info
*,
752 CORE_ADDR
*, CORE_ADDR
*,
753 int, struct dwarf2_cu
*);
755 static void add_partial_symbol (struct partial_die_info
*,
758 static void add_partial_namespace (struct partial_die_info
*pdi
,
759 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
760 int need_pc
, struct dwarf2_cu
*cu
);
762 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
763 CORE_ADDR
*highpc
, int need_pc
,
764 struct dwarf2_cu
*cu
);
766 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
767 struct dwarf2_cu
*cu
);
769 static void add_partial_subprogram (struct partial_die_info
*pdi
,
770 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
771 int need_pc
, struct dwarf2_cu
*cu
);
773 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
774 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
775 bfd
*abfd
, struct dwarf2_cu
*cu
);
777 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
779 static void psymtab_to_symtab_1 (struct partial_symtab
*);
781 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
783 static void dwarf2_free_abbrev_table (void *);
785 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
788 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
791 static struct partial_die_info
*load_partial_dies (bfd
*,
792 gdb_byte
*, gdb_byte
*,
793 int, struct dwarf2_cu
*);
795 static gdb_byte
*read_partial_die (struct partial_die_info
*,
796 struct abbrev_info
*abbrev
,
798 gdb_byte
*, gdb_byte
*,
801 static struct partial_die_info
*find_partial_die (unsigned int,
804 static void fixup_partial_die (struct partial_die_info
*,
807 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
808 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
810 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
811 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
813 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
815 static int read_1_signed_byte (bfd
*, gdb_byte
*);
817 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
819 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
821 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
823 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
826 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
828 static LONGEST read_checked_initial_length_and_offset
829 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
830 unsigned int *, unsigned int *);
832 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
835 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
837 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
839 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
841 static char *read_indirect_string (bfd
*, gdb_byte
*,
842 const struct comp_unit_head
*,
845 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
847 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
849 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
851 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
853 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
856 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
860 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
861 struct dwarf2_cu
*cu
);
863 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
865 static struct die_info
*die_specification (struct die_info
*die
,
866 struct dwarf2_cu
**);
868 static void free_line_header (struct line_header
*lh
);
870 static void add_file_name (struct line_header
*, char *, unsigned int,
871 unsigned int, unsigned int);
873 static struct line_header
*(dwarf_decode_line_header
874 (unsigned int offset
,
875 bfd
*abfd
, struct dwarf2_cu
*cu
));
877 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
878 struct dwarf2_cu
*, struct partial_symtab
*);
880 static void dwarf2_start_subfile (char *, char *, char *);
882 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
885 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
888 static void dwarf2_const_value_data (struct attribute
*attr
,
892 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
894 static int need_gnat_info (struct dwarf2_cu
*);
896 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
898 static void set_descriptive_type (struct type
*, struct die_info
*,
901 static struct type
*die_containing_type (struct die_info
*,
904 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
906 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
908 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
910 static char *typename_concat (struct obstack
*,
915 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
917 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
919 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
921 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
923 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
924 struct dwarf2_cu
*, struct partial_symtab
*);
926 static int dwarf2_get_pc_bounds (struct die_info
*,
927 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
928 struct partial_symtab
*);
930 static void get_scope_pc_bounds (struct die_info
*,
931 CORE_ADDR
*, CORE_ADDR
*,
934 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
935 CORE_ADDR
, struct dwarf2_cu
*);
937 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
940 static void dwarf2_attach_fields_to_type (struct field_info
*,
941 struct type
*, struct dwarf2_cu
*);
943 static void dwarf2_add_member_fn (struct field_info
*,
944 struct die_info
*, struct type
*,
947 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
948 struct type
*, struct dwarf2_cu
*);
950 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
952 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
954 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
956 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
958 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
960 static const char *namespace_name (struct die_info
*die
,
961 int *is_anonymous
, struct dwarf2_cu
*);
963 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
965 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
967 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
970 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
972 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
974 gdb_byte
**new_info_ptr
,
975 struct die_info
*parent
);
977 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
979 gdb_byte
**new_info_ptr
,
980 struct die_info
*parent
);
982 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
984 gdb_byte
**new_info_ptr
,
985 struct die_info
*parent
);
987 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
988 struct die_info
**, gdb_byte
*,
991 static void process_die (struct die_info
*, struct dwarf2_cu
*);
993 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
996 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
998 static struct die_info
*dwarf2_extension (struct die_info
*die
,
999 struct dwarf2_cu
**);
1001 static char *dwarf_tag_name (unsigned int);
1003 static char *dwarf_attr_name (unsigned int);
1005 static char *dwarf_form_name (unsigned int);
1007 static char *dwarf_stack_op_name (unsigned int);
1009 static char *dwarf_bool_name (unsigned int);
1011 static char *dwarf_type_encoding_name (unsigned int);
1014 static char *dwarf_cfi_name (unsigned int);
1017 static struct die_info
*sibling_die (struct die_info
*);
1019 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1021 static void dump_die_for_error (struct die_info
*);
1023 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1026 /*static*/ void dump_die (struct die_info
*, int max_level
);
1028 static void store_in_ref_table (struct die_info
*,
1029 struct dwarf2_cu
*);
1031 static int is_ref_attr (struct attribute
*);
1033 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1035 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1037 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1039 struct dwarf2_cu
**);
1041 static struct die_info
*follow_die_ref (struct die_info
*,
1043 struct dwarf2_cu
**);
1045 static struct die_info
*follow_die_sig (struct die_info
*,
1047 struct dwarf2_cu
**);
1049 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1050 unsigned int offset
);
1052 static void read_signatured_type (struct objfile
*,
1053 struct signatured_type
*type_sig
);
1055 /* memory allocation interface */
1057 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1059 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1061 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1063 static void initialize_cu_func_list (struct dwarf2_cu
*);
1065 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1066 struct dwarf2_cu
*);
1068 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1069 char *, bfd
*, struct dwarf2_cu
*);
1071 static int attr_form_is_block (struct attribute
*);
1073 static int attr_form_is_section_offset (struct attribute
*);
1075 static int attr_form_is_constant (struct attribute
*);
1077 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1079 struct dwarf2_cu
*cu
);
1081 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1082 struct abbrev_info
*abbrev
,
1083 struct dwarf2_cu
*cu
);
1085 static void free_stack_comp_unit (void *);
1087 static hashval_t
partial_die_hash (const void *item
);
1089 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1091 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1092 (unsigned int offset
, struct objfile
*objfile
);
1094 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1095 (unsigned int offset
, struct objfile
*objfile
);
1097 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1099 static void free_one_comp_unit (void *);
1101 static void free_cached_comp_units (void *);
1103 static void age_cached_comp_units (void);
1105 static void free_one_cached_comp_unit (void *);
1107 static struct type
*set_die_type (struct die_info
*, struct type
*,
1108 struct dwarf2_cu
*);
1110 static void create_all_comp_units (struct objfile
*);
1112 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1115 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1117 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1118 struct dwarf2_per_cu_data
*);
1120 static void dwarf2_mark (struct dwarf2_cu
*);
1122 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1124 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1126 /* Try to locate the sections we need for DWARF 2 debugging
1127 information and return true if we have enough to do something. */
1130 dwarf2_has_info (struct objfile
*objfile
)
1132 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1133 if (!dwarf2_per_objfile
)
1135 /* Initialize per-objfile state. */
1136 struct dwarf2_per_objfile
*data
1137 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1138 memset (data
, 0, sizeof (*data
));
1139 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1140 dwarf2_per_objfile
= data
;
1142 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1143 dwarf2_per_objfile
->objfile
= objfile
;
1145 return (dwarf2_per_objfile
->info
.asection
!= NULL
1146 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1149 /* When loading sections, we can either look for ".<name>", or for
1150 * ".z<name>", which indicates a compressed section. */
1153 section_is_p (const char *section_name
, const char *name
)
1155 return (section_name
[0] == '.'
1156 && (strcmp (section_name
+ 1, name
) == 0
1157 || (section_name
[1] == 'z'
1158 && strcmp (section_name
+ 2, name
) == 0)));
1161 /* This function is mapped across the sections and remembers the
1162 offset and size of each of the debugging sections we are interested
1166 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1168 if (section_is_p (sectp
->name
, INFO_SECTION
))
1170 dwarf2_per_objfile
->info
.asection
= sectp
;
1171 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1173 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1175 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1176 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1178 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1180 dwarf2_per_objfile
->line
.asection
= sectp
;
1181 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1183 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1185 dwarf2_per_objfile
->loc
.asection
= sectp
;
1186 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1188 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1190 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1191 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1193 else if (section_is_p (sectp
->name
, STR_SECTION
))
1195 dwarf2_per_objfile
->str
.asection
= sectp
;
1196 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1198 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1200 dwarf2_per_objfile
->frame
.asection
= sectp
;
1201 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1203 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1205 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1206 if (aflag
& SEC_HAS_CONTENTS
)
1208 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1209 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1212 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1214 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1215 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1217 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1219 dwarf2_per_objfile
->types
.asection
= sectp
;
1220 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1223 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1224 && bfd_section_vma (abfd
, sectp
) == 0)
1225 dwarf2_per_objfile
->has_section_at_zero
= 1;
1228 /* Decompress a section that was compressed using zlib. Store the
1229 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1232 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1233 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1235 bfd
*abfd
= objfile
->obfd
;
1237 error (_("Support for zlib-compressed DWARF data (from '%s') "
1238 "is disabled in this copy of GDB"),
1239 bfd_get_filename (abfd
));
1241 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1242 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1243 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1244 bfd_size_type uncompressed_size
;
1245 gdb_byte
*uncompressed_buffer
;
1248 int header_size
= 12;
1250 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1251 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1252 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1253 bfd_get_filename (abfd
));
1255 /* Read the zlib header. In this case, it should be "ZLIB" followed
1256 by the uncompressed section size, 8 bytes in big-endian order. */
1257 if (compressed_size
< header_size
1258 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1259 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1260 bfd_get_filename (abfd
));
1261 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1262 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1263 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1264 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1265 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1266 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1267 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1268 uncompressed_size
+= compressed_buffer
[11];
1270 /* It is possible the section consists of several compressed
1271 buffers concatenated together, so we uncompress in a loop. */
1275 strm
.avail_in
= compressed_size
- header_size
;
1276 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1277 strm
.avail_out
= uncompressed_size
;
1278 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1280 rc
= inflateInit (&strm
);
1281 while (strm
.avail_in
> 0)
1284 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1285 bfd_get_filename (abfd
), rc
);
1286 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1287 + (uncompressed_size
- strm
.avail_out
));
1288 rc
= inflate (&strm
, Z_FINISH
);
1289 if (rc
!= Z_STREAM_END
)
1290 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1291 bfd_get_filename (abfd
), rc
);
1292 rc
= inflateReset (&strm
);
1294 rc
= inflateEnd (&strm
);
1296 || strm
.avail_out
!= 0)
1297 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1298 bfd_get_filename (abfd
), rc
);
1300 do_cleanups (cleanup
);
1301 *outbuf
= uncompressed_buffer
;
1302 *outsize
= uncompressed_size
;
1306 /* Read the contents of the section SECTP from object file specified by
1307 OBJFILE, store info about the section into INFO.
1308 If the section is compressed, uncompress it before returning. */
1311 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1313 bfd
*abfd
= objfile
->obfd
;
1314 asection
*sectp
= info
->asection
;
1315 gdb_byte
*buf
, *retbuf
;
1316 unsigned char header
[4];
1320 info
->buffer
= NULL
;
1321 info
->was_mmapped
= 0;
1324 if (info
->asection
== NULL
|| info
->size
== 0)
1327 /* Check if the file has a 4-byte header indicating compression. */
1328 if (info
->size
> sizeof (header
)
1329 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1330 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1332 /* Upon decompression, update the buffer and its size. */
1333 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1335 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1343 pagesize
= getpagesize ();
1345 /* Only try to mmap sections which are large enough: we don't want to
1346 waste space due to fragmentation. Also, only try mmap for sections
1347 without relocations. */
1349 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1351 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1352 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1353 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1354 MAP_PRIVATE
, pg_offset
);
1356 if (retbuf
!= MAP_FAILED
)
1358 info
->was_mmapped
= 1;
1359 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1360 #if HAVE_POSIX_MADVISE
1361 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1368 /* If we get here, we are a normal, not-compressed section. */
1370 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1372 /* When debugging .o files, we may need to apply relocations; see
1373 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1374 We never compress sections in .o files, so we only need to
1375 try this when the section is not compressed. */
1376 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1379 info
->buffer
= retbuf
;
1383 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1384 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1385 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1386 bfd_get_filename (abfd
));
1389 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1393 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1394 asection
**sectp
, gdb_byte
**bufp
,
1395 bfd_size_type
*sizep
)
1397 struct dwarf2_per_objfile
*data
1398 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1399 struct dwarf2_section_info
*info
;
1400 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1401 info
= &data
->eh_frame
;
1402 else if (section_is_p (section_name
, FRAME_SECTION
))
1403 info
= &data
->frame
;
1407 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1408 /* We haven't read this section in yet. Do it now. */
1409 dwarf2_read_section (objfile
, info
);
1411 *sectp
= info
->asection
;
1412 *bufp
= info
->buffer
;
1413 *sizep
= info
->size
;
1416 /* Build a partial symbol table. */
1419 dwarf2_build_psymtabs (struct objfile
*objfile
)
1421 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
1423 init_psymbol_list (objfile
, 1024);
1426 dwarf2_build_psymtabs_hard (objfile
);
1429 /* Return TRUE if OFFSET is within CU_HEADER. */
1432 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1434 unsigned int bottom
= cu_header
->offset
;
1435 unsigned int top
= (cu_header
->offset
1437 + cu_header
->initial_length_size
);
1438 return (offset
>= bottom
&& offset
< top
);
1441 /* Read in the comp unit header information from the debug_info at info_ptr.
1442 NOTE: This leaves members offset, first_die_offset to be filled in
1446 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1447 gdb_byte
*info_ptr
, bfd
*abfd
)
1450 unsigned int bytes_read
;
1452 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1453 cu_header
->initial_length_size
= bytes_read
;
1454 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1455 info_ptr
+= bytes_read
;
1456 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1458 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1460 info_ptr
+= bytes_read
;
1461 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1463 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1464 if (signed_addr
< 0)
1465 internal_error (__FILE__
, __LINE__
,
1466 _("read_comp_unit_head: dwarf from non elf file"));
1467 cu_header
->signed_addr_p
= signed_addr
;
1473 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1474 gdb_byte
*buffer
, unsigned int buffer_size
,
1477 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1479 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1481 if (header
->version
!= 2 && header
->version
!= 3)
1482 error (_("Dwarf Error: wrong version in compilation unit header "
1483 "(is %d, should be %d) [in module %s]"), header
->version
,
1484 2, bfd_get_filename (abfd
));
1486 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1487 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1488 "(offset 0x%lx + 6) [in module %s]"),
1489 (long) header
->abbrev_offset
,
1490 (long) (beg_of_comp_unit
- buffer
),
1491 bfd_get_filename (abfd
));
1493 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1494 > buffer
+ buffer_size
)
1495 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1496 "(offset 0x%lx + 0) [in module %s]"),
1497 (long) header
->length
,
1498 (long) (beg_of_comp_unit
- buffer
),
1499 bfd_get_filename (abfd
));
1504 /* Read in the types comp unit header information from .debug_types entry at
1505 types_ptr. The result is a pointer to one past the end of the header. */
1508 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
1509 ULONGEST
*signature
,
1510 gdb_byte
*types_ptr
, bfd
*abfd
)
1512 unsigned int bytes_read
;
1513 gdb_byte
*initial_types_ptr
= types_ptr
;
1515 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->types
);
1516 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
1518 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
1520 *signature
= read_8_bytes (abfd
, types_ptr
);
1522 types_ptr
+= cu_header
->offset_size
;
1523 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
1528 /* Allocate a new partial symtab for file named NAME and mark this new
1529 partial symtab as being an include of PST. */
1532 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1533 struct objfile
*objfile
)
1535 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1537 subpst
->section_offsets
= pst
->section_offsets
;
1538 subpst
->textlow
= 0;
1539 subpst
->texthigh
= 0;
1541 subpst
->dependencies
= (struct partial_symtab
**)
1542 obstack_alloc (&objfile
->objfile_obstack
,
1543 sizeof (struct partial_symtab
*));
1544 subpst
->dependencies
[0] = pst
;
1545 subpst
->number_of_dependencies
= 1;
1547 subpst
->globals_offset
= 0;
1548 subpst
->n_global_syms
= 0;
1549 subpst
->statics_offset
= 0;
1550 subpst
->n_static_syms
= 0;
1551 subpst
->symtab
= NULL
;
1552 subpst
->read_symtab
= pst
->read_symtab
;
1555 /* No private part is necessary for include psymtabs. This property
1556 can be used to differentiate between such include psymtabs and
1557 the regular ones. */
1558 subpst
->read_symtab_private
= NULL
;
1561 /* Read the Line Number Program data and extract the list of files
1562 included by the source file represented by PST. Build an include
1563 partial symtab for each of these included files. */
1566 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1567 struct die_info
*die
,
1568 struct partial_symtab
*pst
)
1570 struct objfile
*objfile
= cu
->objfile
;
1571 bfd
*abfd
= objfile
->obfd
;
1572 struct line_header
*lh
= NULL
;
1573 struct attribute
*attr
;
1575 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
1578 unsigned int line_offset
= DW_UNSND (attr
);
1579 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
1582 return; /* No linetable, so no includes. */
1584 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1586 free_line_header (lh
);
1590 hash_type_signature (const void *item
)
1592 const struct signatured_type
*type_sig
= item
;
1593 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1594 return type_sig
->signature
;
1598 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
1600 const struct signatured_type
*lhs
= item_lhs
;
1601 const struct signatured_type
*rhs
= item_rhs
;
1602 return lhs
->signature
== rhs
->signature
;
1605 /* Create the hash table of all entries in the .debug_types section.
1606 The result is zero if there is an error (e.g. missing .debug_types section),
1607 otherwise non-zero. */
1610 create_debug_types_hash_table (struct objfile
*objfile
)
1615 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
1616 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
1618 if (info_ptr
== NULL
)
1620 dwarf2_per_objfile
->signatured_types
= NULL
;
1624 types_htab
= htab_create_alloc_ex (41,
1625 hash_type_signature
,
1628 &objfile
->objfile_obstack
,
1629 hashtab_obstack_allocate
,
1630 dummy_obstack_deallocate
);
1632 if (dwarf2_die_debug
)
1633 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
1635 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1637 unsigned int offset
;
1638 unsigned int offset_size
;
1639 unsigned int type_offset
;
1640 unsigned int length
, initial_length_size
;
1641 unsigned short version
;
1643 struct signatured_type
*type_sig
;
1645 gdb_byte
*ptr
= info_ptr
;
1647 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
1649 /* We need to read the type's signature in order to build the hash
1650 table, but we don't need to read anything else just yet. */
1652 /* Sanity check to ensure entire cu is present. */
1653 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
1654 if (ptr
+ length
+ initial_length_size
1655 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1657 complaint (&symfile_complaints
,
1658 _("debug type entry runs off end of `.debug_types' section, ignored"));
1662 offset_size
= initial_length_size
== 4 ? 4 : 8;
1663 ptr
+= initial_length_size
;
1664 version
= bfd_get_16 (objfile
->obfd
, ptr
);
1666 ptr
+= offset_size
; /* abbrev offset */
1667 ptr
+= 1; /* address size */
1668 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
1670 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
1672 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
1673 memset (type_sig
, 0, sizeof (*type_sig
));
1674 type_sig
->signature
= signature
;
1675 type_sig
->offset
= offset
;
1676 type_sig
->type_offset
= type_offset
;
1678 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
1679 gdb_assert (slot
!= NULL
);
1682 if (dwarf2_die_debug
)
1683 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
1684 offset
, phex (signature
, sizeof (signature
)));
1686 info_ptr
= info_ptr
+ initial_length_size
+ length
;
1689 dwarf2_per_objfile
->signatured_types
= types_htab
;
1694 /* Lookup a signature based type.
1695 Returns NULL if SIG is not present in the table. */
1697 static struct signatured_type
*
1698 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
1700 struct signatured_type find_entry
, *entry
;
1702 if (dwarf2_per_objfile
->signatured_types
== NULL
)
1704 complaint (&symfile_complaints
,
1705 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1709 find_entry
.signature
= sig
;
1710 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
1714 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1717 init_cu_die_reader (struct die_reader_specs
*reader
,
1718 struct dwarf2_cu
*cu
)
1720 reader
->abfd
= cu
->objfile
->obfd
;
1722 if (cu
->per_cu
->from_debug_types
)
1724 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1725 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
1729 gdb_assert (dwarf2_per_objfile
->info
.readin
);
1730 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
1734 /* Find the base address of the compilation unit for range lists and
1735 location lists. It will normally be specified by DW_AT_low_pc.
1736 In DWARF-3 draft 4, the base address could be overridden by
1737 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1738 compilation units with discontinuous ranges. */
1741 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
1743 struct attribute
*attr
;
1746 cu
->base_address
= 0;
1748 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
1751 cu
->base_address
= DW_ADDR (attr
);
1756 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
1759 cu
->base_address
= DW_ADDR (attr
);
1765 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1766 to combine the common parts.
1767 Process a compilation unit for a psymtab.
1768 BUFFER is a pointer to the beginning of the dwarf section buffer,
1769 either .debug_info or debug_types.
1770 INFO_PTR is a pointer to the start of the CU.
1771 Returns a pointer to the next CU. */
1774 process_psymtab_comp_unit (struct objfile
*objfile
,
1775 struct dwarf2_per_cu_data
*this_cu
,
1776 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1777 unsigned int buffer_size
)
1779 bfd
*abfd
= objfile
->obfd
;
1780 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1781 struct die_info
*comp_unit_die
;
1782 struct partial_symtab
*pst
;
1784 struct cleanup
*back_to_inner
;
1785 struct dwarf2_cu cu
;
1786 unsigned int bytes_read
;
1787 int has_children
, has_pc_info
;
1788 struct attribute
*attr
;
1790 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
1791 struct die_reader_specs reader_specs
;
1793 memset (&cu
, 0, sizeof (cu
));
1794 cu
.objfile
= objfile
;
1795 obstack_init (&cu
.comp_unit_obstack
);
1797 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1799 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1800 buffer
, buffer_size
,
1803 /* Complete the cu_header. */
1804 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1805 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1807 cu
.list_in_scope
= &file_symbols
;
1809 /* If this compilation unit was already read in, free the
1810 cached copy in order to read it in again. This is
1811 necessary because we skipped some symbols when we first
1812 read in the compilation unit (see load_partial_dies).
1813 This problem could be avoided, but the benefit is
1815 if (this_cu
->cu
!= NULL
)
1816 free_one_cached_comp_unit (this_cu
->cu
);
1818 /* Note that this is a pointer to our stack frame, being
1819 added to a global data structure. It will be cleaned up
1820 in free_stack_comp_unit when we finish with this
1821 compilation unit. */
1823 cu
.per_cu
= this_cu
;
1825 /* Read the abbrevs for this compilation unit into a table. */
1826 dwarf2_read_abbrevs (abfd
, &cu
);
1827 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1829 /* Read the compilation unit die. */
1830 if (this_cu
->from_debug_types
)
1831 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1832 init_cu_die_reader (&reader_specs
, &cu
);
1833 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1836 if (this_cu
->from_debug_types
)
1838 /* offset,length haven't been set yet for type units. */
1839 this_cu
->offset
= cu
.header
.offset
;
1840 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
1842 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
1844 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1845 + cu
.header
.initial_length_size
);
1846 do_cleanups (back_to_inner
);
1850 /* Set the language we're debugging. */
1851 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
1853 set_cu_language (DW_UNSND (attr
), &cu
);
1855 set_cu_language (language_minimal
, &cu
);
1857 /* Allocate a new partial symbol table structure. */
1858 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
1859 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1860 (attr
!= NULL
) ? DW_STRING (attr
) : "",
1861 /* TEXTLOW and TEXTHIGH are set below. */
1863 objfile
->global_psymbols
.next
,
1864 objfile
->static_psymbols
.next
);
1866 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
1868 pst
->dirname
= DW_STRING (attr
);
1870 pst
->read_symtab_private
= this_cu
;
1872 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1874 /* Store the function that reads in the rest of the symbol table */
1875 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1877 this_cu
->psymtab
= pst
;
1879 dwarf2_find_base_address (comp_unit_die
, &cu
);
1881 /* Possibly set the default values of LOWPC and HIGHPC from
1883 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
1884 &best_highpc
, &cu
, pst
);
1885 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
1886 /* Store the contiguous range if it is not empty; it can be empty for
1887 CUs with no code. */
1888 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1889 best_lowpc
+ baseaddr
,
1890 best_highpc
+ baseaddr
- 1, pst
);
1892 /* Check if comp unit has_children.
1893 If so, read the rest of the partial symbols from this comp unit.
1894 If not, there's no more debug_info for this comp unit. */
1897 struct partial_die_info
*first_die
;
1898 CORE_ADDR lowpc
, highpc
;
1900 lowpc
= ((CORE_ADDR
) -1);
1901 highpc
= ((CORE_ADDR
) 0);
1903 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
1905 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1906 ! has_pc_info
, &cu
);
1908 /* If we didn't find a lowpc, set it to highpc to avoid
1909 complaints from `maint check'. */
1910 if (lowpc
== ((CORE_ADDR
) -1))
1913 /* If the compilation unit didn't have an explicit address range,
1914 then use the information extracted from its child dies. */
1918 best_highpc
= highpc
;
1921 pst
->textlow
= best_lowpc
+ baseaddr
;
1922 pst
->texthigh
= best_highpc
+ baseaddr
;
1924 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1925 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1926 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1927 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1928 sort_pst_symbols (pst
);
1930 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1931 + cu
.header
.initial_length_size
);
1933 if (this_cu
->from_debug_types
)
1935 /* It's not clear we want to do anything with stmt lists here.
1936 Waiting to see what gcc ultimately does. */
1940 /* Get the list of files included in the current compilation unit,
1941 and build a psymtab for each of them. */
1942 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
1945 do_cleanups (back_to_inner
);
1950 /* Traversal function for htab_traverse_noresize.
1951 Process one .debug_types comp-unit. */
1954 process_type_comp_unit (void **slot
, void *info
)
1956 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
1957 struct objfile
*objfile
= (struct objfile
*) info
;
1958 struct dwarf2_per_cu_data
*this_cu
;
1960 this_cu
= &entry
->per_cu
;
1961 this_cu
->from_debug_types
= 1;
1963 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1964 process_psymtab_comp_unit (objfile
, this_cu
,
1965 dwarf2_per_objfile
->types
.buffer
,
1966 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
1967 dwarf2_per_objfile
->types
.size
);
1972 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
1973 Build partial symbol tables for the .debug_types comp-units. */
1976 build_type_psymtabs (struct objfile
*objfile
)
1978 if (! create_debug_types_hash_table (objfile
))
1981 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
1982 process_type_comp_unit
, objfile
);
1985 /* Build the partial symbol table by doing a quick pass through the
1986 .debug_info and .debug_abbrev sections. */
1989 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
1991 bfd
*abfd
= objfile
->obfd
;
1993 struct cleanup
*back_to
;
1995 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1996 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
1998 /* Any cached compilation units will be linked by the per-objfile
1999 read_in_chain. Make sure to free them when we're done. */
2000 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2002 build_type_psymtabs (objfile
);
2004 create_all_comp_units (objfile
);
2006 objfile
->psymtabs_addrmap
=
2007 addrmap_create_mutable (&objfile
->objfile_obstack
);
2009 /* Since the objects we're extracting from .debug_info vary in
2010 length, only the individual functions to extract them (like
2011 read_comp_unit_head and load_partial_die) can really know whether
2012 the buffer is large enough to hold another complete object.
2014 At the moment, they don't actually check that. If .debug_info
2015 holds just one extra byte after the last compilation unit's dies,
2016 then read_comp_unit_head will happily read off the end of the
2017 buffer. read_partial_die is similarly casual. Those functions
2020 For this loop condition, simply checking whether there's any data
2021 left at all should be sufficient. */
2023 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
2024 + dwarf2_per_objfile
->info
.size
))
2026 struct dwarf2_per_cu_data
*this_cu
;
2028 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
2031 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
2032 dwarf2_per_objfile
->info
.buffer
,
2034 dwarf2_per_objfile
->info
.size
);
2037 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
2038 &objfile
->objfile_obstack
);
2040 do_cleanups (back_to
);
2043 /* Load the partial DIEs for a secondary CU into memory. */
2046 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
2047 struct objfile
*objfile
)
2049 bfd
*abfd
= objfile
->obfd
;
2050 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
2051 struct die_info
*comp_unit_die
;
2052 struct dwarf2_cu
*cu
;
2053 unsigned int bytes_read
;
2054 struct cleanup
*back_to
;
2055 struct attribute
*attr
;
2057 struct die_reader_specs reader_specs
;
2059 gdb_assert (! this_cu
->from_debug_types
);
2061 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2062 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
2063 beg_of_comp_unit
= info_ptr
;
2065 cu
= alloc_one_comp_unit (objfile
);
2067 /* ??? Missing cleanup for CU? */
2069 /* Link this compilation unit into the compilation unit tree. */
2071 cu
->per_cu
= this_cu
;
2072 cu
->type_hash
= this_cu
->type_hash
;
2074 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
2075 dwarf2_per_objfile
->info
.buffer
,
2076 dwarf2_per_objfile
->info
.size
,
2079 /* Complete the cu_header. */
2080 cu
->header
.offset
= this_cu
->offset
;
2081 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2083 /* Read the abbrevs for this compilation unit into a table. */
2084 dwarf2_read_abbrevs (abfd
, cu
);
2085 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2087 /* Read the compilation unit die. */
2088 init_cu_die_reader (&reader_specs
, cu
);
2089 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2092 /* Set the language we're debugging. */
2093 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
2095 set_cu_language (DW_UNSND (attr
), cu
);
2097 set_cu_language (language_minimal
, cu
);
2099 /* Check if comp unit has_children.
2100 If so, read the rest of the partial symbols from this comp unit.
2101 If not, there's no more debug_info for this comp unit. */
2103 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
2105 do_cleanups (back_to
);
2108 /* Create a list of all compilation units in OBJFILE. We do this only
2109 if an inter-comp-unit reference is found; presumably if there is one,
2110 there will be many, and one will occur early in the .debug_info section.
2111 So there's no point in building this list incrementally. */
2114 create_all_comp_units (struct objfile
*objfile
)
2118 struct dwarf2_per_cu_data
**all_comp_units
;
2121 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2122 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2126 all_comp_units
= xmalloc (n_allocated
2127 * sizeof (struct dwarf2_per_cu_data
*));
2129 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
2131 unsigned int length
, initial_length_size
;
2132 gdb_byte
*beg_of_comp_unit
;
2133 struct dwarf2_per_cu_data
*this_cu
;
2134 unsigned int offset
;
2136 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
2138 /* Read just enough information to find out where the next
2139 compilation unit is. */
2140 length
= read_initial_length (objfile
->obfd
, info_ptr
,
2141 &initial_length_size
);
2143 /* Save the compilation unit for later lookup. */
2144 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
2145 sizeof (struct dwarf2_per_cu_data
));
2146 memset (this_cu
, 0, sizeof (*this_cu
));
2147 this_cu
->offset
= offset
;
2148 this_cu
->length
= length
+ initial_length_size
;
2150 if (n_comp_units
== n_allocated
)
2153 all_comp_units
= xrealloc (all_comp_units
,
2155 * sizeof (struct dwarf2_per_cu_data
*));
2157 all_comp_units
[n_comp_units
++] = this_cu
;
2159 info_ptr
= info_ptr
+ this_cu
->length
;
2162 dwarf2_per_objfile
->all_comp_units
2163 = obstack_alloc (&objfile
->objfile_obstack
,
2164 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2165 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
2166 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2167 xfree (all_comp_units
);
2168 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
2171 /* Process all loaded DIEs for compilation unit CU, starting at
2172 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2173 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2174 DW_AT_ranges). If NEED_PC is set, then this function will set
2175 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2176 and record the covered ranges in the addrmap. */
2179 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
2180 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2182 struct objfile
*objfile
= cu
->objfile
;
2183 bfd
*abfd
= objfile
->obfd
;
2184 struct partial_die_info
*pdi
;
2186 /* Now, march along the PDI's, descending into ones which have
2187 interesting children but skipping the children of the other ones,
2188 until we reach the end of the compilation unit. */
2194 fixup_partial_die (pdi
, cu
);
2196 /* Anonymous namespaces have no name but have interesting
2197 children, so we need to look at them. Ditto for anonymous
2200 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
2201 || pdi
->tag
== DW_TAG_enumeration_type
)
2205 case DW_TAG_subprogram
:
2206 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2208 case DW_TAG_variable
:
2209 case DW_TAG_typedef
:
2210 case DW_TAG_union_type
:
2211 if (!pdi
->is_declaration
)
2213 add_partial_symbol (pdi
, cu
);
2216 case DW_TAG_class_type
:
2217 case DW_TAG_interface_type
:
2218 case DW_TAG_structure_type
:
2219 if (!pdi
->is_declaration
)
2221 add_partial_symbol (pdi
, cu
);
2224 case DW_TAG_enumeration_type
:
2225 if (!pdi
->is_declaration
)
2226 add_partial_enumeration (pdi
, cu
);
2228 case DW_TAG_base_type
:
2229 case DW_TAG_subrange_type
:
2230 /* File scope base type definitions are added to the partial
2232 add_partial_symbol (pdi
, cu
);
2234 case DW_TAG_namespace
:
2235 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
2238 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
2245 /* If the die has a sibling, skip to the sibling. */
2247 pdi
= pdi
->die_sibling
;
2251 /* Functions used to compute the fully scoped name of a partial DIE.
2253 Normally, this is simple. For C++, the parent DIE's fully scoped
2254 name is concatenated with "::" and the partial DIE's name. For
2255 Java, the same thing occurs except that "." is used instead of "::".
2256 Enumerators are an exception; they use the scope of their parent
2257 enumeration type, i.e. the name of the enumeration type is not
2258 prepended to the enumerator.
2260 There are two complexities. One is DW_AT_specification; in this
2261 case "parent" means the parent of the target of the specification,
2262 instead of the direct parent of the DIE. The other is compilers
2263 which do not emit DW_TAG_namespace; in this case we try to guess
2264 the fully qualified name of structure types from their members'
2265 linkage names. This must be done using the DIE's children rather
2266 than the children of any DW_AT_specification target. We only need
2267 to do this for structures at the top level, i.e. if the target of
2268 any DW_AT_specification (if any; otherwise the DIE itself) does not
2271 /* Compute the scope prefix associated with PDI's parent, in
2272 compilation unit CU. The result will be allocated on CU's
2273 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2274 field. NULL is returned if no prefix is necessary. */
2276 partial_die_parent_scope (struct partial_die_info
*pdi
,
2277 struct dwarf2_cu
*cu
)
2279 char *grandparent_scope
;
2280 struct partial_die_info
*parent
, *real_pdi
;
2282 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2283 then this means the parent of the specification DIE. */
2286 while (real_pdi
->has_specification
)
2287 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2289 parent
= real_pdi
->die_parent
;
2293 if (parent
->scope_set
)
2294 return parent
->scope
;
2296 fixup_partial_die (parent
, cu
);
2298 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2300 if (parent
->tag
== DW_TAG_namespace
2301 || parent
->tag
== DW_TAG_structure_type
2302 || parent
->tag
== DW_TAG_class_type
2303 || parent
->tag
== DW_TAG_interface_type
2304 || parent
->tag
== DW_TAG_union_type
2305 || parent
->tag
== DW_TAG_enumeration_type
)
2307 if (grandparent_scope
== NULL
)
2308 parent
->scope
= parent
->name
;
2310 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2313 else if (parent
->tag
== DW_TAG_enumerator
)
2314 /* Enumerators should not get the name of the enumeration as a prefix. */
2315 parent
->scope
= grandparent_scope
;
2318 /* FIXME drow/2004-04-01: What should we be doing with
2319 function-local names? For partial symbols, we should probably be
2321 complaint (&symfile_complaints
,
2322 _("unhandled containing DIE tag %d for DIE at %d"),
2323 parent
->tag
, pdi
->offset
);
2324 parent
->scope
= grandparent_scope
;
2327 parent
->scope_set
= 1;
2328 return parent
->scope
;
2331 /* Return the fully scoped name associated with PDI, from compilation unit
2332 CU. The result will be allocated with malloc. */
2334 partial_die_full_name (struct partial_die_info
*pdi
,
2335 struct dwarf2_cu
*cu
)
2339 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2340 if (parent_scope
== NULL
)
2343 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2347 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2349 struct objfile
*objfile
= cu
->objfile
;
2351 char *actual_name
= NULL
;
2352 const char *my_prefix
;
2353 const struct partial_symbol
*psym
= NULL
;
2355 int built_actual_name
= 0;
2357 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2359 actual_name
= partial_die_full_name (pdi
, cu
);
2361 built_actual_name
= 1;
2363 if (actual_name
== NULL
)
2364 actual_name
= pdi
->name
;
2368 case DW_TAG_subprogram
:
2369 if (pdi
->is_external
|| cu
->language
== language_ada
)
2371 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2372 of the global scope. But in Ada, we want to be able to access
2373 nested procedures globally. So all Ada subprograms are stored
2374 in the global scope. */
2375 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2376 mst_text, objfile); */
2377 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2379 VAR_DOMAIN
, LOC_BLOCK
,
2380 &objfile
->global_psymbols
,
2381 0, pdi
->lowpc
+ baseaddr
,
2382 cu
->language
, objfile
);
2386 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2387 mst_file_text, objfile); */
2388 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2390 VAR_DOMAIN
, LOC_BLOCK
,
2391 &objfile
->static_psymbols
,
2392 0, pdi
->lowpc
+ baseaddr
,
2393 cu
->language
, objfile
);
2396 case DW_TAG_variable
:
2397 if (pdi
->is_external
)
2400 Don't enter into the minimal symbol tables as there is
2401 a minimal symbol table entry from the ELF symbols already.
2402 Enter into partial symbol table if it has a location
2403 descriptor or a type.
2404 If the location descriptor is missing, new_symbol will create
2405 a LOC_UNRESOLVED symbol, the address of the variable will then
2406 be determined from the minimal symbol table whenever the variable
2408 The address for the partial symbol table entry is not
2409 used by GDB, but it comes in handy for debugging partial symbol
2413 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2414 if (pdi
->locdesc
|| pdi
->has_type
)
2415 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2417 VAR_DOMAIN
, LOC_STATIC
,
2418 &objfile
->global_psymbols
,
2420 cu
->language
, objfile
);
2424 /* Static Variable. Skip symbols without location descriptors. */
2425 if (pdi
->locdesc
== NULL
)
2427 if (built_actual_name
)
2428 xfree (actual_name
);
2431 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2432 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2433 mst_file_data, objfile); */
2434 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2436 VAR_DOMAIN
, LOC_STATIC
,
2437 &objfile
->static_psymbols
,
2439 cu
->language
, objfile
);
2442 case DW_TAG_typedef
:
2443 case DW_TAG_base_type
:
2444 case DW_TAG_subrange_type
:
2445 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2447 VAR_DOMAIN
, LOC_TYPEDEF
,
2448 &objfile
->static_psymbols
,
2449 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2451 case DW_TAG_namespace
:
2452 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2454 VAR_DOMAIN
, LOC_TYPEDEF
,
2455 &objfile
->global_psymbols
,
2456 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2458 case DW_TAG_class_type
:
2459 case DW_TAG_interface_type
:
2460 case DW_TAG_structure_type
:
2461 case DW_TAG_union_type
:
2462 case DW_TAG_enumeration_type
:
2463 /* Skip external references. The DWARF standard says in the section
2464 about "Structure, Union, and Class Type Entries": "An incomplete
2465 structure, union or class type is represented by a structure,
2466 union or class entry that does not have a byte size attribute
2467 and that has a DW_AT_declaration attribute." */
2468 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2470 if (built_actual_name
)
2471 xfree (actual_name
);
2475 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2476 static vs. global. */
2477 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2479 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2480 (cu
->language
== language_cplus
2481 || cu
->language
== language_java
)
2482 ? &objfile
->global_psymbols
2483 : &objfile
->static_psymbols
,
2484 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2487 case DW_TAG_enumerator
:
2488 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2490 VAR_DOMAIN
, LOC_CONST
,
2491 (cu
->language
== language_cplus
2492 || cu
->language
== language_java
)
2493 ? &objfile
->global_psymbols
2494 : &objfile
->static_psymbols
,
2495 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2501 if (built_actual_name
)
2502 xfree (actual_name
);
2505 /* Read a partial die corresponding to a namespace; also, add a symbol
2506 corresponding to that namespace to the symbol table. NAMESPACE is
2507 the name of the enclosing namespace. */
2510 add_partial_namespace (struct partial_die_info
*pdi
,
2511 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2512 int need_pc
, struct dwarf2_cu
*cu
)
2514 struct objfile
*objfile
= cu
->objfile
;
2516 /* Add a symbol for the namespace. */
2518 add_partial_symbol (pdi
, cu
);
2520 /* Now scan partial symbols in that namespace. */
2522 if (pdi
->has_children
)
2523 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2526 /* Read a partial die corresponding to a Fortran module. */
2529 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2530 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2532 /* Now scan partial symbols in that module.
2534 FIXME: Support the separate Fortran module namespaces. */
2536 if (pdi
->has_children
)
2537 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2540 /* Read a partial die corresponding to a subprogram and create a partial
2541 symbol for that subprogram. When the CU language allows it, this
2542 routine also defines a partial symbol for each nested subprogram
2543 that this subprogram contains.
2545 DIE my also be a lexical block, in which case we simply search
2546 recursively for suprograms defined inside that lexical block.
2547 Again, this is only performed when the CU language allows this
2548 type of definitions. */
2551 add_partial_subprogram (struct partial_die_info
*pdi
,
2552 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2553 int need_pc
, struct dwarf2_cu
*cu
)
2555 if (pdi
->tag
== DW_TAG_subprogram
)
2557 if (pdi
->has_pc_info
)
2559 if (pdi
->lowpc
< *lowpc
)
2560 *lowpc
= pdi
->lowpc
;
2561 if (pdi
->highpc
> *highpc
)
2562 *highpc
= pdi
->highpc
;
2566 struct objfile
*objfile
= cu
->objfile
;
2568 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2569 SECT_OFF_TEXT (objfile
));
2570 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2571 pdi
->lowpc
+ baseaddr
,
2572 pdi
->highpc
- 1 + baseaddr
,
2573 cu
->per_cu
->psymtab
);
2575 if (!pdi
->is_declaration
)
2576 add_partial_symbol (pdi
, cu
);
2580 if (! pdi
->has_children
)
2583 if (cu
->language
== language_ada
)
2585 pdi
= pdi
->die_child
;
2588 fixup_partial_die (pdi
, cu
);
2589 if (pdi
->tag
== DW_TAG_subprogram
2590 || pdi
->tag
== DW_TAG_lexical_block
)
2591 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2592 pdi
= pdi
->die_sibling
;
2597 /* See if we can figure out if the class lives in a namespace. We do
2598 this by looking for a member function; its demangled name will
2599 contain namespace info, if there is any. */
2602 guess_structure_name (struct partial_die_info
*struct_pdi
,
2603 struct dwarf2_cu
*cu
)
2605 if ((cu
->language
== language_cplus
2606 || cu
->language
== language_java
)
2607 && cu
->has_namespace_info
== 0
2608 && struct_pdi
->has_children
)
2610 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2611 what template types look like, because the demangler
2612 frequently doesn't give the same name as the debug info. We
2613 could fix this by only using the demangled name to get the
2614 prefix (but see comment in read_structure_type). */
2616 struct partial_die_info
*real_pdi
;
2618 /* If this DIE (this DIE's specification, if any) has a parent, then
2619 we should not do this. We'll prepend the parent's fully qualified
2620 name when we create the partial symbol. */
2622 real_pdi
= struct_pdi
;
2623 while (real_pdi
->has_specification
)
2624 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2626 if (real_pdi
->die_parent
!= NULL
)
2631 /* Read a partial die corresponding to an enumeration type. */
2634 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2635 struct dwarf2_cu
*cu
)
2637 struct objfile
*objfile
= cu
->objfile
;
2638 bfd
*abfd
= objfile
->obfd
;
2639 struct partial_die_info
*pdi
;
2641 if (enum_pdi
->name
!= NULL
)
2642 add_partial_symbol (enum_pdi
, cu
);
2644 pdi
= enum_pdi
->die_child
;
2647 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2648 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2650 add_partial_symbol (pdi
, cu
);
2651 pdi
= pdi
->die_sibling
;
2655 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2656 Return the corresponding abbrev, or NULL if the number is zero (indicating
2657 an empty DIE). In either case *BYTES_READ will be set to the length of
2658 the initial number. */
2660 static struct abbrev_info
*
2661 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2662 struct dwarf2_cu
*cu
)
2664 bfd
*abfd
= cu
->objfile
->obfd
;
2665 unsigned int abbrev_number
;
2666 struct abbrev_info
*abbrev
;
2668 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2670 if (abbrev_number
== 0)
2673 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2676 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2677 bfd_get_filename (abfd
));
2683 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2684 Returns a pointer to the end of a series of DIEs, terminated by an empty
2685 DIE. Any children of the skipped DIEs will also be skipped. */
2688 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2690 struct abbrev_info
*abbrev
;
2691 unsigned int bytes_read
;
2695 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2697 return info_ptr
+ bytes_read
;
2699 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
2703 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2704 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2705 abbrev corresponding to that skipped uleb128 should be passed in
2706 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2710 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2711 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
2713 unsigned int bytes_read
;
2714 struct attribute attr
;
2715 bfd
*abfd
= cu
->objfile
->obfd
;
2716 unsigned int form
, i
;
2718 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2720 /* The only abbrev we care about is DW_AT_sibling. */
2721 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2723 read_attribute (&attr
, &abbrev
->attrs
[i
],
2724 abfd
, info_ptr
, cu
);
2725 if (attr
.form
== DW_FORM_ref_addr
)
2726 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2728 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
2731 /* If it isn't DW_AT_sibling, skip this attribute. */
2732 form
= abbrev
->attrs
[i
].form
;
2736 case DW_FORM_ref_addr
:
2737 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2738 and later it is offset sized. */
2739 if (cu
->header
.version
== 2)
2740 info_ptr
+= cu
->header
.addr_size
;
2742 info_ptr
+= cu
->header
.offset_size
;
2745 info_ptr
+= cu
->header
.addr_size
;
2765 case DW_FORM_string
:
2766 read_string (abfd
, info_ptr
, &bytes_read
);
2767 info_ptr
+= bytes_read
;
2770 info_ptr
+= cu
->header
.offset_size
;
2773 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2774 info_ptr
+= bytes_read
;
2776 case DW_FORM_block1
:
2777 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2779 case DW_FORM_block2
:
2780 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2782 case DW_FORM_block4
:
2783 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2787 case DW_FORM_ref_udata
:
2788 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2790 case DW_FORM_indirect
:
2791 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2792 info_ptr
+= bytes_read
;
2793 /* We need to continue parsing from here, so just go back to
2795 goto skip_attribute
;
2798 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2799 dwarf_form_name (form
),
2800 bfd_get_filename (abfd
));
2804 if (abbrev
->has_children
)
2805 return skip_children (buffer
, info_ptr
, cu
);
2810 /* Locate ORIG_PDI's sibling.
2811 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2815 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
2816 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2817 bfd
*abfd
, struct dwarf2_cu
*cu
)
2819 /* Do we know the sibling already? */
2821 if (orig_pdi
->sibling
)
2822 return orig_pdi
->sibling
;
2824 /* Are there any children to deal with? */
2826 if (!orig_pdi
->has_children
)
2829 /* Skip the children the long way. */
2831 return skip_children (buffer
, info_ptr
, cu
);
2834 /* Expand this partial symbol table into a full symbol table. */
2837 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2839 /* FIXME: This is barely more than a stub. */
2844 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2850 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2851 gdb_flush (gdb_stdout
);
2854 /* Restore our global data. */
2855 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2856 dwarf2_objfile_data_key
);
2858 /* If this psymtab is constructed from a debug-only objfile, the
2859 has_section_at_zero flag will not necessarily be correct. We
2860 can get the correct value for this flag by looking at the data
2861 associated with the (presumably stripped) associated objfile. */
2862 if (pst
->objfile
->separate_debug_objfile_backlink
)
2864 struct dwarf2_per_objfile
*dpo_backlink
2865 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2866 dwarf2_objfile_data_key
);
2867 dwarf2_per_objfile
->has_section_at_zero
2868 = dpo_backlink
->has_section_at_zero
;
2871 psymtab_to_symtab_1 (pst
);
2873 /* Finish up the debug error message. */
2875 printf_filtered (_("done.\n"));
2880 /* Add PER_CU to the queue. */
2883 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2885 struct dwarf2_queue_item
*item
;
2888 item
= xmalloc (sizeof (*item
));
2889 item
->per_cu
= per_cu
;
2892 if (dwarf2_queue
== NULL
)
2893 dwarf2_queue
= item
;
2895 dwarf2_queue_tail
->next
= item
;
2897 dwarf2_queue_tail
= item
;
2900 /* Process the queue. */
2903 process_queue (struct objfile
*objfile
)
2905 struct dwarf2_queue_item
*item
, *next_item
;
2907 /* The queue starts out with one item, but following a DIE reference
2908 may load a new CU, adding it to the end of the queue. */
2909 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2911 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2912 process_full_comp_unit (item
->per_cu
);
2914 item
->per_cu
->queued
= 0;
2915 next_item
= item
->next
;
2919 dwarf2_queue_tail
= NULL
;
2922 /* Free all allocated queue entries. This function only releases anything if
2923 an error was thrown; if the queue was processed then it would have been
2924 freed as we went along. */
2927 dwarf2_release_queue (void *dummy
)
2929 struct dwarf2_queue_item
*item
, *last
;
2931 item
= dwarf2_queue
;
2934 /* Anything still marked queued is likely to be in an
2935 inconsistent state, so discard it. */
2936 if (item
->per_cu
->queued
)
2938 if (item
->per_cu
->cu
!= NULL
)
2939 free_one_cached_comp_unit (item
->per_cu
->cu
);
2940 item
->per_cu
->queued
= 0;
2948 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2951 /* Read in full symbols for PST, and anything it depends on. */
2954 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2956 struct dwarf2_per_cu_data
*per_cu
;
2957 struct cleanup
*back_to
;
2960 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2961 if (!pst
->dependencies
[i
]->readin
)
2963 /* Inform about additional files that need to be read in. */
2966 /* FIXME: i18n: Need to make this a single string. */
2967 fputs_filtered (" ", gdb_stdout
);
2969 fputs_filtered ("and ", gdb_stdout
);
2971 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2972 wrap_here (""); /* Flush output */
2973 gdb_flush (gdb_stdout
);
2975 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2978 per_cu
= pst
->read_symtab_private
;
2982 /* It's an include file, no symbols to read for it.
2983 Everything is in the parent symtab. */
2988 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2990 queue_comp_unit (per_cu
, pst
->objfile
);
2992 if (per_cu
->from_debug_types
)
2993 read_signatured_type_at_offset (pst
->objfile
, per_cu
->offset
);
2995 load_full_comp_unit (per_cu
, pst
->objfile
);
2997 process_queue (pst
->objfile
);
2999 /* Age the cache, releasing compilation units that have not
3000 been used recently. */
3001 age_cached_comp_units ();
3003 do_cleanups (back_to
);
3006 /* Load the DIEs associated with PER_CU into memory. */
3009 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3011 bfd
*abfd
= objfile
->obfd
;
3012 struct dwarf2_cu
*cu
;
3013 unsigned int offset
;
3014 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3015 struct cleanup
*back_to
, *free_cu_cleanup
;
3016 struct attribute
*attr
;
3019 gdb_assert (! per_cu
->from_debug_types
);
3021 /* Set local variables from the partial symbol table info. */
3022 offset
= per_cu
->offset
;
3024 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3025 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
3026 beg_of_comp_unit
= info_ptr
;
3028 cu
= alloc_one_comp_unit (objfile
);
3030 /* If an error occurs while loading, release our storage. */
3031 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3033 /* Read in the comp_unit header. */
3034 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
3036 /* Complete the cu_header. */
3037 cu
->header
.offset
= offset
;
3038 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3040 /* Read the abbrevs for this compilation unit. */
3041 dwarf2_read_abbrevs (abfd
, cu
);
3042 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3044 /* Link this compilation unit into the compilation unit tree. */
3046 cu
->per_cu
= per_cu
;
3047 cu
->type_hash
= per_cu
->type_hash
;
3049 cu
->dies
= read_comp_unit (info_ptr
, cu
);
3051 /* We try not to read any attributes in this function, because not
3052 all objfiles needed for references have been loaded yet, and symbol
3053 table processing isn't initialized. But we have to set the CU language,
3054 or we won't be able to build types correctly. */
3055 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
3057 set_cu_language (DW_UNSND (attr
), cu
);
3059 set_cu_language (language_minimal
, cu
);
3061 /* Link this CU into read_in_chain. */
3062 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3063 dwarf2_per_objfile
->read_in_chain
= per_cu
;
3065 do_cleanups (back_to
);
3067 /* We've successfully allocated this compilation unit. Let our caller
3068 clean it up when finished with it. */
3069 discard_cleanups (free_cu_cleanup
);
3072 /* Generate full symbol information for PST and CU, whose DIEs have
3073 already been loaded into memory. */
3076 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
3078 struct partial_symtab
*pst
= per_cu
->psymtab
;
3079 struct dwarf2_cu
*cu
= per_cu
->cu
;
3080 struct objfile
*objfile
= pst
->objfile
;
3081 bfd
*abfd
= objfile
->obfd
;
3082 CORE_ADDR lowpc
, highpc
;
3083 struct symtab
*symtab
;
3084 struct cleanup
*back_to
;
3087 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3090 back_to
= make_cleanup (really_free_pendings
, NULL
);
3092 cu
->list_in_scope
= &file_symbols
;
3094 dwarf2_find_base_address (cu
->dies
, cu
);
3096 /* Do line number decoding in read_file_scope () */
3097 process_die (cu
->dies
, cu
);
3099 /* Some compilers don't define a DW_AT_high_pc attribute for the
3100 compilation unit. If the DW_AT_high_pc is missing, synthesize
3101 it, by scanning the DIE's below the compilation unit. */
3102 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
3104 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
3106 /* Set symtab language to language from DW_AT_language.
3107 If the compilation is from a C file generated by language preprocessors,
3108 do not set the language if it was already deduced by start_subfile. */
3110 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
3112 symtab
->language
= cu
->language
;
3114 pst
->symtab
= symtab
;
3117 do_cleanups (back_to
);
3120 /* Process a die and its children. */
3123 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
3127 case DW_TAG_padding
:
3129 case DW_TAG_compile_unit
:
3130 read_file_scope (die
, cu
);
3132 case DW_TAG_type_unit
:
3133 read_type_unit_scope (die
, cu
);
3135 case DW_TAG_subprogram
:
3136 case DW_TAG_inlined_subroutine
:
3137 read_func_scope (die
, cu
);
3139 case DW_TAG_lexical_block
:
3140 case DW_TAG_try_block
:
3141 case DW_TAG_catch_block
:
3142 read_lexical_block_scope (die
, cu
);
3144 case DW_TAG_class_type
:
3145 case DW_TAG_interface_type
:
3146 case DW_TAG_structure_type
:
3147 case DW_TAG_union_type
:
3148 process_structure_scope (die
, cu
);
3150 case DW_TAG_enumeration_type
:
3151 process_enumeration_scope (die
, cu
);
3154 /* These dies have a type, but processing them does not create
3155 a symbol or recurse to process the children. Therefore we can
3156 read them on-demand through read_type_die. */
3157 case DW_TAG_subroutine_type
:
3158 case DW_TAG_set_type
:
3159 case DW_TAG_array_type
:
3160 case DW_TAG_pointer_type
:
3161 case DW_TAG_ptr_to_member_type
:
3162 case DW_TAG_reference_type
:
3163 case DW_TAG_string_type
:
3166 case DW_TAG_base_type
:
3167 case DW_TAG_subrange_type
:
3168 case DW_TAG_typedef
:
3169 /* Add a typedef symbol for the type definition, if it has a
3171 new_symbol (die
, read_type_die (die
, cu
), cu
);
3173 case DW_TAG_common_block
:
3174 read_common_block (die
, cu
);
3176 case DW_TAG_common_inclusion
:
3178 case DW_TAG_namespace
:
3179 processing_has_namespace_info
= 1;
3180 read_namespace (die
, cu
);
3183 read_module (die
, cu
);
3185 case DW_TAG_imported_declaration
:
3186 case DW_TAG_imported_module
:
3187 processing_has_namespace_info
= 1;
3188 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
3189 || cu
->language
!= language_fortran
))
3190 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
3191 dwarf_tag_name (die
->tag
));
3192 read_import_statement (die
, cu
);
3195 new_symbol (die
, NULL
, cu
);
3200 /* A helper function for dwarf2_compute_name which determines whether DIE
3201 needs to have the name of the scope prepended to the name listed in the
3205 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3209 case DW_TAG_namespace
:
3210 case DW_TAG_typedef
:
3211 case DW_TAG_class_type
:
3212 case DW_TAG_interface_type
:
3213 case DW_TAG_structure_type
:
3214 case DW_TAG_union_type
:
3215 case DW_TAG_enumeration_type
:
3216 case DW_TAG_enumerator
:
3217 case DW_TAG_subprogram
:
3221 case DW_TAG_variable
:
3222 /* We only need to prefix "globally" visible variables. These include
3223 any variable marked with DW_AT_external or any variable that
3224 lives in a namespace. [Variables in anonymous namespaces
3225 require prefixing, but they are not DW_AT_external.] */
3227 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
3229 struct dwarf2_cu
*spec_cu
= cu
;
3230 return die_needs_namespace (die_specification (die
, &spec_cu
),
3234 if (dwarf2_attr (die
, DW_AT_external
, cu
)
3235 || die
->parent
->tag
== DW_TAG_namespace
)
3245 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3246 compute the physname for the object, which include a method's
3247 formal parameters (C++/Java) and return type (Java).
3249 For Ada, return the DIE's linkage name rather than the fully qualified
3250 name. PHYSNAME is ignored..
3252 The result is allocated on the objfile_obstack and canonicalized. */
3255 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
3259 name
= dwarf2_name (die
, cu
);
3261 /* These are the only languages we know how to qualify names in. */
3263 && (cu
->language
== language_cplus
|| cu
->language
== language_java
))
3265 if (die_needs_namespace (die
, cu
))
3269 struct ui_file
*buf
;
3271 prefix
= determine_prefix (die
, cu
);
3272 buf
= mem_fileopen ();
3273 if (*prefix
!= '\0')
3275 char *prefixed_name
= typename_concat (NULL
, prefix
, name
, cu
);
3276 fputs_unfiltered (prefixed_name
, buf
);
3277 xfree (prefixed_name
);
3280 fputs_unfiltered (name
? name
: "", buf
);
3282 /* For Java and C++ methods, append formal parameter type
3283 information, if PHYSNAME. */
3285 if (physname
&& die
->tag
== DW_TAG_subprogram
3286 && (cu
->language
== language_cplus
3287 || cu
->language
== language_java
))
3289 struct type
*type
= read_type_die (die
, cu
);
3291 c_type_print_args (type
, buf
, 0, cu
->language
);
3293 if (cu
->language
== language_java
)
3295 /* For java, we must append the return type to method
3297 if (die
->tag
== DW_TAG_subprogram
)
3298 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
3301 else if (cu
->language
== language_cplus
)
3303 if (TYPE_NFIELDS (type
) > 0
3304 && TYPE_FIELD_ARTIFICIAL (type
, 0)
3305 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
3306 fputs_unfiltered (" const", buf
);
3310 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
3312 ui_file_delete (buf
);
3314 if (cu
->language
== language_cplus
)
3317 = dwarf2_canonicalize_name (name
, cu
,
3318 &cu
->objfile
->objfile_obstack
);
3324 else if (cu
->language
== language_ada
)
3326 /* For Ada unit, we prefer the linkage name over the name, as
3327 the former contains the exported name, which the user expects
3328 to be able to reference. Ideally, we want the user to be able
3329 to reference this entity using either natural or linkage name,
3330 but we haven't started looking at this enhancement yet. */
3331 struct attribute
*attr
;
3333 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
3334 if (attr
&& DW_STRING (attr
))
3335 name
= DW_STRING (attr
);
3341 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3342 If scope qualifiers are appropriate they will be added. The result
3343 will be allocated on the objfile_obstack, or NULL if the DIE does
3344 not have a name. NAME may either be from a previous call to
3345 dwarf2_name or NULL.
3347 The output string will be canonicalized (if C++/Java). */
3350 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3352 return dwarf2_compute_name (name
, die
, cu
, 0);
3355 /* Construct a physname for the given DIE in CU. NAME may either be
3356 from a previous call to dwarf2_name or NULL. The result will be
3357 allocated on the objfile_objstack or NULL if the DIE does not have a
3360 The output string will be canonicalized (if C++/Java). */
3363 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3365 return dwarf2_compute_name (name
, die
, cu
, 1);
3368 /* Read the import statement specified by the given die and record it. */
3371 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3373 struct attribute
*import_attr
;
3374 struct die_info
*imported_die
;
3375 struct dwarf2_cu
*imported_cu
;
3376 const char *imported_name
;
3377 const char *imported_name_prefix
;
3380 const char *import_prefix
;
3381 char *canonical_name
;
3383 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3384 if (import_attr
== NULL
)
3386 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3387 dwarf_tag_name (die
->tag
));
3392 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
3393 imported_name
= dwarf2_name (imported_die
, imported_cu
);
3394 if (imported_name
== NULL
)
3396 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3398 The import in the following code:
3412 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3413 <52> DW_AT_decl_file : 1
3414 <53> DW_AT_decl_line : 6
3415 <54> DW_AT_import : <0x75>
3416 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3418 <5b> DW_AT_decl_file : 1
3419 <5c> DW_AT_decl_line : 2
3420 <5d> DW_AT_type : <0x6e>
3422 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3423 <76> DW_AT_byte_size : 4
3424 <77> DW_AT_encoding : 5 (signed)
3426 imports the wrong die ( 0x75 instead of 0x58 ).
3427 This case will be ignored until the gcc bug is fixed. */
3431 /* Figure out the local name after import. */
3432 import_alias
= dwarf2_name (die
, cu
);
3434 /* Figure out where the statement is being imported to. */
3435 import_prefix
= determine_prefix (die
, cu
);
3437 /* Figure out what the scope of the imported die is and prepend it
3438 to the name of the imported die. */
3439 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
3441 if (strlen (imported_name_prefix
) > 0)
3443 canonical_name
= alloca (strlen (imported_name_prefix
)
3444 + 2 + strlen (imported_name
) + 1);
3445 strcpy (canonical_name
, imported_name_prefix
);
3446 strcat (canonical_name
, "::");
3447 strcat (canonical_name
, imported_name
);
3451 canonical_name
= alloca (strlen (imported_name
) + 1);
3452 strcpy (canonical_name
, imported_name
);
3455 cp_add_using_directive (import_prefix
,
3458 &cu
->objfile
->objfile_obstack
);
3462 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3464 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3468 free_cu_line_header (void *arg
)
3470 struct dwarf2_cu
*cu
= arg
;
3472 free_line_header (cu
->line_header
);
3473 cu
->line_header
= NULL
;
3477 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3479 struct objfile
*objfile
= cu
->objfile
;
3480 struct comp_unit_head
*cu_header
= &cu
->header
;
3481 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3482 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3483 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3484 struct attribute
*attr
;
3486 char *comp_dir
= NULL
;
3487 struct die_info
*child_die
;
3488 bfd
*abfd
= objfile
->obfd
;
3489 struct line_header
*line_header
= 0;
3492 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3494 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3496 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3497 from finish_block. */
3498 if (lowpc
== ((CORE_ADDR
) -1))
3503 /* Find the filename. Do not use dwarf2_name here, since the filename
3504 is not a source language identifier. */
3505 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3508 name
= DW_STRING (attr
);
3511 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3513 comp_dir
= DW_STRING (attr
);
3514 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3516 comp_dir
= ldirname (name
);
3517 if (comp_dir
!= NULL
)
3518 make_cleanup (xfree
, comp_dir
);
3520 if (comp_dir
!= NULL
)
3522 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3523 directory, get rid of it. */
3524 char *cp
= strchr (comp_dir
, ':');
3526 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3533 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3536 set_cu_language (DW_UNSND (attr
), cu
);
3539 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3541 cu
->producer
= DW_STRING (attr
);
3543 /* We assume that we're processing GCC output. */
3544 processing_gcc_compilation
= 2;
3546 processing_has_namespace_info
= 0;
3548 start_symtab (name
, comp_dir
, lowpc
);
3549 record_debugformat ("DWARF 2");
3550 record_producer (cu
->producer
);
3552 initialize_cu_func_list (cu
);
3554 /* Decode line number information if present. We do this before
3555 processing child DIEs, so that the line header table is available
3556 for DW_AT_decl_file. */
3557 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3560 unsigned int line_offset
= DW_UNSND (attr
);
3561 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3564 cu
->line_header
= line_header
;
3565 make_cleanup (free_cu_line_header
, cu
);
3566 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3570 /* Process all dies in compilation unit. */
3571 if (die
->child
!= NULL
)
3573 child_die
= die
->child
;
3574 while (child_die
&& child_die
->tag
)
3576 process_die (child_die
, cu
);
3577 child_die
= sibling_die (child_die
);
3581 /* Decode macro information, if present. Dwarf 2 macro information
3582 refers to information in the line number info statement program
3583 header, so we can only read it if we've read the header
3585 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3586 if (attr
&& line_header
)
3588 unsigned int macro_offset
= DW_UNSND (attr
);
3589 dwarf_decode_macros (line_header
, macro_offset
,
3590 comp_dir
, abfd
, cu
);
3592 do_cleanups (back_to
);
3595 /* For TUs we want to skip the first top level sibling if it's not the
3596 actual type being defined by this TU. In this case the first top
3597 level sibling is there to provide context only. */
3600 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3602 struct objfile
*objfile
= cu
->objfile
;
3603 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3605 struct attribute
*attr
;
3607 char *comp_dir
= NULL
;
3608 struct die_info
*child_die
;
3609 bfd
*abfd
= objfile
->obfd
;
3610 struct line_header
*line_header
= 0;
3612 /* start_symtab needs a low pc, but we don't really have one.
3613 Do what read_file_scope would do in the absence of such info. */
3614 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3616 /* Find the filename. Do not use dwarf2_name here, since the filename
3617 is not a source language identifier. */
3618 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3620 name
= DW_STRING (attr
);
3622 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3624 comp_dir
= DW_STRING (attr
);
3625 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3627 comp_dir
= ldirname (name
);
3628 if (comp_dir
!= NULL
)
3629 make_cleanup (xfree
, comp_dir
);
3635 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3637 set_cu_language (DW_UNSND (attr
), cu
);
3639 /* This isn't technically needed today. It is done for symmetry
3640 with read_file_scope. */
3641 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3643 cu
->producer
= DW_STRING (attr
);
3645 /* We assume that we're processing GCC output. */
3646 processing_gcc_compilation
= 2;
3648 processing_has_namespace_info
= 0;
3650 start_symtab (name
, comp_dir
, lowpc
);
3651 record_debugformat ("DWARF 2");
3652 record_producer (cu
->producer
);
3654 /* Process the dies in the type unit. */
3655 if (die
->child
== NULL
)
3657 dump_die_for_error (die
);
3658 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3659 bfd_get_filename (abfd
));
3662 child_die
= die
->child
;
3664 while (child_die
&& child_die
->tag
)
3666 process_die (child_die
, cu
);
3668 child_die
= sibling_die (child_die
);
3671 do_cleanups (back_to
);
3675 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3676 struct dwarf2_cu
*cu
)
3678 struct function_range
*thisfn
;
3680 thisfn
= (struct function_range
*)
3681 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3682 thisfn
->name
= name
;
3683 thisfn
->lowpc
= lowpc
;
3684 thisfn
->highpc
= highpc
;
3685 thisfn
->seen_line
= 0;
3686 thisfn
->next
= NULL
;
3688 if (cu
->last_fn
== NULL
)
3689 cu
->first_fn
= thisfn
;
3691 cu
->last_fn
->next
= thisfn
;
3693 cu
->last_fn
= thisfn
;
3696 /* qsort helper for inherit_abstract_dies. */
3699 unsigned_int_compar (const void *ap
, const void *bp
)
3701 unsigned int a
= *(unsigned int *) ap
;
3702 unsigned int b
= *(unsigned int *) bp
;
3704 return (a
> b
) - (b
> a
);
3707 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3708 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3709 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3712 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3714 struct die_info
*child_die
;
3715 unsigned die_children_count
;
3716 /* CU offsets which were referenced by children of the current DIE. */
3718 unsigned *offsets_end
, *offsetp
;
3719 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3720 struct die_info
*origin_die
;
3721 /* Iterator of the ORIGIN_DIE children. */
3722 struct die_info
*origin_child_die
;
3723 struct cleanup
*cleanups
;
3724 struct attribute
*attr
;
3726 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3730 origin_die
= follow_die_ref (die
, attr
, &cu
);
3731 if (die
->tag
!= origin_die
->tag
3732 && !(die
->tag
== DW_TAG_inlined_subroutine
3733 && origin_die
->tag
== DW_TAG_subprogram
))
3734 complaint (&symfile_complaints
,
3735 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3736 die
->offset
, origin_die
->offset
);
3738 child_die
= die
->child
;
3739 die_children_count
= 0;
3740 while (child_die
&& child_die
->tag
)
3742 child_die
= sibling_die (child_die
);
3743 die_children_count
++;
3745 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3746 cleanups
= make_cleanup (xfree
, offsets
);
3748 offsets_end
= offsets
;
3749 child_die
= die
->child
;
3750 while (child_die
&& child_die
->tag
)
3752 /* For each CHILD_DIE, find the corresponding child of
3753 ORIGIN_DIE. If there is more than one layer of
3754 DW_AT_abstract_origin, follow them all; there shouldn't be,
3755 but GCC versions at least through 4.4 generate this (GCC PR
3757 struct die_info
*child_origin_die
= child_die
;
3760 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
3763 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
3766 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3767 counterpart may exist. */
3768 if (child_origin_die
!= child_die
)
3770 if (child_die
->tag
!= child_origin_die
->tag
3771 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3772 && child_origin_die
->tag
== DW_TAG_subprogram
))
3773 complaint (&symfile_complaints
,
3774 _("Child DIE 0x%x and its abstract origin 0x%x have "
3775 "different tags"), child_die
->offset
,
3776 child_origin_die
->offset
);
3777 if (child_origin_die
->parent
!= origin_die
)
3778 complaint (&symfile_complaints
,
3779 _("Child DIE 0x%x and its abstract origin 0x%x have "
3780 "different parents"), child_die
->offset
,
3781 child_origin_die
->offset
);
3783 *offsets_end
++ = child_origin_die
->offset
;
3785 child_die
= sibling_die (child_die
);
3787 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3788 unsigned_int_compar
);
3789 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3790 if (offsetp
[-1] == *offsetp
)
3791 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3792 "to DIE 0x%x as their abstract origin"),
3793 die
->offset
, *offsetp
);
3796 origin_child_die
= origin_die
->child
;
3797 while (origin_child_die
&& origin_child_die
->tag
)
3799 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3800 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3802 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3804 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3805 process_die (origin_child_die
, cu
);
3807 origin_child_die
= sibling_die (origin_child_die
);
3810 do_cleanups (cleanups
);
3814 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3816 struct objfile
*objfile
= cu
->objfile
;
3817 struct context_stack
*new;
3820 struct die_info
*child_die
;
3821 struct attribute
*attr
, *call_line
, *call_file
;
3824 struct block
*block
;
3825 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3829 /* If we do not have call site information, we can't show the
3830 caller of this inlined function. That's too confusing, so
3831 only use the scope for local variables. */
3832 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3833 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3834 if (call_line
== NULL
|| call_file
== NULL
)
3836 read_lexical_block_scope (die
, cu
);
3841 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3843 name
= dwarf2_name (die
, cu
);
3845 /* Ignore functions with missing or empty names and functions with
3846 missing or invalid low and high pc attributes. */
3847 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3853 /* Record the function range for dwarf_decode_lines. */
3854 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3856 new = push_context (0, lowpc
);
3857 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3859 /* If there is a location expression for DW_AT_frame_base, record
3861 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3863 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3864 expression is being recorded directly in the function's symbol
3865 and not in a separate frame-base object. I guess this hack is
3866 to avoid adding some sort of frame-base adjunct/annex to the
3867 function's symbol :-(. The problem with doing this is that it
3868 results in a function symbol with a location expression that
3869 has nothing to do with the location of the function, ouch! The
3870 relationship should be: a function's symbol has-a frame base; a
3871 frame-base has-a location expression. */
3872 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3874 cu
->list_in_scope
= &local_symbols
;
3876 if (die
->child
!= NULL
)
3878 child_die
= die
->child
;
3879 while (child_die
&& child_die
->tag
)
3881 process_die (child_die
, cu
);
3882 child_die
= sibling_die (child_die
);
3886 inherit_abstract_dies (die
, cu
);
3888 new = pop_context ();
3889 /* Make a block for the local symbols within. */
3890 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3891 lowpc
, highpc
, objfile
);
3893 /* For C++, set the block's scope. */
3894 if (cu
->language
== language_cplus
)
3895 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3896 determine_prefix (die
, cu
),
3897 processing_has_namespace_info
);
3899 /* If we have address ranges, record them. */
3900 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3902 /* In C++, we can have functions nested inside functions (e.g., when
3903 a function declares a class that has methods). This means that
3904 when we finish processing a function scope, we may need to go
3905 back to building a containing block's symbol lists. */
3906 local_symbols
= new->locals
;
3907 param_symbols
= new->params
;
3908 using_directives
= new->using_directives
;
3910 /* If we've finished processing a top-level function, subsequent
3911 symbols go in the file symbol list. */
3912 if (outermost_context_p ())
3913 cu
->list_in_scope
= &file_symbols
;
3916 /* Process all the DIES contained within a lexical block scope. Start
3917 a new scope, process the dies, and then close the scope. */
3920 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3922 struct objfile
*objfile
= cu
->objfile
;
3923 struct context_stack
*new;
3924 CORE_ADDR lowpc
, highpc
;
3925 struct die_info
*child_die
;
3928 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3930 /* Ignore blocks with missing or invalid low and high pc attributes. */
3931 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3932 as multiple lexical blocks? Handling children in a sane way would
3933 be nasty. Might be easier to properly extend generic blocks to
3935 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3940 push_context (0, lowpc
);
3941 if (die
->child
!= NULL
)
3943 child_die
= die
->child
;
3944 while (child_die
&& child_die
->tag
)
3946 process_die (child_die
, cu
);
3947 child_die
= sibling_die (child_die
);
3950 new = pop_context ();
3952 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
3955 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3958 /* Note that recording ranges after traversing children, as we
3959 do here, means that recording a parent's ranges entails
3960 walking across all its children's ranges as they appear in
3961 the address map, which is quadratic behavior.
3963 It would be nicer to record the parent's ranges before
3964 traversing its children, simply overriding whatever you find
3965 there. But since we don't even decide whether to create a
3966 block until after we've traversed its children, that's hard
3968 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3970 local_symbols
= new->locals
;
3971 using_directives
= new->using_directives
;
3974 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3975 Return 1 if the attributes are present and valid, otherwise, return 0.
3976 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3979 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3980 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3981 struct partial_symtab
*ranges_pst
)
3983 struct objfile
*objfile
= cu
->objfile
;
3984 struct comp_unit_head
*cu_header
= &cu
->header
;
3985 bfd
*obfd
= objfile
->obfd
;
3986 unsigned int addr_size
= cu_header
->addr_size
;
3987 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3988 /* Base address selection entry. */
3999 found_base
= cu
->base_known
;
4000 base
= cu
->base_address
;
4002 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
4003 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4005 complaint (&symfile_complaints
,
4006 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4010 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4012 /* Read in the largest possible address. */
4013 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
4014 if ((marker
& mask
) == mask
)
4016 /* If we found the largest possible address, then
4017 read the base address. */
4018 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4019 buffer
+= 2 * addr_size
;
4020 offset
+= 2 * addr_size
;
4026 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4030 CORE_ADDR range_beginning
, range_end
;
4032 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
4033 buffer
+= addr_size
;
4034 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
4035 buffer
+= addr_size
;
4036 offset
+= 2 * addr_size
;
4038 /* An end of list marker is a pair of zero addresses. */
4039 if (range_beginning
== 0 && range_end
== 0)
4040 /* Found the end of list entry. */
4043 /* Each base address selection entry is a pair of 2 values.
4044 The first is the largest possible address, the second is
4045 the base address. Check for a base address here. */
4046 if ((range_beginning
& mask
) == mask
)
4048 /* If we found the largest possible address, then
4049 read the base address. */
4050 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4057 /* We have no valid base address for the ranges
4059 complaint (&symfile_complaints
,
4060 _("Invalid .debug_ranges data (no base address)"));
4064 range_beginning
+= base
;
4067 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
4068 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4069 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
4072 /* FIXME: This is recording everything as a low-high
4073 segment of consecutive addresses. We should have a
4074 data structure for discontiguous block ranges
4078 low
= range_beginning
;
4084 if (range_beginning
< low
)
4085 low
= range_beginning
;
4086 if (range_end
> high
)
4092 /* If the first entry is an end-of-list marker, the range
4093 describes an empty scope, i.e. no instructions. */
4099 *high_return
= high
;
4103 /* Get low and high pc attributes from a die. Return 1 if the attributes
4104 are present and valid, otherwise, return 0. Return -1 if the range is
4105 discontinuous, i.e. derived from DW_AT_ranges information. */
4107 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
4108 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
4109 struct partial_symtab
*pst
)
4111 struct attribute
*attr
;
4116 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4119 high
= DW_ADDR (attr
);
4120 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4122 low
= DW_ADDR (attr
);
4124 /* Found high w/o low attribute. */
4127 /* Found consecutive range of addresses. */
4132 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4135 /* Value of the DW_AT_ranges attribute is the offset in the
4136 .debug_ranges section. */
4137 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
4139 /* Found discontinuous range of addresses. */
4147 /* When using the GNU linker, .gnu.linkonce. sections are used to
4148 eliminate duplicate copies of functions and vtables and such.
4149 The linker will arbitrarily choose one and discard the others.
4150 The AT_*_pc values for such functions refer to local labels in
4151 these sections. If the section from that file was discarded, the
4152 labels are not in the output, so the relocs get a value of 0.
4153 If this is a discarded function, mark the pc bounds as invalid,
4154 so that GDB will ignore it. */
4155 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
4163 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4164 its low and high PC addresses. Do nothing if these addresses could not
4165 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4166 and HIGHPC to the high address if greater than HIGHPC. */
4169 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
4170 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4171 struct dwarf2_cu
*cu
)
4173 CORE_ADDR low
, high
;
4174 struct die_info
*child
= die
->child
;
4176 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
4178 *lowpc
= min (*lowpc
, low
);
4179 *highpc
= max (*highpc
, high
);
4182 /* If the language does not allow nested subprograms (either inside
4183 subprograms or lexical blocks), we're done. */
4184 if (cu
->language
!= language_ada
)
4187 /* Check all the children of the given DIE. If it contains nested
4188 subprograms, then check their pc bounds. Likewise, we need to
4189 check lexical blocks as well, as they may also contain subprogram
4191 while (child
&& child
->tag
)
4193 if (child
->tag
== DW_TAG_subprogram
4194 || child
->tag
== DW_TAG_lexical_block
)
4195 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
4196 child
= sibling_die (child
);
4200 /* Get the low and high pc's represented by the scope DIE, and store
4201 them in *LOWPC and *HIGHPC. If the correct values can't be
4202 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4205 get_scope_pc_bounds (struct die_info
*die
,
4206 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4207 struct dwarf2_cu
*cu
)
4209 CORE_ADDR best_low
= (CORE_ADDR
) -1;
4210 CORE_ADDR best_high
= (CORE_ADDR
) 0;
4211 CORE_ADDR current_low
, current_high
;
4213 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
4215 best_low
= current_low
;
4216 best_high
= current_high
;
4220 struct die_info
*child
= die
->child
;
4222 while (child
&& child
->tag
)
4224 switch (child
->tag
) {
4225 case DW_TAG_subprogram
:
4226 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
4228 case DW_TAG_namespace
:
4229 /* FIXME: carlton/2004-01-16: Should we do this for
4230 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4231 that current GCC's always emit the DIEs corresponding
4232 to definitions of methods of classes as children of a
4233 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4234 the DIEs giving the declarations, which could be
4235 anywhere). But I don't see any reason why the
4236 standards says that they have to be there. */
4237 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
4239 if (current_low
!= ((CORE_ADDR
) -1))
4241 best_low
= min (best_low
, current_low
);
4242 best_high
= max (best_high
, current_high
);
4250 child
= sibling_die (child
);
4255 *highpc
= best_high
;
4258 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4261 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
4262 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
4264 struct attribute
*attr
;
4266 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4269 CORE_ADDR high
= DW_ADDR (attr
);
4270 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4273 CORE_ADDR low
= DW_ADDR (attr
);
4274 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
4278 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4281 bfd
*obfd
= cu
->objfile
->obfd
;
4283 /* The value of the DW_AT_ranges attribute is the offset of the
4284 address range list in the .debug_ranges section. */
4285 unsigned long offset
= DW_UNSND (attr
);
4286 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4288 /* For some target architectures, but not others, the
4289 read_address function sign-extends the addresses it returns.
4290 To recognize base address selection entries, we need a
4292 unsigned int addr_size
= cu
->header
.addr_size
;
4293 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4295 /* The base address, to which the next pair is relative. Note
4296 that this 'base' is a DWARF concept: most entries in a range
4297 list are relative, to reduce the number of relocs against the
4298 debugging information. This is separate from this function's
4299 'baseaddr' argument, which GDB uses to relocate debugging
4300 information from a shared library based on the address at
4301 which the library was loaded. */
4302 CORE_ADDR base
= cu
->base_address
;
4303 int base_known
= cu
->base_known
;
4305 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
4306 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4308 complaint (&symfile_complaints
,
4309 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4316 unsigned int bytes_read
;
4317 CORE_ADDR start
, end
;
4319 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4320 buffer
+= bytes_read
;
4321 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4322 buffer
+= bytes_read
;
4324 /* Did we find the end of the range list? */
4325 if (start
== 0 && end
== 0)
4328 /* Did we find a base address selection entry? */
4329 else if ((start
& base_select_mask
) == base_select_mask
)
4335 /* We found an ordinary address range. */
4340 complaint (&symfile_complaints
,
4341 _("Invalid .debug_ranges data (no base address)"));
4345 record_block_range (block
,
4346 baseaddr
+ base
+ start
,
4347 baseaddr
+ base
+ end
- 1);
4353 /* Add an aggregate field to the field list. */
4356 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
4357 struct dwarf2_cu
*cu
)
4359 struct objfile
*objfile
= cu
->objfile
;
4360 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4361 struct nextfield
*new_field
;
4362 struct attribute
*attr
;
4364 char *fieldname
= "";
4366 /* Allocate a new field list entry and link it in. */
4367 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
4368 make_cleanup (xfree
, new_field
);
4369 memset (new_field
, 0, sizeof (struct nextfield
));
4371 if (die
->tag
== DW_TAG_inheritance
)
4373 new_field
->next
= fip
->baseclasses
;
4374 fip
->baseclasses
= new_field
;
4378 new_field
->next
= fip
->fields
;
4379 fip
->fields
= new_field
;
4383 /* Handle accessibility and virtuality of field.
4384 The default accessibility for members is public, the default
4385 accessibility for inheritance is private. */
4386 if (die
->tag
!= DW_TAG_inheritance
)
4387 new_field
->accessibility
= DW_ACCESS_public
;
4389 new_field
->accessibility
= DW_ACCESS_private
;
4390 new_field
->virtuality
= DW_VIRTUALITY_none
;
4392 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4394 new_field
->accessibility
= DW_UNSND (attr
);
4395 if (new_field
->accessibility
!= DW_ACCESS_public
)
4396 fip
->non_public_fields
= 1;
4397 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4399 new_field
->virtuality
= DW_UNSND (attr
);
4401 fp
= &new_field
->field
;
4403 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
4405 /* Data member other than a C++ static data member. */
4407 /* Get type of field. */
4408 fp
->type
= die_type (die
, cu
);
4410 SET_FIELD_BITPOS (*fp
, 0);
4412 /* Get bit size of field (zero if none). */
4413 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
4416 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
4420 FIELD_BITSIZE (*fp
) = 0;
4423 /* Get bit offset of field. */
4424 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4427 int byte_offset
= 0;
4429 if (attr_form_is_section_offset (attr
))
4430 dwarf2_complex_location_expr_complaint ();
4431 else if (attr_form_is_constant (attr
))
4432 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4433 else if (attr_form_is_block (attr
))
4434 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4436 dwarf2_complex_location_expr_complaint ();
4438 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4440 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
4443 if (gdbarch_bits_big_endian (gdbarch
))
4445 /* For big endian bits, the DW_AT_bit_offset gives the
4446 additional bit offset from the MSB of the containing
4447 anonymous object to the MSB of the field. We don't
4448 have to do anything special since we don't need to
4449 know the size of the anonymous object. */
4450 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
4454 /* For little endian bits, compute the bit offset to the
4455 MSB of the anonymous object, subtract off the number of
4456 bits from the MSB of the field to the MSB of the
4457 object, and then subtract off the number of bits of
4458 the field itself. The result is the bit offset of
4459 the LSB of the field. */
4461 int bit_offset
= DW_UNSND (attr
);
4463 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4466 /* The size of the anonymous object containing
4467 the bit field is explicit, so use the
4468 indicated size (in bytes). */
4469 anonymous_size
= DW_UNSND (attr
);
4473 /* The size of the anonymous object containing
4474 the bit field must be inferred from the type
4475 attribute of the data member containing the
4477 anonymous_size
= TYPE_LENGTH (fp
->type
);
4479 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4480 - bit_offset
- FIELD_BITSIZE (*fp
);
4484 /* Get name of field. */
4485 fieldname
= dwarf2_name (die
, cu
);
4486 if (fieldname
== NULL
)
4489 /* The name is already allocated along with this objfile, so we don't
4490 need to duplicate it for the type. */
4491 fp
->name
= fieldname
;
4493 /* Change accessibility for artificial fields (e.g. virtual table
4494 pointer or virtual base class pointer) to private. */
4495 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4497 FIELD_ARTIFICIAL (*fp
) = 1;
4498 new_field
->accessibility
= DW_ACCESS_private
;
4499 fip
->non_public_fields
= 1;
4502 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4504 /* C++ static member. */
4506 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4507 is a declaration, but all versions of G++ as of this writing
4508 (so through at least 3.2.1) incorrectly generate
4509 DW_TAG_variable tags. */
4513 /* Get name of field. */
4514 fieldname
= dwarf2_name (die
, cu
);
4515 if (fieldname
== NULL
)
4518 /* Get physical name. */
4519 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4521 /* The name is already allocated along with this objfile, so we don't
4522 need to duplicate it for the type. */
4523 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4524 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4525 FIELD_NAME (*fp
) = fieldname
;
4527 else if (die
->tag
== DW_TAG_inheritance
)
4529 /* C++ base class field. */
4530 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4533 int byte_offset
= 0;
4535 if (attr_form_is_section_offset (attr
))
4536 dwarf2_complex_location_expr_complaint ();
4537 else if (attr_form_is_constant (attr
))
4538 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4539 else if (attr_form_is_block (attr
))
4540 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4542 dwarf2_complex_location_expr_complaint ();
4544 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4546 FIELD_BITSIZE (*fp
) = 0;
4547 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4548 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4549 fip
->nbaseclasses
++;
4553 /* Create the vector of fields, and attach it to the type. */
4556 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4557 struct dwarf2_cu
*cu
)
4559 int nfields
= fip
->nfields
;
4561 /* Record the field count, allocate space for the array of fields,
4562 and create blank accessibility bitfields if necessary. */
4563 TYPE_NFIELDS (type
) = nfields
;
4564 TYPE_FIELDS (type
) = (struct field
*)
4565 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4566 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4568 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
4570 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4572 TYPE_FIELD_PRIVATE_BITS (type
) =
4573 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4574 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4576 TYPE_FIELD_PROTECTED_BITS (type
) =
4577 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4578 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4580 TYPE_FIELD_IGNORE_BITS (type
) =
4581 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4582 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4585 /* If the type has baseclasses, allocate and clear a bit vector for
4586 TYPE_FIELD_VIRTUAL_BITS. */
4587 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
4589 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4590 unsigned char *pointer
;
4592 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4593 pointer
= TYPE_ALLOC (type
, num_bytes
);
4594 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4595 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4596 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4599 /* Copy the saved-up fields into the field vector. Start from the head
4600 of the list, adding to the tail of the field array, so that they end
4601 up in the same order in the array in which they were added to the list. */
4602 while (nfields
-- > 0)
4604 struct nextfield
*fieldp
;
4608 fieldp
= fip
->fields
;
4609 fip
->fields
= fieldp
->next
;
4613 fieldp
= fip
->baseclasses
;
4614 fip
->baseclasses
= fieldp
->next
;
4617 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
4618 switch (fieldp
->accessibility
)
4620 case DW_ACCESS_private
:
4621 if (cu
->language
!= language_ada
)
4622 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4625 case DW_ACCESS_protected
:
4626 if (cu
->language
!= language_ada
)
4627 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4630 case DW_ACCESS_public
:
4634 /* Unknown accessibility. Complain and treat it as public. */
4636 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4637 fieldp
->accessibility
);
4641 if (nfields
< fip
->nbaseclasses
)
4643 switch (fieldp
->virtuality
)
4645 case DW_VIRTUALITY_virtual
:
4646 case DW_VIRTUALITY_pure_virtual
:
4647 if (cu
->language
== language_ada
)
4648 error ("unexpected virtuality in component of Ada type");
4649 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4656 /* Add a member function to the proper fieldlist. */
4659 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4660 struct type
*type
, struct dwarf2_cu
*cu
)
4662 struct objfile
*objfile
= cu
->objfile
;
4663 struct attribute
*attr
;
4664 struct fnfieldlist
*flp
;
4666 struct fn_field
*fnp
;
4669 struct nextfnfield
*new_fnfield
;
4670 struct type
*this_type
;
4672 if (cu
->language
== language_ada
)
4673 error ("unexpected member function in Ada type");
4675 /* Get name of member function. */
4676 fieldname
= dwarf2_name (die
, cu
);
4677 if (fieldname
== NULL
)
4680 /* Get the mangled name. */
4681 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4683 /* Look up member function name in fieldlist. */
4684 for (i
= 0; i
< fip
->nfnfields
; i
++)
4686 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4690 /* Create new list element if necessary. */
4691 if (i
< fip
->nfnfields
)
4692 flp
= &fip
->fnfieldlists
[i
];
4695 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4697 fip
->fnfieldlists
= (struct fnfieldlist
*)
4698 xrealloc (fip
->fnfieldlists
,
4699 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4700 * sizeof (struct fnfieldlist
));
4701 if (fip
->nfnfields
== 0)
4702 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4704 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4705 flp
->name
= fieldname
;
4711 /* Create a new member function field and chain it to the field list
4713 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4714 make_cleanup (xfree
, new_fnfield
);
4715 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4716 new_fnfield
->next
= flp
->head
;
4717 flp
->head
= new_fnfield
;
4720 /* Fill in the member function field info. */
4721 fnp
= &new_fnfield
->fnfield
;
4722 /* The name is already allocated along with this objfile, so we don't
4723 need to duplicate it for the type. */
4724 fnp
->physname
= physname
? physname
: "";
4725 fnp
->type
= alloc_type (objfile
);
4726 this_type
= read_type_die (die
, cu
);
4727 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4729 int nparams
= TYPE_NFIELDS (this_type
);
4731 /* TYPE is the domain of this method, and THIS_TYPE is the type
4732 of the method itself (TYPE_CODE_METHOD). */
4733 smash_to_method_type (fnp
->type
, type
,
4734 TYPE_TARGET_TYPE (this_type
),
4735 TYPE_FIELDS (this_type
),
4736 TYPE_NFIELDS (this_type
),
4737 TYPE_VARARGS (this_type
));
4739 /* Handle static member functions.
4740 Dwarf2 has no clean way to discern C++ static and non-static
4741 member functions. G++ helps GDB by marking the first
4742 parameter for non-static member functions (which is the
4743 this pointer) as artificial. We obtain this information
4744 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4745 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4746 fnp
->voffset
= VOFFSET_STATIC
;
4749 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4752 /* Get fcontext from DW_AT_containing_type if present. */
4753 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4754 fnp
->fcontext
= die_containing_type (die
, cu
);
4756 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4757 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4759 /* Get accessibility. */
4760 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4763 switch (DW_UNSND (attr
))
4765 case DW_ACCESS_private
:
4766 fnp
->is_private
= 1;
4768 case DW_ACCESS_protected
:
4769 fnp
->is_protected
= 1;
4774 /* Check for artificial methods. */
4775 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4776 if (attr
&& DW_UNSND (attr
) != 0)
4777 fnp
->is_artificial
= 1;
4779 /* Get index in virtual function table if it is a virtual member
4780 function. For GCC, this is an offset in the appropriate
4781 virtual table, as specified by DW_AT_containing_type. For
4782 everyone else, it is an expression to be evaluated relative
4783 to the object address. */
4785 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4786 if (attr
&& fnp
->fcontext
)
4788 /* Support the .debug_loc offsets */
4789 if (attr_form_is_block (attr
))
4791 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4793 else if (attr_form_is_section_offset (attr
))
4795 dwarf2_complex_location_expr_complaint ();
4799 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4805 /* We only support trivial expressions here. This hack will work
4806 for v3 classes, which always start with the vtable pointer. */
4807 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0
4808 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref
)
4810 struct dwarf_block blk
;
4811 blk
.size
= DW_BLOCK (attr
)->size
- 1;
4812 blk
.data
= DW_BLOCK (attr
)->data
+ 1;
4813 fnp
->voffset
= decode_locdesc (&blk
, cu
);
4814 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
4815 dwarf2_complex_location_expr_complaint ();
4817 fnp
->voffset
/= cu
->header
.addr_size
;
4819 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
4822 dwarf2_complex_location_expr_complaint ();
4826 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4827 if (attr
&& DW_UNSND (attr
))
4829 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4830 complaint (&symfile_complaints
,
4831 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4832 fieldname
, die
->offset
);
4833 TYPE_CPLUS_DYNAMIC (type
) = 1;
4838 /* Create the vector of member function fields, and attach it to the type. */
4841 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4842 struct dwarf2_cu
*cu
)
4844 struct fnfieldlist
*flp
;
4845 int total_length
= 0;
4848 if (cu
->language
== language_ada
)
4849 error ("unexpected member functions in Ada type");
4851 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4852 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4853 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4855 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4857 struct nextfnfield
*nfp
= flp
->head
;
4858 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4861 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4862 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4863 fn_flp
->fn_fields
= (struct fn_field
*)
4864 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4865 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4866 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4868 total_length
+= flp
->length
;
4871 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4872 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4875 /* Returns non-zero if NAME is the name of a vtable member in CU's
4876 language, zero otherwise. */
4878 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4880 static const char vptr
[] = "_vptr";
4881 static const char vtable
[] = "vtable";
4883 /* Look for the C++ and Java forms of the vtable. */
4884 if ((cu
->language
== language_java
4885 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4886 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4887 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4893 /* GCC outputs unnamed structures that are really pointers to member
4894 functions, with the ABI-specified layout. If TYPE describes
4895 such a structure, smash it into a member function type.
4897 GCC shouldn't do this; it should just output pointer to member DIEs.
4898 This is GCC PR debug/28767. */
4901 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
4903 struct type
*pfn_type
, *domain_type
, *new_type
;
4905 /* Check for a structure with no name and two children. */
4906 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
4909 /* Check for __pfn and __delta members. */
4910 if (TYPE_FIELD_NAME (type
, 0) == NULL
4911 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
4912 || TYPE_FIELD_NAME (type
, 1) == NULL
4913 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
4916 /* Find the type of the method. */
4917 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
4918 if (pfn_type
== NULL
4919 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4920 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4923 /* Look for the "this" argument. */
4924 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4925 if (TYPE_NFIELDS (pfn_type
) == 0
4926 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
4927 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4930 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4931 new_type
= alloc_type (objfile
);
4932 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4933 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4934 TYPE_VARARGS (pfn_type
));
4935 smash_to_methodptr_type (type
, new_type
);
4938 /* Called when we find the DIE that starts a structure or union scope
4939 (definition) to process all dies that define the members of the
4942 NOTE: we need to call struct_type regardless of whether or not the
4943 DIE has an at_name attribute, since it might be an anonymous
4944 structure or union. This gets the type entered into our set of
4947 However, if the structure is incomplete (an opaque struct/union)
4948 then suppress creating a symbol table entry for it since gdb only
4949 wants to find the one with the complete definition. Note that if
4950 it is complete, we just call new_symbol, which does it's own
4951 checking about whether the struct/union is anonymous or not (and
4952 suppresses creating a symbol table entry itself). */
4954 static struct type
*
4955 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4957 struct objfile
*objfile
= cu
->objfile
;
4959 struct attribute
*attr
;
4961 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4963 /* If the definition of this type lives in .debug_types, read that type.
4964 Don't follow DW_AT_specification though, that will take us back up
4965 the chain and we want to go down. */
4966 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
4969 struct dwarf2_cu
*type_cu
= cu
;
4970 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
4971 /* We could just recurse on read_structure_type, but we need to call
4972 get_die_type to ensure only one type for this DIE is created.
4973 This is important, for example, because for c++ classes we need
4974 TYPE_NAME set which is only done by new_symbol. Blech. */
4975 type
= read_type_die (type_die
, type_cu
);
4976 return set_die_type (die
, type
, cu
);
4979 type
= alloc_type (objfile
);
4980 INIT_CPLUS_SPECIFIC (type
);
4982 name
= dwarf2_name (die
, cu
);
4985 if (cu
->language
== language_cplus
4986 || cu
->language
== language_java
)
4988 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
4989 if (die
->tag
== DW_TAG_structure_type
4990 || die
->tag
== DW_TAG_class_type
)
4991 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
4995 /* The name is already allocated along with this objfile, so
4996 we don't need to duplicate it for the type. */
4997 TYPE_TAG_NAME (type
) = (char *) name
;
4998 if (die
->tag
== DW_TAG_class_type
)
4999 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5003 if (die
->tag
== DW_TAG_structure_type
)
5005 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
5007 else if (die
->tag
== DW_TAG_union_type
)
5009 TYPE_CODE (type
) = TYPE_CODE_UNION
;
5013 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
5016 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
5017 TYPE_DECLARED_CLASS (type
) = 1;
5019 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5022 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5026 TYPE_LENGTH (type
) = 0;
5029 TYPE_STUB_SUPPORTED (type
) = 1;
5030 if (die_is_declaration (die
, cu
))
5031 TYPE_STUB (type
) = 1;
5033 set_descriptive_type (type
, die
, cu
);
5035 /* We need to add the type field to the die immediately so we don't
5036 infinitely recurse when dealing with pointers to the structure
5037 type within the structure itself. */
5038 set_die_type (die
, type
, cu
);
5040 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
5042 struct field_info fi
;
5043 struct die_info
*child_die
;
5045 memset (&fi
, 0, sizeof (struct field_info
));
5047 child_die
= die
->child
;
5049 while (child_die
&& child_die
->tag
)
5051 if (child_die
->tag
== DW_TAG_member
5052 || child_die
->tag
== DW_TAG_variable
)
5054 /* NOTE: carlton/2002-11-05: A C++ static data member
5055 should be a DW_TAG_member that is a declaration, but
5056 all versions of G++ as of this writing (so through at
5057 least 3.2.1) incorrectly generate DW_TAG_variable
5058 tags for them instead. */
5059 dwarf2_add_field (&fi
, child_die
, cu
);
5061 else if (child_die
->tag
== DW_TAG_subprogram
)
5063 /* C++ member function. */
5064 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
5066 else if (child_die
->tag
== DW_TAG_inheritance
)
5068 /* C++ base class field. */
5069 dwarf2_add_field (&fi
, child_die
, cu
);
5071 child_die
= sibling_die (child_die
);
5074 /* Attach fields and member functions to the type. */
5076 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
5079 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
5081 /* Get the type which refers to the base class (possibly this
5082 class itself) which contains the vtable pointer for the current
5083 class from the DW_AT_containing_type attribute. This use of
5084 DW_AT_containing_type is a GNU extension. */
5086 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5088 struct type
*t
= die_containing_type (die
, cu
);
5090 TYPE_VPTR_BASETYPE (type
) = t
;
5095 /* Our own class provides vtbl ptr. */
5096 for (i
= TYPE_NFIELDS (t
) - 1;
5097 i
>= TYPE_N_BASECLASSES (t
);
5100 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
5102 if (is_vtable_name (fieldname
, cu
))
5104 TYPE_VPTR_FIELDNO (type
) = i
;
5109 /* Complain if virtual function table field not found. */
5110 if (i
< TYPE_N_BASECLASSES (t
))
5111 complaint (&symfile_complaints
,
5112 _("virtual function table pointer not found when defining class '%s'"),
5113 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
5118 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
5121 else if (cu
->producer
5122 && strncmp (cu
->producer
,
5123 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5125 /* The IBM XLC compiler does not provide direct indication
5126 of the containing type, but the vtable pointer is
5127 always named __vfp. */
5131 for (i
= TYPE_NFIELDS (type
) - 1;
5132 i
>= TYPE_N_BASECLASSES (type
);
5135 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
5137 TYPE_VPTR_FIELDNO (type
) = i
;
5138 TYPE_VPTR_BASETYPE (type
) = type
;
5146 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
5148 do_cleanups (back_to
);
5153 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5155 struct objfile
*objfile
= cu
->objfile
;
5156 struct die_info
*child_die
= die
->child
;
5157 struct type
*this_type
;
5159 this_type
= get_die_type (die
, cu
);
5160 if (this_type
== NULL
)
5161 this_type
= read_structure_type (die
, cu
);
5163 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5164 snapshots) has been known to create a die giving a declaration
5165 for a class that has, as a child, a die giving a definition for a
5166 nested class. So we have to process our children even if the
5167 current die is a declaration. Normally, of course, a declaration
5168 won't have any children at all. */
5170 while (child_die
!= NULL
&& child_die
->tag
)
5172 if (child_die
->tag
== DW_TAG_member
5173 || child_die
->tag
== DW_TAG_variable
5174 || child_die
->tag
== DW_TAG_inheritance
)
5179 process_die (child_die
, cu
);
5181 child_die
= sibling_die (child_die
);
5184 /* Do not consider external references. According to the DWARF standard,
5185 these DIEs are identified by the fact that they have no byte_size
5186 attribute, and a declaration attribute. */
5187 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
5188 || !die_is_declaration (die
, cu
))
5189 new_symbol (die
, this_type
, cu
);
5192 /* Given a DW_AT_enumeration_type die, set its type. We do not
5193 complete the type's fields yet, or create any symbols. */
5195 static struct type
*
5196 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5198 struct objfile
*objfile
= cu
->objfile
;
5200 struct attribute
*attr
;
5203 /* If the definition of this type lives in .debug_types, read that type.
5204 Don't follow DW_AT_specification though, that will take us back up
5205 the chain and we want to go down. */
5206 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5209 struct dwarf2_cu
*type_cu
= cu
;
5210 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5211 type
= read_type_die (type_die
, type_cu
);
5212 return set_die_type (die
, type
, cu
);
5215 type
= alloc_type (objfile
);
5217 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
5218 name
= dwarf2_full_name (NULL
, die
, cu
);
5220 TYPE_TAG_NAME (type
) = (char *) name
;
5222 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5225 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5229 TYPE_LENGTH (type
) = 0;
5232 /* The enumeration DIE can be incomplete. In Ada, any type can be
5233 declared as private in the package spec, and then defined only
5234 inside the package body. Such types are known as Taft Amendment
5235 Types. When another package uses such a type, an incomplete DIE
5236 may be generated by the compiler. */
5237 if (die_is_declaration (die
, cu
))
5238 TYPE_STUB (type
) = 1;
5240 return set_die_type (die
, type
, cu
);
5243 /* Given a pointer to a die which begins an enumeration, process all
5244 the dies that define the members of the enumeration, and create the
5245 symbol for the enumeration type.
5247 NOTE: We reverse the order of the element list. */
5250 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5252 struct objfile
*objfile
= cu
->objfile
;
5253 struct die_info
*child_die
;
5254 struct field
*fields
;
5257 int unsigned_enum
= 1;
5259 struct type
*this_type
;
5263 this_type
= get_die_type (die
, cu
);
5264 if (this_type
== NULL
)
5265 this_type
= read_enumeration_type (die
, cu
);
5266 if (die
->child
!= NULL
)
5268 child_die
= die
->child
;
5269 while (child_die
&& child_die
->tag
)
5271 if (child_die
->tag
!= DW_TAG_enumerator
)
5273 process_die (child_die
, cu
);
5277 name
= dwarf2_name (child_die
, cu
);
5280 sym
= new_symbol (child_die
, this_type
, cu
);
5281 if (SYMBOL_VALUE (sym
) < 0)
5284 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5286 fields
= (struct field
*)
5288 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
5289 * sizeof (struct field
));
5292 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
5293 FIELD_TYPE (fields
[num_fields
]) = NULL
;
5294 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
5295 FIELD_BITSIZE (fields
[num_fields
]) = 0;
5301 child_die
= sibling_die (child_die
);
5306 TYPE_NFIELDS (this_type
) = num_fields
;
5307 TYPE_FIELDS (this_type
) = (struct field
*)
5308 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
5309 memcpy (TYPE_FIELDS (this_type
), fields
,
5310 sizeof (struct field
) * num_fields
);
5314 TYPE_UNSIGNED (this_type
) = 1;
5317 new_symbol (die
, this_type
, cu
);
5320 /* Extract all information from a DW_TAG_array_type DIE and put it in
5321 the DIE's type field. For now, this only handles one dimensional
5324 static struct type
*
5325 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5327 struct objfile
*objfile
= cu
->objfile
;
5328 struct die_info
*child_die
;
5329 struct type
*type
= NULL
;
5330 struct type
*element_type
, *range_type
, *index_type
;
5331 struct type
**range_types
= NULL
;
5332 struct attribute
*attr
;
5334 struct cleanup
*back_to
;
5337 element_type
= die_type (die
, cu
);
5339 /* Irix 6.2 native cc creates array types without children for
5340 arrays with unspecified length. */
5341 if (die
->child
== NULL
)
5343 index_type
= objfile_type (objfile
)->builtin_int
;
5344 range_type
= create_range_type (NULL
, index_type
, 0, -1);
5345 type
= create_array_type (NULL
, element_type
, range_type
);
5346 return set_die_type (die
, type
, cu
);
5349 back_to
= make_cleanup (null_cleanup
, NULL
);
5350 child_die
= die
->child
;
5351 while (child_die
&& child_die
->tag
)
5353 if (child_die
->tag
== DW_TAG_subrange_type
)
5355 struct type
*child_type
= read_type_die (child_die
, cu
);
5356 if (child_type
!= NULL
)
5358 /* The range type was succesfully read. Save it for
5359 the array type creation. */
5360 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
5362 range_types
= (struct type
**)
5363 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
5364 * sizeof (struct type
*));
5366 make_cleanup (free_current_contents
, &range_types
);
5368 range_types
[ndim
++] = child_type
;
5371 child_die
= sibling_die (child_die
);
5374 /* Dwarf2 dimensions are output from left to right, create the
5375 necessary array types in backwards order. */
5377 type
= element_type
;
5379 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
5383 type
= create_array_type (NULL
, type
, range_types
[i
++]);
5388 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
5391 /* Understand Dwarf2 support for vector types (like they occur on
5392 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5393 array type. This is not part of the Dwarf2/3 standard yet, but a
5394 custom vendor extension. The main difference between a regular
5395 array and the vector variant is that vectors are passed by value
5397 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
5399 make_vector_type (type
);
5401 name
= dwarf2_name (die
, cu
);
5403 TYPE_NAME (type
) = name
;
5405 set_descriptive_type (type
, die
, cu
);
5407 do_cleanups (back_to
);
5409 /* Install the type in the die. */
5410 return set_die_type (die
, type
, cu
);
5413 static enum dwarf_array_dim_ordering
5414 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
5416 struct attribute
*attr
;
5418 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
5420 if (attr
) return DW_SND (attr
);
5423 GNU F77 is a special case, as at 08/2004 array type info is the
5424 opposite order to the dwarf2 specification, but data is still
5425 laid out as per normal fortran.
5427 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5431 if (cu
->language
== language_fortran
5432 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
5434 return DW_ORD_row_major
;
5437 switch (cu
->language_defn
->la_array_ordering
)
5439 case array_column_major
:
5440 return DW_ORD_col_major
;
5441 case array_row_major
:
5443 return DW_ORD_row_major
;
5447 /* Extract all information from a DW_TAG_set_type DIE and put it in
5448 the DIE's type field. */
5450 static struct type
*
5451 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5453 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
5455 return set_die_type (die
, set_type
, cu
);
5458 /* First cut: install each common block member as a global variable. */
5461 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
5463 struct die_info
*child_die
;
5464 struct attribute
*attr
;
5466 CORE_ADDR base
= (CORE_ADDR
) 0;
5468 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5471 /* Support the .debug_loc offsets */
5472 if (attr_form_is_block (attr
))
5474 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
5476 else if (attr_form_is_section_offset (attr
))
5478 dwarf2_complex_location_expr_complaint ();
5482 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5483 "common block member");
5486 if (die
->child
!= NULL
)
5488 child_die
= die
->child
;
5489 while (child_die
&& child_die
->tag
)
5491 sym
= new_symbol (child_die
, NULL
, cu
);
5492 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
5495 CORE_ADDR byte_offset
= 0;
5497 if (attr_form_is_section_offset (attr
))
5498 dwarf2_complex_location_expr_complaint ();
5499 else if (attr_form_is_constant (attr
))
5500 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5501 else if (attr_form_is_block (attr
))
5502 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5504 dwarf2_complex_location_expr_complaint ();
5506 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
5507 add_symbol_to_list (sym
, &global_symbols
);
5509 child_die
= sibling_die (child_die
);
5514 /* Create a type for a C++ namespace. */
5516 static struct type
*
5517 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5519 struct objfile
*objfile
= cu
->objfile
;
5520 const char *previous_prefix
, *name
;
5524 /* For extensions, reuse the type of the original namespace. */
5525 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5527 struct die_info
*ext_die
;
5528 struct dwarf2_cu
*ext_cu
= cu
;
5529 ext_die
= dwarf2_extension (die
, &ext_cu
);
5530 type
= read_type_die (ext_die
, ext_cu
);
5531 return set_die_type (die
, type
, cu
);
5534 name
= namespace_name (die
, &is_anonymous
, cu
);
5536 /* Now build the name of the current namespace. */
5538 previous_prefix
= determine_prefix (die
, cu
);
5539 if (previous_prefix
[0] != '\0')
5540 name
= typename_concat (&objfile
->objfile_obstack
,
5541 previous_prefix
, name
, cu
);
5543 /* Create the type. */
5544 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5546 TYPE_NAME (type
) = (char *) name
;
5547 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5549 set_die_type (die
, type
, cu
);
5554 /* Read a C++ namespace. */
5557 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5559 struct objfile
*objfile
= cu
->objfile
;
5563 /* Add a symbol associated to this if we haven't seen the namespace
5564 before. Also, add a using directive if it's an anonymous
5567 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5571 type
= read_type_die (die
, cu
);
5572 new_symbol (die
, type
, cu
);
5574 name
= namespace_name (die
, &is_anonymous
, cu
);
5577 const char *previous_prefix
= determine_prefix (die
, cu
);
5578 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
5579 &objfile
->objfile_obstack
);
5583 if (die
->child
!= NULL
)
5585 struct die_info
*child_die
= die
->child
;
5587 while (child_die
&& child_die
->tag
)
5589 process_die (child_die
, cu
);
5590 child_die
= sibling_die (child_die
);
5595 /* Read a Fortran module. */
5598 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5600 struct die_info
*child_die
= die
->child
;
5602 /* FIXME: Support the separate Fortran module namespaces. */
5604 while (child_die
&& child_die
->tag
)
5606 process_die (child_die
, cu
);
5607 child_die
= sibling_die (child_die
);
5611 /* Return the name of the namespace represented by DIE. Set
5612 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5616 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5618 struct die_info
*current_die
;
5619 const char *name
= NULL
;
5621 /* Loop through the extensions until we find a name. */
5623 for (current_die
= die
;
5624 current_die
!= NULL
;
5625 current_die
= dwarf2_extension (die
, &cu
))
5627 name
= dwarf2_name (current_die
, cu
);
5632 /* Is it an anonymous namespace? */
5634 *is_anonymous
= (name
== NULL
);
5636 name
= "(anonymous namespace)";
5641 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5642 the user defined type vector. */
5644 static struct type
*
5645 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5647 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5648 struct comp_unit_head
*cu_header
= &cu
->header
;
5650 struct attribute
*attr_byte_size
;
5651 struct attribute
*attr_address_class
;
5652 int byte_size
, addr_class
;
5654 type
= lookup_pointer_type (die_type (die
, cu
));
5656 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5658 byte_size
= DW_UNSND (attr_byte_size
);
5660 byte_size
= cu_header
->addr_size
;
5662 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5663 if (attr_address_class
)
5664 addr_class
= DW_UNSND (attr_address_class
);
5666 addr_class
= DW_ADDR_none
;
5668 /* If the pointer size or address class is different than the
5669 default, create a type variant marked as such and set the
5670 length accordingly. */
5671 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5673 if (gdbarch_address_class_type_flags_p (gdbarch
))
5677 type_flags
= gdbarch_address_class_type_flags
5678 (gdbarch
, byte_size
, addr_class
);
5679 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5681 type
= make_type_with_address_space (type
, type_flags
);
5683 else if (TYPE_LENGTH (type
) != byte_size
)
5685 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5688 /* Should we also complain about unhandled address classes? */
5692 TYPE_LENGTH (type
) = byte_size
;
5693 return set_die_type (die
, type
, cu
);
5696 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5697 the user defined type vector. */
5699 static struct type
*
5700 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5702 struct objfile
*objfile
= cu
->objfile
;
5704 struct type
*to_type
;
5705 struct type
*domain
;
5707 to_type
= die_type (die
, cu
);
5708 domain
= die_containing_type (die
, cu
);
5710 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5711 type
= lookup_methodptr_type (to_type
);
5713 type
= lookup_memberptr_type (to_type
, domain
);
5715 return set_die_type (die
, type
, cu
);
5718 /* Extract all information from a DW_TAG_reference_type DIE and add to
5719 the user defined type vector. */
5721 static struct type
*
5722 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5724 struct comp_unit_head
*cu_header
= &cu
->header
;
5726 struct attribute
*attr
;
5728 type
= lookup_reference_type (die_type (die
, cu
));
5729 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5732 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5736 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5738 return set_die_type (die
, type
, cu
);
5741 static struct type
*
5742 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5744 struct type
*base_type
, *cv_type
;
5746 base_type
= die_type (die
, cu
);
5747 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5748 return set_die_type (die
, cv_type
, cu
);
5751 static struct type
*
5752 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5754 struct type
*base_type
, *cv_type
;
5756 base_type
= die_type (die
, cu
);
5757 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5758 return set_die_type (die
, cv_type
, cu
);
5761 /* Extract all information from a DW_TAG_string_type DIE and add to
5762 the user defined type vector. It isn't really a user defined type,
5763 but it behaves like one, with other DIE's using an AT_user_def_type
5764 attribute to reference it. */
5766 static struct type
*
5767 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5769 struct objfile
*objfile
= cu
->objfile
;
5770 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5771 struct type
*type
, *range_type
, *index_type
, *char_type
;
5772 struct attribute
*attr
;
5773 unsigned int length
;
5775 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5778 length
= DW_UNSND (attr
);
5782 /* check for the DW_AT_byte_size attribute */
5783 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5786 length
= DW_UNSND (attr
);
5794 index_type
= objfile_type (objfile
)->builtin_int
;
5795 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5796 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5797 type
= create_string_type (NULL
, char_type
, range_type
);
5799 return set_die_type (die
, type
, cu
);
5802 /* Handle DIES due to C code like:
5806 int (*funcp)(int a, long l);
5810 ('funcp' generates a DW_TAG_subroutine_type DIE)
5813 static struct type
*
5814 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5816 struct type
*type
; /* Type that this function returns */
5817 struct type
*ftype
; /* Function that returns above type */
5818 struct attribute
*attr
;
5820 type
= die_type (die
, cu
);
5821 ftype
= lookup_function_type (type
);
5823 /* All functions in C++, Pascal and Java have prototypes. */
5824 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5825 if ((attr
&& (DW_UNSND (attr
) != 0))
5826 || cu
->language
== language_cplus
5827 || cu
->language
== language_java
5828 || cu
->language
== language_pascal
)
5829 TYPE_PROTOTYPED (ftype
) = 1;
5831 /* Store the calling convention in the type if it's available in
5832 the subroutine die. Otherwise set the calling convention to
5833 the default value DW_CC_normal. */
5834 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5835 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5837 /* We need to add the subroutine type to the die immediately so
5838 we don't infinitely recurse when dealing with parameters
5839 declared as the same subroutine type. */
5840 set_die_type (die
, ftype
, cu
);
5842 if (die
->child
!= NULL
)
5844 struct die_info
*child_die
;
5848 /* Count the number of parameters.
5849 FIXME: GDB currently ignores vararg functions, but knows about
5850 vararg member functions. */
5851 child_die
= die
->child
;
5852 while (child_die
&& child_die
->tag
)
5854 if (child_die
->tag
== DW_TAG_formal_parameter
)
5856 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5857 TYPE_VARARGS (ftype
) = 1;
5858 child_die
= sibling_die (child_die
);
5861 /* Allocate storage for parameters and fill them in. */
5862 TYPE_NFIELDS (ftype
) = nparams
;
5863 TYPE_FIELDS (ftype
) = (struct field
*)
5864 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5866 child_die
= die
->child
;
5867 while (child_die
&& child_die
->tag
)
5869 if (child_die
->tag
== DW_TAG_formal_parameter
)
5871 /* Dwarf2 has no clean way to discern C++ static and non-static
5872 member functions. G++ helps GDB by marking the first
5873 parameter for non-static member functions (which is the
5874 this pointer) as artificial. We pass this information
5875 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5876 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5878 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5880 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5881 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5884 child_die
= sibling_die (child_die
);
5891 static struct type
*
5892 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5894 struct objfile
*objfile
= cu
->objfile
;
5895 struct attribute
*attr
;
5896 const char *name
= NULL
;
5897 struct type
*this_type
;
5899 name
= dwarf2_full_name (NULL
, die
, cu
);
5900 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5901 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5902 TYPE_NAME (this_type
) = (char *) name
;
5903 set_die_type (die
, this_type
, cu
);
5904 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5908 /* Find a representation of a given base type and install
5909 it in the TYPE field of the die. */
5911 static struct type
*
5912 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5914 struct objfile
*objfile
= cu
->objfile
;
5916 struct attribute
*attr
;
5917 int encoding
= 0, size
= 0;
5919 enum type_code code
= TYPE_CODE_INT
;
5921 struct type
*target_type
= NULL
;
5923 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5926 encoding
= DW_UNSND (attr
);
5928 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5931 size
= DW_UNSND (attr
);
5933 name
= dwarf2_name (die
, cu
);
5936 complaint (&symfile_complaints
,
5937 _("DW_AT_name missing from DW_TAG_base_type"));
5942 case DW_ATE_address
:
5943 /* Turn DW_ATE_address into a void * pointer. */
5944 code
= TYPE_CODE_PTR
;
5945 type_flags
|= TYPE_FLAG_UNSIGNED
;
5946 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5948 case DW_ATE_boolean
:
5949 code
= TYPE_CODE_BOOL
;
5950 type_flags
|= TYPE_FLAG_UNSIGNED
;
5952 case DW_ATE_complex_float
:
5953 code
= TYPE_CODE_COMPLEX
;
5954 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5956 case DW_ATE_decimal_float
:
5957 code
= TYPE_CODE_DECFLOAT
;
5960 code
= TYPE_CODE_FLT
;
5964 case DW_ATE_unsigned
:
5965 type_flags
|= TYPE_FLAG_UNSIGNED
;
5967 case DW_ATE_signed_char
:
5968 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5969 || cu
->language
== language_pascal
)
5970 code
= TYPE_CODE_CHAR
;
5972 case DW_ATE_unsigned_char
:
5973 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5974 || cu
->language
== language_pascal
)
5975 code
= TYPE_CODE_CHAR
;
5976 type_flags
|= TYPE_FLAG_UNSIGNED
;
5979 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5980 dwarf_type_encoding_name (encoding
));
5984 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5985 TYPE_NAME (type
) = name
;
5986 TYPE_TARGET_TYPE (type
) = target_type
;
5988 if (name
&& strcmp (name
, "char") == 0)
5989 TYPE_NOSIGN (type
) = 1;
5991 return set_die_type (die
, type
, cu
);
5994 /* Read the given DW_AT_subrange DIE. */
5996 static struct type
*
5997 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5999 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6000 struct type
*base_type
;
6001 struct type
*range_type
;
6002 struct attribute
*attr
;
6006 LONGEST negative_mask
;
6008 base_type
= die_type (die
, cu
);
6009 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
6011 complaint (&symfile_complaints
,
6012 _("DW_AT_type missing from DW_TAG_subrange_type"));
6014 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
6015 0, NULL
, cu
->objfile
);
6018 if (cu
->language
== language_fortran
)
6020 /* FORTRAN implies a lower bound of 1, if not given. */
6024 /* FIXME: For variable sized arrays either of these could be
6025 a variable rather than a constant value. We'll allow it,
6026 but we don't know how to handle it. */
6027 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
6029 low
= dwarf2_get_attr_constant_value (attr
, 0);
6031 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
6034 if (attr
->form
== DW_FORM_block1
)
6036 /* GCC encodes arrays with unspecified or dynamic length
6037 with a DW_FORM_block1 attribute.
6038 FIXME: GDB does not yet know how to handle dynamic
6039 arrays properly, treat them as arrays with unspecified
6042 FIXME: jimb/2003-09-22: GDB does not really know
6043 how to handle arrays of unspecified length
6044 either; we just represent them as zero-length
6045 arrays. Choose an appropriate upper bound given
6046 the lower bound we've computed above. */
6050 high
= dwarf2_get_attr_constant_value (attr
, 1);
6054 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
6055 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
6056 low
|= negative_mask
;
6057 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
6058 high
|= negative_mask
;
6060 range_type
= create_range_type (NULL
, base_type
, low
, high
);
6062 name
= dwarf2_name (die
, cu
);
6064 TYPE_NAME (range_type
) = name
;
6066 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6068 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
6070 set_descriptive_type (range_type
, die
, cu
);
6072 return set_die_type (die
, range_type
, cu
);
6075 static struct type
*
6076 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6080 /* For now, we only support the C meaning of an unspecified type: void. */
6082 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
6083 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
6085 return set_die_type (die
, type
, cu
);
6088 /* Trivial hash function for die_info: the hash value of a DIE
6089 is its offset in .debug_info for this objfile. */
6092 die_hash (const void *item
)
6094 const struct die_info
*die
= item
;
6098 /* Trivial comparison function for die_info structures: two DIEs
6099 are equal if they have the same offset. */
6102 die_eq (const void *item_lhs
, const void *item_rhs
)
6104 const struct die_info
*die_lhs
= item_lhs
;
6105 const struct die_info
*die_rhs
= item_rhs
;
6106 return die_lhs
->offset
== die_rhs
->offset
;
6109 /* Read a whole compilation unit into a linked list of dies. */
6111 static struct die_info
*
6112 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6114 struct die_reader_specs reader_specs
;
6116 gdb_assert (cu
->die_hash
== NULL
);
6118 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6122 &cu
->comp_unit_obstack
,
6123 hashtab_obstack_allocate
,
6124 dummy_obstack_deallocate
);
6126 init_cu_die_reader (&reader_specs
, cu
);
6128 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
6131 /* Main entry point for reading a DIE and all children.
6132 Read the DIE and dump it if requested. */
6134 static struct die_info
*
6135 read_die_and_children (const struct die_reader_specs
*reader
,
6137 gdb_byte
**new_info_ptr
,
6138 struct die_info
*parent
)
6140 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
6141 new_info_ptr
, parent
);
6143 if (dwarf2_die_debug
)
6145 fprintf_unfiltered (gdb_stdlog
,
6146 "\nRead die from %s of %s:\n",
6147 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
6149 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
6151 : "unknown section",
6152 reader
->abfd
->filename
);
6153 dump_die (result
, dwarf2_die_debug
);
6159 /* Read a single die and all its descendents. Set the die's sibling
6160 field to NULL; set other fields in the die correctly, and set all
6161 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6162 location of the info_ptr after reading all of those dies. PARENT
6163 is the parent of the die in question. */
6165 static struct die_info
*
6166 read_die_and_children_1 (const struct die_reader_specs
*reader
,
6168 gdb_byte
**new_info_ptr
,
6169 struct die_info
*parent
)
6171 struct die_info
*die
;
6175 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
6178 *new_info_ptr
= cur_ptr
;
6181 store_in_ref_table (die
, reader
->cu
);
6184 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
6188 *new_info_ptr
= cur_ptr
;
6191 die
->sibling
= NULL
;
6192 die
->parent
= parent
;
6196 /* Read a die, all of its descendents, and all of its siblings; set
6197 all of the fields of all of the dies correctly. Arguments are as
6198 in read_die_and_children. */
6200 static struct die_info
*
6201 read_die_and_siblings (const struct die_reader_specs
*reader
,
6203 gdb_byte
**new_info_ptr
,
6204 struct die_info
*parent
)
6206 struct die_info
*first_die
, *last_sibling
;
6210 first_die
= last_sibling
= NULL
;
6214 struct die_info
*die
6215 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
6219 *new_info_ptr
= cur_ptr
;
6226 last_sibling
->sibling
= die
;
6232 /* Read the die from the .debug_info section buffer. Set DIEP to
6233 point to a newly allocated die with its information, except for its
6234 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6235 whether the die has children or not. */
6238 read_full_die (const struct die_reader_specs
*reader
,
6239 struct die_info
**diep
, gdb_byte
*info_ptr
,
6242 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6243 struct abbrev_info
*abbrev
;
6244 struct die_info
*die
;
6245 struct dwarf2_cu
*cu
= reader
->cu
;
6246 bfd
*abfd
= reader
->abfd
;
6248 offset
= info_ptr
- reader
->buffer
;
6249 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6250 info_ptr
+= bytes_read
;
6258 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6260 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6262 bfd_get_filename (abfd
));
6264 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6265 die
->offset
= offset
;
6266 die
->tag
= abbrev
->tag
;
6267 die
->abbrev
= abbrev_number
;
6269 die
->num_attrs
= abbrev
->num_attrs
;
6271 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6272 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6273 abfd
, info_ptr
, cu
);
6276 *has_children
= abbrev
->has_children
;
6280 /* In DWARF version 2, the description of the debugging information is
6281 stored in a separate .debug_abbrev section. Before we read any
6282 dies from a section we read in all abbreviations and install them
6283 in a hash table. This function also sets flags in CU describing
6284 the data found in the abbrev table. */
6287 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
6289 struct comp_unit_head
*cu_header
= &cu
->header
;
6290 gdb_byte
*abbrev_ptr
;
6291 struct abbrev_info
*cur_abbrev
;
6292 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
6293 unsigned int abbrev_form
, hash_number
;
6294 struct attr_abbrev
*cur_attrs
;
6295 unsigned int allocated_attrs
;
6297 /* Initialize dwarf2 abbrevs */
6298 obstack_init (&cu
->abbrev_obstack
);
6299 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
6301 * sizeof (struct abbrev_info
*)));
6302 memset (cu
->dwarf2_abbrevs
, 0,
6303 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
6305 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
6306 &dwarf2_per_objfile
->abbrev
);
6307 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
6308 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6309 abbrev_ptr
+= bytes_read
;
6311 allocated_attrs
= ATTR_ALLOC_CHUNK
;
6312 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
6314 /* loop until we reach an abbrev number of 0 */
6315 while (abbrev_number
)
6317 cur_abbrev
= dwarf_alloc_abbrev (cu
);
6319 /* read in abbrev header */
6320 cur_abbrev
->number
= abbrev_number
;
6321 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6322 abbrev_ptr
+= bytes_read
;
6323 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
6326 if (cur_abbrev
->tag
== DW_TAG_namespace
)
6327 cu
->has_namespace_info
= 1;
6329 /* now read in declarations */
6330 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6331 abbrev_ptr
+= bytes_read
;
6332 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6333 abbrev_ptr
+= bytes_read
;
6336 if (cur_abbrev
->num_attrs
== allocated_attrs
)
6338 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
6340 = xrealloc (cur_attrs
, (allocated_attrs
6341 * sizeof (struct attr_abbrev
)));
6344 /* Record whether this compilation unit might have
6345 inter-compilation-unit references. If we don't know what form
6346 this attribute will have, then it might potentially be a
6347 DW_FORM_ref_addr, so we conservatively expect inter-CU
6350 if (abbrev_form
== DW_FORM_ref_addr
6351 || abbrev_form
== DW_FORM_indirect
)
6352 cu
->has_form_ref_addr
= 1;
6354 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
6355 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
6356 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6357 abbrev_ptr
+= bytes_read
;
6358 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6359 abbrev_ptr
+= bytes_read
;
6362 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
6363 (cur_abbrev
->num_attrs
6364 * sizeof (struct attr_abbrev
)));
6365 memcpy (cur_abbrev
->attrs
, cur_attrs
,
6366 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
6368 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
6369 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
6370 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
6372 /* Get next abbreviation.
6373 Under Irix6 the abbreviations for a compilation unit are not
6374 always properly terminated with an abbrev number of 0.
6375 Exit loop if we encounter an abbreviation which we have
6376 already read (which means we are about to read the abbreviations
6377 for the next compile unit) or if the end of the abbreviation
6378 table is reached. */
6379 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
6380 >= dwarf2_per_objfile
->abbrev
.size
)
6382 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6383 abbrev_ptr
+= bytes_read
;
6384 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
6391 /* Release the memory used by the abbrev table for a compilation unit. */
6394 dwarf2_free_abbrev_table (void *ptr_to_cu
)
6396 struct dwarf2_cu
*cu
= ptr_to_cu
;
6398 obstack_free (&cu
->abbrev_obstack
, NULL
);
6399 cu
->dwarf2_abbrevs
= NULL
;
6402 /* Lookup an abbrev_info structure in the abbrev hash table. */
6404 static struct abbrev_info
*
6405 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
6407 unsigned int hash_number
;
6408 struct abbrev_info
*abbrev
;
6410 hash_number
= number
% ABBREV_HASH_SIZE
;
6411 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
6415 if (abbrev
->number
== number
)
6418 abbrev
= abbrev
->next
;
6423 /* Returns nonzero if TAG represents a type that we might generate a partial
6427 is_type_tag_for_partial (int tag
)
6432 /* Some types that would be reasonable to generate partial symbols for,
6433 that we don't at present. */
6434 case DW_TAG_array_type
:
6435 case DW_TAG_file_type
:
6436 case DW_TAG_ptr_to_member_type
:
6437 case DW_TAG_set_type
:
6438 case DW_TAG_string_type
:
6439 case DW_TAG_subroutine_type
:
6441 case DW_TAG_base_type
:
6442 case DW_TAG_class_type
:
6443 case DW_TAG_interface_type
:
6444 case DW_TAG_enumeration_type
:
6445 case DW_TAG_structure_type
:
6446 case DW_TAG_subrange_type
:
6447 case DW_TAG_typedef
:
6448 case DW_TAG_union_type
:
6455 /* Load all DIEs that are interesting for partial symbols into memory. */
6457 static struct partial_die_info
*
6458 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6459 int building_psymtab
, struct dwarf2_cu
*cu
)
6461 struct partial_die_info
*part_die
;
6462 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
6463 struct abbrev_info
*abbrev
;
6464 unsigned int bytes_read
;
6465 unsigned int load_all
= 0;
6467 int nesting_level
= 1;
6472 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
6476 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6480 &cu
->comp_unit_obstack
,
6481 hashtab_obstack_allocate
,
6482 dummy_obstack_deallocate
);
6484 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6485 sizeof (struct partial_die_info
));
6489 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6491 /* A NULL abbrev means the end of a series of children. */
6494 if (--nesting_level
== 0)
6496 /* PART_DIE was probably the last thing allocated on the
6497 comp_unit_obstack, so we could call obstack_free
6498 here. We don't do that because the waste is small,
6499 and will be cleaned up when we're done with this
6500 compilation unit. This way, we're also more robust
6501 against other users of the comp_unit_obstack. */
6504 info_ptr
+= bytes_read
;
6505 last_die
= parent_die
;
6506 parent_die
= parent_die
->die_parent
;
6510 /* Check whether this DIE is interesting enough to save. Normally
6511 we would not be interested in members here, but there may be
6512 later variables referencing them via DW_AT_specification (for
6515 && !is_type_tag_for_partial (abbrev
->tag
)
6516 && abbrev
->tag
!= DW_TAG_enumerator
6517 && abbrev
->tag
!= DW_TAG_subprogram
6518 && abbrev
->tag
!= DW_TAG_lexical_block
6519 && abbrev
->tag
!= DW_TAG_variable
6520 && abbrev
->tag
!= DW_TAG_namespace
6521 && abbrev
->tag
!= DW_TAG_member
)
6523 /* Otherwise we skip to the next sibling, if any. */
6524 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
6528 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
6529 buffer
, info_ptr
, cu
);
6531 /* This two-pass algorithm for processing partial symbols has a
6532 high cost in cache pressure. Thus, handle some simple cases
6533 here which cover the majority of C partial symbols. DIEs
6534 which neither have specification tags in them, nor could have
6535 specification tags elsewhere pointing at them, can simply be
6536 processed and discarded.
6538 This segment is also optional; scan_partial_symbols and
6539 add_partial_symbol will handle these DIEs if we chain
6540 them in normally. When compilers which do not emit large
6541 quantities of duplicate debug information are more common,
6542 this code can probably be removed. */
6544 /* Any complete simple types at the top level (pretty much all
6545 of them, for a language without namespaces), can be processed
6547 if (parent_die
== NULL
6548 && part_die
->has_specification
== 0
6549 && part_die
->is_declaration
== 0
6550 && (part_die
->tag
== DW_TAG_typedef
6551 || part_die
->tag
== DW_TAG_base_type
6552 || part_die
->tag
== DW_TAG_subrange_type
))
6554 if (building_psymtab
&& part_die
->name
!= NULL
)
6555 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6556 VAR_DOMAIN
, LOC_TYPEDEF
,
6557 &cu
->objfile
->static_psymbols
,
6558 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6559 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6563 /* If we're at the second level, and we're an enumerator, and
6564 our parent has no specification (meaning possibly lives in a
6565 namespace elsewhere), then we can add the partial symbol now
6566 instead of queueing it. */
6567 if (part_die
->tag
== DW_TAG_enumerator
6568 && parent_die
!= NULL
6569 && parent_die
->die_parent
== NULL
6570 && parent_die
->tag
== DW_TAG_enumeration_type
6571 && parent_die
->has_specification
== 0)
6573 if (part_die
->name
== NULL
)
6574 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6575 else if (building_psymtab
)
6576 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6577 VAR_DOMAIN
, LOC_CONST
,
6578 (cu
->language
== language_cplus
6579 || cu
->language
== language_java
)
6580 ? &cu
->objfile
->global_psymbols
6581 : &cu
->objfile
->static_psymbols
,
6582 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6584 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6588 /* We'll save this DIE so link it in. */
6589 part_die
->die_parent
= parent_die
;
6590 part_die
->die_sibling
= NULL
;
6591 part_die
->die_child
= NULL
;
6593 if (last_die
&& last_die
== parent_die
)
6594 last_die
->die_child
= part_die
;
6596 last_die
->die_sibling
= part_die
;
6598 last_die
= part_die
;
6600 if (first_die
== NULL
)
6601 first_die
= part_die
;
6603 /* Maybe add the DIE to the hash table. Not all DIEs that we
6604 find interesting need to be in the hash table, because we
6605 also have the parent/sibling/child chains; only those that we
6606 might refer to by offset later during partial symbol reading.
6608 For now this means things that might have be the target of a
6609 DW_AT_specification, DW_AT_abstract_origin, or
6610 DW_AT_extension. DW_AT_extension will refer only to
6611 namespaces; DW_AT_abstract_origin refers to functions (and
6612 many things under the function DIE, but we do not recurse
6613 into function DIEs during partial symbol reading) and
6614 possibly variables as well; DW_AT_specification refers to
6615 declarations. Declarations ought to have the DW_AT_declaration
6616 flag. It happens that GCC forgets to put it in sometimes, but
6617 only for functions, not for types.
6619 Adding more things than necessary to the hash table is harmless
6620 except for the performance cost. Adding too few will result in
6621 wasted time in find_partial_die, when we reread the compilation
6622 unit with load_all_dies set. */
6625 || abbrev
->tag
== DW_TAG_subprogram
6626 || abbrev
->tag
== DW_TAG_variable
6627 || abbrev
->tag
== DW_TAG_namespace
6628 || part_die
->is_declaration
)
6632 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6633 part_die
->offset
, INSERT
);
6637 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6638 sizeof (struct partial_die_info
));
6640 /* For some DIEs we want to follow their children (if any). For C
6641 we have no reason to follow the children of structures; for other
6642 languages we have to, both so that we can get at method physnames
6643 to infer fully qualified class names, and for DW_AT_specification.
6645 For Ada, we need to scan the children of subprograms and lexical
6646 blocks as well because Ada allows the definition of nested
6647 entities that could be interesting for the debugger, such as
6648 nested subprograms for instance. */
6649 if (last_die
->has_children
6651 || last_die
->tag
== DW_TAG_namespace
6652 || last_die
->tag
== DW_TAG_enumeration_type
6653 || (cu
->language
!= language_c
6654 && (last_die
->tag
== DW_TAG_class_type
6655 || last_die
->tag
== DW_TAG_interface_type
6656 || last_die
->tag
== DW_TAG_structure_type
6657 || last_die
->tag
== DW_TAG_union_type
))
6658 || (cu
->language
== language_ada
6659 && (last_die
->tag
== DW_TAG_subprogram
6660 || last_die
->tag
== DW_TAG_lexical_block
))))
6663 parent_die
= last_die
;
6667 /* Otherwise we skip to the next sibling, if any. */
6668 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
6670 /* Back to the top, do it again. */
6674 /* Read a minimal amount of information into the minimal die structure. */
6677 read_partial_die (struct partial_die_info
*part_die
,
6678 struct abbrev_info
*abbrev
,
6679 unsigned int abbrev_len
, bfd
*abfd
,
6680 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6681 struct dwarf2_cu
*cu
)
6683 unsigned int bytes_read
, i
;
6684 struct attribute attr
;
6685 int has_low_pc_attr
= 0;
6686 int has_high_pc_attr
= 0;
6688 memset (part_die
, 0, sizeof (struct partial_die_info
));
6690 part_die
->offset
= info_ptr
- buffer
;
6692 info_ptr
+= abbrev_len
;
6697 part_die
->tag
= abbrev
->tag
;
6698 part_die
->has_children
= abbrev
->has_children
;
6700 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6702 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6704 /* Store the data if it is of an attribute we want to keep in a
6705 partial symbol table. */
6709 switch (part_die
->tag
)
6711 case DW_TAG_compile_unit
:
6712 case DW_TAG_type_unit
:
6713 /* Compilation units have a DW_AT_name that is a filename, not
6714 a source language identifier. */
6715 case DW_TAG_enumeration_type
:
6716 case DW_TAG_enumerator
:
6717 /* These tags always have simple identifiers already; no need
6718 to canonicalize them. */
6719 part_die
->name
= DW_STRING (&attr
);
6723 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6724 &cu
->objfile
->objfile_obstack
);
6728 case DW_AT_MIPS_linkage_name
:
6729 if (cu
->language
== language_ada
)
6730 part_die
->name
= DW_STRING (&attr
);
6733 has_low_pc_attr
= 1;
6734 part_die
->lowpc
= DW_ADDR (&attr
);
6737 has_high_pc_attr
= 1;
6738 part_die
->highpc
= DW_ADDR (&attr
);
6740 case DW_AT_location
:
6741 /* Support the .debug_loc offsets */
6742 if (attr_form_is_block (&attr
))
6744 part_die
->locdesc
= DW_BLOCK (&attr
);
6746 else if (attr_form_is_section_offset (&attr
))
6748 dwarf2_complex_location_expr_complaint ();
6752 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6753 "partial symbol information");
6756 case DW_AT_external
:
6757 part_die
->is_external
= DW_UNSND (&attr
);
6759 case DW_AT_declaration
:
6760 part_die
->is_declaration
= DW_UNSND (&attr
);
6763 part_die
->has_type
= 1;
6765 case DW_AT_abstract_origin
:
6766 case DW_AT_specification
:
6767 case DW_AT_extension
:
6768 part_die
->has_specification
= 1;
6769 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6772 /* Ignore absolute siblings, they might point outside of
6773 the current compile unit. */
6774 if (attr
.form
== DW_FORM_ref_addr
)
6775 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6777 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
6779 case DW_AT_byte_size
:
6780 part_die
->has_byte_size
= 1;
6782 case DW_AT_calling_convention
:
6783 /* DWARF doesn't provide a way to identify a program's source-level
6784 entry point. DW_AT_calling_convention attributes are only meant
6785 to describe functions' calling conventions.
6787 However, because it's a necessary piece of information in
6788 Fortran, and because DW_CC_program is the only piece of debugging
6789 information whose definition refers to a 'main program' at all,
6790 several compilers have begun marking Fortran main programs with
6791 DW_CC_program --- even when those functions use the standard
6792 calling conventions.
6794 So until DWARF specifies a way to provide this information and
6795 compilers pick up the new representation, we'll support this
6797 if (DW_UNSND (&attr
) == DW_CC_program
6798 && cu
->language
== language_fortran
)
6799 set_main_name (part_die
->name
);
6806 /* When using the GNU linker, .gnu.linkonce. sections are used to
6807 eliminate duplicate copies of functions and vtables and such.
6808 The linker will arbitrarily choose one and discard the others.
6809 The AT_*_pc values for such functions refer to local labels in
6810 these sections. If the section from that file was discarded, the
6811 labels are not in the output, so the relocs get a value of 0.
6812 If this is a discarded function, mark the pc bounds as invalid,
6813 so that GDB will ignore it. */
6814 if (has_low_pc_attr
&& has_high_pc_attr
6815 && part_die
->lowpc
< part_die
->highpc
6816 && (part_die
->lowpc
!= 0
6817 || dwarf2_per_objfile
->has_section_at_zero
))
6818 part_die
->has_pc_info
= 1;
6823 /* Find a cached partial DIE at OFFSET in CU. */
6825 static struct partial_die_info
*
6826 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6828 struct partial_die_info
*lookup_die
= NULL
;
6829 struct partial_die_info part_die
;
6831 part_die
.offset
= offset
;
6832 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6837 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6838 except in the case of .debug_types DIEs which do not reference
6839 outside their CU (they do however referencing other types via
6842 static struct partial_die_info
*
6843 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6845 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6846 struct partial_die_info
*pd
= NULL
;
6848 if (cu
->per_cu
->from_debug_types
)
6850 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6856 if (offset_in_cu_p (&cu
->header
, offset
))
6858 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6863 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6865 if (per_cu
->cu
== NULL
)
6867 load_partial_comp_unit (per_cu
, cu
->objfile
);
6868 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6869 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6872 per_cu
->cu
->last_used
= 0;
6873 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6875 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6877 struct cleanup
*back_to
;
6878 struct partial_die_info comp_unit_die
;
6879 struct abbrev_info
*abbrev
;
6880 unsigned int bytes_read
;
6883 per_cu
->load_all_dies
= 1;
6885 /* Re-read the DIEs. */
6886 back_to
= make_cleanup (null_cleanup
, 0);
6887 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6889 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6890 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6892 info_ptr
= (dwarf2_per_objfile
->info
.buffer
6893 + per_cu
->cu
->header
.offset
6894 + per_cu
->cu
->header
.first_die_offset
);
6895 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6896 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6897 per_cu
->cu
->objfile
->obfd
,
6898 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6900 if (comp_unit_die
.has_children
)
6901 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
6902 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6904 do_cleanups (back_to
);
6906 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6912 internal_error (__FILE__
, __LINE__
,
6913 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6914 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6918 /* Adjust PART_DIE before generating a symbol for it. This function
6919 may set the is_external flag or change the DIE's name. */
6922 fixup_partial_die (struct partial_die_info
*part_die
,
6923 struct dwarf2_cu
*cu
)
6925 /* If we found a reference attribute and the DIE has no name, try
6926 to find a name in the referred to DIE. */
6928 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6930 struct partial_die_info
*spec_die
;
6932 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6934 fixup_partial_die (spec_die
, cu
);
6938 part_die
->name
= spec_die
->name
;
6940 /* Copy DW_AT_external attribute if it is set. */
6941 if (spec_die
->is_external
)
6942 part_die
->is_external
= spec_die
->is_external
;
6946 /* Set default names for some unnamed DIEs. */
6947 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6948 || part_die
->tag
== DW_TAG_class_type
))
6949 part_die
->name
= "(anonymous class)";
6951 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6952 part_die
->name
= "(anonymous namespace)";
6954 if (part_die
->tag
== DW_TAG_structure_type
6955 || part_die
->tag
== DW_TAG_class_type
6956 || part_die
->tag
== DW_TAG_union_type
)
6957 guess_structure_name (part_die
, cu
);
6960 /* Read an attribute value described by an attribute form. */
6963 read_attribute_value (struct attribute
*attr
, unsigned form
,
6964 bfd
*abfd
, gdb_byte
*info_ptr
,
6965 struct dwarf2_cu
*cu
)
6967 struct comp_unit_head
*cu_header
= &cu
->header
;
6968 unsigned int bytes_read
;
6969 struct dwarf_block
*blk
;
6974 case DW_FORM_ref_addr
:
6975 if (cu
->header
.version
== 2)
6976 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6978 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
6979 info_ptr
+= bytes_read
;
6982 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6983 info_ptr
+= bytes_read
;
6985 case DW_FORM_block2
:
6986 blk
= dwarf_alloc_block (cu
);
6987 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6989 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6990 info_ptr
+= blk
->size
;
6991 DW_BLOCK (attr
) = blk
;
6993 case DW_FORM_block4
:
6994 blk
= dwarf_alloc_block (cu
);
6995 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6997 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6998 info_ptr
+= blk
->size
;
6999 DW_BLOCK (attr
) = blk
;
7002 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
7006 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
7010 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
7013 case DW_FORM_string
:
7014 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
7015 DW_STRING_IS_CANONICAL (attr
) = 0;
7016 info_ptr
+= bytes_read
;
7019 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
7021 DW_STRING_IS_CANONICAL (attr
) = 0;
7022 info_ptr
+= bytes_read
;
7025 blk
= dwarf_alloc_block (cu
);
7026 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7027 info_ptr
+= bytes_read
;
7028 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7029 info_ptr
+= blk
->size
;
7030 DW_BLOCK (attr
) = blk
;
7032 case DW_FORM_block1
:
7033 blk
= dwarf_alloc_block (cu
);
7034 blk
->size
= read_1_byte (abfd
, info_ptr
);
7036 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7037 info_ptr
+= blk
->size
;
7038 DW_BLOCK (attr
) = blk
;
7041 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7045 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7049 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
7050 info_ptr
+= bytes_read
;
7053 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7054 info_ptr
+= bytes_read
;
7057 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
7061 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
7065 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
7069 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
7073 /* Convert the signature to something we can record in DW_UNSND
7075 NOTE: This is NULL if the type wasn't found. */
7076 DW_SIGNATURED_TYPE (attr
) =
7077 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
7080 case DW_FORM_ref_udata
:
7081 DW_ADDR (attr
) = (cu
->header
.offset
7082 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
7083 info_ptr
+= bytes_read
;
7085 case DW_FORM_indirect
:
7086 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7087 info_ptr
+= bytes_read
;
7088 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
7091 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7092 dwarf_form_name (form
),
7093 bfd_get_filename (abfd
));
7096 /* We have seen instances where the compiler tried to emit a byte
7097 size attribute of -1 which ended up being encoded as an unsigned
7098 0xffffffff. Although 0xffffffff is technically a valid size value,
7099 an object of this size seems pretty unlikely so we can relatively
7100 safely treat these cases as if the size attribute was invalid and
7101 treat them as zero by default. */
7102 if (attr
->name
== DW_AT_byte_size
7103 && form
== DW_FORM_data4
7104 && DW_UNSND (attr
) >= 0xffffffff)
7107 (&symfile_complaints
,
7108 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7109 hex_string (DW_UNSND (attr
)));
7110 DW_UNSND (attr
) = 0;
7116 /* Read an attribute described by an abbreviated attribute. */
7119 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
7120 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7122 attr
->name
= abbrev
->name
;
7123 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
7126 /* read dwarf information from a buffer */
7129 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
7131 return bfd_get_8 (abfd
, buf
);
7135 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
7137 return bfd_get_signed_8 (abfd
, buf
);
7141 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
7143 return bfd_get_16 (abfd
, buf
);
7147 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7149 return bfd_get_signed_16 (abfd
, buf
);
7153 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
7155 return bfd_get_32 (abfd
, buf
);
7159 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7161 return bfd_get_signed_32 (abfd
, buf
);
7165 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
7167 return bfd_get_64 (abfd
, buf
);
7171 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
7172 unsigned int *bytes_read
)
7174 struct comp_unit_head
*cu_header
= &cu
->header
;
7175 CORE_ADDR retval
= 0;
7177 if (cu_header
->signed_addr_p
)
7179 switch (cu_header
->addr_size
)
7182 retval
= bfd_get_signed_16 (abfd
, buf
);
7185 retval
= bfd_get_signed_32 (abfd
, buf
);
7188 retval
= bfd_get_signed_64 (abfd
, buf
);
7191 internal_error (__FILE__
, __LINE__
,
7192 _("read_address: bad switch, signed [in module %s]"),
7193 bfd_get_filename (abfd
));
7198 switch (cu_header
->addr_size
)
7201 retval
= bfd_get_16 (abfd
, buf
);
7204 retval
= bfd_get_32 (abfd
, buf
);
7207 retval
= bfd_get_64 (abfd
, buf
);
7210 internal_error (__FILE__
, __LINE__
,
7211 _("read_address: bad switch, unsigned [in module %s]"),
7212 bfd_get_filename (abfd
));
7216 *bytes_read
= cu_header
->addr_size
;
7220 /* Read the initial length from a section. The (draft) DWARF 3
7221 specification allows the initial length to take up either 4 bytes
7222 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7223 bytes describe the length and all offsets will be 8 bytes in length
7226 An older, non-standard 64-bit format is also handled by this
7227 function. The older format in question stores the initial length
7228 as an 8-byte quantity without an escape value. Lengths greater
7229 than 2^32 aren't very common which means that the initial 4 bytes
7230 is almost always zero. Since a length value of zero doesn't make
7231 sense for the 32-bit format, this initial zero can be considered to
7232 be an escape value which indicates the presence of the older 64-bit
7233 format. As written, the code can't detect (old format) lengths
7234 greater than 4GB. If it becomes necessary to handle lengths
7235 somewhat larger than 4GB, we could allow other small values (such
7236 as the non-sensical values of 1, 2, and 3) to also be used as
7237 escape values indicating the presence of the old format.
7239 The value returned via bytes_read should be used to increment the
7240 relevant pointer after calling read_initial_length().
7242 [ Note: read_initial_length() and read_offset() are based on the
7243 document entitled "DWARF Debugging Information Format", revision
7244 3, draft 8, dated November 19, 2001. This document was obtained
7247 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7249 This document is only a draft and is subject to change. (So beware.)
7251 Details regarding the older, non-standard 64-bit format were
7252 determined empirically by examining 64-bit ELF files produced by
7253 the SGI toolchain on an IRIX 6.5 machine.
7255 - Kevin, July 16, 2002
7259 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
7261 LONGEST length
= bfd_get_32 (abfd
, buf
);
7263 if (length
== 0xffffffff)
7265 length
= bfd_get_64 (abfd
, buf
+ 4);
7268 else if (length
== 0)
7270 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7271 length
= bfd_get_64 (abfd
, buf
);
7282 /* Cover function for read_initial_length.
7283 Returns the length of the object at BUF, and stores the size of the
7284 initial length in *BYTES_READ and stores the size that offsets will be in
7286 If the initial length size is not equivalent to that specified in
7287 CU_HEADER then issue a complaint.
7288 This is useful when reading non-comp-unit headers. */
7291 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
7292 const struct comp_unit_head
*cu_header
,
7293 unsigned int *bytes_read
,
7294 unsigned int *offset_size
)
7296 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
7298 gdb_assert (cu_header
->initial_length_size
== 4
7299 || cu_header
->initial_length_size
== 8
7300 || cu_header
->initial_length_size
== 12);
7302 if (cu_header
->initial_length_size
!= *bytes_read
)
7303 complaint (&symfile_complaints
,
7304 _("intermixed 32-bit and 64-bit DWARF sections"));
7306 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
7310 /* Read an offset from the data stream. The size of the offset is
7311 given by cu_header->offset_size. */
7314 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
7315 unsigned int *bytes_read
)
7317 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
7318 *bytes_read
= cu_header
->offset_size
;
7322 /* Read an offset from the data stream. */
7325 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
7329 switch (offset_size
)
7332 retval
= bfd_get_32 (abfd
, buf
);
7335 retval
= bfd_get_64 (abfd
, buf
);
7338 internal_error (__FILE__
, __LINE__
,
7339 _("read_offset_1: bad switch [in module %s]"),
7340 bfd_get_filename (abfd
));
7347 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
7349 /* If the size of a host char is 8 bits, we can return a pointer
7350 to the buffer, otherwise we have to copy the data to a buffer
7351 allocated on the temporary obstack. */
7352 gdb_assert (HOST_CHAR_BIT
== 8);
7357 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7359 /* If the size of a host char is 8 bits, we can return a pointer
7360 to the string, otherwise we have to copy the string to a buffer
7361 allocated on the temporary obstack. */
7362 gdb_assert (HOST_CHAR_BIT
== 8);
7365 *bytes_read_ptr
= 1;
7368 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
7369 return (char *) buf
;
7373 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
7374 const struct comp_unit_head
*cu_header
,
7375 unsigned int *bytes_read_ptr
)
7377 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
7379 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
7380 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
7382 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7383 bfd_get_filename (abfd
));
7386 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
7388 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7389 bfd_get_filename (abfd
));
7392 gdb_assert (HOST_CHAR_BIT
== 8);
7393 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
7395 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
7398 static unsigned long
7399 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7401 unsigned long result
;
7402 unsigned int num_read
;
7412 byte
= bfd_get_8 (abfd
, buf
);
7415 result
|= ((unsigned long)(byte
& 127) << shift
);
7416 if ((byte
& 128) == 0)
7422 *bytes_read_ptr
= num_read
;
7427 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7430 int i
, shift
, num_read
;
7439 byte
= bfd_get_8 (abfd
, buf
);
7442 result
|= ((long)(byte
& 127) << shift
);
7444 if ((byte
& 128) == 0)
7449 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
7450 result
|= -(((long)1) << shift
);
7451 *bytes_read_ptr
= num_read
;
7455 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7458 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
7464 byte
= bfd_get_8 (abfd
, buf
);
7466 if ((byte
& 128) == 0)
7472 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
7479 cu
->language
= language_c
;
7481 case DW_LANG_C_plus_plus
:
7482 cu
->language
= language_cplus
;
7484 case DW_LANG_Fortran77
:
7485 case DW_LANG_Fortran90
:
7486 case DW_LANG_Fortran95
:
7487 cu
->language
= language_fortran
;
7489 case DW_LANG_Mips_Assembler
:
7490 cu
->language
= language_asm
;
7493 cu
->language
= language_java
;
7497 cu
->language
= language_ada
;
7499 case DW_LANG_Modula2
:
7500 cu
->language
= language_m2
;
7502 case DW_LANG_Pascal83
:
7503 cu
->language
= language_pascal
;
7506 cu
->language
= language_objc
;
7508 case DW_LANG_Cobol74
:
7509 case DW_LANG_Cobol85
:
7511 cu
->language
= language_minimal
;
7514 cu
->language_defn
= language_def (cu
->language
);
7517 /* Return the named attribute or NULL if not there. */
7519 static struct attribute
*
7520 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
7523 struct attribute
*spec
= NULL
;
7525 for (i
= 0; i
< die
->num_attrs
; ++i
)
7527 if (die
->attrs
[i
].name
== name
)
7528 return &die
->attrs
[i
];
7529 if (die
->attrs
[i
].name
== DW_AT_specification
7530 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
7531 spec
= &die
->attrs
[i
];
7536 die
= follow_die_ref (die
, spec
, &cu
);
7537 return dwarf2_attr (die
, name
, cu
);
7543 /* Return the named attribute or NULL if not there,
7544 but do not follow DW_AT_specification, etc.
7545 This is for use in contexts where we're reading .debug_types dies.
7546 Following DW_AT_specification, DW_AT_abstract_origin will take us
7547 back up the chain, and we want to go down. */
7549 static struct attribute
*
7550 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
7551 struct dwarf2_cu
*cu
)
7555 for (i
= 0; i
< die
->num_attrs
; ++i
)
7556 if (die
->attrs
[i
].name
== name
)
7557 return &die
->attrs
[i
];
7562 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7563 and holds a non-zero value. This function should only be used for
7564 DW_FORM_flag attributes. */
7567 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7569 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7571 return (attr
&& DW_UNSND (attr
));
7575 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7577 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7578 which value is non-zero. However, we have to be careful with
7579 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7580 (via dwarf2_flag_true_p) follows this attribute. So we may
7581 end up accidently finding a declaration attribute that belongs
7582 to a different DIE referenced by the specification attribute,
7583 even though the given DIE does not have a declaration attribute. */
7584 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7585 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7588 /* Return the die giving the specification for DIE, if there is
7589 one. *SPEC_CU is the CU containing DIE on input, and the CU
7590 containing the return value on output. If there is no
7591 specification, but there is an abstract origin, that is
7594 static struct die_info
*
7595 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7597 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7600 if (spec_attr
== NULL
)
7601 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7603 if (spec_attr
== NULL
)
7606 return follow_die_ref (die
, spec_attr
, spec_cu
);
7609 /* Free the line_header structure *LH, and any arrays and strings it
7612 free_line_header (struct line_header
*lh
)
7614 if (lh
->standard_opcode_lengths
)
7615 xfree (lh
->standard_opcode_lengths
);
7617 /* Remember that all the lh->file_names[i].name pointers are
7618 pointers into debug_line_buffer, and don't need to be freed. */
7620 xfree (lh
->file_names
);
7622 /* Similarly for the include directory names. */
7623 if (lh
->include_dirs
)
7624 xfree (lh
->include_dirs
);
7630 /* Add an entry to LH's include directory table. */
7632 add_include_dir (struct line_header
*lh
, char *include_dir
)
7634 /* Grow the array if necessary. */
7635 if (lh
->include_dirs_size
== 0)
7637 lh
->include_dirs_size
= 1; /* for testing */
7638 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7639 * sizeof (*lh
->include_dirs
));
7641 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7643 lh
->include_dirs_size
*= 2;
7644 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7645 (lh
->include_dirs_size
7646 * sizeof (*lh
->include_dirs
)));
7649 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7653 /* Add an entry to LH's file name table. */
7655 add_file_name (struct line_header
*lh
,
7657 unsigned int dir_index
,
7658 unsigned int mod_time
,
7659 unsigned int length
)
7661 struct file_entry
*fe
;
7663 /* Grow the array if necessary. */
7664 if (lh
->file_names_size
== 0)
7666 lh
->file_names_size
= 1; /* for testing */
7667 lh
->file_names
= xmalloc (lh
->file_names_size
7668 * sizeof (*lh
->file_names
));
7670 else if (lh
->num_file_names
>= lh
->file_names_size
)
7672 lh
->file_names_size
*= 2;
7673 lh
->file_names
= xrealloc (lh
->file_names
,
7674 (lh
->file_names_size
7675 * sizeof (*lh
->file_names
)));
7678 fe
= &lh
->file_names
[lh
->num_file_names
++];
7680 fe
->dir_index
= dir_index
;
7681 fe
->mod_time
= mod_time
;
7682 fe
->length
= length
;
7688 /* Read the statement program header starting at OFFSET in
7689 .debug_line, according to the endianness of ABFD. Return a pointer
7690 to a struct line_header, allocated using xmalloc.
7692 NOTE: the strings in the include directory and file name tables of
7693 the returned object point into debug_line_buffer, and must not be
7695 static struct line_header
*
7696 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7697 struct dwarf2_cu
*cu
)
7699 struct cleanup
*back_to
;
7700 struct line_header
*lh
;
7702 unsigned int bytes_read
, offset_size
;
7704 char *cur_dir
, *cur_file
;
7706 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
7707 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7709 complaint (&symfile_complaints
, _("missing .debug_line section"));
7713 /* Make sure that at least there's room for the total_length field.
7714 That could be 12 bytes long, but we're just going to fudge that. */
7715 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7717 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7721 lh
= xmalloc (sizeof (*lh
));
7722 memset (lh
, 0, sizeof (*lh
));
7723 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7726 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7728 /* Read in the header. */
7730 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7731 &bytes_read
, &offset_size
);
7732 line_ptr
+= bytes_read
;
7733 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7734 + dwarf2_per_objfile
->line
.size
))
7736 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7739 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7740 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7742 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7743 line_ptr
+= offset_size
;
7744 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7746 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7748 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7750 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7752 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7754 lh
->standard_opcode_lengths
7755 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7757 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7758 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7760 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7764 /* Read directory table. */
7765 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7767 line_ptr
+= bytes_read
;
7768 add_include_dir (lh
, cur_dir
);
7770 line_ptr
+= bytes_read
;
7772 /* Read file name table. */
7773 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7775 unsigned int dir_index
, mod_time
, length
;
7777 line_ptr
+= bytes_read
;
7778 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7779 line_ptr
+= bytes_read
;
7780 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7781 line_ptr
+= bytes_read
;
7782 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7783 line_ptr
+= bytes_read
;
7785 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7787 line_ptr
+= bytes_read
;
7788 lh
->statement_program_start
= line_ptr
;
7790 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7791 + dwarf2_per_objfile
->line
.size
))
7792 complaint (&symfile_complaints
,
7793 _("line number info header doesn't fit in `.debug_line' section"));
7795 discard_cleanups (back_to
);
7799 /* This function exists to work around a bug in certain compilers
7800 (particularly GCC 2.95), in which the first line number marker of a
7801 function does not show up until after the prologue, right before
7802 the second line number marker. This function shifts ADDRESS down
7803 to the beginning of the function if necessary, and is called on
7804 addresses passed to record_line. */
7807 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7809 struct function_range
*fn
;
7811 /* Find the function_range containing address. */
7816 cu
->cached_fn
= cu
->first_fn
;
7820 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7826 while (fn
&& fn
!= cu
->cached_fn
)
7827 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7837 if (address
!= fn
->lowpc
)
7838 complaint (&symfile_complaints
,
7839 _("misplaced first line number at 0x%lx for '%s'"),
7840 (unsigned long) address
, fn
->name
);
7845 /* Decode the Line Number Program (LNP) for the given line_header
7846 structure and CU. The actual information extracted and the type
7847 of structures created from the LNP depends on the value of PST.
7849 1. If PST is NULL, then this procedure uses the data from the program
7850 to create all necessary symbol tables, and their linetables.
7851 The compilation directory of the file is passed in COMP_DIR,
7852 and must not be NULL.
7854 2. If PST is not NULL, this procedure reads the program to determine
7855 the list of files included by the unit represented by PST, and
7856 builds all the associated partial symbol tables. In this case,
7857 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7858 is not used to compute the full name of the symtab, and therefore
7859 omitting it when building the partial symtab does not introduce
7860 the potential for inconsistency - a partial symtab and its associated
7861 symbtab having a different fullname -). */
7864 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7865 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7867 gdb_byte
*line_ptr
, *extended_end
;
7869 unsigned int bytes_read
, extended_len
;
7870 unsigned char op_code
, extended_op
, adj_opcode
;
7872 struct objfile
*objfile
= cu
->objfile
;
7873 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7874 const int decode_for_pst_p
= (pst
!= NULL
);
7875 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7877 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7879 line_ptr
= lh
->statement_program_start
;
7880 line_end
= lh
->statement_program_end
;
7882 /* Read the statement sequences until there's nothing left. */
7883 while (line_ptr
< line_end
)
7885 /* state machine registers */
7886 CORE_ADDR address
= 0;
7887 unsigned int file
= 1;
7888 unsigned int line
= 1;
7889 unsigned int column
= 0;
7890 int is_stmt
= lh
->default_is_stmt
;
7891 int basic_block
= 0;
7892 int end_sequence
= 0;
7895 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7897 /* Start a subfile for the current file of the state machine. */
7898 /* lh->include_dirs and lh->file_names are 0-based, but the
7899 directory and file name numbers in the statement program
7901 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7905 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7907 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7910 /* Decode the table. */
7911 while (!end_sequence
)
7913 op_code
= read_1_byte (abfd
, line_ptr
);
7915 if (line_ptr
> line_end
)
7917 dwarf2_debug_line_missing_end_sequence_complaint ();
7921 if (op_code
>= lh
->opcode_base
)
7923 /* Special operand. */
7924 adj_opcode
= op_code
- lh
->opcode_base
;
7925 address
+= (adj_opcode
/ lh
->line_range
)
7926 * lh
->minimum_instruction_length
;
7927 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7928 if (lh
->num_file_names
< file
|| file
== 0)
7929 dwarf2_debug_line_missing_file_complaint ();
7932 lh
->file_names
[file
- 1].included_p
= 1;
7933 if (!decode_for_pst_p
&& is_stmt
)
7935 if (last_subfile
!= current_subfile
)
7937 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7939 record_line (last_subfile
, 0, addr
);
7940 last_subfile
= current_subfile
;
7942 /* Append row to matrix using current values. */
7943 addr
= check_cu_functions (address
, cu
);
7944 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7945 record_line (current_subfile
, line
, addr
);
7950 else switch (op_code
)
7952 case DW_LNS_extended_op
:
7953 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7954 line_ptr
+= bytes_read
;
7955 extended_end
= line_ptr
+ extended_len
;
7956 extended_op
= read_1_byte (abfd
, line_ptr
);
7958 switch (extended_op
)
7960 case DW_LNE_end_sequence
:
7963 case DW_LNE_set_address
:
7964 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7965 line_ptr
+= bytes_read
;
7966 address
+= baseaddr
;
7968 case DW_LNE_define_file
:
7971 unsigned int dir_index
, mod_time
, length
;
7973 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7974 line_ptr
+= bytes_read
;
7976 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7977 line_ptr
+= bytes_read
;
7979 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7980 line_ptr
+= bytes_read
;
7982 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7983 line_ptr
+= bytes_read
;
7984 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7987 case DW_LNE_set_discriminator
:
7988 /* The discriminator is not interesting to the debugger;
7990 line_ptr
= extended_end
;
7993 complaint (&symfile_complaints
,
7994 _("mangled .debug_line section"));
7997 /* Make sure that we parsed the extended op correctly. If e.g.
7998 we expected a different address size than the producer used,
7999 we may have read the wrong number of bytes. */
8000 if (line_ptr
!= extended_end
)
8002 complaint (&symfile_complaints
,
8003 _("mangled .debug_line section"));
8008 if (lh
->num_file_names
< file
|| file
== 0)
8009 dwarf2_debug_line_missing_file_complaint ();
8012 lh
->file_names
[file
- 1].included_p
= 1;
8013 if (!decode_for_pst_p
&& is_stmt
)
8015 if (last_subfile
!= current_subfile
)
8017 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8019 record_line (last_subfile
, 0, addr
);
8020 last_subfile
= current_subfile
;
8022 addr
= check_cu_functions (address
, cu
);
8023 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8024 record_line (current_subfile
, line
, addr
);
8029 case DW_LNS_advance_pc
:
8030 address
+= lh
->minimum_instruction_length
8031 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8032 line_ptr
+= bytes_read
;
8034 case DW_LNS_advance_line
:
8035 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
8036 line_ptr
+= bytes_read
;
8038 case DW_LNS_set_file
:
8040 /* The arrays lh->include_dirs and lh->file_names are
8041 0-based, but the directory and file name numbers in
8042 the statement program are 1-based. */
8043 struct file_entry
*fe
;
8046 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8047 line_ptr
+= bytes_read
;
8048 if (lh
->num_file_names
< file
|| file
== 0)
8049 dwarf2_debug_line_missing_file_complaint ();
8052 fe
= &lh
->file_names
[file
- 1];
8054 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8055 if (!decode_for_pst_p
)
8057 last_subfile
= current_subfile
;
8058 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8063 case DW_LNS_set_column
:
8064 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8065 line_ptr
+= bytes_read
;
8067 case DW_LNS_negate_stmt
:
8068 is_stmt
= (!is_stmt
);
8070 case DW_LNS_set_basic_block
:
8073 /* Add to the address register of the state machine the
8074 address increment value corresponding to special opcode
8075 255. I.e., this value is scaled by the minimum
8076 instruction length since special opcode 255 would have
8077 scaled the the increment. */
8078 case DW_LNS_const_add_pc
:
8079 address
+= (lh
->minimum_instruction_length
8080 * ((255 - lh
->opcode_base
) / lh
->line_range
));
8082 case DW_LNS_fixed_advance_pc
:
8083 address
+= read_2_bytes (abfd
, line_ptr
);
8088 /* Unknown standard opcode, ignore it. */
8091 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
8093 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8094 line_ptr
+= bytes_read
;
8099 if (lh
->num_file_names
< file
|| file
== 0)
8100 dwarf2_debug_line_missing_file_complaint ();
8103 lh
->file_names
[file
- 1].included_p
= 1;
8104 if (!decode_for_pst_p
)
8106 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8107 record_line (current_subfile
, 0, addr
);
8112 if (decode_for_pst_p
)
8116 /* Now that we're done scanning the Line Header Program, we can
8117 create the psymtab of each included file. */
8118 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
8119 if (lh
->file_names
[file_index
].included_p
== 1)
8121 const struct file_entry fe
= lh
->file_names
[file_index
];
8122 char *include_name
= fe
.name
;
8123 char *dir_name
= NULL
;
8124 char *pst_filename
= pst
->filename
;
8127 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
8129 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
8131 include_name
= concat (dir_name
, SLASH_STRING
,
8132 include_name
, (char *)NULL
);
8133 make_cleanup (xfree
, include_name
);
8136 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
8138 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
8139 pst_filename
, (char *)NULL
);
8140 make_cleanup (xfree
, pst_filename
);
8143 if (strcmp (include_name
, pst_filename
) != 0)
8144 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
8149 /* Make sure a symtab is created for every file, even files
8150 which contain only variables (i.e. no code with associated
8154 struct file_entry
*fe
;
8156 for (i
= 0; i
< lh
->num_file_names
; i
++)
8159 fe
= &lh
->file_names
[i
];
8161 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8162 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8164 /* Skip the main file; we don't need it, and it must be
8165 allocated last, so that it will show up before the
8166 non-primary symtabs in the objfile's symtab list. */
8167 if (current_subfile
== first_subfile
)
8170 if (current_subfile
->symtab
== NULL
)
8171 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8173 fe
->symtab
= current_subfile
->symtab
;
8178 /* Start a subfile for DWARF. FILENAME is the name of the file and
8179 DIRNAME the name of the source directory which contains FILENAME
8180 or NULL if not known. COMP_DIR is the compilation directory for the
8181 linetable's compilation unit or NULL if not known.
8182 This routine tries to keep line numbers from identical absolute and
8183 relative file names in a common subfile.
8185 Using the `list' example from the GDB testsuite, which resides in
8186 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8187 of /srcdir/list0.c yields the following debugging information for list0.c:
8189 DW_AT_name: /srcdir/list0.c
8190 DW_AT_comp_dir: /compdir
8191 files.files[0].name: list0.h
8192 files.files[0].dir: /srcdir
8193 files.files[1].name: list0.c
8194 files.files[1].dir: /srcdir
8196 The line number information for list0.c has to end up in a single
8197 subfile, so that `break /srcdir/list0.c:1' works as expected.
8198 start_subfile will ensure that this happens provided that we pass the
8199 concatenation of files.files[1].dir and files.files[1].name as the
8203 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
8207 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8208 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8209 second argument to start_subfile. To be consistent, we do the
8210 same here. In order not to lose the line information directory,
8211 we concatenate it to the filename when it makes sense.
8212 Note that the Dwarf3 standard says (speaking of filenames in line
8213 information): ``The directory index is ignored for file names
8214 that represent full path names''. Thus ignoring dirname in the
8215 `else' branch below isn't an issue. */
8217 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
8218 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
8220 fullname
= filename
;
8222 start_subfile (fullname
, comp_dir
);
8224 if (fullname
!= filename
)
8229 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
8230 struct dwarf2_cu
*cu
)
8232 struct objfile
*objfile
= cu
->objfile
;
8233 struct comp_unit_head
*cu_header
= &cu
->header
;
8235 /* NOTE drow/2003-01-30: There used to be a comment and some special
8236 code here to turn a symbol with DW_AT_external and a
8237 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8238 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8239 with some versions of binutils) where shared libraries could have
8240 relocations against symbols in their debug information - the
8241 minimal symbol would have the right address, but the debug info
8242 would not. It's no longer necessary, because we will explicitly
8243 apply relocations when we read in the debug information now. */
8245 /* A DW_AT_location attribute with no contents indicates that a
8246 variable has been optimized away. */
8247 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
8249 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8253 /* Handle one degenerate form of location expression specially, to
8254 preserve GDB's previous behavior when section offsets are
8255 specified. If this is just a DW_OP_addr then mark this symbol
8258 if (attr_form_is_block (attr
)
8259 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
8260 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
8264 SYMBOL_VALUE_ADDRESS (sym
) =
8265 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
8266 SYMBOL_CLASS (sym
) = LOC_STATIC
;
8267 fixup_symbol_section (sym
, objfile
);
8268 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
8269 SYMBOL_SECTION (sym
));
8273 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8274 expression evaluator, and use LOC_COMPUTED only when necessary
8275 (i.e. when the value of a register or memory location is
8276 referenced, or a thread-local block, etc.). Then again, it might
8277 not be worthwhile. I'm assuming that it isn't unless performance
8278 or memory numbers show me otherwise. */
8280 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
8281 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
8284 /* Given a pointer to a DWARF information entry, figure out if we need
8285 to make a symbol table entry for it, and if so, create a new entry
8286 and return a pointer to it.
8287 If TYPE is NULL, determine symbol type from the die, otherwise
8288 used the passed type. */
8290 static struct symbol
*
8291 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
8293 struct objfile
*objfile
= cu
->objfile
;
8294 struct symbol
*sym
= NULL
;
8296 struct attribute
*attr
= NULL
;
8297 struct attribute
*attr2
= NULL
;
8299 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8301 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8303 name
= dwarf2_name (die
, cu
);
8306 const char *linkagename
;
8308 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
8309 sizeof (struct symbol
));
8310 OBJSTAT (objfile
, n_syms
++);
8311 memset (sym
, 0, sizeof (struct symbol
));
8313 /* Cache this symbol's name and the name's demangled form (if any). */
8314 SYMBOL_LANGUAGE (sym
) = cu
->language
;
8315 linkagename
= dwarf2_physname (name
, die
, cu
);
8316 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
8318 /* Default assumptions.
8319 Use the passed type or decode it from the die. */
8320 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8321 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8323 SYMBOL_TYPE (sym
) = type
;
8325 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
8326 attr
= dwarf2_attr (die
,
8327 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
8331 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
8334 attr
= dwarf2_attr (die
,
8335 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
8339 int file_index
= DW_UNSND (attr
);
8340 if (cu
->line_header
== NULL
8341 || file_index
> cu
->line_header
->num_file_names
)
8342 complaint (&symfile_complaints
,
8343 _("file index out of range"));
8344 else if (file_index
> 0)
8346 struct file_entry
*fe
;
8347 fe
= &cu
->line_header
->file_names
[file_index
- 1];
8348 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
8355 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8358 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
8360 SYMBOL_CLASS (sym
) = LOC_LABEL
;
8362 case DW_TAG_subprogram
:
8363 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8365 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8366 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8367 if ((attr2
&& (DW_UNSND (attr2
) != 0))
8368 || cu
->language
== language_ada
)
8370 /* Subprograms marked external are stored as a global symbol.
8371 Ada subprograms, whether marked external or not, are always
8372 stored as a global symbol, because we want to be able to
8373 access them globally. For instance, we want to be able
8374 to break on a nested subprogram without having to
8375 specify the context. */
8376 add_symbol_to_list (sym
, &global_symbols
);
8380 add_symbol_to_list (sym
, cu
->list_in_scope
);
8383 case DW_TAG_inlined_subroutine
:
8384 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8386 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8387 SYMBOL_INLINED (sym
) = 1;
8388 /* Do not add the symbol to any lists. It will be found via
8389 BLOCK_FUNCTION from the blockvector. */
8391 case DW_TAG_variable
:
8392 /* Compilation with minimal debug info may result in variables
8393 with missing type entries. Change the misleading `void' type
8394 to something sensible. */
8395 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
8397 = objfile_type (objfile
)->nodebug_data_symbol
;
8399 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8402 dwarf2_const_value (attr
, sym
, cu
);
8403 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8404 if (attr2
&& (DW_UNSND (attr2
) != 0))
8405 add_symbol_to_list (sym
, &global_symbols
);
8407 add_symbol_to_list (sym
, cu
->list_in_scope
);
8410 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8413 var_decode_location (attr
, sym
, cu
);
8414 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8415 if (attr2
&& (DW_UNSND (attr2
) != 0))
8416 add_symbol_to_list (sym
, &global_symbols
);
8418 add_symbol_to_list (sym
, cu
->list_in_scope
);
8422 /* We do not know the address of this symbol.
8423 If it is an external symbol and we have type information
8424 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8425 The address of the variable will then be determined from
8426 the minimal symbol table whenever the variable is
8428 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8429 if (attr2
&& (DW_UNSND (attr2
) != 0)
8430 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
8432 struct pending
**list_to_add
;
8434 /* A variable with DW_AT_external is never static, but it
8435 may be block-scoped. */
8436 list_to_add
= (cu
->list_in_scope
== &file_symbols
8437 ? &global_symbols
: cu
->list_in_scope
);
8439 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8440 add_symbol_to_list (sym
, list_to_add
);
8442 else if (!die_is_declaration (die
, cu
))
8444 /* Use the default LOC_OPTIMIZED_OUT class. */
8445 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
8446 add_symbol_to_list (sym
, cu
->list_in_scope
);
8450 case DW_TAG_formal_parameter
:
8451 /* If we are inside a function, mark this as an argument. If
8452 not, we might be looking at an argument to an inlined function
8453 when we do not have enough information to show inlined frames;
8454 pretend it's a local variable in that case so that the user can
8456 if (context_stack_depth
> 0
8457 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
8458 SYMBOL_IS_ARGUMENT (sym
) = 1;
8459 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8462 var_decode_location (attr
, sym
, cu
);
8464 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8467 dwarf2_const_value (attr
, sym
, cu
);
8469 add_symbol_to_list (sym
, cu
->list_in_scope
);
8471 case DW_TAG_unspecified_parameters
:
8472 /* From varargs functions; gdb doesn't seem to have any
8473 interest in this information, so just ignore it for now.
8476 case DW_TAG_class_type
:
8477 case DW_TAG_interface_type
:
8478 case DW_TAG_structure_type
:
8479 case DW_TAG_union_type
:
8480 case DW_TAG_set_type
:
8481 case DW_TAG_enumeration_type
:
8482 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8483 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8485 /* Make sure that the symbol includes appropriate enclosing
8486 classes/namespaces in its name. These are calculated in
8487 read_structure_type, and the correct name is saved in
8490 if (cu
->language
== language_cplus
8491 || cu
->language
== language_java
)
8493 struct type
*type
= SYMBOL_TYPE (sym
);
8495 if (TYPE_TAG_NAME (type
) != NULL
)
8497 /* FIXME: carlton/2003-11-10: Should this use
8498 SYMBOL_SET_NAMES instead? (The same problem also
8499 arises further down in this function.) */
8500 /* The type's name is already allocated along with
8501 this objfile, so we don't need to duplicate it
8503 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
8508 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8509 really ever be static objects: otherwise, if you try
8510 to, say, break of a class's method and you're in a file
8511 which doesn't mention that class, it won't work unless
8512 the check for all static symbols in lookup_symbol_aux
8513 saves you. See the OtherFileClass tests in
8514 gdb.c++/namespace.exp. */
8516 struct pending
**list_to_add
;
8518 list_to_add
= (cu
->list_in_scope
== &file_symbols
8519 && (cu
->language
== language_cplus
8520 || cu
->language
== language_java
)
8521 ? &global_symbols
: cu
->list_in_scope
);
8523 add_symbol_to_list (sym
, list_to_add
);
8525 /* The semantics of C++ state that "struct foo { ... }" also
8526 defines a typedef for "foo". A Java class declaration also
8527 defines a typedef for the class. */
8528 if (cu
->language
== language_cplus
8529 || cu
->language
== language_java
8530 || cu
->language
== language_ada
)
8532 /* The symbol's name is already allocated along with
8533 this objfile, so we don't need to duplicate it for
8535 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
8536 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
8540 case DW_TAG_typedef
:
8541 SYMBOL_LINKAGE_NAME (sym
)
8542 = (char *) dwarf2_full_name (name
, die
, cu
);
8543 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8544 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8545 add_symbol_to_list (sym
, cu
->list_in_scope
);
8547 case DW_TAG_base_type
:
8548 case DW_TAG_subrange_type
:
8549 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8550 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8551 add_symbol_to_list (sym
, cu
->list_in_scope
);
8553 case DW_TAG_enumerator
:
8554 SYMBOL_LINKAGE_NAME (sym
)
8555 = (char *) dwarf2_full_name (name
, die
, cu
);
8556 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8559 dwarf2_const_value (attr
, sym
, cu
);
8562 /* NOTE: carlton/2003-11-10: See comment above in the
8563 DW_TAG_class_type, etc. block. */
8565 struct pending
**list_to_add
;
8567 list_to_add
= (cu
->list_in_scope
== &file_symbols
8568 && (cu
->language
== language_cplus
8569 || cu
->language
== language_java
)
8570 ? &global_symbols
: cu
->list_in_scope
);
8572 add_symbol_to_list (sym
, list_to_add
);
8575 case DW_TAG_namespace
:
8576 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8577 add_symbol_to_list (sym
, &global_symbols
);
8580 /* Not a tag we recognize. Hopefully we aren't processing
8581 trash data, but since we must specifically ignore things
8582 we don't recognize, there is nothing else we should do at
8584 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8585 dwarf_tag_name (die
->tag
));
8589 /* For the benefit of old versions of GCC, check for anonymous
8590 namespaces based on the demangled name. */
8591 if (!processing_has_namespace_info
8592 && cu
->language
== language_cplus
)
8593 cp_scan_for_anonymous_namespaces (sym
);
8598 /* Copy constant value from an attribute to a symbol. */
8601 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8602 struct dwarf2_cu
*cu
)
8604 struct objfile
*objfile
= cu
->objfile
;
8605 struct comp_unit_head
*cu_header
= &cu
->header
;
8606 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
8607 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
8608 struct dwarf_block
*blk
;
8613 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8614 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8615 cu_header
->addr_size
,
8616 TYPE_LENGTH (SYMBOL_TYPE
8618 SYMBOL_VALUE_BYTES (sym
) =
8619 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8620 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8621 it's body - store_unsigned_integer. */
8622 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8623 byte_order
, DW_ADDR (attr
));
8624 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8626 case DW_FORM_string
:
8628 /* DW_STRING is already allocated on the obstack, point directly
8630 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8631 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8633 case DW_FORM_block1
:
8634 case DW_FORM_block2
:
8635 case DW_FORM_block4
:
8637 blk
= DW_BLOCK (attr
);
8638 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8639 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8641 TYPE_LENGTH (SYMBOL_TYPE
8643 SYMBOL_VALUE_BYTES (sym
) =
8644 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8645 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8646 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8649 /* The DW_AT_const_value attributes are supposed to carry the
8650 symbol's value "represented as it would be on the target
8651 architecture." By the time we get here, it's already been
8652 converted to host endianness, so we just need to sign- or
8653 zero-extend it as appropriate. */
8655 dwarf2_const_value_data (attr
, sym
, 8);
8658 dwarf2_const_value_data (attr
, sym
, 16);
8661 dwarf2_const_value_data (attr
, sym
, 32);
8664 dwarf2_const_value_data (attr
, sym
, 64);
8668 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8669 SYMBOL_CLASS (sym
) = LOC_CONST
;
8673 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8674 SYMBOL_CLASS (sym
) = LOC_CONST
;
8678 complaint (&symfile_complaints
,
8679 _("unsupported const value attribute form: '%s'"),
8680 dwarf_form_name (attr
->form
));
8681 SYMBOL_VALUE (sym
) = 0;
8682 SYMBOL_CLASS (sym
) = LOC_CONST
;
8688 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8689 or zero-extend it as appropriate for the symbol's type. */
8691 dwarf2_const_value_data (struct attribute
*attr
,
8695 LONGEST l
= DW_UNSND (attr
);
8697 if (bits
< sizeof (l
) * 8)
8699 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8700 l
&= ((LONGEST
) 1 << bits
) - 1;
8702 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8705 SYMBOL_VALUE (sym
) = l
;
8706 SYMBOL_CLASS (sym
) = LOC_CONST
;
8710 /* Return the type of the die in question using its DW_AT_type attribute. */
8712 static struct type
*
8713 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8716 struct attribute
*type_attr
;
8717 struct die_info
*type_die
;
8719 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8722 /* A missing DW_AT_type represents a void type. */
8723 return objfile_type (cu
->objfile
)->builtin_void
;
8726 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8728 type
= tag_type_to_type (type_die
, cu
);
8731 dump_die_for_error (type_die
);
8732 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8738 /* True iff CU's producer generates GNAT Ada auxiliary information
8739 that allows to find parallel types through that information instead
8740 of having to do expensive parallel lookups by type name. */
8743 need_gnat_info (struct dwarf2_cu
*cu
)
8745 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8746 of GNAT produces this auxiliary information, without any indication
8747 that it is produced. Part of enhancing the FSF version of GNAT
8748 to produce that information will be to put in place an indicator
8749 that we can use in order to determine whether the descriptive type
8750 info is available or not. One suggestion that has been made is
8751 to use a new attribute, attached to the CU die. For now, assume
8752 that the descriptive type info is not available. */
8757 /* Return the auxiliary type of the die in question using its
8758 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8759 attribute is not present. */
8761 static struct type
*
8762 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8765 struct attribute
*type_attr
;
8766 struct die_info
*type_die
;
8768 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
8772 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8773 type
= tag_type_to_type (type_die
, cu
);
8776 dump_die_for_error (type_die
);
8777 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8783 /* If DIE has a descriptive_type attribute, then set the TYPE's
8784 descriptive type accordingly. */
8787 set_descriptive_type (struct type
*type
, struct die_info
*die
,
8788 struct dwarf2_cu
*cu
)
8790 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
8792 if (descriptive_type
)
8794 ALLOCATE_GNAT_AUX_TYPE (type
);
8795 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
8799 /* Return the containing type of the die in question using its
8800 DW_AT_containing_type attribute. */
8802 static struct type
*
8803 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8805 struct type
*type
= NULL
;
8806 struct attribute
*type_attr
;
8807 struct die_info
*type_die
= NULL
;
8809 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8812 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8813 type
= tag_type_to_type (type_die
, cu
);
8818 dump_die_for_error (type_die
);
8819 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8825 static struct type
*
8826 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8828 struct type
*this_type
;
8830 this_type
= read_type_die (die
, cu
);
8833 dump_die_for_error (die
);
8834 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8840 static struct type
*
8841 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8843 struct type
*this_type
;
8845 this_type
= get_die_type (die
, cu
);
8851 case DW_TAG_class_type
:
8852 case DW_TAG_interface_type
:
8853 case DW_TAG_structure_type
:
8854 case DW_TAG_union_type
:
8855 this_type
= read_structure_type (die
, cu
);
8857 case DW_TAG_enumeration_type
:
8858 this_type
= read_enumeration_type (die
, cu
);
8860 case DW_TAG_subprogram
:
8861 case DW_TAG_subroutine_type
:
8862 case DW_TAG_inlined_subroutine
:
8863 this_type
= read_subroutine_type (die
, cu
);
8865 case DW_TAG_array_type
:
8866 this_type
= read_array_type (die
, cu
);
8868 case DW_TAG_set_type
:
8869 this_type
= read_set_type (die
, cu
);
8871 case DW_TAG_pointer_type
:
8872 this_type
= read_tag_pointer_type (die
, cu
);
8874 case DW_TAG_ptr_to_member_type
:
8875 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8877 case DW_TAG_reference_type
:
8878 this_type
= read_tag_reference_type (die
, cu
);
8880 case DW_TAG_const_type
:
8881 this_type
= read_tag_const_type (die
, cu
);
8883 case DW_TAG_volatile_type
:
8884 this_type
= read_tag_volatile_type (die
, cu
);
8886 case DW_TAG_string_type
:
8887 this_type
= read_tag_string_type (die
, cu
);
8889 case DW_TAG_typedef
:
8890 this_type
= read_typedef (die
, cu
);
8892 case DW_TAG_subrange_type
:
8893 this_type
= read_subrange_type (die
, cu
);
8895 case DW_TAG_base_type
:
8896 this_type
= read_base_type (die
, cu
);
8898 case DW_TAG_unspecified_type
:
8899 this_type
= read_unspecified_type (die
, cu
);
8901 case DW_TAG_namespace
:
8902 this_type
= read_namespace_type (die
, cu
);
8905 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8906 dwarf_tag_name (die
->tag
));
8913 /* Return the name of the namespace/class that DIE is defined within,
8914 or "" if we can't tell. The caller should not xfree the result.
8916 For example, if we're within the method foo() in the following
8926 then determine_prefix on foo's die will return "N::C". */
8929 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8931 struct die_info
*parent
, *spec_die
;
8932 struct dwarf2_cu
*spec_cu
;
8933 struct type
*parent_type
;
8935 if (cu
->language
!= language_cplus
8936 && cu
->language
!= language_java
)
8939 /* We have to be careful in the presence of DW_AT_specification.
8940 For example, with GCC 3.4, given the code
8944 // Definition of N::foo.
8948 then we'll have a tree of DIEs like this:
8950 1: DW_TAG_compile_unit
8951 2: DW_TAG_namespace // N
8952 3: DW_TAG_subprogram // declaration of N::foo
8953 4: DW_TAG_subprogram // definition of N::foo
8954 DW_AT_specification // refers to die #3
8956 Thus, when processing die #4, we have to pretend that we're in
8957 the context of its DW_AT_specification, namely the contex of die
8960 spec_die
= die_specification (die
, &spec_cu
);
8961 if (spec_die
== NULL
)
8962 parent
= die
->parent
;
8965 parent
= spec_die
->parent
;
8972 switch (parent
->tag
)
8974 case DW_TAG_namespace
:
8975 parent_type
= read_type_die (parent
, cu
);
8976 /* We give a name to even anonymous namespaces. */
8977 return TYPE_TAG_NAME (parent_type
);
8978 case DW_TAG_class_type
:
8979 case DW_TAG_interface_type
:
8980 case DW_TAG_structure_type
:
8981 case DW_TAG_union_type
:
8982 parent_type
= read_type_die (parent
, cu
);
8983 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8984 return TYPE_TAG_NAME (parent_type
);
8986 /* An anonymous structure is only allowed non-static data
8987 members; no typedefs, no member functions, et cetera.
8988 So it does not need a prefix. */
8991 return determine_prefix (parent
, cu
);
8995 /* Return a newly-allocated string formed by concatenating PREFIX and
8996 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8997 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8998 perform an obconcat, otherwise allocate storage for the result. The CU argument
8999 is used to determine the language and hence, the appropriate separator. */
9001 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9004 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9005 struct dwarf2_cu
*cu
)
9009 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9011 else if (cu
->language
== language_java
)
9023 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9024 strcpy (retval
, prefix
);
9025 strcat (retval
, sep
);
9026 strcat (retval
, suffix
);
9031 /* We have an obstack. */
9032 return obconcat (obs
, prefix
, sep
, suffix
);
9036 /* Return sibling of die, NULL if no sibling. */
9038 static struct die_info
*
9039 sibling_die (struct die_info
*die
)
9041 return die
->sibling
;
9044 /* Get name of a die, return NULL if not found. */
9047 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9048 struct obstack
*obstack
)
9050 if (name
&& cu
->language
== language_cplus
)
9052 char *canon_name
= cp_canonicalize_string (name
);
9054 if (canon_name
!= NULL
)
9056 if (strcmp (canon_name
, name
) != 0)
9057 name
= obsavestring (canon_name
, strlen (canon_name
),
9066 /* Get name of a die, return NULL if not found. */
9069 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9071 struct attribute
*attr
;
9073 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9074 if (!attr
|| !DW_STRING (attr
))
9079 case DW_TAG_compile_unit
:
9080 /* Compilation units have a DW_AT_name that is a filename, not
9081 a source language identifier. */
9082 case DW_TAG_enumeration_type
:
9083 case DW_TAG_enumerator
:
9084 /* These tags always have simple identifiers already; no need
9085 to canonicalize them. */
9086 return DW_STRING (attr
);
9088 if (!DW_STRING_IS_CANONICAL (attr
))
9091 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9092 &cu
->objfile
->objfile_obstack
);
9093 DW_STRING_IS_CANONICAL (attr
) = 1;
9095 return DW_STRING (attr
);
9099 /* Return the die that this die in an extension of, or NULL if there
9100 is none. *EXT_CU is the CU containing DIE on input, and the CU
9101 containing the return value on output. */
9103 static struct die_info
*
9104 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9106 struct attribute
*attr
;
9108 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9112 return follow_die_ref (die
, attr
, ext_cu
);
9115 /* Convert a DIE tag into its string name. */
9118 dwarf_tag_name (unsigned tag
)
9122 case DW_TAG_padding
:
9123 return "DW_TAG_padding";
9124 case DW_TAG_array_type
:
9125 return "DW_TAG_array_type";
9126 case DW_TAG_class_type
:
9127 return "DW_TAG_class_type";
9128 case DW_TAG_entry_point
:
9129 return "DW_TAG_entry_point";
9130 case DW_TAG_enumeration_type
:
9131 return "DW_TAG_enumeration_type";
9132 case DW_TAG_formal_parameter
:
9133 return "DW_TAG_formal_parameter";
9134 case DW_TAG_imported_declaration
:
9135 return "DW_TAG_imported_declaration";
9137 return "DW_TAG_label";
9138 case DW_TAG_lexical_block
:
9139 return "DW_TAG_lexical_block";
9141 return "DW_TAG_member";
9142 case DW_TAG_pointer_type
:
9143 return "DW_TAG_pointer_type";
9144 case DW_TAG_reference_type
:
9145 return "DW_TAG_reference_type";
9146 case DW_TAG_compile_unit
:
9147 return "DW_TAG_compile_unit";
9148 case DW_TAG_string_type
:
9149 return "DW_TAG_string_type";
9150 case DW_TAG_structure_type
:
9151 return "DW_TAG_structure_type";
9152 case DW_TAG_subroutine_type
:
9153 return "DW_TAG_subroutine_type";
9154 case DW_TAG_typedef
:
9155 return "DW_TAG_typedef";
9156 case DW_TAG_union_type
:
9157 return "DW_TAG_union_type";
9158 case DW_TAG_unspecified_parameters
:
9159 return "DW_TAG_unspecified_parameters";
9160 case DW_TAG_variant
:
9161 return "DW_TAG_variant";
9162 case DW_TAG_common_block
:
9163 return "DW_TAG_common_block";
9164 case DW_TAG_common_inclusion
:
9165 return "DW_TAG_common_inclusion";
9166 case DW_TAG_inheritance
:
9167 return "DW_TAG_inheritance";
9168 case DW_TAG_inlined_subroutine
:
9169 return "DW_TAG_inlined_subroutine";
9171 return "DW_TAG_module";
9172 case DW_TAG_ptr_to_member_type
:
9173 return "DW_TAG_ptr_to_member_type";
9174 case DW_TAG_set_type
:
9175 return "DW_TAG_set_type";
9176 case DW_TAG_subrange_type
:
9177 return "DW_TAG_subrange_type";
9178 case DW_TAG_with_stmt
:
9179 return "DW_TAG_with_stmt";
9180 case DW_TAG_access_declaration
:
9181 return "DW_TAG_access_declaration";
9182 case DW_TAG_base_type
:
9183 return "DW_TAG_base_type";
9184 case DW_TAG_catch_block
:
9185 return "DW_TAG_catch_block";
9186 case DW_TAG_const_type
:
9187 return "DW_TAG_const_type";
9188 case DW_TAG_constant
:
9189 return "DW_TAG_constant";
9190 case DW_TAG_enumerator
:
9191 return "DW_TAG_enumerator";
9192 case DW_TAG_file_type
:
9193 return "DW_TAG_file_type";
9195 return "DW_TAG_friend";
9196 case DW_TAG_namelist
:
9197 return "DW_TAG_namelist";
9198 case DW_TAG_namelist_item
:
9199 return "DW_TAG_namelist_item";
9200 case DW_TAG_packed_type
:
9201 return "DW_TAG_packed_type";
9202 case DW_TAG_subprogram
:
9203 return "DW_TAG_subprogram";
9204 case DW_TAG_template_type_param
:
9205 return "DW_TAG_template_type_param";
9206 case DW_TAG_template_value_param
:
9207 return "DW_TAG_template_value_param";
9208 case DW_TAG_thrown_type
:
9209 return "DW_TAG_thrown_type";
9210 case DW_TAG_try_block
:
9211 return "DW_TAG_try_block";
9212 case DW_TAG_variant_part
:
9213 return "DW_TAG_variant_part";
9214 case DW_TAG_variable
:
9215 return "DW_TAG_variable";
9216 case DW_TAG_volatile_type
:
9217 return "DW_TAG_volatile_type";
9218 case DW_TAG_dwarf_procedure
:
9219 return "DW_TAG_dwarf_procedure";
9220 case DW_TAG_restrict_type
:
9221 return "DW_TAG_restrict_type";
9222 case DW_TAG_interface_type
:
9223 return "DW_TAG_interface_type";
9224 case DW_TAG_namespace
:
9225 return "DW_TAG_namespace";
9226 case DW_TAG_imported_module
:
9227 return "DW_TAG_imported_module";
9228 case DW_TAG_unspecified_type
:
9229 return "DW_TAG_unspecified_type";
9230 case DW_TAG_partial_unit
:
9231 return "DW_TAG_partial_unit";
9232 case DW_TAG_imported_unit
:
9233 return "DW_TAG_imported_unit";
9234 case DW_TAG_condition
:
9235 return "DW_TAG_condition";
9236 case DW_TAG_shared_type
:
9237 return "DW_TAG_shared_type";
9238 case DW_TAG_type_unit
:
9239 return "DW_TAG_type_unit";
9240 case DW_TAG_MIPS_loop
:
9241 return "DW_TAG_MIPS_loop";
9242 case DW_TAG_HP_array_descriptor
:
9243 return "DW_TAG_HP_array_descriptor";
9244 case DW_TAG_format_label
:
9245 return "DW_TAG_format_label";
9246 case DW_TAG_function_template
:
9247 return "DW_TAG_function_template";
9248 case DW_TAG_class_template
:
9249 return "DW_TAG_class_template";
9250 case DW_TAG_GNU_BINCL
:
9251 return "DW_TAG_GNU_BINCL";
9252 case DW_TAG_GNU_EINCL
:
9253 return "DW_TAG_GNU_EINCL";
9254 case DW_TAG_upc_shared_type
:
9255 return "DW_TAG_upc_shared_type";
9256 case DW_TAG_upc_strict_type
:
9257 return "DW_TAG_upc_strict_type";
9258 case DW_TAG_upc_relaxed_type
:
9259 return "DW_TAG_upc_relaxed_type";
9260 case DW_TAG_PGI_kanji_type
:
9261 return "DW_TAG_PGI_kanji_type";
9262 case DW_TAG_PGI_interface_block
:
9263 return "DW_TAG_PGI_interface_block";
9265 return "DW_TAG_<unknown>";
9269 /* Convert a DWARF attribute code into its string name. */
9272 dwarf_attr_name (unsigned attr
)
9277 return "DW_AT_sibling";
9278 case DW_AT_location
:
9279 return "DW_AT_location";
9281 return "DW_AT_name";
9282 case DW_AT_ordering
:
9283 return "DW_AT_ordering";
9284 case DW_AT_subscr_data
:
9285 return "DW_AT_subscr_data";
9286 case DW_AT_byte_size
:
9287 return "DW_AT_byte_size";
9288 case DW_AT_bit_offset
:
9289 return "DW_AT_bit_offset";
9290 case DW_AT_bit_size
:
9291 return "DW_AT_bit_size";
9292 case DW_AT_element_list
:
9293 return "DW_AT_element_list";
9294 case DW_AT_stmt_list
:
9295 return "DW_AT_stmt_list";
9297 return "DW_AT_low_pc";
9299 return "DW_AT_high_pc";
9300 case DW_AT_language
:
9301 return "DW_AT_language";
9303 return "DW_AT_member";
9305 return "DW_AT_discr";
9306 case DW_AT_discr_value
:
9307 return "DW_AT_discr_value";
9308 case DW_AT_visibility
:
9309 return "DW_AT_visibility";
9311 return "DW_AT_import";
9312 case DW_AT_string_length
:
9313 return "DW_AT_string_length";
9314 case DW_AT_common_reference
:
9315 return "DW_AT_common_reference";
9316 case DW_AT_comp_dir
:
9317 return "DW_AT_comp_dir";
9318 case DW_AT_const_value
:
9319 return "DW_AT_const_value";
9320 case DW_AT_containing_type
:
9321 return "DW_AT_containing_type";
9322 case DW_AT_default_value
:
9323 return "DW_AT_default_value";
9325 return "DW_AT_inline";
9326 case DW_AT_is_optional
:
9327 return "DW_AT_is_optional";
9328 case DW_AT_lower_bound
:
9329 return "DW_AT_lower_bound";
9330 case DW_AT_producer
:
9331 return "DW_AT_producer";
9332 case DW_AT_prototyped
:
9333 return "DW_AT_prototyped";
9334 case DW_AT_return_addr
:
9335 return "DW_AT_return_addr";
9336 case DW_AT_start_scope
:
9337 return "DW_AT_start_scope";
9338 case DW_AT_bit_stride
:
9339 return "DW_AT_bit_stride";
9340 case DW_AT_upper_bound
:
9341 return "DW_AT_upper_bound";
9342 case DW_AT_abstract_origin
:
9343 return "DW_AT_abstract_origin";
9344 case DW_AT_accessibility
:
9345 return "DW_AT_accessibility";
9346 case DW_AT_address_class
:
9347 return "DW_AT_address_class";
9348 case DW_AT_artificial
:
9349 return "DW_AT_artificial";
9350 case DW_AT_base_types
:
9351 return "DW_AT_base_types";
9352 case DW_AT_calling_convention
:
9353 return "DW_AT_calling_convention";
9355 return "DW_AT_count";
9356 case DW_AT_data_member_location
:
9357 return "DW_AT_data_member_location";
9358 case DW_AT_decl_column
:
9359 return "DW_AT_decl_column";
9360 case DW_AT_decl_file
:
9361 return "DW_AT_decl_file";
9362 case DW_AT_decl_line
:
9363 return "DW_AT_decl_line";
9364 case DW_AT_declaration
:
9365 return "DW_AT_declaration";
9366 case DW_AT_discr_list
:
9367 return "DW_AT_discr_list";
9368 case DW_AT_encoding
:
9369 return "DW_AT_encoding";
9370 case DW_AT_external
:
9371 return "DW_AT_external";
9372 case DW_AT_frame_base
:
9373 return "DW_AT_frame_base";
9375 return "DW_AT_friend";
9376 case DW_AT_identifier_case
:
9377 return "DW_AT_identifier_case";
9378 case DW_AT_macro_info
:
9379 return "DW_AT_macro_info";
9380 case DW_AT_namelist_items
:
9381 return "DW_AT_namelist_items";
9382 case DW_AT_priority
:
9383 return "DW_AT_priority";
9385 return "DW_AT_segment";
9386 case DW_AT_specification
:
9387 return "DW_AT_specification";
9388 case DW_AT_static_link
:
9389 return "DW_AT_static_link";
9391 return "DW_AT_type";
9392 case DW_AT_use_location
:
9393 return "DW_AT_use_location";
9394 case DW_AT_variable_parameter
:
9395 return "DW_AT_variable_parameter";
9396 case DW_AT_virtuality
:
9397 return "DW_AT_virtuality";
9398 case DW_AT_vtable_elem_location
:
9399 return "DW_AT_vtable_elem_location";
9400 /* DWARF 3 values. */
9401 case DW_AT_allocated
:
9402 return "DW_AT_allocated";
9403 case DW_AT_associated
:
9404 return "DW_AT_associated";
9405 case DW_AT_data_location
:
9406 return "DW_AT_data_location";
9407 case DW_AT_byte_stride
:
9408 return "DW_AT_byte_stride";
9409 case DW_AT_entry_pc
:
9410 return "DW_AT_entry_pc";
9411 case DW_AT_use_UTF8
:
9412 return "DW_AT_use_UTF8";
9413 case DW_AT_extension
:
9414 return "DW_AT_extension";
9416 return "DW_AT_ranges";
9417 case DW_AT_trampoline
:
9418 return "DW_AT_trampoline";
9419 case DW_AT_call_column
:
9420 return "DW_AT_call_column";
9421 case DW_AT_call_file
:
9422 return "DW_AT_call_file";
9423 case DW_AT_call_line
:
9424 return "DW_AT_call_line";
9425 case DW_AT_description
:
9426 return "DW_AT_description";
9427 case DW_AT_binary_scale
:
9428 return "DW_AT_binary_scale";
9429 case DW_AT_decimal_scale
:
9430 return "DW_AT_decimal_scale";
9432 return "DW_AT_small";
9433 case DW_AT_decimal_sign
:
9434 return "DW_AT_decimal_sign";
9435 case DW_AT_digit_count
:
9436 return "DW_AT_digit_count";
9437 case DW_AT_picture_string
:
9438 return "DW_AT_picture_string";
9440 return "DW_AT_mutable";
9441 case DW_AT_threads_scaled
:
9442 return "DW_AT_threads_scaled";
9443 case DW_AT_explicit
:
9444 return "DW_AT_explicit";
9445 case DW_AT_object_pointer
:
9446 return "DW_AT_object_pointer";
9447 case DW_AT_endianity
:
9448 return "DW_AT_endianity";
9449 case DW_AT_elemental
:
9450 return "DW_AT_elemental";
9452 return "DW_AT_pure";
9453 case DW_AT_recursive
:
9454 return "DW_AT_recursive";
9455 /* DWARF 4 values. */
9456 case DW_AT_signature
:
9457 return "DW_AT_signature";
9458 /* SGI/MIPS extensions. */
9459 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9460 case DW_AT_MIPS_fde
:
9461 return "DW_AT_MIPS_fde";
9463 case DW_AT_MIPS_loop_begin
:
9464 return "DW_AT_MIPS_loop_begin";
9465 case DW_AT_MIPS_tail_loop_begin
:
9466 return "DW_AT_MIPS_tail_loop_begin";
9467 case DW_AT_MIPS_epilog_begin
:
9468 return "DW_AT_MIPS_epilog_begin";
9469 case DW_AT_MIPS_loop_unroll_factor
:
9470 return "DW_AT_MIPS_loop_unroll_factor";
9471 case DW_AT_MIPS_software_pipeline_depth
:
9472 return "DW_AT_MIPS_software_pipeline_depth";
9473 case DW_AT_MIPS_linkage_name
:
9474 return "DW_AT_MIPS_linkage_name";
9475 case DW_AT_MIPS_stride
:
9476 return "DW_AT_MIPS_stride";
9477 case DW_AT_MIPS_abstract_name
:
9478 return "DW_AT_MIPS_abstract_name";
9479 case DW_AT_MIPS_clone_origin
:
9480 return "DW_AT_MIPS_clone_origin";
9481 case DW_AT_MIPS_has_inlines
:
9482 return "DW_AT_MIPS_has_inlines";
9483 /* HP extensions. */
9484 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9485 case DW_AT_HP_block_index
:
9486 return "DW_AT_HP_block_index";
9488 case DW_AT_HP_unmodifiable
:
9489 return "DW_AT_HP_unmodifiable";
9490 case DW_AT_HP_actuals_stmt_list
:
9491 return "DW_AT_HP_actuals_stmt_list";
9492 case DW_AT_HP_proc_per_section
:
9493 return "DW_AT_HP_proc_per_section";
9494 case DW_AT_HP_raw_data_ptr
:
9495 return "DW_AT_HP_raw_data_ptr";
9496 case DW_AT_HP_pass_by_reference
:
9497 return "DW_AT_HP_pass_by_reference";
9498 case DW_AT_HP_opt_level
:
9499 return "DW_AT_HP_opt_level";
9500 case DW_AT_HP_prof_version_id
:
9501 return "DW_AT_HP_prof_version_id";
9502 case DW_AT_HP_opt_flags
:
9503 return "DW_AT_HP_opt_flags";
9504 case DW_AT_HP_cold_region_low_pc
:
9505 return "DW_AT_HP_cold_region_low_pc";
9506 case DW_AT_HP_cold_region_high_pc
:
9507 return "DW_AT_HP_cold_region_high_pc";
9508 case DW_AT_HP_all_variables_modifiable
:
9509 return "DW_AT_HP_all_variables_modifiable";
9510 case DW_AT_HP_linkage_name
:
9511 return "DW_AT_HP_linkage_name";
9512 case DW_AT_HP_prof_flags
:
9513 return "DW_AT_HP_prof_flags";
9514 /* GNU extensions. */
9515 case DW_AT_sf_names
:
9516 return "DW_AT_sf_names";
9517 case DW_AT_src_info
:
9518 return "DW_AT_src_info";
9519 case DW_AT_mac_info
:
9520 return "DW_AT_mac_info";
9521 case DW_AT_src_coords
:
9522 return "DW_AT_src_coords";
9523 case DW_AT_body_begin
:
9524 return "DW_AT_body_begin";
9525 case DW_AT_body_end
:
9526 return "DW_AT_body_end";
9527 case DW_AT_GNU_vector
:
9528 return "DW_AT_GNU_vector";
9529 /* VMS extensions. */
9530 case DW_AT_VMS_rtnbeg_pd_address
:
9531 return "DW_AT_VMS_rtnbeg_pd_address";
9532 /* UPC extension. */
9533 case DW_AT_upc_threads_scaled
:
9534 return "DW_AT_upc_threads_scaled";
9535 /* PGI (STMicroelectronics) extensions. */
9536 case DW_AT_PGI_lbase
:
9537 return "DW_AT_PGI_lbase";
9538 case DW_AT_PGI_soffset
:
9539 return "DW_AT_PGI_soffset";
9540 case DW_AT_PGI_lstride
:
9541 return "DW_AT_PGI_lstride";
9543 return "DW_AT_<unknown>";
9547 /* Convert a DWARF value form code into its string name. */
9550 dwarf_form_name (unsigned form
)
9555 return "DW_FORM_addr";
9556 case DW_FORM_block2
:
9557 return "DW_FORM_block2";
9558 case DW_FORM_block4
:
9559 return "DW_FORM_block4";
9561 return "DW_FORM_data2";
9563 return "DW_FORM_data4";
9565 return "DW_FORM_data8";
9566 case DW_FORM_string
:
9567 return "DW_FORM_string";
9569 return "DW_FORM_block";
9570 case DW_FORM_block1
:
9571 return "DW_FORM_block1";
9573 return "DW_FORM_data1";
9575 return "DW_FORM_flag";
9577 return "DW_FORM_sdata";
9579 return "DW_FORM_strp";
9581 return "DW_FORM_udata";
9582 case DW_FORM_ref_addr
:
9583 return "DW_FORM_ref_addr";
9585 return "DW_FORM_ref1";
9587 return "DW_FORM_ref2";
9589 return "DW_FORM_ref4";
9591 return "DW_FORM_ref8";
9592 case DW_FORM_ref_udata
:
9593 return "DW_FORM_ref_udata";
9594 case DW_FORM_indirect
:
9595 return "DW_FORM_indirect";
9596 case DW_FORM_sec_offset
:
9597 return "DW_FORM_sec_offset";
9598 case DW_FORM_exprloc
:
9599 return "DW_FORM_exprloc";
9600 case DW_FORM_flag_present
:
9601 return "DW_FORM_flag_present";
9603 return "DW_FORM_sig8";
9605 return "DW_FORM_<unknown>";
9609 /* Convert a DWARF stack opcode into its string name. */
9612 dwarf_stack_op_name (unsigned op
)
9617 return "DW_OP_addr";
9619 return "DW_OP_deref";
9621 return "DW_OP_const1u";
9623 return "DW_OP_const1s";
9625 return "DW_OP_const2u";
9627 return "DW_OP_const2s";
9629 return "DW_OP_const4u";
9631 return "DW_OP_const4s";
9633 return "DW_OP_const8u";
9635 return "DW_OP_const8s";
9637 return "DW_OP_constu";
9639 return "DW_OP_consts";
9643 return "DW_OP_drop";
9645 return "DW_OP_over";
9647 return "DW_OP_pick";
9649 return "DW_OP_swap";
9653 return "DW_OP_xderef";
9661 return "DW_OP_minus";
9673 return "DW_OP_plus";
9674 case DW_OP_plus_uconst
:
9675 return "DW_OP_plus_uconst";
9681 return "DW_OP_shra";
9699 return "DW_OP_skip";
9701 return "DW_OP_lit0";
9703 return "DW_OP_lit1";
9705 return "DW_OP_lit2";
9707 return "DW_OP_lit3";
9709 return "DW_OP_lit4";
9711 return "DW_OP_lit5";
9713 return "DW_OP_lit6";
9715 return "DW_OP_lit7";
9717 return "DW_OP_lit8";
9719 return "DW_OP_lit9";
9721 return "DW_OP_lit10";
9723 return "DW_OP_lit11";
9725 return "DW_OP_lit12";
9727 return "DW_OP_lit13";
9729 return "DW_OP_lit14";
9731 return "DW_OP_lit15";
9733 return "DW_OP_lit16";
9735 return "DW_OP_lit17";
9737 return "DW_OP_lit18";
9739 return "DW_OP_lit19";
9741 return "DW_OP_lit20";
9743 return "DW_OP_lit21";
9745 return "DW_OP_lit22";
9747 return "DW_OP_lit23";
9749 return "DW_OP_lit24";
9751 return "DW_OP_lit25";
9753 return "DW_OP_lit26";
9755 return "DW_OP_lit27";
9757 return "DW_OP_lit28";
9759 return "DW_OP_lit29";
9761 return "DW_OP_lit30";
9763 return "DW_OP_lit31";
9765 return "DW_OP_reg0";
9767 return "DW_OP_reg1";
9769 return "DW_OP_reg2";
9771 return "DW_OP_reg3";
9773 return "DW_OP_reg4";
9775 return "DW_OP_reg5";
9777 return "DW_OP_reg6";
9779 return "DW_OP_reg7";
9781 return "DW_OP_reg8";
9783 return "DW_OP_reg9";
9785 return "DW_OP_reg10";
9787 return "DW_OP_reg11";
9789 return "DW_OP_reg12";
9791 return "DW_OP_reg13";
9793 return "DW_OP_reg14";
9795 return "DW_OP_reg15";
9797 return "DW_OP_reg16";
9799 return "DW_OP_reg17";
9801 return "DW_OP_reg18";
9803 return "DW_OP_reg19";
9805 return "DW_OP_reg20";
9807 return "DW_OP_reg21";
9809 return "DW_OP_reg22";
9811 return "DW_OP_reg23";
9813 return "DW_OP_reg24";
9815 return "DW_OP_reg25";
9817 return "DW_OP_reg26";
9819 return "DW_OP_reg27";
9821 return "DW_OP_reg28";
9823 return "DW_OP_reg29";
9825 return "DW_OP_reg30";
9827 return "DW_OP_reg31";
9829 return "DW_OP_breg0";
9831 return "DW_OP_breg1";
9833 return "DW_OP_breg2";
9835 return "DW_OP_breg3";
9837 return "DW_OP_breg4";
9839 return "DW_OP_breg5";
9841 return "DW_OP_breg6";
9843 return "DW_OP_breg7";
9845 return "DW_OP_breg8";
9847 return "DW_OP_breg9";
9849 return "DW_OP_breg10";
9851 return "DW_OP_breg11";
9853 return "DW_OP_breg12";
9855 return "DW_OP_breg13";
9857 return "DW_OP_breg14";
9859 return "DW_OP_breg15";
9861 return "DW_OP_breg16";
9863 return "DW_OP_breg17";
9865 return "DW_OP_breg18";
9867 return "DW_OP_breg19";
9869 return "DW_OP_breg20";
9871 return "DW_OP_breg21";
9873 return "DW_OP_breg22";
9875 return "DW_OP_breg23";
9877 return "DW_OP_breg24";
9879 return "DW_OP_breg25";
9881 return "DW_OP_breg26";
9883 return "DW_OP_breg27";
9885 return "DW_OP_breg28";
9887 return "DW_OP_breg29";
9889 return "DW_OP_breg30";
9891 return "DW_OP_breg31";
9893 return "DW_OP_regx";
9895 return "DW_OP_fbreg";
9897 return "DW_OP_bregx";
9899 return "DW_OP_piece";
9900 case DW_OP_deref_size
:
9901 return "DW_OP_deref_size";
9902 case DW_OP_xderef_size
:
9903 return "DW_OP_xderef_size";
9906 /* DWARF 3 extensions. */
9907 case DW_OP_push_object_address
:
9908 return "DW_OP_push_object_address";
9910 return "DW_OP_call2";
9912 return "DW_OP_call4";
9913 case DW_OP_call_ref
:
9914 return "DW_OP_call_ref";
9915 /* GNU extensions. */
9916 case DW_OP_form_tls_address
:
9917 return "DW_OP_form_tls_address";
9918 case DW_OP_call_frame_cfa
:
9919 return "DW_OP_call_frame_cfa";
9920 case DW_OP_bit_piece
:
9921 return "DW_OP_bit_piece";
9922 case DW_OP_GNU_push_tls_address
:
9923 return "DW_OP_GNU_push_tls_address";
9924 case DW_OP_GNU_uninit
:
9925 return "DW_OP_GNU_uninit";
9926 /* HP extensions. */
9927 case DW_OP_HP_is_value
:
9928 return "DW_OP_HP_is_value";
9929 case DW_OP_HP_fltconst4
:
9930 return "DW_OP_HP_fltconst4";
9931 case DW_OP_HP_fltconst8
:
9932 return "DW_OP_HP_fltconst8";
9933 case DW_OP_HP_mod_range
:
9934 return "DW_OP_HP_mod_range";
9935 case DW_OP_HP_unmod_range
:
9936 return "DW_OP_HP_unmod_range";
9938 return "DW_OP_HP_tls";
9940 return "OP_<unknown>";
9945 dwarf_bool_name (unsigned mybool
)
9953 /* Convert a DWARF type code into its string name. */
9956 dwarf_type_encoding_name (unsigned enc
)
9961 return "DW_ATE_void";
9962 case DW_ATE_address
:
9963 return "DW_ATE_address";
9964 case DW_ATE_boolean
:
9965 return "DW_ATE_boolean";
9966 case DW_ATE_complex_float
:
9967 return "DW_ATE_complex_float";
9969 return "DW_ATE_float";
9971 return "DW_ATE_signed";
9972 case DW_ATE_signed_char
:
9973 return "DW_ATE_signed_char";
9974 case DW_ATE_unsigned
:
9975 return "DW_ATE_unsigned";
9976 case DW_ATE_unsigned_char
:
9977 return "DW_ATE_unsigned_char";
9979 case DW_ATE_imaginary_float
:
9980 return "DW_ATE_imaginary_float";
9981 case DW_ATE_packed_decimal
:
9982 return "DW_ATE_packed_decimal";
9983 case DW_ATE_numeric_string
:
9984 return "DW_ATE_numeric_string";
9986 return "DW_ATE_edited";
9987 case DW_ATE_signed_fixed
:
9988 return "DW_ATE_signed_fixed";
9989 case DW_ATE_unsigned_fixed
:
9990 return "DW_ATE_unsigned_fixed";
9991 case DW_ATE_decimal_float
:
9992 return "DW_ATE_decimal_float";
9993 /* HP extensions. */
9994 case DW_ATE_HP_float80
:
9995 return "DW_ATE_HP_float80";
9996 case DW_ATE_HP_complex_float80
:
9997 return "DW_ATE_HP_complex_float80";
9998 case DW_ATE_HP_float128
:
9999 return "DW_ATE_HP_float128";
10000 case DW_ATE_HP_complex_float128
:
10001 return "DW_ATE_HP_complex_float128";
10002 case DW_ATE_HP_floathpintel
:
10003 return "DW_ATE_HP_floathpintel";
10004 case DW_ATE_HP_imaginary_float80
:
10005 return "DW_ATE_HP_imaginary_float80";
10006 case DW_ATE_HP_imaginary_float128
:
10007 return "DW_ATE_HP_imaginary_float128";
10009 return "DW_ATE_<unknown>";
10013 /* Convert a DWARF call frame info operation to its string name. */
10017 dwarf_cfi_name (unsigned cfi_opc
)
10021 case DW_CFA_advance_loc
:
10022 return "DW_CFA_advance_loc";
10023 case DW_CFA_offset
:
10024 return "DW_CFA_offset";
10025 case DW_CFA_restore
:
10026 return "DW_CFA_restore";
10028 return "DW_CFA_nop";
10029 case DW_CFA_set_loc
:
10030 return "DW_CFA_set_loc";
10031 case DW_CFA_advance_loc1
:
10032 return "DW_CFA_advance_loc1";
10033 case DW_CFA_advance_loc2
:
10034 return "DW_CFA_advance_loc2";
10035 case DW_CFA_advance_loc4
:
10036 return "DW_CFA_advance_loc4";
10037 case DW_CFA_offset_extended
:
10038 return "DW_CFA_offset_extended";
10039 case DW_CFA_restore_extended
:
10040 return "DW_CFA_restore_extended";
10041 case DW_CFA_undefined
:
10042 return "DW_CFA_undefined";
10043 case DW_CFA_same_value
:
10044 return "DW_CFA_same_value";
10045 case DW_CFA_register
:
10046 return "DW_CFA_register";
10047 case DW_CFA_remember_state
:
10048 return "DW_CFA_remember_state";
10049 case DW_CFA_restore_state
:
10050 return "DW_CFA_restore_state";
10051 case DW_CFA_def_cfa
:
10052 return "DW_CFA_def_cfa";
10053 case DW_CFA_def_cfa_register
:
10054 return "DW_CFA_def_cfa_register";
10055 case DW_CFA_def_cfa_offset
:
10056 return "DW_CFA_def_cfa_offset";
10058 case DW_CFA_def_cfa_expression
:
10059 return "DW_CFA_def_cfa_expression";
10060 case DW_CFA_expression
:
10061 return "DW_CFA_expression";
10062 case DW_CFA_offset_extended_sf
:
10063 return "DW_CFA_offset_extended_sf";
10064 case DW_CFA_def_cfa_sf
:
10065 return "DW_CFA_def_cfa_sf";
10066 case DW_CFA_def_cfa_offset_sf
:
10067 return "DW_CFA_def_cfa_offset_sf";
10068 case DW_CFA_val_offset
:
10069 return "DW_CFA_val_offset";
10070 case DW_CFA_val_offset_sf
:
10071 return "DW_CFA_val_offset_sf";
10072 case DW_CFA_val_expression
:
10073 return "DW_CFA_val_expression";
10074 /* SGI/MIPS specific. */
10075 case DW_CFA_MIPS_advance_loc8
:
10076 return "DW_CFA_MIPS_advance_loc8";
10077 /* GNU extensions. */
10078 case DW_CFA_GNU_window_save
:
10079 return "DW_CFA_GNU_window_save";
10080 case DW_CFA_GNU_args_size
:
10081 return "DW_CFA_GNU_args_size";
10082 case DW_CFA_GNU_negative_offset_extended
:
10083 return "DW_CFA_GNU_negative_offset_extended";
10085 return "DW_CFA_<unknown>";
10091 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10095 print_spaces (indent
, f
);
10096 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10097 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10099 if (die
->parent
!= NULL
)
10101 print_spaces (indent
, f
);
10102 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10103 die
->parent
->offset
);
10106 print_spaces (indent
, f
);
10107 fprintf_unfiltered (f
, " has children: %s\n",
10108 dwarf_bool_name (die
->child
!= NULL
));
10110 print_spaces (indent
, f
);
10111 fprintf_unfiltered (f
, " attributes:\n");
10113 for (i
= 0; i
< die
->num_attrs
; ++i
)
10115 print_spaces (indent
, f
);
10116 fprintf_unfiltered (f
, " %s (%s) ",
10117 dwarf_attr_name (die
->attrs
[i
].name
),
10118 dwarf_form_name (die
->attrs
[i
].form
));
10120 switch (die
->attrs
[i
].form
)
10122 case DW_FORM_ref_addr
:
10124 fprintf_unfiltered (f
, "address: ");
10125 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10127 case DW_FORM_block2
:
10128 case DW_FORM_block4
:
10129 case DW_FORM_block
:
10130 case DW_FORM_block1
:
10131 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10136 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10137 (long) (DW_ADDR (&die
->attrs
[i
])));
10139 case DW_FORM_data1
:
10140 case DW_FORM_data2
:
10141 case DW_FORM_data4
:
10142 case DW_FORM_data8
:
10143 case DW_FORM_udata
:
10144 case DW_FORM_sdata
:
10145 fprintf_unfiltered (f
, "constant: %s",
10146 pulongest (DW_UNSND (&die
->attrs
[i
])));
10149 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10150 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10151 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10153 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10155 case DW_FORM_string
:
10157 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10158 DW_STRING (&die
->attrs
[i
])
10159 ? DW_STRING (&die
->attrs
[i
]) : "",
10160 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10163 if (DW_UNSND (&die
->attrs
[i
]))
10164 fprintf_unfiltered (f
, "flag: TRUE");
10166 fprintf_unfiltered (f
, "flag: FALSE");
10168 case DW_FORM_indirect
:
10169 /* the reader will have reduced the indirect form to
10170 the "base form" so this form should not occur */
10171 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10174 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10175 die
->attrs
[i
].form
);
10178 fprintf_unfiltered (f
, "\n");
10183 dump_die_for_error (struct die_info
*die
)
10185 dump_die_shallow (gdb_stderr
, 0, die
);
10189 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10191 int indent
= level
* 4;
10193 gdb_assert (die
!= NULL
);
10195 if (level
>= max_level
)
10198 dump_die_shallow (f
, indent
, die
);
10200 if (die
->child
!= NULL
)
10202 print_spaces (indent
, f
);
10203 fprintf_unfiltered (f
, " Children:");
10204 if (level
+ 1 < max_level
)
10206 fprintf_unfiltered (f
, "\n");
10207 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10211 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10215 if (die
->sibling
!= NULL
&& level
> 0)
10217 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10221 /* This is called from the pdie macro in gdbinit.in.
10222 It's not static so gcc will keep a copy callable from gdb. */
10225 dump_die (struct die_info
*die
, int max_level
)
10227 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10231 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10235 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10241 is_ref_attr (struct attribute
*attr
)
10243 switch (attr
->form
)
10245 case DW_FORM_ref_addr
:
10250 case DW_FORM_ref_udata
:
10257 static unsigned int
10258 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10260 if (is_ref_attr (attr
))
10261 return DW_ADDR (attr
);
10263 complaint (&symfile_complaints
,
10264 _("unsupported die ref attribute form: '%s'"),
10265 dwarf_form_name (attr
->form
));
10269 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10270 * the value held by the attribute is not constant. */
10273 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10275 if (attr
->form
== DW_FORM_sdata
)
10276 return DW_SND (attr
);
10277 else if (attr
->form
== DW_FORM_udata
10278 || attr
->form
== DW_FORM_data1
10279 || attr
->form
== DW_FORM_data2
10280 || attr
->form
== DW_FORM_data4
10281 || attr
->form
== DW_FORM_data8
)
10282 return DW_UNSND (attr
);
10285 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10286 dwarf_form_name (attr
->form
));
10287 return default_value
;
10291 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10292 unit and add it to our queue.
10293 The result is non-zero if PER_CU was queued, otherwise the result is zero
10294 meaning either PER_CU is already queued or it is already loaded. */
10297 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10298 struct dwarf2_per_cu_data
*per_cu
)
10300 /* Mark the dependence relation so that we don't flush PER_CU
10302 dwarf2_add_dependence (this_cu
, per_cu
);
10304 /* If it's already on the queue, we have nothing to do. */
10305 if (per_cu
->queued
)
10308 /* If the compilation unit is already loaded, just mark it as
10310 if (per_cu
->cu
!= NULL
)
10312 per_cu
->cu
->last_used
= 0;
10316 /* Add it to the queue. */
10317 queue_comp_unit (per_cu
, this_cu
->objfile
);
10322 /* Follow reference or signature attribute ATTR of SRC_DIE.
10323 On entry *REF_CU is the CU of SRC_DIE.
10324 On exit *REF_CU is the CU of the result. */
10326 static struct die_info
*
10327 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10328 struct dwarf2_cu
**ref_cu
)
10330 struct die_info
*die
;
10332 if (is_ref_attr (attr
))
10333 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10334 else if (attr
->form
== DW_FORM_sig8
)
10335 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10338 dump_die_for_error (src_die
);
10339 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10340 (*ref_cu
)->objfile
->name
);
10346 /* Follow reference attribute ATTR of SRC_DIE.
10347 On entry *REF_CU is the CU of SRC_DIE.
10348 On exit *REF_CU is the CU of the result. */
10350 static struct die_info
*
10351 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10352 struct dwarf2_cu
**ref_cu
)
10354 struct die_info
*die
;
10355 unsigned int offset
;
10356 struct die_info temp_die
;
10357 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10359 gdb_assert (cu
->per_cu
!= NULL
);
10361 offset
= dwarf2_get_ref_die_offset (attr
);
10363 if (cu
->per_cu
->from_debug_types
)
10365 /* .debug_types CUs cannot reference anything outside their CU.
10366 If they need to, they have to reference a signatured type via
10368 if (! offset_in_cu_p (&cu
->header
, offset
))
10372 else if (! offset_in_cu_p (&cu
->header
, offset
))
10374 struct dwarf2_per_cu_data
*per_cu
;
10375 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10377 /* If necessary, add it to the queue and load its DIEs. */
10378 if (maybe_queue_comp_unit (cu
, per_cu
))
10379 load_full_comp_unit (per_cu
, cu
->objfile
);
10381 target_cu
= per_cu
->cu
;
10386 *ref_cu
= target_cu
;
10387 temp_die
.offset
= offset
;
10388 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10394 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10395 "at 0x%x [in module %s]"),
10396 offset
, src_die
->offset
, cu
->objfile
->name
);
10399 /* Follow the signature attribute ATTR in SRC_DIE.
10400 On entry *REF_CU is the CU of SRC_DIE.
10401 On exit *REF_CU is the CU of the result. */
10403 static struct die_info
*
10404 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10405 struct dwarf2_cu
**ref_cu
)
10407 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10408 struct die_info temp_die
;
10409 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10410 struct dwarf2_cu
*sig_cu
;
10411 struct die_info
*die
;
10413 /* sig_type will be NULL if the signatured type is missing from
10415 if (sig_type
== NULL
)
10416 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10417 "at 0x%x [in module %s]"),
10418 src_die
->offset
, objfile
->name
);
10420 /* If necessary, add it to the queue and load its DIEs. */
10422 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10423 read_signatured_type (objfile
, sig_type
);
10425 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10427 sig_cu
= sig_type
->per_cu
.cu
;
10428 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10429 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10436 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10437 "at 0x%x [in module %s]"),
10438 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10441 /* Given an offset of a signatured type, return its signatured_type. */
10443 static struct signatured_type
*
10444 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10446 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10447 unsigned int length
, initial_length_size
;
10448 unsigned int sig_offset
;
10449 struct signatured_type find_entry
, *type_sig
;
10451 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10452 sig_offset
= (initial_length_size
10454 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10455 + 1 /*address_size*/);
10456 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10457 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10459 /* This is only used to lookup previously recorded types.
10460 If we didn't find it, it's our bug. */
10461 gdb_assert (type_sig
!= NULL
);
10462 gdb_assert (offset
== type_sig
->offset
);
10467 /* Read in signatured type at OFFSET and build its CU and die(s). */
10470 read_signatured_type_at_offset (struct objfile
*objfile
,
10471 unsigned int offset
)
10473 struct signatured_type
*type_sig
;
10475 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
10477 /* We have the section offset, but we need the signature to do the
10478 hash table lookup. */
10479 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10481 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10483 read_signatured_type (objfile
, type_sig
);
10485 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10488 /* Read in a signatured type and build its CU and DIEs. */
10491 read_signatured_type (struct objfile
*objfile
,
10492 struct signatured_type
*type_sig
)
10494 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10495 struct die_reader_specs reader_specs
;
10496 struct dwarf2_cu
*cu
;
10497 ULONGEST signature
;
10498 struct cleanup
*back_to
, *free_cu_cleanup
;
10499 struct attribute
*attr
;
10501 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10503 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10504 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10505 obstack_init (&cu
->comp_unit_obstack
);
10506 cu
->objfile
= objfile
;
10507 type_sig
->per_cu
.cu
= cu
;
10508 cu
->per_cu
= &type_sig
->per_cu
;
10510 /* If an error occurs while loading, release our storage. */
10511 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10513 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10514 types_ptr
, objfile
->obfd
);
10515 gdb_assert (signature
== type_sig
->signature
);
10518 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10522 &cu
->comp_unit_obstack
,
10523 hashtab_obstack_allocate
,
10524 dummy_obstack_deallocate
);
10526 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10527 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10529 init_cu_die_reader (&reader_specs
, cu
);
10531 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10534 /* We try not to read any attributes in this function, because not
10535 all objfiles needed for references have been loaded yet, and symbol
10536 table processing isn't initialized. But we have to set the CU language,
10537 or we won't be able to build types correctly. */
10538 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10540 set_cu_language (DW_UNSND (attr
), cu
);
10542 set_cu_language (language_minimal
, cu
);
10544 do_cleanups (back_to
);
10546 /* We've successfully allocated this compilation unit. Let our caller
10547 clean it up when finished with it. */
10548 discard_cleanups (free_cu_cleanup
);
10550 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10551 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10554 /* Decode simple location descriptions.
10555 Given a pointer to a dwarf block that defines a location, compute
10556 the location and return the value.
10558 NOTE drow/2003-11-18: This function is called in two situations
10559 now: for the address of static or global variables (partial symbols
10560 only) and for offsets into structures which are expected to be
10561 (more or less) constant. The partial symbol case should go away,
10562 and only the constant case should remain. That will let this
10563 function complain more accurately. A few special modes are allowed
10564 without complaint for global variables (for instance, global
10565 register values and thread-local values).
10567 A location description containing no operations indicates that the
10568 object is optimized out. The return value is 0 for that case.
10569 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10570 callers will only want a very basic result and this can become a
10573 Note that stack[0] is unused except as a default error return.
10574 Note that stack overflow is not yet handled. */
10577 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10579 struct objfile
*objfile
= cu
->objfile
;
10580 struct comp_unit_head
*cu_header
= &cu
->header
;
10582 int size
= blk
->size
;
10583 gdb_byte
*data
= blk
->data
;
10584 CORE_ADDR stack
[64];
10586 unsigned int bytes_read
, unsnd
;
10630 stack
[++stacki
] = op
- DW_OP_lit0
;
10665 stack
[++stacki
] = op
- DW_OP_reg0
;
10667 dwarf2_complex_location_expr_complaint ();
10671 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10673 stack
[++stacki
] = unsnd
;
10675 dwarf2_complex_location_expr_complaint ();
10679 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
10684 case DW_OP_const1u
:
10685 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
10689 case DW_OP_const1s
:
10690 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
10694 case DW_OP_const2u
:
10695 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
10699 case DW_OP_const2s
:
10700 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
10704 case DW_OP_const4u
:
10705 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
10709 case DW_OP_const4s
:
10710 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
10715 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
10721 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
10726 stack
[stacki
+ 1] = stack
[stacki
];
10731 stack
[stacki
- 1] += stack
[stacki
];
10735 case DW_OP_plus_uconst
:
10736 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10741 stack
[stacki
- 1] -= stack
[stacki
];
10746 /* If we're not the last op, then we definitely can't encode
10747 this using GDB's address_class enum. This is valid for partial
10748 global symbols, although the variable's address will be bogus
10751 dwarf2_complex_location_expr_complaint ();
10754 case DW_OP_GNU_push_tls_address
:
10755 /* The top of the stack has the offset from the beginning
10756 of the thread control block at which the variable is located. */
10757 /* Nothing should follow this operator, so the top of stack would
10759 /* This is valid for partial global symbols, but the variable's
10760 address will be bogus in the psymtab. */
10762 dwarf2_complex_location_expr_complaint ();
10765 case DW_OP_GNU_uninit
:
10769 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
10770 dwarf_stack_op_name (op
));
10771 return (stack
[stacki
]);
10774 return (stack
[stacki
]);
10777 /* memory allocation interface */
10779 static struct dwarf_block
*
10780 dwarf_alloc_block (struct dwarf2_cu
*cu
)
10782 struct dwarf_block
*blk
;
10784 blk
= (struct dwarf_block
*)
10785 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
10789 static struct abbrev_info
*
10790 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
10792 struct abbrev_info
*abbrev
;
10794 abbrev
= (struct abbrev_info
*)
10795 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
10796 memset (abbrev
, 0, sizeof (struct abbrev_info
));
10800 static struct die_info
*
10801 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
10803 struct die_info
*die
;
10804 size_t size
= sizeof (struct die_info
);
10807 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
10809 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
10810 memset (die
, 0, sizeof (struct die_info
));
10815 /* Macro support. */
10818 /* Return the full name of file number I in *LH's file name table.
10819 Use COMP_DIR as the name of the current directory of the
10820 compilation. The result is allocated using xmalloc; the caller is
10821 responsible for freeing it. */
10823 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
10825 /* Is the file number a valid index into the line header's file name
10826 table? Remember that file numbers start with one, not zero. */
10827 if (1 <= file
&& file
<= lh
->num_file_names
)
10829 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10831 if (IS_ABSOLUTE_PATH (fe
->name
))
10832 return xstrdup (fe
->name
);
10840 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10846 dir_len
= strlen (dir
);
10847 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
10848 strcpy (full_name
, dir
);
10849 full_name
[dir_len
] = '/';
10850 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
10854 return xstrdup (fe
->name
);
10859 /* The compiler produced a bogus file number. We can at least
10860 record the macro definitions made in the file, even if we
10861 won't be able to find the file by name. */
10862 char fake_name
[80];
10863 sprintf (fake_name
, "<bad macro file number %d>", file
);
10865 complaint (&symfile_complaints
,
10866 _("bad file number in macro information (%d)"),
10869 return xstrdup (fake_name
);
10874 static struct macro_source_file
*
10875 macro_start_file (int file
, int line
,
10876 struct macro_source_file
*current_file
,
10877 const char *comp_dir
,
10878 struct line_header
*lh
, struct objfile
*objfile
)
10880 /* The full name of this source file. */
10881 char *full_name
= file_full_name (file
, lh
, comp_dir
);
10883 /* We don't create a macro table for this compilation unit
10884 at all until we actually get a filename. */
10885 if (! pending_macros
)
10886 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
10887 objfile
->macro_cache
);
10889 if (! current_file
)
10890 /* If we have no current file, then this must be the start_file
10891 directive for the compilation unit's main source file. */
10892 current_file
= macro_set_main (pending_macros
, full_name
);
10894 current_file
= macro_include (current_file
, line
, full_name
);
10898 return current_file
;
10902 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
10903 followed by a null byte. */
10905 copy_string (const char *buf
, int len
)
10907 char *s
= xmalloc (len
+ 1);
10908 memcpy (s
, buf
, len
);
10915 static const char *
10916 consume_improper_spaces (const char *p
, const char *body
)
10920 complaint (&symfile_complaints
,
10921 _("macro definition contains spaces in formal argument list:\n`%s'"),
10933 parse_macro_definition (struct macro_source_file
*file
, int line
,
10938 /* The body string takes one of two forms. For object-like macro
10939 definitions, it should be:
10941 <macro name> " " <definition>
10943 For function-like macro definitions, it should be:
10945 <macro name> "() " <definition>
10947 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
10949 Spaces may appear only where explicitly indicated, and in the
10952 The Dwarf 2 spec says that an object-like macro's name is always
10953 followed by a space, but versions of GCC around March 2002 omit
10954 the space when the macro's definition is the empty string.
10956 The Dwarf 2 spec says that there should be no spaces between the
10957 formal arguments in a function-like macro's formal argument list,
10958 but versions of GCC around March 2002 include spaces after the
10962 /* Find the extent of the macro name. The macro name is terminated
10963 by either a space or null character (for an object-like macro) or
10964 an opening paren (for a function-like macro). */
10965 for (p
= body
; *p
; p
++)
10966 if (*p
== ' ' || *p
== '(')
10969 if (*p
== ' ' || *p
== '\0')
10971 /* It's an object-like macro. */
10972 int name_len
= p
- body
;
10973 char *name
= copy_string (body
, name_len
);
10974 const char *replacement
;
10977 replacement
= body
+ name_len
+ 1;
10980 dwarf2_macro_malformed_definition_complaint (body
);
10981 replacement
= body
+ name_len
;
10984 macro_define_object (file
, line
, name
, replacement
);
10988 else if (*p
== '(')
10990 /* It's a function-like macro. */
10991 char *name
= copy_string (body
, p
- body
);
10994 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
10998 p
= consume_improper_spaces (p
, body
);
11000 /* Parse the formal argument list. */
11001 while (*p
&& *p
!= ')')
11003 /* Find the extent of the current argument name. */
11004 const char *arg_start
= p
;
11006 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11009 if (! *p
|| p
== arg_start
)
11010 dwarf2_macro_malformed_definition_complaint (body
);
11013 /* Make sure argv has room for the new argument. */
11014 if (argc
>= argv_size
)
11017 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11020 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11023 p
= consume_improper_spaces (p
, body
);
11025 /* Consume the comma, if present. */
11030 p
= consume_improper_spaces (p
, body
);
11039 /* Perfectly formed definition, no complaints. */
11040 macro_define_function (file
, line
, name
,
11041 argc
, (const char **) argv
,
11043 else if (*p
== '\0')
11045 /* Complain, but do define it. */
11046 dwarf2_macro_malformed_definition_complaint (body
);
11047 macro_define_function (file
, line
, name
,
11048 argc
, (const char **) argv
,
11052 /* Just complain. */
11053 dwarf2_macro_malformed_definition_complaint (body
);
11056 /* Just complain. */
11057 dwarf2_macro_malformed_definition_complaint (body
);
11063 for (i
= 0; i
< argc
; i
++)
11069 dwarf2_macro_malformed_definition_complaint (body
);
11074 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11075 char *comp_dir
, bfd
*abfd
,
11076 struct dwarf2_cu
*cu
)
11078 gdb_byte
*mac_ptr
, *mac_end
;
11079 struct macro_source_file
*current_file
= 0;
11080 enum dwarf_macinfo_record_type macinfo_type
;
11081 int at_commandline
;
11083 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11084 &dwarf2_per_objfile
->macinfo
);
11085 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11087 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11091 /* First pass: Find the name of the base filename.
11092 This filename is needed in order to process all macros whose definition
11093 (or undefinition) comes from the command line. These macros are defined
11094 before the first DW_MACINFO_start_file entry, and yet still need to be
11095 associated to the base file.
11097 To determine the base file name, we scan the macro definitions until we
11098 reach the first DW_MACINFO_start_file entry. We then initialize
11099 CURRENT_FILE accordingly so that any macro definition found before the
11100 first DW_MACINFO_start_file can still be associated to the base file. */
11102 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11103 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11104 + dwarf2_per_objfile
->macinfo
.size
;
11108 /* Do we at least have room for a macinfo type byte? */
11109 if (mac_ptr
>= mac_end
)
11111 /* Complaint is printed during the second pass as GDB will probably
11112 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11116 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11119 switch (macinfo_type
)
11121 /* A zero macinfo type indicates the end of the macro
11126 case DW_MACINFO_define
:
11127 case DW_MACINFO_undef
:
11128 /* Only skip the data by MAC_PTR. */
11130 unsigned int bytes_read
;
11132 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11133 mac_ptr
+= bytes_read
;
11134 read_string (abfd
, mac_ptr
, &bytes_read
);
11135 mac_ptr
+= bytes_read
;
11139 case DW_MACINFO_start_file
:
11141 unsigned int bytes_read
;
11144 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11145 mac_ptr
+= bytes_read
;
11146 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11147 mac_ptr
+= bytes_read
;
11149 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11154 case DW_MACINFO_end_file
:
11155 /* No data to skip by MAC_PTR. */
11158 case DW_MACINFO_vendor_ext
:
11159 /* Only skip the data by MAC_PTR. */
11161 unsigned int bytes_read
;
11163 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11164 mac_ptr
+= bytes_read
;
11165 read_string (abfd
, mac_ptr
, &bytes_read
);
11166 mac_ptr
+= bytes_read
;
11173 } while (macinfo_type
!= 0 && current_file
== NULL
);
11175 /* Second pass: Process all entries.
11177 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11178 command-line macro definitions/undefinitions. This flag is unset when we
11179 reach the first DW_MACINFO_start_file entry. */
11181 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11183 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11184 GDB is still reading the definitions from command line. First
11185 DW_MACINFO_start_file will need to be ignored as it was already executed
11186 to create CURRENT_FILE for the main source holding also the command line
11187 definitions. On first met DW_MACINFO_start_file this flag is reset to
11188 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11190 at_commandline
= 1;
11194 /* Do we at least have room for a macinfo type byte? */
11195 if (mac_ptr
>= mac_end
)
11197 dwarf2_macros_too_long_complaint ();
11201 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11204 switch (macinfo_type
)
11206 /* A zero macinfo type indicates the end of the macro
11211 case DW_MACINFO_define
:
11212 case DW_MACINFO_undef
:
11214 unsigned int bytes_read
;
11218 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11219 mac_ptr
+= bytes_read
;
11220 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11221 mac_ptr
+= bytes_read
;
11223 if (! current_file
)
11225 /* DWARF violation as no main source is present. */
11226 complaint (&symfile_complaints
,
11227 _("debug info with no main source gives macro %s "
11229 macinfo_type
== DW_MACINFO_define
?
11231 macinfo_type
== DW_MACINFO_undef
?
11232 _("undefinition") :
11233 _("something-or-other"), line
, body
);
11236 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11237 complaint (&symfile_complaints
,
11238 _("debug info gives %s macro %s with %s line %d: %s"),
11239 at_commandline
? _("command-line") : _("in-file"),
11240 macinfo_type
== DW_MACINFO_define
?
11242 macinfo_type
== DW_MACINFO_undef
?
11243 _("undefinition") :
11244 _("something-or-other"),
11245 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11247 if (macinfo_type
== DW_MACINFO_define
)
11248 parse_macro_definition (current_file
, line
, body
);
11249 else if (macinfo_type
== DW_MACINFO_undef
)
11250 macro_undef (current_file
, line
, body
);
11254 case DW_MACINFO_start_file
:
11256 unsigned int bytes_read
;
11259 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11260 mac_ptr
+= bytes_read
;
11261 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11262 mac_ptr
+= bytes_read
;
11264 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11265 complaint (&symfile_complaints
,
11266 _("debug info gives source %d included "
11267 "from %s at %s line %d"),
11268 file
, at_commandline
? _("command-line") : _("file"),
11269 line
== 0 ? _("zero") : _("non-zero"), line
);
11271 if (at_commandline
)
11273 /* This DW_MACINFO_start_file was executed in the pass one. */
11274 at_commandline
= 0;
11277 current_file
= macro_start_file (file
, line
,
11278 current_file
, comp_dir
,
11283 case DW_MACINFO_end_file
:
11284 if (! current_file
)
11285 complaint (&symfile_complaints
,
11286 _("macro debug info has an unmatched `close_file' directive"));
11289 current_file
= current_file
->included_by
;
11290 if (! current_file
)
11292 enum dwarf_macinfo_record_type next_type
;
11294 /* GCC circa March 2002 doesn't produce the zero
11295 type byte marking the end of the compilation
11296 unit. Complain if it's not there, but exit no
11299 /* Do we at least have room for a macinfo type byte? */
11300 if (mac_ptr
>= mac_end
)
11302 dwarf2_macros_too_long_complaint ();
11306 /* We don't increment mac_ptr here, so this is just
11308 next_type
= read_1_byte (abfd
, mac_ptr
);
11309 if (next_type
!= 0)
11310 complaint (&symfile_complaints
,
11311 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11318 case DW_MACINFO_vendor_ext
:
11320 unsigned int bytes_read
;
11324 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11325 mac_ptr
+= bytes_read
;
11326 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11327 mac_ptr
+= bytes_read
;
11329 /* We don't recognize any vendor extensions. */
11333 } while (macinfo_type
!= 0);
11336 /* Check if the attribute's form is a DW_FORM_block*
11337 if so return true else false. */
11339 attr_form_is_block (struct attribute
*attr
)
11341 return (attr
== NULL
? 0 :
11342 attr
->form
== DW_FORM_block1
11343 || attr
->form
== DW_FORM_block2
11344 || attr
->form
== DW_FORM_block4
11345 || attr
->form
== DW_FORM_block
);
11348 /* Return non-zero if ATTR's value is a section offset --- classes
11349 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11350 You may use DW_UNSND (attr) to retrieve such offsets.
11352 Section 7.5.4, "Attribute Encodings", explains that no attribute
11353 may have a value that belongs to more than one of these classes; it
11354 would be ambiguous if we did, because we use the same forms for all
11357 attr_form_is_section_offset (struct attribute
*attr
)
11359 return (attr
->form
== DW_FORM_data4
11360 || attr
->form
== DW_FORM_data8
);
11364 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11365 zero otherwise. When this function returns true, you can apply
11366 dwarf2_get_attr_constant_value to it.
11368 However, note that for some attributes you must check
11369 attr_form_is_section_offset before using this test. DW_FORM_data4
11370 and DW_FORM_data8 are members of both the constant class, and of
11371 the classes that contain offsets into other debug sections
11372 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11373 that, if an attribute's can be either a constant or one of the
11374 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11375 taken as section offsets, not constants. */
11377 attr_form_is_constant (struct attribute
*attr
)
11379 switch (attr
->form
)
11381 case DW_FORM_sdata
:
11382 case DW_FORM_udata
:
11383 case DW_FORM_data1
:
11384 case DW_FORM_data2
:
11385 case DW_FORM_data4
:
11386 case DW_FORM_data8
:
11394 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11395 struct dwarf2_cu
*cu
)
11397 if (attr_form_is_section_offset (attr
)
11398 /* ".debug_loc" may not exist at all, or the offset may be outside
11399 the section. If so, fall through to the complaint in the
11401 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11403 struct dwarf2_loclist_baton
*baton
;
11405 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11406 sizeof (struct dwarf2_loclist_baton
));
11407 baton
->per_cu
= cu
->per_cu
;
11408 gdb_assert (baton
->per_cu
);
11410 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11411 &dwarf2_per_objfile
->loc
);
11413 /* We don't know how long the location list is, but make sure we
11414 don't run off the edge of the section. */
11415 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11416 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11417 baton
->base_address
= cu
->base_address
;
11418 if (cu
->base_known
== 0)
11419 complaint (&symfile_complaints
,
11420 _("Location list used without specifying the CU base address."));
11422 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11423 SYMBOL_LOCATION_BATON (sym
) = baton
;
11427 struct dwarf2_locexpr_baton
*baton
;
11429 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11430 sizeof (struct dwarf2_locexpr_baton
));
11431 baton
->per_cu
= cu
->per_cu
;
11432 gdb_assert (baton
->per_cu
);
11434 if (attr_form_is_block (attr
))
11436 /* Note that we're just copying the block's data pointer
11437 here, not the actual data. We're still pointing into the
11438 info_buffer for SYM's objfile; right now we never release
11439 that buffer, but when we do clean up properly this may
11441 baton
->size
= DW_BLOCK (attr
)->size
;
11442 baton
->data
= DW_BLOCK (attr
)->data
;
11446 dwarf2_invalid_attrib_class_complaint ("location description",
11447 SYMBOL_NATURAL_NAME (sym
));
11449 baton
->data
= NULL
;
11452 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11453 SYMBOL_LOCATION_BATON (sym
) = baton
;
11457 /* Return the OBJFILE associated with the compilation unit CU. */
11460 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11462 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11464 /* Return the master objfile, so that we can report and look up the
11465 correct file containing this variable. */
11466 if (objfile
->separate_debug_objfile_backlink
)
11467 objfile
= objfile
->separate_debug_objfile_backlink
;
11472 /* Return the address size given in the compilation unit header for CU. */
11475 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11478 return per_cu
->cu
->header
.addr_size
;
11481 /* If the CU is not currently read in, we re-read its header. */
11482 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11483 struct dwarf2_per_objfile
*per_objfile
11484 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11485 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11487 struct comp_unit_head cu_header
;
11488 memset (&cu_header
, 0, sizeof cu_header
);
11489 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11490 return cu_header
.addr_size
;
11494 /* Locate the .debug_info compilation unit from CU's objfile which contains
11495 the DIE at OFFSET. Raises an error on failure. */
11497 static struct dwarf2_per_cu_data
*
11498 dwarf2_find_containing_comp_unit (unsigned int offset
,
11499 struct objfile
*objfile
)
11501 struct dwarf2_per_cu_data
*this_cu
;
11505 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11508 int mid
= low
+ (high
- low
) / 2;
11509 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11514 gdb_assert (low
== high
);
11515 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11518 error (_("Dwarf Error: could not find partial DIE containing "
11519 "offset 0x%lx [in module %s]"),
11520 (long) offset
, bfd_get_filename (objfile
->obfd
));
11522 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11523 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11527 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11528 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11529 && offset
>= this_cu
->offset
+ this_cu
->length
)
11530 error (_("invalid dwarf2 offset %u"), offset
);
11531 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11536 /* Locate the compilation unit from OBJFILE which is located at exactly
11537 OFFSET. Raises an error on failure. */
11539 static struct dwarf2_per_cu_data
*
11540 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11542 struct dwarf2_per_cu_data
*this_cu
;
11543 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11544 if (this_cu
->offset
!= offset
)
11545 error (_("no compilation unit with offset %u."), offset
);
11549 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11551 static struct dwarf2_cu
*
11552 alloc_one_comp_unit (struct objfile
*objfile
)
11554 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11555 cu
->objfile
= objfile
;
11556 obstack_init (&cu
->comp_unit_obstack
);
11560 /* Release one cached compilation unit, CU. We unlink it from the tree
11561 of compilation units, but we don't remove it from the read_in_chain;
11562 the caller is responsible for that.
11563 NOTE: DATA is a void * because this function is also used as a
11564 cleanup routine. */
11567 free_one_comp_unit (void *data
)
11569 struct dwarf2_cu
*cu
= data
;
11571 if (cu
->per_cu
!= NULL
)
11572 cu
->per_cu
->cu
= NULL
;
11575 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11580 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11581 when we're finished with it. We can't free the pointer itself, but be
11582 sure to unlink it from the cache. Also release any associated storage
11583 and perform cache maintenance.
11585 Only used during partial symbol parsing. */
11588 free_stack_comp_unit (void *data
)
11590 struct dwarf2_cu
*cu
= data
;
11592 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11593 cu
->partial_dies
= NULL
;
11595 if (cu
->per_cu
!= NULL
)
11597 /* This compilation unit is on the stack in our caller, so we
11598 should not xfree it. Just unlink it. */
11599 cu
->per_cu
->cu
= NULL
;
11602 /* If we had a per-cu pointer, then we may have other compilation
11603 units loaded, so age them now. */
11604 age_cached_comp_units ();
11608 /* Free all cached compilation units. */
11611 free_cached_comp_units (void *data
)
11613 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11615 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11616 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11617 while (per_cu
!= NULL
)
11619 struct dwarf2_per_cu_data
*next_cu
;
11621 next_cu
= per_cu
->cu
->read_in_chain
;
11623 free_one_comp_unit (per_cu
->cu
);
11624 *last_chain
= next_cu
;
11630 /* Increase the age counter on each cached compilation unit, and free
11631 any that are too old. */
11634 age_cached_comp_units (void)
11636 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11638 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
11639 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11640 while (per_cu
!= NULL
)
11642 per_cu
->cu
->last_used
++;
11643 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
11644 dwarf2_mark (per_cu
->cu
);
11645 per_cu
= per_cu
->cu
->read_in_chain
;
11648 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11649 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11650 while (per_cu
!= NULL
)
11652 struct dwarf2_per_cu_data
*next_cu
;
11654 next_cu
= per_cu
->cu
->read_in_chain
;
11656 if (!per_cu
->cu
->mark
)
11658 free_one_comp_unit (per_cu
->cu
);
11659 *last_chain
= next_cu
;
11662 last_chain
= &per_cu
->cu
->read_in_chain
;
11668 /* Remove a single compilation unit from the cache. */
11671 free_one_cached_comp_unit (void *target_cu
)
11673 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11675 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11676 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11677 while (per_cu
!= NULL
)
11679 struct dwarf2_per_cu_data
*next_cu
;
11681 next_cu
= per_cu
->cu
->read_in_chain
;
11683 if (per_cu
->cu
== target_cu
)
11685 free_one_comp_unit (per_cu
->cu
);
11686 *last_chain
= next_cu
;
11690 last_chain
= &per_cu
->cu
->read_in_chain
;
11696 /* Release all extra memory associated with OBJFILE. */
11699 dwarf2_free_objfile (struct objfile
*objfile
)
11701 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
11703 if (dwarf2_per_objfile
== NULL
)
11706 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11707 free_cached_comp_units (NULL
);
11709 /* Everything else should be on the objfile obstack. */
11712 /* A pair of DIE offset and GDB type pointer. We store these
11713 in a hash table separate from the DIEs, and preserve them
11714 when the DIEs are flushed out of cache. */
11716 struct dwarf2_offset_and_type
11718 unsigned int offset
;
11722 /* Hash function for a dwarf2_offset_and_type. */
11725 offset_and_type_hash (const void *item
)
11727 const struct dwarf2_offset_and_type
*ofs
= item
;
11728 return ofs
->offset
;
11731 /* Equality function for a dwarf2_offset_and_type. */
11734 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
11736 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
11737 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
11738 return ofs_lhs
->offset
== ofs_rhs
->offset
;
11741 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11742 table if necessary. For convenience, return TYPE. */
11744 static struct type
*
11745 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11747 struct dwarf2_offset_and_type
**slot
, ofs
;
11749 /* For Ada types, make sure that the gnat-specific data is always
11750 initialized (if not already set). There are a few types where
11751 we should not be doing so, because the type-specific area is
11752 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11753 where the type-specific area is used to store the floatformat).
11754 But this is not a problem, because the gnat-specific information
11755 is actually not needed for these types. */
11756 if (need_gnat_info (cu
)
11757 && TYPE_CODE (type
) != TYPE_CODE_FUNC
11758 && TYPE_CODE (type
) != TYPE_CODE_FLT
11759 && !HAVE_GNAT_AUX_INFO (type
))
11760 INIT_GNAT_SPECIFIC (type
);
11762 if (cu
->type_hash
== NULL
)
11764 gdb_assert (cu
->per_cu
!= NULL
);
11765 cu
->per_cu
->type_hash
11766 = htab_create_alloc_ex (cu
->header
.length
/ 24,
11767 offset_and_type_hash
,
11768 offset_and_type_eq
,
11770 &cu
->objfile
->objfile_obstack
,
11771 hashtab_obstack_allocate
,
11772 dummy_obstack_deallocate
);
11773 cu
->type_hash
= cu
->per_cu
->type_hash
;
11776 ofs
.offset
= die
->offset
;
11778 slot
= (struct dwarf2_offset_and_type
**)
11779 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
11780 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
11785 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
11786 not have a saved type. */
11788 static struct type
*
11789 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11791 struct dwarf2_offset_and_type
*slot
, ofs
;
11792 htab_t type_hash
= cu
->type_hash
;
11794 if (type_hash
== NULL
)
11797 ofs
.offset
= die
->offset
;
11798 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
11805 /* Add a dependence relationship from CU to REF_PER_CU. */
11808 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
11809 struct dwarf2_per_cu_data
*ref_per_cu
)
11813 if (cu
->dependencies
== NULL
)
11815 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
11816 NULL
, &cu
->comp_unit_obstack
,
11817 hashtab_obstack_allocate
,
11818 dummy_obstack_deallocate
);
11820 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
11822 *slot
= ref_per_cu
;
11825 /* Subroutine of dwarf2_mark to pass to htab_traverse.
11826 Set the mark field in every compilation unit in the
11827 cache that we must keep because we are keeping CU. */
11830 dwarf2_mark_helper (void **slot
, void *data
)
11832 struct dwarf2_per_cu_data
*per_cu
;
11834 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
11835 if (per_cu
->cu
->mark
)
11837 per_cu
->cu
->mark
= 1;
11839 if (per_cu
->cu
->dependencies
!= NULL
)
11840 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11845 /* Set the mark field in CU and in every other compilation unit in the
11846 cache that we must keep because we are keeping CU. */
11849 dwarf2_mark (struct dwarf2_cu
*cu
)
11854 if (cu
->dependencies
!= NULL
)
11855 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11859 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
11863 per_cu
->cu
->mark
= 0;
11864 per_cu
= per_cu
->cu
->read_in_chain
;
11868 /* Trivial hash function for partial_die_info: the hash value of a DIE
11869 is its offset in .debug_info for this objfile. */
11872 partial_die_hash (const void *item
)
11874 const struct partial_die_info
*part_die
= item
;
11875 return part_die
->offset
;
11878 /* Trivial comparison function for partial_die_info structures: two DIEs
11879 are equal if they have the same offset. */
11882 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
11884 const struct partial_die_info
*part_die_lhs
= item_lhs
;
11885 const struct partial_die_info
*part_die_rhs
= item_rhs
;
11886 return part_die_lhs
->offset
== part_die_rhs
->offset
;
11889 static struct cmd_list_element
*set_dwarf2_cmdlist
;
11890 static struct cmd_list_element
*show_dwarf2_cmdlist
;
11893 set_dwarf2_cmd (char *args
, int from_tty
)
11895 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
11899 show_dwarf2_cmd (char *args
, int from_tty
)
11901 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
11904 /* If section described by INFO was mmapped, munmap it now. */
11907 munmap_section_buffer (struct dwarf2_section_info
*info
)
11909 if (info
->was_mmapped
)
11912 intptr_t begin
= (intptr_t) info
->buffer
;
11913 intptr_t map_begin
= begin
& ~(pagesize
- 1);
11914 size_t map_length
= info
->size
+ begin
- map_begin
;
11915 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
11917 /* Without HAVE_MMAP, we should never be here to begin with. */
11923 /* munmap debug sections for OBJFILE, if necessary. */
11926 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
11928 struct dwarf2_per_objfile
*data
= d
;
11929 munmap_section_buffer (&data
->info
);
11930 munmap_section_buffer (&data
->abbrev
);
11931 munmap_section_buffer (&data
->line
);
11932 munmap_section_buffer (&data
->str
);
11933 munmap_section_buffer (&data
->macinfo
);
11934 munmap_section_buffer (&data
->ranges
);
11935 munmap_section_buffer (&data
->loc
);
11936 munmap_section_buffer (&data
->frame
);
11937 munmap_section_buffer (&data
->eh_frame
);
11940 void _initialize_dwarf2_read (void);
11943 _initialize_dwarf2_read (void)
11945 dwarf2_objfile_data_key
11946 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
11948 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
11949 Set DWARF 2 specific variables.\n\
11950 Configure DWARF 2 variables such as the cache size"),
11951 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
11952 0/*allow-unknown*/, &maintenance_set_cmdlist
);
11954 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
11955 Show DWARF 2 specific variables\n\
11956 Show DWARF 2 variables such as the cache size"),
11957 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
11958 0/*allow-unknown*/, &maintenance_show_cmdlist
);
11960 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
11961 &dwarf2_max_cache_age
, _("\
11962 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
11963 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
11964 A higher limit means that cached compilation units will be stored\n\
11965 in memory longer, and more total memory will be used. Zero disables\n\
11966 caching, which can slow down startup."),
11968 show_dwarf2_max_cache_age
,
11969 &set_dwarf2_cmdlist
,
11970 &show_dwarf2_cmdlist
);
11972 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
11973 Set debugging of the dwarf2 DIE reader."), _("\
11974 Show debugging of the dwarf2 DIE reader."), _("\
11975 When enabled (non-zero), DIEs are dumped after they are read in.\n\
11976 The value is the maximum depth to print."),
11979 &setdebuglist
, &showdebuglist
);