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 maximum_ops_per_instruction
;
400 unsigned char default_is_stmt
;
402 unsigned char line_range
;
403 unsigned char opcode_base
;
405 /* standard_opcode_lengths[i] is the number of operands for the
406 standard opcode whose value is i. This means that
407 standard_opcode_lengths[0] is unused, and the last meaningful
408 element is standard_opcode_lengths[opcode_base - 1]. */
409 unsigned char *standard_opcode_lengths
;
411 /* The include_directories table. NOTE! These strings are not
412 allocated with xmalloc; instead, they are pointers into
413 debug_line_buffer. If you try to free them, `free' will get
415 unsigned int num_include_dirs
, include_dirs_size
;
418 /* The file_names table. NOTE! These strings are not allocated
419 with xmalloc; instead, they are pointers into debug_line_buffer.
420 Don't try to free them directly. */
421 unsigned int num_file_names
, file_names_size
;
425 unsigned int dir_index
;
426 unsigned int mod_time
;
428 int included_p
; /* Non-zero if referenced by the Line Number Program. */
429 struct symtab
*symtab
; /* The associated symbol table, if any. */
432 /* The start and end of the statement program following this
433 header. These point into dwarf2_per_objfile->line_buffer. */
434 gdb_byte
*statement_program_start
, *statement_program_end
;
437 /* When we construct a partial symbol table entry we only
438 need this much information. */
439 struct partial_die_info
441 /* Offset of this DIE. */
444 /* DWARF-2 tag for this DIE. */
445 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
447 /* Assorted flags describing the data found in this DIE. */
448 unsigned int has_children
: 1;
449 unsigned int is_external
: 1;
450 unsigned int is_declaration
: 1;
451 unsigned int has_type
: 1;
452 unsigned int has_specification
: 1;
453 unsigned int has_pc_info
: 1;
455 /* Flag set if the SCOPE field of this structure has been
457 unsigned int scope_set
: 1;
459 /* Flag set if the DIE has a byte_size attribute. */
460 unsigned int has_byte_size
: 1;
462 /* The name of this DIE. Normally the value of DW_AT_name, but
463 sometimes a default name for unnamed DIEs. */
466 /* The scope to prepend to our children. This is generally
467 allocated on the comp_unit_obstack, so will disappear
468 when this compilation unit leaves the cache. */
471 /* The location description associated with this DIE, if any. */
472 struct dwarf_block
*locdesc
;
474 /* If HAS_PC_INFO, the PC range associated with this DIE. */
478 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
479 DW_AT_sibling, if any. */
482 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
483 DW_AT_specification (or DW_AT_abstract_origin or
485 unsigned int spec_offset
;
487 /* Pointers to this DIE's parent, first child, and next sibling,
489 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
492 /* This data structure holds the information of an abbrev. */
495 unsigned int number
; /* number identifying abbrev */
496 enum dwarf_tag tag
; /* dwarf tag */
497 unsigned short has_children
; /* boolean */
498 unsigned short num_attrs
; /* number of attributes */
499 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
500 struct abbrev_info
*next
; /* next in chain */
505 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
506 ENUM_BITFIELD(dwarf_form
) form
: 16;
509 /* Attributes have a name and a value */
512 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
513 ENUM_BITFIELD(dwarf_form
) form
: 15;
515 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
516 field should be in u.str (existing only for DW_STRING) but it is kept
517 here for better struct attribute alignment. */
518 unsigned int string_is_canonical
: 1;
523 struct dwarf_block
*blk
;
527 struct signatured_type
*signatured_type
;
532 /* This data structure holds a complete die structure. */
535 /* DWARF-2 tag for this DIE. */
536 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
538 /* Number of attributes */
539 unsigned short num_attrs
;
544 /* Offset in .debug_info or .debug_types section. */
547 /* The dies in a compilation unit form an n-ary tree. PARENT
548 points to this die's parent; CHILD points to the first child of
549 this node; and all the children of a given node are chained
550 together via their SIBLING fields, terminated by a die whose
552 struct die_info
*child
; /* Its first child, if any. */
553 struct die_info
*sibling
; /* Its next sibling, if any. */
554 struct die_info
*parent
; /* Its parent, if any. */
556 /* An array of attributes, with NUM_ATTRS elements. There may be
557 zero, but it's not common and zero-sized arrays are not
558 sufficiently portable C. */
559 struct attribute attrs
[1];
562 struct function_range
565 CORE_ADDR lowpc
, highpc
;
567 struct function_range
*next
;
570 /* Get at parts of an attribute structure */
572 #define DW_STRING(attr) ((attr)->u.str)
573 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
574 #define DW_UNSND(attr) ((attr)->u.unsnd)
575 #define DW_BLOCK(attr) ((attr)->u.blk)
576 #define DW_SND(attr) ((attr)->u.snd)
577 #define DW_ADDR(attr) ((attr)->u.addr)
578 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
580 /* Blocks are a bunch of untyped bytes. */
587 #ifndef ATTR_ALLOC_CHUNK
588 #define ATTR_ALLOC_CHUNK 4
591 /* Allocate fields for structs, unions and enums in this size. */
592 #ifndef DW_FIELD_ALLOC_CHUNK
593 #define DW_FIELD_ALLOC_CHUNK 4
596 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
597 but this would require a corresponding change in unpack_field_as_long
599 static int bits_per_byte
= 8;
601 /* The routines that read and process dies for a C struct or C++ class
602 pass lists of data member fields and lists of member function fields
603 in an instance of a field_info structure, as defined below. */
606 /* List of data member and baseclasses fields. */
609 struct nextfield
*next
;
614 *fields
, *baseclasses
;
616 /* Number of fields (including baseclasses). */
619 /* Number of baseclasses. */
622 /* Set if the accesibility of one of the fields is not public. */
623 int non_public_fields
;
625 /* Member function fields array, entries are allocated in the order they
626 are encountered in the object file. */
629 struct nextfnfield
*next
;
630 struct fn_field fnfield
;
634 /* Member function fieldlist array, contains name of possibly overloaded
635 member function, number of overloaded member functions and a pointer
636 to the head of the member function field chain. */
641 struct nextfnfield
*head
;
645 /* Number of entries in the fnfieldlists array. */
649 /* One item on the queue of compilation units to read in full symbols
651 struct dwarf2_queue_item
653 struct dwarf2_per_cu_data
*per_cu
;
654 struct dwarf2_queue_item
*next
;
657 /* The current queue. */
658 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
660 /* Loaded secondary compilation units are kept in memory until they
661 have not been referenced for the processing of this many
662 compilation units. Set this to zero to disable caching. Cache
663 sizes of up to at least twenty will improve startup time for
664 typical inter-CU-reference binaries, at an obvious memory cost. */
665 static int dwarf2_max_cache_age
= 5;
667 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
668 struct cmd_list_element
*c
, const char *value
)
670 fprintf_filtered (file
, _("\
671 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
676 /* Various complaints about symbol reading that don't abort the process */
679 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
681 complaint (&symfile_complaints
,
682 _("statement list doesn't fit in .debug_line section"));
686 dwarf2_debug_line_missing_file_complaint (void)
688 complaint (&symfile_complaints
,
689 _(".debug_line section has line data without a file"));
693 dwarf2_debug_line_missing_end_sequence_complaint (void)
695 complaint (&symfile_complaints
,
696 _(".debug_line section has line program sequence without an end"));
700 dwarf2_complex_location_expr_complaint (void)
702 complaint (&symfile_complaints
, _("location expression too complex"));
706 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
709 complaint (&symfile_complaints
,
710 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
715 dwarf2_macros_too_long_complaint (void)
717 complaint (&symfile_complaints
,
718 _("macro info runs off end of `.debug_macinfo' section"));
722 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
724 complaint (&symfile_complaints
,
725 _("macro debug info contains a malformed macro definition:\n`%s'"),
730 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
732 complaint (&symfile_complaints
,
733 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
736 /* local function prototypes */
738 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
740 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
743 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
745 struct partial_symtab
*);
747 static void dwarf2_build_psymtabs_hard (struct objfile
*);
749 static void scan_partial_symbols (struct partial_die_info
*,
750 CORE_ADDR
*, CORE_ADDR
*,
751 int, struct dwarf2_cu
*);
753 static void add_partial_symbol (struct partial_die_info
*,
756 static void add_partial_namespace (struct partial_die_info
*pdi
,
757 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
758 int need_pc
, struct dwarf2_cu
*cu
);
760 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
761 CORE_ADDR
*highpc
, int need_pc
,
762 struct dwarf2_cu
*cu
);
764 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
765 struct dwarf2_cu
*cu
);
767 static void add_partial_subprogram (struct partial_die_info
*pdi
,
768 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
769 int need_pc
, struct dwarf2_cu
*cu
);
771 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
772 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
773 bfd
*abfd
, struct dwarf2_cu
*cu
);
775 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
777 static void psymtab_to_symtab_1 (struct partial_symtab
*);
779 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
781 static void dwarf2_free_abbrev_table (void *);
783 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
786 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
789 static struct partial_die_info
*load_partial_dies (bfd
*,
790 gdb_byte
*, gdb_byte
*,
791 int, struct dwarf2_cu
*);
793 static gdb_byte
*read_partial_die (struct partial_die_info
*,
794 struct abbrev_info
*abbrev
,
796 gdb_byte
*, gdb_byte
*,
799 static struct partial_die_info
*find_partial_die (unsigned int,
802 static void fixup_partial_die (struct partial_die_info
*,
805 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
806 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
808 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
809 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
811 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
813 static int read_1_signed_byte (bfd
*, gdb_byte
*);
815 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
817 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
819 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
821 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
824 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
826 static LONGEST read_checked_initial_length_and_offset
827 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
828 unsigned int *, unsigned int *);
830 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
833 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
835 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
837 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
839 static char *read_indirect_string (bfd
*, gdb_byte
*,
840 const struct comp_unit_head
*,
843 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
845 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
847 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
849 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
851 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
854 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
858 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
859 struct dwarf2_cu
*cu
);
861 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
863 static struct die_info
*die_specification (struct die_info
*die
,
864 struct dwarf2_cu
**);
866 static void free_line_header (struct line_header
*lh
);
868 static void add_file_name (struct line_header
*, char *, unsigned int,
869 unsigned int, unsigned int);
871 static struct line_header
*(dwarf_decode_line_header
872 (unsigned int offset
,
873 bfd
*abfd
, struct dwarf2_cu
*cu
));
875 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
876 struct dwarf2_cu
*, struct partial_symtab
*);
878 static void dwarf2_start_subfile (char *, char *, char *);
880 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
883 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
886 static void dwarf2_const_value_data (struct attribute
*attr
,
890 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
892 static int need_gnat_info (struct dwarf2_cu
*);
894 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
896 static void set_descriptive_type (struct type
*, struct die_info
*,
899 static struct type
*die_containing_type (struct die_info
*,
902 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
904 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
906 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
908 static char *typename_concat (struct obstack
*,
913 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
915 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
917 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
919 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
921 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
922 struct dwarf2_cu
*, struct partial_symtab
*);
924 static int dwarf2_get_pc_bounds (struct die_info
*,
925 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
926 struct partial_symtab
*);
928 static void get_scope_pc_bounds (struct die_info
*,
929 CORE_ADDR
*, CORE_ADDR
*,
932 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
933 CORE_ADDR
, struct dwarf2_cu
*);
935 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
938 static void dwarf2_attach_fields_to_type (struct field_info
*,
939 struct type
*, struct dwarf2_cu
*);
941 static void dwarf2_add_member_fn (struct field_info
*,
942 struct die_info
*, struct type
*,
945 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
946 struct type
*, struct dwarf2_cu
*);
948 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
950 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
952 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
954 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
956 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
958 static const char *namespace_name (struct die_info
*die
,
959 int *is_anonymous
, struct dwarf2_cu
*);
961 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
963 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
965 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
968 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
970 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
972 gdb_byte
**new_info_ptr
,
973 struct die_info
*parent
);
975 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
977 gdb_byte
**new_info_ptr
,
978 struct die_info
*parent
);
980 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
982 gdb_byte
**new_info_ptr
,
983 struct die_info
*parent
);
985 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
986 struct die_info
**, gdb_byte
*,
989 static void process_die (struct die_info
*, struct dwarf2_cu
*);
991 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
994 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
996 static struct die_info
*dwarf2_extension (struct die_info
*die
,
997 struct dwarf2_cu
**);
999 static char *dwarf_tag_name (unsigned int);
1001 static char *dwarf_attr_name (unsigned int);
1003 static char *dwarf_form_name (unsigned int);
1005 static char *dwarf_stack_op_name (unsigned int);
1007 static char *dwarf_bool_name (unsigned int);
1009 static char *dwarf_type_encoding_name (unsigned int);
1012 static char *dwarf_cfi_name (unsigned int);
1015 static struct die_info
*sibling_die (struct die_info
*);
1017 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1019 static void dump_die_for_error (struct die_info
*);
1021 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1024 /*static*/ void dump_die (struct die_info
*, int max_level
);
1026 static void store_in_ref_table (struct die_info
*,
1027 struct dwarf2_cu
*);
1029 static int is_ref_attr (struct attribute
*);
1031 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1033 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1035 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1037 struct dwarf2_cu
**);
1039 static struct die_info
*follow_die_ref (struct die_info
*,
1041 struct dwarf2_cu
**);
1043 static struct die_info
*follow_die_sig (struct die_info
*,
1045 struct dwarf2_cu
**);
1047 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1048 unsigned int offset
);
1050 static void read_signatured_type (struct objfile
*,
1051 struct signatured_type
*type_sig
);
1053 /* memory allocation interface */
1055 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1057 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1059 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1061 static void initialize_cu_func_list (struct dwarf2_cu
*);
1063 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1064 struct dwarf2_cu
*);
1066 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1067 char *, bfd
*, struct dwarf2_cu
*);
1069 static int attr_form_is_block (struct attribute
*);
1071 static int attr_form_is_section_offset (struct attribute
*);
1073 static int attr_form_is_constant (struct attribute
*);
1075 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1077 struct dwarf2_cu
*cu
);
1079 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1080 struct abbrev_info
*abbrev
,
1081 struct dwarf2_cu
*cu
);
1083 static void free_stack_comp_unit (void *);
1085 static hashval_t
partial_die_hash (const void *item
);
1087 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1089 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1090 (unsigned int offset
, struct objfile
*objfile
);
1092 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1093 (unsigned int offset
, struct objfile
*objfile
);
1095 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1097 static void free_one_comp_unit (void *);
1099 static void free_cached_comp_units (void *);
1101 static void age_cached_comp_units (void);
1103 static void free_one_cached_comp_unit (void *);
1105 static struct type
*set_die_type (struct die_info
*, struct type
*,
1106 struct dwarf2_cu
*);
1108 static void create_all_comp_units (struct objfile
*);
1110 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1113 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1115 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1116 struct dwarf2_per_cu_data
*);
1118 static void dwarf2_mark (struct dwarf2_cu
*);
1120 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1122 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1124 /* Try to locate the sections we need for DWARF 2 debugging
1125 information and return true if we have enough to do something. */
1128 dwarf2_has_info (struct objfile
*objfile
)
1130 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1131 if (!dwarf2_per_objfile
)
1133 /* Initialize per-objfile state. */
1134 struct dwarf2_per_objfile
*data
1135 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1137 memset (data
, 0, sizeof (*data
));
1138 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1139 dwarf2_per_objfile
= data
;
1141 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1142 dwarf2_per_objfile
->objfile
= objfile
;
1144 return (dwarf2_per_objfile
->info
.asection
!= NULL
1145 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1148 /* When loading sections, we can either look for ".<name>", or for
1149 * ".z<name>", which indicates a compressed section. */
1152 section_is_p (const char *section_name
, const char *name
)
1154 return (section_name
[0] == '.'
1155 && (strcmp (section_name
+ 1, name
) == 0
1156 || (section_name
[1] == 'z'
1157 && strcmp (section_name
+ 2, name
) == 0)));
1160 /* This function is mapped across the sections and remembers the
1161 offset and size of each of the debugging sections we are interested
1165 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1167 if (section_is_p (sectp
->name
, INFO_SECTION
))
1169 dwarf2_per_objfile
->info
.asection
= sectp
;
1170 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1172 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1174 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1175 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1177 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1179 dwarf2_per_objfile
->line
.asection
= sectp
;
1180 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1182 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1184 dwarf2_per_objfile
->loc
.asection
= sectp
;
1185 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1187 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1189 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1190 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1192 else if (section_is_p (sectp
->name
, STR_SECTION
))
1194 dwarf2_per_objfile
->str
.asection
= sectp
;
1195 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1197 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1199 dwarf2_per_objfile
->frame
.asection
= sectp
;
1200 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1202 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1204 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1206 if (aflag
& SEC_HAS_CONTENTS
)
1208 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1209 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1212 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1214 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1215 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1217 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1219 dwarf2_per_objfile
->types
.asection
= sectp
;
1220 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1223 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1224 && bfd_section_vma (abfd
, sectp
) == 0)
1225 dwarf2_per_objfile
->has_section_at_zero
= 1;
1228 /* Decompress a section that was compressed using zlib. Store the
1229 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1232 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1233 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1235 bfd
*abfd
= objfile
->obfd
;
1237 error (_("Support for zlib-compressed DWARF data (from '%s') "
1238 "is disabled in this copy of GDB"),
1239 bfd_get_filename (abfd
));
1241 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1242 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1243 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1244 bfd_size_type uncompressed_size
;
1245 gdb_byte
*uncompressed_buffer
;
1248 int header_size
= 12;
1250 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1251 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1252 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1253 bfd_get_filename (abfd
));
1255 /* Read the zlib header. In this case, it should be "ZLIB" followed
1256 by the uncompressed section size, 8 bytes in big-endian order. */
1257 if (compressed_size
< header_size
1258 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1259 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1260 bfd_get_filename (abfd
));
1261 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1262 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1263 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1264 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1265 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1266 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1267 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1268 uncompressed_size
+= compressed_buffer
[11];
1270 /* It is possible the section consists of several compressed
1271 buffers concatenated together, so we uncompress in a loop. */
1275 strm
.avail_in
= compressed_size
- header_size
;
1276 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1277 strm
.avail_out
= uncompressed_size
;
1278 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1280 rc
= inflateInit (&strm
);
1281 while (strm
.avail_in
> 0)
1284 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1285 bfd_get_filename (abfd
), rc
);
1286 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1287 + (uncompressed_size
- strm
.avail_out
));
1288 rc
= inflate (&strm
, Z_FINISH
);
1289 if (rc
!= Z_STREAM_END
)
1290 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1291 bfd_get_filename (abfd
), rc
);
1292 rc
= inflateReset (&strm
);
1294 rc
= inflateEnd (&strm
);
1296 || strm
.avail_out
!= 0)
1297 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1298 bfd_get_filename (abfd
), rc
);
1300 do_cleanups (cleanup
);
1301 *outbuf
= uncompressed_buffer
;
1302 *outsize
= uncompressed_size
;
1306 /* Read the contents of the section SECTP from object file specified by
1307 OBJFILE, store info about the section into INFO.
1308 If the section is compressed, uncompress it before returning. */
1311 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1313 bfd
*abfd
= objfile
->obfd
;
1314 asection
*sectp
= info
->asection
;
1315 gdb_byte
*buf
, *retbuf
;
1316 unsigned char header
[4];
1320 info
->buffer
= NULL
;
1321 info
->was_mmapped
= 0;
1324 if (info
->asection
== NULL
|| info
->size
== 0)
1327 /* Check if the file has a 4-byte header indicating compression. */
1328 if (info
->size
> sizeof (header
)
1329 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1330 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1332 /* Upon decompression, update the buffer and its size. */
1333 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1335 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1343 pagesize
= getpagesize ();
1345 /* Only try to mmap sections which are large enough: we don't want to
1346 waste space due to fragmentation. Also, only try mmap for sections
1347 without relocations. */
1349 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1351 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1352 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1353 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1354 MAP_PRIVATE
, pg_offset
);
1356 if (retbuf
!= MAP_FAILED
)
1358 info
->was_mmapped
= 1;
1359 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1360 #if HAVE_POSIX_MADVISE
1361 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1368 /* If we get here, we are a normal, not-compressed section. */
1370 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1372 /* When debugging .o files, we may need to apply relocations; see
1373 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1374 We never compress sections in .o files, so we only need to
1375 try this when the section is not compressed. */
1376 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1379 info
->buffer
= retbuf
;
1383 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1384 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1385 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1386 bfd_get_filename (abfd
));
1389 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1393 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1394 asection
**sectp
, gdb_byte
**bufp
,
1395 bfd_size_type
*sizep
)
1397 struct dwarf2_per_objfile
*data
1398 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1399 struct dwarf2_section_info
*info
;
1401 /* We may see an objfile without any DWARF, in which case we just
1410 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1411 info
= &data
->eh_frame
;
1412 else if (section_is_p (section_name
, FRAME_SECTION
))
1413 info
= &data
->frame
;
1417 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1418 /* We haven't read this section in yet. Do it now. */
1419 dwarf2_read_section (objfile
, info
);
1421 *sectp
= info
->asection
;
1422 *bufp
= info
->buffer
;
1423 *sizep
= info
->size
;
1426 /* Build a partial symbol table. */
1429 dwarf2_build_psymtabs (struct objfile
*objfile
)
1431 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
1433 init_psymbol_list (objfile
, 1024);
1436 dwarf2_build_psymtabs_hard (objfile
);
1439 /* Return TRUE if OFFSET is within CU_HEADER. */
1442 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1444 unsigned int bottom
= cu_header
->offset
;
1445 unsigned int top
= (cu_header
->offset
1447 + cu_header
->initial_length_size
);
1449 return (offset
>= bottom
&& offset
< top
);
1452 /* Read in the comp unit header information from the debug_info at info_ptr.
1453 NOTE: This leaves members offset, first_die_offset to be filled in
1457 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1458 gdb_byte
*info_ptr
, bfd
*abfd
)
1461 unsigned int bytes_read
;
1463 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1464 cu_header
->initial_length_size
= bytes_read
;
1465 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1466 info_ptr
+= bytes_read
;
1467 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1469 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1471 info_ptr
+= bytes_read
;
1472 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1474 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1475 if (signed_addr
< 0)
1476 internal_error (__FILE__
, __LINE__
,
1477 _("read_comp_unit_head: dwarf from non elf file"));
1478 cu_header
->signed_addr_p
= signed_addr
;
1484 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1485 gdb_byte
*buffer
, unsigned int buffer_size
,
1488 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1490 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1492 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
1493 error (_("Dwarf Error: wrong version in compilation unit header "
1494 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
1495 bfd_get_filename (abfd
));
1497 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1498 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1499 "(offset 0x%lx + 6) [in module %s]"),
1500 (long) header
->abbrev_offset
,
1501 (long) (beg_of_comp_unit
- buffer
),
1502 bfd_get_filename (abfd
));
1504 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1505 > buffer
+ buffer_size
)
1506 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1507 "(offset 0x%lx + 0) [in module %s]"),
1508 (long) header
->length
,
1509 (long) (beg_of_comp_unit
- buffer
),
1510 bfd_get_filename (abfd
));
1515 /* Read in the types comp unit header information from .debug_types entry at
1516 types_ptr. The result is a pointer to one past the end of the header. */
1519 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
1520 ULONGEST
*signature
,
1521 gdb_byte
*types_ptr
, bfd
*abfd
)
1523 gdb_byte
*initial_types_ptr
= types_ptr
;
1525 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
1526 &dwarf2_per_objfile
->types
);
1527 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
1529 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
1531 *signature
= read_8_bytes (abfd
, types_ptr
);
1533 types_ptr
+= cu_header
->offset_size
;
1534 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
1539 /* Allocate a new partial symtab for file named NAME and mark this new
1540 partial symtab as being an include of PST. */
1543 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1544 struct objfile
*objfile
)
1546 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1548 subpst
->section_offsets
= pst
->section_offsets
;
1549 subpst
->textlow
= 0;
1550 subpst
->texthigh
= 0;
1552 subpst
->dependencies
= (struct partial_symtab
**)
1553 obstack_alloc (&objfile
->objfile_obstack
,
1554 sizeof (struct partial_symtab
*));
1555 subpst
->dependencies
[0] = pst
;
1556 subpst
->number_of_dependencies
= 1;
1558 subpst
->globals_offset
= 0;
1559 subpst
->n_global_syms
= 0;
1560 subpst
->statics_offset
= 0;
1561 subpst
->n_static_syms
= 0;
1562 subpst
->symtab
= NULL
;
1563 subpst
->read_symtab
= pst
->read_symtab
;
1566 /* No private part is necessary for include psymtabs. This property
1567 can be used to differentiate between such include psymtabs and
1568 the regular ones. */
1569 subpst
->read_symtab_private
= NULL
;
1572 /* Read the Line Number Program data and extract the list of files
1573 included by the source file represented by PST. Build an include
1574 partial symtab for each of these included files. */
1577 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1578 struct die_info
*die
,
1579 struct partial_symtab
*pst
)
1581 struct objfile
*objfile
= cu
->objfile
;
1582 bfd
*abfd
= objfile
->obfd
;
1583 struct line_header
*lh
= NULL
;
1584 struct attribute
*attr
;
1586 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
1589 unsigned int line_offset
= DW_UNSND (attr
);
1591 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
1594 return; /* No linetable, so no includes. */
1596 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1598 free_line_header (lh
);
1602 hash_type_signature (const void *item
)
1604 const struct signatured_type
*type_sig
= item
;
1606 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1607 return type_sig
->signature
;
1611 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
1613 const struct signatured_type
*lhs
= item_lhs
;
1614 const struct signatured_type
*rhs
= item_rhs
;
1616 return lhs
->signature
== rhs
->signature
;
1619 /* Create the hash table of all entries in the .debug_types section.
1620 The result is zero if there is an error (e.g. missing .debug_types section),
1621 otherwise non-zero. */
1624 create_debug_types_hash_table (struct objfile
*objfile
)
1629 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
1630 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
1632 if (info_ptr
== NULL
)
1634 dwarf2_per_objfile
->signatured_types
= NULL
;
1638 types_htab
= htab_create_alloc_ex (41,
1639 hash_type_signature
,
1642 &objfile
->objfile_obstack
,
1643 hashtab_obstack_allocate
,
1644 dummy_obstack_deallocate
);
1646 if (dwarf2_die_debug
)
1647 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
1649 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1651 unsigned int offset
;
1652 unsigned int offset_size
;
1653 unsigned int type_offset
;
1654 unsigned int length
, initial_length_size
;
1655 unsigned short version
;
1657 struct signatured_type
*type_sig
;
1659 gdb_byte
*ptr
= info_ptr
;
1661 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
1663 /* We need to read the type's signature in order to build the hash
1664 table, but we don't need to read anything else just yet. */
1666 /* Sanity check to ensure entire cu is present. */
1667 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
1668 if (ptr
+ length
+ initial_length_size
1669 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1671 complaint (&symfile_complaints
,
1672 _("debug type entry runs off end of `.debug_types' section, ignored"));
1676 offset_size
= initial_length_size
== 4 ? 4 : 8;
1677 ptr
+= initial_length_size
;
1678 version
= bfd_get_16 (objfile
->obfd
, ptr
);
1680 ptr
+= offset_size
; /* abbrev offset */
1681 ptr
+= 1; /* address size */
1682 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
1684 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
1686 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
1687 memset (type_sig
, 0, sizeof (*type_sig
));
1688 type_sig
->signature
= signature
;
1689 type_sig
->offset
= offset
;
1690 type_sig
->type_offset
= type_offset
;
1692 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
1693 gdb_assert (slot
!= NULL
);
1696 if (dwarf2_die_debug
)
1697 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
1698 offset
, phex (signature
, sizeof (signature
)));
1700 info_ptr
= info_ptr
+ initial_length_size
+ length
;
1703 dwarf2_per_objfile
->signatured_types
= types_htab
;
1708 /* Lookup a signature based type.
1709 Returns NULL if SIG is not present in the table. */
1711 static struct signatured_type
*
1712 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
1714 struct signatured_type find_entry
, *entry
;
1716 if (dwarf2_per_objfile
->signatured_types
== NULL
)
1718 complaint (&symfile_complaints
,
1719 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1723 find_entry
.signature
= sig
;
1724 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
1728 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1731 init_cu_die_reader (struct die_reader_specs
*reader
,
1732 struct dwarf2_cu
*cu
)
1734 reader
->abfd
= cu
->objfile
->obfd
;
1736 if (cu
->per_cu
->from_debug_types
)
1738 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1739 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
1743 gdb_assert (dwarf2_per_objfile
->info
.readin
);
1744 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
1748 /* Find the base address of the compilation unit for range lists and
1749 location lists. It will normally be specified by DW_AT_low_pc.
1750 In DWARF-3 draft 4, the base address could be overridden by
1751 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1752 compilation units with discontinuous ranges. */
1755 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
1757 struct attribute
*attr
;
1760 cu
->base_address
= 0;
1762 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
1765 cu
->base_address
= DW_ADDR (attr
);
1770 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
1773 cu
->base_address
= DW_ADDR (attr
);
1779 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1780 to combine the common parts.
1781 Process a compilation unit for a psymtab.
1782 BUFFER is a pointer to the beginning of the dwarf section buffer,
1783 either .debug_info or debug_types.
1784 INFO_PTR is a pointer to the start of the CU.
1785 Returns a pointer to the next CU. */
1788 process_psymtab_comp_unit (struct objfile
*objfile
,
1789 struct dwarf2_per_cu_data
*this_cu
,
1790 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1791 unsigned int buffer_size
)
1793 bfd
*abfd
= objfile
->obfd
;
1794 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1795 struct die_info
*comp_unit_die
;
1796 struct partial_symtab
*pst
;
1798 struct cleanup
*back_to_inner
;
1799 struct dwarf2_cu cu
;
1800 int has_children
, has_pc_info
;
1801 struct attribute
*attr
;
1802 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
1803 struct die_reader_specs reader_specs
;
1805 memset (&cu
, 0, sizeof (cu
));
1806 cu
.objfile
= objfile
;
1807 obstack_init (&cu
.comp_unit_obstack
);
1809 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1811 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1812 buffer
, buffer_size
,
1815 /* Complete the cu_header. */
1816 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1817 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1819 cu
.list_in_scope
= &file_symbols
;
1821 /* If this compilation unit was already read in, free the
1822 cached copy in order to read it in again. This is
1823 necessary because we skipped some symbols when we first
1824 read in the compilation unit (see load_partial_dies).
1825 This problem could be avoided, but the benefit is
1827 if (this_cu
->cu
!= NULL
)
1828 free_one_cached_comp_unit (this_cu
->cu
);
1830 /* Note that this is a pointer to our stack frame, being
1831 added to a global data structure. It will be cleaned up
1832 in free_stack_comp_unit when we finish with this
1833 compilation unit. */
1835 cu
.per_cu
= this_cu
;
1837 /* Read the abbrevs for this compilation unit into a table. */
1838 dwarf2_read_abbrevs (abfd
, &cu
);
1839 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1841 /* Read the compilation unit die. */
1842 if (this_cu
->from_debug_types
)
1843 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1844 init_cu_die_reader (&reader_specs
, &cu
);
1845 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1848 if (this_cu
->from_debug_types
)
1850 /* offset,length haven't been set yet for type units. */
1851 this_cu
->offset
= cu
.header
.offset
;
1852 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
1854 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
1856 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1857 + cu
.header
.initial_length_size
);
1858 do_cleanups (back_to_inner
);
1862 /* Set the language we're debugging. */
1863 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
1865 set_cu_language (DW_UNSND (attr
), &cu
);
1867 set_cu_language (language_minimal
, &cu
);
1869 /* Allocate a new partial symbol table structure. */
1870 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
1871 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1872 (attr
!= NULL
) ? DW_STRING (attr
) : "",
1873 /* TEXTLOW and TEXTHIGH are set below. */
1875 objfile
->global_psymbols
.next
,
1876 objfile
->static_psymbols
.next
);
1878 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
1880 pst
->dirname
= DW_STRING (attr
);
1882 pst
->read_symtab_private
= this_cu
;
1884 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1886 /* Store the function that reads in the rest of the symbol table */
1887 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1889 this_cu
->psymtab
= pst
;
1891 dwarf2_find_base_address (comp_unit_die
, &cu
);
1893 /* Possibly set the default values of LOWPC and HIGHPC from
1895 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
1896 &best_highpc
, &cu
, pst
);
1897 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
1898 /* Store the contiguous range if it is not empty; it can be empty for
1899 CUs with no code. */
1900 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1901 best_lowpc
+ baseaddr
,
1902 best_highpc
+ baseaddr
- 1, pst
);
1904 /* Check if comp unit has_children.
1905 If so, read the rest of the partial symbols from this comp unit.
1906 If not, there's no more debug_info for this comp unit. */
1909 struct partial_die_info
*first_die
;
1910 CORE_ADDR lowpc
, highpc
;
1912 lowpc
= ((CORE_ADDR
) -1);
1913 highpc
= ((CORE_ADDR
) 0);
1915 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
1917 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1918 ! has_pc_info
, &cu
);
1920 /* If we didn't find a lowpc, set it to highpc to avoid
1921 complaints from `maint check'. */
1922 if (lowpc
== ((CORE_ADDR
) -1))
1925 /* If the compilation unit didn't have an explicit address range,
1926 then use the information extracted from its child dies. */
1930 best_highpc
= highpc
;
1933 pst
->textlow
= best_lowpc
+ baseaddr
;
1934 pst
->texthigh
= best_highpc
+ baseaddr
;
1936 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1937 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1938 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1939 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1940 sort_pst_symbols (pst
);
1942 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1943 + cu
.header
.initial_length_size
);
1945 if (this_cu
->from_debug_types
)
1947 /* It's not clear we want to do anything with stmt lists here.
1948 Waiting to see what gcc ultimately does. */
1952 /* Get the list of files included in the current compilation unit,
1953 and build a psymtab for each of them. */
1954 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
1957 do_cleanups (back_to_inner
);
1962 /* Traversal function for htab_traverse_noresize.
1963 Process one .debug_types comp-unit. */
1966 process_type_comp_unit (void **slot
, void *info
)
1968 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
1969 struct objfile
*objfile
= (struct objfile
*) info
;
1970 struct dwarf2_per_cu_data
*this_cu
;
1972 this_cu
= &entry
->per_cu
;
1973 this_cu
->from_debug_types
= 1;
1975 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1976 process_psymtab_comp_unit (objfile
, this_cu
,
1977 dwarf2_per_objfile
->types
.buffer
,
1978 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
1979 dwarf2_per_objfile
->types
.size
);
1984 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
1985 Build partial symbol tables for the .debug_types comp-units. */
1988 build_type_psymtabs (struct objfile
*objfile
)
1990 if (! create_debug_types_hash_table (objfile
))
1993 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
1994 process_type_comp_unit
, objfile
);
1997 /* Build the partial symbol table by doing a quick pass through the
1998 .debug_info and .debug_abbrev sections. */
2001 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
2004 struct cleanup
*back_to
;
2006 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2007 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2009 /* Any cached compilation units will be linked by the per-objfile
2010 read_in_chain. Make sure to free them when we're done. */
2011 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2013 build_type_psymtabs (objfile
);
2015 create_all_comp_units (objfile
);
2017 objfile
->psymtabs_addrmap
=
2018 addrmap_create_mutable (&objfile
->objfile_obstack
);
2020 /* Since the objects we're extracting from .debug_info vary in
2021 length, only the individual functions to extract them (like
2022 read_comp_unit_head and load_partial_die) can really know whether
2023 the buffer is large enough to hold another complete object.
2025 At the moment, they don't actually check that. If .debug_info
2026 holds just one extra byte after the last compilation unit's dies,
2027 then read_comp_unit_head will happily read off the end of the
2028 buffer. read_partial_die is similarly casual. Those functions
2031 For this loop condition, simply checking whether there's any data
2032 left at all should be sufficient. */
2034 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
2035 + dwarf2_per_objfile
->info
.size
))
2037 struct dwarf2_per_cu_data
*this_cu
;
2039 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
2042 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
2043 dwarf2_per_objfile
->info
.buffer
,
2045 dwarf2_per_objfile
->info
.size
);
2048 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
2049 &objfile
->objfile_obstack
);
2051 do_cleanups (back_to
);
2054 /* Load the partial DIEs for a secondary CU into memory. */
2057 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
2058 struct objfile
*objfile
)
2060 bfd
*abfd
= objfile
->obfd
;
2061 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
2062 struct die_info
*comp_unit_die
;
2063 struct dwarf2_cu
*cu
;
2064 struct cleanup
*back_to
;
2065 struct attribute
*attr
;
2067 struct die_reader_specs reader_specs
;
2069 gdb_assert (! this_cu
->from_debug_types
);
2071 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2072 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
2073 beg_of_comp_unit
= info_ptr
;
2075 cu
= alloc_one_comp_unit (objfile
);
2077 /* ??? Missing cleanup for CU? */
2079 /* Link this compilation unit into the compilation unit tree. */
2081 cu
->per_cu
= this_cu
;
2082 cu
->type_hash
= this_cu
->type_hash
;
2084 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
2085 dwarf2_per_objfile
->info
.buffer
,
2086 dwarf2_per_objfile
->info
.size
,
2089 /* Complete the cu_header. */
2090 cu
->header
.offset
= this_cu
->offset
;
2091 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2093 /* Read the abbrevs for this compilation unit into a table. */
2094 dwarf2_read_abbrevs (abfd
, cu
);
2095 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2097 /* Read the compilation unit die. */
2098 init_cu_die_reader (&reader_specs
, cu
);
2099 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2102 /* Set the language we're debugging. */
2103 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
2105 set_cu_language (DW_UNSND (attr
), cu
);
2107 set_cu_language (language_minimal
, cu
);
2109 /* Check if comp unit has_children.
2110 If so, read the rest of the partial symbols from this comp unit.
2111 If not, there's no more debug_info for this comp unit. */
2113 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
2115 do_cleanups (back_to
);
2118 /* Create a list of all compilation units in OBJFILE. We do this only
2119 if an inter-comp-unit reference is found; presumably if there is one,
2120 there will be many, and one will occur early in the .debug_info section.
2121 So there's no point in building this list incrementally. */
2124 create_all_comp_units (struct objfile
*objfile
)
2128 struct dwarf2_per_cu_data
**all_comp_units
;
2131 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2132 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2136 all_comp_units
= xmalloc (n_allocated
2137 * sizeof (struct dwarf2_per_cu_data
*));
2139 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
2141 unsigned int length
, initial_length_size
;
2142 struct dwarf2_per_cu_data
*this_cu
;
2143 unsigned int offset
;
2145 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
2147 /* Read just enough information to find out where the next
2148 compilation unit is. */
2149 length
= read_initial_length (objfile
->obfd
, info_ptr
,
2150 &initial_length_size
);
2152 /* Save the compilation unit for later lookup. */
2153 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
2154 sizeof (struct dwarf2_per_cu_data
));
2155 memset (this_cu
, 0, sizeof (*this_cu
));
2156 this_cu
->offset
= offset
;
2157 this_cu
->length
= length
+ initial_length_size
;
2159 if (n_comp_units
== n_allocated
)
2162 all_comp_units
= xrealloc (all_comp_units
,
2164 * sizeof (struct dwarf2_per_cu_data
*));
2166 all_comp_units
[n_comp_units
++] = this_cu
;
2168 info_ptr
= info_ptr
+ this_cu
->length
;
2171 dwarf2_per_objfile
->all_comp_units
2172 = obstack_alloc (&objfile
->objfile_obstack
,
2173 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2174 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
2175 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2176 xfree (all_comp_units
);
2177 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
2180 /* Process all loaded DIEs for compilation unit CU, starting at
2181 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2182 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2183 DW_AT_ranges). If NEED_PC is set, then this function will set
2184 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2185 and record the covered ranges in the addrmap. */
2188 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
2189 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2191 struct partial_die_info
*pdi
;
2193 /* Now, march along the PDI's, descending into ones which have
2194 interesting children but skipping the children of the other ones,
2195 until we reach the end of the compilation unit. */
2201 fixup_partial_die (pdi
, cu
);
2203 /* Anonymous namespaces have no name but have interesting
2204 children, so we need to look at them. Ditto for anonymous
2207 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
2208 || pdi
->tag
== DW_TAG_enumeration_type
)
2212 case DW_TAG_subprogram
:
2213 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2215 case DW_TAG_variable
:
2216 case DW_TAG_typedef
:
2217 case DW_TAG_union_type
:
2218 if (!pdi
->is_declaration
)
2220 add_partial_symbol (pdi
, cu
);
2223 case DW_TAG_class_type
:
2224 case DW_TAG_interface_type
:
2225 case DW_TAG_structure_type
:
2226 if (!pdi
->is_declaration
)
2228 add_partial_symbol (pdi
, cu
);
2231 case DW_TAG_enumeration_type
:
2232 if (!pdi
->is_declaration
)
2233 add_partial_enumeration (pdi
, cu
);
2235 case DW_TAG_base_type
:
2236 case DW_TAG_subrange_type
:
2237 /* File scope base type definitions are added to the partial
2239 add_partial_symbol (pdi
, cu
);
2241 case DW_TAG_namespace
:
2242 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
2245 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
2252 /* If the die has a sibling, skip to the sibling. */
2254 pdi
= pdi
->die_sibling
;
2258 /* Functions used to compute the fully scoped name of a partial DIE.
2260 Normally, this is simple. For C++, the parent DIE's fully scoped
2261 name is concatenated with "::" and the partial DIE's name. For
2262 Java, the same thing occurs except that "." is used instead of "::".
2263 Enumerators are an exception; they use the scope of their parent
2264 enumeration type, i.e. the name of the enumeration type is not
2265 prepended to the enumerator.
2267 There are two complexities. One is DW_AT_specification; in this
2268 case "parent" means the parent of the target of the specification,
2269 instead of the direct parent of the DIE. The other is compilers
2270 which do not emit DW_TAG_namespace; in this case we try to guess
2271 the fully qualified name of structure types from their members'
2272 linkage names. This must be done using the DIE's children rather
2273 than the children of any DW_AT_specification target. We only need
2274 to do this for structures at the top level, i.e. if the target of
2275 any DW_AT_specification (if any; otherwise the DIE itself) does not
2278 /* Compute the scope prefix associated with PDI's parent, in
2279 compilation unit CU. The result will be allocated on CU's
2280 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2281 field. NULL is returned if no prefix is necessary. */
2283 partial_die_parent_scope (struct partial_die_info
*pdi
,
2284 struct dwarf2_cu
*cu
)
2286 char *grandparent_scope
;
2287 struct partial_die_info
*parent
, *real_pdi
;
2289 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2290 then this means the parent of the specification DIE. */
2293 while (real_pdi
->has_specification
)
2294 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2296 parent
= real_pdi
->die_parent
;
2300 if (parent
->scope_set
)
2301 return parent
->scope
;
2303 fixup_partial_die (parent
, cu
);
2305 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2307 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
2308 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
2309 Work around this problem here. */
2310 if (cu
->language
== language_cplus
2311 && parent
->tag
== DW_TAG_namespace
2312 && strcmp (parent
->name
, "::") == 0
2313 && grandparent_scope
== NULL
)
2315 parent
->scope
= NULL
;
2316 parent
->scope_set
= 1;
2320 if (parent
->tag
== DW_TAG_namespace
2321 || parent
->tag
== DW_TAG_structure_type
2322 || parent
->tag
== DW_TAG_class_type
2323 || parent
->tag
== DW_TAG_interface_type
2324 || parent
->tag
== DW_TAG_union_type
2325 || parent
->tag
== DW_TAG_enumeration_type
)
2327 if (grandparent_scope
== NULL
)
2328 parent
->scope
= parent
->name
;
2330 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2333 else if (parent
->tag
== DW_TAG_enumerator
)
2334 /* Enumerators should not get the name of the enumeration as a prefix. */
2335 parent
->scope
= grandparent_scope
;
2338 /* FIXME drow/2004-04-01: What should we be doing with
2339 function-local names? For partial symbols, we should probably be
2341 complaint (&symfile_complaints
,
2342 _("unhandled containing DIE tag %d for DIE at %d"),
2343 parent
->tag
, pdi
->offset
);
2344 parent
->scope
= grandparent_scope
;
2347 parent
->scope_set
= 1;
2348 return parent
->scope
;
2351 /* Return the fully scoped name associated with PDI, from compilation unit
2352 CU. The result will be allocated with malloc. */
2354 partial_die_full_name (struct partial_die_info
*pdi
,
2355 struct dwarf2_cu
*cu
)
2359 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2360 if (parent_scope
== NULL
)
2363 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2367 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2369 struct objfile
*objfile
= cu
->objfile
;
2371 char *actual_name
= NULL
;
2372 const struct partial_symbol
*psym
= NULL
;
2374 int built_actual_name
= 0;
2376 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2378 actual_name
= partial_die_full_name (pdi
, cu
);
2380 built_actual_name
= 1;
2382 if (actual_name
== NULL
)
2383 actual_name
= pdi
->name
;
2387 case DW_TAG_subprogram
:
2388 if (pdi
->is_external
|| cu
->language
== language_ada
)
2390 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2391 of the global scope. But in Ada, we want to be able to access
2392 nested procedures globally. So all Ada subprograms are stored
2393 in the global scope. */
2394 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2395 mst_text, objfile); */
2396 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2398 VAR_DOMAIN
, LOC_BLOCK
,
2399 &objfile
->global_psymbols
,
2400 0, pdi
->lowpc
+ baseaddr
,
2401 cu
->language
, objfile
);
2405 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2406 mst_file_text, objfile); */
2407 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2409 VAR_DOMAIN
, LOC_BLOCK
,
2410 &objfile
->static_psymbols
,
2411 0, pdi
->lowpc
+ baseaddr
,
2412 cu
->language
, objfile
);
2415 case DW_TAG_variable
:
2416 if (pdi
->is_external
)
2419 Don't enter into the minimal symbol tables as there is
2420 a minimal symbol table entry from the ELF symbols already.
2421 Enter into partial symbol table if it has a location
2422 descriptor or a type.
2423 If the location descriptor is missing, new_symbol will create
2424 a LOC_UNRESOLVED symbol, the address of the variable will then
2425 be determined from the minimal symbol table whenever the variable
2427 The address for the partial symbol table entry is not
2428 used by GDB, but it comes in handy for debugging partial symbol
2432 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2433 if (pdi
->locdesc
|| pdi
->has_type
)
2434 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2436 VAR_DOMAIN
, LOC_STATIC
,
2437 &objfile
->global_psymbols
,
2439 cu
->language
, objfile
);
2443 /* Static Variable. Skip symbols without location descriptors. */
2444 if (pdi
->locdesc
== NULL
)
2446 if (built_actual_name
)
2447 xfree (actual_name
);
2450 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2451 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2452 mst_file_data, objfile); */
2453 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2455 VAR_DOMAIN
, LOC_STATIC
,
2456 &objfile
->static_psymbols
,
2458 cu
->language
, objfile
);
2461 case DW_TAG_typedef
:
2462 case DW_TAG_base_type
:
2463 case DW_TAG_subrange_type
:
2464 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2466 VAR_DOMAIN
, LOC_TYPEDEF
,
2467 &objfile
->static_psymbols
,
2468 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2470 case DW_TAG_namespace
:
2471 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2473 VAR_DOMAIN
, LOC_TYPEDEF
,
2474 &objfile
->global_psymbols
,
2475 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2477 case DW_TAG_class_type
:
2478 case DW_TAG_interface_type
:
2479 case DW_TAG_structure_type
:
2480 case DW_TAG_union_type
:
2481 case DW_TAG_enumeration_type
:
2482 /* Skip external references. The DWARF standard says in the section
2483 about "Structure, Union, and Class Type Entries": "An incomplete
2484 structure, union or class type is represented by a structure,
2485 union or class entry that does not have a byte size attribute
2486 and that has a DW_AT_declaration attribute." */
2487 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2489 if (built_actual_name
)
2490 xfree (actual_name
);
2494 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2495 static vs. global. */
2496 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2498 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2499 (cu
->language
== language_cplus
2500 || cu
->language
== language_java
)
2501 ? &objfile
->global_psymbols
2502 : &objfile
->static_psymbols
,
2503 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2506 case DW_TAG_enumerator
:
2507 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2509 VAR_DOMAIN
, LOC_CONST
,
2510 (cu
->language
== language_cplus
2511 || cu
->language
== language_java
)
2512 ? &objfile
->global_psymbols
2513 : &objfile
->static_psymbols
,
2514 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2520 if (built_actual_name
)
2521 xfree (actual_name
);
2524 /* Read a partial die corresponding to a namespace; also, add a symbol
2525 corresponding to that namespace to the symbol table. NAMESPACE is
2526 the name of the enclosing namespace. */
2529 add_partial_namespace (struct partial_die_info
*pdi
,
2530 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2531 int need_pc
, struct dwarf2_cu
*cu
)
2533 /* Add a symbol for the namespace. */
2535 add_partial_symbol (pdi
, cu
);
2537 /* Now scan partial symbols in that namespace. */
2539 if (pdi
->has_children
)
2540 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2543 /* Read a partial die corresponding to a Fortran module. */
2546 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2547 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2549 /* Now scan partial symbols in that module.
2551 FIXME: Support the separate Fortran module namespaces. */
2553 if (pdi
->has_children
)
2554 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2557 /* Read a partial die corresponding to a subprogram and create a partial
2558 symbol for that subprogram. When the CU language allows it, this
2559 routine also defines a partial symbol for each nested subprogram
2560 that this subprogram contains.
2562 DIE my also be a lexical block, in which case we simply search
2563 recursively for suprograms defined inside that lexical block.
2564 Again, this is only performed when the CU language allows this
2565 type of definitions. */
2568 add_partial_subprogram (struct partial_die_info
*pdi
,
2569 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2570 int need_pc
, struct dwarf2_cu
*cu
)
2572 if (pdi
->tag
== DW_TAG_subprogram
)
2574 if (pdi
->has_pc_info
)
2576 if (pdi
->lowpc
< *lowpc
)
2577 *lowpc
= pdi
->lowpc
;
2578 if (pdi
->highpc
> *highpc
)
2579 *highpc
= pdi
->highpc
;
2583 struct objfile
*objfile
= cu
->objfile
;
2585 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2586 SECT_OFF_TEXT (objfile
));
2587 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2588 pdi
->lowpc
+ baseaddr
,
2589 pdi
->highpc
- 1 + baseaddr
,
2590 cu
->per_cu
->psymtab
);
2592 if (!pdi
->is_declaration
)
2593 /* Ignore subprogram DIEs that do not have a name, they are
2594 illegal. Do not emit a complaint at this point, we will
2595 do so when we convert this psymtab into a symtab. */
2597 add_partial_symbol (pdi
, cu
);
2601 if (! pdi
->has_children
)
2604 if (cu
->language
== language_ada
)
2606 pdi
= pdi
->die_child
;
2609 fixup_partial_die (pdi
, cu
);
2610 if (pdi
->tag
== DW_TAG_subprogram
2611 || pdi
->tag
== DW_TAG_lexical_block
)
2612 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2613 pdi
= pdi
->die_sibling
;
2618 /* See if we can figure out if the class lives in a namespace. We do
2619 this by looking for a member function; its demangled name will
2620 contain namespace info, if there is any. */
2623 guess_structure_name (struct partial_die_info
*struct_pdi
,
2624 struct dwarf2_cu
*cu
)
2626 if ((cu
->language
== language_cplus
2627 || cu
->language
== language_java
)
2628 && cu
->has_namespace_info
== 0
2629 && struct_pdi
->has_children
)
2631 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2632 what template types look like, because the demangler
2633 frequently doesn't give the same name as the debug info. We
2634 could fix this by only using the demangled name to get the
2635 prefix (but see comment in read_structure_type). */
2637 struct partial_die_info
*real_pdi
;
2639 /* If this DIE (this DIE's specification, if any) has a parent, then
2640 we should not do this. We'll prepend the parent's fully qualified
2641 name when we create the partial symbol. */
2643 real_pdi
= struct_pdi
;
2644 while (real_pdi
->has_specification
)
2645 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2647 if (real_pdi
->die_parent
!= NULL
)
2652 /* Read a partial die corresponding to an enumeration type. */
2655 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2656 struct dwarf2_cu
*cu
)
2658 struct partial_die_info
*pdi
;
2660 if (enum_pdi
->name
!= NULL
)
2661 add_partial_symbol (enum_pdi
, cu
);
2663 pdi
= enum_pdi
->die_child
;
2666 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2667 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2669 add_partial_symbol (pdi
, cu
);
2670 pdi
= pdi
->die_sibling
;
2674 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2675 Return the corresponding abbrev, or NULL if the number is zero (indicating
2676 an empty DIE). In either case *BYTES_READ will be set to the length of
2677 the initial number. */
2679 static struct abbrev_info
*
2680 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2681 struct dwarf2_cu
*cu
)
2683 bfd
*abfd
= cu
->objfile
->obfd
;
2684 unsigned int abbrev_number
;
2685 struct abbrev_info
*abbrev
;
2687 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2689 if (abbrev_number
== 0)
2692 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2695 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2696 bfd_get_filename (abfd
));
2702 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2703 Returns a pointer to the end of a series of DIEs, terminated by an empty
2704 DIE. Any children of the skipped DIEs will also be skipped. */
2707 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2709 struct abbrev_info
*abbrev
;
2710 unsigned int bytes_read
;
2714 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2716 return info_ptr
+ bytes_read
;
2718 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
2722 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2723 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2724 abbrev corresponding to that skipped uleb128 should be passed in
2725 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2729 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2730 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
2732 unsigned int bytes_read
;
2733 struct attribute attr
;
2734 bfd
*abfd
= cu
->objfile
->obfd
;
2735 unsigned int form
, i
;
2737 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2739 /* The only abbrev we care about is DW_AT_sibling. */
2740 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2742 read_attribute (&attr
, &abbrev
->attrs
[i
],
2743 abfd
, info_ptr
, cu
);
2744 if (attr
.form
== DW_FORM_ref_addr
)
2745 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2747 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
2750 /* If it isn't DW_AT_sibling, skip this attribute. */
2751 form
= abbrev
->attrs
[i
].form
;
2755 case DW_FORM_ref_addr
:
2756 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2757 and later it is offset sized. */
2758 if (cu
->header
.version
== 2)
2759 info_ptr
+= cu
->header
.addr_size
;
2761 info_ptr
+= cu
->header
.offset_size
;
2764 info_ptr
+= cu
->header
.addr_size
;
2771 case DW_FORM_flag_present
:
2786 case DW_FORM_string
:
2787 read_string (abfd
, info_ptr
, &bytes_read
);
2788 info_ptr
+= bytes_read
;
2790 case DW_FORM_sec_offset
:
2792 info_ptr
+= cu
->header
.offset_size
;
2794 case DW_FORM_exprloc
:
2796 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2797 info_ptr
+= bytes_read
;
2799 case DW_FORM_block1
:
2800 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2802 case DW_FORM_block2
:
2803 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2805 case DW_FORM_block4
:
2806 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2810 case DW_FORM_ref_udata
:
2811 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2813 case DW_FORM_indirect
:
2814 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2815 info_ptr
+= bytes_read
;
2816 /* We need to continue parsing from here, so just go back to
2818 goto skip_attribute
;
2821 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2822 dwarf_form_name (form
),
2823 bfd_get_filename (abfd
));
2827 if (abbrev
->has_children
)
2828 return skip_children (buffer
, info_ptr
, cu
);
2833 /* Locate ORIG_PDI's sibling.
2834 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2838 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
2839 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2840 bfd
*abfd
, struct dwarf2_cu
*cu
)
2842 /* Do we know the sibling already? */
2844 if (orig_pdi
->sibling
)
2845 return orig_pdi
->sibling
;
2847 /* Are there any children to deal with? */
2849 if (!orig_pdi
->has_children
)
2852 /* Skip the children the long way. */
2854 return skip_children (buffer
, info_ptr
, cu
);
2857 /* Expand this partial symbol table into a full symbol table. */
2860 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2862 /* FIXME: This is barely more than a stub. */
2867 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2873 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2874 gdb_flush (gdb_stdout
);
2877 /* Restore our global data. */
2878 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2879 dwarf2_objfile_data_key
);
2881 /* If this psymtab is constructed from a debug-only objfile, the
2882 has_section_at_zero flag will not necessarily be correct. We
2883 can get the correct value for this flag by looking at the data
2884 associated with the (presumably stripped) associated objfile. */
2885 if (pst
->objfile
->separate_debug_objfile_backlink
)
2887 struct dwarf2_per_objfile
*dpo_backlink
2888 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2889 dwarf2_objfile_data_key
);
2891 dwarf2_per_objfile
->has_section_at_zero
2892 = dpo_backlink
->has_section_at_zero
;
2895 psymtab_to_symtab_1 (pst
);
2897 /* Finish up the debug error message. */
2899 printf_filtered (_("done.\n"));
2904 /* Add PER_CU to the queue. */
2907 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2909 struct dwarf2_queue_item
*item
;
2912 item
= xmalloc (sizeof (*item
));
2913 item
->per_cu
= per_cu
;
2916 if (dwarf2_queue
== NULL
)
2917 dwarf2_queue
= item
;
2919 dwarf2_queue_tail
->next
= item
;
2921 dwarf2_queue_tail
= item
;
2924 /* Process the queue. */
2927 process_queue (struct objfile
*objfile
)
2929 struct dwarf2_queue_item
*item
, *next_item
;
2931 /* The queue starts out with one item, but following a DIE reference
2932 may load a new CU, adding it to the end of the queue. */
2933 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2935 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2936 process_full_comp_unit (item
->per_cu
);
2938 item
->per_cu
->queued
= 0;
2939 next_item
= item
->next
;
2943 dwarf2_queue_tail
= NULL
;
2946 /* Free all allocated queue entries. This function only releases anything if
2947 an error was thrown; if the queue was processed then it would have been
2948 freed as we went along. */
2951 dwarf2_release_queue (void *dummy
)
2953 struct dwarf2_queue_item
*item
, *last
;
2955 item
= dwarf2_queue
;
2958 /* Anything still marked queued is likely to be in an
2959 inconsistent state, so discard it. */
2960 if (item
->per_cu
->queued
)
2962 if (item
->per_cu
->cu
!= NULL
)
2963 free_one_cached_comp_unit (item
->per_cu
->cu
);
2964 item
->per_cu
->queued
= 0;
2972 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2975 /* Read in full symbols for PST, and anything it depends on. */
2978 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2980 struct dwarf2_per_cu_data
*per_cu
;
2981 struct cleanup
*back_to
;
2984 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2985 if (!pst
->dependencies
[i
]->readin
)
2987 /* Inform about additional files that need to be read in. */
2990 /* FIXME: i18n: Need to make this a single string. */
2991 fputs_filtered (" ", gdb_stdout
);
2993 fputs_filtered ("and ", gdb_stdout
);
2995 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2996 wrap_here (""); /* Flush output */
2997 gdb_flush (gdb_stdout
);
2999 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
3002 per_cu
= pst
->read_symtab_private
;
3006 /* It's an include file, no symbols to read for it.
3007 Everything is in the parent symtab. */
3012 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
3014 queue_comp_unit (per_cu
, pst
->objfile
);
3016 if (per_cu
->from_debug_types
)
3017 read_signatured_type_at_offset (pst
->objfile
, per_cu
->offset
);
3019 load_full_comp_unit (per_cu
, pst
->objfile
);
3021 process_queue (pst
->objfile
);
3023 /* Age the cache, releasing compilation units that have not
3024 been used recently. */
3025 age_cached_comp_units ();
3027 do_cleanups (back_to
);
3030 /* Load the DIEs associated with PER_CU into memory. */
3033 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3035 bfd
*abfd
= objfile
->obfd
;
3036 struct dwarf2_cu
*cu
;
3037 unsigned int offset
;
3038 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3039 struct cleanup
*back_to
, *free_cu_cleanup
;
3040 struct attribute
*attr
;
3042 gdb_assert (! per_cu
->from_debug_types
);
3044 /* Set local variables from the partial symbol table info. */
3045 offset
= per_cu
->offset
;
3047 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3048 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
3049 beg_of_comp_unit
= info_ptr
;
3051 cu
= alloc_one_comp_unit (objfile
);
3053 /* If an error occurs while loading, release our storage. */
3054 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3056 /* Read in the comp_unit header. */
3057 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
3059 /* Complete the cu_header. */
3060 cu
->header
.offset
= offset
;
3061 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3063 /* Read the abbrevs for this compilation unit. */
3064 dwarf2_read_abbrevs (abfd
, cu
);
3065 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3067 /* Link this compilation unit into the compilation unit tree. */
3069 cu
->per_cu
= per_cu
;
3070 cu
->type_hash
= per_cu
->type_hash
;
3072 cu
->dies
= read_comp_unit (info_ptr
, cu
);
3074 /* We try not to read any attributes in this function, because not
3075 all objfiles needed for references have been loaded yet, and symbol
3076 table processing isn't initialized. But we have to set the CU language,
3077 or we won't be able to build types correctly. */
3078 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
3080 set_cu_language (DW_UNSND (attr
), cu
);
3082 set_cu_language (language_minimal
, cu
);
3084 /* Similarly, if we do not read the producer, we can not apply
3085 producer-specific interpretation. */
3086 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
3088 cu
->producer
= DW_STRING (attr
);
3090 /* Link this CU into read_in_chain. */
3091 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3092 dwarf2_per_objfile
->read_in_chain
= per_cu
;
3094 do_cleanups (back_to
);
3096 /* We've successfully allocated this compilation unit. Let our caller
3097 clean it up when finished with it. */
3098 discard_cleanups (free_cu_cleanup
);
3101 /* Generate full symbol information for PST and CU, whose DIEs have
3102 already been loaded into memory. */
3105 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
3107 struct partial_symtab
*pst
= per_cu
->psymtab
;
3108 struct dwarf2_cu
*cu
= per_cu
->cu
;
3109 struct objfile
*objfile
= pst
->objfile
;
3110 CORE_ADDR lowpc
, highpc
;
3111 struct symtab
*symtab
;
3112 struct cleanup
*back_to
;
3115 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3118 back_to
= make_cleanup (really_free_pendings
, NULL
);
3120 cu
->list_in_scope
= &file_symbols
;
3122 dwarf2_find_base_address (cu
->dies
, cu
);
3124 /* Do line number decoding in read_file_scope () */
3125 process_die (cu
->dies
, cu
);
3127 /* Some compilers don't define a DW_AT_high_pc attribute for the
3128 compilation unit. If the DW_AT_high_pc is missing, synthesize
3129 it, by scanning the DIE's below the compilation unit. */
3130 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
3132 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
3134 /* Set symtab language to language from DW_AT_language.
3135 If the compilation is from a C file generated by language preprocessors,
3136 do not set the language if it was already deduced by start_subfile. */
3138 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
3140 symtab
->language
= cu
->language
;
3142 pst
->symtab
= symtab
;
3145 do_cleanups (back_to
);
3148 /* Process a die and its children. */
3151 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
3155 case DW_TAG_padding
:
3157 case DW_TAG_compile_unit
:
3158 read_file_scope (die
, cu
);
3160 case DW_TAG_type_unit
:
3161 read_type_unit_scope (die
, cu
);
3163 case DW_TAG_subprogram
:
3164 case DW_TAG_inlined_subroutine
:
3165 read_func_scope (die
, cu
);
3167 case DW_TAG_lexical_block
:
3168 case DW_TAG_try_block
:
3169 case DW_TAG_catch_block
:
3170 read_lexical_block_scope (die
, cu
);
3172 case DW_TAG_class_type
:
3173 case DW_TAG_interface_type
:
3174 case DW_TAG_structure_type
:
3175 case DW_TAG_union_type
:
3176 process_structure_scope (die
, cu
);
3178 case DW_TAG_enumeration_type
:
3179 process_enumeration_scope (die
, cu
);
3182 /* These dies have a type, but processing them does not create
3183 a symbol or recurse to process the children. Therefore we can
3184 read them on-demand through read_type_die. */
3185 case DW_TAG_subroutine_type
:
3186 case DW_TAG_set_type
:
3187 case DW_TAG_array_type
:
3188 case DW_TAG_pointer_type
:
3189 case DW_TAG_ptr_to_member_type
:
3190 case DW_TAG_reference_type
:
3191 case DW_TAG_string_type
:
3194 case DW_TAG_base_type
:
3195 case DW_TAG_subrange_type
:
3196 case DW_TAG_typedef
:
3197 /* Add a typedef symbol for the type definition, if it has a
3199 new_symbol (die
, read_type_die (die
, cu
), cu
);
3201 case DW_TAG_common_block
:
3202 read_common_block (die
, cu
);
3204 case DW_TAG_common_inclusion
:
3206 case DW_TAG_namespace
:
3207 processing_has_namespace_info
= 1;
3208 read_namespace (die
, cu
);
3211 read_module (die
, cu
);
3213 case DW_TAG_imported_declaration
:
3214 case DW_TAG_imported_module
:
3215 processing_has_namespace_info
= 1;
3216 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
3217 || cu
->language
!= language_fortran
))
3218 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
3219 dwarf_tag_name (die
->tag
));
3220 read_import_statement (die
, cu
);
3223 new_symbol (die
, NULL
, cu
);
3228 /* A helper function for dwarf2_compute_name which determines whether DIE
3229 needs to have the name of the scope prepended to the name listed in the
3233 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3235 struct attribute
*attr
;
3239 case DW_TAG_namespace
:
3240 case DW_TAG_typedef
:
3241 case DW_TAG_class_type
:
3242 case DW_TAG_interface_type
:
3243 case DW_TAG_structure_type
:
3244 case DW_TAG_union_type
:
3245 case DW_TAG_enumeration_type
:
3246 case DW_TAG_enumerator
:
3247 case DW_TAG_subprogram
:
3251 case DW_TAG_variable
:
3252 /* We only need to prefix "globally" visible variables. These include
3253 any variable marked with DW_AT_external or any variable that
3254 lives in a namespace. [Variables in anonymous namespaces
3255 require prefixing, but they are not DW_AT_external.] */
3257 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
3259 struct dwarf2_cu
*spec_cu
= cu
;
3261 return die_needs_namespace (die_specification (die
, &spec_cu
),
3265 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
3266 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
)
3268 /* A variable in a lexical block of some kind does not need a
3269 namespace, even though in C++ such variables may be external
3270 and have a mangled name. */
3271 if (die
->parent
->tag
== DW_TAG_lexical_block
3272 || die
->parent
->tag
== DW_TAG_try_block
3273 || die
->parent
->tag
== DW_TAG_catch_block
3274 || die
->parent
->tag
== DW_TAG_subprogram
)
3283 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3284 compute the physname for the object, which include a method's
3285 formal parameters (C++/Java) and return type (Java).
3287 For Ada, return the DIE's linkage name rather than the fully qualified
3288 name. PHYSNAME is ignored..
3290 The result is allocated on the objfile_obstack and canonicalized. */
3293 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
3297 name
= dwarf2_name (die
, cu
);
3299 /* These are the only languages we know how to qualify names in. */
3301 && (cu
->language
== language_cplus
|| cu
->language
== language_java
))
3303 if (die_needs_namespace (die
, cu
))
3307 struct ui_file
*buf
;
3309 prefix
= determine_prefix (die
, cu
);
3310 buf
= mem_fileopen ();
3311 if (*prefix
!= '\0')
3313 char *prefixed_name
= typename_concat (NULL
, prefix
, name
, cu
);
3315 fputs_unfiltered (prefixed_name
, buf
);
3316 xfree (prefixed_name
);
3319 fputs_unfiltered (name
? name
: "", buf
);
3321 /* For Java and C++ methods, append formal parameter type
3322 information, if PHYSNAME. */
3324 if (physname
&& die
->tag
== DW_TAG_subprogram
3325 && (cu
->language
== language_cplus
3326 || cu
->language
== language_java
))
3328 struct type
*type
= read_type_die (die
, cu
);
3330 c_type_print_args (type
, buf
, 0, cu
->language
);
3332 if (cu
->language
== language_java
)
3334 /* For java, we must append the return type to method
3336 if (die
->tag
== DW_TAG_subprogram
)
3337 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
3340 else if (cu
->language
== language_cplus
)
3342 if (TYPE_NFIELDS (type
) > 0
3343 && TYPE_FIELD_ARTIFICIAL (type
, 0)
3344 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
3345 fputs_unfiltered (" const", buf
);
3349 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
3351 ui_file_delete (buf
);
3353 if (cu
->language
== language_cplus
)
3356 = dwarf2_canonicalize_name (name
, cu
,
3357 &cu
->objfile
->objfile_obstack
);
3364 else if (cu
->language
== language_ada
)
3366 /* For Ada unit, we prefer the linkage name over the name, as
3367 the former contains the exported name, which the user expects
3368 to be able to reference. Ideally, we want the user to be able
3369 to reference this entity using either natural or linkage name,
3370 but we haven't started looking at this enhancement yet. */
3371 struct attribute
*attr
;
3373 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
3375 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
3376 if (attr
&& DW_STRING (attr
))
3377 name
= DW_STRING (attr
);
3383 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3384 If scope qualifiers are appropriate they will be added. The result
3385 will be allocated on the objfile_obstack, or NULL if the DIE does
3386 not have a name. NAME may either be from a previous call to
3387 dwarf2_name or NULL.
3389 The output string will be canonicalized (if C++/Java). */
3392 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3394 return dwarf2_compute_name (name
, die
, cu
, 0);
3397 /* Construct a physname for the given DIE in CU. NAME may either be
3398 from a previous call to dwarf2_name or NULL. The result will be
3399 allocated on the objfile_objstack or NULL if the DIE does not have a
3402 The output string will be canonicalized (if C++/Java). */
3405 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3407 return dwarf2_compute_name (name
, die
, cu
, 1);
3410 /* Read the import statement specified by the given die and record it. */
3413 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3415 struct attribute
*import_attr
;
3416 struct die_info
*imported_die
;
3417 struct dwarf2_cu
*imported_cu
;
3418 const char *imported_name
;
3419 const char *imported_name_prefix
;
3420 const char *canonical_name
;
3421 const char *import_alias
;
3422 const char *imported_declaration
= NULL
;
3423 const char *import_prefix
;
3427 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3428 if (import_attr
== NULL
)
3430 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3431 dwarf_tag_name (die
->tag
));
3436 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
3437 imported_name
= dwarf2_name (imported_die
, imported_cu
);
3438 if (imported_name
== NULL
)
3440 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3442 The import in the following code:
3456 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3457 <52> DW_AT_decl_file : 1
3458 <53> DW_AT_decl_line : 6
3459 <54> DW_AT_import : <0x75>
3460 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3462 <5b> DW_AT_decl_file : 1
3463 <5c> DW_AT_decl_line : 2
3464 <5d> DW_AT_type : <0x6e>
3466 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3467 <76> DW_AT_byte_size : 4
3468 <77> DW_AT_encoding : 5 (signed)
3470 imports the wrong die ( 0x75 instead of 0x58 ).
3471 This case will be ignored until the gcc bug is fixed. */
3475 /* Figure out the local name after import. */
3476 import_alias
= dwarf2_name (die
, cu
);
3478 /* Figure out where the statement is being imported to. */
3479 import_prefix
= determine_prefix (die
, cu
);
3481 /* Figure out what the scope of the imported die is and prepend it
3482 to the name of the imported die. */
3483 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
3485 if (imported_die
->tag
!= DW_TAG_namespace
)
3487 imported_declaration
= imported_name
;
3488 canonical_name
= imported_name_prefix
;
3490 else if (strlen (imported_name_prefix
) > 0)
3492 temp
= alloca (strlen (imported_name_prefix
)
3493 + 2 + strlen (imported_name
) + 1);
3494 strcpy (temp
, imported_name_prefix
);
3495 strcat (temp
, "::");
3496 strcat (temp
, imported_name
);
3497 canonical_name
= temp
;
3500 canonical_name
= imported_name
;
3502 cp_add_using_directive (import_prefix
,
3505 imported_declaration
,
3506 &cu
->objfile
->objfile_obstack
);
3510 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3512 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3516 free_cu_line_header (void *arg
)
3518 struct dwarf2_cu
*cu
= arg
;
3520 free_line_header (cu
->line_header
);
3521 cu
->line_header
= NULL
;
3525 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3527 struct objfile
*objfile
= cu
->objfile
;
3528 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3529 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3530 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3531 struct attribute
*attr
;
3533 char *comp_dir
= NULL
;
3534 struct die_info
*child_die
;
3535 bfd
*abfd
= objfile
->obfd
;
3536 struct line_header
*line_header
= 0;
3539 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3541 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3543 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3544 from finish_block. */
3545 if (lowpc
== ((CORE_ADDR
) -1))
3550 /* Find the filename. Do not use dwarf2_name here, since the filename
3551 is not a source language identifier. */
3552 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3555 name
= DW_STRING (attr
);
3558 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3560 comp_dir
= DW_STRING (attr
);
3561 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3563 comp_dir
= ldirname (name
);
3564 if (comp_dir
!= NULL
)
3565 make_cleanup (xfree
, comp_dir
);
3567 if (comp_dir
!= NULL
)
3569 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3570 directory, get rid of it. */
3571 char *cp
= strchr (comp_dir
, ':');
3573 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3580 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3583 set_cu_language (DW_UNSND (attr
), cu
);
3586 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3588 cu
->producer
= DW_STRING (attr
);
3590 /* We assume that we're processing GCC output. */
3591 processing_gcc_compilation
= 2;
3593 processing_has_namespace_info
= 0;
3595 start_symtab (name
, comp_dir
, lowpc
);
3596 record_debugformat ("DWARF 2");
3597 record_producer (cu
->producer
);
3599 initialize_cu_func_list (cu
);
3601 /* Decode line number information if present. We do this before
3602 processing child DIEs, so that the line header table is available
3603 for DW_AT_decl_file. */
3604 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3607 unsigned int line_offset
= DW_UNSND (attr
);
3608 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3611 cu
->line_header
= line_header
;
3612 make_cleanup (free_cu_line_header
, cu
);
3613 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3617 /* Process all dies in compilation unit. */
3618 if (die
->child
!= NULL
)
3620 child_die
= die
->child
;
3621 while (child_die
&& child_die
->tag
)
3623 process_die (child_die
, cu
);
3624 child_die
= sibling_die (child_die
);
3628 /* Decode macro information, if present. Dwarf 2 macro information
3629 refers to information in the line number info statement program
3630 header, so we can only read it if we've read the header
3632 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3633 if (attr
&& line_header
)
3635 unsigned int macro_offset
= DW_UNSND (attr
);
3637 dwarf_decode_macros (line_header
, macro_offset
,
3638 comp_dir
, abfd
, cu
);
3640 do_cleanups (back_to
);
3643 /* For TUs we want to skip the first top level sibling if it's not the
3644 actual type being defined by this TU. In this case the first top
3645 level sibling is there to provide context only. */
3648 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3650 struct objfile
*objfile
= cu
->objfile
;
3651 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3653 struct attribute
*attr
;
3655 char *comp_dir
= NULL
;
3656 struct die_info
*child_die
;
3657 bfd
*abfd
= objfile
->obfd
;
3659 /* start_symtab needs a low pc, but we don't really have one.
3660 Do what read_file_scope would do in the absence of such info. */
3661 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3663 /* Find the filename. Do not use dwarf2_name here, since the filename
3664 is not a source language identifier. */
3665 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3667 name
= DW_STRING (attr
);
3669 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3671 comp_dir
= DW_STRING (attr
);
3672 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3674 comp_dir
= ldirname (name
);
3675 if (comp_dir
!= NULL
)
3676 make_cleanup (xfree
, comp_dir
);
3682 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3684 set_cu_language (DW_UNSND (attr
), cu
);
3686 /* This isn't technically needed today. It is done for symmetry
3687 with read_file_scope. */
3688 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3690 cu
->producer
= DW_STRING (attr
);
3692 /* We assume that we're processing GCC output. */
3693 processing_gcc_compilation
= 2;
3695 processing_has_namespace_info
= 0;
3697 start_symtab (name
, comp_dir
, lowpc
);
3698 record_debugformat ("DWARF 2");
3699 record_producer (cu
->producer
);
3701 /* Process the dies in the type unit. */
3702 if (die
->child
== NULL
)
3704 dump_die_for_error (die
);
3705 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3706 bfd_get_filename (abfd
));
3709 child_die
= die
->child
;
3711 while (child_die
&& child_die
->tag
)
3713 process_die (child_die
, cu
);
3715 child_die
= sibling_die (child_die
);
3718 do_cleanups (back_to
);
3722 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3723 struct dwarf2_cu
*cu
)
3725 struct function_range
*thisfn
;
3727 thisfn
= (struct function_range
*)
3728 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3729 thisfn
->name
= name
;
3730 thisfn
->lowpc
= lowpc
;
3731 thisfn
->highpc
= highpc
;
3732 thisfn
->seen_line
= 0;
3733 thisfn
->next
= NULL
;
3735 if (cu
->last_fn
== NULL
)
3736 cu
->first_fn
= thisfn
;
3738 cu
->last_fn
->next
= thisfn
;
3740 cu
->last_fn
= thisfn
;
3743 /* qsort helper for inherit_abstract_dies. */
3746 unsigned_int_compar (const void *ap
, const void *bp
)
3748 unsigned int a
= *(unsigned int *) ap
;
3749 unsigned int b
= *(unsigned int *) bp
;
3751 return (a
> b
) - (b
> a
);
3754 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3755 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3756 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3759 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3761 struct die_info
*child_die
;
3762 unsigned die_children_count
;
3763 /* CU offsets which were referenced by children of the current DIE. */
3765 unsigned *offsets_end
, *offsetp
;
3766 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3767 struct die_info
*origin_die
;
3768 /* Iterator of the ORIGIN_DIE children. */
3769 struct die_info
*origin_child_die
;
3770 struct cleanup
*cleanups
;
3771 struct attribute
*attr
;
3773 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3777 origin_die
= follow_die_ref (die
, attr
, &cu
);
3778 if (die
->tag
!= origin_die
->tag
3779 && !(die
->tag
== DW_TAG_inlined_subroutine
3780 && origin_die
->tag
== DW_TAG_subprogram
))
3781 complaint (&symfile_complaints
,
3782 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3783 die
->offset
, origin_die
->offset
);
3785 child_die
= die
->child
;
3786 die_children_count
= 0;
3787 while (child_die
&& child_die
->tag
)
3789 child_die
= sibling_die (child_die
);
3790 die_children_count
++;
3792 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3793 cleanups
= make_cleanup (xfree
, offsets
);
3795 offsets_end
= offsets
;
3796 child_die
= die
->child
;
3797 while (child_die
&& child_die
->tag
)
3799 /* For each CHILD_DIE, find the corresponding child of
3800 ORIGIN_DIE. If there is more than one layer of
3801 DW_AT_abstract_origin, follow them all; there shouldn't be,
3802 but GCC versions at least through 4.4 generate this (GCC PR
3804 struct die_info
*child_origin_die
= child_die
;
3808 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
3811 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
3814 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3815 counterpart may exist. */
3816 if (child_origin_die
!= child_die
)
3818 if (child_die
->tag
!= child_origin_die
->tag
3819 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3820 && child_origin_die
->tag
== DW_TAG_subprogram
))
3821 complaint (&symfile_complaints
,
3822 _("Child DIE 0x%x and its abstract origin 0x%x have "
3823 "different tags"), child_die
->offset
,
3824 child_origin_die
->offset
);
3825 if (child_origin_die
->parent
!= origin_die
)
3826 complaint (&symfile_complaints
,
3827 _("Child DIE 0x%x and its abstract origin 0x%x have "
3828 "different parents"), child_die
->offset
,
3829 child_origin_die
->offset
);
3831 *offsets_end
++ = child_origin_die
->offset
;
3833 child_die
= sibling_die (child_die
);
3835 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3836 unsigned_int_compar
);
3837 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3838 if (offsetp
[-1] == *offsetp
)
3839 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3840 "to DIE 0x%x as their abstract origin"),
3841 die
->offset
, *offsetp
);
3844 origin_child_die
= origin_die
->child
;
3845 while (origin_child_die
&& origin_child_die
->tag
)
3847 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3848 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3850 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3852 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3853 process_die (origin_child_die
, cu
);
3855 origin_child_die
= sibling_die (origin_child_die
);
3858 do_cleanups (cleanups
);
3862 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3864 struct objfile
*objfile
= cu
->objfile
;
3865 struct context_stack
*new;
3868 struct die_info
*child_die
;
3869 struct attribute
*attr
, *call_line
, *call_file
;
3872 struct block
*block
;
3873 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3877 /* If we do not have call site information, we can't show the
3878 caller of this inlined function. That's too confusing, so
3879 only use the scope for local variables. */
3880 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3881 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3882 if (call_line
== NULL
|| call_file
== NULL
)
3884 read_lexical_block_scope (die
, cu
);
3889 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3891 name
= dwarf2_name (die
, cu
);
3893 /* Ignore functions with missing or empty names. These are actually
3894 illegal according to the DWARF standard. */
3897 complaint (&symfile_complaints
,
3898 _("missing name for subprogram DIE at %d"), die
->offset
);
3902 /* Ignore functions with missing or invalid low and high pc attributes. */
3903 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3905 complaint (&symfile_complaints
,
3906 _("cannot get low and high bounds for subprogram DIE at %d"),
3914 /* Record the function range for dwarf_decode_lines. */
3915 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3917 new = push_context (0, lowpc
);
3918 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3920 /* If there is a location expression for DW_AT_frame_base, record
3922 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3924 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3925 expression is being recorded directly in the function's symbol
3926 and not in a separate frame-base object. I guess this hack is
3927 to avoid adding some sort of frame-base adjunct/annex to the
3928 function's symbol :-(. The problem with doing this is that it
3929 results in a function symbol with a location expression that
3930 has nothing to do with the location of the function, ouch! The
3931 relationship should be: a function's symbol has-a frame base; a
3932 frame-base has-a location expression. */
3933 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3935 cu
->list_in_scope
= &local_symbols
;
3937 if (die
->child
!= NULL
)
3939 child_die
= die
->child
;
3940 while (child_die
&& child_die
->tag
)
3942 process_die (child_die
, cu
);
3943 child_die
= sibling_die (child_die
);
3947 inherit_abstract_dies (die
, cu
);
3949 /* If we have a DW_AT_specification, we might need to import using
3950 directives from the context of the specification DIE. See the
3951 comment in determine_prefix. */
3952 if (cu
->language
== language_cplus
3953 && dwarf2_attr (die
, DW_AT_specification
, cu
))
3955 struct dwarf2_cu
*spec_cu
= cu
;
3956 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
3960 child_die
= spec_die
->child
;
3961 while (child_die
&& child_die
->tag
)
3963 if (child_die
->tag
== DW_TAG_imported_module
)
3964 process_die (child_die
, spec_cu
);
3965 child_die
= sibling_die (child_die
);
3968 /* In some cases, GCC generates specification DIEs that
3969 themselves contain DW_AT_specification attributes. */
3970 spec_die
= die_specification (spec_die
, &spec_cu
);
3974 new = pop_context ();
3975 /* Make a block for the local symbols within. */
3976 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3977 lowpc
, highpc
, objfile
);
3979 /* For C++, set the block's scope. */
3980 if (cu
->language
== language_cplus
)
3981 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3982 determine_prefix (die
, cu
),
3983 processing_has_namespace_info
);
3985 /* If we have address ranges, record them. */
3986 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3988 /* In C++, we can have functions nested inside functions (e.g., when
3989 a function declares a class that has methods). This means that
3990 when we finish processing a function scope, we may need to go
3991 back to building a containing block's symbol lists. */
3992 local_symbols
= new->locals
;
3993 param_symbols
= new->params
;
3994 using_directives
= new->using_directives
;
3996 /* If we've finished processing a top-level function, subsequent
3997 symbols go in the file symbol list. */
3998 if (outermost_context_p ())
3999 cu
->list_in_scope
= &file_symbols
;
4002 /* Process all the DIES contained within a lexical block scope. Start
4003 a new scope, process the dies, and then close the scope. */
4006 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4008 struct objfile
*objfile
= cu
->objfile
;
4009 struct context_stack
*new;
4010 CORE_ADDR lowpc
, highpc
;
4011 struct die_info
*child_die
;
4014 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4016 /* Ignore blocks with missing or invalid low and high pc attributes. */
4017 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
4018 as multiple lexical blocks? Handling children in a sane way would
4019 be nasty. Might be easier to properly extend generic blocks to
4021 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
4026 push_context (0, lowpc
);
4027 if (die
->child
!= NULL
)
4029 child_die
= die
->child
;
4030 while (child_die
&& child_die
->tag
)
4032 process_die (child_die
, cu
);
4033 child_die
= sibling_die (child_die
);
4036 new = pop_context ();
4038 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
4041 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
4044 /* Note that recording ranges after traversing children, as we
4045 do here, means that recording a parent's ranges entails
4046 walking across all its children's ranges as they appear in
4047 the address map, which is quadratic behavior.
4049 It would be nicer to record the parent's ranges before
4050 traversing its children, simply overriding whatever you find
4051 there. But since we don't even decide whether to create a
4052 block until after we've traversed its children, that's hard
4054 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
4056 local_symbols
= new->locals
;
4057 using_directives
= new->using_directives
;
4060 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
4061 Return 1 if the attributes are present and valid, otherwise, return 0.
4062 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
4065 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
4066 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
4067 struct partial_symtab
*ranges_pst
)
4069 struct objfile
*objfile
= cu
->objfile
;
4070 struct comp_unit_head
*cu_header
= &cu
->header
;
4071 bfd
*obfd
= objfile
->obfd
;
4072 unsigned int addr_size
= cu_header
->addr_size
;
4073 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4074 /* Base address selection entry. */
4085 found_base
= cu
->base_known
;
4086 base
= cu
->base_address
;
4088 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
4089 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4091 complaint (&symfile_complaints
,
4092 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4096 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4098 /* Read in the largest possible address. */
4099 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
4100 if ((marker
& mask
) == mask
)
4102 /* If we found the largest possible address, then
4103 read the base address. */
4104 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4105 buffer
+= 2 * addr_size
;
4106 offset
+= 2 * addr_size
;
4112 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4116 CORE_ADDR range_beginning
, range_end
;
4118 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
4119 buffer
+= addr_size
;
4120 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
4121 buffer
+= addr_size
;
4122 offset
+= 2 * addr_size
;
4124 /* An end of list marker is a pair of zero addresses. */
4125 if (range_beginning
== 0 && range_end
== 0)
4126 /* Found the end of list entry. */
4129 /* Each base address selection entry is a pair of 2 values.
4130 The first is the largest possible address, the second is
4131 the base address. Check for a base address here. */
4132 if ((range_beginning
& mask
) == mask
)
4134 /* If we found the largest possible address, then
4135 read the base address. */
4136 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4143 /* We have no valid base address for the ranges
4145 complaint (&symfile_complaints
,
4146 _("Invalid .debug_ranges data (no base address)"));
4150 range_beginning
+= base
;
4153 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
4154 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4155 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
4158 /* FIXME: This is recording everything as a low-high
4159 segment of consecutive addresses. We should have a
4160 data structure for discontiguous block ranges
4164 low
= range_beginning
;
4170 if (range_beginning
< low
)
4171 low
= range_beginning
;
4172 if (range_end
> high
)
4178 /* If the first entry is an end-of-list marker, the range
4179 describes an empty scope, i.e. no instructions. */
4185 *high_return
= high
;
4189 /* Get low and high pc attributes from a die. Return 1 if the attributes
4190 are present and valid, otherwise, return 0. Return -1 if the range is
4191 discontinuous, i.e. derived from DW_AT_ranges information. */
4193 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
4194 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
4195 struct partial_symtab
*pst
)
4197 struct attribute
*attr
;
4202 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4205 high
= DW_ADDR (attr
);
4206 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4208 low
= DW_ADDR (attr
);
4210 /* Found high w/o low attribute. */
4213 /* Found consecutive range of addresses. */
4218 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4221 /* Value of the DW_AT_ranges attribute is the offset in the
4222 .debug_ranges section. */
4223 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
4225 /* Found discontinuous range of addresses. */
4233 /* When using the GNU linker, .gnu.linkonce. sections are used to
4234 eliminate duplicate copies of functions and vtables and such.
4235 The linker will arbitrarily choose one and discard the others.
4236 The AT_*_pc values for such functions refer to local labels in
4237 these sections. If the section from that file was discarded, the
4238 labels are not in the output, so the relocs get a value of 0.
4239 If this is a discarded function, mark the pc bounds as invalid,
4240 so that GDB will ignore it. */
4241 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
4249 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4250 its low and high PC addresses. Do nothing if these addresses could not
4251 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4252 and HIGHPC to the high address if greater than HIGHPC. */
4255 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
4256 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4257 struct dwarf2_cu
*cu
)
4259 CORE_ADDR low
, high
;
4260 struct die_info
*child
= die
->child
;
4262 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
4264 *lowpc
= min (*lowpc
, low
);
4265 *highpc
= max (*highpc
, high
);
4268 /* If the language does not allow nested subprograms (either inside
4269 subprograms or lexical blocks), we're done. */
4270 if (cu
->language
!= language_ada
)
4273 /* Check all the children of the given DIE. If it contains nested
4274 subprograms, then check their pc bounds. Likewise, we need to
4275 check lexical blocks as well, as they may also contain subprogram
4277 while (child
&& child
->tag
)
4279 if (child
->tag
== DW_TAG_subprogram
4280 || child
->tag
== DW_TAG_lexical_block
)
4281 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
4282 child
= sibling_die (child
);
4286 /* Get the low and high pc's represented by the scope DIE, and store
4287 them in *LOWPC and *HIGHPC. If the correct values can't be
4288 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4291 get_scope_pc_bounds (struct die_info
*die
,
4292 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4293 struct dwarf2_cu
*cu
)
4295 CORE_ADDR best_low
= (CORE_ADDR
) -1;
4296 CORE_ADDR best_high
= (CORE_ADDR
) 0;
4297 CORE_ADDR current_low
, current_high
;
4299 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
4301 best_low
= current_low
;
4302 best_high
= current_high
;
4306 struct die_info
*child
= die
->child
;
4308 while (child
&& child
->tag
)
4310 switch (child
->tag
) {
4311 case DW_TAG_subprogram
:
4312 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
4314 case DW_TAG_namespace
:
4315 /* FIXME: carlton/2004-01-16: Should we do this for
4316 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4317 that current GCC's always emit the DIEs corresponding
4318 to definitions of methods of classes as children of a
4319 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4320 the DIEs giving the declarations, which could be
4321 anywhere). But I don't see any reason why the
4322 standards says that they have to be there. */
4323 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
4325 if (current_low
!= ((CORE_ADDR
) -1))
4327 best_low
= min (best_low
, current_low
);
4328 best_high
= max (best_high
, current_high
);
4336 child
= sibling_die (child
);
4341 *highpc
= best_high
;
4344 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4347 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
4348 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
4350 struct attribute
*attr
;
4352 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4355 CORE_ADDR high
= DW_ADDR (attr
);
4357 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4360 CORE_ADDR low
= DW_ADDR (attr
);
4362 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
4366 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4369 bfd
*obfd
= cu
->objfile
->obfd
;
4371 /* The value of the DW_AT_ranges attribute is the offset of the
4372 address range list in the .debug_ranges section. */
4373 unsigned long offset
= DW_UNSND (attr
);
4374 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4376 /* For some target architectures, but not others, the
4377 read_address function sign-extends the addresses it returns.
4378 To recognize base address selection entries, we need a
4380 unsigned int addr_size
= cu
->header
.addr_size
;
4381 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4383 /* The base address, to which the next pair is relative. Note
4384 that this 'base' is a DWARF concept: most entries in a range
4385 list are relative, to reduce the number of relocs against the
4386 debugging information. This is separate from this function's
4387 'baseaddr' argument, which GDB uses to relocate debugging
4388 information from a shared library based on the address at
4389 which the library was loaded. */
4390 CORE_ADDR base
= cu
->base_address
;
4391 int base_known
= cu
->base_known
;
4393 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
4394 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4396 complaint (&symfile_complaints
,
4397 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4404 unsigned int bytes_read
;
4405 CORE_ADDR start
, end
;
4407 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4408 buffer
+= bytes_read
;
4409 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4410 buffer
+= bytes_read
;
4412 /* Did we find the end of the range list? */
4413 if (start
== 0 && end
== 0)
4416 /* Did we find a base address selection entry? */
4417 else if ((start
& base_select_mask
) == base_select_mask
)
4423 /* We found an ordinary address range. */
4428 complaint (&symfile_complaints
,
4429 _("Invalid .debug_ranges data (no base address)"));
4433 record_block_range (block
,
4434 baseaddr
+ base
+ start
,
4435 baseaddr
+ base
+ end
- 1);
4441 /* Add an aggregate field to the field list. */
4444 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
4445 struct dwarf2_cu
*cu
)
4447 struct objfile
*objfile
= cu
->objfile
;
4448 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4449 struct nextfield
*new_field
;
4450 struct attribute
*attr
;
4452 char *fieldname
= "";
4454 /* Allocate a new field list entry and link it in. */
4455 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
4456 make_cleanup (xfree
, new_field
);
4457 memset (new_field
, 0, sizeof (struct nextfield
));
4459 if (die
->tag
== DW_TAG_inheritance
)
4461 new_field
->next
= fip
->baseclasses
;
4462 fip
->baseclasses
= new_field
;
4466 new_field
->next
= fip
->fields
;
4467 fip
->fields
= new_field
;
4471 /* Handle accessibility and virtuality of field.
4472 The default accessibility for members is public, the default
4473 accessibility for inheritance is private. */
4474 if (die
->tag
!= DW_TAG_inheritance
)
4475 new_field
->accessibility
= DW_ACCESS_public
;
4477 new_field
->accessibility
= DW_ACCESS_private
;
4478 new_field
->virtuality
= DW_VIRTUALITY_none
;
4480 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4482 new_field
->accessibility
= DW_UNSND (attr
);
4483 if (new_field
->accessibility
!= DW_ACCESS_public
)
4484 fip
->non_public_fields
= 1;
4485 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4487 new_field
->virtuality
= DW_UNSND (attr
);
4489 fp
= &new_field
->field
;
4491 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
4493 /* Data member other than a C++ static data member. */
4495 /* Get type of field. */
4496 fp
->type
= die_type (die
, cu
);
4498 SET_FIELD_BITPOS (*fp
, 0);
4500 /* Get bit size of field (zero if none). */
4501 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
4504 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
4508 FIELD_BITSIZE (*fp
) = 0;
4511 /* Get bit offset of field. */
4512 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4515 int byte_offset
= 0;
4517 if (attr_form_is_section_offset (attr
))
4518 dwarf2_complex_location_expr_complaint ();
4519 else if (attr_form_is_constant (attr
))
4520 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4521 else if (attr_form_is_block (attr
))
4522 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4524 dwarf2_complex_location_expr_complaint ();
4526 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4528 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
4531 if (gdbarch_bits_big_endian (gdbarch
))
4533 /* For big endian bits, the DW_AT_bit_offset gives the
4534 additional bit offset from the MSB of the containing
4535 anonymous object to the MSB of the field. We don't
4536 have to do anything special since we don't need to
4537 know the size of the anonymous object. */
4538 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
4542 /* For little endian bits, compute the bit offset to the
4543 MSB of the anonymous object, subtract off the number of
4544 bits from the MSB of the field to the MSB of the
4545 object, and then subtract off the number of bits of
4546 the field itself. The result is the bit offset of
4547 the LSB of the field. */
4549 int bit_offset
= DW_UNSND (attr
);
4551 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4554 /* The size of the anonymous object containing
4555 the bit field is explicit, so use the
4556 indicated size (in bytes). */
4557 anonymous_size
= DW_UNSND (attr
);
4561 /* The size of the anonymous object containing
4562 the bit field must be inferred from the type
4563 attribute of the data member containing the
4565 anonymous_size
= TYPE_LENGTH (fp
->type
);
4567 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4568 - bit_offset
- FIELD_BITSIZE (*fp
);
4572 /* Get name of field. */
4573 fieldname
= dwarf2_name (die
, cu
);
4574 if (fieldname
== NULL
)
4577 /* The name is already allocated along with this objfile, so we don't
4578 need to duplicate it for the type. */
4579 fp
->name
= fieldname
;
4581 /* Change accessibility for artificial fields (e.g. virtual table
4582 pointer or virtual base class pointer) to private. */
4583 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4585 FIELD_ARTIFICIAL (*fp
) = 1;
4586 new_field
->accessibility
= DW_ACCESS_private
;
4587 fip
->non_public_fields
= 1;
4590 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4592 /* C++ static member. */
4594 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4595 is a declaration, but all versions of G++ as of this writing
4596 (so through at least 3.2.1) incorrectly generate
4597 DW_TAG_variable tags. */
4601 /* Get name of field. */
4602 fieldname
= dwarf2_name (die
, cu
);
4603 if (fieldname
== NULL
)
4606 /* Get physical name. */
4607 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4609 /* The name is already allocated along with this objfile, so we don't
4610 need to duplicate it for the type. */
4611 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4612 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4613 FIELD_NAME (*fp
) = fieldname
;
4615 else if (die
->tag
== DW_TAG_inheritance
)
4617 /* C++ base class field. */
4618 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4621 int byte_offset
= 0;
4623 if (attr_form_is_section_offset (attr
))
4624 dwarf2_complex_location_expr_complaint ();
4625 else if (attr_form_is_constant (attr
))
4626 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4627 else if (attr_form_is_block (attr
))
4628 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4630 dwarf2_complex_location_expr_complaint ();
4632 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4634 FIELD_BITSIZE (*fp
) = 0;
4635 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4636 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4637 fip
->nbaseclasses
++;
4641 /* Create the vector of fields, and attach it to the type. */
4644 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4645 struct dwarf2_cu
*cu
)
4647 int nfields
= fip
->nfields
;
4649 /* Record the field count, allocate space for the array of fields,
4650 and create blank accessibility bitfields if necessary. */
4651 TYPE_NFIELDS (type
) = nfields
;
4652 TYPE_FIELDS (type
) = (struct field
*)
4653 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4654 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4656 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
4658 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4660 TYPE_FIELD_PRIVATE_BITS (type
) =
4661 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4662 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4664 TYPE_FIELD_PROTECTED_BITS (type
) =
4665 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4666 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4668 TYPE_FIELD_IGNORE_BITS (type
) =
4669 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4670 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4673 /* If the type has baseclasses, allocate and clear a bit vector for
4674 TYPE_FIELD_VIRTUAL_BITS. */
4675 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
4677 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4678 unsigned char *pointer
;
4680 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4681 pointer
= TYPE_ALLOC (type
, num_bytes
);
4682 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4683 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4684 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4687 /* Copy the saved-up fields into the field vector. Start from the head
4688 of the list, adding to the tail of the field array, so that they end
4689 up in the same order in the array in which they were added to the list. */
4690 while (nfields
-- > 0)
4692 struct nextfield
*fieldp
;
4696 fieldp
= fip
->fields
;
4697 fip
->fields
= fieldp
->next
;
4701 fieldp
= fip
->baseclasses
;
4702 fip
->baseclasses
= fieldp
->next
;
4705 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
4706 switch (fieldp
->accessibility
)
4708 case DW_ACCESS_private
:
4709 if (cu
->language
!= language_ada
)
4710 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4713 case DW_ACCESS_protected
:
4714 if (cu
->language
!= language_ada
)
4715 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4718 case DW_ACCESS_public
:
4722 /* Unknown accessibility. Complain and treat it as public. */
4724 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4725 fieldp
->accessibility
);
4729 if (nfields
< fip
->nbaseclasses
)
4731 switch (fieldp
->virtuality
)
4733 case DW_VIRTUALITY_virtual
:
4734 case DW_VIRTUALITY_pure_virtual
:
4735 if (cu
->language
== language_ada
)
4736 error ("unexpected virtuality in component of Ada type");
4737 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4744 /* Add a member function to the proper fieldlist. */
4747 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4748 struct type
*type
, struct dwarf2_cu
*cu
)
4750 struct objfile
*objfile
= cu
->objfile
;
4751 struct attribute
*attr
;
4752 struct fnfieldlist
*flp
;
4754 struct fn_field
*fnp
;
4757 struct nextfnfield
*new_fnfield
;
4758 struct type
*this_type
;
4760 if (cu
->language
== language_ada
)
4761 error ("unexpected member function in Ada type");
4763 /* Get name of member function. */
4764 fieldname
= dwarf2_name (die
, cu
);
4765 if (fieldname
== NULL
)
4768 /* Get the mangled name. */
4769 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4771 /* Look up member function name in fieldlist. */
4772 for (i
= 0; i
< fip
->nfnfields
; i
++)
4774 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4778 /* Create new list element if necessary. */
4779 if (i
< fip
->nfnfields
)
4780 flp
= &fip
->fnfieldlists
[i
];
4783 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4785 fip
->fnfieldlists
= (struct fnfieldlist
*)
4786 xrealloc (fip
->fnfieldlists
,
4787 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4788 * sizeof (struct fnfieldlist
));
4789 if (fip
->nfnfields
== 0)
4790 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4792 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4793 flp
->name
= fieldname
;
4799 /* Create a new member function field and chain it to the field list
4801 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4802 make_cleanup (xfree
, new_fnfield
);
4803 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4804 new_fnfield
->next
= flp
->head
;
4805 flp
->head
= new_fnfield
;
4808 /* Fill in the member function field info. */
4809 fnp
= &new_fnfield
->fnfield
;
4810 /* The name is already allocated along with this objfile, so we don't
4811 need to duplicate it for the type. */
4812 fnp
->physname
= physname
? physname
: "";
4813 fnp
->type
= alloc_type (objfile
);
4814 this_type
= read_type_die (die
, cu
);
4815 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4817 int nparams
= TYPE_NFIELDS (this_type
);
4819 /* TYPE is the domain of this method, and THIS_TYPE is the type
4820 of the method itself (TYPE_CODE_METHOD). */
4821 smash_to_method_type (fnp
->type
, type
,
4822 TYPE_TARGET_TYPE (this_type
),
4823 TYPE_FIELDS (this_type
),
4824 TYPE_NFIELDS (this_type
),
4825 TYPE_VARARGS (this_type
));
4827 /* Handle static member functions.
4828 Dwarf2 has no clean way to discern C++ static and non-static
4829 member functions. G++ helps GDB by marking the first
4830 parameter for non-static member functions (which is the
4831 this pointer) as artificial. We obtain this information
4832 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4833 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4834 fnp
->voffset
= VOFFSET_STATIC
;
4837 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4840 /* Get fcontext from DW_AT_containing_type if present. */
4841 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4842 fnp
->fcontext
= die_containing_type (die
, cu
);
4844 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4845 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4847 /* Get accessibility. */
4848 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4851 switch (DW_UNSND (attr
))
4853 case DW_ACCESS_private
:
4854 fnp
->is_private
= 1;
4856 case DW_ACCESS_protected
:
4857 fnp
->is_protected
= 1;
4862 /* Check for artificial methods. */
4863 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4864 if (attr
&& DW_UNSND (attr
) != 0)
4865 fnp
->is_artificial
= 1;
4867 /* Get index in virtual function table if it is a virtual member
4868 function. For GCC, this is an offset in the appropriate
4869 virtual table, as specified by DW_AT_containing_type. For
4870 everyone else, it is an expression to be evaluated relative
4871 to the object address. */
4873 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4874 if (attr
&& fnp
->fcontext
)
4876 /* Support the .debug_loc offsets */
4877 if (attr_form_is_block (attr
))
4879 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4881 else if (attr_form_is_section_offset (attr
))
4883 dwarf2_complex_location_expr_complaint ();
4887 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4893 /* We only support trivial expressions here. This hack will work
4894 for v3 classes, which always start with the vtable pointer. */
4895 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0
4896 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref
)
4898 struct dwarf_block blk
;
4900 blk
.size
= DW_BLOCK (attr
)->size
- 1;
4901 blk
.data
= DW_BLOCK (attr
)->data
+ 1;
4902 fnp
->voffset
= decode_locdesc (&blk
, cu
);
4903 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
4904 dwarf2_complex_location_expr_complaint ();
4906 fnp
->voffset
/= cu
->header
.addr_size
;
4908 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
4911 dwarf2_complex_location_expr_complaint ();
4915 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4916 if (attr
&& DW_UNSND (attr
))
4918 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4919 complaint (&symfile_complaints
,
4920 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4921 fieldname
, die
->offset
);
4922 TYPE_CPLUS_DYNAMIC (type
) = 1;
4927 /* Create the vector of member function fields, and attach it to the type. */
4930 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4931 struct dwarf2_cu
*cu
)
4933 struct fnfieldlist
*flp
;
4934 int total_length
= 0;
4937 if (cu
->language
== language_ada
)
4938 error ("unexpected member functions in Ada type");
4940 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4941 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4942 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4944 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4946 struct nextfnfield
*nfp
= flp
->head
;
4947 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4950 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4951 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4952 fn_flp
->fn_fields
= (struct fn_field
*)
4953 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4954 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4955 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4957 total_length
+= flp
->length
;
4960 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4961 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4964 /* Returns non-zero if NAME is the name of a vtable member in CU's
4965 language, zero otherwise. */
4967 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4969 static const char vptr
[] = "_vptr";
4970 static const char vtable
[] = "vtable";
4972 /* Look for the C++ and Java forms of the vtable. */
4973 if ((cu
->language
== language_java
4974 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4975 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4976 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4982 /* GCC outputs unnamed structures that are really pointers to member
4983 functions, with the ABI-specified layout. If TYPE describes
4984 such a structure, smash it into a member function type.
4986 GCC shouldn't do this; it should just output pointer to member DIEs.
4987 This is GCC PR debug/28767. */
4990 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
4992 struct type
*pfn_type
, *domain_type
, *new_type
;
4994 /* Check for a structure with no name and two children. */
4995 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
4998 /* Check for __pfn and __delta members. */
4999 if (TYPE_FIELD_NAME (type
, 0) == NULL
5000 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
5001 || TYPE_FIELD_NAME (type
, 1) == NULL
5002 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
5005 /* Find the type of the method. */
5006 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
5007 if (pfn_type
== NULL
5008 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
5009 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
5012 /* Look for the "this" argument. */
5013 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
5014 if (TYPE_NFIELDS (pfn_type
) == 0
5015 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
5016 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
5019 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
5020 new_type
= alloc_type (objfile
);
5021 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
5022 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
5023 TYPE_VARARGS (pfn_type
));
5024 smash_to_methodptr_type (type
, new_type
);
5027 /* Called when we find the DIE that starts a structure or union scope
5028 (definition) to process all dies that define the members of the
5031 NOTE: we need to call struct_type regardless of whether or not the
5032 DIE has an at_name attribute, since it might be an anonymous
5033 structure or union. This gets the type entered into our set of
5036 However, if the structure is incomplete (an opaque struct/union)
5037 then suppress creating a symbol table entry for it since gdb only
5038 wants to find the one with the complete definition. Note that if
5039 it is complete, we just call new_symbol, which does it's own
5040 checking about whether the struct/union is anonymous or not (and
5041 suppresses creating a symbol table entry itself). */
5043 static struct type
*
5044 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5046 struct objfile
*objfile
= cu
->objfile
;
5048 struct attribute
*attr
;
5050 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5052 /* If the definition of this type lives in .debug_types, read that type.
5053 Don't follow DW_AT_specification though, that will take us back up
5054 the chain and we want to go down. */
5055 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5058 struct dwarf2_cu
*type_cu
= cu
;
5059 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5061 /* We could just recurse on read_structure_type, but we need to call
5062 get_die_type to ensure only one type for this DIE is created.
5063 This is important, for example, because for c++ classes we need
5064 TYPE_NAME set which is only done by new_symbol. Blech. */
5065 type
= read_type_die (type_die
, type_cu
);
5066 return set_die_type (die
, type
, cu
);
5069 type
= alloc_type (objfile
);
5070 INIT_CPLUS_SPECIFIC (type
);
5072 name
= dwarf2_name (die
, cu
);
5075 if (cu
->language
== language_cplus
5076 || cu
->language
== language_java
)
5078 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
5079 if (die
->tag
== DW_TAG_structure_type
5080 || die
->tag
== DW_TAG_class_type
)
5081 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5085 /* The name is already allocated along with this objfile, so
5086 we don't need to duplicate it for the type. */
5087 TYPE_TAG_NAME (type
) = (char *) name
;
5088 if (die
->tag
== DW_TAG_class_type
)
5089 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5093 if (die
->tag
== DW_TAG_structure_type
)
5095 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
5097 else if (die
->tag
== DW_TAG_union_type
)
5099 TYPE_CODE (type
) = TYPE_CODE_UNION
;
5103 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
5106 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
5107 TYPE_DECLARED_CLASS (type
) = 1;
5109 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5112 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5116 TYPE_LENGTH (type
) = 0;
5119 TYPE_STUB_SUPPORTED (type
) = 1;
5120 if (die_is_declaration (die
, cu
))
5121 TYPE_STUB (type
) = 1;
5122 else if (attr
== NULL
&& die
->child
== NULL
5123 && producer_is_realview (cu
->producer
))
5124 /* RealView does not output the required DW_AT_declaration
5125 on incomplete types. */
5126 TYPE_STUB (type
) = 1;
5128 set_descriptive_type (type
, die
, cu
);
5130 /* We need to add the type field to the die immediately so we don't
5131 infinitely recurse when dealing with pointers to the structure
5132 type within the structure itself. */
5133 set_die_type (die
, type
, cu
);
5135 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
5137 struct field_info fi
;
5138 struct die_info
*child_die
;
5140 memset (&fi
, 0, sizeof (struct field_info
));
5142 child_die
= die
->child
;
5144 while (child_die
&& child_die
->tag
)
5146 if (child_die
->tag
== DW_TAG_member
5147 || child_die
->tag
== DW_TAG_variable
)
5149 /* NOTE: carlton/2002-11-05: A C++ static data member
5150 should be a DW_TAG_member that is a declaration, but
5151 all versions of G++ as of this writing (so through at
5152 least 3.2.1) incorrectly generate DW_TAG_variable
5153 tags for them instead. */
5154 dwarf2_add_field (&fi
, child_die
, cu
);
5156 else if (child_die
->tag
== DW_TAG_subprogram
)
5158 /* C++ member function. */
5159 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
5161 else if (child_die
->tag
== DW_TAG_inheritance
)
5163 /* C++ base class field. */
5164 dwarf2_add_field (&fi
, child_die
, cu
);
5166 child_die
= sibling_die (child_die
);
5169 /* Attach fields and member functions to the type. */
5171 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
5174 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
5176 /* Get the type which refers to the base class (possibly this
5177 class itself) which contains the vtable pointer for the current
5178 class from the DW_AT_containing_type attribute. This use of
5179 DW_AT_containing_type is a GNU extension. */
5181 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5183 struct type
*t
= die_containing_type (die
, cu
);
5185 TYPE_VPTR_BASETYPE (type
) = t
;
5190 /* Our own class provides vtbl ptr. */
5191 for (i
= TYPE_NFIELDS (t
) - 1;
5192 i
>= TYPE_N_BASECLASSES (t
);
5195 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
5197 if (is_vtable_name (fieldname
, cu
))
5199 TYPE_VPTR_FIELDNO (type
) = i
;
5204 /* Complain if virtual function table field not found. */
5205 if (i
< TYPE_N_BASECLASSES (t
))
5206 complaint (&symfile_complaints
,
5207 _("virtual function table pointer not found when defining class '%s'"),
5208 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
5213 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
5216 else if (cu
->producer
5217 && strncmp (cu
->producer
,
5218 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5220 /* The IBM XLC compiler does not provide direct indication
5221 of the containing type, but the vtable pointer is
5222 always named __vfp. */
5226 for (i
= TYPE_NFIELDS (type
) - 1;
5227 i
>= TYPE_N_BASECLASSES (type
);
5230 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
5232 TYPE_VPTR_FIELDNO (type
) = i
;
5233 TYPE_VPTR_BASETYPE (type
) = type
;
5241 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
5243 do_cleanups (back_to
);
5248 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5250 struct die_info
*child_die
= die
->child
;
5251 struct type
*this_type
;
5253 this_type
= get_die_type (die
, cu
);
5254 if (this_type
== NULL
)
5255 this_type
= read_structure_type (die
, cu
);
5257 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5258 snapshots) has been known to create a die giving a declaration
5259 for a class that has, as a child, a die giving a definition for a
5260 nested class. So we have to process our children even if the
5261 current die is a declaration. Normally, of course, a declaration
5262 won't have any children at all. */
5264 while (child_die
!= NULL
&& child_die
->tag
)
5266 if (child_die
->tag
== DW_TAG_member
5267 || child_die
->tag
== DW_TAG_variable
5268 || child_die
->tag
== DW_TAG_inheritance
)
5273 process_die (child_die
, cu
);
5275 child_die
= sibling_die (child_die
);
5278 /* Do not consider external references. According to the DWARF standard,
5279 these DIEs are identified by the fact that they have no byte_size
5280 attribute, and a declaration attribute. */
5281 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
5282 || !die_is_declaration (die
, cu
))
5283 new_symbol (die
, this_type
, cu
);
5286 /* Given a DW_AT_enumeration_type die, set its type. We do not
5287 complete the type's fields yet, or create any symbols. */
5289 static struct type
*
5290 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5292 struct objfile
*objfile
= cu
->objfile
;
5294 struct attribute
*attr
;
5297 /* If the definition of this type lives in .debug_types, read that type.
5298 Don't follow DW_AT_specification though, that will take us back up
5299 the chain and we want to go down. */
5300 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5303 struct dwarf2_cu
*type_cu
= cu
;
5304 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5306 type
= read_type_die (type_die
, type_cu
);
5307 return set_die_type (die
, type
, cu
);
5310 type
= alloc_type (objfile
);
5312 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
5313 name
= dwarf2_full_name (NULL
, die
, cu
);
5315 TYPE_TAG_NAME (type
) = (char *) name
;
5317 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5320 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5324 TYPE_LENGTH (type
) = 0;
5327 /* The enumeration DIE can be incomplete. In Ada, any type can be
5328 declared as private in the package spec, and then defined only
5329 inside the package body. Such types are known as Taft Amendment
5330 Types. When another package uses such a type, an incomplete DIE
5331 may be generated by the compiler. */
5332 if (die_is_declaration (die
, cu
))
5333 TYPE_STUB (type
) = 1;
5335 return set_die_type (die
, type
, cu
);
5338 /* Given a pointer to a die which begins an enumeration, process all
5339 the dies that define the members of the enumeration, and create the
5340 symbol for the enumeration type.
5342 NOTE: We reverse the order of the element list. */
5345 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5347 struct die_info
*child_die
;
5348 struct field
*fields
;
5351 int unsigned_enum
= 1;
5353 struct type
*this_type
;
5357 this_type
= get_die_type (die
, cu
);
5358 if (this_type
== NULL
)
5359 this_type
= read_enumeration_type (die
, cu
);
5360 if (die
->child
!= NULL
)
5362 child_die
= die
->child
;
5363 while (child_die
&& child_die
->tag
)
5365 if (child_die
->tag
!= DW_TAG_enumerator
)
5367 process_die (child_die
, cu
);
5371 name
= dwarf2_name (child_die
, cu
);
5374 sym
= new_symbol (child_die
, this_type
, cu
);
5375 if (SYMBOL_VALUE (sym
) < 0)
5378 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5380 fields
= (struct field
*)
5382 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
5383 * sizeof (struct field
));
5386 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
5387 FIELD_TYPE (fields
[num_fields
]) = NULL
;
5388 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
5389 FIELD_BITSIZE (fields
[num_fields
]) = 0;
5395 child_die
= sibling_die (child_die
);
5400 TYPE_NFIELDS (this_type
) = num_fields
;
5401 TYPE_FIELDS (this_type
) = (struct field
*)
5402 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
5403 memcpy (TYPE_FIELDS (this_type
), fields
,
5404 sizeof (struct field
) * num_fields
);
5408 TYPE_UNSIGNED (this_type
) = 1;
5411 new_symbol (die
, this_type
, cu
);
5414 /* Extract all information from a DW_TAG_array_type DIE and put it in
5415 the DIE's type field. For now, this only handles one dimensional
5418 static struct type
*
5419 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5421 struct objfile
*objfile
= cu
->objfile
;
5422 struct die_info
*child_die
;
5423 struct type
*type
= NULL
;
5424 struct type
*element_type
, *range_type
, *index_type
;
5425 struct type
**range_types
= NULL
;
5426 struct attribute
*attr
;
5428 struct cleanup
*back_to
;
5431 element_type
= die_type (die
, cu
);
5433 /* Irix 6.2 native cc creates array types without children for
5434 arrays with unspecified length. */
5435 if (die
->child
== NULL
)
5437 index_type
= objfile_type (objfile
)->builtin_int
;
5438 range_type
= create_range_type (NULL
, index_type
, 0, -1);
5439 type
= create_array_type (NULL
, element_type
, range_type
);
5440 return set_die_type (die
, type
, cu
);
5443 back_to
= make_cleanup (null_cleanup
, NULL
);
5444 child_die
= die
->child
;
5445 while (child_die
&& child_die
->tag
)
5447 if (child_die
->tag
== DW_TAG_subrange_type
)
5449 struct type
*child_type
= read_type_die (child_die
, cu
);
5451 if (child_type
!= NULL
)
5453 /* The range type was succesfully read. Save it for
5454 the array type creation. */
5455 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
5457 range_types
= (struct type
**)
5458 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
5459 * sizeof (struct type
*));
5461 make_cleanup (free_current_contents
, &range_types
);
5463 range_types
[ndim
++] = child_type
;
5466 child_die
= sibling_die (child_die
);
5469 /* Dwarf2 dimensions are output from left to right, create the
5470 necessary array types in backwards order. */
5472 type
= element_type
;
5474 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
5479 type
= create_array_type (NULL
, type
, range_types
[i
++]);
5484 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
5487 /* Understand Dwarf2 support for vector types (like they occur on
5488 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5489 array type. This is not part of the Dwarf2/3 standard yet, but a
5490 custom vendor extension. The main difference between a regular
5491 array and the vector variant is that vectors are passed by value
5493 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
5495 make_vector_type (type
);
5497 name
= dwarf2_name (die
, cu
);
5499 TYPE_NAME (type
) = name
;
5501 set_descriptive_type (type
, die
, cu
);
5503 do_cleanups (back_to
);
5505 /* Install the type in the die. */
5506 return set_die_type (die
, type
, cu
);
5509 static enum dwarf_array_dim_ordering
5510 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
5512 struct attribute
*attr
;
5514 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
5516 if (attr
) return DW_SND (attr
);
5519 GNU F77 is a special case, as at 08/2004 array type info is the
5520 opposite order to the dwarf2 specification, but data is still
5521 laid out as per normal fortran.
5523 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5527 if (cu
->language
== language_fortran
5528 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
5530 return DW_ORD_row_major
;
5533 switch (cu
->language_defn
->la_array_ordering
)
5535 case array_column_major
:
5536 return DW_ORD_col_major
;
5537 case array_row_major
:
5539 return DW_ORD_row_major
;
5543 /* Extract all information from a DW_TAG_set_type DIE and put it in
5544 the DIE's type field. */
5546 static struct type
*
5547 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5549 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
5551 return set_die_type (die
, set_type
, cu
);
5554 /* First cut: install each common block member as a global variable. */
5557 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
5559 struct die_info
*child_die
;
5560 struct attribute
*attr
;
5562 CORE_ADDR base
= (CORE_ADDR
) 0;
5564 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5567 /* Support the .debug_loc offsets */
5568 if (attr_form_is_block (attr
))
5570 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
5572 else if (attr_form_is_section_offset (attr
))
5574 dwarf2_complex_location_expr_complaint ();
5578 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5579 "common block member");
5582 if (die
->child
!= NULL
)
5584 child_die
= die
->child
;
5585 while (child_die
&& child_die
->tag
)
5587 sym
= new_symbol (child_die
, NULL
, cu
);
5588 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
5591 CORE_ADDR byte_offset
= 0;
5593 if (attr_form_is_section_offset (attr
))
5594 dwarf2_complex_location_expr_complaint ();
5595 else if (attr_form_is_constant (attr
))
5596 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5597 else if (attr_form_is_block (attr
))
5598 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5600 dwarf2_complex_location_expr_complaint ();
5602 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
5603 add_symbol_to_list (sym
, &global_symbols
);
5605 child_die
= sibling_die (child_die
);
5610 /* Create a type for a C++ namespace. */
5612 static struct type
*
5613 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5615 struct objfile
*objfile
= cu
->objfile
;
5616 const char *previous_prefix
, *name
;
5620 /* For extensions, reuse the type of the original namespace. */
5621 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5623 struct die_info
*ext_die
;
5624 struct dwarf2_cu
*ext_cu
= cu
;
5626 ext_die
= dwarf2_extension (die
, &ext_cu
);
5627 type
= read_type_die (ext_die
, ext_cu
);
5628 return set_die_type (die
, type
, cu
);
5631 name
= namespace_name (die
, &is_anonymous
, cu
);
5633 /* Now build the name of the current namespace. */
5635 previous_prefix
= determine_prefix (die
, cu
);
5636 if (previous_prefix
[0] != '\0')
5637 name
= typename_concat (&objfile
->objfile_obstack
,
5638 previous_prefix
, name
, cu
);
5640 /* Create the type. */
5641 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5643 TYPE_NAME (type
) = (char *) name
;
5644 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5646 return set_die_type (die
, type
, cu
);
5649 /* Read a C++ namespace. */
5652 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5654 struct objfile
*objfile
= cu
->objfile
;
5658 /* Add a symbol associated to this if we haven't seen the namespace
5659 before. Also, add a using directive if it's an anonymous
5662 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5666 type
= read_type_die (die
, cu
);
5667 new_symbol (die
, type
, cu
);
5669 name
= namespace_name (die
, &is_anonymous
, cu
);
5672 const char *previous_prefix
= determine_prefix (die
, cu
);
5674 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
5675 NULL
, &objfile
->objfile_obstack
);
5679 if (die
->child
!= NULL
)
5681 struct die_info
*child_die
= die
->child
;
5683 while (child_die
&& child_die
->tag
)
5685 process_die (child_die
, cu
);
5686 child_die
= sibling_die (child_die
);
5691 /* Read a Fortran module. */
5694 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5696 struct die_info
*child_die
= die
->child
;
5698 /* FIXME: Support the separate Fortran module namespaces. */
5700 while (child_die
&& child_die
->tag
)
5702 process_die (child_die
, cu
);
5703 child_die
= sibling_die (child_die
);
5707 /* Return the name of the namespace represented by DIE. Set
5708 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5712 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5714 struct die_info
*current_die
;
5715 const char *name
= NULL
;
5717 /* Loop through the extensions until we find a name. */
5719 for (current_die
= die
;
5720 current_die
!= NULL
;
5721 current_die
= dwarf2_extension (die
, &cu
))
5723 name
= dwarf2_name (current_die
, cu
);
5728 /* Is it an anonymous namespace? */
5730 *is_anonymous
= (name
== NULL
);
5732 name
= "(anonymous namespace)";
5737 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5738 the user defined type vector. */
5740 static struct type
*
5741 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5743 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5744 struct comp_unit_head
*cu_header
= &cu
->header
;
5746 struct attribute
*attr_byte_size
;
5747 struct attribute
*attr_address_class
;
5748 int byte_size
, addr_class
;
5750 type
= lookup_pointer_type (die_type (die
, cu
));
5752 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5754 byte_size
= DW_UNSND (attr_byte_size
);
5756 byte_size
= cu_header
->addr_size
;
5758 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5759 if (attr_address_class
)
5760 addr_class
= DW_UNSND (attr_address_class
);
5762 addr_class
= DW_ADDR_none
;
5764 /* If the pointer size or address class is different than the
5765 default, create a type variant marked as such and set the
5766 length accordingly. */
5767 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5769 if (gdbarch_address_class_type_flags_p (gdbarch
))
5773 type_flags
= gdbarch_address_class_type_flags
5774 (gdbarch
, byte_size
, addr_class
);
5775 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5777 type
= make_type_with_address_space (type
, type_flags
);
5779 else if (TYPE_LENGTH (type
) != byte_size
)
5781 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5785 /* Should we also complain about unhandled address classes? */
5789 TYPE_LENGTH (type
) = byte_size
;
5790 return set_die_type (die
, type
, cu
);
5793 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5794 the user defined type vector. */
5796 static struct type
*
5797 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5800 struct type
*to_type
;
5801 struct type
*domain
;
5803 to_type
= die_type (die
, cu
);
5804 domain
= die_containing_type (die
, cu
);
5806 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5807 type
= lookup_methodptr_type (to_type
);
5809 type
= lookup_memberptr_type (to_type
, domain
);
5811 return set_die_type (die
, type
, cu
);
5814 /* Extract all information from a DW_TAG_reference_type DIE and add to
5815 the user defined type vector. */
5817 static struct type
*
5818 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5820 struct comp_unit_head
*cu_header
= &cu
->header
;
5822 struct attribute
*attr
;
5824 type
= lookup_reference_type (die_type (die
, cu
));
5825 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5828 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5832 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5834 return set_die_type (die
, type
, cu
);
5837 static struct type
*
5838 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5840 struct type
*base_type
, *cv_type
;
5842 base_type
= die_type (die
, cu
);
5843 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5844 return set_die_type (die
, cv_type
, cu
);
5847 static struct type
*
5848 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5850 struct type
*base_type
, *cv_type
;
5852 base_type
= die_type (die
, cu
);
5853 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5854 return set_die_type (die
, cv_type
, cu
);
5857 /* Extract all information from a DW_TAG_string_type DIE and add to
5858 the user defined type vector. It isn't really a user defined type,
5859 but it behaves like one, with other DIE's using an AT_user_def_type
5860 attribute to reference it. */
5862 static struct type
*
5863 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5865 struct objfile
*objfile
= cu
->objfile
;
5866 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5867 struct type
*type
, *range_type
, *index_type
, *char_type
;
5868 struct attribute
*attr
;
5869 unsigned int length
;
5871 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5874 length
= DW_UNSND (attr
);
5878 /* check for the DW_AT_byte_size attribute */
5879 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5882 length
= DW_UNSND (attr
);
5890 index_type
= objfile_type (objfile
)->builtin_int
;
5891 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5892 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5893 type
= create_string_type (NULL
, char_type
, range_type
);
5895 return set_die_type (die
, type
, cu
);
5898 /* Handle DIES due to C code like:
5902 int (*funcp)(int a, long l);
5906 ('funcp' generates a DW_TAG_subroutine_type DIE)
5909 static struct type
*
5910 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5912 struct type
*type
; /* Type that this function returns */
5913 struct type
*ftype
; /* Function that returns above type */
5914 struct attribute
*attr
;
5916 type
= die_type (die
, cu
);
5917 ftype
= lookup_function_type (type
);
5919 /* All functions in C++, Pascal and Java have prototypes. */
5920 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5921 if ((attr
&& (DW_UNSND (attr
) != 0))
5922 || cu
->language
== language_cplus
5923 || cu
->language
== language_java
5924 || cu
->language
== language_pascal
)
5925 TYPE_PROTOTYPED (ftype
) = 1;
5926 else if (producer_is_realview (cu
->producer
))
5927 /* RealView does not emit DW_AT_prototyped. We can not
5928 distinguish prototyped and unprototyped functions; default to
5929 prototyped, since that is more common in modern code (and
5930 RealView warns about unprototyped functions). */
5931 TYPE_PROTOTYPED (ftype
) = 1;
5933 /* Store the calling convention in the type if it's available in
5934 the subroutine die. Otherwise set the calling convention to
5935 the default value DW_CC_normal. */
5936 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5937 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5939 /* We need to add the subroutine type to the die immediately so
5940 we don't infinitely recurse when dealing with parameters
5941 declared as the same subroutine type. */
5942 set_die_type (die
, ftype
, cu
);
5944 if (die
->child
!= NULL
)
5946 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
5947 struct die_info
*child_die
;
5948 int nparams
, iparams
;
5950 /* Count the number of parameters.
5951 FIXME: GDB currently ignores vararg functions, but knows about
5952 vararg member functions. */
5954 child_die
= die
->child
;
5955 while (child_die
&& child_die
->tag
)
5957 if (child_die
->tag
== DW_TAG_formal_parameter
)
5959 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5960 TYPE_VARARGS (ftype
) = 1;
5961 child_die
= sibling_die (child_die
);
5964 /* Allocate storage for parameters and fill them in. */
5965 TYPE_NFIELDS (ftype
) = nparams
;
5966 TYPE_FIELDS (ftype
) = (struct field
*)
5967 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5969 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
5970 even if we error out during the parameters reading below. */
5971 for (iparams
= 0; iparams
< nparams
; iparams
++)
5972 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
5975 child_die
= die
->child
;
5976 while (child_die
&& child_die
->tag
)
5978 if (child_die
->tag
== DW_TAG_formal_parameter
)
5980 /* Dwarf2 has no clean way to discern C++ static and non-static
5981 member functions. G++ helps GDB by marking the first
5982 parameter for non-static member functions (which is the
5983 this pointer) as artificial. We pass this information
5984 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5985 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5987 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5990 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5992 /* GCC/43521: In java, the formal parameter
5993 "this" is sometimes not marked with DW_AT_artificial. */
5994 if (cu
->language
== language_java
)
5996 const char *name
= dwarf2_name (child_die
, cu
);
5998 if (name
&& !strcmp (name
, "this"))
5999 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
6002 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
6005 child_die
= sibling_die (child_die
);
6012 static struct type
*
6013 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
6015 struct objfile
*objfile
= cu
->objfile
;
6016 const char *name
= NULL
;
6017 struct type
*this_type
;
6019 name
= dwarf2_full_name (NULL
, die
, cu
);
6020 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
6021 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
6022 TYPE_NAME (this_type
) = (char *) name
;
6023 set_die_type (die
, this_type
, cu
);
6024 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
6028 /* Find a representation of a given base type and install
6029 it in the TYPE field of the die. */
6031 static struct type
*
6032 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6034 struct objfile
*objfile
= cu
->objfile
;
6036 struct attribute
*attr
;
6037 int encoding
= 0, size
= 0;
6039 enum type_code code
= TYPE_CODE_INT
;
6041 struct type
*target_type
= NULL
;
6043 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
6046 encoding
= DW_UNSND (attr
);
6048 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6051 size
= DW_UNSND (attr
);
6053 name
= dwarf2_name (die
, cu
);
6056 complaint (&symfile_complaints
,
6057 _("DW_AT_name missing from DW_TAG_base_type"));
6062 case DW_ATE_address
:
6063 /* Turn DW_ATE_address into a void * pointer. */
6064 code
= TYPE_CODE_PTR
;
6065 type_flags
|= TYPE_FLAG_UNSIGNED
;
6066 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
6068 case DW_ATE_boolean
:
6069 code
= TYPE_CODE_BOOL
;
6070 type_flags
|= TYPE_FLAG_UNSIGNED
;
6072 case DW_ATE_complex_float
:
6073 code
= TYPE_CODE_COMPLEX
;
6074 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
6076 case DW_ATE_decimal_float
:
6077 code
= TYPE_CODE_DECFLOAT
;
6080 code
= TYPE_CODE_FLT
;
6084 case DW_ATE_unsigned
:
6085 type_flags
|= TYPE_FLAG_UNSIGNED
;
6087 case DW_ATE_signed_char
:
6088 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6089 || cu
->language
== language_pascal
)
6090 code
= TYPE_CODE_CHAR
;
6092 case DW_ATE_unsigned_char
:
6093 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6094 || cu
->language
== language_pascal
)
6095 code
= TYPE_CODE_CHAR
;
6096 type_flags
|= TYPE_FLAG_UNSIGNED
;
6099 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
6100 dwarf_type_encoding_name (encoding
));
6104 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
6105 TYPE_NAME (type
) = name
;
6106 TYPE_TARGET_TYPE (type
) = target_type
;
6108 if (name
&& strcmp (name
, "char") == 0)
6109 TYPE_NOSIGN (type
) = 1;
6111 return set_die_type (die
, type
, cu
);
6114 /* Read the given DW_AT_subrange DIE. */
6116 static struct type
*
6117 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6119 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6120 struct type
*base_type
;
6121 struct type
*range_type
;
6122 struct attribute
*attr
;
6126 LONGEST negative_mask
;
6128 base_type
= die_type (die
, cu
);
6129 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
6131 complaint (&symfile_complaints
,
6132 _("DW_AT_type missing from DW_TAG_subrange_type"));
6134 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
6135 0, NULL
, cu
->objfile
);
6138 if (cu
->language
== language_fortran
)
6140 /* FORTRAN implies a lower bound of 1, if not given. */
6144 /* FIXME: For variable sized arrays either of these could be
6145 a variable rather than a constant value. We'll allow it,
6146 but we don't know how to handle it. */
6147 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
6149 low
= dwarf2_get_attr_constant_value (attr
, 0);
6151 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
6154 if (attr
->form
== DW_FORM_block1
)
6156 /* GCC encodes arrays with unspecified or dynamic length
6157 with a DW_FORM_block1 attribute.
6158 FIXME: GDB does not yet know how to handle dynamic
6159 arrays properly, treat them as arrays with unspecified
6162 FIXME: jimb/2003-09-22: GDB does not really know
6163 how to handle arrays of unspecified length
6164 either; we just represent them as zero-length
6165 arrays. Choose an appropriate upper bound given
6166 the lower bound we've computed above. */
6170 high
= dwarf2_get_attr_constant_value (attr
, 1);
6174 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
6175 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
6176 low
|= negative_mask
;
6177 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
6178 high
|= negative_mask
;
6180 range_type
= create_range_type (NULL
, base_type
, low
, high
);
6182 /* Mark arrays with dynamic length at least as an array of unspecified
6183 length. GDB could check the boundary but before it gets implemented at
6184 least allow accessing the array elements. */
6185 if (attr
&& attr
->form
== DW_FORM_block1
)
6186 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
6188 name
= dwarf2_name (die
, cu
);
6190 TYPE_NAME (range_type
) = name
;
6192 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6194 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
6196 set_descriptive_type (range_type
, die
, cu
);
6198 return set_die_type (die
, range_type
, cu
);
6201 static struct type
*
6202 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6206 /* For now, we only support the C meaning of an unspecified type: void. */
6208 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
6209 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
6211 return set_die_type (die
, type
, cu
);
6214 /* Trivial hash function for die_info: the hash value of a DIE
6215 is its offset in .debug_info for this objfile. */
6218 die_hash (const void *item
)
6220 const struct die_info
*die
= item
;
6225 /* Trivial comparison function for die_info structures: two DIEs
6226 are equal if they have the same offset. */
6229 die_eq (const void *item_lhs
, const void *item_rhs
)
6231 const struct die_info
*die_lhs
= item_lhs
;
6232 const struct die_info
*die_rhs
= item_rhs
;
6234 return die_lhs
->offset
== die_rhs
->offset
;
6237 /* Read a whole compilation unit into a linked list of dies. */
6239 static struct die_info
*
6240 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6242 struct die_reader_specs reader_specs
;
6244 gdb_assert (cu
->die_hash
== NULL
);
6246 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6250 &cu
->comp_unit_obstack
,
6251 hashtab_obstack_allocate
,
6252 dummy_obstack_deallocate
);
6254 init_cu_die_reader (&reader_specs
, cu
);
6256 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
6259 /* Main entry point for reading a DIE and all children.
6260 Read the DIE and dump it if requested. */
6262 static struct die_info
*
6263 read_die_and_children (const struct die_reader_specs
*reader
,
6265 gdb_byte
**new_info_ptr
,
6266 struct die_info
*parent
)
6268 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
6269 new_info_ptr
, parent
);
6271 if (dwarf2_die_debug
)
6273 fprintf_unfiltered (gdb_stdlog
,
6274 "\nRead die from %s of %s:\n",
6275 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
6277 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
6279 : "unknown section",
6280 reader
->abfd
->filename
);
6281 dump_die (result
, dwarf2_die_debug
);
6287 /* Read a single die and all its descendents. Set the die's sibling
6288 field to NULL; set other fields in the die correctly, and set all
6289 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6290 location of the info_ptr after reading all of those dies. PARENT
6291 is the parent of the die in question. */
6293 static struct die_info
*
6294 read_die_and_children_1 (const struct die_reader_specs
*reader
,
6296 gdb_byte
**new_info_ptr
,
6297 struct die_info
*parent
)
6299 struct die_info
*die
;
6303 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
6306 *new_info_ptr
= cur_ptr
;
6309 store_in_ref_table (die
, reader
->cu
);
6312 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
6316 *new_info_ptr
= cur_ptr
;
6319 die
->sibling
= NULL
;
6320 die
->parent
= parent
;
6324 /* Read a die, all of its descendents, and all of its siblings; set
6325 all of the fields of all of the dies correctly. Arguments are as
6326 in read_die_and_children. */
6328 static struct die_info
*
6329 read_die_and_siblings (const struct die_reader_specs
*reader
,
6331 gdb_byte
**new_info_ptr
,
6332 struct die_info
*parent
)
6334 struct die_info
*first_die
, *last_sibling
;
6338 first_die
= last_sibling
= NULL
;
6342 struct die_info
*die
6343 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
6347 *new_info_ptr
= cur_ptr
;
6354 last_sibling
->sibling
= die
;
6360 /* Read the die from the .debug_info section buffer. Set DIEP to
6361 point to a newly allocated die with its information, except for its
6362 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6363 whether the die has children or not. */
6366 read_full_die (const struct die_reader_specs
*reader
,
6367 struct die_info
**diep
, gdb_byte
*info_ptr
,
6370 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6371 struct abbrev_info
*abbrev
;
6372 struct die_info
*die
;
6373 struct dwarf2_cu
*cu
= reader
->cu
;
6374 bfd
*abfd
= reader
->abfd
;
6376 offset
= info_ptr
- reader
->buffer
;
6377 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6378 info_ptr
+= bytes_read
;
6386 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6388 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6390 bfd_get_filename (abfd
));
6392 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6393 die
->offset
= offset
;
6394 die
->tag
= abbrev
->tag
;
6395 die
->abbrev
= abbrev_number
;
6397 die
->num_attrs
= abbrev
->num_attrs
;
6399 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6400 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6401 abfd
, info_ptr
, cu
);
6404 *has_children
= abbrev
->has_children
;
6408 /* In DWARF version 2, the description of the debugging information is
6409 stored in a separate .debug_abbrev section. Before we read any
6410 dies from a section we read in all abbreviations and install them
6411 in a hash table. This function also sets flags in CU describing
6412 the data found in the abbrev table. */
6415 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
6417 struct comp_unit_head
*cu_header
= &cu
->header
;
6418 gdb_byte
*abbrev_ptr
;
6419 struct abbrev_info
*cur_abbrev
;
6420 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
6421 unsigned int abbrev_form
, hash_number
;
6422 struct attr_abbrev
*cur_attrs
;
6423 unsigned int allocated_attrs
;
6425 /* Initialize dwarf2 abbrevs */
6426 obstack_init (&cu
->abbrev_obstack
);
6427 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
6429 * sizeof (struct abbrev_info
*)));
6430 memset (cu
->dwarf2_abbrevs
, 0,
6431 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
6433 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
6434 &dwarf2_per_objfile
->abbrev
);
6435 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
6436 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6437 abbrev_ptr
+= bytes_read
;
6439 allocated_attrs
= ATTR_ALLOC_CHUNK
;
6440 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
6442 /* loop until we reach an abbrev number of 0 */
6443 while (abbrev_number
)
6445 cur_abbrev
= dwarf_alloc_abbrev (cu
);
6447 /* read in abbrev header */
6448 cur_abbrev
->number
= abbrev_number
;
6449 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6450 abbrev_ptr
+= bytes_read
;
6451 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
6454 if (cur_abbrev
->tag
== DW_TAG_namespace
)
6455 cu
->has_namespace_info
= 1;
6457 /* now read in declarations */
6458 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6459 abbrev_ptr
+= bytes_read
;
6460 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6461 abbrev_ptr
+= bytes_read
;
6464 if (cur_abbrev
->num_attrs
== allocated_attrs
)
6466 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
6468 = xrealloc (cur_attrs
, (allocated_attrs
6469 * sizeof (struct attr_abbrev
)));
6472 /* Record whether this compilation unit might have
6473 inter-compilation-unit references. If we don't know what form
6474 this attribute will have, then it might potentially be a
6475 DW_FORM_ref_addr, so we conservatively expect inter-CU
6478 if (abbrev_form
== DW_FORM_ref_addr
6479 || abbrev_form
== DW_FORM_indirect
)
6480 cu
->has_form_ref_addr
= 1;
6482 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
6483 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
6484 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6485 abbrev_ptr
+= bytes_read
;
6486 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6487 abbrev_ptr
+= bytes_read
;
6490 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
6491 (cur_abbrev
->num_attrs
6492 * sizeof (struct attr_abbrev
)));
6493 memcpy (cur_abbrev
->attrs
, cur_attrs
,
6494 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
6496 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
6497 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
6498 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
6500 /* Get next abbreviation.
6501 Under Irix6 the abbreviations for a compilation unit are not
6502 always properly terminated with an abbrev number of 0.
6503 Exit loop if we encounter an abbreviation which we have
6504 already read (which means we are about to read the abbreviations
6505 for the next compile unit) or if the end of the abbreviation
6506 table is reached. */
6507 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
6508 >= dwarf2_per_objfile
->abbrev
.size
)
6510 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6511 abbrev_ptr
+= bytes_read
;
6512 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
6519 /* Release the memory used by the abbrev table for a compilation unit. */
6522 dwarf2_free_abbrev_table (void *ptr_to_cu
)
6524 struct dwarf2_cu
*cu
= ptr_to_cu
;
6526 obstack_free (&cu
->abbrev_obstack
, NULL
);
6527 cu
->dwarf2_abbrevs
= NULL
;
6530 /* Lookup an abbrev_info structure in the abbrev hash table. */
6532 static struct abbrev_info
*
6533 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
6535 unsigned int hash_number
;
6536 struct abbrev_info
*abbrev
;
6538 hash_number
= number
% ABBREV_HASH_SIZE
;
6539 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
6543 if (abbrev
->number
== number
)
6546 abbrev
= abbrev
->next
;
6551 /* Returns nonzero if TAG represents a type that we might generate a partial
6555 is_type_tag_for_partial (int tag
)
6560 /* Some types that would be reasonable to generate partial symbols for,
6561 that we don't at present. */
6562 case DW_TAG_array_type
:
6563 case DW_TAG_file_type
:
6564 case DW_TAG_ptr_to_member_type
:
6565 case DW_TAG_set_type
:
6566 case DW_TAG_string_type
:
6567 case DW_TAG_subroutine_type
:
6569 case DW_TAG_base_type
:
6570 case DW_TAG_class_type
:
6571 case DW_TAG_interface_type
:
6572 case DW_TAG_enumeration_type
:
6573 case DW_TAG_structure_type
:
6574 case DW_TAG_subrange_type
:
6575 case DW_TAG_typedef
:
6576 case DW_TAG_union_type
:
6583 /* Load all DIEs that are interesting for partial symbols into memory. */
6585 static struct partial_die_info
*
6586 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6587 int building_psymtab
, struct dwarf2_cu
*cu
)
6589 struct partial_die_info
*part_die
;
6590 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
6591 struct abbrev_info
*abbrev
;
6592 unsigned int bytes_read
;
6593 unsigned int load_all
= 0;
6595 int nesting_level
= 1;
6600 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
6604 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6608 &cu
->comp_unit_obstack
,
6609 hashtab_obstack_allocate
,
6610 dummy_obstack_deallocate
);
6612 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6613 sizeof (struct partial_die_info
));
6617 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6619 /* A NULL abbrev means the end of a series of children. */
6622 if (--nesting_level
== 0)
6624 /* PART_DIE was probably the last thing allocated on the
6625 comp_unit_obstack, so we could call obstack_free
6626 here. We don't do that because the waste is small,
6627 and will be cleaned up when we're done with this
6628 compilation unit. This way, we're also more robust
6629 against other users of the comp_unit_obstack. */
6632 info_ptr
+= bytes_read
;
6633 last_die
= parent_die
;
6634 parent_die
= parent_die
->die_parent
;
6638 /* Check whether this DIE is interesting enough to save. Normally
6639 we would not be interested in members here, but there may be
6640 later variables referencing them via DW_AT_specification (for
6643 && !is_type_tag_for_partial (abbrev
->tag
)
6644 && abbrev
->tag
!= DW_TAG_enumerator
6645 && abbrev
->tag
!= DW_TAG_subprogram
6646 && abbrev
->tag
!= DW_TAG_lexical_block
6647 && abbrev
->tag
!= DW_TAG_variable
6648 && abbrev
->tag
!= DW_TAG_namespace
6649 && abbrev
->tag
!= DW_TAG_member
)
6651 /* Otherwise we skip to the next sibling, if any. */
6652 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
6656 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
6657 buffer
, info_ptr
, cu
);
6659 /* This two-pass algorithm for processing partial symbols has a
6660 high cost in cache pressure. Thus, handle some simple cases
6661 here which cover the majority of C partial symbols. DIEs
6662 which neither have specification tags in them, nor could have
6663 specification tags elsewhere pointing at them, can simply be
6664 processed and discarded.
6666 This segment is also optional; scan_partial_symbols and
6667 add_partial_symbol will handle these DIEs if we chain
6668 them in normally. When compilers which do not emit large
6669 quantities of duplicate debug information are more common,
6670 this code can probably be removed. */
6672 /* Any complete simple types at the top level (pretty much all
6673 of them, for a language without namespaces), can be processed
6675 if (parent_die
== NULL
6676 && part_die
->has_specification
== 0
6677 && part_die
->is_declaration
== 0
6678 && (part_die
->tag
== DW_TAG_typedef
6679 || part_die
->tag
== DW_TAG_base_type
6680 || part_die
->tag
== DW_TAG_subrange_type
))
6682 if (building_psymtab
&& part_die
->name
!= NULL
)
6683 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6684 VAR_DOMAIN
, LOC_TYPEDEF
,
6685 &cu
->objfile
->static_psymbols
,
6686 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6687 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6691 /* If we're at the second level, and we're an enumerator, and
6692 our parent has no specification (meaning possibly lives in a
6693 namespace elsewhere), then we can add the partial symbol now
6694 instead of queueing it. */
6695 if (part_die
->tag
== DW_TAG_enumerator
6696 && parent_die
!= NULL
6697 && parent_die
->die_parent
== NULL
6698 && parent_die
->tag
== DW_TAG_enumeration_type
6699 && parent_die
->has_specification
== 0)
6701 if (part_die
->name
== NULL
)
6702 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6703 else if (building_psymtab
)
6704 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6705 VAR_DOMAIN
, LOC_CONST
,
6706 (cu
->language
== language_cplus
6707 || cu
->language
== language_java
)
6708 ? &cu
->objfile
->global_psymbols
6709 : &cu
->objfile
->static_psymbols
,
6710 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6712 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6716 /* We'll save this DIE so link it in. */
6717 part_die
->die_parent
= parent_die
;
6718 part_die
->die_sibling
= NULL
;
6719 part_die
->die_child
= NULL
;
6721 if (last_die
&& last_die
== parent_die
)
6722 last_die
->die_child
= part_die
;
6724 last_die
->die_sibling
= part_die
;
6726 last_die
= part_die
;
6728 if (first_die
== NULL
)
6729 first_die
= part_die
;
6731 /* Maybe add the DIE to the hash table. Not all DIEs that we
6732 find interesting need to be in the hash table, because we
6733 also have the parent/sibling/child chains; only those that we
6734 might refer to by offset later during partial symbol reading.
6736 For now this means things that might have be the target of a
6737 DW_AT_specification, DW_AT_abstract_origin, or
6738 DW_AT_extension. DW_AT_extension will refer only to
6739 namespaces; DW_AT_abstract_origin refers to functions (and
6740 many things under the function DIE, but we do not recurse
6741 into function DIEs during partial symbol reading) and
6742 possibly variables as well; DW_AT_specification refers to
6743 declarations. Declarations ought to have the DW_AT_declaration
6744 flag. It happens that GCC forgets to put it in sometimes, but
6745 only for functions, not for types.
6747 Adding more things than necessary to the hash table is harmless
6748 except for the performance cost. Adding too few will result in
6749 wasted time in find_partial_die, when we reread the compilation
6750 unit with load_all_dies set. */
6753 || abbrev
->tag
== DW_TAG_subprogram
6754 || abbrev
->tag
== DW_TAG_variable
6755 || abbrev
->tag
== DW_TAG_namespace
6756 || part_die
->is_declaration
)
6760 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6761 part_die
->offset
, INSERT
);
6765 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6766 sizeof (struct partial_die_info
));
6768 /* For some DIEs we want to follow their children (if any). For C
6769 we have no reason to follow the children of structures; for other
6770 languages we have to, both so that we can get at method physnames
6771 to infer fully qualified class names, and for DW_AT_specification.
6773 For Ada, we need to scan the children of subprograms and lexical
6774 blocks as well because Ada allows the definition of nested
6775 entities that could be interesting for the debugger, such as
6776 nested subprograms for instance. */
6777 if (last_die
->has_children
6779 || last_die
->tag
== DW_TAG_namespace
6780 || last_die
->tag
== DW_TAG_enumeration_type
6781 || (cu
->language
!= language_c
6782 && (last_die
->tag
== DW_TAG_class_type
6783 || last_die
->tag
== DW_TAG_interface_type
6784 || last_die
->tag
== DW_TAG_structure_type
6785 || last_die
->tag
== DW_TAG_union_type
))
6786 || (cu
->language
== language_ada
6787 && (last_die
->tag
== DW_TAG_subprogram
6788 || last_die
->tag
== DW_TAG_lexical_block
))))
6791 parent_die
= last_die
;
6795 /* Otherwise we skip to the next sibling, if any. */
6796 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
6798 /* Back to the top, do it again. */
6802 /* Read a minimal amount of information into the minimal die structure. */
6805 read_partial_die (struct partial_die_info
*part_die
,
6806 struct abbrev_info
*abbrev
,
6807 unsigned int abbrev_len
, bfd
*abfd
,
6808 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6809 struct dwarf2_cu
*cu
)
6812 struct attribute attr
;
6813 int has_low_pc_attr
= 0;
6814 int has_high_pc_attr
= 0;
6816 memset (part_die
, 0, sizeof (struct partial_die_info
));
6818 part_die
->offset
= info_ptr
- buffer
;
6820 info_ptr
+= abbrev_len
;
6825 part_die
->tag
= abbrev
->tag
;
6826 part_die
->has_children
= abbrev
->has_children
;
6828 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6830 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6832 /* Store the data if it is of an attribute we want to keep in a
6833 partial symbol table. */
6837 switch (part_die
->tag
)
6839 case DW_TAG_compile_unit
:
6840 case DW_TAG_type_unit
:
6841 /* Compilation units have a DW_AT_name that is a filename, not
6842 a source language identifier. */
6843 case DW_TAG_enumeration_type
:
6844 case DW_TAG_enumerator
:
6845 /* These tags always have simple identifiers already; no need
6846 to canonicalize them. */
6847 part_die
->name
= DW_STRING (&attr
);
6851 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6852 &cu
->objfile
->objfile_obstack
);
6856 case DW_AT_linkage_name
:
6857 case DW_AT_MIPS_linkage_name
:
6858 /* Note that both forms of linkage name might appear. We
6859 assume they will be the same, and we only store the last
6861 if (cu
->language
== language_ada
)
6862 part_die
->name
= DW_STRING (&attr
);
6865 has_low_pc_attr
= 1;
6866 part_die
->lowpc
= DW_ADDR (&attr
);
6869 has_high_pc_attr
= 1;
6870 part_die
->highpc
= DW_ADDR (&attr
);
6872 case DW_AT_location
:
6873 /* Support the .debug_loc offsets */
6874 if (attr_form_is_block (&attr
))
6876 part_die
->locdesc
= DW_BLOCK (&attr
);
6878 else if (attr_form_is_section_offset (&attr
))
6880 dwarf2_complex_location_expr_complaint ();
6884 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6885 "partial symbol information");
6888 case DW_AT_external
:
6889 part_die
->is_external
= DW_UNSND (&attr
);
6891 case DW_AT_declaration
:
6892 part_die
->is_declaration
= DW_UNSND (&attr
);
6895 part_die
->has_type
= 1;
6897 case DW_AT_abstract_origin
:
6898 case DW_AT_specification
:
6899 case DW_AT_extension
:
6900 part_die
->has_specification
= 1;
6901 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6904 /* Ignore absolute siblings, they might point outside of
6905 the current compile unit. */
6906 if (attr
.form
== DW_FORM_ref_addr
)
6907 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6909 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
6911 case DW_AT_byte_size
:
6912 part_die
->has_byte_size
= 1;
6914 case DW_AT_calling_convention
:
6915 /* DWARF doesn't provide a way to identify a program's source-level
6916 entry point. DW_AT_calling_convention attributes are only meant
6917 to describe functions' calling conventions.
6919 However, because it's a necessary piece of information in
6920 Fortran, and because DW_CC_program is the only piece of debugging
6921 information whose definition refers to a 'main program' at all,
6922 several compilers have begun marking Fortran main programs with
6923 DW_CC_program --- even when those functions use the standard
6924 calling conventions.
6926 So until DWARF specifies a way to provide this information and
6927 compilers pick up the new representation, we'll support this
6929 if (DW_UNSND (&attr
) == DW_CC_program
6930 && cu
->language
== language_fortran
)
6931 set_main_name (part_die
->name
);
6938 /* When using the GNU linker, .gnu.linkonce. sections are used to
6939 eliminate duplicate copies of functions and vtables and such.
6940 The linker will arbitrarily choose one and discard the others.
6941 The AT_*_pc values for such functions refer to local labels in
6942 these sections. If the section from that file was discarded, the
6943 labels are not in the output, so the relocs get a value of 0.
6944 If this is a discarded function, mark the pc bounds as invalid,
6945 so that GDB will ignore it. */
6946 if (has_low_pc_attr
&& has_high_pc_attr
6947 && part_die
->lowpc
< part_die
->highpc
6948 && (part_die
->lowpc
!= 0
6949 || dwarf2_per_objfile
->has_section_at_zero
))
6950 part_die
->has_pc_info
= 1;
6955 /* Find a cached partial DIE at OFFSET in CU. */
6957 static struct partial_die_info
*
6958 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6960 struct partial_die_info
*lookup_die
= NULL
;
6961 struct partial_die_info part_die
;
6963 part_die
.offset
= offset
;
6964 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6969 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6970 except in the case of .debug_types DIEs which do not reference
6971 outside their CU (they do however referencing other types via
6974 static struct partial_die_info
*
6975 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6977 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6978 struct partial_die_info
*pd
= NULL
;
6980 if (cu
->per_cu
->from_debug_types
)
6982 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6988 if (offset_in_cu_p (&cu
->header
, offset
))
6990 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6995 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6997 if (per_cu
->cu
== NULL
)
6999 load_partial_comp_unit (per_cu
, cu
->objfile
);
7000 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7001 dwarf2_per_objfile
->read_in_chain
= per_cu
;
7004 per_cu
->cu
->last_used
= 0;
7005 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
7007 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
7009 struct cleanup
*back_to
;
7010 struct partial_die_info comp_unit_die
;
7011 struct abbrev_info
*abbrev
;
7012 unsigned int bytes_read
;
7015 per_cu
->load_all_dies
= 1;
7017 /* Re-read the DIEs. */
7018 back_to
= make_cleanup (null_cleanup
, 0);
7019 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
7021 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
7022 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
7024 info_ptr
= (dwarf2_per_objfile
->info
.buffer
7025 + per_cu
->cu
->header
.offset
7026 + per_cu
->cu
->header
.first_die_offset
);
7027 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
7028 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
7029 per_cu
->cu
->objfile
->obfd
,
7030 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
7032 if (comp_unit_die
.has_children
)
7033 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
7034 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
7036 do_cleanups (back_to
);
7038 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
7044 internal_error (__FILE__
, __LINE__
,
7045 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
7046 offset
, bfd_get_filename (cu
->objfile
->obfd
));
7050 /* Adjust PART_DIE before generating a symbol for it. This function
7051 may set the is_external flag or change the DIE's name. */
7054 fixup_partial_die (struct partial_die_info
*part_die
,
7055 struct dwarf2_cu
*cu
)
7057 /* If we found a reference attribute and the DIE has no name, try
7058 to find a name in the referred to DIE. */
7060 if (part_die
->name
== NULL
&& part_die
->has_specification
)
7062 struct partial_die_info
*spec_die
;
7064 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
7066 fixup_partial_die (spec_die
, cu
);
7070 part_die
->name
= spec_die
->name
;
7072 /* Copy DW_AT_external attribute if it is set. */
7073 if (spec_die
->is_external
)
7074 part_die
->is_external
= spec_die
->is_external
;
7078 /* Set default names for some unnamed DIEs. */
7079 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
7080 || part_die
->tag
== DW_TAG_class_type
))
7081 part_die
->name
= "(anonymous class)";
7083 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
7084 part_die
->name
= "(anonymous namespace)";
7086 if (part_die
->tag
== DW_TAG_structure_type
7087 || part_die
->tag
== DW_TAG_class_type
7088 || part_die
->tag
== DW_TAG_union_type
)
7089 guess_structure_name (part_die
, cu
);
7092 /* Read an attribute value described by an attribute form. */
7095 read_attribute_value (struct attribute
*attr
, unsigned form
,
7096 bfd
*abfd
, gdb_byte
*info_ptr
,
7097 struct dwarf2_cu
*cu
)
7099 struct comp_unit_head
*cu_header
= &cu
->header
;
7100 unsigned int bytes_read
;
7101 struct dwarf_block
*blk
;
7106 case DW_FORM_ref_addr
:
7107 if (cu
->header
.version
== 2)
7108 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7110 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
7111 info_ptr
+= bytes_read
;
7114 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7115 info_ptr
+= bytes_read
;
7117 case DW_FORM_block2
:
7118 blk
= dwarf_alloc_block (cu
);
7119 blk
->size
= read_2_bytes (abfd
, info_ptr
);
7121 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7122 info_ptr
+= blk
->size
;
7123 DW_BLOCK (attr
) = blk
;
7125 case DW_FORM_block4
:
7126 blk
= dwarf_alloc_block (cu
);
7127 blk
->size
= read_4_bytes (abfd
, info_ptr
);
7129 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7130 info_ptr
+= blk
->size
;
7131 DW_BLOCK (attr
) = blk
;
7134 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
7138 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
7142 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
7145 case DW_FORM_sec_offset
:
7146 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
7147 info_ptr
+= bytes_read
;
7149 case DW_FORM_string
:
7150 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
7151 DW_STRING_IS_CANONICAL (attr
) = 0;
7152 info_ptr
+= bytes_read
;
7155 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
7157 DW_STRING_IS_CANONICAL (attr
) = 0;
7158 info_ptr
+= bytes_read
;
7160 case DW_FORM_exprloc
:
7162 blk
= dwarf_alloc_block (cu
);
7163 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7164 info_ptr
+= bytes_read
;
7165 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7166 info_ptr
+= blk
->size
;
7167 DW_BLOCK (attr
) = blk
;
7169 case DW_FORM_block1
:
7170 blk
= dwarf_alloc_block (cu
);
7171 blk
->size
= read_1_byte (abfd
, info_ptr
);
7173 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7174 info_ptr
+= blk
->size
;
7175 DW_BLOCK (attr
) = blk
;
7178 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7182 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7185 case DW_FORM_flag_present
:
7186 DW_UNSND (attr
) = 1;
7189 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
7190 info_ptr
+= bytes_read
;
7193 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7194 info_ptr
+= bytes_read
;
7197 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
7201 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
7205 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
7209 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
7213 /* Convert the signature to something we can record in DW_UNSND
7215 NOTE: This is NULL if the type wasn't found. */
7216 DW_SIGNATURED_TYPE (attr
) =
7217 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
7220 case DW_FORM_ref_udata
:
7221 DW_ADDR (attr
) = (cu
->header
.offset
7222 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
7223 info_ptr
+= bytes_read
;
7225 case DW_FORM_indirect
:
7226 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7227 info_ptr
+= bytes_read
;
7228 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
7231 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7232 dwarf_form_name (form
),
7233 bfd_get_filename (abfd
));
7236 /* We have seen instances where the compiler tried to emit a byte
7237 size attribute of -1 which ended up being encoded as an unsigned
7238 0xffffffff. Although 0xffffffff is technically a valid size value,
7239 an object of this size seems pretty unlikely so we can relatively
7240 safely treat these cases as if the size attribute was invalid and
7241 treat them as zero by default. */
7242 if (attr
->name
== DW_AT_byte_size
7243 && form
== DW_FORM_data4
7244 && DW_UNSND (attr
) >= 0xffffffff)
7247 (&symfile_complaints
,
7248 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7249 hex_string (DW_UNSND (attr
)));
7250 DW_UNSND (attr
) = 0;
7256 /* Read an attribute described by an abbreviated attribute. */
7259 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
7260 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7262 attr
->name
= abbrev
->name
;
7263 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
7266 /* read dwarf information from a buffer */
7269 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
7271 return bfd_get_8 (abfd
, buf
);
7275 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
7277 return bfd_get_signed_8 (abfd
, buf
);
7281 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
7283 return bfd_get_16 (abfd
, buf
);
7287 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7289 return bfd_get_signed_16 (abfd
, buf
);
7293 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
7295 return bfd_get_32 (abfd
, buf
);
7299 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7301 return bfd_get_signed_32 (abfd
, buf
);
7305 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
7307 return bfd_get_64 (abfd
, buf
);
7311 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
7312 unsigned int *bytes_read
)
7314 struct comp_unit_head
*cu_header
= &cu
->header
;
7315 CORE_ADDR retval
= 0;
7317 if (cu_header
->signed_addr_p
)
7319 switch (cu_header
->addr_size
)
7322 retval
= bfd_get_signed_16 (abfd
, buf
);
7325 retval
= bfd_get_signed_32 (abfd
, buf
);
7328 retval
= bfd_get_signed_64 (abfd
, buf
);
7331 internal_error (__FILE__
, __LINE__
,
7332 _("read_address: bad switch, signed [in module %s]"),
7333 bfd_get_filename (abfd
));
7338 switch (cu_header
->addr_size
)
7341 retval
= bfd_get_16 (abfd
, buf
);
7344 retval
= bfd_get_32 (abfd
, buf
);
7347 retval
= bfd_get_64 (abfd
, buf
);
7350 internal_error (__FILE__
, __LINE__
,
7351 _("read_address: bad switch, unsigned [in module %s]"),
7352 bfd_get_filename (abfd
));
7356 *bytes_read
= cu_header
->addr_size
;
7360 /* Read the initial length from a section. The (draft) DWARF 3
7361 specification allows the initial length to take up either 4 bytes
7362 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7363 bytes describe the length and all offsets will be 8 bytes in length
7366 An older, non-standard 64-bit format is also handled by this
7367 function. The older format in question stores the initial length
7368 as an 8-byte quantity without an escape value. Lengths greater
7369 than 2^32 aren't very common which means that the initial 4 bytes
7370 is almost always zero. Since a length value of zero doesn't make
7371 sense for the 32-bit format, this initial zero can be considered to
7372 be an escape value which indicates the presence of the older 64-bit
7373 format. As written, the code can't detect (old format) lengths
7374 greater than 4GB. If it becomes necessary to handle lengths
7375 somewhat larger than 4GB, we could allow other small values (such
7376 as the non-sensical values of 1, 2, and 3) to also be used as
7377 escape values indicating the presence of the old format.
7379 The value returned via bytes_read should be used to increment the
7380 relevant pointer after calling read_initial_length().
7382 [ Note: read_initial_length() and read_offset() are based on the
7383 document entitled "DWARF Debugging Information Format", revision
7384 3, draft 8, dated November 19, 2001. This document was obtained
7387 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7389 This document is only a draft and is subject to change. (So beware.)
7391 Details regarding the older, non-standard 64-bit format were
7392 determined empirically by examining 64-bit ELF files produced by
7393 the SGI toolchain on an IRIX 6.5 machine.
7395 - Kevin, July 16, 2002
7399 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
7401 LONGEST length
= bfd_get_32 (abfd
, buf
);
7403 if (length
== 0xffffffff)
7405 length
= bfd_get_64 (abfd
, buf
+ 4);
7408 else if (length
== 0)
7410 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7411 length
= bfd_get_64 (abfd
, buf
);
7422 /* Cover function for read_initial_length.
7423 Returns the length of the object at BUF, and stores the size of the
7424 initial length in *BYTES_READ and stores the size that offsets will be in
7426 If the initial length size is not equivalent to that specified in
7427 CU_HEADER then issue a complaint.
7428 This is useful when reading non-comp-unit headers. */
7431 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
7432 const struct comp_unit_head
*cu_header
,
7433 unsigned int *bytes_read
,
7434 unsigned int *offset_size
)
7436 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
7438 gdb_assert (cu_header
->initial_length_size
== 4
7439 || cu_header
->initial_length_size
== 8
7440 || cu_header
->initial_length_size
== 12);
7442 if (cu_header
->initial_length_size
!= *bytes_read
)
7443 complaint (&symfile_complaints
,
7444 _("intermixed 32-bit and 64-bit DWARF sections"));
7446 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
7450 /* Read an offset from the data stream. The size of the offset is
7451 given by cu_header->offset_size. */
7454 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
7455 unsigned int *bytes_read
)
7457 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
7459 *bytes_read
= cu_header
->offset_size
;
7463 /* Read an offset from the data stream. */
7466 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
7470 switch (offset_size
)
7473 retval
= bfd_get_32 (abfd
, buf
);
7476 retval
= bfd_get_64 (abfd
, buf
);
7479 internal_error (__FILE__
, __LINE__
,
7480 _("read_offset_1: bad switch [in module %s]"),
7481 bfd_get_filename (abfd
));
7488 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
7490 /* If the size of a host char is 8 bits, we can return a pointer
7491 to the buffer, otherwise we have to copy the data to a buffer
7492 allocated on the temporary obstack. */
7493 gdb_assert (HOST_CHAR_BIT
== 8);
7498 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7500 /* If the size of a host char is 8 bits, we can return a pointer
7501 to the string, otherwise we have to copy the string to a buffer
7502 allocated on the temporary obstack. */
7503 gdb_assert (HOST_CHAR_BIT
== 8);
7506 *bytes_read_ptr
= 1;
7509 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
7510 return (char *) buf
;
7514 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
7515 const struct comp_unit_head
*cu_header
,
7516 unsigned int *bytes_read_ptr
)
7518 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
7520 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
7521 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
7523 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7524 bfd_get_filename (abfd
));
7527 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
7529 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7530 bfd_get_filename (abfd
));
7533 gdb_assert (HOST_CHAR_BIT
== 8);
7534 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
7536 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
7539 static unsigned long
7540 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7542 unsigned long result
;
7543 unsigned int num_read
;
7553 byte
= bfd_get_8 (abfd
, buf
);
7556 result
|= ((unsigned long)(byte
& 127) << shift
);
7557 if ((byte
& 128) == 0)
7563 *bytes_read_ptr
= num_read
;
7568 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7571 int i
, shift
, num_read
;
7580 byte
= bfd_get_8 (abfd
, buf
);
7583 result
|= ((long)(byte
& 127) << shift
);
7585 if ((byte
& 128) == 0)
7590 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
7591 result
|= -(((long)1) << shift
);
7592 *bytes_read_ptr
= num_read
;
7596 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7599 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
7605 byte
= bfd_get_8 (abfd
, buf
);
7607 if ((byte
& 128) == 0)
7613 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
7620 cu
->language
= language_c
;
7622 case DW_LANG_C_plus_plus
:
7623 cu
->language
= language_cplus
;
7626 cu
->language
= language_d
;
7628 case DW_LANG_Fortran77
:
7629 case DW_LANG_Fortran90
:
7630 case DW_LANG_Fortran95
:
7631 cu
->language
= language_fortran
;
7633 case DW_LANG_Mips_Assembler
:
7634 cu
->language
= language_asm
;
7637 cu
->language
= language_java
;
7641 cu
->language
= language_ada
;
7643 case DW_LANG_Modula2
:
7644 cu
->language
= language_m2
;
7646 case DW_LANG_Pascal83
:
7647 cu
->language
= language_pascal
;
7650 cu
->language
= language_objc
;
7652 case DW_LANG_Cobol74
:
7653 case DW_LANG_Cobol85
:
7655 cu
->language
= language_minimal
;
7658 cu
->language_defn
= language_def (cu
->language
);
7661 /* Return the named attribute or NULL if not there. */
7663 static struct attribute
*
7664 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
7667 struct attribute
*spec
= NULL
;
7669 for (i
= 0; i
< die
->num_attrs
; ++i
)
7671 if (die
->attrs
[i
].name
== name
)
7672 return &die
->attrs
[i
];
7673 if (die
->attrs
[i
].name
== DW_AT_specification
7674 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
7675 spec
= &die
->attrs
[i
];
7680 die
= follow_die_ref (die
, spec
, &cu
);
7681 return dwarf2_attr (die
, name
, cu
);
7687 /* Return the named attribute or NULL if not there,
7688 but do not follow DW_AT_specification, etc.
7689 This is for use in contexts where we're reading .debug_types dies.
7690 Following DW_AT_specification, DW_AT_abstract_origin will take us
7691 back up the chain, and we want to go down. */
7693 static struct attribute
*
7694 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
7695 struct dwarf2_cu
*cu
)
7699 for (i
= 0; i
< die
->num_attrs
; ++i
)
7700 if (die
->attrs
[i
].name
== name
)
7701 return &die
->attrs
[i
];
7706 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7707 and holds a non-zero value. This function should only be used for
7708 DW_FORM_flag or DW_FORM_flag_present attributes. */
7711 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7713 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7715 return (attr
&& DW_UNSND (attr
));
7719 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7721 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7722 which value is non-zero. However, we have to be careful with
7723 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7724 (via dwarf2_flag_true_p) follows this attribute. So we may
7725 end up accidently finding a declaration attribute that belongs
7726 to a different DIE referenced by the specification attribute,
7727 even though the given DIE does not have a declaration attribute. */
7728 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7729 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7732 /* Return the die giving the specification for DIE, if there is
7733 one. *SPEC_CU is the CU containing DIE on input, and the CU
7734 containing the return value on output. If there is no
7735 specification, but there is an abstract origin, that is
7738 static struct die_info
*
7739 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7741 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7744 if (spec_attr
== NULL
)
7745 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7747 if (spec_attr
== NULL
)
7750 return follow_die_ref (die
, spec_attr
, spec_cu
);
7753 /* Free the line_header structure *LH, and any arrays and strings it
7756 free_line_header (struct line_header
*lh
)
7758 if (lh
->standard_opcode_lengths
)
7759 xfree (lh
->standard_opcode_lengths
);
7761 /* Remember that all the lh->file_names[i].name pointers are
7762 pointers into debug_line_buffer, and don't need to be freed. */
7764 xfree (lh
->file_names
);
7766 /* Similarly for the include directory names. */
7767 if (lh
->include_dirs
)
7768 xfree (lh
->include_dirs
);
7774 /* Add an entry to LH's include directory table. */
7776 add_include_dir (struct line_header
*lh
, char *include_dir
)
7778 /* Grow the array if necessary. */
7779 if (lh
->include_dirs_size
== 0)
7781 lh
->include_dirs_size
= 1; /* for testing */
7782 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7783 * sizeof (*lh
->include_dirs
));
7785 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7787 lh
->include_dirs_size
*= 2;
7788 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7789 (lh
->include_dirs_size
7790 * sizeof (*lh
->include_dirs
)));
7793 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7797 /* Add an entry to LH's file name table. */
7799 add_file_name (struct line_header
*lh
,
7801 unsigned int dir_index
,
7802 unsigned int mod_time
,
7803 unsigned int length
)
7805 struct file_entry
*fe
;
7807 /* Grow the array if necessary. */
7808 if (lh
->file_names_size
== 0)
7810 lh
->file_names_size
= 1; /* for testing */
7811 lh
->file_names
= xmalloc (lh
->file_names_size
7812 * sizeof (*lh
->file_names
));
7814 else if (lh
->num_file_names
>= lh
->file_names_size
)
7816 lh
->file_names_size
*= 2;
7817 lh
->file_names
= xrealloc (lh
->file_names
,
7818 (lh
->file_names_size
7819 * sizeof (*lh
->file_names
)));
7822 fe
= &lh
->file_names
[lh
->num_file_names
++];
7824 fe
->dir_index
= dir_index
;
7825 fe
->mod_time
= mod_time
;
7826 fe
->length
= length
;
7832 /* Read the statement program header starting at OFFSET in
7833 .debug_line, according to the endianness of ABFD. Return a pointer
7834 to a struct line_header, allocated using xmalloc.
7836 NOTE: the strings in the include directory and file name tables of
7837 the returned object point into debug_line_buffer, and must not be
7839 static struct line_header
*
7840 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7841 struct dwarf2_cu
*cu
)
7843 struct cleanup
*back_to
;
7844 struct line_header
*lh
;
7846 unsigned int bytes_read
, offset_size
;
7848 char *cur_dir
, *cur_file
;
7850 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
7851 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7853 complaint (&symfile_complaints
, _("missing .debug_line section"));
7857 /* Make sure that at least there's room for the total_length field.
7858 That could be 12 bytes long, but we're just going to fudge that. */
7859 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7861 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7865 lh
= xmalloc (sizeof (*lh
));
7866 memset (lh
, 0, sizeof (*lh
));
7867 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7870 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7872 /* Read in the header. */
7874 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7875 &bytes_read
, &offset_size
);
7876 line_ptr
+= bytes_read
;
7877 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7878 + dwarf2_per_objfile
->line
.size
))
7880 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7883 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7884 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7886 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7887 line_ptr
+= offset_size
;
7888 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7890 if (lh
->version
>= 4)
7892 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
7896 lh
->maximum_ops_per_instruction
= 1;
7898 if (lh
->maximum_ops_per_instruction
== 0)
7900 lh
->maximum_ops_per_instruction
= 1;
7901 complaint (&symfile_complaints
,
7902 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
7905 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7907 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7909 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7911 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7913 lh
->standard_opcode_lengths
7914 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7916 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7917 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7919 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7923 /* Read directory table. */
7924 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7926 line_ptr
+= bytes_read
;
7927 add_include_dir (lh
, cur_dir
);
7929 line_ptr
+= bytes_read
;
7931 /* Read file name table. */
7932 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7934 unsigned int dir_index
, mod_time
, length
;
7936 line_ptr
+= bytes_read
;
7937 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7938 line_ptr
+= bytes_read
;
7939 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7940 line_ptr
+= bytes_read
;
7941 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7942 line_ptr
+= bytes_read
;
7944 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7946 line_ptr
+= bytes_read
;
7947 lh
->statement_program_start
= line_ptr
;
7949 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7950 + dwarf2_per_objfile
->line
.size
))
7951 complaint (&symfile_complaints
,
7952 _("line number info header doesn't fit in `.debug_line' section"));
7954 discard_cleanups (back_to
);
7958 /* This function exists to work around a bug in certain compilers
7959 (particularly GCC 2.95), in which the first line number marker of a
7960 function does not show up until after the prologue, right before
7961 the second line number marker. This function shifts ADDRESS down
7962 to the beginning of the function if necessary, and is called on
7963 addresses passed to record_line. */
7966 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7968 struct function_range
*fn
;
7970 /* Find the function_range containing address. */
7975 cu
->cached_fn
= cu
->first_fn
;
7979 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7985 while (fn
&& fn
!= cu
->cached_fn
)
7986 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7996 if (address
!= fn
->lowpc
)
7997 complaint (&symfile_complaints
,
7998 _("misplaced first line number at 0x%lx for '%s'"),
7999 (unsigned long) address
, fn
->name
);
8004 /* Decode the Line Number Program (LNP) for the given line_header
8005 structure and CU. The actual information extracted and the type
8006 of structures created from the LNP depends on the value of PST.
8008 1. If PST is NULL, then this procedure uses the data from the program
8009 to create all necessary symbol tables, and their linetables.
8010 The compilation directory of the file is passed in COMP_DIR,
8011 and must not be NULL.
8013 2. If PST is not NULL, this procedure reads the program to determine
8014 the list of files included by the unit represented by PST, and
8015 builds all the associated partial symbol tables. In this case,
8016 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
8017 is not used to compute the full name of the symtab, and therefore
8018 omitting it when building the partial symtab does not introduce
8019 the potential for inconsistency - a partial symtab and its associated
8020 symbtab having a different fullname -). */
8023 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
8024 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
8026 gdb_byte
*line_ptr
, *extended_end
;
8028 unsigned int bytes_read
, extended_len
;
8029 unsigned char op_code
, extended_op
, adj_opcode
;
8031 struct objfile
*objfile
= cu
->objfile
;
8032 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8033 const int decode_for_pst_p
= (pst
!= NULL
);
8034 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
8036 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8038 line_ptr
= lh
->statement_program_start
;
8039 line_end
= lh
->statement_program_end
;
8041 /* Read the statement sequences until there's nothing left. */
8042 while (line_ptr
< line_end
)
8044 /* state machine registers */
8045 CORE_ADDR address
= 0;
8046 unsigned int file
= 1;
8047 unsigned int line
= 1;
8048 unsigned int column
= 0;
8049 int is_stmt
= lh
->default_is_stmt
;
8050 int basic_block
= 0;
8051 int end_sequence
= 0;
8053 unsigned char op_index
= 0;
8055 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
8057 /* Start a subfile for the current file of the state machine. */
8058 /* lh->include_dirs and lh->file_names are 0-based, but the
8059 directory and file name numbers in the statement program
8061 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8065 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8067 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8070 /* Decode the table. */
8071 while (!end_sequence
)
8073 op_code
= read_1_byte (abfd
, line_ptr
);
8075 if (line_ptr
> line_end
)
8077 dwarf2_debug_line_missing_end_sequence_complaint ();
8081 if (op_code
>= lh
->opcode_base
)
8083 /* Special operand. */
8084 adj_opcode
= op_code
- lh
->opcode_base
;
8085 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
8086 / lh
->maximum_ops_per_instruction
)
8087 * lh
->minimum_instruction_length
);
8088 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
8089 % lh
->maximum_ops_per_instruction
);
8090 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
8091 if (lh
->num_file_names
< file
|| file
== 0)
8092 dwarf2_debug_line_missing_file_complaint ();
8093 /* For now we ignore lines not starting on an
8094 instruction boundary. */
8095 else if (op_index
== 0)
8097 lh
->file_names
[file
- 1].included_p
= 1;
8098 if (!decode_for_pst_p
&& is_stmt
)
8100 if (last_subfile
!= current_subfile
)
8102 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8104 record_line (last_subfile
, 0, addr
);
8105 last_subfile
= current_subfile
;
8107 /* Append row to matrix using current values. */
8108 addr
= check_cu_functions (address
, cu
);
8109 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8110 record_line (current_subfile
, line
, addr
);
8115 else switch (op_code
)
8117 case DW_LNS_extended_op
:
8118 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8119 line_ptr
+= bytes_read
;
8120 extended_end
= line_ptr
+ extended_len
;
8121 extended_op
= read_1_byte (abfd
, line_ptr
);
8123 switch (extended_op
)
8125 case DW_LNE_end_sequence
:
8128 case DW_LNE_set_address
:
8129 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
8131 line_ptr
+= bytes_read
;
8132 address
+= baseaddr
;
8134 case DW_LNE_define_file
:
8137 unsigned int dir_index
, mod_time
, length
;
8139 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
8140 line_ptr
+= bytes_read
;
8142 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8143 line_ptr
+= bytes_read
;
8145 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8146 line_ptr
+= bytes_read
;
8148 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8149 line_ptr
+= bytes_read
;
8150 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
8153 case DW_LNE_set_discriminator
:
8154 /* The discriminator is not interesting to the debugger;
8156 line_ptr
= extended_end
;
8159 complaint (&symfile_complaints
,
8160 _("mangled .debug_line section"));
8163 /* Make sure that we parsed the extended op correctly. If e.g.
8164 we expected a different address size than the producer used,
8165 we may have read the wrong number of bytes. */
8166 if (line_ptr
!= extended_end
)
8168 complaint (&symfile_complaints
,
8169 _("mangled .debug_line section"));
8174 if (lh
->num_file_names
< file
|| file
== 0)
8175 dwarf2_debug_line_missing_file_complaint ();
8178 lh
->file_names
[file
- 1].included_p
= 1;
8179 if (!decode_for_pst_p
&& is_stmt
)
8181 if (last_subfile
!= current_subfile
)
8183 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8185 record_line (last_subfile
, 0, addr
);
8186 last_subfile
= current_subfile
;
8188 addr
= check_cu_functions (address
, cu
);
8189 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8190 record_line (current_subfile
, line
, addr
);
8195 case DW_LNS_advance_pc
:
8198 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8200 address
+= (((op_index
+ adjust
)
8201 / lh
->maximum_ops_per_instruction
)
8202 * lh
->minimum_instruction_length
);
8203 op_index
= ((op_index
+ adjust
)
8204 % lh
->maximum_ops_per_instruction
);
8205 line_ptr
+= bytes_read
;
8208 case DW_LNS_advance_line
:
8209 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
8210 line_ptr
+= bytes_read
;
8212 case DW_LNS_set_file
:
8214 /* The arrays lh->include_dirs and lh->file_names are
8215 0-based, but the directory and file name numbers in
8216 the statement program are 1-based. */
8217 struct file_entry
*fe
;
8220 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8221 line_ptr
+= bytes_read
;
8222 if (lh
->num_file_names
< file
|| file
== 0)
8223 dwarf2_debug_line_missing_file_complaint ();
8226 fe
= &lh
->file_names
[file
- 1];
8228 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8229 if (!decode_for_pst_p
)
8231 last_subfile
= current_subfile
;
8232 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8237 case DW_LNS_set_column
:
8238 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8239 line_ptr
+= bytes_read
;
8241 case DW_LNS_negate_stmt
:
8242 is_stmt
= (!is_stmt
);
8244 case DW_LNS_set_basic_block
:
8247 /* Add to the address register of the state machine the
8248 address increment value corresponding to special opcode
8249 255. I.e., this value is scaled by the minimum
8250 instruction length since special opcode 255 would have
8251 scaled the the increment. */
8252 case DW_LNS_const_add_pc
:
8254 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
8256 address
+= (((op_index
+ adjust
)
8257 / lh
->maximum_ops_per_instruction
)
8258 * lh
->minimum_instruction_length
);
8259 op_index
= ((op_index
+ adjust
)
8260 % lh
->maximum_ops_per_instruction
);
8263 case DW_LNS_fixed_advance_pc
:
8264 address
+= read_2_bytes (abfd
, line_ptr
);
8270 /* Unknown standard opcode, ignore it. */
8273 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
8275 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8276 line_ptr
+= bytes_read
;
8281 if (lh
->num_file_names
< file
|| file
== 0)
8282 dwarf2_debug_line_missing_file_complaint ();
8285 lh
->file_names
[file
- 1].included_p
= 1;
8286 if (!decode_for_pst_p
)
8288 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8289 record_line (current_subfile
, 0, addr
);
8294 if (decode_for_pst_p
)
8298 /* Now that we're done scanning the Line Header Program, we can
8299 create the psymtab of each included file. */
8300 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
8301 if (lh
->file_names
[file_index
].included_p
== 1)
8303 const struct file_entry fe
= lh
->file_names
[file_index
];
8304 char *include_name
= fe
.name
;
8305 char *dir_name
= NULL
;
8306 char *pst_filename
= pst
->filename
;
8309 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
8311 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
8313 include_name
= concat (dir_name
, SLASH_STRING
,
8314 include_name
, (char *)NULL
);
8315 make_cleanup (xfree
, include_name
);
8318 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
8320 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
8321 pst_filename
, (char *)NULL
);
8322 make_cleanup (xfree
, pst_filename
);
8325 if (strcmp (include_name
, pst_filename
) != 0)
8326 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
8331 /* Make sure a symtab is created for every file, even files
8332 which contain only variables (i.e. no code with associated
8336 struct file_entry
*fe
;
8338 for (i
= 0; i
< lh
->num_file_names
; i
++)
8342 fe
= &lh
->file_names
[i
];
8344 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8345 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8347 /* Skip the main file; we don't need it, and it must be
8348 allocated last, so that it will show up before the
8349 non-primary symtabs in the objfile's symtab list. */
8350 if (current_subfile
== first_subfile
)
8353 if (current_subfile
->symtab
== NULL
)
8354 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8356 fe
->symtab
= current_subfile
->symtab
;
8361 /* Start a subfile for DWARF. FILENAME is the name of the file and
8362 DIRNAME the name of the source directory which contains FILENAME
8363 or NULL if not known. COMP_DIR is the compilation directory for the
8364 linetable's compilation unit or NULL if not known.
8365 This routine tries to keep line numbers from identical absolute and
8366 relative file names in a common subfile.
8368 Using the `list' example from the GDB testsuite, which resides in
8369 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8370 of /srcdir/list0.c yields the following debugging information for list0.c:
8372 DW_AT_name: /srcdir/list0.c
8373 DW_AT_comp_dir: /compdir
8374 files.files[0].name: list0.h
8375 files.files[0].dir: /srcdir
8376 files.files[1].name: list0.c
8377 files.files[1].dir: /srcdir
8379 The line number information for list0.c has to end up in a single
8380 subfile, so that `break /srcdir/list0.c:1' works as expected.
8381 start_subfile will ensure that this happens provided that we pass the
8382 concatenation of files.files[1].dir and files.files[1].name as the
8386 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
8390 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8391 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8392 second argument to start_subfile. To be consistent, we do the
8393 same here. In order not to lose the line information directory,
8394 we concatenate it to the filename when it makes sense.
8395 Note that the Dwarf3 standard says (speaking of filenames in line
8396 information): ``The directory index is ignored for file names
8397 that represent full path names''. Thus ignoring dirname in the
8398 `else' branch below isn't an issue. */
8400 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
8401 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
8403 fullname
= filename
;
8405 start_subfile (fullname
, comp_dir
);
8407 if (fullname
!= filename
)
8412 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
8413 struct dwarf2_cu
*cu
)
8415 struct objfile
*objfile
= cu
->objfile
;
8416 struct comp_unit_head
*cu_header
= &cu
->header
;
8418 /* NOTE drow/2003-01-30: There used to be a comment and some special
8419 code here to turn a symbol with DW_AT_external and a
8420 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8421 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8422 with some versions of binutils) where shared libraries could have
8423 relocations against symbols in their debug information - the
8424 minimal symbol would have the right address, but the debug info
8425 would not. It's no longer necessary, because we will explicitly
8426 apply relocations when we read in the debug information now. */
8428 /* A DW_AT_location attribute with no contents indicates that a
8429 variable has been optimized away. */
8430 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
8432 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8436 /* Handle one degenerate form of location expression specially, to
8437 preserve GDB's previous behavior when section offsets are
8438 specified. If this is just a DW_OP_addr then mark this symbol
8441 if (attr_form_is_block (attr
)
8442 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
8443 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
8447 SYMBOL_VALUE_ADDRESS (sym
) =
8448 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
8449 SYMBOL_CLASS (sym
) = LOC_STATIC
;
8450 fixup_symbol_section (sym
, objfile
);
8451 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
8452 SYMBOL_SECTION (sym
));
8456 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8457 expression evaluator, and use LOC_COMPUTED only when necessary
8458 (i.e. when the value of a register or memory location is
8459 referenced, or a thread-local block, etc.). Then again, it might
8460 not be worthwhile. I'm assuming that it isn't unless performance
8461 or memory numbers show me otherwise. */
8463 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
8464 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
8467 /* Given a pointer to a DWARF information entry, figure out if we need
8468 to make a symbol table entry for it, and if so, create a new entry
8469 and return a pointer to it.
8470 If TYPE is NULL, determine symbol type from the die, otherwise
8471 used the passed type. */
8473 static struct symbol
*
8474 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
8476 struct objfile
*objfile
= cu
->objfile
;
8477 struct symbol
*sym
= NULL
;
8479 struct attribute
*attr
= NULL
;
8480 struct attribute
*attr2
= NULL
;
8482 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8484 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8486 name
= dwarf2_name (die
, cu
);
8489 const char *linkagename
;
8491 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
8492 sizeof (struct symbol
));
8493 OBJSTAT (objfile
, n_syms
++);
8494 memset (sym
, 0, sizeof (struct symbol
));
8496 /* Cache this symbol's name and the name's demangled form (if any). */
8497 SYMBOL_LANGUAGE (sym
) = cu
->language
;
8498 linkagename
= dwarf2_physname (name
, die
, cu
);
8499 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
8501 /* Default assumptions.
8502 Use the passed type or decode it from the die. */
8503 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8504 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8506 SYMBOL_TYPE (sym
) = type
;
8508 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
8509 attr
= dwarf2_attr (die
,
8510 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
8514 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
8517 attr
= dwarf2_attr (die
,
8518 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
8522 int file_index
= DW_UNSND (attr
);
8524 if (cu
->line_header
== NULL
8525 || file_index
> cu
->line_header
->num_file_names
)
8526 complaint (&symfile_complaints
,
8527 _("file index out of range"));
8528 else if (file_index
> 0)
8530 struct file_entry
*fe
;
8532 fe
= &cu
->line_header
->file_names
[file_index
- 1];
8533 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
8540 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8543 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
8545 SYMBOL_CLASS (sym
) = LOC_LABEL
;
8547 case DW_TAG_subprogram
:
8548 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8550 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8551 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8552 if ((attr2
&& (DW_UNSND (attr2
) != 0))
8553 || cu
->language
== language_ada
)
8555 /* Subprograms marked external are stored as a global symbol.
8556 Ada subprograms, whether marked external or not, are always
8557 stored as a global symbol, because we want to be able to
8558 access them globally. For instance, we want to be able
8559 to break on a nested subprogram without having to
8560 specify the context. */
8561 add_symbol_to_list (sym
, &global_symbols
);
8565 add_symbol_to_list (sym
, cu
->list_in_scope
);
8568 case DW_TAG_inlined_subroutine
:
8569 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8571 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8572 SYMBOL_INLINED (sym
) = 1;
8573 /* Do not add the symbol to any lists. It will be found via
8574 BLOCK_FUNCTION from the blockvector. */
8576 case DW_TAG_variable
:
8577 /* Compilation with minimal debug info may result in variables
8578 with missing type entries. Change the misleading `void' type
8579 to something sensible. */
8580 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
8582 = objfile_type (objfile
)->nodebug_data_symbol
;
8584 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8587 dwarf2_const_value (attr
, sym
, cu
);
8588 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8589 if (attr2
&& (DW_UNSND (attr2
) != 0))
8590 add_symbol_to_list (sym
, &global_symbols
);
8592 add_symbol_to_list (sym
, cu
->list_in_scope
);
8595 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8598 var_decode_location (attr
, sym
, cu
);
8599 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8600 if (attr2
&& (DW_UNSND (attr2
) != 0))
8602 struct pending
**list_to_add
;
8604 /* A variable with DW_AT_external is never static,
8605 but it may be block-scoped. */
8606 list_to_add
= (cu
->list_in_scope
== &file_symbols
8607 ? &global_symbols
: cu
->list_in_scope
);
8608 add_symbol_to_list (sym
, list_to_add
);
8611 add_symbol_to_list (sym
, cu
->list_in_scope
);
8615 /* We do not know the address of this symbol.
8616 If it is an external symbol and we have type information
8617 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8618 The address of the variable will then be determined from
8619 the minimal symbol table whenever the variable is
8621 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8622 if (attr2
&& (DW_UNSND (attr2
) != 0)
8623 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
8625 struct pending
**list_to_add
;
8627 /* A variable with DW_AT_external is never static, but it
8628 may be block-scoped. */
8629 list_to_add
= (cu
->list_in_scope
== &file_symbols
8630 ? &global_symbols
: cu
->list_in_scope
);
8632 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8633 add_symbol_to_list (sym
, list_to_add
);
8635 else if (!die_is_declaration (die
, cu
))
8637 /* Use the default LOC_OPTIMIZED_OUT class. */
8638 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
8639 add_symbol_to_list (sym
, cu
->list_in_scope
);
8643 case DW_TAG_formal_parameter
:
8644 /* If we are inside a function, mark this as an argument. If
8645 not, we might be looking at an argument to an inlined function
8646 when we do not have enough information to show inlined frames;
8647 pretend it's a local variable in that case so that the user can
8649 if (context_stack_depth
> 0
8650 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
8651 SYMBOL_IS_ARGUMENT (sym
) = 1;
8652 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8655 var_decode_location (attr
, sym
, cu
);
8657 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8660 dwarf2_const_value (attr
, sym
, cu
);
8662 add_symbol_to_list (sym
, cu
->list_in_scope
);
8664 case DW_TAG_unspecified_parameters
:
8665 /* From varargs functions; gdb doesn't seem to have any
8666 interest in this information, so just ignore it for now.
8669 case DW_TAG_class_type
:
8670 case DW_TAG_interface_type
:
8671 case DW_TAG_structure_type
:
8672 case DW_TAG_union_type
:
8673 case DW_TAG_set_type
:
8674 case DW_TAG_enumeration_type
:
8675 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8676 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8678 /* Make sure that the symbol includes appropriate enclosing
8679 classes/namespaces in its name. These are calculated in
8680 read_structure_type, and the correct name is saved in
8683 if (cu
->language
== language_cplus
8684 || cu
->language
== language_java
)
8686 struct type
*type
= SYMBOL_TYPE (sym
);
8688 if (TYPE_TAG_NAME (type
) != NULL
)
8690 /* FIXME: carlton/2003-11-10: Should this use
8691 SYMBOL_SET_NAMES instead? (The same problem also
8692 arises further down in this function.) */
8693 /* The type's name is already allocated along with
8694 this objfile, so we don't need to duplicate it
8696 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
8701 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8702 really ever be static objects: otherwise, if you try
8703 to, say, break of a class's method and you're in a file
8704 which doesn't mention that class, it won't work unless
8705 the check for all static symbols in lookup_symbol_aux
8706 saves you. See the OtherFileClass tests in
8707 gdb.c++/namespace.exp. */
8709 struct pending
**list_to_add
;
8711 list_to_add
= (cu
->list_in_scope
== &file_symbols
8712 && (cu
->language
== language_cplus
8713 || cu
->language
== language_java
)
8714 ? &global_symbols
: cu
->list_in_scope
);
8716 add_symbol_to_list (sym
, list_to_add
);
8718 /* The semantics of C++ state that "struct foo { ... }" also
8719 defines a typedef for "foo". A Java class declaration also
8720 defines a typedef for the class. */
8721 if (cu
->language
== language_cplus
8722 || cu
->language
== language_java
8723 || cu
->language
== language_ada
)
8725 /* The symbol's name is already allocated along with
8726 this objfile, so we don't need to duplicate it for
8728 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
8729 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
8733 case DW_TAG_typedef
:
8734 SYMBOL_LINKAGE_NAME (sym
)
8735 = (char *) dwarf2_full_name (name
, die
, cu
);
8736 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8737 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8738 add_symbol_to_list (sym
, cu
->list_in_scope
);
8740 case DW_TAG_base_type
:
8741 case DW_TAG_subrange_type
:
8742 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8743 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8744 add_symbol_to_list (sym
, cu
->list_in_scope
);
8746 case DW_TAG_enumerator
:
8747 SYMBOL_LINKAGE_NAME (sym
)
8748 = (char *) dwarf2_full_name (name
, die
, cu
);
8749 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8752 dwarf2_const_value (attr
, sym
, cu
);
8755 /* NOTE: carlton/2003-11-10: See comment above in the
8756 DW_TAG_class_type, etc. block. */
8758 struct pending
**list_to_add
;
8760 list_to_add
= (cu
->list_in_scope
== &file_symbols
8761 && (cu
->language
== language_cplus
8762 || cu
->language
== language_java
)
8763 ? &global_symbols
: cu
->list_in_scope
);
8765 add_symbol_to_list (sym
, list_to_add
);
8768 case DW_TAG_namespace
:
8769 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8770 add_symbol_to_list (sym
, &global_symbols
);
8773 /* Not a tag we recognize. Hopefully we aren't processing
8774 trash data, but since we must specifically ignore things
8775 we don't recognize, there is nothing else we should do at
8777 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8778 dwarf_tag_name (die
->tag
));
8782 /* For the benefit of old versions of GCC, check for anonymous
8783 namespaces based on the demangled name. */
8784 if (!processing_has_namespace_info
8785 && cu
->language
== language_cplus
)
8786 cp_scan_for_anonymous_namespaces (sym
);
8791 /* Copy constant value from an attribute to a symbol. */
8794 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8795 struct dwarf2_cu
*cu
)
8797 struct objfile
*objfile
= cu
->objfile
;
8798 struct comp_unit_head
*cu_header
= &cu
->header
;
8799 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
8800 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
8801 struct dwarf_block
*blk
;
8806 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8807 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8808 cu_header
->addr_size
,
8809 TYPE_LENGTH (SYMBOL_TYPE
8811 SYMBOL_VALUE_BYTES (sym
) =
8812 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8813 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8814 it's body - store_unsigned_integer. */
8815 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8816 byte_order
, DW_ADDR (attr
));
8817 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8819 case DW_FORM_string
:
8821 /* DW_STRING is already allocated on the obstack, point directly
8823 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8824 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8826 case DW_FORM_block1
:
8827 case DW_FORM_block2
:
8828 case DW_FORM_block4
:
8830 case DW_FORM_exprloc
:
8831 blk
= DW_BLOCK (attr
);
8832 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8833 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8835 TYPE_LENGTH (SYMBOL_TYPE
8837 SYMBOL_VALUE_BYTES (sym
) =
8838 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8839 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8840 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8843 /* The DW_AT_const_value attributes are supposed to carry the
8844 symbol's value "represented as it would be on the target
8845 architecture." By the time we get here, it's already been
8846 converted to host endianness, so we just need to sign- or
8847 zero-extend it as appropriate. */
8849 dwarf2_const_value_data (attr
, sym
, 8);
8852 dwarf2_const_value_data (attr
, sym
, 16);
8855 dwarf2_const_value_data (attr
, sym
, 32);
8858 dwarf2_const_value_data (attr
, sym
, 64);
8862 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8863 SYMBOL_CLASS (sym
) = LOC_CONST
;
8867 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8868 SYMBOL_CLASS (sym
) = LOC_CONST
;
8872 complaint (&symfile_complaints
,
8873 _("unsupported const value attribute form: '%s'"),
8874 dwarf_form_name (attr
->form
));
8875 SYMBOL_VALUE (sym
) = 0;
8876 SYMBOL_CLASS (sym
) = LOC_CONST
;
8882 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8883 or zero-extend it as appropriate for the symbol's type. */
8885 dwarf2_const_value_data (struct attribute
*attr
,
8889 LONGEST l
= DW_UNSND (attr
);
8891 if (bits
< sizeof (l
) * 8)
8893 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8894 l
&= ((LONGEST
) 1 << bits
) - 1;
8896 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8899 SYMBOL_VALUE (sym
) = l
;
8900 SYMBOL_CLASS (sym
) = LOC_CONST
;
8904 /* Return the type of the die in question using its DW_AT_type attribute. */
8906 static struct type
*
8907 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8909 struct attribute
*type_attr
;
8910 struct die_info
*type_die
;
8912 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8915 /* A missing DW_AT_type represents a void type. */
8916 return objfile_type (cu
->objfile
)->builtin_void
;
8919 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8921 return tag_type_to_type (type_die
, cu
);
8924 /* True iff CU's producer generates GNAT Ada auxiliary information
8925 that allows to find parallel types through that information instead
8926 of having to do expensive parallel lookups by type name. */
8929 need_gnat_info (struct dwarf2_cu
*cu
)
8931 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8932 of GNAT produces this auxiliary information, without any indication
8933 that it is produced. Part of enhancing the FSF version of GNAT
8934 to produce that information will be to put in place an indicator
8935 that we can use in order to determine whether the descriptive type
8936 info is available or not. One suggestion that has been made is
8937 to use a new attribute, attached to the CU die. For now, assume
8938 that the descriptive type info is not available. */
8943 /* Return the auxiliary type of the die in question using its
8944 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8945 attribute is not present. */
8947 static struct type
*
8948 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8950 struct attribute
*type_attr
;
8951 struct die_info
*type_die
;
8953 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
8957 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8958 return tag_type_to_type (type_die
, cu
);
8961 /* If DIE has a descriptive_type attribute, then set the TYPE's
8962 descriptive type accordingly. */
8965 set_descriptive_type (struct type
*type
, struct die_info
*die
,
8966 struct dwarf2_cu
*cu
)
8968 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
8970 if (descriptive_type
)
8972 ALLOCATE_GNAT_AUX_TYPE (type
);
8973 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
8977 /* Return the containing type of the die in question using its
8978 DW_AT_containing_type attribute. */
8980 static struct type
*
8981 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8983 struct attribute
*type_attr
;
8984 struct die_info
*type_die
;
8986 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8988 error (_("Dwarf Error: Problem turning containing type into gdb type "
8989 "[in module %s]"), cu
->objfile
->name
);
8991 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8992 return tag_type_to_type (type_die
, cu
);
8995 static struct type
*
8996 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8998 struct type
*this_type
;
9000 this_type
= read_type_die (die
, cu
);
9003 dump_die_for_error (die
);
9004 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
9010 static struct type
*
9011 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9013 struct type
*this_type
;
9015 this_type
= get_die_type (die
, cu
);
9021 case DW_TAG_class_type
:
9022 case DW_TAG_interface_type
:
9023 case DW_TAG_structure_type
:
9024 case DW_TAG_union_type
:
9025 this_type
= read_structure_type (die
, cu
);
9027 case DW_TAG_enumeration_type
:
9028 this_type
= read_enumeration_type (die
, cu
);
9030 case DW_TAG_subprogram
:
9031 case DW_TAG_subroutine_type
:
9032 case DW_TAG_inlined_subroutine
:
9033 this_type
= read_subroutine_type (die
, cu
);
9035 case DW_TAG_array_type
:
9036 this_type
= read_array_type (die
, cu
);
9038 case DW_TAG_set_type
:
9039 this_type
= read_set_type (die
, cu
);
9041 case DW_TAG_pointer_type
:
9042 this_type
= read_tag_pointer_type (die
, cu
);
9044 case DW_TAG_ptr_to_member_type
:
9045 this_type
= read_tag_ptr_to_member_type (die
, cu
);
9047 case DW_TAG_reference_type
:
9048 this_type
= read_tag_reference_type (die
, cu
);
9050 case DW_TAG_const_type
:
9051 this_type
= read_tag_const_type (die
, cu
);
9053 case DW_TAG_volatile_type
:
9054 this_type
= read_tag_volatile_type (die
, cu
);
9056 case DW_TAG_string_type
:
9057 this_type
= read_tag_string_type (die
, cu
);
9059 case DW_TAG_typedef
:
9060 this_type
= read_typedef (die
, cu
);
9062 case DW_TAG_subrange_type
:
9063 this_type
= read_subrange_type (die
, cu
);
9065 case DW_TAG_base_type
:
9066 this_type
= read_base_type (die
, cu
);
9068 case DW_TAG_unspecified_type
:
9069 this_type
= read_unspecified_type (die
, cu
);
9071 case DW_TAG_namespace
:
9072 this_type
= read_namespace_type (die
, cu
);
9075 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
9076 dwarf_tag_name (die
->tag
));
9083 /* Return the name of the namespace/class that DIE is defined within,
9084 or "" if we can't tell. The caller should not xfree the result.
9086 For example, if we're within the method foo() in the following
9096 then determine_prefix on foo's die will return "N::C". */
9099 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
9101 struct die_info
*parent
, *spec_die
;
9102 struct dwarf2_cu
*spec_cu
;
9103 struct type
*parent_type
;
9105 if (cu
->language
!= language_cplus
9106 && cu
->language
!= language_java
)
9109 /* We have to be careful in the presence of DW_AT_specification.
9110 For example, with GCC 3.4, given the code
9114 // Definition of N::foo.
9118 then we'll have a tree of DIEs like this:
9120 1: DW_TAG_compile_unit
9121 2: DW_TAG_namespace // N
9122 3: DW_TAG_subprogram // declaration of N::foo
9123 4: DW_TAG_subprogram // definition of N::foo
9124 DW_AT_specification // refers to die #3
9126 Thus, when processing die #4, we have to pretend that we're in
9127 the context of its DW_AT_specification, namely the contex of die
9130 spec_die
= die_specification (die
, &spec_cu
);
9131 if (spec_die
== NULL
)
9132 parent
= die
->parent
;
9135 parent
= spec_die
->parent
;
9142 switch (parent
->tag
)
9144 case DW_TAG_namespace
:
9145 parent_type
= read_type_die (parent
, cu
);
9146 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9147 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9148 Work around this problem here. */
9149 if (cu
->language
== language_cplus
9150 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
9152 /* We give a name to even anonymous namespaces. */
9153 return TYPE_TAG_NAME (parent_type
);
9154 case DW_TAG_class_type
:
9155 case DW_TAG_interface_type
:
9156 case DW_TAG_structure_type
:
9157 case DW_TAG_union_type
:
9158 parent_type
= read_type_die (parent
, cu
);
9159 if (TYPE_TAG_NAME (parent_type
) != NULL
)
9160 return TYPE_TAG_NAME (parent_type
);
9162 /* An anonymous structure is only allowed non-static data
9163 members; no typedefs, no member functions, et cetera.
9164 So it does not need a prefix. */
9167 return determine_prefix (parent
, cu
);
9171 /* Return a newly-allocated string formed by concatenating PREFIX and
9172 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9173 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9174 perform an obconcat, otherwise allocate storage for the result. The CU argument
9175 is used to determine the language and hence, the appropriate separator. */
9177 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9180 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9181 struct dwarf2_cu
*cu
)
9185 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9187 else if (cu
->language
== language_java
)
9199 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9201 strcpy (retval
, prefix
);
9202 strcat (retval
, sep
);
9203 strcat (retval
, suffix
);
9208 /* We have an obstack. */
9209 return obconcat (obs
, prefix
, sep
, suffix
, (char *) NULL
);
9213 /* Return sibling of die, NULL if no sibling. */
9215 static struct die_info
*
9216 sibling_die (struct die_info
*die
)
9218 return die
->sibling
;
9221 /* Get name of a die, return NULL if not found. */
9224 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9225 struct obstack
*obstack
)
9227 if (name
&& cu
->language
== language_cplus
)
9229 char *canon_name
= cp_canonicalize_string (name
);
9231 if (canon_name
!= NULL
)
9233 if (strcmp (canon_name
, name
) != 0)
9234 name
= obsavestring (canon_name
, strlen (canon_name
),
9243 /* Get name of a die, return NULL if not found. */
9246 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9248 struct attribute
*attr
;
9250 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9251 if (!attr
|| !DW_STRING (attr
))
9256 case DW_TAG_compile_unit
:
9257 /* Compilation units have a DW_AT_name that is a filename, not
9258 a source language identifier. */
9259 case DW_TAG_enumeration_type
:
9260 case DW_TAG_enumerator
:
9261 /* These tags always have simple identifiers already; no need
9262 to canonicalize them. */
9263 return DW_STRING (attr
);
9265 case DW_TAG_subprogram
:
9266 /* Java constructors will all be named "<init>", so return
9267 the class name when we see this special case. */
9268 if (cu
->language
== language_java
9269 && DW_STRING (attr
) != NULL
9270 && strcmp (DW_STRING (attr
), "<init>") == 0)
9272 struct dwarf2_cu
*spec_cu
= cu
;
9273 struct die_info
*spec_die
;
9275 /* GCJ will output '<init>' for Java constructor names.
9276 For this special case, return the name of the parent class. */
9278 /* GCJ may output suprogram DIEs with AT_specification set.
9279 If so, use the name of the specified DIE. */
9280 spec_die
= die_specification (die
, &spec_cu
);
9281 if (spec_die
!= NULL
)
9282 return dwarf2_name (spec_die
, spec_cu
);
9287 if (die
->tag
== DW_TAG_class_type
)
9288 return dwarf2_name (die
, cu
);
9290 while (die
->tag
!= DW_TAG_compile_unit
);
9294 case DW_TAG_class_type
:
9295 case DW_TAG_interface_type
:
9296 case DW_TAG_structure_type
:
9297 case DW_TAG_union_type
:
9298 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
9299 structures or unions. These were of the form "._%d" in GCC 4.1,
9300 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
9301 and GCC 4.4. We work around this problem by ignoring these. */
9302 if (strncmp (DW_STRING (attr
), "._", 2) == 0
9303 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
9311 if (!DW_STRING_IS_CANONICAL (attr
))
9314 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9315 &cu
->objfile
->objfile_obstack
);
9316 DW_STRING_IS_CANONICAL (attr
) = 1;
9318 return DW_STRING (attr
);
9321 /* Return the die that this die in an extension of, or NULL if there
9322 is none. *EXT_CU is the CU containing DIE on input, and the CU
9323 containing the return value on output. */
9325 static struct die_info
*
9326 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9328 struct attribute
*attr
;
9330 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9334 return follow_die_ref (die
, attr
, ext_cu
);
9337 /* Convert a DIE tag into its string name. */
9340 dwarf_tag_name (unsigned tag
)
9344 case DW_TAG_padding
:
9345 return "DW_TAG_padding";
9346 case DW_TAG_array_type
:
9347 return "DW_TAG_array_type";
9348 case DW_TAG_class_type
:
9349 return "DW_TAG_class_type";
9350 case DW_TAG_entry_point
:
9351 return "DW_TAG_entry_point";
9352 case DW_TAG_enumeration_type
:
9353 return "DW_TAG_enumeration_type";
9354 case DW_TAG_formal_parameter
:
9355 return "DW_TAG_formal_parameter";
9356 case DW_TAG_imported_declaration
:
9357 return "DW_TAG_imported_declaration";
9359 return "DW_TAG_label";
9360 case DW_TAG_lexical_block
:
9361 return "DW_TAG_lexical_block";
9363 return "DW_TAG_member";
9364 case DW_TAG_pointer_type
:
9365 return "DW_TAG_pointer_type";
9366 case DW_TAG_reference_type
:
9367 return "DW_TAG_reference_type";
9368 case DW_TAG_compile_unit
:
9369 return "DW_TAG_compile_unit";
9370 case DW_TAG_string_type
:
9371 return "DW_TAG_string_type";
9372 case DW_TAG_structure_type
:
9373 return "DW_TAG_structure_type";
9374 case DW_TAG_subroutine_type
:
9375 return "DW_TAG_subroutine_type";
9376 case DW_TAG_typedef
:
9377 return "DW_TAG_typedef";
9378 case DW_TAG_union_type
:
9379 return "DW_TAG_union_type";
9380 case DW_TAG_unspecified_parameters
:
9381 return "DW_TAG_unspecified_parameters";
9382 case DW_TAG_variant
:
9383 return "DW_TAG_variant";
9384 case DW_TAG_common_block
:
9385 return "DW_TAG_common_block";
9386 case DW_TAG_common_inclusion
:
9387 return "DW_TAG_common_inclusion";
9388 case DW_TAG_inheritance
:
9389 return "DW_TAG_inheritance";
9390 case DW_TAG_inlined_subroutine
:
9391 return "DW_TAG_inlined_subroutine";
9393 return "DW_TAG_module";
9394 case DW_TAG_ptr_to_member_type
:
9395 return "DW_TAG_ptr_to_member_type";
9396 case DW_TAG_set_type
:
9397 return "DW_TAG_set_type";
9398 case DW_TAG_subrange_type
:
9399 return "DW_TAG_subrange_type";
9400 case DW_TAG_with_stmt
:
9401 return "DW_TAG_with_stmt";
9402 case DW_TAG_access_declaration
:
9403 return "DW_TAG_access_declaration";
9404 case DW_TAG_base_type
:
9405 return "DW_TAG_base_type";
9406 case DW_TAG_catch_block
:
9407 return "DW_TAG_catch_block";
9408 case DW_TAG_const_type
:
9409 return "DW_TAG_const_type";
9410 case DW_TAG_constant
:
9411 return "DW_TAG_constant";
9412 case DW_TAG_enumerator
:
9413 return "DW_TAG_enumerator";
9414 case DW_TAG_file_type
:
9415 return "DW_TAG_file_type";
9417 return "DW_TAG_friend";
9418 case DW_TAG_namelist
:
9419 return "DW_TAG_namelist";
9420 case DW_TAG_namelist_item
:
9421 return "DW_TAG_namelist_item";
9422 case DW_TAG_packed_type
:
9423 return "DW_TAG_packed_type";
9424 case DW_TAG_subprogram
:
9425 return "DW_TAG_subprogram";
9426 case DW_TAG_template_type_param
:
9427 return "DW_TAG_template_type_param";
9428 case DW_TAG_template_value_param
:
9429 return "DW_TAG_template_value_param";
9430 case DW_TAG_thrown_type
:
9431 return "DW_TAG_thrown_type";
9432 case DW_TAG_try_block
:
9433 return "DW_TAG_try_block";
9434 case DW_TAG_variant_part
:
9435 return "DW_TAG_variant_part";
9436 case DW_TAG_variable
:
9437 return "DW_TAG_variable";
9438 case DW_TAG_volatile_type
:
9439 return "DW_TAG_volatile_type";
9440 case DW_TAG_dwarf_procedure
:
9441 return "DW_TAG_dwarf_procedure";
9442 case DW_TAG_restrict_type
:
9443 return "DW_TAG_restrict_type";
9444 case DW_TAG_interface_type
:
9445 return "DW_TAG_interface_type";
9446 case DW_TAG_namespace
:
9447 return "DW_TAG_namespace";
9448 case DW_TAG_imported_module
:
9449 return "DW_TAG_imported_module";
9450 case DW_TAG_unspecified_type
:
9451 return "DW_TAG_unspecified_type";
9452 case DW_TAG_partial_unit
:
9453 return "DW_TAG_partial_unit";
9454 case DW_TAG_imported_unit
:
9455 return "DW_TAG_imported_unit";
9456 case DW_TAG_condition
:
9457 return "DW_TAG_condition";
9458 case DW_TAG_shared_type
:
9459 return "DW_TAG_shared_type";
9460 case DW_TAG_type_unit
:
9461 return "DW_TAG_type_unit";
9462 case DW_TAG_MIPS_loop
:
9463 return "DW_TAG_MIPS_loop";
9464 case DW_TAG_HP_array_descriptor
:
9465 return "DW_TAG_HP_array_descriptor";
9466 case DW_TAG_format_label
:
9467 return "DW_TAG_format_label";
9468 case DW_TAG_function_template
:
9469 return "DW_TAG_function_template";
9470 case DW_TAG_class_template
:
9471 return "DW_TAG_class_template";
9472 case DW_TAG_GNU_BINCL
:
9473 return "DW_TAG_GNU_BINCL";
9474 case DW_TAG_GNU_EINCL
:
9475 return "DW_TAG_GNU_EINCL";
9476 case DW_TAG_upc_shared_type
:
9477 return "DW_TAG_upc_shared_type";
9478 case DW_TAG_upc_strict_type
:
9479 return "DW_TAG_upc_strict_type";
9480 case DW_TAG_upc_relaxed_type
:
9481 return "DW_TAG_upc_relaxed_type";
9482 case DW_TAG_PGI_kanji_type
:
9483 return "DW_TAG_PGI_kanji_type";
9484 case DW_TAG_PGI_interface_block
:
9485 return "DW_TAG_PGI_interface_block";
9487 return "DW_TAG_<unknown>";
9491 /* Convert a DWARF attribute code into its string name. */
9494 dwarf_attr_name (unsigned attr
)
9499 return "DW_AT_sibling";
9500 case DW_AT_location
:
9501 return "DW_AT_location";
9503 return "DW_AT_name";
9504 case DW_AT_ordering
:
9505 return "DW_AT_ordering";
9506 case DW_AT_subscr_data
:
9507 return "DW_AT_subscr_data";
9508 case DW_AT_byte_size
:
9509 return "DW_AT_byte_size";
9510 case DW_AT_bit_offset
:
9511 return "DW_AT_bit_offset";
9512 case DW_AT_bit_size
:
9513 return "DW_AT_bit_size";
9514 case DW_AT_element_list
:
9515 return "DW_AT_element_list";
9516 case DW_AT_stmt_list
:
9517 return "DW_AT_stmt_list";
9519 return "DW_AT_low_pc";
9521 return "DW_AT_high_pc";
9522 case DW_AT_language
:
9523 return "DW_AT_language";
9525 return "DW_AT_member";
9527 return "DW_AT_discr";
9528 case DW_AT_discr_value
:
9529 return "DW_AT_discr_value";
9530 case DW_AT_visibility
:
9531 return "DW_AT_visibility";
9533 return "DW_AT_import";
9534 case DW_AT_string_length
:
9535 return "DW_AT_string_length";
9536 case DW_AT_common_reference
:
9537 return "DW_AT_common_reference";
9538 case DW_AT_comp_dir
:
9539 return "DW_AT_comp_dir";
9540 case DW_AT_const_value
:
9541 return "DW_AT_const_value";
9542 case DW_AT_containing_type
:
9543 return "DW_AT_containing_type";
9544 case DW_AT_default_value
:
9545 return "DW_AT_default_value";
9547 return "DW_AT_inline";
9548 case DW_AT_is_optional
:
9549 return "DW_AT_is_optional";
9550 case DW_AT_lower_bound
:
9551 return "DW_AT_lower_bound";
9552 case DW_AT_producer
:
9553 return "DW_AT_producer";
9554 case DW_AT_prototyped
:
9555 return "DW_AT_prototyped";
9556 case DW_AT_return_addr
:
9557 return "DW_AT_return_addr";
9558 case DW_AT_start_scope
:
9559 return "DW_AT_start_scope";
9560 case DW_AT_bit_stride
:
9561 return "DW_AT_bit_stride";
9562 case DW_AT_upper_bound
:
9563 return "DW_AT_upper_bound";
9564 case DW_AT_abstract_origin
:
9565 return "DW_AT_abstract_origin";
9566 case DW_AT_accessibility
:
9567 return "DW_AT_accessibility";
9568 case DW_AT_address_class
:
9569 return "DW_AT_address_class";
9570 case DW_AT_artificial
:
9571 return "DW_AT_artificial";
9572 case DW_AT_base_types
:
9573 return "DW_AT_base_types";
9574 case DW_AT_calling_convention
:
9575 return "DW_AT_calling_convention";
9577 return "DW_AT_count";
9578 case DW_AT_data_member_location
:
9579 return "DW_AT_data_member_location";
9580 case DW_AT_decl_column
:
9581 return "DW_AT_decl_column";
9582 case DW_AT_decl_file
:
9583 return "DW_AT_decl_file";
9584 case DW_AT_decl_line
:
9585 return "DW_AT_decl_line";
9586 case DW_AT_declaration
:
9587 return "DW_AT_declaration";
9588 case DW_AT_discr_list
:
9589 return "DW_AT_discr_list";
9590 case DW_AT_encoding
:
9591 return "DW_AT_encoding";
9592 case DW_AT_external
:
9593 return "DW_AT_external";
9594 case DW_AT_frame_base
:
9595 return "DW_AT_frame_base";
9597 return "DW_AT_friend";
9598 case DW_AT_identifier_case
:
9599 return "DW_AT_identifier_case";
9600 case DW_AT_macro_info
:
9601 return "DW_AT_macro_info";
9602 case DW_AT_namelist_items
:
9603 return "DW_AT_namelist_items";
9604 case DW_AT_priority
:
9605 return "DW_AT_priority";
9607 return "DW_AT_segment";
9608 case DW_AT_specification
:
9609 return "DW_AT_specification";
9610 case DW_AT_static_link
:
9611 return "DW_AT_static_link";
9613 return "DW_AT_type";
9614 case DW_AT_use_location
:
9615 return "DW_AT_use_location";
9616 case DW_AT_variable_parameter
:
9617 return "DW_AT_variable_parameter";
9618 case DW_AT_virtuality
:
9619 return "DW_AT_virtuality";
9620 case DW_AT_vtable_elem_location
:
9621 return "DW_AT_vtable_elem_location";
9622 /* DWARF 3 values. */
9623 case DW_AT_allocated
:
9624 return "DW_AT_allocated";
9625 case DW_AT_associated
:
9626 return "DW_AT_associated";
9627 case DW_AT_data_location
:
9628 return "DW_AT_data_location";
9629 case DW_AT_byte_stride
:
9630 return "DW_AT_byte_stride";
9631 case DW_AT_entry_pc
:
9632 return "DW_AT_entry_pc";
9633 case DW_AT_use_UTF8
:
9634 return "DW_AT_use_UTF8";
9635 case DW_AT_extension
:
9636 return "DW_AT_extension";
9638 return "DW_AT_ranges";
9639 case DW_AT_trampoline
:
9640 return "DW_AT_trampoline";
9641 case DW_AT_call_column
:
9642 return "DW_AT_call_column";
9643 case DW_AT_call_file
:
9644 return "DW_AT_call_file";
9645 case DW_AT_call_line
:
9646 return "DW_AT_call_line";
9647 case DW_AT_description
:
9648 return "DW_AT_description";
9649 case DW_AT_binary_scale
:
9650 return "DW_AT_binary_scale";
9651 case DW_AT_decimal_scale
:
9652 return "DW_AT_decimal_scale";
9654 return "DW_AT_small";
9655 case DW_AT_decimal_sign
:
9656 return "DW_AT_decimal_sign";
9657 case DW_AT_digit_count
:
9658 return "DW_AT_digit_count";
9659 case DW_AT_picture_string
:
9660 return "DW_AT_picture_string";
9662 return "DW_AT_mutable";
9663 case DW_AT_threads_scaled
:
9664 return "DW_AT_threads_scaled";
9665 case DW_AT_explicit
:
9666 return "DW_AT_explicit";
9667 case DW_AT_object_pointer
:
9668 return "DW_AT_object_pointer";
9669 case DW_AT_endianity
:
9670 return "DW_AT_endianity";
9671 case DW_AT_elemental
:
9672 return "DW_AT_elemental";
9674 return "DW_AT_pure";
9675 case DW_AT_recursive
:
9676 return "DW_AT_recursive";
9677 /* DWARF 4 values. */
9678 case DW_AT_signature
:
9679 return "DW_AT_signature";
9680 case DW_AT_linkage_name
:
9681 return "DW_AT_linkage_name";
9682 /* SGI/MIPS extensions. */
9683 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9684 case DW_AT_MIPS_fde
:
9685 return "DW_AT_MIPS_fde";
9687 case DW_AT_MIPS_loop_begin
:
9688 return "DW_AT_MIPS_loop_begin";
9689 case DW_AT_MIPS_tail_loop_begin
:
9690 return "DW_AT_MIPS_tail_loop_begin";
9691 case DW_AT_MIPS_epilog_begin
:
9692 return "DW_AT_MIPS_epilog_begin";
9693 case DW_AT_MIPS_loop_unroll_factor
:
9694 return "DW_AT_MIPS_loop_unroll_factor";
9695 case DW_AT_MIPS_software_pipeline_depth
:
9696 return "DW_AT_MIPS_software_pipeline_depth";
9697 case DW_AT_MIPS_linkage_name
:
9698 return "DW_AT_MIPS_linkage_name";
9699 case DW_AT_MIPS_stride
:
9700 return "DW_AT_MIPS_stride";
9701 case DW_AT_MIPS_abstract_name
:
9702 return "DW_AT_MIPS_abstract_name";
9703 case DW_AT_MIPS_clone_origin
:
9704 return "DW_AT_MIPS_clone_origin";
9705 case DW_AT_MIPS_has_inlines
:
9706 return "DW_AT_MIPS_has_inlines";
9707 /* HP extensions. */
9708 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9709 case DW_AT_HP_block_index
:
9710 return "DW_AT_HP_block_index";
9712 case DW_AT_HP_unmodifiable
:
9713 return "DW_AT_HP_unmodifiable";
9714 case DW_AT_HP_actuals_stmt_list
:
9715 return "DW_AT_HP_actuals_stmt_list";
9716 case DW_AT_HP_proc_per_section
:
9717 return "DW_AT_HP_proc_per_section";
9718 case DW_AT_HP_raw_data_ptr
:
9719 return "DW_AT_HP_raw_data_ptr";
9720 case DW_AT_HP_pass_by_reference
:
9721 return "DW_AT_HP_pass_by_reference";
9722 case DW_AT_HP_opt_level
:
9723 return "DW_AT_HP_opt_level";
9724 case DW_AT_HP_prof_version_id
:
9725 return "DW_AT_HP_prof_version_id";
9726 case DW_AT_HP_opt_flags
:
9727 return "DW_AT_HP_opt_flags";
9728 case DW_AT_HP_cold_region_low_pc
:
9729 return "DW_AT_HP_cold_region_low_pc";
9730 case DW_AT_HP_cold_region_high_pc
:
9731 return "DW_AT_HP_cold_region_high_pc";
9732 case DW_AT_HP_all_variables_modifiable
:
9733 return "DW_AT_HP_all_variables_modifiable";
9734 case DW_AT_HP_linkage_name
:
9735 return "DW_AT_HP_linkage_name";
9736 case DW_AT_HP_prof_flags
:
9737 return "DW_AT_HP_prof_flags";
9738 /* GNU extensions. */
9739 case DW_AT_sf_names
:
9740 return "DW_AT_sf_names";
9741 case DW_AT_src_info
:
9742 return "DW_AT_src_info";
9743 case DW_AT_mac_info
:
9744 return "DW_AT_mac_info";
9745 case DW_AT_src_coords
:
9746 return "DW_AT_src_coords";
9747 case DW_AT_body_begin
:
9748 return "DW_AT_body_begin";
9749 case DW_AT_body_end
:
9750 return "DW_AT_body_end";
9751 case DW_AT_GNU_vector
:
9752 return "DW_AT_GNU_vector";
9753 /* VMS extensions. */
9754 case DW_AT_VMS_rtnbeg_pd_address
:
9755 return "DW_AT_VMS_rtnbeg_pd_address";
9756 /* UPC extension. */
9757 case DW_AT_upc_threads_scaled
:
9758 return "DW_AT_upc_threads_scaled";
9759 /* PGI (STMicroelectronics) extensions. */
9760 case DW_AT_PGI_lbase
:
9761 return "DW_AT_PGI_lbase";
9762 case DW_AT_PGI_soffset
:
9763 return "DW_AT_PGI_soffset";
9764 case DW_AT_PGI_lstride
:
9765 return "DW_AT_PGI_lstride";
9767 return "DW_AT_<unknown>";
9771 /* Convert a DWARF value form code into its string name. */
9774 dwarf_form_name (unsigned form
)
9779 return "DW_FORM_addr";
9780 case DW_FORM_block2
:
9781 return "DW_FORM_block2";
9782 case DW_FORM_block4
:
9783 return "DW_FORM_block4";
9785 return "DW_FORM_data2";
9787 return "DW_FORM_data4";
9789 return "DW_FORM_data8";
9790 case DW_FORM_string
:
9791 return "DW_FORM_string";
9793 return "DW_FORM_block";
9794 case DW_FORM_block1
:
9795 return "DW_FORM_block1";
9797 return "DW_FORM_data1";
9799 return "DW_FORM_flag";
9801 return "DW_FORM_sdata";
9803 return "DW_FORM_strp";
9805 return "DW_FORM_udata";
9806 case DW_FORM_ref_addr
:
9807 return "DW_FORM_ref_addr";
9809 return "DW_FORM_ref1";
9811 return "DW_FORM_ref2";
9813 return "DW_FORM_ref4";
9815 return "DW_FORM_ref8";
9816 case DW_FORM_ref_udata
:
9817 return "DW_FORM_ref_udata";
9818 case DW_FORM_indirect
:
9819 return "DW_FORM_indirect";
9820 case DW_FORM_sec_offset
:
9821 return "DW_FORM_sec_offset";
9822 case DW_FORM_exprloc
:
9823 return "DW_FORM_exprloc";
9824 case DW_FORM_flag_present
:
9825 return "DW_FORM_flag_present";
9827 return "DW_FORM_sig8";
9829 return "DW_FORM_<unknown>";
9833 /* Convert a DWARF stack opcode into its string name. */
9836 dwarf_stack_op_name (unsigned op
)
9841 return "DW_OP_addr";
9843 return "DW_OP_deref";
9845 return "DW_OP_const1u";
9847 return "DW_OP_const1s";
9849 return "DW_OP_const2u";
9851 return "DW_OP_const2s";
9853 return "DW_OP_const4u";
9855 return "DW_OP_const4s";
9857 return "DW_OP_const8u";
9859 return "DW_OP_const8s";
9861 return "DW_OP_constu";
9863 return "DW_OP_consts";
9867 return "DW_OP_drop";
9869 return "DW_OP_over";
9871 return "DW_OP_pick";
9873 return "DW_OP_swap";
9877 return "DW_OP_xderef";
9885 return "DW_OP_minus";
9897 return "DW_OP_plus";
9898 case DW_OP_plus_uconst
:
9899 return "DW_OP_plus_uconst";
9905 return "DW_OP_shra";
9923 return "DW_OP_skip";
9925 return "DW_OP_lit0";
9927 return "DW_OP_lit1";
9929 return "DW_OP_lit2";
9931 return "DW_OP_lit3";
9933 return "DW_OP_lit4";
9935 return "DW_OP_lit5";
9937 return "DW_OP_lit6";
9939 return "DW_OP_lit7";
9941 return "DW_OP_lit8";
9943 return "DW_OP_lit9";
9945 return "DW_OP_lit10";
9947 return "DW_OP_lit11";
9949 return "DW_OP_lit12";
9951 return "DW_OP_lit13";
9953 return "DW_OP_lit14";
9955 return "DW_OP_lit15";
9957 return "DW_OP_lit16";
9959 return "DW_OP_lit17";
9961 return "DW_OP_lit18";
9963 return "DW_OP_lit19";
9965 return "DW_OP_lit20";
9967 return "DW_OP_lit21";
9969 return "DW_OP_lit22";
9971 return "DW_OP_lit23";
9973 return "DW_OP_lit24";
9975 return "DW_OP_lit25";
9977 return "DW_OP_lit26";
9979 return "DW_OP_lit27";
9981 return "DW_OP_lit28";
9983 return "DW_OP_lit29";
9985 return "DW_OP_lit30";
9987 return "DW_OP_lit31";
9989 return "DW_OP_reg0";
9991 return "DW_OP_reg1";
9993 return "DW_OP_reg2";
9995 return "DW_OP_reg3";
9997 return "DW_OP_reg4";
9999 return "DW_OP_reg5";
10001 return "DW_OP_reg6";
10003 return "DW_OP_reg7";
10005 return "DW_OP_reg8";
10007 return "DW_OP_reg9";
10009 return "DW_OP_reg10";
10011 return "DW_OP_reg11";
10013 return "DW_OP_reg12";
10015 return "DW_OP_reg13";
10017 return "DW_OP_reg14";
10019 return "DW_OP_reg15";
10021 return "DW_OP_reg16";
10023 return "DW_OP_reg17";
10025 return "DW_OP_reg18";
10027 return "DW_OP_reg19";
10029 return "DW_OP_reg20";
10031 return "DW_OP_reg21";
10033 return "DW_OP_reg22";
10035 return "DW_OP_reg23";
10037 return "DW_OP_reg24";
10039 return "DW_OP_reg25";
10041 return "DW_OP_reg26";
10043 return "DW_OP_reg27";
10045 return "DW_OP_reg28";
10047 return "DW_OP_reg29";
10049 return "DW_OP_reg30";
10051 return "DW_OP_reg31";
10053 return "DW_OP_breg0";
10055 return "DW_OP_breg1";
10057 return "DW_OP_breg2";
10059 return "DW_OP_breg3";
10061 return "DW_OP_breg4";
10063 return "DW_OP_breg5";
10065 return "DW_OP_breg6";
10067 return "DW_OP_breg7";
10069 return "DW_OP_breg8";
10071 return "DW_OP_breg9";
10073 return "DW_OP_breg10";
10075 return "DW_OP_breg11";
10077 return "DW_OP_breg12";
10079 return "DW_OP_breg13";
10081 return "DW_OP_breg14";
10083 return "DW_OP_breg15";
10085 return "DW_OP_breg16";
10087 return "DW_OP_breg17";
10089 return "DW_OP_breg18";
10091 return "DW_OP_breg19";
10093 return "DW_OP_breg20";
10095 return "DW_OP_breg21";
10097 return "DW_OP_breg22";
10099 return "DW_OP_breg23";
10101 return "DW_OP_breg24";
10103 return "DW_OP_breg25";
10105 return "DW_OP_breg26";
10107 return "DW_OP_breg27";
10109 return "DW_OP_breg28";
10111 return "DW_OP_breg29";
10113 return "DW_OP_breg30";
10115 return "DW_OP_breg31";
10117 return "DW_OP_regx";
10119 return "DW_OP_fbreg";
10121 return "DW_OP_bregx";
10123 return "DW_OP_piece";
10124 case DW_OP_deref_size
:
10125 return "DW_OP_deref_size";
10126 case DW_OP_xderef_size
:
10127 return "DW_OP_xderef_size";
10129 return "DW_OP_nop";
10130 /* DWARF 3 extensions. */
10131 case DW_OP_push_object_address
:
10132 return "DW_OP_push_object_address";
10134 return "DW_OP_call2";
10136 return "DW_OP_call4";
10137 case DW_OP_call_ref
:
10138 return "DW_OP_call_ref";
10139 /* GNU extensions. */
10140 case DW_OP_form_tls_address
:
10141 return "DW_OP_form_tls_address";
10142 case DW_OP_call_frame_cfa
:
10143 return "DW_OP_call_frame_cfa";
10144 case DW_OP_bit_piece
:
10145 return "DW_OP_bit_piece";
10146 case DW_OP_GNU_push_tls_address
:
10147 return "DW_OP_GNU_push_tls_address";
10148 case DW_OP_GNU_uninit
:
10149 return "DW_OP_GNU_uninit";
10150 /* HP extensions. */
10151 case DW_OP_HP_is_value
:
10152 return "DW_OP_HP_is_value";
10153 case DW_OP_HP_fltconst4
:
10154 return "DW_OP_HP_fltconst4";
10155 case DW_OP_HP_fltconst8
:
10156 return "DW_OP_HP_fltconst8";
10157 case DW_OP_HP_mod_range
:
10158 return "DW_OP_HP_mod_range";
10159 case DW_OP_HP_unmod_range
:
10160 return "DW_OP_HP_unmod_range";
10162 return "DW_OP_HP_tls";
10164 return "OP_<unknown>";
10169 dwarf_bool_name (unsigned mybool
)
10177 /* Convert a DWARF type code into its string name. */
10180 dwarf_type_encoding_name (unsigned enc
)
10185 return "DW_ATE_void";
10186 case DW_ATE_address
:
10187 return "DW_ATE_address";
10188 case DW_ATE_boolean
:
10189 return "DW_ATE_boolean";
10190 case DW_ATE_complex_float
:
10191 return "DW_ATE_complex_float";
10193 return "DW_ATE_float";
10194 case DW_ATE_signed
:
10195 return "DW_ATE_signed";
10196 case DW_ATE_signed_char
:
10197 return "DW_ATE_signed_char";
10198 case DW_ATE_unsigned
:
10199 return "DW_ATE_unsigned";
10200 case DW_ATE_unsigned_char
:
10201 return "DW_ATE_unsigned_char";
10203 case DW_ATE_imaginary_float
:
10204 return "DW_ATE_imaginary_float";
10205 case DW_ATE_packed_decimal
:
10206 return "DW_ATE_packed_decimal";
10207 case DW_ATE_numeric_string
:
10208 return "DW_ATE_numeric_string";
10209 case DW_ATE_edited
:
10210 return "DW_ATE_edited";
10211 case DW_ATE_signed_fixed
:
10212 return "DW_ATE_signed_fixed";
10213 case DW_ATE_unsigned_fixed
:
10214 return "DW_ATE_unsigned_fixed";
10215 case DW_ATE_decimal_float
:
10216 return "DW_ATE_decimal_float";
10217 /* HP extensions. */
10218 case DW_ATE_HP_float80
:
10219 return "DW_ATE_HP_float80";
10220 case DW_ATE_HP_complex_float80
:
10221 return "DW_ATE_HP_complex_float80";
10222 case DW_ATE_HP_float128
:
10223 return "DW_ATE_HP_float128";
10224 case DW_ATE_HP_complex_float128
:
10225 return "DW_ATE_HP_complex_float128";
10226 case DW_ATE_HP_floathpintel
:
10227 return "DW_ATE_HP_floathpintel";
10228 case DW_ATE_HP_imaginary_float80
:
10229 return "DW_ATE_HP_imaginary_float80";
10230 case DW_ATE_HP_imaginary_float128
:
10231 return "DW_ATE_HP_imaginary_float128";
10233 return "DW_ATE_<unknown>";
10237 /* Convert a DWARF call frame info operation to its string name. */
10241 dwarf_cfi_name (unsigned cfi_opc
)
10245 case DW_CFA_advance_loc
:
10246 return "DW_CFA_advance_loc";
10247 case DW_CFA_offset
:
10248 return "DW_CFA_offset";
10249 case DW_CFA_restore
:
10250 return "DW_CFA_restore";
10252 return "DW_CFA_nop";
10253 case DW_CFA_set_loc
:
10254 return "DW_CFA_set_loc";
10255 case DW_CFA_advance_loc1
:
10256 return "DW_CFA_advance_loc1";
10257 case DW_CFA_advance_loc2
:
10258 return "DW_CFA_advance_loc2";
10259 case DW_CFA_advance_loc4
:
10260 return "DW_CFA_advance_loc4";
10261 case DW_CFA_offset_extended
:
10262 return "DW_CFA_offset_extended";
10263 case DW_CFA_restore_extended
:
10264 return "DW_CFA_restore_extended";
10265 case DW_CFA_undefined
:
10266 return "DW_CFA_undefined";
10267 case DW_CFA_same_value
:
10268 return "DW_CFA_same_value";
10269 case DW_CFA_register
:
10270 return "DW_CFA_register";
10271 case DW_CFA_remember_state
:
10272 return "DW_CFA_remember_state";
10273 case DW_CFA_restore_state
:
10274 return "DW_CFA_restore_state";
10275 case DW_CFA_def_cfa
:
10276 return "DW_CFA_def_cfa";
10277 case DW_CFA_def_cfa_register
:
10278 return "DW_CFA_def_cfa_register";
10279 case DW_CFA_def_cfa_offset
:
10280 return "DW_CFA_def_cfa_offset";
10282 case DW_CFA_def_cfa_expression
:
10283 return "DW_CFA_def_cfa_expression";
10284 case DW_CFA_expression
:
10285 return "DW_CFA_expression";
10286 case DW_CFA_offset_extended_sf
:
10287 return "DW_CFA_offset_extended_sf";
10288 case DW_CFA_def_cfa_sf
:
10289 return "DW_CFA_def_cfa_sf";
10290 case DW_CFA_def_cfa_offset_sf
:
10291 return "DW_CFA_def_cfa_offset_sf";
10292 case DW_CFA_val_offset
:
10293 return "DW_CFA_val_offset";
10294 case DW_CFA_val_offset_sf
:
10295 return "DW_CFA_val_offset_sf";
10296 case DW_CFA_val_expression
:
10297 return "DW_CFA_val_expression";
10298 /* SGI/MIPS specific. */
10299 case DW_CFA_MIPS_advance_loc8
:
10300 return "DW_CFA_MIPS_advance_loc8";
10301 /* GNU extensions. */
10302 case DW_CFA_GNU_window_save
:
10303 return "DW_CFA_GNU_window_save";
10304 case DW_CFA_GNU_args_size
:
10305 return "DW_CFA_GNU_args_size";
10306 case DW_CFA_GNU_negative_offset_extended
:
10307 return "DW_CFA_GNU_negative_offset_extended";
10309 return "DW_CFA_<unknown>";
10315 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10319 print_spaces (indent
, f
);
10320 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10321 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10323 if (die
->parent
!= NULL
)
10325 print_spaces (indent
, f
);
10326 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10327 die
->parent
->offset
);
10330 print_spaces (indent
, f
);
10331 fprintf_unfiltered (f
, " has children: %s\n",
10332 dwarf_bool_name (die
->child
!= NULL
));
10334 print_spaces (indent
, f
);
10335 fprintf_unfiltered (f
, " attributes:\n");
10337 for (i
= 0; i
< die
->num_attrs
; ++i
)
10339 print_spaces (indent
, f
);
10340 fprintf_unfiltered (f
, " %s (%s) ",
10341 dwarf_attr_name (die
->attrs
[i
].name
),
10342 dwarf_form_name (die
->attrs
[i
].form
));
10344 switch (die
->attrs
[i
].form
)
10346 case DW_FORM_ref_addr
:
10348 fprintf_unfiltered (f
, "address: ");
10349 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10351 case DW_FORM_block2
:
10352 case DW_FORM_block4
:
10353 case DW_FORM_block
:
10354 case DW_FORM_block1
:
10355 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10357 case DW_FORM_exprloc
:
10358 fprintf_unfiltered (f
, "expression: size %u",
10359 DW_BLOCK (&die
->attrs
[i
])->size
);
10364 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10365 (long) (DW_ADDR (&die
->attrs
[i
])));
10367 case DW_FORM_data1
:
10368 case DW_FORM_data2
:
10369 case DW_FORM_data4
:
10370 case DW_FORM_data8
:
10371 case DW_FORM_udata
:
10372 case DW_FORM_sdata
:
10373 fprintf_unfiltered (f
, "constant: %s",
10374 pulongest (DW_UNSND (&die
->attrs
[i
])));
10376 case DW_FORM_sec_offset
:
10377 fprintf_unfiltered (f
, "section offset: %s",
10378 pulongest (DW_UNSND (&die
->attrs
[i
])));
10381 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10382 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10383 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10385 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10387 case DW_FORM_string
:
10389 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10390 DW_STRING (&die
->attrs
[i
])
10391 ? DW_STRING (&die
->attrs
[i
]) : "",
10392 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10395 if (DW_UNSND (&die
->attrs
[i
]))
10396 fprintf_unfiltered (f
, "flag: TRUE");
10398 fprintf_unfiltered (f
, "flag: FALSE");
10400 case DW_FORM_flag_present
:
10401 fprintf_unfiltered (f
, "flag: TRUE");
10403 case DW_FORM_indirect
:
10404 /* the reader will have reduced the indirect form to
10405 the "base form" so this form should not occur */
10406 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10409 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10410 die
->attrs
[i
].form
);
10413 fprintf_unfiltered (f
, "\n");
10418 dump_die_for_error (struct die_info
*die
)
10420 dump_die_shallow (gdb_stderr
, 0, die
);
10424 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10426 int indent
= level
* 4;
10428 gdb_assert (die
!= NULL
);
10430 if (level
>= max_level
)
10433 dump_die_shallow (f
, indent
, die
);
10435 if (die
->child
!= NULL
)
10437 print_spaces (indent
, f
);
10438 fprintf_unfiltered (f
, " Children:");
10439 if (level
+ 1 < max_level
)
10441 fprintf_unfiltered (f
, "\n");
10442 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10446 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10450 if (die
->sibling
!= NULL
&& level
> 0)
10452 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10456 /* This is called from the pdie macro in gdbinit.in.
10457 It's not static so gcc will keep a copy callable from gdb. */
10460 dump_die (struct die_info
*die
, int max_level
)
10462 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10466 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10470 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10476 is_ref_attr (struct attribute
*attr
)
10478 switch (attr
->form
)
10480 case DW_FORM_ref_addr
:
10485 case DW_FORM_ref_udata
:
10492 static unsigned int
10493 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10495 if (is_ref_attr (attr
))
10496 return DW_ADDR (attr
);
10498 complaint (&symfile_complaints
,
10499 _("unsupported die ref attribute form: '%s'"),
10500 dwarf_form_name (attr
->form
));
10504 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10505 * the value held by the attribute is not constant. */
10508 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10510 if (attr
->form
== DW_FORM_sdata
)
10511 return DW_SND (attr
);
10512 else if (attr
->form
== DW_FORM_udata
10513 || attr
->form
== DW_FORM_data1
10514 || attr
->form
== DW_FORM_data2
10515 || attr
->form
== DW_FORM_data4
10516 || attr
->form
== DW_FORM_data8
)
10517 return DW_UNSND (attr
);
10520 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10521 dwarf_form_name (attr
->form
));
10522 return default_value
;
10526 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10527 unit and add it to our queue.
10528 The result is non-zero if PER_CU was queued, otherwise the result is zero
10529 meaning either PER_CU is already queued or it is already loaded. */
10532 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10533 struct dwarf2_per_cu_data
*per_cu
)
10535 /* Mark the dependence relation so that we don't flush PER_CU
10537 dwarf2_add_dependence (this_cu
, per_cu
);
10539 /* If it's already on the queue, we have nothing to do. */
10540 if (per_cu
->queued
)
10543 /* If the compilation unit is already loaded, just mark it as
10545 if (per_cu
->cu
!= NULL
)
10547 per_cu
->cu
->last_used
= 0;
10551 /* Add it to the queue. */
10552 queue_comp_unit (per_cu
, this_cu
->objfile
);
10557 /* Follow reference or signature attribute ATTR of SRC_DIE.
10558 On entry *REF_CU is the CU of SRC_DIE.
10559 On exit *REF_CU is the CU of the result. */
10561 static struct die_info
*
10562 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10563 struct dwarf2_cu
**ref_cu
)
10565 struct die_info
*die
;
10567 if (is_ref_attr (attr
))
10568 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10569 else if (attr
->form
== DW_FORM_sig8
)
10570 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10573 dump_die_for_error (src_die
);
10574 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10575 (*ref_cu
)->objfile
->name
);
10581 /* Follow reference attribute ATTR of SRC_DIE.
10582 On entry *REF_CU is the CU of SRC_DIE.
10583 On exit *REF_CU is the CU of the result. */
10585 static struct die_info
*
10586 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10587 struct dwarf2_cu
**ref_cu
)
10589 struct die_info
*die
;
10590 unsigned int offset
;
10591 struct die_info temp_die
;
10592 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10594 gdb_assert (cu
->per_cu
!= NULL
);
10596 offset
= dwarf2_get_ref_die_offset (attr
);
10598 if (cu
->per_cu
->from_debug_types
)
10600 /* .debug_types CUs cannot reference anything outside their CU.
10601 If they need to, they have to reference a signatured type via
10603 if (! offset_in_cu_p (&cu
->header
, offset
))
10607 else if (! offset_in_cu_p (&cu
->header
, offset
))
10609 struct dwarf2_per_cu_data
*per_cu
;
10611 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10613 /* If necessary, add it to the queue and load its DIEs. */
10614 if (maybe_queue_comp_unit (cu
, per_cu
))
10615 load_full_comp_unit (per_cu
, cu
->objfile
);
10617 target_cu
= per_cu
->cu
;
10622 *ref_cu
= target_cu
;
10623 temp_die
.offset
= offset
;
10624 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10630 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10631 "at 0x%x [in module %s]"),
10632 offset
, src_die
->offset
, cu
->objfile
->name
);
10635 /* Follow the signature attribute ATTR in SRC_DIE.
10636 On entry *REF_CU is the CU of SRC_DIE.
10637 On exit *REF_CU is the CU of the result. */
10639 static struct die_info
*
10640 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10641 struct dwarf2_cu
**ref_cu
)
10643 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10644 struct die_info temp_die
;
10645 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10646 struct dwarf2_cu
*sig_cu
;
10647 struct die_info
*die
;
10649 /* sig_type will be NULL if the signatured type is missing from
10651 if (sig_type
== NULL
)
10652 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10653 "at 0x%x [in module %s]"),
10654 src_die
->offset
, objfile
->name
);
10656 /* If necessary, add it to the queue and load its DIEs. */
10658 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10659 read_signatured_type (objfile
, sig_type
);
10661 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10663 sig_cu
= sig_type
->per_cu
.cu
;
10664 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10665 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10672 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10673 "at 0x%x [in module %s]"),
10674 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10677 /* Given an offset of a signatured type, return its signatured_type. */
10679 static struct signatured_type
*
10680 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10682 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10683 unsigned int length
, initial_length_size
;
10684 unsigned int sig_offset
;
10685 struct signatured_type find_entry
, *type_sig
;
10687 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10688 sig_offset
= (initial_length_size
10690 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10691 + 1 /*address_size*/);
10692 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10693 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10695 /* This is only used to lookup previously recorded types.
10696 If we didn't find it, it's our bug. */
10697 gdb_assert (type_sig
!= NULL
);
10698 gdb_assert (offset
== type_sig
->offset
);
10703 /* Read in signatured type at OFFSET and build its CU and die(s). */
10706 read_signatured_type_at_offset (struct objfile
*objfile
,
10707 unsigned int offset
)
10709 struct signatured_type
*type_sig
;
10711 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
10713 /* We have the section offset, but we need the signature to do the
10714 hash table lookup. */
10715 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10717 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10719 read_signatured_type (objfile
, type_sig
);
10721 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10724 /* Read in a signatured type and build its CU and DIEs. */
10727 read_signatured_type (struct objfile
*objfile
,
10728 struct signatured_type
*type_sig
)
10730 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10731 struct die_reader_specs reader_specs
;
10732 struct dwarf2_cu
*cu
;
10733 ULONGEST signature
;
10734 struct cleanup
*back_to
, *free_cu_cleanup
;
10735 struct attribute
*attr
;
10737 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10739 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10740 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10741 obstack_init (&cu
->comp_unit_obstack
);
10742 cu
->objfile
= objfile
;
10743 type_sig
->per_cu
.cu
= cu
;
10744 cu
->per_cu
= &type_sig
->per_cu
;
10746 /* If an error occurs while loading, release our storage. */
10747 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10749 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10750 types_ptr
, objfile
->obfd
);
10751 gdb_assert (signature
== type_sig
->signature
);
10754 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10758 &cu
->comp_unit_obstack
,
10759 hashtab_obstack_allocate
,
10760 dummy_obstack_deallocate
);
10762 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10763 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10765 init_cu_die_reader (&reader_specs
, cu
);
10767 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10770 /* We try not to read any attributes in this function, because not
10771 all objfiles needed for references have been loaded yet, and symbol
10772 table processing isn't initialized. But we have to set the CU language,
10773 or we won't be able to build types correctly. */
10774 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10776 set_cu_language (DW_UNSND (attr
), cu
);
10778 set_cu_language (language_minimal
, cu
);
10780 do_cleanups (back_to
);
10782 /* We've successfully allocated this compilation unit. Let our caller
10783 clean it up when finished with it. */
10784 discard_cleanups (free_cu_cleanup
);
10786 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10787 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10790 /* Decode simple location descriptions.
10791 Given a pointer to a dwarf block that defines a location, compute
10792 the location and return the value.
10794 NOTE drow/2003-11-18: This function is called in two situations
10795 now: for the address of static or global variables (partial symbols
10796 only) and for offsets into structures which are expected to be
10797 (more or less) constant. The partial symbol case should go away,
10798 and only the constant case should remain. That will let this
10799 function complain more accurately. A few special modes are allowed
10800 without complaint for global variables (for instance, global
10801 register values and thread-local values).
10803 A location description containing no operations indicates that the
10804 object is optimized out. The return value is 0 for that case.
10805 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10806 callers will only want a very basic result and this can become a
10809 Note that stack[0] is unused except as a default error return.
10810 Note that stack overflow is not yet handled. */
10813 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10815 struct objfile
*objfile
= cu
->objfile
;
10817 int size
= blk
->size
;
10818 gdb_byte
*data
= blk
->data
;
10819 CORE_ADDR stack
[64];
10821 unsigned int bytes_read
, unsnd
;
10865 stack
[++stacki
] = op
- DW_OP_lit0
;
10900 stack
[++stacki
] = op
- DW_OP_reg0
;
10902 dwarf2_complex_location_expr_complaint ();
10906 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10908 stack
[++stacki
] = unsnd
;
10910 dwarf2_complex_location_expr_complaint ();
10914 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
10919 case DW_OP_const1u
:
10920 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
10924 case DW_OP_const1s
:
10925 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
10929 case DW_OP_const2u
:
10930 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
10934 case DW_OP_const2s
:
10935 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
10939 case DW_OP_const4u
:
10940 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
10944 case DW_OP_const4s
:
10945 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
10950 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
10956 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
10961 stack
[stacki
+ 1] = stack
[stacki
];
10966 stack
[stacki
- 1] += stack
[stacki
];
10970 case DW_OP_plus_uconst
:
10971 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10976 stack
[stacki
- 1] -= stack
[stacki
];
10981 /* If we're not the last op, then we definitely can't encode
10982 this using GDB's address_class enum. This is valid for partial
10983 global symbols, although the variable's address will be bogus
10986 dwarf2_complex_location_expr_complaint ();
10989 case DW_OP_GNU_push_tls_address
:
10990 /* The top of the stack has the offset from the beginning
10991 of the thread control block at which the variable is located. */
10992 /* Nothing should follow this operator, so the top of stack would
10994 /* This is valid for partial global symbols, but the variable's
10995 address will be bogus in the psymtab. */
10997 dwarf2_complex_location_expr_complaint ();
11000 case DW_OP_GNU_uninit
:
11004 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
11005 dwarf_stack_op_name (op
));
11006 return (stack
[stacki
]);
11009 return (stack
[stacki
]);
11012 /* memory allocation interface */
11014 static struct dwarf_block
*
11015 dwarf_alloc_block (struct dwarf2_cu
*cu
)
11017 struct dwarf_block
*blk
;
11019 blk
= (struct dwarf_block
*)
11020 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
11024 static struct abbrev_info
*
11025 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
11027 struct abbrev_info
*abbrev
;
11029 abbrev
= (struct abbrev_info
*)
11030 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
11031 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11035 static struct die_info
*
11036 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
11038 struct die_info
*die
;
11039 size_t size
= sizeof (struct die_info
);
11042 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
11044 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
11045 memset (die
, 0, sizeof (struct die_info
));
11050 /* Macro support. */
11053 /* Return the full name of file number I in *LH's file name table.
11054 Use COMP_DIR as the name of the current directory of the
11055 compilation. The result is allocated using xmalloc; the caller is
11056 responsible for freeing it. */
11058 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
11060 /* Is the file number a valid index into the line header's file name
11061 table? Remember that file numbers start with one, not zero. */
11062 if (1 <= file
&& file
<= lh
->num_file_names
)
11064 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11066 if (IS_ABSOLUTE_PATH (fe
->name
))
11067 return xstrdup (fe
->name
);
11075 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11081 dir_len
= strlen (dir
);
11082 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
11083 strcpy (full_name
, dir
);
11084 full_name
[dir_len
] = '/';
11085 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
11089 return xstrdup (fe
->name
);
11094 /* The compiler produced a bogus file number. We can at least
11095 record the macro definitions made in the file, even if we
11096 won't be able to find the file by name. */
11097 char fake_name
[80];
11099 sprintf (fake_name
, "<bad macro file number %d>", file
);
11101 complaint (&symfile_complaints
,
11102 _("bad file number in macro information (%d)"),
11105 return xstrdup (fake_name
);
11110 static struct macro_source_file
*
11111 macro_start_file (int file
, int line
,
11112 struct macro_source_file
*current_file
,
11113 const char *comp_dir
,
11114 struct line_header
*lh
, struct objfile
*objfile
)
11116 /* The full name of this source file. */
11117 char *full_name
= file_full_name (file
, lh
, comp_dir
);
11119 /* We don't create a macro table for this compilation unit
11120 at all until we actually get a filename. */
11121 if (! pending_macros
)
11122 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
11123 objfile
->macro_cache
);
11125 if (! current_file
)
11126 /* If we have no current file, then this must be the start_file
11127 directive for the compilation unit's main source file. */
11128 current_file
= macro_set_main (pending_macros
, full_name
);
11130 current_file
= macro_include (current_file
, line
, full_name
);
11134 return current_file
;
11138 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
11139 followed by a null byte. */
11141 copy_string (const char *buf
, int len
)
11143 char *s
= xmalloc (len
+ 1);
11145 memcpy (s
, buf
, len
);
11151 static const char *
11152 consume_improper_spaces (const char *p
, const char *body
)
11156 complaint (&symfile_complaints
,
11157 _("macro definition contains spaces in formal argument list:\n`%s'"),
11169 parse_macro_definition (struct macro_source_file
*file
, int line
,
11174 /* The body string takes one of two forms. For object-like macro
11175 definitions, it should be:
11177 <macro name> " " <definition>
11179 For function-like macro definitions, it should be:
11181 <macro name> "() " <definition>
11183 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
11185 Spaces may appear only where explicitly indicated, and in the
11188 The Dwarf 2 spec says that an object-like macro's name is always
11189 followed by a space, but versions of GCC around March 2002 omit
11190 the space when the macro's definition is the empty string.
11192 The Dwarf 2 spec says that there should be no spaces between the
11193 formal arguments in a function-like macro's formal argument list,
11194 but versions of GCC around March 2002 include spaces after the
11198 /* Find the extent of the macro name. The macro name is terminated
11199 by either a space or null character (for an object-like macro) or
11200 an opening paren (for a function-like macro). */
11201 for (p
= body
; *p
; p
++)
11202 if (*p
== ' ' || *p
== '(')
11205 if (*p
== ' ' || *p
== '\0')
11207 /* It's an object-like macro. */
11208 int name_len
= p
- body
;
11209 char *name
= copy_string (body
, name_len
);
11210 const char *replacement
;
11213 replacement
= body
+ name_len
+ 1;
11216 dwarf2_macro_malformed_definition_complaint (body
);
11217 replacement
= body
+ name_len
;
11220 macro_define_object (file
, line
, name
, replacement
);
11224 else if (*p
== '(')
11226 /* It's a function-like macro. */
11227 char *name
= copy_string (body
, p
- body
);
11230 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
11234 p
= consume_improper_spaces (p
, body
);
11236 /* Parse the formal argument list. */
11237 while (*p
&& *p
!= ')')
11239 /* Find the extent of the current argument name. */
11240 const char *arg_start
= p
;
11242 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11245 if (! *p
|| p
== arg_start
)
11246 dwarf2_macro_malformed_definition_complaint (body
);
11249 /* Make sure argv has room for the new argument. */
11250 if (argc
>= argv_size
)
11253 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11256 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11259 p
= consume_improper_spaces (p
, body
);
11261 /* Consume the comma, if present. */
11266 p
= consume_improper_spaces (p
, body
);
11275 /* Perfectly formed definition, no complaints. */
11276 macro_define_function (file
, line
, name
,
11277 argc
, (const char **) argv
,
11279 else if (*p
== '\0')
11281 /* Complain, but do define it. */
11282 dwarf2_macro_malformed_definition_complaint (body
);
11283 macro_define_function (file
, line
, name
,
11284 argc
, (const char **) argv
,
11288 /* Just complain. */
11289 dwarf2_macro_malformed_definition_complaint (body
);
11292 /* Just complain. */
11293 dwarf2_macro_malformed_definition_complaint (body
);
11299 for (i
= 0; i
< argc
; i
++)
11305 dwarf2_macro_malformed_definition_complaint (body
);
11310 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11311 char *comp_dir
, bfd
*abfd
,
11312 struct dwarf2_cu
*cu
)
11314 gdb_byte
*mac_ptr
, *mac_end
;
11315 struct macro_source_file
*current_file
= 0;
11316 enum dwarf_macinfo_record_type macinfo_type
;
11317 int at_commandline
;
11319 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11320 &dwarf2_per_objfile
->macinfo
);
11321 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11323 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11327 /* First pass: Find the name of the base filename.
11328 This filename is needed in order to process all macros whose definition
11329 (or undefinition) comes from the command line. These macros are defined
11330 before the first DW_MACINFO_start_file entry, and yet still need to be
11331 associated to the base file.
11333 To determine the base file name, we scan the macro definitions until we
11334 reach the first DW_MACINFO_start_file entry. We then initialize
11335 CURRENT_FILE accordingly so that any macro definition found before the
11336 first DW_MACINFO_start_file can still be associated to the base file. */
11338 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11339 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11340 + dwarf2_per_objfile
->macinfo
.size
;
11344 /* Do we at least have room for a macinfo type byte? */
11345 if (mac_ptr
>= mac_end
)
11347 /* Complaint is printed during the second pass as GDB will probably
11348 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11352 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11355 switch (macinfo_type
)
11357 /* A zero macinfo type indicates the end of the macro
11362 case DW_MACINFO_define
:
11363 case DW_MACINFO_undef
:
11364 /* Only skip the data by MAC_PTR. */
11366 unsigned int bytes_read
;
11368 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11369 mac_ptr
+= bytes_read
;
11370 read_string (abfd
, mac_ptr
, &bytes_read
);
11371 mac_ptr
+= bytes_read
;
11375 case DW_MACINFO_start_file
:
11377 unsigned int bytes_read
;
11380 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11381 mac_ptr
+= bytes_read
;
11382 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11383 mac_ptr
+= bytes_read
;
11385 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11390 case DW_MACINFO_end_file
:
11391 /* No data to skip by MAC_PTR. */
11394 case DW_MACINFO_vendor_ext
:
11395 /* Only skip the data by MAC_PTR. */
11397 unsigned int bytes_read
;
11399 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11400 mac_ptr
+= bytes_read
;
11401 read_string (abfd
, mac_ptr
, &bytes_read
);
11402 mac_ptr
+= bytes_read
;
11409 } while (macinfo_type
!= 0 && current_file
== NULL
);
11411 /* Second pass: Process all entries.
11413 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11414 command-line macro definitions/undefinitions. This flag is unset when we
11415 reach the first DW_MACINFO_start_file entry. */
11417 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11419 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11420 GDB is still reading the definitions from command line. First
11421 DW_MACINFO_start_file will need to be ignored as it was already executed
11422 to create CURRENT_FILE for the main source holding also the command line
11423 definitions. On first met DW_MACINFO_start_file this flag is reset to
11424 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11426 at_commandline
= 1;
11430 /* Do we at least have room for a macinfo type byte? */
11431 if (mac_ptr
>= mac_end
)
11433 dwarf2_macros_too_long_complaint ();
11437 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11440 switch (macinfo_type
)
11442 /* A zero macinfo type indicates the end of the macro
11447 case DW_MACINFO_define
:
11448 case DW_MACINFO_undef
:
11450 unsigned int bytes_read
;
11454 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11455 mac_ptr
+= bytes_read
;
11456 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11457 mac_ptr
+= bytes_read
;
11459 if (! current_file
)
11461 /* DWARF violation as no main source is present. */
11462 complaint (&symfile_complaints
,
11463 _("debug info with no main source gives macro %s "
11465 macinfo_type
== DW_MACINFO_define
?
11467 macinfo_type
== DW_MACINFO_undef
?
11468 _("undefinition") :
11469 _("something-or-other"), line
, body
);
11472 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11473 complaint (&symfile_complaints
,
11474 _("debug info gives %s macro %s with %s line %d: %s"),
11475 at_commandline
? _("command-line") : _("in-file"),
11476 macinfo_type
== DW_MACINFO_define
?
11478 macinfo_type
== DW_MACINFO_undef
?
11479 _("undefinition") :
11480 _("something-or-other"),
11481 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11483 if (macinfo_type
== DW_MACINFO_define
)
11484 parse_macro_definition (current_file
, line
, body
);
11485 else if (macinfo_type
== DW_MACINFO_undef
)
11486 macro_undef (current_file
, line
, body
);
11490 case DW_MACINFO_start_file
:
11492 unsigned int bytes_read
;
11495 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11496 mac_ptr
+= bytes_read
;
11497 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11498 mac_ptr
+= bytes_read
;
11500 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11501 complaint (&symfile_complaints
,
11502 _("debug info gives source %d included "
11503 "from %s at %s line %d"),
11504 file
, at_commandline
? _("command-line") : _("file"),
11505 line
== 0 ? _("zero") : _("non-zero"), line
);
11507 if (at_commandline
)
11509 /* This DW_MACINFO_start_file was executed in the pass one. */
11510 at_commandline
= 0;
11513 current_file
= macro_start_file (file
, line
,
11514 current_file
, comp_dir
,
11519 case DW_MACINFO_end_file
:
11520 if (! current_file
)
11521 complaint (&symfile_complaints
,
11522 _("macro debug info has an unmatched `close_file' directive"));
11525 current_file
= current_file
->included_by
;
11526 if (! current_file
)
11528 enum dwarf_macinfo_record_type next_type
;
11530 /* GCC circa March 2002 doesn't produce the zero
11531 type byte marking the end of the compilation
11532 unit. Complain if it's not there, but exit no
11535 /* Do we at least have room for a macinfo type byte? */
11536 if (mac_ptr
>= mac_end
)
11538 dwarf2_macros_too_long_complaint ();
11542 /* We don't increment mac_ptr here, so this is just
11544 next_type
= read_1_byte (abfd
, mac_ptr
);
11545 if (next_type
!= 0)
11546 complaint (&symfile_complaints
,
11547 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11554 case DW_MACINFO_vendor_ext
:
11556 unsigned int bytes_read
;
11560 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11561 mac_ptr
+= bytes_read
;
11562 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11563 mac_ptr
+= bytes_read
;
11565 /* We don't recognize any vendor extensions. */
11569 } while (macinfo_type
!= 0);
11572 /* Check if the attribute's form is a DW_FORM_block*
11573 if so return true else false. */
11575 attr_form_is_block (struct attribute
*attr
)
11577 return (attr
== NULL
? 0 :
11578 attr
->form
== DW_FORM_block1
11579 || attr
->form
== DW_FORM_block2
11580 || attr
->form
== DW_FORM_block4
11581 || attr
->form
== DW_FORM_block
11582 || attr
->form
== DW_FORM_exprloc
);
11585 /* Return non-zero if ATTR's value is a section offset --- classes
11586 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11587 You may use DW_UNSND (attr) to retrieve such offsets.
11589 Section 7.5.4, "Attribute Encodings", explains that no attribute
11590 may have a value that belongs to more than one of these classes; it
11591 would be ambiguous if we did, because we use the same forms for all
11594 attr_form_is_section_offset (struct attribute
*attr
)
11596 return (attr
->form
== DW_FORM_data4
11597 || attr
->form
== DW_FORM_data8
11598 || attr
->form
== DW_FORM_sec_offset
);
11602 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11603 zero otherwise. When this function returns true, you can apply
11604 dwarf2_get_attr_constant_value to it.
11606 However, note that for some attributes you must check
11607 attr_form_is_section_offset before using this test. DW_FORM_data4
11608 and DW_FORM_data8 are members of both the constant class, and of
11609 the classes that contain offsets into other debug sections
11610 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11611 that, if an attribute's can be either a constant or one of the
11612 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11613 taken as section offsets, not constants. */
11615 attr_form_is_constant (struct attribute
*attr
)
11617 switch (attr
->form
)
11619 case DW_FORM_sdata
:
11620 case DW_FORM_udata
:
11621 case DW_FORM_data1
:
11622 case DW_FORM_data2
:
11623 case DW_FORM_data4
:
11624 case DW_FORM_data8
:
11632 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11633 struct dwarf2_cu
*cu
)
11635 if (attr_form_is_section_offset (attr
)
11636 /* ".debug_loc" may not exist at all, or the offset may be outside
11637 the section. If so, fall through to the complaint in the
11639 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11641 struct dwarf2_loclist_baton
*baton
;
11643 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11644 sizeof (struct dwarf2_loclist_baton
));
11645 baton
->per_cu
= cu
->per_cu
;
11646 gdb_assert (baton
->per_cu
);
11648 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11649 &dwarf2_per_objfile
->loc
);
11651 /* We don't know how long the location list is, but make sure we
11652 don't run off the edge of the section. */
11653 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11654 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11655 baton
->base_address
= cu
->base_address
;
11656 if (cu
->base_known
== 0)
11657 complaint (&symfile_complaints
,
11658 _("Location list used without specifying the CU base address."));
11660 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11661 SYMBOL_LOCATION_BATON (sym
) = baton
;
11665 struct dwarf2_locexpr_baton
*baton
;
11667 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11668 sizeof (struct dwarf2_locexpr_baton
));
11669 baton
->per_cu
= cu
->per_cu
;
11670 gdb_assert (baton
->per_cu
);
11672 if (attr_form_is_block (attr
))
11674 /* Note that we're just copying the block's data pointer
11675 here, not the actual data. We're still pointing into the
11676 info_buffer for SYM's objfile; right now we never release
11677 that buffer, but when we do clean up properly this may
11679 baton
->size
= DW_BLOCK (attr
)->size
;
11680 baton
->data
= DW_BLOCK (attr
)->data
;
11684 dwarf2_invalid_attrib_class_complaint ("location description",
11685 SYMBOL_NATURAL_NAME (sym
));
11687 baton
->data
= NULL
;
11690 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11691 SYMBOL_LOCATION_BATON (sym
) = baton
;
11695 /* Return the OBJFILE associated with the compilation unit CU. */
11698 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11700 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11702 /* Return the master objfile, so that we can report and look up the
11703 correct file containing this variable. */
11704 if (objfile
->separate_debug_objfile_backlink
)
11705 objfile
= objfile
->separate_debug_objfile_backlink
;
11710 /* Return the address size given in the compilation unit header for CU. */
11713 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11716 return per_cu
->cu
->header
.addr_size
;
11719 /* If the CU is not currently read in, we re-read its header. */
11720 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11721 struct dwarf2_per_objfile
*per_objfile
11722 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11723 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11724 struct comp_unit_head cu_header
;
11726 memset (&cu_header
, 0, sizeof cu_header
);
11727 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11728 return cu_header
.addr_size
;
11732 /* Locate the .debug_info compilation unit from CU's objfile which contains
11733 the DIE at OFFSET. Raises an error on failure. */
11735 static struct dwarf2_per_cu_data
*
11736 dwarf2_find_containing_comp_unit (unsigned int offset
,
11737 struct objfile
*objfile
)
11739 struct dwarf2_per_cu_data
*this_cu
;
11743 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11746 int mid
= low
+ (high
- low
) / 2;
11748 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11753 gdb_assert (low
== high
);
11754 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11757 error (_("Dwarf Error: could not find partial DIE containing "
11758 "offset 0x%lx [in module %s]"),
11759 (long) offset
, bfd_get_filename (objfile
->obfd
));
11761 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11762 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11766 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11767 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11768 && offset
>= this_cu
->offset
+ this_cu
->length
)
11769 error (_("invalid dwarf2 offset %u"), offset
);
11770 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11775 /* Locate the compilation unit from OBJFILE which is located at exactly
11776 OFFSET. Raises an error on failure. */
11778 static struct dwarf2_per_cu_data
*
11779 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11781 struct dwarf2_per_cu_data
*this_cu
;
11783 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11784 if (this_cu
->offset
!= offset
)
11785 error (_("no compilation unit with offset %u."), offset
);
11789 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11791 static struct dwarf2_cu
*
11792 alloc_one_comp_unit (struct objfile
*objfile
)
11794 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11795 cu
->objfile
= objfile
;
11796 obstack_init (&cu
->comp_unit_obstack
);
11800 /* Release one cached compilation unit, CU. We unlink it from the tree
11801 of compilation units, but we don't remove it from the read_in_chain;
11802 the caller is responsible for that.
11803 NOTE: DATA is a void * because this function is also used as a
11804 cleanup routine. */
11807 free_one_comp_unit (void *data
)
11809 struct dwarf2_cu
*cu
= data
;
11811 if (cu
->per_cu
!= NULL
)
11812 cu
->per_cu
->cu
= NULL
;
11815 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11820 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11821 when we're finished with it. We can't free the pointer itself, but be
11822 sure to unlink it from the cache. Also release any associated storage
11823 and perform cache maintenance.
11825 Only used during partial symbol parsing. */
11828 free_stack_comp_unit (void *data
)
11830 struct dwarf2_cu
*cu
= data
;
11832 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11833 cu
->partial_dies
= NULL
;
11835 if (cu
->per_cu
!= NULL
)
11837 /* This compilation unit is on the stack in our caller, so we
11838 should not xfree it. Just unlink it. */
11839 cu
->per_cu
->cu
= NULL
;
11842 /* If we had a per-cu pointer, then we may have other compilation
11843 units loaded, so age them now. */
11844 age_cached_comp_units ();
11848 /* Free all cached compilation units. */
11851 free_cached_comp_units (void *data
)
11853 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11855 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11856 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11857 while (per_cu
!= NULL
)
11859 struct dwarf2_per_cu_data
*next_cu
;
11861 next_cu
= per_cu
->cu
->read_in_chain
;
11863 free_one_comp_unit (per_cu
->cu
);
11864 *last_chain
= next_cu
;
11870 /* Increase the age counter on each cached compilation unit, and free
11871 any that are too old. */
11874 age_cached_comp_units (void)
11876 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11878 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
11879 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11880 while (per_cu
!= NULL
)
11882 per_cu
->cu
->last_used
++;
11883 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
11884 dwarf2_mark (per_cu
->cu
);
11885 per_cu
= per_cu
->cu
->read_in_chain
;
11888 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11889 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11890 while (per_cu
!= NULL
)
11892 struct dwarf2_per_cu_data
*next_cu
;
11894 next_cu
= per_cu
->cu
->read_in_chain
;
11896 if (!per_cu
->cu
->mark
)
11898 free_one_comp_unit (per_cu
->cu
);
11899 *last_chain
= next_cu
;
11902 last_chain
= &per_cu
->cu
->read_in_chain
;
11908 /* Remove a single compilation unit from the cache. */
11911 free_one_cached_comp_unit (void *target_cu
)
11913 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11915 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11916 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11917 while (per_cu
!= NULL
)
11919 struct dwarf2_per_cu_data
*next_cu
;
11921 next_cu
= per_cu
->cu
->read_in_chain
;
11923 if (per_cu
->cu
== target_cu
)
11925 free_one_comp_unit (per_cu
->cu
);
11926 *last_chain
= next_cu
;
11930 last_chain
= &per_cu
->cu
->read_in_chain
;
11936 /* Release all extra memory associated with OBJFILE. */
11939 dwarf2_free_objfile (struct objfile
*objfile
)
11941 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
11943 if (dwarf2_per_objfile
== NULL
)
11946 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11947 free_cached_comp_units (NULL
);
11949 /* Everything else should be on the objfile obstack. */
11952 /* A pair of DIE offset and GDB type pointer. We store these
11953 in a hash table separate from the DIEs, and preserve them
11954 when the DIEs are flushed out of cache. */
11956 struct dwarf2_offset_and_type
11958 unsigned int offset
;
11962 /* Hash function for a dwarf2_offset_and_type. */
11965 offset_and_type_hash (const void *item
)
11967 const struct dwarf2_offset_and_type
*ofs
= item
;
11969 return ofs
->offset
;
11972 /* Equality function for a dwarf2_offset_and_type. */
11975 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
11977 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
11978 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
11980 return ofs_lhs
->offset
== ofs_rhs
->offset
;
11983 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11984 table if necessary. For convenience, return TYPE. */
11986 static struct type
*
11987 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11989 struct dwarf2_offset_and_type
**slot
, ofs
;
11991 /* For Ada types, make sure that the gnat-specific data is always
11992 initialized (if not already set). There are a few types where
11993 we should not be doing so, because the type-specific area is
11994 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11995 where the type-specific area is used to store the floatformat).
11996 But this is not a problem, because the gnat-specific information
11997 is actually not needed for these types. */
11998 if (need_gnat_info (cu
)
11999 && TYPE_CODE (type
) != TYPE_CODE_FUNC
12000 && TYPE_CODE (type
) != TYPE_CODE_FLT
12001 && !HAVE_GNAT_AUX_INFO (type
))
12002 INIT_GNAT_SPECIFIC (type
);
12004 if (cu
->type_hash
== NULL
)
12006 gdb_assert (cu
->per_cu
!= NULL
);
12007 cu
->per_cu
->type_hash
12008 = htab_create_alloc_ex (cu
->header
.length
/ 24,
12009 offset_and_type_hash
,
12010 offset_and_type_eq
,
12012 &cu
->objfile
->objfile_obstack
,
12013 hashtab_obstack_allocate
,
12014 dummy_obstack_deallocate
);
12015 cu
->type_hash
= cu
->per_cu
->type_hash
;
12018 ofs
.offset
= die
->offset
;
12020 slot
= (struct dwarf2_offset_and_type
**)
12021 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
12022 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
12027 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
12028 not have a saved type. */
12030 static struct type
*
12031 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12033 struct dwarf2_offset_and_type
*slot
, ofs
;
12034 htab_t type_hash
= cu
->type_hash
;
12036 if (type_hash
== NULL
)
12039 ofs
.offset
= die
->offset
;
12040 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
12047 /* Add a dependence relationship from CU to REF_PER_CU. */
12050 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
12051 struct dwarf2_per_cu_data
*ref_per_cu
)
12055 if (cu
->dependencies
== NULL
)
12057 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
12058 NULL
, &cu
->comp_unit_obstack
,
12059 hashtab_obstack_allocate
,
12060 dummy_obstack_deallocate
);
12062 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
12064 *slot
= ref_per_cu
;
12067 /* Subroutine of dwarf2_mark to pass to htab_traverse.
12068 Set the mark field in every compilation unit in the
12069 cache that we must keep because we are keeping CU. */
12072 dwarf2_mark_helper (void **slot
, void *data
)
12074 struct dwarf2_per_cu_data
*per_cu
;
12076 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
12077 if (per_cu
->cu
->mark
)
12079 per_cu
->cu
->mark
= 1;
12081 if (per_cu
->cu
->dependencies
!= NULL
)
12082 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
12087 /* Set the mark field in CU and in every other compilation unit in the
12088 cache that we must keep because we are keeping CU. */
12091 dwarf2_mark (struct dwarf2_cu
*cu
)
12096 if (cu
->dependencies
!= NULL
)
12097 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
12101 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
12105 per_cu
->cu
->mark
= 0;
12106 per_cu
= per_cu
->cu
->read_in_chain
;
12110 /* Trivial hash function for partial_die_info: the hash value of a DIE
12111 is its offset in .debug_info for this objfile. */
12114 partial_die_hash (const void *item
)
12116 const struct partial_die_info
*part_die
= item
;
12118 return part_die
->offset
;
12121 /* Trivial comparison function for partial_die_info structures: two DIEs
12122 are equal if they have the same offset. */
12125 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
12127 const struct partial_die_info
*part_die_lhs
= item_lhs
;
12128 const struct partial_die_info
*part_die_rhs
= item_rhs
;
12130 return part_die_lhs
->offset
== part_die_rhs
->offset
;
12133 static struct cmd_list_element
*set_dwarf2_cmdlist
;
12134 static struct cmd_list_element
*show_dwarf2_cmdlist
;
12137 set_dwarf2_cmd (char *args
, int from_tty
)
12139 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
12143 show_dwarf2_cmd (char *args
, int from_tty
)
12145 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
12148 /* If section described by INFO was mmapped, munmap it now. */
12151 munmap_section_buffer (struct dwarf2_section_info
*info
)
12153 if (info
->was_mmapped
)
12156 intptr_t begin
= (intptr_t) info
->buffer
;
12157 intptr_t map_begin
= begin
& ~(pagesize
- 1);
12158 size_t map_length
= info
->size
+ begin
- map_begin
;
12160 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
12162 /* Without HAVE_MMAP, we should never be here to begin with. */
12168 /* munmap debug sections for OBJFILE, if necessary. */
12171 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
12173 struct dwarf2_per_objfile
*data
= d
;
12175 munmap_section_buffer (&data
->info
);
12176 munmap_section_buffer (&data
->abbrev
);
12177 munmap_section_buffer (&data
->line
);
12178 munmap_section_buffer (&data
->str
);
12179 munmap_section_buffer (&data
->macinfo
);
12180 munmap_section_buffer (&data
->ranges
);
12181 munmap_section_buffer (&data
->loc
);
12182 munmap_section_buffer (&data
->frame
);
12183 munmap_section_buffer (&data
->eh_frame
);
12186 void _initialize_dwarf2_read (void);
12189 _initialize_dwarf2_read (void)
12191 dwarf2_objfile_data_key
12192 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
12194 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
12195 Set DWARF 2 specific variables.\n\
12196 Configure DWARF 2 variables such as the cache size"),
12197 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
12198 0/*allow-unknown*/, &maintenance_set_cmdlist
);
12200 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
12201 Show DWARF 2 specific variables\n\
12202 Show DWARF 2 variables such as the cache size"),
12203 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
12204 0/*allow-unknown*/, &maintenance_show_cmdlist
);
12206 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
12207 &dwarf2_max_cache_age
, _("\
12208 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
12209 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12210 A higher limit means that cached compilation units will be stored\n\
12211 in memory longer, and more total memory will be used. Zero disables\n\
12212 caching, which can slow down startup."),
12214 show_dwarf2_max_cache_age
,
12215 &set_dwarf2_cmdlist
,
12216 &show_dwarf2_cmdlist
);
12218 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
12219 Set debugging of the dwarf2 DIE reader."), _("\
12220 Show debugging of the dwarf2 DIE reader."), _("\
12221 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12222 The value is the maximum depth to print."),
12225 &setdebuglist
, &showdebuglist
);