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
));
1136 memset (data
, 0, sizeof (*data
));
1137 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1138 dwarf2_per_objfile
= data
;
1140 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1141 dwarf2_per_objfile
->objfile
= objfile
;
1143 return (dwarf2_per_objfile
->info
.asection
!= NULL
1144 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1147 /* When loading sections, we can either look for ".<name>", or for
1148 * ".z<name>", which indicates a compressed section. */
1151 section_is_p (const char *section_name
, const char *name
)
1153 return (section_name
[0] == '.'
1154 && (strcmp (section_name
+ 1, name
) == 0
1155 || (section_name
[1] == 'z'
1156 && strcmp (section_name
+ 2, name
) == 0)));
1159 /* This function is mapped across the sections and remembers the
1160 offset and size of each of the debugging sections we are interested
1164 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1166 if (section_is_p (sectp
->name
, INFO_SECTION
))
1168 dwarf2_per_objfile
->info
.asection
= sectp
;
1169 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1171 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1173 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1174 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1176 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1178 dwarf2_per_objfile
->line
.asection
= sectp
;
1179 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1181 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1183 dwarf2_per_objfile
->loc
.asection
= sectp
;
1184 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1186 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1188 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1189 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1191 else if (section_is_p (sectp
->name
, STR_SECTION
))
1193 dwarf2_per_objfile
->str
.asection
= sectp
;
1194 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1196 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1198 dwarf2_per_objfile
->frame
.asection
= sectp
;
1199 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1201 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1203 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1204 if (aflag
& SEC_HAS_CONTENTS
)
1206 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1207 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1210 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1212 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1213 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1215 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1217 dwarf2_per_objfile
->types
.asection
= sectp
;
1218 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1221 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1222 && bfd_section_vma (abfd
, sectp
) == 0)
1223 dwarf2_per_objfile
->has_section_at_zero
= 1;
1226 /* Decompress a section that was compressed using zlib. Store the
1227 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1230 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1231 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1233 bfd
*abfd
= objfile
->obfd
;
1235 error (_("Support for zlib-compressed DWARF data (from '%s') "
1236 "is disabled in this copy of GDB"),
1237 bfd_get_filename (abfd
));
1239 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1240 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1241 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1242 bfd_size_type uncompressed_size
;
1243 gdb_byte
*uncompressed_buffer
;
1246 int header_size
= 12;
1248 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1249 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1250 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1251 bfd_get_filename (abfd
));
1253 /* Read the zlib header. In this case, it should be "ZLIB" followed
1254 by the uncompressed section size, 8 bytes in big-endian order. */
1255 if (compressed_size
< header_size
1256 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1257 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1258 bfd_get_filename (abfd
));
1259 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1260 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1261 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1262 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1263 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1264 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1265 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1266 uncompressed_size
+= compressed_buffer
[11];
1268 /* It is possible the section consists of several compressed
1269 buffers concatenated together, so we uncompress in a loop. */
1273 strm
.avail_in
= compressed_size
- header_size
;
1274 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1275 strm
.avail_out
= uncompressed_size
;
1276 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1278 rc
= inflateInit (&strm
);
1279 while (strm
.avail_in
> 0)
1282 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1283 bfd_get_filename (abfd
), rc
);
1284 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1285 + (uncompressed_size
- strm
.avail_out
));
1286 rc
= inflate (&strm
, Z_FINISH
);
1287 if (rc
!= Z_STREAM_END
)
1288 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1289 bfd_get_filename (abfd
), rc
);
1290 rc
= inflateReset (&strm
);
1292 rc
= inflateEnd (&strm
);
1294 || strm
.avail_out
!= 0)
1295 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1296 bfd_get_filename (abfd
), rc
);
1298 do_cleanups (cleanup
);
1299 *outbuf
= uncompressed_buffer
;
1300 *outsize
= uncompressed_size
;
1304 /* Read the contents of the section SECTP from object file specified by
1305 OBJFILE, store info about the section into INFO.
1306 If the section is compressed, uncompress it before returning. */
1309 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1311 bfd
*abfd
= objfile
->obfd
;
1312 asection
*sectp
= info
->asection
;
1313 gdb_byte
*buf
, *retbuf
;
1314 unsigned char header
[4];
1318 info
->buffer
= NULL
;
1319 info
->was_mmapped
= 0;
1322 if (info
->asection
== NULL
|| info
->size
== 0)
1325 /* Check if the file has a 4-byte header indicating compression. */
1326 if (info
->size
> sizeof (header
)
1327 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1328 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1330 /* Upon decompression, update the buffer and its size. */
1331 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1333 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1341 pagesize
= getpagesize ();
1343 /* Only try to mmap sections which are large enough: we don't want to
1344 waste space due to fragmentation. Also, only try mmap for sections
1345 without relocations. */
1347 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1349 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1350 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1351 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1352 MAP_PRIVATE
, pg_offset
);
1354 if (retbuf
!= MAP_FAILED
)
1356 info
->was_mmapped
= 1;
1357 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1358 #if HAVE_POSIX_MADVISE
1359 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1366 /* If we get here, we are a normal, not-compressed section. */
1368 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1370 /* When debugging .o files, we may need to apply relocations; see
1371 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1372 We never compress sections in .o files, so we only need to
1373 try this when the section is not compressed. */
1374 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1377 info
->buffer
= retbuf
;
1381 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1382 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1383 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1384 bfd_get_filename (abfd
));
1387 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1391 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1392 asection
**sectp
, gdb_byte
**bufp
,
1393 bfd_size_type
*sizep
)
1395 struct dwarf2_per_objfile
*data
1396 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1397 struct dwarf2_section_info
*info
;
1399 /* We may see an objfile without any DWARF, in which case we just
1408 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1409 info
= &data
->eh_frame
;
1410 else if (section_is_p (section_name
, FRAME_SECTION
))
1411 info
= &data
->frame
;
1415 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1416 /* We haven't read this section in yet. Do it now. */
1417 dwarf2_read_section (objfile
, info
);
1419 *sectp
= info
->asection
;
1420 *bufp
= info
->buffer
;
1421 *sizep
= info
->size
;
1424 /* Build a partial symbol table. */
1427 dwarf2_build_psymtabs (struct objfile
*objfile
)
1429 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
1431 init_psymbol_list (objfile
, 1024);
1434 dwarf2_build_psymtabs_hard (objfile
);
1437 /* Return TRUE if OFFSET is within CU_HEADER. */
1440 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1442 unsigned int bottom
= cu_header
->offset
;
1443 unsigned int top
= (cu_header
->offset
1445 + cu_header
->initial_length_size
);
1446 return (offset
>= bottom
&& offset
< top
);
1449 /* Read in the comp unit header information from the debug_info at info_ptr.
1450 NOTE: This leaves members offset, first_die_offset to be filled in
1454 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1455 gdb_byte
*info_ptr
, bfd
*abfd
)
1458 unsigned int bytes_read
;
1460 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1461 cu_header
->initial_length_size
= bytes_read
;
1462 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1463 info_ptr
+= bytes_read
;
1464 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1466 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1468 info_ptr
+= bytes_read
;
1469 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1471 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1472 if (signed_addr
< 0)
1473 internal_error (__FILE__
, __LINE__
,
1474 _("read_comp_unit_head: dwarf from non elf file"));
1475 cu_header
->signed_addr_p
= signed_addr
;
1481 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1482 gdb_byte
*buffer
, unsigned int buffer_size
,
1485 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1487 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1489 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
1490 error (_("Dwarf Error: wrong version in compilation unit header "
1491 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
1492 bfd_get_filename (abfd
));
1494 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1495 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1496 "(offset 0x%lx + 6) [in module %s]"),
1497 (long) header
->abbrev_offset
,
1498 (long) (beg_of_comp_unit
- buffer
),
1499 bfd_get_filename (abfd
));
1501 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1502 > buffer
+ buffer_size
)
1503 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1504 "(offset 0x%lx + 0) [in module %s]"),
1505 (long) header
->length
,
1506 (long) (beg_of_comp_unit
- buffer
),
1507 bfd_get_filename (abfd
));
1512 /* Read in the types comp unit header information from .debug_types entry at
1513 types_ptr. The result is a pointer to one past the end of the header. */
1516 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
1517 ULONGEST
*signature
,
1518 gdb_byte
*types_ptr
, bfd
*abfd
)
1520 gdb_byte
*initial_types_ptr
= types_ptr
;
1522 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
1523 &dwarf2_per_objfile
->types
);
1524 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
1526 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
1528 *signature
= read_8_bytes (abfd
, types_ptr
);
1530 types_ptr
+= cu_header
->offset_size
;
1531 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
1536 /* Allocate a new partial symtab for file named NAME and mark this new
1537 partial symtab as being an include of PST. */
1540 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1541 struct objfile
*objfile
)
1543 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1545 subpst
->section_offsets
= pst
->section_offsets
;
1546 subpst
->textlow
= 0;
1547 subpst
->texthigh
= 0;
1549 subpst
->dependencies
= (struct partial_symtab
**)
1550 obstack_alloc (&objfile
->objfile_obstack
,
1551 sizeof (struct partial_symtab
*));
1552 subpst
->dependencies
[0] = pst
;
1553 subpst
->number_of_dependencies
= 1;
1555 subpst
->globals_offset
= 0;
1556 subpst
->n_global_syms
= 0;
1557 subpst
->statics_offset
= 0;
1558 subpst
->n_static_syms
= 0;
1559 subpst
->symtab
= NULL
;
1560 subpst
->read_symtab
= pst
->read_symtab
;
1563 /* No private part is necessary for include psymtabs. This property
1564 can be used to differentiate between such include psymtabs and
1565 the regular ones. */
1566 subpst
->read_symtab_private
= NULL
;
1569 /* Read the Line Number Program data and extract the list of files
1570 included by the source file represented by PST. Build an include
1571 partial symtab for each of these included files. */
1574 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1575 struct die_info
*die
,
1576 struct partial_symtab
*pst
)
1578 struct objfile
*objfile
= cu
->objfile
;
1579 bfd
*abfd
= objfile
->obfd
;
1580 struct line_header
*lh
= NULL
;
1581 struct attribute
*attr
;
1583 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
1586 unsigned int line_offset
= DW_UNSND (attr
);
1587 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
1590 return; /* No linetable, so no includes. */
1592 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1594 free_line_header (lh
);
1598 hash_type_signature (const void *item
)
1600 const struct signatured_type
*type_sig
= item
;
1601 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1602 return type_sig
->signature
;
1606 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
1608 const struct signatured_type
*lhs
= item_lhs
;
1609 const struct signatured_type
*rhs
= item_rhs
;
1610 return lhs
->signature
== rhs
->signature
;
1613 /* Create the hash table of all entries in the .debug_types section.
1614 The result is zero if there is an error (e.g. missing .debug_types section),
1615 otherwise non-zero. */
1618 create_debug_types_hash_table (struct objfile
*objfile
)
1623 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
1624 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
1626 if (info_ptr
== NULL
)
1628 dwarf2_per_objfile
->signatured_types
= NULL
;
1632 types_htab
= htab_create_alloc_ex (41,
1633 hash_type_signature
,
1636 &objfile
->objfile_obstack
,
1637 hashtab_obstack_allocate
,
1638 dummy_obstack_deallocate
);
1640 if (dwarf2_die_debug
)
1641 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
1643 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1645 unsigned int offset
;
1646 unsigned int offset_size
;
1647 unsigned int type_offset
;
1648 unsigned int length
, initial_length_size
;
1649 unsigned short version
;
1651 struct signatured_type
*type_sig
;
1653 gdb_byte
*ptr
= info_ptr
;
1655 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
1657 /* We need to read the type's signature in order to build the hash
1658 table, but we don't need to read anything else just yet. */
1660 /* Sanity check to ensure entire cu is present. */
1661 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
1662 if (ptr
+ length
+ initial_length_size
1663 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1665 complaint (&symfile_complaints
,
1666 _("debug type entry runs off end of `.debug_types' section, ignored"));
1670 offset_size
= initial_length_size
== 4 ? 4 : 8;
1671 ptr
+= initial_length_size
;
1672 version
= bfd_get_16 (objfile
->obfd
, ptr
);
1674 ptr
+= offset_size
; /* abbrev offset */
1675 ptr
+= 1; /* address size */
1676 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
1678 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
1680 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
1681 memset (type_sig
, 0, sizeof (*type_sig
));
1682 type_sig
->signature
= signature
;
1683 type_sig
->offset
= offset
;
1684 type_sig
->type_offset
= type_offset
;
1686 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
1687 gdb_assert (slot
!= NULL
);
1690 if (dwarf2_die_debug
)
1691 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
1692 offset
, phex (signature
, sizeof (signature
)));
1694 info_ptr
= info_ptr
+ initial_length_size
+ length
;
1697 dwarf2_per_objfile
->signatured_types
= types_htab
;
1702 /* Lookup a signature based type.
1703 Returns NULL if SIG is not present in the table. */
1705 static struct signatured_type
*
1706 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
1708 struct signatured_type find_entry
, *entry
;
1710 if (dwarf2_per_objfile
->signatured_types
== NULL
)
1712 complaint (&symfile_complaints
,
1713 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1717 find_entry
.signature
= sig
;
1718 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
1722 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1725 init_cu_die_reader (struct die_reader_specs
*reader
,
1726 struct dwarf2_cu
*cu
)
1728 reader
->abfd
= cu
->objfile
->obfd
;
1730 if (cu
->per_cu
->from_debug_types
)
1732 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1733 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
1737 gdb_assert (dwarf2_per_objfile
->info
.readin
);
1738 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
1742 /* Find the base address of the compilation unit for range lists and
1743 location lists. It will normally be specified by DW_AT_low_pc.
1744 In DWARF-3 draft 4, the base address could be overridden by
1745 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1746 compilation units with discontinuous ranges. */
1749 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
1751 struct attribute
*attr
;
1754 cu
->base_address
= 0;
1756 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
1759 cu
->base_address
= DW_ADDR (attr
);
1764 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
1767 cu
->base_address
= DW_ADDR (attr
);
1773 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1774 to combine the common parts.
1775 Process a compilation unit for a psymtab.
1776 BUFFER is a pointer to the beginning of the dwarf section buffer,
1777 either .debug_info or debug_types.
1778 INFO_PTR is a pointer to the start of the CU.
1779 Returns a pointer to the next CU. */
1782 process_psymtab_comp_unit (struct objfile
*objfile
,
1783 struct dwarf2_per_cu_data
*this_cu
,
1784 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1785 unsigned int buffer_size
)
1787 bfd
*abfd
= objfile
->obfd
;
1788 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1789 struct die_info
*comp_unit_die
;
1790 struct partial_symtab
*pst
;
1792 struct cleanup
*back_to_inner
;
1793 struct dwarf2_cu cu
;
1794 int has_children
, has_pc_info
;
1795 struct attribute
*attr
;
1796 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
1797 struct die_reader_specs reader_specs
;
1799 memset (&cu
, 0, sizeof (cu
));
1800 cu
.objfile
= objfile
;
1801 obstack_init (&cu
.comp_unit_obstack
);
1803 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1805 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1806 buffer
, buffer_size
,
1809 /* Complete the cu_header. */
1810 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1811 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1813 cu
.list_in_scope
= &file_symbols
;
1815 /* If this compilation unit was already read in, free the
1816 cached copy in order to read it in again. This is
1817 necessary because we skipped some symbols when we first
1818 read in the compilation unit (see load_partial_dies).
1819 This problem could be avoided, but the benefit is
1821 if (this_cu
->cu
!= NULL
)
1822 free_one_cached_comp_unit (this_cu
->cu
);
1824 /* Note that this is a pointer to our stack frame, being
1825 added to a global data structure. It will be cleaned up
1826 in free_stack_comp_unit when we finish with this
1827 compilation unit. */
1829 cu
.per_cu
= this_cu
;
1831 /* Read the abbrevs for this compilation unit into a table. */
1832 dwarf2_read_abbrevs (abfd
, &cu
);
1833 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1835 /* Read the compilation unit die. */
1836 if (this_cu
->from_debug_types
)
1837 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1838 init_cu_die_reader (&reader_specs
, &cu
);
1839 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1842 if (this_cu
->from_debug_types
)
1844 /* offset,length haven't been set yet for type units. */
1845 this_cu
->offset
= cu
.header
.offset
;
1846 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
1848 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
1850 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1851 + cu
.header
.initial_length_size
);
1852 do_cleanups (back_to_inner
);
1856 /* Set the language we're debugging. */
1857 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
1859 set_cu_language (DW_UNSND (attr
), &cu
);
1861 set_cu_language (language_minimal
, &cu
);
1863 /* Allocate a new partial symbol table structure. */
1864 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
1865 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1866 (attr
!= NULL
) ? DW_STRING (attr
) : "",
1867 /* TEXTLOW and TEXTHIGH are set below. */
1869 objfile
->global_psymbols
.next
,
1870 objfile
->static_psymbols
.next
);
1872 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
1874 pst
->dirname
= DW_STRING (attr
);
1876 pst
->read_symtab_private
= this_cu
;
1878 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1880 /* Store the function that reads in the rest of the symbol table */
1881 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1883 this_cu
->psymtab
= pst
;
1885 dwarf2_find_base_address (comp_unit_die
, &cu
);
1887 /* Possibly set the default values of LOWPC and HIGHPC from
1889 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
1890 &best_highpc
, &cu
, pst
);
1891 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
1892 /* Store the contiguous range if it is not empty; it can be empty for
1893 CUs with no code. */
1894 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1895 best_lowpc
+ baseaddr
,
1896 best_highpc
+ baseaddr
- 1, pst
);
1898 /* Check if comp unit has_children.
1899 If so, read the rest of the partial symbols from this comp unit.
1900 If not, there's no more debug_info for this comp unit. */
1903 struct partial_die_info
*first_die
;
1904 CORE_ADDR lowpc
, highpc
;
1906 lowpc
= ((CORE_ADDR
) -1);
1907 highpc
= ((CORE_ADDR
) 0);
1909 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
1911 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1912 ! has_pc_info
, &cu
);
1914 /* If we didn't find a lowpc, set it to highpc to avoid
1915 complaints from `maint check'. */
1916 if (lowpc
== ((CORE_ADDR
) -1))
1919 /* If the compilation unit didn't have an explicit address range,
1920 then use the information extracted from its child dies. */
1924 best_highpc
= highpc
;
1927 pst
->textlow
= best_lowpc
+ baseaddr
;
1928 pst
->texthigh
= best_highpc
+ baseaddr
;
1930 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1931 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1932 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1933 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1934 sort_pst_symbols (pst
);
1936 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1937 + cu
.header
.initial_length_size
);
1939 if (this_cu
->from_debug_types
)
1941 /* It's not clear we want to do anything with stmt lists here.
1942 Waiting to see what gcc ultimately does. */
1946 /* Get the list of files included in the current compilation unit,
1947 and build a psymtab for each of them. */
1948 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
1951 do_cleanups (back_to_inner
);
1956 /* Traversal function for htab_traverse_noresize.
1957 Process one .debug_types comp-unit. */
1960 process_type_comp_unit (void **slot
, void *info
)
1962 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
1963 struct objfile
*objfile
= (struct objfile
*) info
;
1964 struct dwarf2_per_cu_data
*this_cu
;
1966 this_cu
= &entry
->per_cu
;
1967 this_cu
->from_debug_types
= 1;
1969 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1970 process_psymtab_comp_unit (objfile
, this_cu
,
1971 dwarf2_per_objfile
->types
.buffer
,
1972 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
1973 dwarf2_per_objfile
->types
.size
);
1978 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
1979 Build partial symbol tables for the .debug_types comp-units. */
1982 build_type_psymtabs (struct objfile
*objfile
)
1984 if (! create_debug_types_hash_table (objfile
))
1987 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
1988 process_type_comp_unit
, objfile
);
1991 /* Build the partial symbol table by doing a quick pass through the
1992 .debug_info and .debug_abbrev sections. */
1995 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
1998 struct cleanup
*back_to
;
2000 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2001 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2003 /* Any cached compilation units will be linked by the per-objfile
2004 read_in_chain. Make sure to free them when we're done. */
2005 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2007 build_type_psymtabs (objfile
);
2009 create_all_comp_units (objfile
);
2011 objfile
->psymtabs_addrmap
=
2012 addrmap_create_mutable (&objfile
->objfile_obstack
);
2014 /* Since the objects we're extracting from .debug_info vary in
2015 length, only the individual functions to extract them (like
2016 read_comp_unit_head and load_partial_die) can really know whether
2017 the buffer is large enough to hold another complete object.
2019 At the moment, they don't actually check that. If .debug_info
2020 holds just one extra byte after the last compilation unit's dies,
2021 then read_comp_unit_head will happily read off the end of the
2022 buffer. read_partial_die is similarly casual. Those functions
2025 For this loop condition, simply checking whether there's any data
2026 left at all should be sufficient. */
2028 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
2029 + dwarf2_per_objfile
->info
.size
))
2031 struct dwarf2_per_cu_data
*this_cu
;
2033 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
2036 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
2037 dwarf2_per_objfile
->info
.buffer
,
2039 dwarf2_per_objfile
->info
.size
);
2042 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
2043 &objfile
->objfile_obstack
);
2045 do_cleanups (back_to
);
2048 /* Load the partial DIEs for a secondary CU into memory. */
2051 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
2052 struct objfile
*objfile
)
2054 bfd
*abfd
= objfile
->obfd
;
2055 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
2056 struct die_info
*comp_unit_die
;
2057 struct dwarf2_cu
*cu
;
2058 struct cleanup
*back_to
;
2059 struct attribute
*attr
;
2061 struct die_reader_specs reader_specs
;
2063 gdb_assert (! this_cu
->from_debug_types
);
2065 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2066 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
2067 beg_of_comp_unit
= info_ptr
;
2069 cu
= alloc_one_comp_unit (objfile
);
2071 /* ??? Missing cleanup for CU? */
2073 /* Link this compilation unit into the compilation unit tree. */
2075 cu
->per_cu
= this_cu
;
2076 cu
->type_hash
= this_cu
->type_hash
;
2078 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
2079 dwarf2_per_objfile
->info
.buffer
,
2080 dwarf2_per_objfile
->info
.size
,
2083 /* Complete the cu_header. */
2084 cu
->header
.offset
= this_cu
->offset
;
2085 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2087 /* Read the abbrevs for this compilation unit into a table. */
2088 dwarf2_read_abbrevs (abfd
, cu
);
2089 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2091 /* Read the compilation unit die. */
2092 init_cu_die_reader (&reader_specs
, cu
);
2093 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2096 /* Set the language we're debugging. */
2097 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
2099 set_cu_language (DW_UNSND (attr
), cu
);
2101 set_cu_language (language_minimal
, cu
);
2103 /* Check if comp unit has_children.
2104 If so, read the rest of the partial symbols from this comp unit.
2105 If not, there's no more debug_info for this comp unit. */
2107 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
2109 do_cleanups (back_to
);
2112 /* Create a list of all compilation units in OBJFILE. We do this only
2113 if an inter-comp-unit reference is found; presumably if there is one,
2114 there will be many, and one will occur early in the .debug_info section.
2115 So there's no point in building this list incrementally. */
2118 create_all_comp_units (struct objfile
*objfile
)
2122 struct dwarf2_per_cu_data
**all_comp_units
;
2125 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2126 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2130 all_comp_units
= xmalloc (n_allocated
2131 * sizeof (struct dwarf2_per_cu_data
*));
2133 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
2135 unsigned int length
, initial_length_size
;
2136 struct dwarf2_per_cu_data
*this_cu
;
2137 unsigned int offset
;
2139 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
2141 /* Read just enough information to find out where the next
2142 compilation unit is. */
2143 length
= read_initial_length (objfile
->obfd
, info_ptr
,
2144 &initial_length_size
);
2146 /* Save the compilation unit for later lookup. */
2147 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
2148 sizeof (struct dwarf2_per_cu_data
));
2149 memset (this_cu
, 0, sizeof (*this_cu
));
2150 this_cu
->offset
= offset
;
2151 this_cu
->length
= length
+ initial_length_size
;
2153 if (n_comp_units
== n_allocated
)
2156 all_comp_units
= xrealloc (all_comp_units
,
2158 * sizeof (struct dwarf2_per_cu_data
*));
2160 all_comp_units
[n_comp_units
++] = this_cu
;
2162 info_ptr
= info_ptr
+ this_cu
->length
;
2165 dwarf2_per_objfile
->all_comp_units
2166 = obstack_alloc (&objfile
->objfile_obstack
,
2167 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2168 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
2169 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2170 xfree (all_comp_units
);
2171 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
2174 /* Process all loaded DIEs for compilation unit CU, starting at
2175 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2176 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2177 DW_AT_ranges). If NEED_PC is set, then this function will set
2178 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2179 and record the covered ranges in the addrmap. */
2182 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
2183 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2185 struct partial_die_info
*pdi
;
2187 /* Now, march along the PDI's, descending into ones which have
2188 interesting children but skipping the children of the other ones,
2189 until we reach the end of the compilation unit. */
2195 fixup_partial_die (pdi
, cu
);
2197 /* Anonymous namespaces have no name but have interesting
2198 children, so we need to look at them. Ditto for anonymous
2201 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
2202 || pdi
->tag
== DW_TAG_enumeration_type
)
2206 case DW_TAG_subprogram
:
2207 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2209 case DW_TAG_variable
:
2210 case DW_TAG_typedef
:
2211 case DW_TAG_union_type
:
2212 if (!pdi
->is_declaration
)
2214 add_partial_symbol (pdi
, cu
);
2217 case DW_TAG_class_type
:
2218 case DW_TAG_interface_type
:
2219 case DW_TAG_structure_type
:
2220 if (!pdi
->is_declaration
)
2222 add_partial_symbol (pdi
, cu
);
2225 case DW_TAG_enumeration_type
:
2226 if (!pdi
->is_declaration
)
2227 add_partial_enumeration (pdi
, cu
);
2229 case DW_TAG_base_type
:
2230 case DW_TAG_subrange_type
:
2231 /* File scope base type definitions are added to the partial
2233 add_partial_symbol (pdi
, cu
);
2235 case DW_TAG_namespace
:
2236 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
2239 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
2246 /* If the die has a sibling, skip to the sibling. */
2248 pdi
= pdi
->die_sibling
;
2252 /* Functions used to compute the fully scoped name of a partial DIE.
2254 Normally, this is simple. For C++, the parent DIE's fully scoped
2255 name is concatenated with "::" and the partial DIE's name. For
2256 Java, the same thing occurs except that "." is used instead of "::".
2257 Enumerators are an exception; they use the scope of their parent
2258 enumeration type, i.e. the name of the enumeration type is not
2259 prepended to the enumerator.
2261 There are two complexities. One is DW_AT_specification; in this
2262 case "parent" means the parent of the target of the specification,
2263 instead of the direct parent of the DIE. The other is compilers
2264 which do not emit DW_TAG_namespace; in this case we try to guess
2265 the fully qualified name of structure types from their members'
2266 linkage names. This must be done using the DIE's children rather
2267 than the children of any DW_AT_specification target. We only need
2268 to do this for structures at the top level, i.e. if the target of
2269 any DW_AT_specification (if any; otherwise the DIE itself) does not
2272 /* Compute the scope prefix associated with PDI's parent, in
2273 compilation unit CU. The result will be allocated on CU's
2274 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2275 field. NULL is returned if no prefix is necessary. */
2277 partial_die_parent_scope (struct partial_die_info
*pdi
,
2278 struct dwarf2_cu
*cu
)
2280 char *grandparent_scope
;
2281 struct partial_die_info
*parent
, *real_pdi
;
2283 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2284 then this means the parent of the specification DIE. */
2287 while (real_pdi
->has_specification
)
2288 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2290 parent
= real_pdi
->die_parent
;
2294 if (parent
->scope_set
)
2295 return parent
->scope
;
2297 fixup_partial_die (parent
, cu
);
2299 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2301 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
2302 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
2303 Work around this problem here. */
2304 if (cu
->language
== language_cplus
2305 && parent
->tag
== DW_TAG_namespace
2306 && strcmp (parent
->name
, "::") == 0
2307 && grandparent_scope
== NULL
)
2309 parent
->scope
= NULL
;
2310 parent
->scope_set
= 1;
2314 if (parent
->tag
== DW_TAG_namespace
2315 || parent
->tag
== DW_TAG_structure_type
2316 || parent
->tag
== DW_TAG_class_type
2317 || parent
->tag
== DW_TAG_interface_type
2318 || parent
->tag
== DW_TAG_union_type
2319 || parent
->tag
== DW_TAG_enumeration_type
)
2321 if (grandparent_scope
== NULL
)
2322 parent
->scope
= parent
->name
;
2324 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2327 else if (parent
->tag
== DW_TAG_enumerator
)
2328 /* Enumerators should not get the name of the enumeration as a prefix. */
2329 parent
->scope
= grandparent_scope
;
2332 /* FIXME drow/2004-04-01: What should we be doing with
2333 function-local names? For partial symbols, we should probably be
2335 complaint (&symfile_complaints
,
2336 _("unhandled containing DIE tag %d for DIE at %d"),
2337 parent
->tag
, pdi
->offset
);
2338 parent
->scope
= grandparent_scope
;
2341 parent
->scope_set
= 1;
2342 return parent
->scope
;
2345 /* Return the fully scoped name associated with PDI, from compilation unit
2346 CU. The result will be allocated with malloc. */
2348 partial_die_full_name (struct partial_die_info
*pdi
,
2349 struct dwarf2_cu
*cu
)
2353 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2354 if (parent_scope
== NULL
)
2357 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2361 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2363 struct objfile
*objfile
= cu
->objfile
;
2365 char *actual_name
= NULL
;
2366 const struct partial_symbol
*psym
= NULL
;
2368 int built_actual_name
= 0;
2370 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2372 actual_name
= partial_die_full_name (pdi
, cu
);
2374 built_actual_name
= 1;
2376 if (actual_name
== NULL
)
2377 actual_name
= pdi
->name
;
2381 case DW_TAG_subprogram
:
2382 if (pdi
->is_external
|| cu
->language
== language_ada
)
2384 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2385 of the global scope. But in Ada, we want to be able to access
2386 nested procedures globally. So all Ada subprograms are stored
2387 in the global scope. */
2388 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2389 mst_text, objfile); */
2390 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2392 VAR_DOMAIN
, LOC_BLOCK
,
2393 &objfile
->global_psymbols
,
2394 0, pdi
->lowpc
+ baseaddr
,
2395 cu
->language
, objfile
);
2399 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2400 mst_file_text, objfile); */
2401 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2403 VAR_DOMAIN
, LOC_BLOCK
,
2404 &objfile
->static_psymbols
,
2405 0, pdi
->lowpc
+ baseaddr
,
2406 cu
->language
, objfile
);
2409 case DW_TAG_variable
:
2410 if (pdi
->is_external
)
2413 Don't enter into the minimal symbol tables as there is
2414 a minimal symbol table entry from the ELF symbols already.
2415 Enter into partial symbol table if it has a location
2416 descriptor or a type.
2417 If the location descriptor is missing, new_symbol will create
2418 a LOC_UNRESOLVED symbol, the address of the variable will then
2419 be determined from the minimal symbol table whenever the variable
2421 The address for the partial symbol table entry is not
2422 used by GDB, but it comes in handy for debugging partial symbol
2426 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2427 if (pdi
->locdesc
|| pdi
->has_type
)
2428 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2430 VAR_DOMAIN
, LOC_STATIC
,
2431 &objfile
->global_psymbols
,
2433 cu
->language
, objfile
);
2437 /* Static Variable. Skip symbols without location descriptors. */
2438 if (pdi
->locdesc
== NULL
)
2440 if (built_actual_name
)
2441 xfree (actual_name
);
2444 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2445 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2446 mst_file_data, objfile); */
2447 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2449 VAR_DOMAIN
, LOC_STATIC
,
2450 &objfile
->static_psymbols
,
2452 cu
->language
, objfile
);
2455 case DW_TAG_typedef
:
2456 case DW_TAG_base_type
:
2457 case DW_TAG_subrange_type
:
2458 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2460 VAR_DOMAIN
, LOC_TYPEDEF
,
2461 &objfile
->static_psymbols
,
2462 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2464 case DW_TAG_namespace
:
2465 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2467 VAR_DOMAIN
, LOC_TYPEDEF
,
2468 &objfile
->global_psymbols
,
2469 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2471 case DW_TAG_class_type
:
2472 case DW_TAG_interface_type
:
2473 case DW_TAG_structure_type
:
2474 case DW_TAG_union_type
:
2475 case DW_TAG_enumeration_type
:
2476 /* Skip external references. The DWARF standard says in the section
2477 about "Structure, Union, and Class Type Entries": "An incomplete
2478 structure, union or class type is represented by a structure,
2479 union or class entry that does not have a byte size attribute
2480 and that has a DW_AT_declaration attribute." */
2481 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2483 if (built_actual_name
)
2484 xfree (actual_name
);
2488 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2489 static vs. global. */
2490 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2492 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2493 (cu
->language
== language_cplus
2494 || cu
->language
== language_java
)
2495 ? &objfile
->global_psymbols
2496 : &objfile
->static_psymbols
,
2497 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2500 case DW_TAG_enumerator
:
2501 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2503 VAR_DOMAIN
, LOC_CONST
,
2504 (cu
->language
== language_cplus
2505 || cu
->language
== language_java
)
2506 ? &objfile
->global_psymbols
2507 : &objfile
->static_psymbols
,
2508 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2514 if (built_actual_name
)
2515 xfree (actual_name
);
2518 /* Read a partial die corresponding to a namespace; also, add a symbol
2519 corresponding to that namespace to the symbol table. NAMESPACE is
2520 the name of the enclosing namespace. */
2523 add_partial_namespace (struct partial_die_info
*pdi
,
2524 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2525 int need_pc
, struct dwarf2_cu
*cu
)
2527 /* Add a symbol for the namespace. */
2529 add_partial_symbol (pdi
, cu
);
2531 /* Now scan partial symbols in that namespace. */
2533 if (pdi
->has_children
)
2534 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2537 /* Read a partial die corresponding to a Fortran module. */
2540 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2541 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2543 /* Now scan partial symbols in that module.
2545 FIXME: Support the separate Fortran module namespaces. */
2547 if (pdi
->has_children
)
2548 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2551 /* Read a partial die corresponding to a subprogram and create a partial
2552 symbol for that subprogram. When the CU language allows it, this
2553 routine also defines a partial symbol for each nested subprogram
2554 that this subprogram contains.
2556 DIE my also be a lexical block, in which case we simply search
2557 recursively for suprograms defined inside that lexical block.
2558 Again, this is only performed when the CU language allows this
2559 type of definitions. */
2562 add_partial_subprogram (struct partial_die_info
*pdi
,
2563 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2564 int need_pc
, struct dwarf2_cu
*cu
)
2566 if (pdi
->tag
== DW_TAG_subprogram
)
2568 if (pdi
->has_pc_info
)
2570 if (pdi
->lowpc
< *lowpc
)
2571 *lowpc
= pdi
->lowpc
;
2572 if (pdi
->highpc
> *highpc
)
2573 *highpc
= pdi
->highpc
;
2577 struct objfile
*objfile
= cu
->objfile
;
2579 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2580 SECT_OFF_TEXT (objfile
));
2581 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2582 pdi
->lowpc
+ baseaddr
,
2583 pdi
->highpc
- 1 + baseaddr
,
2584 cu
->per_cu
->psymtab
);
2586 if (!pdi
->is_declaration
)
2587 /* Ignore subprogram DIEs that do not have a name, they are
2588 illegal. Do not emit a complaint at this point, we will
2589 do so when we convert this psymtab into a symtab. */
2591 add_partial_symbol (pdi
, cu
);
2595 if (! pdi
->has_children
)
2598 if (cu
->language
== language_ada
)
2600 pdi
= pdi
->die_child
;
2603 fixup_partial_die (pdi
, cu
);
2604 if (pdi
->tag
== DW_TAG_subprogram
2605 || pdi
->tag
== DW_TAG_lexical_block
)
2606 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2607 pdi
= pdi
->die_sibling
;
2612 /* See if we can figure out if the class lives in a namespace. We do
2613 this by looking for a member function; its demangled name will
2614 contain namespace info, if there is any. */
2617 guess_structure_name (struct partial_die_info
*struct_pdi
,
2618 struct dwarf2_cu
*cu
)
2620 if ((cu
->language
== language_cplus
2621 || cu
->language
== language_java
)
2622 && cu
->has_namespace_info
== 0
2623 && struct_pdi
->has_children
)
2625 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2626 what template types look like, because the demangler
2627 frequently doesn't give the same name as the debug info. We
2628 could fix this by only using the demangled name to get the
2629 prefix (but see comment in read_structure_type). */
2631 struct partial_die_info
*real_pdi
;
2633 /* If this DIE (this DIE's specification, if any) has a parent, then
2634 we should not do this. We'll prepend the parent's fully qualified
2635 name when we create the partial symbol. */
2637 real_pdi
= struct_pdi
;
2638 while (real_pdi
->has_specification
)
2639 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2641 if (real_pdi
->die_parent
!= NULL
)
2646 /* Read a partial die corresponding to an enumeration type. */
2649 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2650 struct dwarf2_cu
*cu
)
2652 struct partial_die_info
*pdi
;
2654 if (enum_pdi
->name
!= NULL
)
2655 add_partial_symbol (enum_pdi
, cu
);
2657 pdi
= enum_pdi
->die_child
;
2660 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2661 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2663 add_partial_symbol (pdi
, cu
);
2664 pdi
= pdi
->die_sibling
;
2668 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2669 Return the corresponding abbrev, or NULL if the number is zero (indicating
2670 an empty DIE). In either case *BYTES_READ will be set to the length of
2671 the initial number. */
2673 static struct abbrev_info
*
2674 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2675 struct dwarf2_cu
*cu
)
2677 bfd
*abfd
= cu
->objfile
->obfd
;
2678 unsigned int abbrev_number
;
2679 struct abbrev_info
*abbrev
;
2681 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2683 if (abbrev_number
== 0)
2686 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2689 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2690 bfd_get_filename (abfd
));
2696 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2697 Returns a pointer to the end of a series of DIEs, terminated by an empty
2698 DIE. Any children of the skipped DIEs will also be skipped. */
2701 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2703 struct abbrev_info
*abbrev
;
2704 unsigned int bytes_read
;
2708 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2710 return info_ptr
+ bytes_read
;
2712 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
2716 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2717 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2718 abbrev corresponding to that skipped uleb128 should be passed in
2719 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2723 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2724 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
2726 unsigned int bytes_read
;
2727 struct attribute attr
;
2728 bfd
*abfd
= cu
->objfile
->obfd
;
2729 unsigned int form
, i
;
2731 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2733 /* The only abbrev we care about is DW_AT_sibling. */
2734 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2736 read_attribute (&attr
, &abbrev
->attrs
[i
],
2737 abfd
, info_ptr
, cu
);
2738 if (attr
.form
== DW_FORM_ref_addr
)
2739 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2741 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
2744 /* If it isn't DW_AT_sibling, skip this attribute. */
2745 form
= abbrev
->attrs
[i
].form
;
2749 case DW_FORM_ref_addr
:
2750 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2751 and later it is offset sized. */
2752 if (cu
->header
.version
== 2)
2753 info_ptr
+= cu
->header
.addr_size
;
2755 info_ptr
+= cu
->header
.offset_size
;
2758 info_ptr
+= cu
->header
.addr_size
;
2765 case DW_FORM_flag_present
:
2780 case DW_FORM_string
:
2781 read_string (abfd
, info_ptr
, &bytes_read
);
2782 info_ptr
+= bytes_read
;
2784 case DW_FORM_sec_offset
:
2786 info_ptr
+= cu
->header
.offset_size
;
2788 case DW_FORM_exprloc
:
2790 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2791 info_ptr
+= bytes_read
;
2793 case DW_FORM_block1
:
2794 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2796 case DW_FORM_block2
:
2797 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2799 case DW_FORM_block4
:
2800 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2804 case DW_FORM_ref_udata
:
2805 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2807 case DW_FORM_indirect
:
2808 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2809 info_ptr
+= bytes_read
;
2810 /* We need to continue parsing from here, so just go back to
2812 goto skip_attribute
;
2815 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2816 dwarf_form_name (form
),
2817 bfd_get_filename (abfd
));
2821 if (abbrev
->has_children
)
2822 return skip_children (buffer
, info_ptr
, cu
);
2827 /* Locate ORIG_PDI's sibling.
2828 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2832 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
2833 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2834 bfd
*abfd
, struct dwarf2_cu
*cu
)
2836 /* Do we know the sibling already? */
2838 if (orig_pdi
->sibling
)
2839 return orig_pdi
->sibling
;
2841 /* Are there any children to deal with? */
2843 if (!orig_pdi
->has_children
)
2846 /* Skip the children the long way. */
2848 return skip_children (buffer
, info_ptr
, cu
);
2851 /* Expand this partial symbol table into a full symbol table. */
2854 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2856 /* FIXME: This is barely more than a stub. */
2861 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2867 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2868 gdb_flush (gdb_stdout
);
2871 /* Restore our global data. */
2872 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2873 dwarf2_objfile_data_key
);
2875 /* If this psymtab is constructed from a debug-only objfile, the
2876 has_section_at_zero flag will not necessarily be correct. We
2877 can get the correct value for this flag by looking at the data
2878 associated with the (presumably stripped) associated objfile. */
2879 if (pst
->objfile
->separate_debug_objfile_backlink
)
2881 struct dwarf2_per_objfile
*dpo_backlink
2882 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2883 dwarf2_objfile_data_key
);
2884 dwarf2_per_objfile
->has_section_at_zero
2885 = dpo_backlink
->has_section_at_zero
;
2888 psymtab_to_symtab_1 (pst
);
2890 /* Finish up the debug error message. */
2892 printf_filtered (_("done.\n"));
2897 /* Add PER_CU to the queue. */
2900 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2902 struct dwarf2_queue_item
*item
;
2905 item
= xmalloc (sizeof (*item
));
2906 item
->per_cu
= per_cu
;
2909 if (dwarf2_queue
== NULL
)
2910 dwarf2_queue
= item
;
2912 dwarf2_queue_tail
->next
= item
;
2914 dwarf2_queue_tail
= item
;
2917 /* Process the queue. */
2920 process_queue (struct objfile
*objfile
)
2922 struct dwarf2_queue_item
*item
, *next_item
;
2924 /* The queue starts out with one item, but following a DIE reference
2925 may load a new CU, adding it to the end of the queue. */
2926 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2928 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2929 process_full_comp_unit (item
->per_cu
);
2931 item
->per_cu
->queued
= 0;
2932 next_item
= item
->next
;
2936 dwarf2_queue_tail
= NULL
;
2939 /* Free all allocated queue entries. This function only releases anything if
2940 an error was thrown; if the queue was processed then it would have been
2941 freed as we went along. */
2944 dwarf2_release_queue (void *dummy
)
2946 struct dwarf2_queue_item
*item
, *last
;
2948 item
= dwarf2_queue
;
2951 /* Anything still marked queued is likely to be in an
2952 inconsistent state, so discard it. */
2953 if (item
->per_cu
->queued
)
2955 if (item
->per_cu
->cu
!= NULL
)
2956 free_one_cached_comp_unit (item
->per_cu
->cu
);
2957 item
->per_cu
->queued
= 0;
2965 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2968 /* Read in full symbols for PST, and anything it depends on. */
2971 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2973 struct dwarf2_per_cu_data
*per_cu
;
2974 struct cleanup
*back_to
;
2977 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2978 if (!pst
->dependencies
[i
]->readin
)
2980 /* Inform about additional files that need to be read in. */
2983 /* FIXME: i18n: Need to make this a single string. */
2984 fputs_filtered (" ", gdb_stdout
);
2986 fputs_filtered ("and ", gdb_stdout
);
2988 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2989 wrap_here (""); /* Flush output */
2990 gdb_flush (gdb_stdout
);
2992 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2995 per_cu
= pst
->read_symtab_private
;
2999 /* It's an include file, no symbols to read for it.
3000 Everything is in the parent symtab. */
3005 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
3007 queue_comp_unit (per_cu
, pst
->objfile
);
3009 if (per_cu
->from_debug_types
)
3010 read_signatured_type_at_offset (pst
->objfile
, per_cu
->offset
);
3012 load_full_comp_unit (per_cu
, pst
->objfile
);
3014 process_queue (pst
->objfile
);
3016 /* Age the cache, releasing compilation units that have not
3017 been used recently. */
3018 age_cached_comp_units ();
3020 do_cleanups (back_to
);
3023 /* Load the DIEs associated with PER_CU into memory. */
3026 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3028 bfd
*abfd
= objfile
->obfd
;
3029 struct dwarf2_cu
*cu
;
3030 unsigned int offset
;
3031 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3032 struct cleanup
*back_to
, *free_cu_cleanup
;
3033 struct attribute
*attr
;
3035 gdb_assert (! per_cu
->from_debug_types
);
3037 /* Set local variables from the partial symbol table info. */
3038 offset
= per_cu
->offset
;
3040 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3041 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
3042 beg_of_comp_unit
= info_ptr
;
3044 cu
= alloc_one_comp_unit (objfile
);
3046 /* If an error occurs while loading, release our storage. */
3047 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3049 /* Read in the comp_unit header. */
3050 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
3052 /* Complete the cu_header. */
3053 cu
->header
.offset
= offset
;
3054 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3056 /* Read the abbrevs for this compilation unit. */
3057 dwarf2_read_abbrevs (abfd
, cu
);
3058 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3060 /* Link this compilation unit into the compilation unit tree. */
3062 cu
->per_cu
= per_cu
;
3063 cu
->type_hash
= per_cu
->type_hash
;
3065 cu
->dies
= read_comp_unit (info_ptr
, cu
);
3067 /* We try not to read any attributes in this function, because not
3068 all objfiles needed for references have been loaded yet, and symbol
3069 table processing isn't initialized. But we have to set the CU language,
3070 or we won't be able to build types correctly. */
3071 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
3073 set_cu_language (DW_UNSND (attr
), cu
);
3075 set_cu_language (language_minimal
, cu
);
3077 /* Similarly, if we do not read the producer, we can not apply
3078 producer-specific interpretation. */
3079 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
3081 cu
->producer
= DW_STRING (attr
);
3083 /* Link this CU into read_in_chain. */
3084 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3085 dwarf2_per_objfile
->read_in_chain
= per_cu
;
3087 do_cleanups (back_to
);
3089 /* We've successfully allocated this compilation unit. Let our caller
3090 clean it up when finished with it. */
3091 discard_cleanups (free_cu_cleanup
);
3094 /* Generate full symbol information for PST and CU, whose DIEs have
3095 already been loaded into memory. */
3098 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
3100 struct partial_symtab
*pst
= per_cu
->psymtab
;
3101 struct dwarf2_cu
*cu
= per_cu
->cu
;
3102 struct objfile
*objfile
= pst
->objfile
;
3103 CORE_ADDR lowpc
, highpc
;
3104 struct symtab
*symtab
;
3105 struct cleanup
*back_to
;
3108 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3111 back_to
= make_cleanup (really_free_pendings
, NULL
);
3113 cu
->list_in_scope
= &file_symbols
;
3115 dwarf2_find_base_address (cu
->dies
, cu
);
3117 /* Do line number decoding in read_file_scope () */
3118 process_die (cu
->dies
, cu
);
3120 /* Some compilers don't define a DW_AT_high_pc attribute for the
3121 compilation unit. If the DW_AT_high_pc is missing, synthesize
3122 it, by scanning the DIE's below the compilation unit. */
3123 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
3125 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
3127 /* Set symtab language to language from DW_AT_language.
3128 If the compilation is from a C file generated by language preprocessors,
3129 do not set the language if it was already deduced by start_subfile. */
3131 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
3133 symtab
->language
= cu
->language
;
3135 pst
->symtab
= symtab
;
3138 do_cleanups (back_to
);
3141 /* Process a die and its children. */
3144 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
3148 case DW_TAG_padding
:
3150 case DW_TAG_compile_unit
:
3151 read_file_scope (die
, cu
);
3153 case DW_TAG_type_unit
:
3154 read_type_unit_scope (die
, cu
);
3156 case DW_TAG_subprogram
:
3157 case DW_TAG_inlined_subroutine
:
3158 read_func_scope (die
, cu
);
3160 case DW_TAG_lexical_block
:
3161 case DW_TAG_try_block
:
3162 case DW_TAG_catch_block
:
3163 read_lexical_block_scope (die
, cu
);
3165 case DW_TAG_class_type
:
3166 case DW_TAG_interface_type
:
3167 case DW_TAG_structure_type
:
3168 case DW_TAG_union_type
:
3169 process_structure_scope (die
, cu
);
3171 case DW_TAG_enumeration_type
:
3172 process_enumeration_scope (die
, cu
);
3175 /* These dies have a type, but processing them does not create
3176 a symbol or recurse to process the children. Therefore we can
3177 read them on-demand through read_type_die. */
3178 case DW_TAG_subroutine_type
:
3179 case DW_TAG_set_type
:
3180 case DW_TAG_array_type
:
3181 case DW_TAG_pointer_type
:
3182 case DW_TAG_ptr_to_member_type
:
3183 case DW_TAG_reference_type
:
3184 case DW_TAG_string_type
:
3187 case DW_TAG_base_type
:
3188 case DW_TAG_subrange_type
:
3189 case DW_TAG_typedef
:
3190 /* Add a typedef symbol for the type definition, if it has a
3192 new_symbol (die
, read_type_die (die
, cu
), cu
);
3194 case DW_TAG_common_block
:
3195 read_common_block (die
, cu
);
3197 case DW_TAG_common_inclusion
:
3199 case DW_TAG_namespace
:
3200 processing_has_namespace_info
= 1;
3201 read_namespace (die
, cu
);
3204 read_module (die
, cu
);
3206 case DW_TAG_imported_declaration
:
3207 case DW_TAG_imported_module
:
3208 processing_has_namespace_info
= 1;
3209 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
3210 || cu
->language
!= language_fortran
))
3211 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
3212 dwarf_tag_name (die
->tag
));
3213 read_import_statement (die
, cu
);
3216 new_symbol (die
, NULL
, cu
);
3221 /* A helper function for dwarf2_compute_name which determines whether DIE
3222 needs to have the name of the scope prepended to the name listed in the
3226 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3228 struct attribute
*attr
;
3232 case DW_TAG_namespace
:
3233 case DW_TAG_typedef
:
3234 case DW_TAG_class_type
:
3235 case DW_TAG_interface_type
:
3236 case DW_TAG_structure_type
:
3237 case DW_TAG_union_type
:
3238 case DW_TAG_enumeration_type
:
3239 case DW_TAG_enumerator
:
3240 case DW_TAG_subprogram
:
3244 case DW_TAG_variable
:
3245 /* We only need to prefix "globally" visible variables. These include
3246 any variable marked with DW_AT_external or any variable that
3247 lives in a namespace. [Variables in anonymous namespaces
3248 require prefixing, but they are not DW_AT_external.] */
3250 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
3252 struct dwarf2_cu
*spec_cu
= cu
;
3253 return die_needs_namespace (die_specification (die
, &spec_cu
),
3257 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
3258 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
)
3260 /* A variable in a lexical block of some kind does not need a
3261 namespace, even though in C++ such variables may be external
3262 and have a mangled name. */
3263 if (die
->parent
->tag
== DW_TAG_lexical_block
3264 || die
->parent
->tag
== DW_TAG_try_block
3265 || die
->parent
->tag
== DW_TAG_catch_block
3266 || die
->parent
->tag
== DW_TAG_subprogram
)
3275 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3276 compute the physname for the object, which include a method's
3277 formal parameters (C++/Java) and return type (Java).
3279 For Ada, return the DIE's linkage name rather than the fully qualified
3280 name. PHYSNAME is ignored..
3282 The result is allocated on the objfile_obstack and canonicalized. */
3285 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
3289 name
= dwarf2_name (die
, cu
);
3291 /* These are the only languages we know how to qualify names in. */
3293 && (cu
->language
== language_cplus
|| cu
->language
== language_java
))
3295 if (die_needs_namespace (die
, cu
))
3299 struct ui_file
*buf
;
3301 prefix
= determine_prefix (die
, cu
);
3302 buf
= mem_fileopen ();
3303 if (*prefix
!= '\0')
3305 char *prefixed_name
= typename_concat (NULL
, prefix
, name
, cu
);
3306 fputs_unfiltered (prefixed_name
, buf
);
3307 xfree (prefixed_name
);
3310 fputs_unfiltered (name
? name
: "", buf
);
3312 /* For Java and C++ methods, append formal parameter type
3313 information, if PHYSNAME. */
3315 if (physname
&& die
->tag
== DW_TAG_subprogram
3316 && (cu
->language
== language_cplus
3317 || cu
->language
== language_java
))
3319 struct type
*type
= read_type_die (die
, cu
);
3321 c_type_print_args (type
, buf
, 0, cu
->language
);
3323 if (cu
->language
== language_java
)
3325 /* For java, we must append the return type to method
3327 if (die
->tag
== DW_TAG_subprogram
)
3328 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
3331 else if (cu
->language
== language_cplus
)
3333 if (TYPE_NFIELDS (type
) > 0
3334 && TYPE_FIELD_ARTIFICIAL (type
, 0)
3335 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
3336 fputs_unfiltered (" const", buf
);
3340 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
3342 ui_file_delete (buf
);
3344 if (cu
->language
== language_cplus
)
3347 = dwarf2_canonicalize_name (name
, cu
,
3348 &cu
->objfile
->objfile_obstack
);
3354 else if (cu
->language
== language_ada
)
3356 /* For Ada unit, we prefer the linkage name over the name, as
3357 the former contains the exported name, which the user expects
3358 to be able to reference. Ideally, we want the user to be able
3359 to reference this entity using either natural or linkage name,
3360 but we haven't started looking at this enhancement yet. */
3361 struct attribute
*attr
;
3363 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
3365 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
3366 if (attr
&& DW_STRING (attr
))
3367 name
= DW_STRING (attr
);
3373 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3374 If scope qualifiers are appropriate they will be added. The result
3375 will be allocated on the objfile_obstack, or NULL if the DIE does
3376 not have a name. NAME may either be from a previous call to
3377 dwarf2_name or NULL.
3379 The output string will be canonicalized (if C++/Java). */
3382 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3384 return dwarf2_compute_name (name
, die
, cu
, 0);
3387 /* Construct a physname for the given DIE in CU. NAME may either be
3388 from a previous call to dwarf2_name or NULL. The result will be
3389 allocated on the objfile_objstack or NULL if the DIE does not have a
3392 The output string will be canonicalized (if C++/Java). */
3395 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3397 return dwarf2_compute_name (name
, die
, cu
, 1);
3400 /* Read the import statement specified by the given die and record it. */
3403 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3405 struct attribute
*import_attr
;
3406 struct die_info
*imported_die
;
3407 struct dwarf2_cu
*imported_cu
;
3408 const char *imported_name
;
3409 const char *imported_name_prefix
;
3410 const char *canonical_name
;
3411 const char *import_alias
;
3412 const char *imported_declaration
= NULL
;
3413 const char *import_prefix
;
3417 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3418 if (import_attr
== NULL
)
3420 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3421 dwarf_tag_name (die
->tag
));
3426 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
3427 imported_name
= dwarf2_name (imported_die
, imported_cu
);
3428 if (imported_name
== NULL
)
3430 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3432 The import in the following code:
3446 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3447 <52> DW_AT_decl_file : 1
3448 <53> DW_AT_decl_line : 6
3449 <54> DW_AT_import : <0x75>
3450 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3452 <5b> DW_AT_decl_file : 1
3453 <5c> DW_AT_decl_line : 2
3454 <5d> DW_AT_type : <0x6e>
3456 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3457 <76> DW_AT_byte_size : 4
3458 <77> DW_AT_encoding : 5 (signed)
3460 imports the wrong die ( 0x75 instead of 0x58 ).
3461 This case will be ignored until the gcc bug is fixed. */
3465 /* Figure out the local name after import. */
3466 import_alias
= dwarf2_name (die
, cu
);
3468 /* Figure out where the statement is being imported to. */
3469 import_prefix
= determine_prefix (die
, cu
);
3471 /* Figure out what the scope of the imported die is and prepend it
3472 to the name of the imported die. */
3473 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
3475 if (imported_die
->tag
!= DW_TAG_namespace
)
3477 imported_declaration
= imported_name
;
3478 canonical_name
= imported_name_prefix
;
3480 else if (strlen (imported_name_prefix
) > 0)
3482 temp
= alloca (strlen (imported_name_prefix
)
3483 + 2 + strlen (imported_name
) + 1);
3484 strcpy (temp
, imported_name_prefix
);
3485 strcat (temp
, "::");
3486 strcat (temp
, imported_name
);
3487 canonical_name
= temp
;
3490 canonical_name
= imported_name
;
3492 cp_add_using_directive (import_prefix
,
3495 imported_declaration
,
3496 &cu
->objfile
->objfile_obstack
);
3500 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3502 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3506 free_cu_line_header (void *arg
)
3508 struct dwarf2_cu
*cu
= arg
;
3510 free_line_header (cu
->line_header
);
3511 cu
->line_header
= NULL
;
3515 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3517 struct objfile
*objfile
= cu
->objfile
;
3518 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3519 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3520 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3521 struct attribute
*attr
;
3523 char *comp_dir
= NULL
;
3524 struct die_info
*child_die
;
3525 bfd
*abfd
= objfile
->obfd
;
3526 struct line_header
*line_header
= 0;
3529 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3531 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3533 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3534 from finish_block. */
3535 if (lowpc
== ((CORE_ADDR
) -1))
3540 /* Find the filename. Do not use dwarf2_name here, since the filename
3541 is not a source language identifier. */
3542 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3545 name
= DW_STRING (attr
);
3548 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3550 comp_dir
= DW_STRING (attr
);
3551 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3553 comp_dir
= ldirname (name
);
3554 if (comp_dir
!= NULL
)
3555 make_cleanup (xfree
, comp_dir
);
3557 if (comp_dir
!= NULL
)
3559 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3560 directory, get rid of it. */
3561 char *cp
= strchr (comp_dir
, ':');
3563 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3570 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3573 set_cu_language (DW_UNSND (attr
), cu
);
3576 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3578 cu
->producer
= DW_STRING (attr
);
3580 /* We assume that we're processing GCC output. */
3581 processing_gcc_compilation
= 2;
3583 processing_has_namespace_info
= 0;
3585 start_symtab (name
, comp_dir
, lowpc
);
3586 record_debugformat ("DWARF 2");
3587 record_producer (cu
->producer
);
3589 initialize_cu_func_list (cu
);
3591 /* Decode line number information if present. We do this before
3592 processing child DIEs, so that the line header table is available
3593 for DW_AT_decl_file. */
3594 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3597 unsigned int line_offset
= DW_UNSND (attr
);
3598 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3601 cu
->line_header
= line_header
;
3602 make_cleanup (free_cu_line_header
, cu
);
3603 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3607 /* Process all dies in compilation unit. */
3608 if (die
->child
!= NULL
)
3610 child_die
= die
->child
;
3611 while (child_die
&& child_die
->tag
)
3613 process_die (child_die
, cu
);
3614 child_die
= sibling_die (child_die
);
3618 /* Decode macro information, if present. Dwarf 2 macro information
3619 refers to information in the line number info statement program
3620 header, so we can only read it if we've read the header
3622 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3623 if (attr
&& line_header
)
3625 unsigned int macro_offset
= DW_UNSND (attr
);
3626 dwarf_decode_macros (line_header
, macro_offset
,
3627 comp_dir
, abfd
, cu
);
3629 do_cleanups (back_to
);
3632 /* For TUs we want to skip the first top level sibling if it's not the
3633 actual type being defined by this TU. In this case the first top
3634 level sibling is there to provide context only. */
3637 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3639 struct objfile
*objfile
= cu
->objfile
;
3640 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3642 struct attribute
*attr
;
3644 char *comp_dir
= NULL
;
3645 struct die_info
*child_die
;
3646 bfd
*abfd
= objfile
->obfd
;
3648 /* start_symtab needs a low pc, but we don't really have one.
3649 Do what read_file_scope would do in the absence of such info. */
3650 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3652 /* Find the filename. Do not use dwarf2_name here, since the filename
3653 is not a source language identifier. */
3654 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3656 name
= DW_STRING (attr
);
3658 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3660 comp_dir
= DW_STRING (attr
);
3661 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3663 comp_dir
= ldirname (name
);
3664 if (comp_dir
!= NULL
)
3665 make_cleanup (xfree
, comp_dir
);
3671 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3673 set_cu_language (DW_UNSND (attr
), cu
);
3675 /* This isn't technically needed today. It is done for symmetry
3676 with read_file_scope. */
3677 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3679 cu
->producer
= DW_STRING (attr
);
3681 /* We assume that we're processing GCC output. */
3682 processing_gcc_compilation
= 2;
3684 processing_has_namespace_info
= 0;
3686 start_symtab (name
, comp_dir
, lowpc
);
3687 record_debugformat ("DWARF 2");
3688 record_producer (cu
->producer
);
3690 /* Process the dies in the type unit. */
3691 if (die
->child
== NULL
)
3693 dump_die_for_error (die
);
3694 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3695 bfd_get_filename (abfd
));
3698 child_die
= die
->child
;
3700 while (child_die
&& child_die
->tag
)
3702 process_die (child_die
, cu
);
3704 child_die
= sibling_die (child_die
);
3707 do_cleanups (back_to
);
3711 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3712 struct dwarf2_cu
*cu
)
3714 struct function_range
*thisfn
;
3716 thisfn
= (struct function_range
*)
3717 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3718 thisfn
->name
= name
;
3719 thisfn
->lowpc
= lowpc
;
3720 thisfn
->highpc
= highpc
;
3721 thisfn
->seen_line
= 0;
3722 thisfn
->next
= NULL
;
3724 if (cu
->last_fn
== NULL
)
3725 cu
->first_fn
= thisfn
;
3727 cu
->last_fn
->next
= thisfn
;
3729 cu
->last_fn
= thisfn
;
3732 /* qsort helper for inherit_abstract_dies. */
3735 unsigned_int_compar (const void *ap
, const void *bp
)
3737 unsigned int a
= *(unsigned int *) ap
;
3738 unsigned int b
= *(unsigned int *) bp
;
3740 return (a
> b
) - (b
> a
);
3743 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3744 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3745 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3748 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3750 struct die_info
*child_die
;
3751 unsigned die_children_count
;
3752 /* CU offsets which were referenced by children of the current DIE. */
3754 unsigned *offsets_end
, *offsetp
;
3755 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3756 struct die_info
*origin_die
;
3757 /* Iterator of the ORIGIN_DIE children. */
3758 struct die_info
*origin_child_die
;
3759 struct cleanup
*cleanups
;
3760 struct attribute
*attr
;
3762 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3766 origin_die
= follow_die_ref (die
, attr
, &cu
);
3767 if (die
->tag
!= origin_die
->tag
3768 && !(die
->tag
== DW_TAG_inlined_subroutine
3769 && origin_die
->tag
== DW_TAG_subprogram
))
3770 complaint (&symfile_complaints
,
3771 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3772 die
->offset
, origin_die
->offset
);
3774 child_die
= die
->child
;
3775 die_children_count
= 0;
3776 while (child_die
&& child_die
->tag
)
3778 child_die
= sibling_die (child_die
);
3779 die_children_count
++;
3781 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3782 cleanups
= make_cleanup (xfree
, offsets
);
3784 offsets_end
= offsets
;
3785 child_die
= die
->child
;
3786 while (child_die
&& child_die
->tag
)
3788 /* For each CHILD_DIE, find the corresponding child of
3789 ORIGIN_DIE. If there is more than one layer of
3790 DW_AT_abstract_origin, follow them all; there shouldn't be,
3791 but GCC versions at least through 4.4 generate this (GCC PR
3793 struct die_info
*child_origin_die
= child_die
;
3796 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
3799 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
3802 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3803 counterpart may exist. */
3804 if (child_origin_die
!= child_die
)
3806 if (child_die
->tag
!= child_origin_die
->tag
3807 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3808 && child_origin_die
->tag
== DW_TAG_subprogram
))
3809 complaint (&symfile_complaints
,
3810 _("Child DIE 0x%x and its abstract origin 0x%x have "
3811 "different tags"), child_die
->offset
,
3812 child_origin_die
->offset
);
3813 if (child_origin_die
->parent
!= origin_die
)
3814 complaint (&symfile_complaints
,
3815 _("Child DIE 0x%x and its abstract origin 0x%x have "
3816 "different parents"), child_die
->offset
,
3817 child_origin_die
->offset
);
3819 *offsets_end
++ = child_origin_die
->offset
;
3821 child_die
= sibling_die (child_die
);
3823 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3824 unsigned_int_compar
);
3825 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3826 if (offsetp
[-1] == *offsetp
)
3827 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3828 "to DIE 0x%x as their abstract origin"),
3829 die
->offset
, *offsetp
);
3832 origin_child_die
= origin_die
->child
;
3833 while (origin_child_die
&& origin_child_die
->tag
)
3835 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3836 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3838 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3840 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3841 process_die (origin_child_die
, cu
);
3843 origin_child_die
= sibling_die (origin_child_die
);
3846 do_cleanups (cleanups
);
3850 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3852 struct objfile
*objfile
= cu
->objfile
;
3853 struct context_stack
*new;
3856 struct die_info
*child_die
;
3857 struct attribute
*attr
, *call_line
, *call_file
;
3860 struct block
*block
;
3861 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3865 /* If we do not have call site information, we can't show the
3866 caller of this inlined function. That's too confusing, so
3867 only use the scope for local variables. */
3868 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3869 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3870 if (call_line
== NULL
|| call_file
== NULL
)
3872 read_lexical_block_scope (die
, cu
);
3877 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3879 name
= dwarf2_name (die
, cu
);
3881 /* Ignore functions with missing or empty names. These are actually
3882 illegal according to the DWARF standard. */
3885 complaint (&symfile_complaints
,
3886 _("missing name for subprogram DIE at %d"), die
->offset
);
3890 /* Ignore functions with missing or invalid low and high pc attributes. */
3891 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3893 complaint (&symfile_complaints
,
3894 _("cannot get low and high bounds for subprogram DIE at %d"),
3902 /* Record the function range for dwarf_decode_lines. */
3903 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3905 new = push_context (0, lowpc
);
3906 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3908 /* If there is a location expression for DW_AT_frame_base, record
3910 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3912 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3913 expression is being recorded directly in the function's symbol
3914 and not in a separate frame-base object. I guess this hack is
3915 to avoid adding some sort of frame-base adjunct/annex to the
3916 function's symbol :-(. The problem with doing this is that it
3917 results in a function symbol with a location expression that
3918 has nothing to do with the location of the function, ouch! The
3919 relationship should be: a function's symbol has-a frame base; a
3920 frame-base has-a location expression. */
3921 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3923 cu
->list_in_scope
= &local_symbols
;
3925 if (die
->child
!= NULL
)
3927 child_die
= die
->child
;
3928 while (child_die
&& child_die
->tag
)
3930 process_die (child_die
, cu
);
3931 child_die
= sibling_die (child_die
);
3935 inherit_abstract_dies (die
, cu
);
3937 /* If we have a DW_AT_specification, we might need to import using
3938 directives from the context of the specification DIE. See the
3939 comment in determine_prefix. */
3940 if (cu
->language
== language_cplus
3941 && dwarf2_attr (die
, DW_AT_specification
, cu
))
3943 struct dwarf2_cu
*spec_cu
= cu
;
3944 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
3948 child_die
= spec_die
->child
;
3949 while (child_die
&& child_die
->tag
)
3951 if (child_die
->tag
== DW_TAG_imported_module
)
3952 process_die (child_die
, spec_cu
);
3953 child_die
= sibling_die (child_die
);
3956 /* In some cases, GCC generates specification DIEs that
3957 themselves contain DW_AT_specification attributes. */
3958 spec_die
= die_specification (spec_die
, &spec_cu
);
3962 new = pop_context ();
3963 /* Make a block for the local symbols within. */
3964 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3965 lowpc
, highpc
, objfile
);
3967 /* For C++, set the block's scope. */
3968 if (cu
->language
== language_cplus
)
3969 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3970 determine_prefix (die
, cu
),
3971 processing_has_namespace_info
);
3973 /* If we have address ranges, record them. */
3974 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3976 /* In C++, we can have functions nested inside functions (e.g., when
3977 a function declares a class that has methods). This means that
3978 when we finish processing a function scope, we may need to go
3979 back to building a containing block's symbol lists. */
3980 local_symbols
= new->locals
;
3981 param_symbols
= new->params
;
3982 using_directives
= new->using_directives
;
3984 /* If we've finished processing a top-level function, subsequent
3985 symbols go in the file symbol list. */
3986 if (outermost_context_p ())
3987 cu
->list_in_scope
= &file_symbols
;
3990 /* Process all the DIES contained within a lexical block scope. Start
3991 a new scope, process the dies, and then close the scope. */
3994 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3996 struct objfile
*objfile
= cu
->objfile
;
3997 struct context_stack
*new;
3998 CORE_ADDR lowpc
, highpc
;
3999 struct die_info
*child_die
;
4002 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4004 /* Ignore blocks with missing or invalid low and high pc attributes. */
4005 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
4006 as multiple lexical blocks? Handling children in a sane way would
4007 be nasty. Might be easier to properly extend generic blocks to
4009 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
4014 push_context (0, lowpc
);
4015 if (die
->child
!= NULL
)
4017 child_die
= die
->child
;
4018 while (child_die
&& child_die
->tag
)
4020 process_die (child_die
, cu
);
4021 child_die
= sibling_die (child_die
);
4024 new = pop_context ();
4026 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
4029 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
4032 /* Note that recording ranges after traversing children, as we
4033 do here, means that recording a parent's ranges entails
4034 walking across all its children's ranges as they appear in
4035 the address map, which is quadratic behavior.
4037 It would be nicer to record the parent's ranges before
4038 traversing its children, simply overriding whatever you find
4039 there. But since we don't even decide whether to create a
4040 block until after we've traversed its children, that's hard
4042 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
4044 local_symbols
= new->locals
;
4045 using_directives
= new->using_directives
;
4048 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
4049 Return 1 if the attributes are present and valid, otherwise, return 0.
4050 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
4053 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
4054 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
4055 struct partial_symtab
*ranges_pst
)
4057 struct objfile
*objfile
= cu
->objfile
;
4058 struct comp_unit_head
*cu_header
= &cu
->header
;
4059 bfd
*obfd
= objfile
->obfd
;
4060 unsigned int addr_size
= cu_header
->addr_size
;
4061 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4062 /* Base address selection entry. */
4073 found_base
= cu
->base_known
;
4074 base
= cu
->base_address
;
4076 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
4077 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4079 complaint (&symfile_complaints
,
4080 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4084 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4086 /* Read in the largest possible address. */
4087 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
4088 if ((marker
& mask
) == mask
)
4090 /* If we found the largest possible address, then
4091 read the base address. */
4092 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4093 buffer
+= 2 * addr_size
;
4094 offset
+= 2 * addr_size
;
4100 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4104 CORE_ADDR range_beginning
, range_end
;
4106 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
4107 buffer
+= addr_size
;
4108 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
4109 buffer
+= addr_size
;
4110 offset
+= 2 * addr_size
;
4112 /* An end of list marker is a pair of zero addresses. */
4113 if (range_beginning
== 0 && range_end
== 0)
4114 /* Found the end of list entry. */
4117 /* Each base address selection entry is a pair of 2 values.
4118 The first is the largest possible address, the second is
4119 the base address. Check for a base address here. */
4120 if ((range_beginning
& mask
) == mask
)
4122 /* If we found the largest possible address, then
4123 read the base address. */
4124 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4131 /* We have no valid base address for the ranges
4133 complaint (&symfile_complaints
,
4134 _("Invalid .debug_ranges data (no base address)"));
4138 range_beginning
+= base
;
4141 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
4142 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4143 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
4146 /* FIXME: This is recording everything as a low-high
4147 segment of consecutive addresses. We should have a
4148 data structure for discontiguous block ranges
4152 low
= range_beginning
;
4158 if (range_beginning
< low
)
4159 low
= range_beginning
;
4160 if (range_end
> high
)
4166 /* If the first entry is an end-of-list marker, the range
4167 describes an empty scope, i.e. no instructions. */
4173 *high_return
= high
;
4177 /* Get low and high pc attributes from a die. Return 1 if the attributes
4178 are present and valid, otherwise, return 0. Return -1 if the range is
4179 discontinuous, i.e. derived from DW_AT_ranges information. */
4181 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
4182 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
4183 struct partial_symtab
*pst
)
4185 struct attribute
*attr
;
4190 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4193 high
= DW_ADDR (attr
);
4194 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4196 low
= DW_ADDR (attr
);
4198 /* Found high w/o low attribute. */
4201 /* Found consecutive range of addresses. */
4206 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4209 /* Value of the DW_AT_ranges attribute is the offset in the
4210 .debug_ranges section. */
4211 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
4213 /* Found discontinuous range of addresses. */
4221 /* When using the GNU linker, .gnu.linkonce. sections are used to
4222 eliminate duplicate copies of functions and vtables and such.
4223 The linker will arbitrarily choose one and discard the others.
4224 The AT_*_pc values for such functions refer to local labels in
4225 these sections. If the section from that file was discarded, the
4226 labels are not in the output, so the relocs get a value of 0.
4227 If this is a discarded function, mark the pc bounds as invalid,
4228 so that GDB will ignore it. */
4229 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
4237 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4238 its low and high PC addresses. Do nothing if these addresses could not
4239 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4240 and HIGHPC to the high address if greater than HIGHPC. */
4243 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
4244 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4245 struct dwarf2_cu
*cu
)
4247 CORE_ADDR low
, high
;
4248 struct die_info
*child
= die
->child
;
4250 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
4252 *lowpc
= min (*lowpc
, low
);
4253 *highpc
= max (*highpc
, high
);
4256 /* If the language does not allow nested subprograms (either inside
4257 subprograms or lexical blocks), we're done. */
4258 if (cu
->language
!= language_ada
)
4261 /* Check all the children of the given DIE. If it contains nested
4262 subprograms, then check their pc bounds. Likewise, we need to
4263 check lexical blocks as well, as they may also contain subprogram
4265 while (child
&& child
->tag
)
4267 if (child
->tag
== DW_TAG_subprogram
4268 || child
->tag
== DW_TAG_lexical_block
)
4269 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
4270 child
= sibling_die (child
);
4274 /* Get the low and high pc's represented by the scope DIE, and store
4275 them in *LOWPC and *HIGHPC. If the correct values can't be
4276 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4279 get_scope_pc_bounds (struct die_info
*die
,
4280 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4281 struct dwarf2_cu
*cu
)
4283 CORE_ADDR best_low
= (CORE_ADDR
) -1;
4284 CORE_ADDR best_high
= (CORE_ADDR
) 0;
4285 CORE_ADDR current_low
, current_high
;
4287 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
4289 best_low
= current_low
;
4290 best_high
= current_high
;
4294 struct die_info
*child
= die
->child
;
4296 while (child
&& child
->tag
)
4298 switch (child
->tag
) {
4299 case DW_TAG_subprogram
:
4300 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
4302 case DW_TAG_namespace
:
4303 /* FIXME: carlton/2004-01-16: Should we do this for
4304 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4305 that current GCC's always emit the DIEs corresponding
4306 to definitions of methods of classes as children of a
4307 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4308 the DIEs giving the declarations, which could be
4309 anywhere). But I don't see any reason why the
4310 standards says that they have to be there. */
4311 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
4313 if (current_low
!= ((CORE_ADDR
) -1))
4315 best_low
= min (best_low
, current_low
);
4316 best_high
= max (best_high
, current_high
);
4324 child
= sibling_die (child
);
4329 *highpc
= best_high
;
4332 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4335 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
4336 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
4338 struct attribute
*attr
;
4340 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4343 CORE_ADDR high
= DW_ADDR (attr
);
4344 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4347 CORE_ADDR low
= DW_ADDR (attr
);
4348 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
4352 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4355 bfd
*obfd
= cu
->objfile
->obfd
;
4357 /* The value of the DW_AT_ranges attribute is the offset of the
4358 address range list in the .debug_ranges section. */
4359 unsigned long offset
= DW_UNSND (attr
);
4360 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4362 /* For some target architectures, but not others, the
4363 read_address function sign-extends the addresses it returns.
4364 To recognize base address selection entries, we need a
4366 unsigned int addr_size
= cu
->header
.addr_size
;
4367 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4369 /* The base address, to which the next pair is relative. Note
4370 that this 'base' is a DWARF concept: most entries in a range
4371 list are relative, to reduce the number of relocs against the
4372 debugging information. This is separate from this function's
4373 'baseaddr' argument, which GDB uses to relocate debugging
4374 information from a shared library based on the address at
4375 which the library was loaded. */
4376 CORE_ADDR base
= cu
->base_address
;
4377 int base_known
= cu
->base_known
;
4379 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
4380 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4382 complaint (&symfile_complaints
,
4383 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4390 unsigned int bytes_read
;
4391 CORE_ADDR start
, end
;
4393 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4394 buffer
+= bytes_read
;
4395 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4396 buffer
+= bytes_read
;
4398 /* Did we find the end of the range list? */
4399 if (start
== 0 && end
== 0)
4402 /* Did we find a base address selection entry? */
4403 else if ((start
& base_select_mask
) == base_select_mask
)
4409 /* We found an ordinary address range. */
4414 complaint (&symfile_complaints
,
4415 _("Invalid .debug_ranges data (no base address)"));
4419 record_block_range (block
,
4420 baseaddr
+ base
+ start
,
4421 baseaddr
+ base
+ end
- 1);
4427 /* Add an aggregate field to the field list. */
4430 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
4431 struct dwarf2_cu
*cu
)
4433 struct objfile
*objfile
= cu
->objfile
;
4434 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4435 struct nextfield
*new_field
;
4436 struct attribute
*attr
;
4438 char *fieldname
= "";
4440 /* Allocate a new field list entry and link it in. */
4441 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
4442 make_cleanup (xfree
, new_field
);
4443 memset (new_field
, 0, sizeof (struct nextfield
));
4445 if (die
->tag
== DW_TAG_inheritance
)
4447 new_field
->next
= fip
->baseclasses
;
4448 fip
->baseclasses
= new_field
;
4452 new_field
->next
= fip
->fields
;
4453 fip
->fields
= new_field
;
4457 /* Handle accessibility and virtuality of field.
4458 The default accessibility for members is public, the default
4459 accessibility for inheritance is private. */
4460 if (die
->tag
!= DW_TAG_inheritance
)
4461 new_field
->accessibility
= DW_ACCESS_public
;
4463 new_field
->accessibility
= DW_ACCESS_private
;
4464 new_field
->virtuality
= DW_VIRTUALITY_none
;
4466 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4468 new_field
->accessibility
= DW_UNSND (attr
);
4469 if (new_field
->accessibility
!= DW_ACCESS_public
)
4470 fip
->non_public_fields
= 1;
4471 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4473 new_field
->virtuality
= DW_UNSND (attr
);
4475 fp
= &new_field
->field
;
4477 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
4479 /* Data member other than a C++ static data member. */
4481 /* Get type of field. */
4482 fp
->type
= die_type (die
, cu
);
4484 SET_FIELD_BITPOS (*fp
, 0);
4486 /* Get bit size of field (zero if none). */
4487 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
4490 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
4494 FIELD_BITSIZE (*fp
) = 0;
4497 /* Get bit offset of field. */
4498 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4501 int byte_offset
= 0;
4503 if (attr_form_is_section_offset (attr
))
4504 dwarf2_complex_location_expr_complaint ();
4505 else if (attr_form_is_constant (attr
))
4506 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4507 else if (attr_form_is_block (attr
))
4508 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4510 dwarf2_complex_location_expr_complaint ();
4512 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4514 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
4517 if (gdbarch_bits_big_endian (gdbarch
))
4519 /* For big endian bits, the DW_AT_bit_offset gives the
4520 additional bit offset from the MSB of the containing
4521 anonymous object to the MSB of the field. We don't
4522 have to do anything special since we don't need to
4523 know the size of the anonymous object. */
4524 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
4528 /* For little endian bits, compute the bit offset to the
4529 MSB of the anonymous object, subtract off the number of
4530 bits from the MSB of the field to the MSB of the
4531 object, and then subtract off the number of bits of
4532 the field itself. The result is the bit offset of
4533 the LSB of the field. */
4535 int bit_offset
= DW_UNSND (attr
);
4537 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4540 /* The size of the anonymous object containing
4541 the bit field is explicit, so use the
4542 indicated size (in bytes). */
4543 anonymous_size
= DW_UNSND (attr
);
4547 /* The size of the anonymous object containing
4548 the bit field must be inferred from the type
4549 attribute of the data member containing the
4551 anonymous_size
= TYPE_LENGTH (fp
->type
);
4553 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4554 - bit_offset
- FIELD_BITSIZE (*fp
);
4558 /* Get name of field. */
4559 fieldname
= dwarf2_name (die
, cu
);
4560 if (fieldname
== NULL
)
4563 /* The name is already allocated along with this objfile, so we don't
4564 need to duplicate it for the type. */
4565 fp
->name
= fieldname
;
4567 /* Change accessibility for artificial fields (e.g. virtual table
4568 pointer or virtual base class pointer) to private. */
4569 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4571 FIELD_ARTIFICIAL (*fp
) = 1;
4572 new_field
->accessibility
= DW_ACCESS_private
;
4573 fip
->non_public_fields
= 1;
4576 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4578 /* C++ static member. */
4580 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4581 is a declaration, but all versions of G++ as of this writing
4582 (so through at least 3.2.1) incorrectly generate
4583 DW_TAG_variable tags. */
4587 /* Get name of field. */
4588 fieldname
= dwarf2_name (die
, cu
);
4589 if (fieldname
== NULL
)
4592 /* Get physical name. */
4593 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4595 /* The name is already allocated along with this objfile, so we don't
4596 need to duplicate it for the type. */
4597 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4598 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4599 FIELD_NAME (*fp
) = fieldname
;
4601 else if (die
->tag
== DW_TAG_inheritance
)
4603 /* C++ base class field. */
4604 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4607 int byte_offset
= 0;
4609 if (attr_form_is_section_offset (attr
))
4610 dwarf2_complex_location_expr_complaint ();
4611 else if (attr_form_is_constant (attr
))
4612 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4613 else if (attr_form_is_block (attr
))
4614 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4616 dwarf2_complex_location_expr_complaint ();
4618 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4620 FIELD_BITSIZE (*fp
) = 0;
4621 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4622 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4623 fip
->nbaseclasses
++;
4627 /* Create the vector of fields, and attach it to the type. */
4630 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4631 struct dwarf2_cu
*cu
)
4633 int nfields
= fip
->nfields
;
4635 /* Record the field count, allocate space for the array of fields,
4636 and create blank accessibility bitfields if necessary. */
4637 TYPE_NFIELDS (type
) = nfields
;
4638 TYPE_FIELDS (type
) = (struct field
*)
4639 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4640 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4642 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
4644 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4646 TYPE_FIELD_PRIVATE_BITS (type
) =
4647 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4648 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4650 TYPE_FIELD_PROTECTED_BITS (type
) =
4651 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4652 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4654 TYPE_FIELD_IGNORE_BITS (type
) =
4655 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4656 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4659 /* If the type has baseclasses, allocate and clear a bit vector for
4660 TYPE_FIELD_VIRTUAL_BITS. */
4661 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
4663 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4664 unsigned char *pointer
;
4666 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4667 pointer
= TYPE_ALLOC (type
, num_bytes
);
4668 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4669 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4670 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4673 /* Copy the saved-up fields into the field vector. Start from the head
4674 of the list, adding to the tail of the field array, so that they end
4675 up in the same order in the array in which they were added to the list. */
4676 while (nfields
-- > 0)
4678 struct nextfield
*fieldp
;
4682 fieldp
= fip
->fields
;
4683 fip
->fields
= fieldp
->next
;
4687 fieldp
= fip
->baseclasses
;
4688 fip
->baseclasses
= fieldp
->next
;
4691 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
4692 switch (fieldp
->accessibility
)
4694 case DW_ACCESS_private
:
4695 if (cu
->language
!= language_ada
)
4696 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4699 case DW_ACCESS_protected
:
4700 if (cu
->language
!= language_ada
)
4701 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4704 case DW_ACCESS_public
:
4708 /* Unknown accessibility. Complain and treat it as public. */
4710 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4711 fieldp
->accessibility
);
4715 if (nfields
< fip
->nbaseclasses
)
4717 switch (fieldp
->virtuality
)
4719 case DW_VIRTUALITY_virtual
:
4720 case DW_VIRTUALITY_pure_virtual
:
4721 if (cu
->language
== language_ada
)
4722 error ("unexpected virtuality in component of Ada type");
4723 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4730 /* Add a member function to the proper fieldlist. */
4733 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4734 struct type
*type
, struct dwarf2_cu
*cu
)
4736 struct objfile
*objfile
= cu
->objfile
;
4737 struct attribute
*attr
;
4738 struct fnfieldlist
*flp
;
4740 struct fn_field
*fnp
;
4743 struct nextfnfield
*new_fnfield
;
4744 struct type
*this_type
;
4746 if (cu
->language
== language_ada
)
4747 error ("unexpected member function in Ada type");
4749 /* Get name of member function. */
4750 fieldname
= dwarf2_name (die
, cu
);
4751 if (fieldname
== NULL
)
4754 /* Get the mangled name. */
4755 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4757 /* Look up member function name in fieldlist. */
4758 for (i
= 0; i
< fip
->nfnfields
; i
++)
4760 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4764 /* Create new list element if necessary. */
4765 if (i
< fip
->nfnfields
)
4766 flp
= &fip
->fnfieldlists
[i
];
4769 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4771 fip
->fnfieldlists
= (struct fnfieldlist
*)
4772 xrealloc (fip
->fnfieldlists
,
4773 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4774 * sizeof (struct fnfieldlist
));
4775 if (fip
->nfnfields
== 0)
4776 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4778 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4779 flp
->name
= fieldname
;
4785 /* Create a new member function field and chain it to the field list
4787 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4788 make_cleanup (xfree
, new_fnfield
);
4789 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4790 new_fnfield
->next
= flp
->head
;
4791 flp
->head
= new_fnfield
;
4794 /* Fill in the member function field info. */
4795 fnp
= &new_fnfield
->fnfield
;
4796 /* The name is already allocated along with this objfile, so we don't
4797 need to duplicate it for the type. */
4798 fnp
->physname
= physname
? physname
: "";
4799 fnp
->type
= alloc_type (objfile
);
4800 this_type
= read_type_die (die
, cu
);
4801 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4803 int nparams
= TYPE_NFIELDS (this_type
);
4805 /* TYPE is the domain of this method, and THIS_TYPE is the type
4806 of the method itself (TYPE_CODE_METHOD). */
4807 smash_to_method_type (fnp
->type
, type
,
4808 TYPE_TARGET_TYPE (this_type
),
4809 TYPE_FIELDS (this_type
),
4810 TYPE_NFIELDS (this_type
),
4811 TYPE_VARARGS (this_type
));
4813 /* Handle static member functions.
4814 Dwarf2 has no clean way to discern C++ static and non-static
4815 member functions. G++ helps GDB by marking the first
4816 parameter for non-static member functions (which is the
4817 this pointer) as artificial. We obtain this information
4818 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4819 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4820 fnp
->voffset
= VOFFSET_STATIC
;
4823 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4826 /* Get fcontext from DW_AT_containing_type if present. */
4827 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4828 fnp
->fcontext
= die_containing_type (die
, cu
);
4830 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4831 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4833 /* Get accessibility. */
4834 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4837 switch (DW_UNSND (attr
))
4839 case DW_ACCESS_private
:
4840 fnp
->is_private
= 1;
4842 case DW_ACCESS_protected
:
4843 fnp
->is_protected
= 1;
4848 /* Check for artificial methods. */
4849 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4850 if (attr
&& DW_UNSND (attr
) != 0)
4851 fnp
->is_artificial
= 1;
4853 /* Get index in virtual function table if it is a virtual member
4854 function. For GCC, this is an offset in the appropriate
4855 virtual table, as specified by DW_AT_containing_type. For
4856 everyone else, it is an expression to be evaluated relative
4857 to the object address. */
4859 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4860 if (attr
&& fnp
->fcontext
)
4862 /* Support the .debug_loc offsets */
4863 if (attr_form_is_block (attr
))
4865 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4867 else if (attr_form_is_section_offset (attr
))
4869 dwarf2_complex_location_expr_complaint ();
4873 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4879 /* We only support trivial expressions here. This hack will work
4880 for v3 classes, which always start with the vtable pointer. */
4881 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0
4882 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref
)
4884 struct dwarf_block blk
;
4885 blk
.size
= DW_BLOCK (attr
)->size
- 1;
4886 blk
.data
= DW_BLOCK (attr
)->data
+ 1;
4887 fnp
->voffset
= decode_locdesc (&blk
, cu
);
4888 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
4889 dwarf2_complex_location_expr_complaint ();
4891 fnp
->voffset
/= cu
->header
.addr_size
;
4893 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
4896 dwarf2_complex_location_expr_complaint ();
4900 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4901 if (attr
&& DW_UNSND (attr
))
4903 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4904 complaint (&symfile_complaints
,
4905 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4906 fieldname
, die
->offset
);
4907 TYPE_CPLUS_DYNAMIC (type
) = 1;
4912 /* Create the vector of member function fields, and attach it to the type. */
4915 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4916 struct dwarf2_cu
*cu
)
4918 struct fnfieldlist
*flp
;
4919 int total_length
= 0;
4922 if (cu
->language
== language_ada
)
4923 error ("unexpected member functions in Ada type");
4925 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4926 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4927 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4929 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4931 struct nextfnfield
*nfp
= flp
->head
;
4932 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4935 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4936 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4937 fn_flp
->fn_fields
= (struct fn_field
*)
4938 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4939 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4940 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4942 total_length
+= flp
->length
;
4945 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4946 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4949 /* Returns non-zero if NAME is the name of a vtable member in CU's
4950 language, zero otherwise. */
4952 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4954 static const char vptr
[] = "_vptr";
4955 static const char vtable
[] = "vtable";
4957 /* Look for the C++ and Java forms of the vtable. */
4958 if ((cu
->language
== language_java
4959 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4960 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4961 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4967 /* GCC outputs unnamed structures that are really pointers to member
4968 functions, with the ABI-specified layout. If TYPE describes
4969 such a structure, smash it into a member function type.
4971 GCC shouldn't do this; it should just output pointer to member DIEs.
4972 This is GCC PR debug/28767. */
4975 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
4977 struct type
*pfn_type
, *domain_type
, *new_type
;
4979 /* Check for a structure with no name and two children. */
4980 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
4983 /* Check for __pfn and __delta members. */
4984 if (TYPE_FIELD_NAME (type
, 0) == NULL
4985 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
4986 || TYPE_FIELD_NAME (type
, 1) == NULL
4987 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
4990 /* Find the type of the method. */
4991 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
4992 if (pfn_type
== NULL
4993 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4994 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4997 /* Look for the "this" argument. */
4998 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4999 if (TYPE_NFIELDS (pfn_type
) == 0
5000 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
5001 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
5004 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
5005 new_type
= alloc_type (objfile
);
5006 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
5007 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
5008 TYPE_VARARGS (pfn_type
));
5009 smash_to_methodptr_type (type
, new_type
);
5012 /* Called when we find the DIE that starts a structure or union scope
5013 (definition) to process all dies that define the members of the
5016 NOTE: we need to call struct_type regardless of whether or not the
5017 DIE has an at_name attribute, since it might be an anonymous
5018 structure or union. This gets the type entered into our set of
5021 However, if the structure is incomplete (an opaque struct/union)
5022 then suppress creating a symbol table entry for it since gdb only
5023 wants to find the one with the complete definition. Note that if
5024 it is complete, we just call new_symbol, which does it's own
5025 checking about whether the struct/union is anonymous or not (and
5026 suppresses creating a symbol table entry itself). */
5028 static struct type
*
5029 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5031 struct objfile
*objfile
= cu
->objfile
;
5033 struct attribute
*attr
;
5035 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5037 /* If the definition of this type lives in .debug_types, read that type.
5038 Don't follow DW_AT_specification though, that will take us back up
5039 the chain and we want to go down. */
5040 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5043 struct dwarf2_cu
*type_cu
= cu
;
5044 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5045 /* We could just recurse on read_structure_type, but we need to call
5046 get_die_type to ensure only one type for this DIE is created.
5047 This is important, for example, because for c++ classes we need
5048 TYPE_NAME set which is only done by new_symbol. Blech. */
5049 type
= read_type_die (type_die
, type_cu
);
5050 return set_die_type (die
, type
, cu
);
5053 type
= alloc_type (objfile
);
5054 INIT_CPLUS_SPECIFIC (type
);
5056 name
= dwarf2_name (die
, cu
);
5059 if (cu
->language
== language_cplus
5060 || cu
->language
== language_java
)
5062 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
5063 if (die
->tag
== DW_TAG_structure_type
5064 || die
->tag
== DW_TAG_class_type
)
5065 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5069 /* The name is already allocated along with this objfile, so
5070 we don't need to duplicate it for the type. */
5071 TYPE_TAG_NAME (type
) = (char *) name
;
5072 if (die
->tag
== DW_TAG_class_type
)
5073 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5077 if (die
->tag
== DW_TAG_structure_type
)
5079 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
5081 else if (die
->tag
== DW_TAG_union_type
)
5083 TYPE_CODE (type
) = TYPE_CODE_UNION
;
5087 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
5090 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
5091 TYPE_DECLARED_CLASS (type
) = 1;
5093 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5096 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5100 TYPE_LENGTH (type
) = 0;
5103 TYPE_STUB_SUPPORTED (type
) = 1;
5104 if (die_is_declaration (die
, cu
))
5105 TYPE_STUB (type
) = 1;
5106 else if (attr
== NULL
&& die
->child
== NULL
5107 && producer_is_realview (cu
->producer
))
5108 /* RealView does not output the required DW_AT_declaration
5109 on incomplete types. */
5110 TYPE_STUB (type
) = 1;
5112 set_descriptive_type (type
, die
, cu
);
5114 /* We need to add the type field to the die immediately so we don't
5115 infinitely recurse when dealing with pointers to the structure
5116 type within the structure itself. */
5117 set_die_type (die
, type
, cu
);
5119 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
5121 struct field_info fi
;
5122 struct die_info
*child_die
;
5124 memset (&fi
, 0, sizeof (struct field_info
));
5126 child_die
= die
->child
;
5128 while (child_die
&& child_die
->tag
)
5130 if (child_die
->tag
== DW_TAG_member
5131 || child_die
->tag
== DW_TAG_variable
)
5133 /* NOTE: carlton/2002-11-05: A C++ static data member
5134 should be a DW_TAG_member that is a declaration, but
5135 all versions of G++ as of this writing (so through at
5136 least 3.2.1) incorrectly generate DW_TAG_variable
5137 tags for them instead. */
5138 dwarf2_add_field (&fi
, child_die
, cu
);
5140 else if (child_die
->tag
== DW_TAG_subprogram
)
5142 /* C++ member function. */
5143 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
5145 else if (child_die
->tag
== DW_TAG_inheritance
)
5147 /* C++ base class field. */
5148 dwarf2_add_field (&fi
, child_die
, cu
);
5150 child_die
= sibling_die (child_die
);
5153 /* Attach fields and member functions to the type. */
5155 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
5158 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
5160 /* Get the type which refers to the base class (possibly this
5161 class itself) which contains the vtable pointer for the current
5162 class from the DW_AT_containing_type attribute. This use of
5163 DW_AT_containing_type is a GNU extension. */
5165 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5167 struct type
*t
= die_containing_type (die
, cu
);
5169 TYPE_VPTR_BASETYPE (type
) = t
;
5174 /* Our own class provides vtbl ptr. */
5175 for (i
= TYPE_NFIELDS (t
) - 1;
5176 i
>= TYPE_N_BASECLASSES (t
);
5179 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
5181 if (is_vtable_name (fieldname
, cu
))
5183 TYPE_VPTR_FIELDNO (type
) = i
;
5188 /* Complain if virtual function table field not found. */
5189 if (i
< TYPE_N_BASECLASSES (t
))
5190 complaint (&symfile_complaints
,
5191 _("virtual function table pointer not found when defining class '%s'"),
5192 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
5197 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
5200 else if (cu
->producer
5201 && strncmp (cu
->producer
,
5202 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5204 /* The IBM XLC compiler does not provide direct indication
5205 of the containing type, but the vtable pointer is
5206 always named __vfp. */
5210 for (i
= TYPE_NFIELDS (type
) - 1;
5211 i
>= TYPE_N_BASECLASSES (type
);
5214 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
5216 TYPE_VPTR_FIELDNO (type
) = i
;
5217 TYPE_VPTR_BASETYPE (type
) = type
;
5225 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
5227 do_cleanups (back_to
);
5232 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5234 struct die_info
*child_die
= die
->child
;
5235 struct type
*this_type
;
5237 this_type
= get_die_type (die
, cu
);
5238 if (this_type
== NULL
)
5239 this_type
= read_structure_type (die
, cu
);
5241 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5242 snapshots) has been known to create a die giving a declaration
5243 for a class that has, as a child, a die giving a definition for a
5244 nested class. So we have to process our children even if the
5245 current die is a declaration. Normally, of course, a declaration
5246 won't have any children at all. */
5248 while (child_die
!= NULL
&& child_die
->tag
)
5250 if (child_die
->tag
== DW_TAG_member
5251 || child_die
->tag
== DW_TAG_variable
5252 || child_die
->tag
== DW_TAG_inheritance
)
5257 process_die (child_die
, cu
);
5259 child_die
= sibling_die (child_die
);
5262 /* Do not consider external references. According to the DWARF standard,
5263 these DIEs are identified by the fact that they have no byte_size
5264 attribute, and a declaration attribute. */
5265 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
5266 || !die_is_declaration (die
, cu
))
5267 new_symbol (die
, this_type
, cu
);
5270 /* Given a DW_AT_enumeration_type die, set its type. We do not
5271 complete the type's fields yet, or create any symbols. */
5273 static struct type
*
5274 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5276 struct objfile
*objfile
= cu
->objfile
;
5278 struct attribute
*attr
;
5281 /* If the definition of this type lives in .debug_types, read that type.
5282 Don't follow DW_AT_specification though, that will take us back up
5283 the chain and we want to go down. */
5284 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5287 struct dwarf2_cu
*type_cu
= cu
;
5288 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5289 type
= read_type_die (type_die
, type_cu
);
5290 return set_die_type (die
, type
, cu
);
5293 type
= alloc_type (objfile
);
5295 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
5296 name
= dwarf2_full_name (NULL
, die
, cu
);
5298 TYPE_TAG_NAME (type
) = (char *) name
;
5300 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5303 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5307 TYPE_LENGTH (type
) = 0;
5310 /* The enumeration DIE can be incomplete. In Ada, any type can be
5311 declared as private in the package spec, and then defined only
5312 inside the package body. Such types are known as Taft Amendment
5313 Types. When another package uses such a type, an incomplete DIE
5314 may be generated by the compiler. */
5315 if (die_is_declaration (die
, cu
))
5316 TYPE_STUB (type
) = 1;
5318 return set_die_type (die
, type
, cu
);
5321 /* Given a pointer to a die which begins an enumeration, process all
5322 the dies that define the members of the enumeration, and create the
5323 symbol for the enumeration type.
5325 NOTE: We reverse the order of the element list. */
5328 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5330 struct die_info
*child_die
;
5331 struct field
*fields
;
5334 int unsigned_enum
= 1;
5336 struct type
*this_type
;
5340 this_type
= get_die_type (die
, cu
);
5341 if (this_type
== NULL
)
5342 this_type
= read_enumeration_type (die
, cu
);
5343 if (die
->child
!= NULL
)
5345 child_die
= die
->child
;
5346 while (child_die
&& child_die
->tag
)
5348 if (child_die
->tag
!= DW_TAG_enumerator
)
5350 process_die (child_die
, cu
);
5354 name
= dwarf2_name (child_die
, cu
);
5357 sym
= new_symbol (child_die
, this_type
, cu
);
5358 if (SYMBOL_VALUE (sym
) < 0)
5361 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5363 fields
= (struct field
*)
5365 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
5366 * sizeof (struct field
));
5369 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
5370 FIELD_TYPE (fields
[num_fields
]) = NULL
;
5371 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
5372 FIELD_BITSIZE (fields
[num_fields
]) = 0;
5378 child_die
= sibling_die (child_die
);
5383 TYPE_NFIELDS (this_type
) = num_fields
;
5384 TYPE_FIELDS (this_type
) = (struct field
*)
5385 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
5386 memcpy (TYPE_FIELDS (this_type
), fields
,
5387 sizeof (struct field
) * num_fields
);
5391 TYPE_UNSIGNED (this_type
) = 1;
5394 new_symbol (die
, this_type
, cu
);
5397 /* Extract all information from a DW_TAG_array_type DIE and put it in
5398 the DIE's type field. For now, this only handles one dimensional
5401 static struct type
*
5402 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5404 struct objfile
*objfile
= cu
->objfile
;
5405 struct die_info
*child_die
;
5406 struct type
*type
= NULL
;
5407 struct type
*element_type
, *range_type
, *index_type
;
5408 struct type
**range_types
= NULL
;
5409 struct attribute
*attr
;
5411 struct cleanup
*back_to
;
5414 element_type
= die_type (die
, cu
);
5416 /* Irix 6.2 native cc creates array types without children for
5417 arrays with unspecified length. */
5418 if (die
->child
== NULL
)
5420 index_type
= objfile_type (objfile
)->builtin_int
;
5421 range_type
= create_range_type (NULL
, index_type
, 0, -1);
5422 type
= create_array_type (NULL
, element_type
, range_type
);
5423 return set_die_type (die
, type
, cu
);
5426 back_to
= make_cleanup (null_cleanup
, NULL
);
5427 child_die
= die
->child
;
5428 while (child_die
&& child_die
->tag
)
5430 if (child_die
->tag
== DW_TAG_subrange_type
)
5432 struct type
*child_type
= read_type_die (child_die
, cu
);
5433 if (child_type
!= NULL
)
5435 /* The range type was succesfully read. Save it for
5436 the array type creation. */
5437 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
5439 range_types
= (struct type
**)
5440 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
5441 * sizeof (struct type
*));
5443 make_cleanup (free_current_contents
, &range_types
);
5445 range_types
[ndim
++] = child_type
;
5448 child_die
= sibling_die (child_die
);
5451 /* Dwarf2 dimensions are output from left to right, create the
5452 necessary array types in backwards order. */
5454 type
= element_type
;
5456 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
5460 type
= create_array_type (NULL
, type
, range_types
[i
++]);
5465 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
5468 /* Understand Dwarf2 support for vector types (like they occur on
5469 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5470 array type. This is not part of the Dwarf2/3 standard yet, but a
5471 custom vendor extension. The main difference between a regular
5472 array and the vector variant is that vectors are passed by value
5474 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
5476 make_vector_type (type
);
5478 name
= dwarf2_name (die
, cu
);
5480 TYPE_NAME (type
) = name
;
5482 set_descriptive_type (type
, die
, cu
);
5484 do_cleanups (back_to
);
5486 /* Install the type in the die. */
5487 return set_die_type (die
, type
, cu
);
5490 static enum dwarf_array_dim_ordering
5491 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
5493 struct attribute
*attr
;
5495 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
5497 if (attr
) return DW_SND (attr
);
5500 GNU F77 is a special case, as at 08/2004 array type info is the
5501 opposite order to the dwarf2 specification, but data is still
5502 laid out as per normal fortran.
5504 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5508 if (cu
->language
== language_fortran
5509 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
5511 return DW_ORD_row_major
;
5514 switch (cu
->language_defn
->la_array_ordering
)
5516 case array_column_major
:
5517 return DW_ORD_col_major
;
5518 case array_row_major
:
5520 return DW_ORD_row_major
;
5524 /* Extract all information from a DW_TAG_set_type DIE and put it in
5525 the DIE's type field. */
5527 static struct type
*
5528 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5530 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
5532 return set_die_type (die
, set_type
, cu
);
5535 /* First cut: install each common block member as a global variable. */
5538 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
5540 struct die_info
*child_die
;
5541 struct attribute
*attr
;
5543 CORE_ADDR base
= (CORE_ADDR
) 0;
5545 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5548 /* Support the .debug_loc offsets */
5549 if (attr_form_is_block (attr
))
5551 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
5553 else if (attr_form_is_section_offset (attr
))
5555 dwarf2_complex_location_expr_complaint ();
5559 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5560 "common block member");
5563 if (die
->child
!= NULL
)
5565 child_die
= die
->child
;
5566 while (child_die
&& child_die
->tag
)
5568 sym
= new_symbol (child_die
, NULL
, cu
);
5569 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
5572 CORE_ADDR byte_offset
= 0;
5574 if (attr_form_is_section_offset (attr
))
5575 dwarf2_complex_location_expr_complaint ();
5576 else if (attr_form_is_constant (attr
))
5577 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5578 else if (attr_form_is_block (attr
))
5579 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5581 dwarf2_complex_location_expr_complaint ();
5583 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
5584 add_symbol_to_list (sym
, &global_symbols
);
5586 child_die
= sibling_die (child_die
);
5591 /* Create a type for a C++ namespace. */
5593 static struct type
*
5594 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5596 struct objfile
*objfile
= cu
->objfile
;
5597 const char *previous_prefix
, *name
;
5601 /* For extensions, reuse the type of the original namespace. */
5602 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5604 struct die_info
*ext_die
;
5605 struct dwarf2_cu
*ext_cu
= cu
;
5606 ext_die
= dwarf2_extension (die
, &ext_cu
);
5607 type
= read_type_die (ext_die
, ext_cu
);
5608 return set_die_type (die
, type
, cu
);
5611 name
= namespace_name (die
, &is_anonymous
, cu
);
5613 /* Now build the name of the current namespace. */
5615 previous_prefix
= determine_prefix (die
, cu
);
5616 if (previous_prefix
[0] != '\0')
5617 name
= typename_concat (&objfile
->objfile_obstack
,
5618 previous_prefix
, name
, cu
);
5620 /* Create the type. */
5621 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5623 TYPE_NAME (type
) = (char *) name
;
5624 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5626 return set_die_type (die
, type
, cu
);
5629 /* Read a C++ namespace. */
5632 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5634 struct objfile
*objfile
= cu
->objfile
;
5638 /* Add a symbol associated to this if we haven't seen the namespace
5639 before. Also, add a using directive if it's an anonymous
5642 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5646 type
= read_type_die (die
, cu
);
5647 new_symbol (die
, type
, cu
);
5649 name
= namespace_name (die
, &is_anonymous
, cu
);
5652 const char *previous_prefix
= determine_prefix (die
, cu
);
5653 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
5654 NULL
, &objfile
->objfile_obstack
);
5658 if (die
->child
!= NULL
)
5660 struct die_info
*child_die
= die
->child
;
5662 while (child_die
&& child_die
->tag
)
5664 process_die (child_die
, cu
);
5665 child_die
= sibling_die (child_die
);
5670 /* Read a Fortran module. */
5673 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5675 struct die_info
*child_die
= die
->child
;
5677 /* FIXME: Support the separate Fortran module namespaces. */
5679 while (child_die
&& child_die
->tag
)
5681 process_die (child_die
, cu
);
5682 child_die
= sibling_die (child_die
);
5686 /* Return the name of the namespace represented by DIE. Set
5687 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5691 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5693 struct die_info
*current_die
;
5694 const char *name
= NULL
;
5696 /* Loop through the extensions until we find a name. */
5698 for (current_die
= die
;
5699 current_die
!= NULL
;
5700 current_die
= dwarf2_extension (die
, &cu
))
5702 name
= dwarf2_name (current_die
, cu
);
5707 /* Is it an anonymous namespace? */
5709 *is_anonymous
= (name
== NULL
);
5711 name
= "(anonymous namespace)";
5716 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5717 the user defined type vector. */
5719 static struct type
*
5720 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5722 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5723 struct comp_unit_head
*cu_header
= &cu
->header
;
5725 struct attribute
*attr_byte_size
;
5726 struct attribute
*attr_address_class
;
5727 int byte_size
, addr_class
;
5729 type
= lookup_pointer_type (die_type (die
, cu
));
5731 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5733 byte_size
= DW_UNSND (attr_byte_size
);
5735 byte_size
= cu_header
->addr_size
;
5737 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5738 if (attr_address_class
)
5739 addr_class
= DW_UNSND (attr_address_class
);
5741 addr_class
= DW_ADDR_none
;
5743 /* If the pointer size or address class is different than the
5744 default, create a type variant marked as such and set the
5745 length accordingly. */
5746 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5748 if (gdbarch_address_class_type_flags_p (gdbarch
))
5752 type_flags
= gdbarch_address_class_type_flags
5753 (gdbarch
, byte_size
, addr_class
);
5754 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5756 type
= make_type_with_address_space (type
, type_flags
);
5758 else if (TYPE_LENGTH (type
) != byte_size
)
5760 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5763 /* Should we also complain about unhandled address classes? */
5767 TYPE_LENGTH (type
) = byte_size
;
5768 return set_die_type (die
, type
, cu
);
5771 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5772 the user defined type vector. */
5774 static struct type
*
5775 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5778 struct type
*to_type
;
5779 struct type
*domain
;
5781 to_type
= die_type (die
, cu
);
5782 domain
= die_containing_type (die
, cu
);
5784 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5785 type
= lookup_methodptr_type (to_type
);
5787 type
= lookup_memberptr_type (to_type
, domain
);
5789 return set_die_type (die
, type
, cu
);
5792 /* Extract all information from a DW_TAG_reference_type DIE and add to
5793 the user defined type vector. */
5795 static struct type
*
5796 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5798 struct comp_unit_head
*cu_header
= &cu
->header
;
5800 struct attribute
*attr
;
5802 type
= lookup_reference_type (die_type (die
, cu
));
5803 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5806 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5810 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5812 return set_die_type (die
, type
, cu
);
5815 static struct type
*
5816 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5818 struct type
*base_type
, *cv_type
;
5820 base_type
= die_type (die
, cu
);
5821 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5822 return set_die_type (die
, cv_type
, cu
);
5825 static struct type
*
5826 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5828 struct type
*base_type
, *cv_type
;
5830 base_type
= die_type (die
, cu
);
5831 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5832 return set_die_type (die
, cv_type
, cu
);
5835 /* Extract all information from a DW_TAG_string_type DIE and add to
5836 the user defined type vector. It isn't really a user defined type,
5837 but it behaves like one, with other DIE's using an AT_user_def_type
5838 attribute to reference it. */
5840 static struct type
*
5841 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5843 struct objfile
*objfile
= cu
->objfile
;
5844 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5845 struct type
*type
, *range_type
, *index_type
, *char_type
;
5846 struct attribute
*attr
;
5847 unsigned int length
;
5849 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5852 length
= DW_UNSND (attr
);
5856 /* check for the DW_AT_byte_size attribute */
5857 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5860 length
= DW_UNSND (attr
);
5868 index_type
= objfile_type (objfile
)->builtin_int
;
5869 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5870 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5871 type
= create_string_type (NULL
, char_type
, range_type
);
5873 return set_die_type (die
, type
, cu
);
5876 /* Handle DIES due to C code like:
5880 int (*funcp)(int a, long l);
5884 ('funcp' generates a DW_TAG_subroutine_type DIE)
5887 static struct type
*
5888 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5890 struct type
*type
; /* Type that this function returns */
5891 struct type
*ftype
; /* Function that returns above type */
5892 struct attribute
*attr
;
5894 type
= die_type (die
, cu
);
5895 ftype
= lookup_function_type (type
);
5897 /* All functions in C++, Pascal and Java have prototypes. */
5898 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5899 if ((attr
&& (DW_UNSND (attr
) != 0))
5900 || cu
->language
== language_cplus
5901 || cu
->language
== language_java
5902 || cu
->language
== language_pascal
)
5903 TYPE_PROTOTYPED (ftype
) = 1;
5904 else if (producer_is_realview (cu
->producer
))
5905 /* RealView does not emit DW_AT_prototyped. We can not
5906 distinguish prototyped and unprototyped functions; default to
5907 prototyped, since that is more common in modern code (and
5908 RealView warns about unprototyped functions). */
5909 TYPE_PROTOTYPED (ftype
) = 1;
5911 /* Store the calling convention in the type if it's available in
5912 the subroutine die. Otherwise set the calling convention to
5913 the default value DW_CC_normal. */
5914 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5915 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5917 /* We need to add the subroutine type to the die immediately so
5918 we don't infinitely recurse when dealing with parameters
5919 declared as the same subroutine type. */
5920 set_die_type (die
, ftype
, cu
);
5922 if (die
->child
!= NULL
)
5924 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
5925 struct die_info
*child_die
;
5926 int nparams
, iparams
;
5928 /* Count the number of parameters.
5929 FIXME: GDB currently ignores vararg functions, but knows about
5930 vararg member functions. */
5932 child_die
= die
->child
;
5933 while (child_die
&& child_die
->tag
)
5935 if (child_die
->tag
== DW_TAG_formal_parameter
)
5937 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5938 TYPE_VARARGS (ftype
) = 1;
5939 child_die
= sibling_die (child_die
);
5942 /* Allocate storage for parameters and fill them in. */
5943 TYPE_NFIELDS (ftype
) = nparams
;
5944 TYPE_FIELDS (ftype
) = (struct field
*)
5945 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5947 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
5948 even if we error out during the parameters reading below. */
5949 for (iparams
= 0; iparams
< nparams
; iparams
++)
5950 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
5953 child_die
= die
->child
;
5954 while (child_die
&& child_die
->tag
)
5956 if (child_die
->tag
== DW_TAG_formal_parameter
)
5958 /* Dwarf2 has no clean way to discern C++ static and non-static
5959 member functions. G++ helps GDB by marking the first
5960 parameter for non-static member functions (which is the
5961 this pointer) as artificial. We pass this information
5962 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5963 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5965 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5968 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5970 /* GCC/43521: In java, the formal parameter
5971 "this" is sometimes not marked with DW_AT_artificial. */
5972 if (cu
->language
== language_java
)
5974 const char *name
= dwarf2_name (child_die
, cu
);
5975 if (name
&& !strcmp (name
, "this"))
5976 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
5979 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5982 child_die
= sibling_die (child_die
);
5989 static struct type
*
5990 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5992 struct objfile
*objfile
= cu
->objfile
;
5993 const char *name
= NULL
;
5994 struct type
*this_type
;
5996 name
= dwarf2_full_name (NULL
, die
, cu
);
5997 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5998 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5999 TYPE_NAME (this_type
) = (char *) name
;
6000 set_die_type (die
, this_type
, cu
);
6001 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
6005 /* Find a representation of a given base type and install
6006 it in the TYPE field of the die. */
6008 static struct type
*
6009 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6011 struct objfile
*objfile
= cu
->objfile
;
6013 struct attribute
*attr
;
6014 int encoding
= 0, size
= 0;
6016 enum type_code code
= TYPE_CODE_INT
;
6018 struct type
*target_type
= NULL
;
6020 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
6023 encoding
= DW_UNSND (attr
);
6025 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6028 size
= DW_UNSND (attr
);
6030 name
= dwarf2_name (die
, cu
);
6033 complaint (&symfile_complaints
,
6034 _("DW_AT_name missing from DW_TAG_base_type"));
6039 case DW_ATE_address
:
6040 /* Turn DW_ATE_address into a void * pointer. */
6041 code
= TYPE_CODE_PTR
;
6042 type_flags
|= TYPE_FLAG_UNSIGNED
;
6043 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
6045 case DW_ATE_boolean
:
6046 code
= TYPE_CODE_BOOL
;
6047 type_flags
|= TYPE_FLAG_UNSIGNED
;
6049 case DW_ATE_complex_float
:
6050 code
= TYPE_CODE_COMPLEX
;
6051 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
6053 case DW_ATE_decimal_float
:
6054 code
= TYPE_CODE_DECFLOAT
;
6057 code
= TYPE_CODE_FLT
;
6061 case DW_ATE_unsigned
:
6062 type_flags
|= TYPE_FLAG_UNSIGNED
;
6064 case DW_ATE_signed_char
:
6065 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6066 || cu
->language
== language_pascal
)
6067 code
= TYPE_CODE_CHAR
;
6069 case DW_ATE_unsigned_char
:
6070 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6071 || cu
->language
== language_pascal
)
6072 code
= TYPE_CODE_CHAR
;
6073 type_flags
|= TYPE_FLAG_UNSIGNED
;
6076 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
6077 dwarf_type_encoding_name (encoding
));
6081 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
6082 TYPE_NAME (type
) = name
;
6083 TYPE_TARGET_TYPE (type
) = target_type
;
6085 if (name
&& strcmp (name
, "char") == 0)
6086 TYPE_NOSIGN (type
) = 1;
6088 return set_die_type (die
, type
, cu
);
6091 /* Read the given DW_AT_subrange DIE. */
6093 static struct type
*
6094 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6096 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6097 struct type
*base_type
;
6098 struct type
*range_type
;
6099 struct attribute
*attr
;
6103 LONGEST negative_mask
;
6105 base_type
= die_type (die
, cu
);
6106 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
6108 complaint (&symfile_complaints
,
6109 _("DW_AT_type missing from DW_TAG_subrange_type"));
6111 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
6112 0, NULL
, cu
->objfile
);
6115 if (cu
->language
== language_fortran
)
6117 /* FORTRAN implies a lower bound of 1, if not given. */
6121 /* FIXME: For variable sized arrays either of these could be
6122 a variable rather than a constant value. We'll allow it,
6123 but we don't know how to handle it. */
6124 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
6126 low
= dwarf2_get_attr_constant_value (attr
, 0);
6128 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
6131 if (attr
->form
== DW_FORM_block1
)
6133 /* GCC encodes arrays with unspecified or dynamic length
6134 with a DW_FORM_block1 attribute.
6135 FIXME: GDB does not yet know how to handle dynamic
6136 arrays properly, treat them as arrays with unspecified
6139 FIXME: jimb/2003-09-22: GDB does not really know
6140 how to handle arrays of unspecified length
6141 either; we just represent them as zero-length
6142 arrays. Choose an appropriate upper bound given
6143 the lower bound we've computed above. */
6147 high
= dwarf2_get_attr_constant_value (attr
, 1);
6151 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
6152 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
6153 low
|= negative_mask
;
6154 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
6155 high
|= negative_mask
;
6157 range_type
= create_range_type (NULL
, base_type
, low
, high
);
6159 /* Mark arrays with dynamic length at least as an array of unspecified
6160 length. GDB could check the boundary but before it gets implemented at
6161 least allow accessing the array elements. */
6162 if (attr
&& attr
->form
== DW_FORM_block1
)
6163 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
6165 name
= dwarf2_name (die
, cu
);
6167 TYPE_NAME (range_type
) = name
;
6169 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6171 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
6173 set_descriptive_type (range_type
, die
, cu
);
6175 return set_die_type (die
, range_type
, cu
);
6178 static struct type
*
6179 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6183 /* For now, we only support the C meaning of an unspecified type: void. */
6185 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
6186 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
6188 return set_die_type (die
, type
, cu
);
6191 /* Trivial hash function for die_info: the hash value of a DIE
6192 is its offset in .debug_info for this objfile. */
6195 die_hash (const void *item
)
6197 const struct die_info
*die
= item
;
6201 /* Trivial comparison function for die_info structures: two DIEs
6202 are equal if they have the same offset. */
6205 die_eq (const void *item_lhs
, const void *item_rhs
)
6207 const struct die_info
*die_lhs
= item_lhs
;
6208 const struct die_info
*die_rhs
= item_rhs
;
6209 return die_lhs
->offset
== die_rhs
->offset
;
6212 /* Read a whole compilation unit into a linked list of dies. */
6214 static struct die_info
*
6215 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6217 struct die_reader_specs reader_specs
;
6219 gdb_assert (cu
->die_hash
== NULL
);
6221 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6225 &cu
->comp_unit_obstack
,
6226 hashtab_obstack_allocate
,
6227 dummy_obstack_deallocate
);
6229 init_cu_die_reader (&reader_specs
, cu
);
6231 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
6234 /* Main entry point for reading a DIE and all children.
6235 Read the DIE and dump it if requested. */
6237 static struct die_info
*
6238 read_die_and_children (const struct die_reader_specs
*reader
,
6240 gdb_byte
**new_info_ptr
,
6241 struct die_info
*parent
)
6243 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
6244 new_info_ptr
, parent
);
6246 if (dwarf2_die_debug
)
6248 fprintf_unfiltered (gdb_stdlog
,
6249 "\nRead die from %s of %s:\n",
6250 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
6252 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
6254 : "unknown section",
6255 reader
->abfd
->filename
);
6256 dump_die (result
, dwarf2_die_debug
);
6262 /* Read a single die and all its descendents. Set the die's sibling
6263 field to NULL; set other fields in the die correctly, and set all
6264 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6265 location of the info_ptr after reading all of those dies. PARENT
6266 is the parent of the die in question. */
6268 static struct die_info
*
6269 read_die_and_children_1 (const struct die_reader_specs
*reader
,
6271 gdb_byte
**new_info_ptr
,
6272 struct die_info
*parent
)
6274 struct die_info
*die
;
6278 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
6281 *new_info_ptr
= cur_ptr
;
6284 store_in_ref_table (die
, reader
->cu
);
6287 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
6291 *new_info_ptr
= cur_ptr
;
6294 die
->sibling
= NULL
;
6295 die
->parent
= parent
;
6299 /* Read a die, all of its descendents, and all of its siblings; set
6300 all of the fields of all of the dies correctly. Arguments are as
6301 in read_die_and_children. */
6303 static struct die_info
*
6304 read_die_and_siblings (const struct die_reader_specs
*reader
,
6306 gdb_byte
**new_info_ptr
,
6307 struct die_info
*parent
)
6309 struct die_info
*first_die
, *last_sibling
;
6313 first_die
= last_sibling
= NULL
;
6317 struct die_info
*die
6318 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
6322 *new_info_ptr
= cur_ptr
;
6329 last_sibling
->sibling
= die
;
6335 /* Read the die from the .debug_info section buffer. Set DIEP to
6336 point to a newly allocated die with its information, except for its
6337 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6338 whether the die has children or not. */
6341 read_full_die (const struct die_reader_specs
*reader
,
6342 struct die_info
**diep
, gdb_byte
*info_ptr
,
6345 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6346 struct abbrev_info
*abbrev
;
6347 struct die_info
*die
;
6348 struct dwarf2_cu
*cu
= reader
->cu
;
6349 bfd
*abfd
= reader
->abfd
;
6351 offset
= info_ptr
- reader
->buffer
;
6352 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6353 info_ptr
+= bytes_read
;
6361 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6363 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6365 bfd_get_filename (abfd
));
6367 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6368 die
->offset
= offset
;
6369 die
->tag
= abbrev
->tag
;
6370 die
->abbrev
= abbrev_number
;
6372 die
->num_attrs
= abbrev
->num_attrs
;
6374 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6375 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6376 abfd
, info_ptr
, cu
);
6379 *has_children
= abbrev
->has_children
;
6383 /* In DWARF version 2, the description of the debugging information is
6384 stored in a separate .debug_abbrev section. Before we read any
6385 dies from a section we read in all abbreviations and install them
6386 in a hash table. This function also sets flags in CU describing
6387 the data found in the abbrev table. */
6390 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
6392 struct comp_unit_head
*cu_header
= &cu
->header
;
6393 gdb_byte
*abbrev_ptr
;
6394 struct abbrev_info
*cur_abbrev
;
6395 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
6396 unsigned int abbrev_form
, hash_number
;
6397 struct attr_abbrev
*cur_attrs
;
6398 unsigned int allocated_attrs
;
6400 /* Initialize dwarf2 abbrevs */
6401 obstack_init (&cu
->abbrev_obstack
);
6402 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
6404 * sizeof (struct abbrev_info
*)));
6405 memset (cu
->dwarf2_abbrevs
, 0,
6406 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
6408 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
6409 &dwarf2_per_objfile
->abbrev
);
6410 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
6411 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6412 abbrev_ptr
+= bytes_read
;
6414 allocated_attrs
= ATTR_ALLOC_CHUNK
;
6415 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
6417 /* loop until we reach an abbrev number of 0 */
6418 while (abbrev_number
)
6420 cur_abbrev
= dwarf_alloc_abbrev (cu
);
6422 /* read in abbrev header */
6423 cur_abbrev
->number
= abbrev_number
;
6424 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6425 abbrev_ptr
+= bytes_read
;
6426 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
6429 if (cur_abbrev
->tag
== DW_TAG_namespace
)
6430 cu
->has_namespace_info
= 1;
6432 /* now read in declarations */
6433 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6434 abbrev_ptr
+= bytes_read
;
6435 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6436 abbrev_ptr
+= bytes_read
;
6439 if (cur_abbrev
->num_attrs
== allocated_attrs
)
6441 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
6443 = xrealloc (cur_attrs
, (allocated_attrs
6444 * sizeof (struct attr_abbrev
)));
6447 /* Record whether this compilation unit might have
6448 inter-compilation-unit references. If we don't know what form
6449 this attribute will have, then it might potentially be a
6450 DW_FORM_ref_addr, so we conservatively expect inter-CU
6453 if (abbrev_form
== DW_FORM_ref_addr
6454 || abbrev_form
== DW_FORM_indirect
)
6455 cu
->has_form_ref_addr
= 1;
6457 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
6458 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
6459 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6460 abbrev_ptr
+= bytes_read
;
6461 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6462 abbrev_ptr
+= bytes_read
;
6465 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
6466 (cur_abbrev
->num_attrs
6467 * sizeof (struct attr_abbrev
)));
6468 memcpy (cur_abbrev
->attrs
, cur_attrs
,
6469 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
6471 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
6472 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
6473 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
6475 /* Get next abbreviation.
6476 Under Irix6 the abbreviations for a compilation unit are not
6477 always properly terminated with an abbrev number of 0.
6478 Exit loop if we encounter an abbreviation which we have
6479 already read (which means we are about to read the abbreviations
6480 for the next compile unit) or if the end of the abbreviation
6481 table is reached. */
6482 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
6483 >= dwarf2_per_objfile
->abbrev
.size
)
6485 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6486 abbrev_ptr
+= bytes_read
;
6487 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
6494 /* Release the memory used by the abbrev table for a compilation unit. */
6497 dwarf2_free_abbrev_table (void *ptr_to_cu
)
6499 struct dwarf2_cu
*cu
= ptr_to_cu
;
6501 obstack_free (&cu
->abbrev_obstack
, NULL
);
6502 cu
->dwarf2_abbrevs
= NULL
;
6505 /* Lookup an abbrev_info structure in the abbrev hash table. */
6507 static struct abbrev_info
*
6508 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
6510 unsigned int hash_number
;
6511 struct abbrev_info
*abbrev
;
6513 hash_number
= number
% ABBREV_HASH_SIZE
;
6514 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
6518 if (abbrev
->number
== number
)
6521 abbrev
= abbrev
->next
;
6526 /* Returns nonzero if TAG represents a type that we might generate a partial
6530 is_type_tag_for_partial (int tag
)
6535 /* Some types that would be reasonable to generate partial symbols for,
6536 that we don't at present. */
6537 case DW_TAG_array_type
:
6538 case DW_TAG_file_type
:
6539 case DW_TAG_ptr_to_member_type
:
6540 case DW_TAG_set_type
:
6541 case DW_TAG_string_type
:
6542 case DW_TAG_subroutine_type
:
6544 case DW_TAG_base_type
:
6545 case DW_TAG_class_type
:
6546 case DW_TAG_interface_type
:
6547 case DW_TAG_enumeration_type
:
6548 case DW_TAG_structure_type
:
6549 case DW_TAG_subrange_type
:
6550 case DW_TAG_typedef
:
6551 case DW_TAG_union_type
:
6558 /* Load all DIEs that are interesting for partial symbols into memory. */
6560 static struct partial_die_info
*
6561 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6562 int building_psymtab
, struct dwarf2_cu
*cu
)
6564 struct partial_die_info
*part_die
;
6565 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
6566 struct abbrev_info
*abbrev
;
6567 unsigned int bytes_read
;
6568 unsigned int load_all
= 0;
6570 int nesting_level
= 1;
6575 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
6579 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6583 &cu
->comp_unit_obstack
,
6584 hashtab_obstack_allocate
,
6585 dummy_obstack_deallocate
);
6587 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6588 sizeof (struct partial_die_info
));
6592 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6594 /* A NULL abbrev means the end of a series of children. */
6597 if (--nesting_level
== 0)
6599 /* PART_DIE was probably the last thing allocated on the
6600 comp_unit_obstack, so we could call obstack_free
6601 here. We don't do that because the waste is small,
6602 and will be cleaned up when we're done with this
6603 compilation unit. This way, we're also more robust
6604 against other users of the comp_unit_obstack. */
6607 info_ptr
+= bytes_read
;
6608 last_die
= parent_die
;
6609 parent_die
= parent_die
->die_parent
;
6613 /* Check whether this DIE is interesting enough to save. Normally
6614 we would not be interested in members here, but there may be
6615 later variables referencing them via DW_AT_specification (for
6618 && !is_type_tag_for_partial (abbrev
->tag
)
6619 && abbrev
->tag
!= DW_TAG_enumerator
6620 && abbrev
->tag
!= DW_TAG_subprogram
6621 && abbrev
->tag
!= DW_TAG_lexical_block
6622 && abbrev
->tag
!= DW_TAG_variable
6623 && abbrev
->tag
!= DW_TAG_namespace
6624 && abbrev
->tag
!= DW_TAG_member
)
6626 /* Otherwise we skip to the next sibling, if any. */
6627 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
6631 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
6632 buffer
, info_ptr
, cu
);
6634 /* This two-pass algorithm for processing partial symbols has a
6635 high cost in cache pressure. Thus, handle some simple cases
6636 here which cover the majority of C partial symbols. DIEs
6637 which neither have specification tags in them, nor could have
6638 specification tags elsewhere pointing at them, can simply be
6639 processed and discarded.
6641 This segment is also optional; scan_partial_symbols and
6642 add_partial_symbol will handle these DIEs if we chain
6643 them in normally. When compilers which do not emit large
6644 quantities of duplicate debug information are more common,
6645 this code can probably be removed. */
6647 /* Any complete simple types at the top level (pretty much all
6648 of them, for a language without namespaces), can be processed
6650 if (parent_die
== NULL
6651 && part_die
->has_specification
== 0
6652 && part_die
->is_declaration
== 0
6653 && (part_die
->tag
== DW_TAG_typedef
6654 || part_die
->tag
== DW_TAG_base_type
6655 || part_die
->tag
== DW_TAG_subrange_type
))
6657 if (building_psymtab
&& part_die
->name
!= NULL
)
6658 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6659 VAR_DOMAIN
, LOC_TYPEDEF
,
6660 &cu
->objfile
->static_psymbols
,
6661 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6662 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6666 /* If we're at the second level, and we're an enumerator, and
6667 our parent has no specification (meaning possibly lives in a
6668 namespace elsewhere), then we can add the partial symbol now
6669 instead of queueing it. */
6670 if (part_die
->tag
== DW_TAG_enumerator
6671 && parent_die
!= NULL
6672 && parent_die
->die_parent
== NULL
6673 && parent_die
->tag
== DW_TAG_enumeration_type
6674 && parent_die
->has_specification
== 0)
6676 if (part_die
->name
== NULL
)
6677 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6678 else if (building_psymtab
)
6679 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6680 VAR_DOMAIN
, LOC_CONST
,
6681 (cu
->language
== language_cplus
6682 || cu
->language
== language_java
)
6683 ? &cu
->objfile
->global_psymbols
6684 : &cu
->objfile
->static_psymbols
,
6685 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6687 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6691 /* We'll save this DIE so link it in. */
6692 part_die
->die_parent
= parent_die
;
6693 part_die
->die_sibling
= NULL
;
6694 part_die
->die_child
= NULL
;
6696 if (last_die
&& last_die
== parent_die
)
6697 last_die
->die_child
= part_die
;
6699 last_die
->die_sibling
= part_die
;
6701 last_die
= part_die
;
6703 if (first_die
== NULL
)
6704 first_die
= part_die
;
6706 /* Maybe add the DIE to the hash table. Not all DIEs that we
6707 find interesting need to be in the hash table, because we
6708 also have the parent/sibling/child chains; only those that we
6709 might refer to by offset later during partial symbol reading.
6711 For now this means things that might have be the target of a
6712 DW_AT_specification, DW_AT_abstract_origin, or
6713 DW_AT_extension. DW_AT_extension will refer only to
6714 namespaces; DW_AT_abstract_origin refers to functions (and
6715 many things under the function DIE, but we do not recurse
6716 into function DIEs during partial symbol reading) and
6717 possibly variables as well; DW_AT_specification refers to
6718 declarations. Declarations ought to have the DW_AT_declaration
6719 flag. It happens that GCC forgets to put it in sometimes, but
6720 only for functions, not for types.
6722 Adding more things than necessary to the hash table is harmless
6723 except for the performance cost. Adding too few will result in
6724 wasted time in find_partial_die, when we reread the compilation
6725 unit with load_all_dies set. */
6728 || abbrev
->tag
== DW_TAG_subprogram
6729 || abbrev
->tag
== DW_TAG_variable
6730 || abbrev
->tag
== DW_TAG_namespace
6731 || part_die
->is_declaration
)
6735 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6736 part_die
->offset
, INSERT
);
6740 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6741 sizeof (struct partial_die_info
));
6743 /* For some DIEs we want to follow their children (if any). For C
6744 we have no reason to follow the children of structures; for other
6745 languages we have to, both so that we can get at method physnames
6746 to infer fully qualified class names, and for DW_AT_specification.
6748 For Ada, we need to scan the children of subprograms and lexical
6749 blocks as well because Ada allows the definition of nested
6750 entities that could be interesting for the debugger, such as
6751 nested subprograms for instance. */
6752 if (last_die
->has_children
6754 || last_die
->tag
== DW_TAG_namespace
6755 || last_die
->tag
== DW_TAG_enumeration_type
6756 || (cu
->language
!= language_c
6757 && (last_die
->tag
== DW_TAG_class_type
6758 || last_die
->tag
== DW_TAG_interface_type
6759 || last_die
->tag
== DW_TAG_structure_type
6760 || last_die
->tag
== DW_TAG_union_type
))
6761 || (cu
->language
== language_ada
6762 && (last_die
->tag
== DW_TAG_subprogram
6763 || last_die
->tag
== DW_TAG_lexical_block
))))
6766 parent_die
= last_die
;
6770 /* Otherwise we skip to the next sibling, if any. */
6771 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
6773 /* Back to the top, do it again. */
6777 /* Read a minimal amount of information into the minimal die structure. */
6780 read_partial_die (struct partial_die_info
*part_die
,
6781 struct abbrev_info
*abbrev
,
6782 unsigned int abbrev_len
, bfd
*abfd
,
6783 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6784 struct dwarf2_cu
*cu
)
6787 struct attribute attr
;
6788 int has_low_pc_attr
= 0;
6789 int has_high_pc_attr
= 0;
6791 memset (part_die
, 0, sizeof (struct partial_die_info
));
6793 part_die
->offset
= info_ptr
- buffer
;
6795 info_ptr
+= abbrev_len
;
6800 part_die
->tag
= abbrev
->tag
;
6801 part_die
->has_children
= abbrev
->has_children
;
6803 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6805 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6807 /* Store the data if it is of an attribute we want to keep in a
6808 partial symbol table. */
6812 switch (part_die
->tag
)
6814 case DW_TAG_compile_unit
:
6815 case DW_TAG_type_unit
:
6816 /* Compilation units have a DW_AT_name that is a filename, not
6817 a source language identifier. */
6818 case DW_TAG_enumeration_type
:
6819 case DW_TAG_enumerator
:
6820 /* These tags always have simple identifiers already; no need
6821 to canonicalize them. */
6822 part_die
->name
= DW_STRING (&attr
);
6826 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6827 &cu
->objfile
->objfile_obstack
);
6831 case DW_AT_linkage_name
:
6832 case DW_AT_MIPS_linkage_name
:
6833 /* Note that both forms of linkage name might appear. We
6834 assume they will be the same, and we only store the last
6836 if (cu
->language
== language_ada
)
6837 part_die
->name
= DW_STRING (&attr
);
6840 has_low_pc_attr
= 1;
6841 part_die
->lowpc
= DW_ADDR (&attr
);
6844 has_high_pc_attr
= 1;
6845 part_die
->highpc
= DW_ADDR (&attr
);
6847 case DW_AT_location
:
6848 /* Support the .debug_loc offsets */
6849 if (attr_form_is_block (&attr
))
6851 part_die
->locdesc
= DW_BLOCK (&attr
);
6853 else if (attr_form_is_section_offset (&attr
))
6855 dwarf2_complex_location_expr_complaint ();
6859 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6860 "partial symbol information");
6863 case DW_AT_external
:
6864 part_die
->is_external
= DW_UNSND (&attr
);
6866 case DW_AT_declaration
:
6867 part_die
->is_declaration
= DW_UNSND (&attr
);
6870 part_die
->has_type
= 1;
6872 case DW_AT_abstract_origin
:
6873 case DW_AT_specification
:
6874 case DW_AT_extension
:
6875 part_die
->has_specification
= 1;
6876 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6879 /* Ignore absolute siblings, they might point outside of
6880 the current compile unit. */
6881 if (attr
.form
== DW_FORM_ref_addr
)
6882 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6884 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
6886 case DW_AT_byte_size
:
6887 part_die
->has_byte_size
= 1;
6889 case DW_AT_calling_convention
:
6890 /* DWARF doesn't provide a way to identify a program's source-level
6891 entry point. DW_AT_calling_convention attributes are only meant
6892 to describe functions' calling conventions.
6894 However, because it's a necessary piece of information in
6895 Fortran, and because DW_CC_program is the only piece of debugging
6896 information whose definition refers to a 'main program' at all,
6897 several compilers have begun marking Fortran main programs with
6898 DW_CC_program --- even when those functions use the standard
6899 calling conventions.
6901 So until DWARF specifies a way to provide this information and
6902 compilers pick up the new representation, we'll support this
6904 if (DW_UNSND (&attr
) == DW_CC_program
6905 && cu
->language
== language_fortran
)
6906 set_main_name (part_die
->name
);
6913 /* When using the GNU linker, .gnu.linkonce. sections are used to
6914 eliminate duplicate copies of functions and vtables and such.
6915 The linker will arbitrarily choose one and discard the others.
6916 The AT_*_pc values for such functions refer to local labels in
6917 these sections. If the section from that file was discarded, the
6918 labels are not in the output, so the relocs get a value of 0.
6919 If this is a discarded function, mark the pc bounds as invalid,
6920 so that GDB will ignore it. */
6921 if (has_low_pc_attr
&& has_high_pc_attr
6922 && part_die
->lowpc
< part_die
->highpc
6923 && (part_die
->lowpc
!= 0
6924 || dwarf2_per_objfile
->has_section_at_zero
))
6925 part_die
->has_pc_info
= 1;
6930 /* Find a cached partial DIE at OFFSET in CU. */
6932 static struct partial_die_info
*
6933 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6935 struct partial_die_info
*lookup_die
= NULL
;
6936 struct partial_die_info part_die
;
6938 part_die
.offset
= offset
;
6939 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6944 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6945 except in the case of .debug_types DIEs which do not reference
6946 outside their CU (they do however referencing other types via
6949 static struct partial_die_info
*
6950 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6952 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6953 struct partial_die_info
*pd
= NULL
;
6955 if (cu
->per_cu
->from_debug_types
)
6957 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6963 if (offset_in_cu_p (&cu
->header
, offset
))
6965 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6970 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6972 if (per_cu
->cu
== NULL
)
6974 load_partial_comp_unit (per_cu
, cu
->objfile
);
6975 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6976 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6979 per_cu
->cu
->last_used
= 0;
6980 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6982 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6984 struct cleanup
*back_to
;
6985 struct partial_die_info comp_unit_die
;
6986 struct abbrev_info
*abbrev
;
6987 unsigned int bytes_read
;
6990 per_cu
->load_all_dies
= 1;
6992 /* Re-read the DIEs. */
6993 back_to
= make_cleanup (null_cleanup
, 0);
6994 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6996 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6997 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6999 info_ptr
= (dwarf2_per_objfile
->info
.buffer
7000 + per_cu
->cu
->header
.offset
7001 + per_cu
->cu
->header
.first_die_offset
);
7002 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
7003 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
7004 per_cu
->cu
->objfile
->obfd
,
7005 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
7007 if (comp_unit_die
.has_children
)
7008 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
7009 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
7011 do_cleanups (back_to
);
7013 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
7019 internal_error (__FILE__
, __LINE__
,
7020 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
7021 offset
, bfd_get_filename (cu
->objfile
->obfd
));
7025 /* Adjust PART_DIE before generating a symbol for it. This function
7026 may set the is_external flag or change the DIE's name. */
7029 fixup_partial_die (struct partial_die_info
*part_die
,
7030 struct dwarf2_cu
*cu
)
7032 /* If we found a reference attribute and the DIE has no name, try
7033 to find a name in the referred to DIE. */
7035 if (part_die
->name
== NULL
&& part_die
->has_specification
)
7037 struct partial_die_info
*spec_die
;
7039 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
7041 fixup_partial_die (spec_die
, cu
);
7045 part_die
->name
= spec_die
->name
;
7047 /* Copy DW_AT_external attribute if it is set. */
7048 if (spec_die
->is_external
)
7049 part_die
->is_external
= spec_die
->is_external
;
7053 /* Set default names for some unnamed DIEs. */
7054 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
7055 || part_die
->tag
== DW_TAG_class_type
))
7056 part_die
->name
= "(anonymous class)";
7058 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
7059 part_die
->name
= "(anonymous namespace)";
7061 if (part_die
->tag
== DW_TAG_structure_type
7062 || part_die
->tag
== DW_TAG_class_type
7063 || part_die
->tag
== DW_TAG_union_type
)
7064 guess_structure_name (part_die
, cu
);
7067 /* Read an attribute value described by an attribute form. */
7070 read_attribute_value (struct attribute
*attr
, unsigned form
,
7071 bfd
*abfd
, gdb_byte
*info_ptr
,
7072 struct dwarf2_cu
*cu
)
7074 struct comp_unit_head
*cu_header
= &cu
->header
;
7075 unsigned int bytes_read
;
7076 struct dwarf_block
*blk
;
7081 case DW_FORM_ref_addr
:
7082 if (cu
->header
.version
== 2)
7083 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7085 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
7086 info_ptr
+= bytes_read
;
7089 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7090 info_ptr
+= bytes_read
;
7092 case DW_FORM_block2
:
7093 blk
= dwarf_alloc_block (cu
);
7094 blk
->size
= read_2_bytes (abfd
, info_ptr
);
7096 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7097 info_ptr
+= blk
->size
;
7098 DW_BLOCK (attr
) = blk
;
7100 case DW_FORM_block4
:
7101 blk
= dwarf_alloc_block (cu
);
7102 blk
->size
= read_4_bytes (abfd
, info_ptr
);
7104 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7105 info_ptr
+= blk
->size
;
7106 DW_BLOCK (attr
) = blk
;
7109 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
7113 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
7117 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
7120 case DW_FORM_sec_offset
:
7121 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
7122 info_ptr
+= bytes_read
;
7124 case DW_FORM_string
:
7125 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
7126 DW_STRING_IS_CANONICAL (attr
) = 0;
7127 info_ptr
+= bytes_read
;
7130 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
7132 DW_STRING_IS_CANONICAL (attr
) = 0;
7133 info_ptr
+= bytes_read
;
7135 case DW_FORM_exprloc
:
7137 blk
= dwarf_alloc_block (cu
);
7138 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7139 info_ptr
+= bytes_read
;
7140 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7141 info_ptr
+= blk
->size
;
7142 DW_BLOCK (attr
) = blk
;
7144 case DW_FORM_block1
:
7145 blk
= dwarf_alloc_block (cu
);
7146 blk
->size
= read_1_byte (abfd
, info_ptr
);
7148 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7149 info_ptr
+= blk
->size
;
7150 DW_BLOCK (attr
) = blk
;
7153 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7157 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7160 case DW_FORM_flag_present
:
7161 DW_UNSND (attr
) = 1;
7164 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
7165 info_ptr
+= bytes_read
;
7168 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7169 info_ptr
+= bytes_read
;
7172 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
7176 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
7180 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
7184 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
7188 /* Convert the signature to something we can record in DW_UNSND
7190 NOTE: This is NULL if the type wasn't found. */
7191 DW_SIGNATURED_TYPE (attr
) =
7192 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
7195 case DW_FORM_ref_udata
:
7196 DW_ADDR (attr
) = (cu
->header
.offset
7197 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
7198 info_ptr
+= bytes_read
;
7200 case DW_FORM_indirect
:
7201 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7202 info_ptr
+= bytes_read
;
7203 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
7206 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7207 dwarf_form_name (form
),
7208 bfd_get_filename (abfd
));
7211 /* We have seen instances where the compiler tried to emit a byte
7212 size attribute of -1 which ended up being encoded as an unsigned
7213 0xffffffff. Although 0xffffffff is technically a valid size value,
7214 an object of this size seems pretty unlikely so we can relatively
7215 safely treat these cases as if the size attribute was invalid and
7216 treat them as zero by default. */
7217 if (attr
->name
== DW_AT_byte_size
7218 && form
== DW_FORM_data4
7219 && DW_UNSND (attr
) >= 0xffffffff)
7222 (&symfile_complaints
,
7223 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7224 hex_string (DW_UNSND (attr
)));
7225 DW_UNSND (attr
) = 0;
7231 /* Read an attribute described by an abbreviated attribute. */
7234 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
7235 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7237 attr
->name
= abbrev
->name
;
7238 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
7241 /* read dwarf information from a buffer */
7244 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
7246 return bfd_get_8 (abfd
, buf
);
7250 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
7252 return bfd_get_signed_8 (abfd
, buf
);
7256 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
7258 return bfd_get_16 (abfd
, buf
);
7262 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7264 return bfd_get_signed_16 (abfd
, buf
);
7268 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
7270 return bfd_get_32 (abfd
, buf
);
7274 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7276 return bfd_get_signed_32 (abfd
, buf
);
7280 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
7282 return bfd_get_64 (abfd
, buf
);
7286 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
7287 unsigned int *bytes_read
)
7289 struct comp_unit_head
*cu_header
= &cu
->header
;
7290 CORE_ADDR retval
= 0;
7292 if (cu_header
->signed_addr_p
)
7294 switch (cu_header
->addr_size
)
7297 retval
= bfd_get_signed_16 (abfd
, buf
);
7300 retval
= bfd_get_signed_32 (abfd
, buf
);
7303 retval
= bfd_get_signed_64 (abfd
, buf
);
7306 internal_error (__FILE__
, __LINE__
,
7307 _("read_address: bad switch, signed [in module %s]"),
7308 bfd_get_filename (abfd
));
7313 switch (cu_header
->addr_size
)
7316 retval
= bfd_get_16 (abfd
, buf
);
7319 retval
= bfd_get_32 (abfd
, buf
);
7322 retval
= bfd_get_64 (abfd
, buf
);
7325 internal_error (__FILE__
, __LINE__
,
7326 _("read_address: bad switch, unsigned [in module %s]"),
7327 bfd_get_filename (abfd
));
7331 *bytes_read
= cu_header
->addr_size
;
7335 /* Read the initial length from a section. The (draft) DWARF 3
7336 specification allows the initial length to take up either 4 bytes
7337 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7338 bytes describe the length and all offsets will be 8 bytes in length
7341 An older, non-standard 64-bit format is also handled by this
7342 function. The older format in question stores the initial length
7343 as an 8-byte quantity without an escape value. Lengths greater
7344 than 2^32 aren't very common which means that the initial 4 bytes
7345 is almost always zero. Since a length value of zero doesn't make
7346 sense for the 32-bit format, this initial zero can be considered to
7347 be an escape value which indicates the presence of the older 64-bit
7348 format. As written, the code can't detect (old format) lengths
7349 greater than 4GB. If it becomes necessary to handle lengths
7350 somewhat larger than 4GB, we could allow other small values (such
7351 as the non-sensical values of 1, 2, and 3) to also be used as
7352 escape values indicating the presence of the old format.
7354 The value returned via bytes_read should be used to increment the
7355 relevant pointer after calling read_initial_length().
7357 [ Note: read_initial_length() and read_offset() are based on the
7358 document entitled "DWARF Debugging Information Format", revision
7359 3, draft 8, dated November 19, 2001. This document was obtained
7362 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7364 This document is only a draft and is subject to change. (So beware.)
7366 Details regarding the older, non-standard 64-bit format were
7367 determined empirically by examining 64-bit ELF files produced by
7368 the SGI toolchain on an IRIX 6.5 machine.
7370 - Kevin, July 16, 2002
7374 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
7376 LONGEST length
= bfd_get_32 (abfd
, buf
);
7378 if (length
== 0xffffffff)
7380 length
= bfd_get_64 (abfd
, buf
+ 4);
7383 else if (length
== 0)
7385 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7386 length
= bfd_get_64 (abfd
, buf
);
7397 /* Cover function for read_initial_length.
7398 Returns the length of the object at BUF, and stores the size of the
7399 initial length in *BYTES_READ and stores the size that offsets will be in
7401 If the initial length size is not equivalent to that specified in
7402 CU_HEADER then issue a complaint.
7403 This is useful when reading non-comp-unit headers. */
7406 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
7407 const struct comp_unit_head
*cu_header
,
7408 unsigned int *bytes_read
,
7409 unsigned int *offset_size
)
7411 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
7413 gdb_assert (cu_header
->initial_length_size
== 4
7414 || cu_header
->initial_length_size
== 8
7415 || cu_header
->initial_length_size
== 12);
7417 if (cu_header
->initial_length_size
!= *bytes_read
)
7418 complaint (&symfile_complaints
,
7419 _("intermixed 32-bit and 64-bit DWARF sections"));
7421 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
7425 /* Read an offset from the data stream. The size of the offset is
7426 given by cu_header->offset_size. */
7429 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
7430 unsigned int *bytes_read
)
7432 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
7433 *bytes_read
= cu_header
->offset_size
;
7437 /* Read an offset from the data stream. */
7440 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
7444 switch (offset_size
)
7447 retval
= bfd_get_32 (abfd
, buf
);
7450 retval
= bfd_get_64 (abfd
, buf
);
7453 internal_error (__FILE__
, __LINE__
,
7454 _("read_offset_1: bad switch [in module %s]"),
7455 bfd_get_filename (abfd
));
7462 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
7464 /* If the size of a host char is 8 bits, we can return a pointer
7465 to the buffer, otherwise we have to copy the data to a buffer
7466 allocated on the temporary obstack. */
7467 gdb_assert (HOST_CHAR_BIT
== 8);
7472 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7474 /* If the size of a host char is 8 bits, we can return a pointer
7475 to the string, otherwise we have to copy the string to a buffer
7476 allocated on the temporary obstack. */
7477 gdb_assert (HOST_CHAR_BIT
== 8);
7480 *bytes_read_ptr
= 1;
7483 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
7484 return (char *) buf
;
7488 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
7489 const struct comp_unit_head
*cu_header
,
7490 unsigned int *bytes_read_ptr
)
7492 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
7494 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
7495 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
7497 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7498 bfd_get_filename (abfd
));
7501 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
7503 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7504 bfd_get_filename (abfd
));
7507 gdb_assert (HOST_CHAR_BIT
== 8);
7508 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
7510 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
7513 static unsigned long
7514 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7516 unsigned long result
;
7517 unsigned int num_read
;
7527 byte
= bfd_get_8 (abfd
, buf
);
7530 result
|= ((unsigned long)(byte
& 127) << shift
);
7531 if ((byte
& 128) == 0)
7537 *bytes_read_ptr
= num_read
;
7542 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7545 int i
, shift
, num_read
;
7554 byte
= bfd_get_8 (abfd
, buf
);
7557 result
|= ((long)(byte
& 127) << shift
);
7559 if ((byte
& 128) == 0)
7564 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
7565 result
|= -(((long)1) << shift
);
7566 *bytes_read_ptr
= num_read
;
7570 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7573 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
7579 byte
= bfd_get_8 (abfd
, buf
);
7581 if ((byte
& 128) == 0)
7587 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
7594 cu
->language
= language_c
;
7596 case DW_LANG_C_plus_plus
:
7597 cu
->language
= language_cplus
;
7600 cu
->language
= language_d
;
7602 case DW_LANG_Fortran77
:
7603 case DW_LANG_Fortran90
:
7604 case DW_LANG_Fortran95
:
7605 cu
->language
= language_fortran
;
7607 case DW_LANG_Mips_Assembler
:
7608 cu
->language
= language_asm
;
7611 cu
->language
= language_java
;
7615 cu
->language
= language_ada
;
7617 case DW_LANG_Modula2
:
7618 cu
->language
= language_m2
;
7620 case DW_LANG_Pascal83
:
7621 cu
->language
= language_pascal
;
7624 cu
->language
= language_objc
;
7626 case DW_LANG_Cobol74
:
7627 case DW_LANG_Cobol85
:
7629 cu
->language
= language_minimal
;
7632 cu
->language_defn
= language_def (cu
->language
);
7635 /* Return the named attribute or NULL if not there. */
7637 static struct attribute
*
7638 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
7641 struct attribute
*spec
= NULL
;
7643 for (i
= 0; i
< die
->num_attrs
; ++i
)
7645 if (die
->attrs
[i
].name
== name
)
7646 return &die
->attrs
[i
];
7647 if (die
->attrs
[i
].name
== DW_AT_specification
7648 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
7649 spec
= &die
->attrs
[i
];
7654 die
= follow_die_ref (die
, spec
, &cu
);
7655 return dwarf2_attr (die
, name
, cu
);
7661 /* Return the named attribute or NULL if not there,
7662 but do not follow DW_AT_specification, etc.
7663 This is for use in contexts where we're reading .debug_types dies.
7664 Following DW_AT_specification, DW_AT_abstract_origin will take us
7665 back up the chain, and we want to go down. */
7667 static struct attribute
*
7668 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
7669 struct dwarf2_cu
*cu
)
7673 for (i
= 0; i
< die
->num_attrs
; ++i
)
7674 if (die
->attrs
[i
].name
== name
)
7675 return &die
->attrs
[i
];
7680 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7681 and holds a non-zero value. This function should only be used for
7682 DW_FORM_flag or DW_FORM_flag_present attributes. */
7685 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7687 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7689 return (attr
&& DW_UNSND (attr
));
7693 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7695 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7696 which value is non-zero. However, we have to be careful with
7697 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7698 (via dwarf2_flag_true_p) follows this attribute. So we may
7699 end up accidently finding a declaration attribute that belongs
7700 to a different DIE referenced by the specification attribute,
7701 even though the given DIE does not have a declaration attribute. */
7702 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7703 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7706 /* Return the die giving the specification for DIE, if there is
7707 one. *SPEC_CU is the CU containing DIE on input, and the CU
7708 containing the return value on output. If there is no
7709 specification, but there is an abstract origin, that is
7712 static struct die_info
*
7713 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7715 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7718 if (spec_attr
== NULL
)
7719 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7721 if (spec_attr
== NULL
)
7724 return follow_die_ref (die
, spec_attr
, spec_cu
);
7727 /* Free the line_header structure *LH, and any arrays and strings it
7730 free_line_header (struct line_header
*lh
)
7732 if (lh
->standard_opcode_lengths
)
7733 xfree (lh
->standard_opcode_lengths
);
7735 /* Remember that all the lh->file_names[i].name pointers are
7736 pointers into debug_line_buffer, and don't need to be freed. */
7738 xfree (lh
->file_names
);
7740 /* Similarly for the include directory names. */
7741 if (lh
->include_dirs
)
7742 xfree (lh
->include_dirs
);
7748 /* Add an entry to LH's include directory table. */
7750 add_include_dir (struct line_header
*lh
, char *include_dir
)
7752 /* Grow the array if necessary. */
7753 if (lh
->include_dirs_size
== 0)
7755 lh
->include_dirs_size
= 1; /* for testing */
7756 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7757 * sizeof (*lh
->include_dirs
));
7759 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7761 lh
->include_dirs_size
*= 2;
7762 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7763 (lh
->include_dirs_size
7764 * sizeof (*lh
->include_dirs
)));
7767 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7771 /* Add an entry to LH's file name table. */
7773 add_file_name (struct line_header
*lh
,
7775 unsigned int dir_index
,
7776 unsigned int mod_time
,
7777 unsigned int length
)
7779 struct file_entry
*fe
;
7781 /* Grow the array if necessary. */
7782 if (lh
->file_names_size
== 0)
7784 lh
->file_names_size
= 1; /* for testing */
7785 lh
->file_names
= xmalloc (lh
->file_names_size
7786 * sizeof (*lh
->file_names
));
7788 else if (lh
->num_file_names
>= lh
->file_names_size
)
7790 lh
->file_names_size
*= 2;
7791 lh
->file_names
= xrealloc (lh
->file_names
,
7792 (lh
->file_names_size
7793 * sizeof (*lh
->file_names
)));
7796 fe
= &lh
->file_names
[lh
->num_file_names
++];
7798 fe
->dir_index
= dir_index
;
7799 fe
->mod_time
= mod_time
;
7800 fe
->length
= length
;
7806 /* Read the statement program header starting at OFFSET in
7807 .debug_line, according to the endianness of ABFD. Return a pointer
7808 to a struct line_header, allocated using xmalloc.
7810 NOTE: the strings in the include directory and file name tables of
7811 the returned object point into debug_line_buffer, and must not be
7813 static struct line_header
*
7814 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7815 struct dwarf2_cu
*cu
)
7817 struct cleanup
*back_to
;
7818 struct line_header
*lh
;
7820 unsigned int bytes_read
, offset_size
;
7822 char *cur_dir
, *cur_file
;
7824 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
7825 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7827 complaint (&symfile_complaints
, _("missing .debug_line section"));
7831 /* Make sure that at least there's room for the total_length field.
7832 That could be 12 bytes long, but we're just going to fudge that. */
7833 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7835 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7839 lh
= xmalloc (sizeof (*lh
));
7840 memset (lh
, 0, sizeof (*lh
));
7841 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7844 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7846 /* Read in the header. */
7848 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7849 &bytes_read
, &offset_size
);
7850 line_ptr
+= bytes_read
;
7851 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7852 + dwarf2_per_objfile
->line
.size
))
7854 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7857 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7858 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7860 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7861 line_ptr
+= offset_size
;
7862 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7864 if (lh
->version
>= 4)
7866 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
7870 lh
->maximum_ops_per_instruction
= 1;
7872 if (lh
->maximum_ops_per_instruction
== 0)
7874 lh
->maximum_ops_per_instruction
= 1;
7875 complaint (&symfile_complaints
,
7876 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
7879 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7881 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7883 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7885 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7887 lh
->standard_opcode_lengths
7888 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7890 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7891 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7893 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7897 /* Read directory table. */
7898 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7900 line_ptr
+= bytes_read
;
7901 add_include_dir (lh
, cur_dir
);
7903 line_ptr
+= bytes_read
;
7905 /* Read file name table. */
7906 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7908 unsigned int dir_index
, mod_time
, length
;
7910 line_ptr
+= bytes_read
;
7911 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7912 line_ptr
+= bytes_read
;
7913 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7914 line_ptr
+= bytes_read
;
7915 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7916 line_ptr
+= bytes_read
;
7918 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7920 line_ptr
+= bytes_read
;
7921 lh
->statement_program_start
= line_ptr
;
7923 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7924 + dwarf2_per_objfile
->line
.size
))
7925 complaint (&symfile_complaints
,
7926 _("line number info header doesn't fit in `.debug_line' section"));
7928 discard_cleanups (back_to
);
7932 /* This function exists to work around a bug in certain compilers
7933 (particularly GCC 2.95), in which the first line number marker of a
7934 function does not show up until after the prologue, right before
7935 the second line number marker. This function shifts ADDRESS down
7936 to the beginning of the function if necessary, and is called on
7937 addresses passed to record_line. */
7940 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7942 struct function_range
*fn
;
7944 /* Find the function_range containing address. */
7949 cu
->cached_fn
= cu
->first_fn
;
7953 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7959 while (fn
&& fn
!= cu
->cached_fn
)
7960 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7970 if (address
!= fn
->lowpc
)
7971 complaint (&symfile_complaints
,
7972 _("misplaced first line number at 0x%lx for '%s'"),
7973 (unsigned long) address
, fn
->name
);
7978 /* Decode the Line Number Program (LNP) for the given line_header
7979 structure and CU. The actual information extracted and the type
7980 of structures created from the LNP depends on the value of PST.
7982 1. If PST is NULL, then this procedure uses the data from the program
7983 to create all necessary symbol tables, and their linetables.
7984 The compilation directory of the file is passed in COMP_DIR,
7985 and must not be NULL.
7987 2. If PST is not NULL, this procedure reads the program to determine
7988 the list of files included by the unit represented by PST, and
7989 builds all the associated partial symbol tables. In this case,
7990 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7991 is not used to compute the full name of the symtab, and therefore
7992 omitting it when building the partial symtab does not introduce
7993 the potential for inconsistency - a partial symtab and its associated
7994 symbtab having a different fullname -). */
7997 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7998 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
8000 gdb_byte
*line_ptr
, *extended_end
;
8002 unsigned int bytes_read
, extended_len
;
8003 unsigned char op_code
, extended_op
, adj_opcode
;
8005 struct objfile
*objfile
= cu
->objfile
;
8006 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8007 const int decode_for_pst_p
= (pst
!= NULL
);
8008 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
8010 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8012 line_ptr
= lh
->statement_program_start
;
8013 line_end
= lh
->statement_program_end
;
8015 /* Read the statement sequences until there's nothing left. */
8016 while (line_ptr
< line_end
)
8018 /* state machine registers */
8019 CORE_ADDR address
= 0;
8020 unsigned int file
= 1;
8021 unsigned int line
= 1;
8022 unsigned int column
= 0;
8023 int is_stmt
= lh
->default_is_stmt
;
8024 int basic_block
= 0;
8025 int end_sequence
= 0;
8027 unsigned char op_index
= 0;
8029 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
8031 /* Start a subfile for the current file of the state machine. */
8032 /* lh->include_dirs and lh->file_names are 0-based, but the
8033 directory and file name numbers in the statement program
8035 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8039 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8041 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8044 /* Decode the table. */
8045 while (!end_sequence
)
8047 op_code
= read_1_byte (abfd
, line_ptr
);
8049 if (line_ptr
> line_end
)
8051 dwarf2_debug_line_missing_end_sequence_complaint ();
8055 if (op_code
>= lh
->opcode_base
)
8057 /* Special operand. */
8058 adj_opcode
= op_code
- lh
->opcode_base
;
8059 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
8060 / lh
->maximum_ops_per_instruction
)
8061 * lh
->minimum_instruction_length
);
8062 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
8063 % lh
->maximum_ops_per_instruction
);
8064 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
8065 if (lh
->num_file_names
< file
|| file
== 0)
8066 dwarf2_debug_line_missing_file_complaint ();
8067 /* For now we ignore lines not starting on an
8068 instruction boundary. */
8069 else if (op_index
== 0)
8071 lh
->file_names
[file
- 1].included_p
= 1;
8072 if (!decode_for_pst_p
&& is_stmt
)
8074 if (last_subfile
!= current_subfile
)
8076 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8078 record_line (last_subfile
, 0, addr
);
8079 last_subfile
= current_subfile
;
8081 /* Append row to matrix using current values. */
8082 addr
= check_cu_functions (address
, cu
);
8083 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8084 record_line (current_subfile
, line
, addr
);
8089 else switch (op_code
)
8091 case DW_LNS_extended_op
:
8092 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8093 line_ptr
+= bytes_read
;
8094 extended_end
= line_ptr
+ extended_len
;
8095 extended_op
= read_1_byte (abfd
, line_ptr
);
8097 switch (extended_op
)
8099 case DW_LNE_end_sequence
:
8102 case DW_LNE_set_address
:
8103 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
8105 line_ptr
+= bytes_read
;
8106 address
+= baseaddr
;
8108 case DW_LNE_define_file
:
8111 unsigned int dir_index
, mod_time
, length
;
8113 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
8114 line_ptr
+= bytes_read
;
8116 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8117 line_ptr
+= bytes_read
;
8119 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8120 line_ptr
+= bytes_read
;
8122 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8123 line_ptr
+= bytes_read
;
8124 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
8127 case DW_LNE_set_discriminator
:
8128 /* The discriminator is not interesting to the debugger;
8130 line_ptr
= extended_end
;
8133 complaint (&symfile_complaints
,
8134 _("mangled .debug_line section"));
8137 /* Make sure that we parsed the extended op correctly. If e.g.
8138 we expected a different address size than the producer used,
8139 we may have read the wrong number of bytes. */
8140 if (line_ptr
!= extended_end
)
8142 complaint (&symfile_complaints
,
8143 _("mangled .debug_line section"));
8148 if (lh
->num_file_names
< file
|| file
== 0)
8149 dwarf2_debug_line_missing_file_complaint ();
8152 lh
->file_names
[file
- 1].included_p
= 1;
8153 if (!decode_for_pst_p
&& is_stmt
)
8155 if (last_subfile
!= current_subfile
)
8157 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8159 record_line (last_subfile
, 0, addr
);
8160 last_subfile
= current_subfile
;
8162 addr
= check_cu_functions (address
, cu
);
8163 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8164 record_line (current_subfile
, line
, addr
);
8169 case DW_LNS_advance_pc
:
8172 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8174 address
+= (((op_index
+ adjust
)
8175 / lh
->maximum_ops_per_instruction
)
8176 * lh
->minimum_instruction_length
);
8177 op_index
= ((op_index
+ adjust
)
8178 % lh
->maximum_ops_per_instruction
);
8179 line_ptr
+= bytes_read
;
8182 case DW_LNS_advance_line
:
8183 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
8184 line_ptr
+= bytes_read
;
8186 case DW_LNS_set_file
:
8188 /* The arrays lh->include_dirs and lh->file_names are
8189 0-based, but the directory and file name numbers in
8190 the statement program are 1-based. */
8191 struct file_entry
*fe
;
8194 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8195 line_ptr
+= bytes_read
;
8196 if (lh
->num_file_names
< file
|| file
== 0)
8197 dwarf2_debug_line_missing_file_complaint ();
8200 fe
= &lh
->file_names
[file
- 1];
8202 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8203 if (!decode_for_pst_p
)
8205 last_subfile
= current_subfile
;
8206 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8211 case DW_LNS_set_column
:
8212 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8213 line_ptr
+= bytes_read
;
8215 case DW_LNS_negate_stmt
:
8216 is_stmt
= (!is_stmt
);
8218 case DW_LNS_set_basic_block
:
8221 /* Add to the address register of the state machine the
8222 address increment value corresponding to special opcode
8223 255. I.e., this value is scaled by the minimum
8224 instruction length since special opcode 255 would have
8225 scaled the the increment. */
8226 case DW_LNS_const_add_pc
:
8228 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
8230 address
+= (((op_index
+ adjust
)
8231 / lh
->maximum_ops_per_instruction
)
8232 * lh
->minimum_instruction_length
);
8233 op_index
= ((op_index
+ adjust
)
8234 % lh
->maximum_ops_per_instruction
);
8237 case DW_LNS_fixed_advance_pc
:
8238 address
+= read_2_bytes (abfd
, line_ptr
);
8244 /* Unknown standard opcode, ignore it. */
8247 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
8249 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8250 line_ptr
+= bytes_read
;
8255 if (lh
->num_file_names
< file
|| file
== 0)
8256 dwarf2_debug_line_missing_file_complaint ();
8259 lh
->file_names
[file
- 1].included_p
= 1;
8260 if (!decode_for_pst_p
)
8262 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8263 record_line (current_subfile
, 0, addr
);
8268 if (decode_for_pst_p
)
8272 /* Now that we're done scanning the Line Header Program, we can
8273 create the psymtab of each included file. */
8274 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
8275 if (lh
->file_names
[file_index
].included_p
== 1)
8277 const struct file_entry fe
= lh
->file_names
[file_index
];
8278 char *include_name
= fe
.name
;
8279 char *dir_name
= NULL
;
8280 char *pst_filename
= pst
->filename
;
8283 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
8285 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
8287 include_name
= concat (dir_name
, SLASH_STRING
,
8288 include_name
, (char *)NULL
);
8289 make_cleanup (xfree
, include_name
);
8292 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
8294 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
8295 pst_filename
, (char *)NULL
);
8296 make_cleanup (xfree
, pst_filename
);
8299 if (strcmp (include_name
, pst_filename
) != 0)
8300 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
8305 /* Make sure a symtab is created for every file, even files
8306 which contain only variables (i.e. no code with associated
8310 struct file_entry
*fe
;
8312 for (i
= 0; i
< lh
->num_file_names
; i
++)
8315 fe
= &lh
->file_names
[i
];
8317 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8318 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8320 /* Skip the main file; we don't need it, and it must be
8321 allocated last, so that it will show up before the
8322 non-primary symtabs in the objfile's symtab list. */
8323 if (current_subfile
== first_subfile
)
8326 if (current_subfile
->symtab
== NULL
)
8327 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8329 fe
->symtab
= current_subfile
->symtab
;
8334 /* Start a subfile for DWARF. FILENAME is the name of the file and
8335 DIRNAME the name of the source directory which contains FILENAME
8336 or NULL if not known. COMP_DIR is the compilation directory for the
8337 linetable's compilation unit or NULL if not known.
8338 This routine tries to keep line numbers from identical absolute and
8339 relative file names in a common subfile.
8341 Using the `list' example from the GDB testsuite, which resides in
8342 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8343 of /srcdir/list0.c yields the following debugging information for list0.c:
8345 DW_AT_name: /srcdir/list0.c
8346 DW_AT_comp_dir: /compdir
8347 files.files[0].name: list0.h
8348 files.files[0].dir: /srcdir
8349 files.files[1].name: list0.c
8350 files.files[1].dir: /srcdir
8352 The line number information for list0.c has to end up in a single
8353 subfile, so that `break /srcdir/list0.c:1' works as expected.
8354 start_subfile will ensure that this happens provided that we pass the
8355 concatenation of files.files[1].dir and files.files[1].name as the
8359 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
8363 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8364 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8365 second argument to start_subfile. To be consistent, we do the
8366 same here. In order not to lose the line information directory,
8367 we concatenate it to the filename when it makes sense.
8368 Note that the Dwarf3 standard says (speaking of filenames in line
8369 information): ``The directory index is ignored for file names
8370 that represent full path names''. Thus ignoring dirname in the
8371 `else' branch below isn't an issue. */
8373 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
8374 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
8376 fullname
= filename
;
8378 start_subfile (fullname
, comp_dir
);
8380 if (fullname
!= filename
)
8385 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
8386 struct dwarf2_cu
*cu
)
8388 struct objfile
*objfile
= cu
->objfile
;
8389 struct comp_unit_head
*cu_header
= &cu
->header
;
8391 /* NOTE drow/2003-01-30: There used to be a comment and some special
8392 code here to turn a symbol with DW_AT_external and a
8393 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8394 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8395 with some versions of binutils) where shared libraries could have
8396 relocations against symbols in their debug information - the
8397 minimal symbol would have the right address, but the debug info
8398 would not. It's no longer necessary, because we will explicitly
8399 apply relocations when we read in the debug information now. */
8401 /* A DW_AT_location attribute with no contents indicates that a
8402 variable has been optimized away. */
8403 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
8405 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8409 /* Handle one degenerate form of location expression specially, to
8410 preserve GDB's previous behavior when section offsets are
8411 specified. If this is just a DW_OP_addr then mark this symbol
8414 if (attr_form_is_block (attr
)
8415 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
8416 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
8420 SYMBOL_VALUE_ADDRESS (sym
) =
8421 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
8422 SYMBOL_CLASS (sym
) = LOC_STATIC
;
8423 fixup_symbol_section (sym
, objfile
);
8424 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
8425 SYMBOL_SECTION (sym
));
8429 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8430 expression evaluator, and use LOC_COMPUTED only when necessary
8431 (i.e. when the value of a register or memory location is
8432 referenced, or a thread-local block, etc.). Then again, it might
8433 not be worthwhile. I'm assuming that it isn't unless performance
8434 or memory numbers show me otherwise. */
8436 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
8437 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
8440 /* Given a pointer to a DWARF information entry, figure out if we need
8441 to make a symbol table entry for it, and if so, create a new entry
8442 and return a pointer to it.
8443 If TYPE is NULL, determine symbol type from the die, otherwise
8444 used the passed type. */
8446 static struct symbol
*
8447 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
8449 struct objfile
*objfile
= cu
->objfile
;
8450 struct symbol
*sym
= NULL
;
8452 struct attribute
*attr
= NULL
;
8453 struct attribute
*attr2
= NULL
;
8455 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8457 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8459 name
= dwarf2_name (die
, cu
);
8462 const char *linkagename
;
8464 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
8465 sizeof (struct symbol
));
8466 OBJSTAT (objfile
, n_syms
++);
8467 memset (sym
, 0, sizeof (struct symbol
));
8469 /* Cache this symbol's name and the name's demangled form (if any). */
8470 SYMBOL_LANGUAGE (sym
) = cu
->language
;
8471 linkagename
= dwarf2_physname (name
, die
, cu
);
8472 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
8474 /* Default assumptions.
8475 Use the passed type or decode it from the die. */
8476 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8477 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8479 SYMBOL_TYPE (sym
) = type
;
8481 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
8482 attr
= dwarf2_attr (die
,
8483 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
8487 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
8490 attr
= dwarf2_attr (die
,
8491 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
8495 int file_index
= DW_UNSND (attr
);
8496 if (cu
->line_header
== NULL
8497 || file_index
> cu
->line_header
->num_file_names
)
8498 complaint (&symfile_complaints
,
8499 _("file index out of range"));
8500 else if (file_index
> 0)
8502 struct file_entry
*fe
;
8503 fe
= &cu
->line_header
->file_names
[file_index
- 1];
8504 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
8511 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8514 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
8516 SYMBOL_CLASS (sym
) = LOC_LABEL
;
8518 case DW_TAG_subprogram
:
8519 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8521 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8522 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8523 if ((attr2
&& (DW_UNSND (attr2
) != 0))
8524 || cu
->language
== language_ada
)
8526 /* Subprograms marked external are stored as a global symbol.
8527 Ada subprograms, whether marked external or not, are always
8528 stored as a global symbol, because we want to be able to
8529 access them globally. For instance, we want to be able
8530 to break on a nested subprogram without having to
8531 specify the context. */
8532 add_symbol_to_list (sym
, &global_symbols
);
8536 add_symbol_to_list (sym
, cu
->list_in_scope
);
8539 case DW_TAG_inlined_subroutine
:
8540 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8542 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8543 SYMBOL_INLINED (sym
) = 1;
8544 /* Do not add the symbol to any lists. It will be found via
8545 BLOCK_FUNCTION from the blockvector. */
8547 case DW_TAG_variable
:
8548 /* Compilation with minimal debug info may result in variables
8549 with missing type entries. Change the misleading `void' type
8550 to something sensible. */
8551 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
8553 = objfile_type (objfile
)->nodebug_data_symbol
;
8555 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8558 dwarf2_const_value (attr
, sym
, cu
);
8559 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8560 if (attr2
&& (DW_UNSND (attr2
) != 0))
8561 add_symbol_to_list (sym
, &global_symbols
);
8563 add_symbol_to_list (sym
, cu
->list_in_scope
);
8566 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8569 var_decode_location (attr
, sym
, cu
);
8570 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8571 if (attr2
&& (DW_UNSND (attr2
) != 0))
8573 struct pending
**list_to_add
;
8575 /* A variable with DW_AT_external is never static,
8576 but it may be block-scoped. */
8577 list_to_add
= (cu
->list_in_scope
== &file_symbols
8578 ? &global_symbols
: cu
->list_in_scope
);
8579 add_symbol_to_list (sym
, list_to_add
);
8582 add_symbol_to_list (sym
, cu
->list_in_scope
);
8586 /* We do not know the address of this symbol.
8587 If it is an external symbol and we have type information
8588 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8589 The address of the variable will then be determined from
8590 the minimal symbol table whenever the variable is
8592 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8593 if (attr2
&& (DW_UNSND (attr2
) != 0)
8594 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
8596 struct pending
**list_to_add
;
8598 /* A variable with DW_AT_external is never static, but it
8599 may be block-scoped. */
8600 list_to_add
= (cu
->list_in_scope
== &file_symbols
8601 ? &global_symbols
: cu
->list_in_scope
);
8603 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8604 add_symbol_to_list (sym
, list_to_add
);
8606 else if (!die_is_declaration (die
, cu
))
8608 /* Use the default LOC_OPTIMIZED_OUT class. */
8609 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
8610 add_symbol_to_list (sym
, cu
->list_in_scope
);
8614 case DW_TAG_formal_parameter
:
8615 /* If we are inside a function, mark this as an argument. If
8616 not, we might be looking at an argument to an inlined function
8617 when we do not have enough information to show inlined frames;
8618 pretend it's a local variable in that case so that the user can
8620 if (context_stack_depth
> 0
8621 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
8622 SYMBOL_IS_ARGUMENT (sym
) = 1;
8623 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8626 var_decode_location (attr
, sym
, cu
);
8628 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8631 dwarf2_const_value (attr
, sym
, cu
);
8633 add_symbol_to_list (sym
, cu
->list_in_scope
);
8635 case DW_TAG_unspecified_parameters
:
8636 /* From varargs functions; gdb doesn't seem to have any
8637 interest in this information, so just ignore it for now.
8640 case DW_TAG_class_type
:
8641 case DW_TAG_interface_type
:
8642 case DW_TAG_structure_type
:
8643 case DW_TAG_union_type
:
8644 case DW_TAG_set_type
:
8645 case DW_TAG_enumeration_type
:
8646 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8647 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8649 /* Make sure that the symbol includes appropriate enclosing
8650 classes/namespaces in its name. These are calculated in
8651 read_structure_type, and the correct name is saved in
8654 if (cu
->language
== language_cplus
8655 || cu
->language
== language_java
)
8657 struct type
*type
= SYMBOL_TYPE (sym
);
8659 if (TYPE_TAG_NAME (type
) != NULL
)
8661 /* FIXME: carlton/2003-11-10: Should this use
8662 SYMBOL_SET_NAMES instead? (The same problem also
8663 arises further down in this function.) */
8664 /* The type's name is already allocated along with
8665 this objfile, so we don't need to duplicate it
8667 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
8672 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8673 really ever be static objects: otherwise, if you try
8674 to, say, break of a class's method and you're in a file
8675 which doesn't mention that class, it won't work unless
8676 the check for all static symbols in lookup_symbol_aux
8677 saves you. See the OtherFileClass tests in
8678 gdb.c++/namespace.exp. */
8680 struct pending
**list_to_add
;
8682 list_to_add
= (cu
->list_in_scope
== &file_symbols
8683 && (cu
->language
== language_cplus
8684 || cu
->language
== language_java
)
8685 ? &global_symbols
: cu
->list_in_scope
);
8687 add_symbol_to_list (sym
, list_to_add
);
8689 /* The semantics of C++ state that "struct foo { ... }" also
8690 defines a typedef for "foo". A Java class declaration also
8691 defines a typedef for the class. */
8692 if (cu
->language
== language_cplus
8693 || cu
->language
== language_java
8694 || cu
->language
== language_ada
)
8696 /* The symbol's name is already allocated along with
8697 this objfile, so we don't need to duplicate it for
8699 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
8700 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
8704 case DW_TAG_typedef
:
8705 SYMBOL_LINKAGE_NAME (sym
)
8706 = (char *) dwarf2_full_name (name
, die
, cu
);
8707 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8708 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8709 add_symbol_to_list (sym
, cu
->list_in_scope
);
8711 case DW_TAG_base_type
:
8712 case DW_TAG_subrange_type
:
8713 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8714 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8715 add_symbol_to_list (sym
, cu
->list_in_scope
);
8717 case DW_TAG_enumerator
:
8718 SYMBOL_LINKAGE_NAME (sym
)
8719 = (char *) dwarf2_full_name (name
, die
, cu
);
8720 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8723 dwarf2_const_value (attr
, sym
, cu
);
8726 /* NOTE: carlton/2003-11-10: See comment above in the
8727 DW_TAG_class_type, etc. block. */
8729 struct pending
**list_to_add
;
8731 list_to_add
= (cu
->list_in_scope
== &file_symbols
8732 && (cu
->language
== language_cplus
8733 || cu
->language
== language_java
)
8734 ? &global_symbols
: cu
->list_in_scope
);
8736 add_symbol_to_list (sym
, list_to_add
);
8739 case DW_TAG_namespace
:
8740 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8741 add_symbol_to_list (sym
, &global_symbols
);
8744 /* Not a tag we recognize. Hopefully we aren't processing
8745 trash data, but since we must specifically ignore things
8746 we don't recognize, there is nothing else we should do at
8748 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8749 dwarf_tag_name (die
->tag
));
8753 /* For the benefit of old versions of GCC, check for anonymous
8754 namespaces based on the demangled name. */
8755 if (!processing_has_namespace_info
8756 && cu
->language
== language_cplus
)
8757 cp_scan_for_anonymous_namespaces (sym
);
8762 /* Copy constant value from an attribute to a symbol. */
8765 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8766 struct dwarf2_cu
*cu
)
8768 struct objfile
*objfile
= cu
->objfile
;
8769 struct comp_unit_head
*cu_header
= &cu
->header
;
8770 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
8771 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
8772 struct dwarf_block
*blk
;
8777 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8778 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8779 cu_header
->addr_size
,
8780 TYPE_LENGTH (SYMBOL_TYPE
8782 SYMBOL_VALUE_BYTES (sym
) =
8783 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8784 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8785 it's body - store_unsigned_integer. */
8786 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8787 byte_order
, DW_ADDR (attr
));
8788 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8790 case DW_FORM_string
:
8792 /* DW_STRING is already allocated on the obstack, point directly
8794 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8795 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8797 case DW_FORM_block1
:
8798 case DW_FORM_block2
:
8799 case DW_FORM_block4
:
8801 case DW_FORM_exprloc
:
8802 blk
= DW_BLOCK (attr
);
8803 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8804 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8806 TYPE_LENGTH (SYMBOL_TYPE
8808 SYMBOL_VALUE_BYTES (sym
) =
8809 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8810 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8811 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8814 /* The DW_AT_const_value attributes are supposed to carry the
8815 symbol's value "represented as it would be on the target
8816 architecture." By the time we get here, it's already been
8817 converted to host endianness, so we just need to sign- or
8818 zero-extend it as appropriate. */
8820 dwarf2_const_value_data (attr
, sym
, 8);
8823 dwarf2_const_value_data (attr
, sym
, 16);
8826 dwarf2_const_value_data (attr
, sym
, 32);
8829 dwarf2_const_value_data (attr
, sym
, 64);
8833 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8834 SYMBOL_CLASS (sym
) = LOC_CONST
;
8838 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8839 SYMBOL_CLASS (sym
) = LOC_CONST
;
8843 complaint (&symfile_complaints
,
8844 _("unsupported const value attribute form: '%s'"),
8845 dwarf_form_name (attr
->form
));
8846 SYMBOL_VALUE (sym
) = 0;
8847 SYMBOL_CLASS (sym
) = LOC_CONST
;
8853 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8854 or zero-extend it as appropriate for the symbol's type. */
8856 dwarf2_const_value_data (struct attribute
*attr
,
8860 LONGEST l
= DW_UNSND (attr
);
8862 if (bits
< sizeof (l
) * 8)
8864 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8865 l
&= ((LONGEST
) 1 << bits
) - 1;
8867 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8870 SYMBOL_VALUE (sym
) = l
;
8871 SYMBOL_CLASS (sym
) = LOC_CONST
;
8875 /* Return the type of the die in question using its DW_AT_type attribute. */
8877 static struct type
*
8878 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8880 struct attribute
*type_attr
;
8881 struct die_info
*type_die
;
8883 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8886 /* A missing DW_AT_type represents a void type. */
8887 return objfile_type (cu
->objfile
)->builtin_void
;
8890 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8892 return tag_type_to_type (type_die
, cu
);
8895 /* True iff CU's producer generates GNAT Ada auxiliary information
8896 that allows to find parallel types through that information instead
8897 of having to do expensive parallel lookups by type name. */
8900 need_gnat_info (struct dwarf2_cu
*cu
)
8902 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8903 of GNAT produces this auxiliary information, without any indication
8904 that it is produced. Part of enhancing the FSF version of GNAT
8905 to produce that information will be to put in place an indicator
8906 that we can use in order to determine whether the descriptive type
8907 info is available or not. One suggestion that has been made is
8908 to use a new attribute, attached to the CU die. For now, assume
8909 that the descriptive type info is not available. */
8914 /* Return the auxiliary type of the die in question using its
8915 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8916 attribute is not present. */
8918 static struct type
*
8919 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8921 struct attribute
*type_attr
;
8922 struct die_info
*type_die
;
8924 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
8928 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8929 return tag_type_to_type (type_die
, cu
);
8932 /* If DIE has a descriptive_type attribute, then set the TYPE's
8933 descriptive type accordingly. */
8936 set_descriptive_type (struct type
*type
, struct die_info
*die
,
8937 struct dwarf2_cu
*cu
)
8939 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
8941 if (descriptive_type
)
8943 ALLOCATE_GNAT_AUX_TYPE (type
);
8944 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
8948 /* Return the containing type of the die in question using its
8949 DW_AT_containing_type attribute. */
8951 static struct type
*
8952 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8954 struct attribute
*type_attr
;
8955 struct die_info
*type_die
;
8957 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8959 error (_("Dwarf Error: Problem turning containing type into gdb type "
8960 "[in module %s]"), cu
->objfile
->name
);
8962 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8963 return tag_type_to_type (type_die
, cu
);
8966 static struct type
*
8967 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8969 struct type
*this_type
;
8971 this_type
= read_type_die (die
, cu
);
8974 dump_die_for_error (die
);
8975 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8981 static struct type
*
8982 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8984 struct type
*this_type
;
8986 this_type
= get_die_type (die
, cu
);
8992 case DW_TAG_class_type
:
8993 case DW_TAG_interface_type
:
8994 case DW_TAG_structure_type
:
8995 case DW_TAG_union_type
:
8996 this_type
= read_structure_type (die
, cu
);
8998 case DW_TAG_enumeration_type
:
8999 this_type
= read_enumeration_type (die
, cu
);
9001 case DW_TAG_subprogram
:
9002 case DW_TAG_subroutine_type
:
9003 case DW_TAG_inlined_subroutine
:
9004 this_type
= read_subroutine_type (die
, cu
);
9006 case DW_TAG_array_type
:
9007 this_type
= read_array_type (die
, cu
);
9009 case DW_TAG_set_type
:
9010 this_type
= read_set_type (die
, cu
);
9012 case DW_TAG_pointer_type
:
9013 this_type
= read_tag_pointer_type (die
, cu
);
9015 case DW_TAG_ptr_to_member_type
:
9016 this_type
= read_tag_ptr_to_member_type (die
, cu
);
9018 case DW_TAG_reference_type
:
9019 this_type
= read_tag_reference_type (die
, cu
);
9021 case DW_TAG_const_type
:
9022 this_type
= read_tag_const_type (die
, cu
);
9024 case DW_TAG_volatile_type
:
9025 this_type
= read_tag_volatile_type (die
, cu
);
9027 case DW_TAG_string_type
:
9028 this_type
= read_tag_string_type (die
, cu
);
9030 case DW_TAG_typedef
:
9031 this_type
= read_typedef (die
, cu
);
9033 case DW_TAG_subrange_type
:
9034 this_type
= read_subrange_type (die
, cu
);
9036 case DW_TAG_base_type
:
9037 this_type
= read_base_type (die
, cu
);
9039 case DW_TAG_unspecified_type
:
9040 this_type
= read_unspecified_type (die
, cu
);
9042 case DW_TAG_namespace
:
9043 this_type
= read_namespace_type (die
, cu
);
9046 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
9047 dwarf_tag_name (die
->tag
));
9054 /* Return the name of the namespace/class that DIE is defined within,
9055 or "" if we can't tell. The caller should not xfree the result.
9057 For example, if we're within the method foo() in the following
9067 then determine_prefix on foo's die will return "N::C". */
9070 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
9072 struct die_info
*parent
, *spec_die
;
9073 struct dwarf2_cu
*spec_cu
;
9074 struct type
*parent_type
;
9076 if (cu
->language
!= language_cplus
9077 && cu
->language
!= language_java
)
9080 /* We have to be careful in the presence of DW_AT_specification.
9081 For example, with GCC 3.4, given the code
9085 // Definition of N::foo.
9089 then we'll have a tree of DIEs like this:
9091 1: DW_TAG_compile_unit
9092 2: DW_TAG_namespace // N
9093 3: DW_TAG_subprogram // declaration of N::foo
9094 4: DW_TAG_subprogram // definition of N::foo
9095 DW_AT_specification // refers to die #3
9097 Thus, when processing die #4, we have to pretend that we're in
9098 the context of its DW_AT_specification, namely the contex of die
9101 spec_die
= die_specification (die
, &spec_cu
);
9102 if (spec_die
== NULL
)
9103 parent
= die
->parent
;
9106 parent
= spec_die
->parent
;
9113 switch (parent
->tag
)
9115 case DW_TAG_namespace
:
9116 parent_type
= read_type_die (parent
, cu
);
9117 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9118 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9119 Work around this problem here. */
9120 if (cu
->language
== language_cplus
9121 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
9123 /* We give a name to even anonymous namespaces. */
9124 return TYPE_TAG_NAME (parent_type
);
9125 case DW_TAG_class_type
:
9126 case DW_TAG_interface_type
:
9127 case DW_TAG_structure_type
:
9128 case DW_TAG_union_type
:
9129 parent_type
= read_type_die (parent
, cu
);
9130 if (TYPE_TAG_NAME (parent_type
) != NULL
)
9131 return TYPE_TAG_NAME (parent_type
);
9133 /* An anonymous structure is only allowed non-static data
9134 members; no typedefs, no member functions, et cetera.
9135 So it does not need a prefix. */
9138 return determine_prefix (parent
, cu
);
9142 /* Return a newly-allocated string formed by concatenating PREFIX and
9143 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9144 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9145 perform an obconcat, otherwise allocate storage for the result. The CU argument
9146 is used to determine the language and hence, the appropriate separator. */
9148 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9151 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9152 struct dwarf2_cu
*cu
)
9156 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9158 else if (cu
->language
== language_java
)
9170 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9171 strcpy (retval
, prefix
);
9172 strcat (retval
, sep
);
9173 strcat (retval
, suffix
);
9178 /* We have an obstack. */
9179 return obconcat (obs
, prefix
, sep
, suffix
, (char *) NULL
);
9183 /* Return sibling of die, NULL if no sibling. */
9185 static struct die_info
*
9186 sibling_die (struct die_info
*die
)
9188 return die
->sibling
;
9191 /* Get name of a die, return NULL if not found. */
9194 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9195 struct obstack
*obstack
)
9197 if (name
&& cu
->language
== language_cplus
)
9199 char *canon_name
= cp_canonicalize_string (name
);
9201 if (canon_name
!= NULL
)
9203 if (strcmp (canon_name
, name
) != 0)
9204 name
= obsavestring (canon_name
, strlen (canon_name
),
9213 /* Get name of a die, return NULL if not found. */
9216 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9218 struct attribute
*attr
;
9220 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9221 if (!attr
|| !DW_STRING (attr
))
9226 case DW_TAG_compile_unit
:
9227 /* Compilation units have a DW_AT_name that is a filename, not
9228 a source language identifier. */
9229 case DW_TAG_enumeration_type
:
9230 case DW_TAG_enumerator
:
9231 /* These tags always have simple identifiers already; no need
9232 to canonicalize them. */
9233 return DW_STRING (attr
);
9235 case DW_TAG_subprogram
:
9236 /* Java constructors will all be named "<init>", so return
9237 the class name when we see this special case. */
9238 if (cu
->language
== language_java
9239 && DW_STRING (attr
) != NULL
9240 && strcmp (DW_STRING (attr
), "<init>") == 0)
9242 struct dwarf2_cu
*spec_cu
= cu
;
9243 struct die_info
*spec_die
;
9245 /* GCJ will output '<init>' for Java constructor names.
9246 For this special case, return the name of the parent class. */
9248 /* GCJ may output suprogram DIEs with AT_specification set.
9249 If so, use the name of the specified DIE. */
9250 spec_die
= die_specification (die
, &spec_cu
);
9251 if (spec_die
!= NULL
)
9252 return dwarf2_name (spec_die
, spec_cu
);
9257 if (die
->tag
== DW_TAG_class_type
)
9258 return dwarf2_name (die
, cu
);
9260 while (die
->tag
!= DW_TAG_compile_unit
);
9264 case DW_TAG_class_type
:
9265 case DW_TAG_interface_type
:
9266 case DW_TAG_structure_type
:
9267 case DW_TAG_union_type
:
9268 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
9269 structures or unions. These were of the form "._%d" in GCC 4.1,
9270 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
9271 and GCC 4.4. We work around this problem by ignoring these. */
9272 if (strncmp (DW_STRING (attr
), "._", 2) == 0
9273 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
9281 if (!DW_STRING_IS_CANONICAL (attr
))
9284 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9285 &cu
->objfile
->objfile_obstack
);
9286 DW_STRING_IS_CANONICAL (attr
) = 1;
9288 return DW_STRING (attr
);
9291 /* Return the die that this die in an extension of, or NULL if there
9292 is none. *EXT_CU is the CU containing DIE on input, and the CU
9293 containing the return value on output. */
9295 static struct die_info
*
9296 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9298 struct attribute
*attr
;
9300 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9304 return follow_die_ref (die
, attr
, ext_cu
);
9307 /* Convert a DIE tag into its string name. */
9310 dwarf_tag_name (unsigned tag
)
9314 case DW_TAG_padding
:
9315 return "DW_TAG_padding";
9316 case DW_TAG_array_type
:
9317 return "DW_TAG_array_type";
9318 case DW_TAG_class_type
:
9319 return "DW_TAG_class_type";
9320 case DW_TAG_entry_point
:
9321 return "DW_TAG_entry_point";
9322 case DW_TAG_enumeration_type
:
9323 return "DW_TAG_enumeration_type";
9324 case DW_TAG_formal_parameter
:
9325 return "DW_TAG_formal_parameter";
9326 case DW_TAG_imported_declaration
:
9327 return "DW_TAG_imported_declaration";
9329 return "DW_TAG_label";
9330 case DW_TAG_lexical_block
:
9331 return "DW_TAG_lexical_block";
9333 return "DW_TAG_member";
9334 case DW_TAG_pointer_type
:
9335 return "DW_TAG_pointer_type";
9336 case DW_TAG_reference_type
:
9337 return "DW_TAG_reference_type";
9338 case DW_TAG_compile_unit
:
9339 return "DW_TAG_compile_unit";
9340 case DW_TAG_string_type
:
9341 return "DW_TAG_string_type";
9342 case DW_TAG_structure_type
:
9343 return "DW_TAG_structure_type";
9344 case DW_TAG_subroutine_type
:
9345 return "DW_TAG_subroutine_type";
9346 case DW_TAG_typedef
:
9347 return "DW_TAG_typedef";
9348 case DW_TAG_union_type
:
9349 return "DW_TAG_union_type";
9350 case DW_TAG_unspecified_parameters
:
9351 return "DW_TAG_unspecified_parameters";
9352 case DW_TAG_variant
:
9353 return "DW_TAG_variant";
9354 case DW_TAG_common_block
:
9355 return "DW_TAG_common_block";
9356 case DW_TAG_common_inclusion
:
9357 return "DW_TAG_common_inclusion";
9358 case DW_TAG_inheritance
:
9359 return "DW_TAG_inheritance";
9360 case DW_TAG_inlined_subroutine
:
9361 return "DW_TAG_inlined_subroutine";
9363 return "DW_TAG_module";
9364 case DW_TAG_ptr_to_member_type
:
9365 return "DW_TAG_ptr_to_member_type";
9366 case DW_TAG_set_type
:
9367 return "DW_TAG_set_type";
9368 case DW_TAG_subrange_type
:
9369 return "DW_TAG_subrange_type";
9370 case DW_TAG_with_stmt
:
9371 return "DW_TAG_with_stmt";
9372 case DW_TAG_access_declaration
:
9373 return "DW_TAG_access_declaration";
9374 case DW_TAG_base_type
:
9375 return "DW_TAG_base_type";
9376 case DW_TAG_catch_block
:
9377 return "DW_TAG_catch_block";
9378 case DW_TAG_const_type
:
9379 return "DW_TAG_const_type";
9380 case DW_TAG_constant
:
9381 return "DW_TAG_constant";
9382 case DW_TAG_enumerator
:
9383 return "DW_TAG_enumerator";
9384 case DW_TAG_file_type
:
9385 return "DW_TAG_file_type";
9387 return "DW_TAG_friend";
9388 case DW_TAG_namelist
:
9389 return "DW_TAG_namelist";
9390 case DW_TAG_namelist_item
:
9391 return "DW_TAG_namelist_item";
9392 case DW_TAG_packed_type
:
9393 return "DW_TAG_packed_type";
9394 case DW_TAG_subprogram
:
9395 return "DW_TAG_subprogram";
9396 case DW_TAG_template_type_param
:
9397 return "DW_TAG_template_type_param";
9398 case DW_TAG_template_value_param
:
9399 return "DW_TAG_template_value_param";
9400 case DW_TAG_thrown_type
:
9401 return "DW_TAG_thrown_type";
9402 case DW_TAG_try_block
:
9403 return "DW_TAG_try_block";
9404 case DW_TAG_variant_part
:
9405 return "DW_TAG_variant_part";
9406 case DW_TAG_variable
:
9407 return "DW_TAG_variable";
9408 case DW_TAG_volatile_type
:
9409 return "DW_TAG_volatile_type";
9410 case DW_TAG_dwarf_procedure
:
9411 return "DW_TAG_dwarf_procedure";
9412 case DW_TAG_restrict_type
:
9413 return "DW_TAG_restrict_type";
9414 case DW_TAG_interface_type
:
9415 return "DW_TAG_interface_type";
9416 case DW_TAG_namespace
:
9417 return "DW_TAG_namespace";
9418 case DW_TAG_imported_module
:
9419 return "DW_TAG_imported_module";
9420 case DW_TAG_unspecified_type
:
9421 return "DW_TAG_unspecified_type";
9422 case DW_TAG_partial_unit
:
9423 return "DW_TAG_partial_unit";
9424 case DW_TAG_imported_unit
:
9425 return "DW_TAG_imported_unit";
9426 case DW_TAG_condition
:
9427 return "DW_TAG_condition";
9428 case DW_TAG_shared_type
:
9429 return "DW_TAG_shared_type";
9430 case DW_TAG_type_unit
:
9431 return "DW_TAG_type_unit";
9432 case DW_TAG_MIPS_loop
:
9433 return "DW_TAG_MIPS_loop";
9434 case DW_TAG_HP_array_descriptor
:
9435 return "DW_TAG_HP_array_descriptor";
9436 case DW_TAG_format_label
:
9437 return "DW_TAG_format_label";
9438 case DW_TAG_function_template
:
9439 return "DW_TAG_function_template";
9440 case DW_TAG_class_template
:
9441 return "DW_TAG_class_template";
9442 case DW_TAG_GNU_BINCL
:
9443 return "DW_TAG_GNU_BINCL";
9444 case DW_TAG_GNU_EINCL
:
9445 return "DW_TAG_GNU_EINCL";
9446 case DW_TAG_upc_shared_type
:
9447 return "DW_TAG_upc_shared_type";
9448 case DW_TAG_upc_strict_type
:
9449 return "DW_TAG_upc_strict_type";
9450 case DW_TAG_upc_relaxed_type
:
9451 return "DW_TAG_upc_relaxed_type";
9452 case DW_TAG_PGI_kanji_type
:
9453 return "DW_TAG_PGI_kanji_type";
9454 case DW_TAG_PGI_interface_block
:
9455 return "DW_TAG_PGI_interface_block";
9457 return "DW_TAG_<unknown>";
9461 /* Convert a DWARF attribute code into its string name. */
9464 dwarf_attr_name (unsigned attr
)
9469 return "DW_AT_sibling";
9470 case DW_AT_location
:
9471 return "DW_AT_location";
9473 return "DW_AT_name";
9474 case DW_AT_ordering
:
9475 return "DW_AT_ordering";
9476 case DW_AT_subscr_data
:
9477 return "DW_AT_subscr_data";
9478 case DW_AT_byte_size
:
9479 return "DW_AT_byte_size";
9480 case DW_AT_bit_offset
:
9481 return "DW_AT_bit_offset";
9482 case DW_AT_bit_size
:
9483 return "DW_AT_bit_size";
9484 case DW_AT_element_list
:
9485 return "DW_AT_element_list";
9486 case DW_AT_stmt_list
:
9487 return "DW_AT_stmt_list";
9489 return "DW_AT_low_pc";
9491 return "DW_AT_high_pc";
9492 case DW_AT_language
:
9493 return "DW_AT_language";
9495 return "DW_AT_member";
9497 return "DW_AT_discr";
9498 case DW_AT_discr_value
:
9499 return "DW_AT_discr_value";
9500 case DW_AT_visibility
:
9501 return "DW_AT_visibility";
9503 return "DW_AT_import";
9504 case DW_AT_string_length
:
9505 return "DW_AT_string_length";
9506 case DW_AT_common_reference
:
9507 return "DW_AT_common_reference";
9508 case DW_AT_comp_dir
:
9509 return "DW_AT_comp_dir";
9510 case DW_AT_const_value
:
9511 return "DW_AT_const_value";
9512 case DW_AT_containing_type
:
9513 return "DW_AT_containing_type";
9514 case DW_AT_default_value
:
9515 return "DW_AT_default_value";
9517 return "DW_AT_inline";
9518 case DW_AT_is_optional
:
9519 return "DW_AT_is_optional";
9520 case DW_AT_lower_bound
:
9521 return "DW_AT_lower_bound";
9522 case DW_AT_producer
:
9523 return "DW_AT_producer";
9524 case DW_AT_prototyped
:
9525 return "DW_AT_prototyped";
9526 case DW_AT_return_addr
:
9527 return "DW_AT_return_addr";
9528 case DW_AT_start_scope
:
9529 return "DW_AT_start_scope";
9530 case DW_AT_bit_stride
:
9531 return "DW_AT_bit_stride";
9532 case DW_AT_upper_bound
:
9533 return "DW_AT_upper_bound";
9534 case DW_AT_abstract_origin
:
9535 return "DW_AT_abstract_origin";
9536 case DW_AT_accessibility
:
9537 return "DW_AT_accessibility";
9538 case DW_AT_address_class
:
9539 return "DW_AT_address_class";
9540 case DW_AT_artificial
:
9541 return "DW_AT_artificial";
9542 case DW_AT_base_types
:
9543 return "DW_AT_base_types";
9544 case DW_AT_calling_convention
:
9545 return "DW_AT_calling_convention";
9547 return "DW_AT_count";
9548 case DW_AT_data_member_location
:
9549 return "DW_AT_data_member_location";
9550 case DW_AT_decl_column
:
9551 return "DW_AT_decl_column";
9552 case DW_AT_decl_file
:
9553 return "DW_AT_decl_file";
9554 case DW_AT_decl_line
:
9555 return "DW_AT_decl_line";
9556 case DW_AT_declaration
:
9557 return "DW_AT_declaration";
9558 case DW_AT_discr_list
:
9559 return "DW_AT_discr_list";
9560 case DW_AT_encoding
:
9561 return "DW_AT_encoding";
9562 case DW_AT_external
:
9563 return "DW_AT_external";
9564 case DW_AT_frame_base
:
9565 return "DW_AT_frame_base";
9567 return "DW_AT_friend";
9568 case DW_AT_identifier_case
:
9569 return "DW_AT_identifier_case";
9570 case DW_AT_macro_info
:
9571 return "DW_AT_macro_info";
9572 case DW_AT_namelist_items
:
9573 return "DW_AT_namelist_items";
9574 case DW_AT_priority
:
9575 return "DW_AT_priority";
9577 return "DW_AT_segment";
9578 case DW_AT_specification
:
9579 return "DW_AT_specification";
9580 case DW_AT_static_link
:
9581 return "DW_AT_static_link";
9583 return "DW_AT_type";
9584 case DW_AT_use_location
:
9585 return "DW_AT_use_location";
9586 case DW_AT_variable_parameter
:
9587 return "DW_AT_variable_parameter";
9588 case DW_AT_virtuality
:
9589 return "DW_AT_virtuality";
9590 case DW_AT_vtable_elem_location
:
9591 return "DW_AT_vtable_elem_location";
9592 /* DWARF 3 values. */
9593 case DW_AT_allocated
:
9594 return "DW_AT_allocated";
9595 case DW_AT_associated
:
9596 return "DW_AT_associated";
9597 case DW_AT_data_location
:
9598 return "DW_AT_data_location";
9599 case DW_AT_byte_stride
:
9600 return "DW_AT_byte_stride";
9601 case DW_AT_entry_pc
:
9602 return "DW_AT_entry_pc";
9603 case DW_AT_use_UTF8
:
9604 return "DW_AT_use_UTF8";
9605 case DW_AT_extension
:
9606 return "DW_AT_extension";
9608 return "DW_AT_ranges";
9609 case DW_AT_trampoline
:
9610 return "DW_AT_trampoline";
9611 case DW_AT_call_column
:
9612 return "DW_AT_call_column";
9613 case DW_AT_call_file
:
9614 return "DW_AT_call_file";
9615 case DW_AT_call_line
:
9616 return "DW_AT_call_line";
9617 case DW_AT_description
:
9618 return "DW_AT_description";
9619 case DW_AT_binary_scale
:
9620 return "DW_AT_binary_scale";
9621 case DW_AT_decimal_scale
:
9622 return "DW_AT_decimal_scale";
9624 return "DW_AT_small";
9625 case DW_AT_decimal_sign
:
9626 return "DW_AT_decimal_sign";
9627 case DW_AT_digit_count
:
9628 return "DW_AT_digit_count";
9629 case DW_AT_picture_string
:
9630 return "DW_AT_picture_string";
9632 return "DW_AT_mutable";
9633 case DW_AT_threads_scaled
:
9634 return "DW_AT_threads_scaled";
9635 case DW_AT_explicit
:
9636 return "DW_AT_explicit";
9637 case DW_AT_object_pointer
:
9638 return "DW_AT_object_pointer";
9639 case DW_AT_endianity
:
9640 return "DW_AT_endianity";
9641 case DW_AT_elemental
:
9642 return "DW_AT_elemental";
9644 return "DW_AT_pure";
9645 case DW_AT_recursive
:
9646 return "DW_AT_recursive";
9647 /* DWARF 4 values. */
9648 case DW_AT_signature
:
9649 return "DW_AT_signature";
9650 case DW_AT_linkage_name
:
9651 return "DW_AT_linkage_name";
9652 /* SGI/MIPS extensions. */
9653 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9654 case DW_AT_MIPS_fde
:
9655 return "DW_AT_MIPS_fde";
9657 case DW_AT_MIPS_loop_begin
:
9658 return "DW_AT_MIPS_loop_begin";
9659 case DW_AT_MIPS_tail_loop_begin
:
9660 return "DW_AT_MIPS_tail_loop_begin";
9661 case DW_AT_MIPS_epilog_begin
:
9662 return "DW_AT_MIPS_epilog_begin";
9663 case DW_AT_MIPS_loop_unroll_factor
:
9664 return "DW_AT_MIPS_loop_unroll_factor";
9665 case DW_AT_MIPS_software_pipeline_depth
:
9666 return "DW_AT_MIPS_software_pipeline_depth";
9667 case DW_AT_MIPS_linkage_name
:
9668 return "DW_AT_MIPS_linkage_name";
9669 case DW_AT_MIPS_stride
:
9670 return "DW_AT_MIPS_stride";
9671 case DW_AT_MIPS_abstract_name
:
9672 return "DW_AT_MIPS_abstract_name";
9673 case DW_AT_MIPS_clone_origin
:
9674 return "DW_AT_MIPS_clone_origin";
9675 case DW_AT_MIPS_has_inlines
:
9676 return "DW_AT_MIPS_has_inlines";
9677 /* HP extensions. */
9678 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9679 case DW_AT_HP_block_index
:
9680 return "DW_AT_HP_block_index";
9682 case DW_AT_HP_unmodifiable
:
9683 return "DW_AT_HP_unmodifiable";
9684 case DW_AT_HP_actuals_stmt_list
:
9685 return "DW_AT_HP_actuals_stmt_list";
9686 case DW_AT_HP_proc_per_section
:
9687 return "DW_AT_HP_proc_per_section";
9688 case DW_AT_HP_raw_data_ptr
:
9689 return "DW_AT_HP_raw_data_ptr";
9690 case DW_AT_HP_pass_by_reference
:
9691 return "DW_AT_HP_pass_by_reference";
9692 case DW_AT_HP_opt_level
:
9693 return "DW_AT_HP_opt_level";
9694 case DW_AT_HP_prof_version_id
:
9695 return "DW_AT_HP_prof_version_id";
9696 case DW_AT_HP_opt_flags
:
9697 return "DW_AT_HP_opt_flags";
9698 case DW_AT_HP_cold_region_low_pc
:
9699 return "DW_AT_HP_cold_region_low_pc";
9700 case DW_AT_HP_cold_region_high_pc
:
9701 return "DW_AT_HP_cold_region_high_pc";
9702 case DW_AT_HP_all_variables_modifiable
:
9703 return "DW_AT_HP_all_variables_modifiable";
9704 case DW_AT_HP_linkage_name
:
9705 return "DW_AT_HP_linkage_name";
9706 case DW_AT_HP_prof_flags
:
9707 return "DW_AT_HP_prof_flags";
9708 /* GNU extensions. */
9709 case DW_AT_sf_names
:
9710 return "DW_AT_sf_names";
9711 case DW_AT_src_info
:
9712 return "DW_AT_src_info";
9713 case DW_AT_mac_info
:
9714 return "DW_AT_mac_info";
9715 case DW_AT_src_coords
:
9716 return "DW_AT_src_coords";
9717 case DW_AT_body_begin
:
9718 return "DW_AT_body_begin";
9719 case DW_AT_body_end
:
9720 return "DW_AT_body_end";
9721 case DW_AT_GNU_vector
:
9722 return "DW_AT_GNU_vector";
9723 /* VMS extensions. */
9724 case DW_AT_VMS_rtnbeg_pd_address
:
9725 return "DW_AT_VMS_rtnbeg_pd_address";
9726 /* UPC extension. */
9727 case DW_AT_upc_threads_scaled
:
9728 return "DW_AT_upc_threads_scaled";
9729 /* PGI (STMicroelectronics) extensions. */
9730 case DW_AT_PGI_lbase
:
9731 return "DW_AT_PGI_lbase";
9732 case DW_AT_PGI_soffset
:
9733 return "DW_AT_PGI_soffset";
9734 case DW_AT_PGI_lstride
:
9735 return "DW_AT_PGI_lstride";
9737 return "DW_AT_<unknown>";
9741 /* Convert a DWARF value form code into its string name. */
9744 dwarf_form_name (unsigned form
)
9749 return "DW_FORM_addr";
9750 case DW_FORM_block2
:
9751 return "DW_FORM_block2";
9752 case DW_FORM_block4
:
9753 return "DW_FORM_block4";
9755 return "DW_FORM_data2";
9757 return "DW_FORM_data4";
9759 return "DW_FORM_data8";
9760 case DW_FORM_string
:
9761 return "DW_FORM_string";
9763 return "DW_FORM_block";
9764 case DW_FORM_block1
:
9765 return "DW_FORM_block1";
9767 return "DW_FORM_data1";
9769 return "DW_FORM_flag";
9771 return "DW_FORM_sdata";
9773 return "DW_FORM_strp";
9775 return "DW_FORM_udata";
9776 case DW_FORM_ref_addr
:
9777 return "DW_FORM_ref_addr";
9779 return "DW_FORM_ref1";
9781 return "DW_FORM_ref2";
9783 return "DW_FORM_ref4";
9785 return "DW_FORM_ref8";
9786 case DW_FORM_ref_udata
:
9787 return "DW_FORM_ref_udata";
9788 case DW_FORM_indirect
:
9789 return "DW_FORM_indirect";
9790 case DW_FORM_sec_offset
:
9791 return "DW_FORM_sec_offset";
9792 case DW_FORM_exprloc
:
9793 return "DW_FORM_exprloc";
9794 case DW_FORM_flag_present
:
9795 return "DW_FORM_flag_present";
9797 return "DW_FORM_sig8";
9799 return "DW_FORM_<unknown>";
9803 /* Convert a DWARF stack opcode into its string name. */
9806 dwarf_stack_op_name (unsigned op
)
9811 return "DW_OP_addr";
9813 return "DW_OP_deref";
9815 return "DW_OP_const1u";
9817 return "DW_OP_const1s";
9819 return "DW_OP_const2u";
9821 return "DW_OP_const2s";
9823 return "DW_OP_const4u";
9825 return "DW_OP_const4s";
9827 return "DW_OP_const8u";
9829 return "DW_OP_const8s";
9831 return "DW_OP_constu";
9833 return "DW_OP_consts";
9837 return "DW_OP_drop";
9839 return "DW_OP_over";
9841 return "DW_OP_pick";
9843 return "DW_OP_swap";
9847 return "DW_OP_xderef";
9855 return "DW_OP_minus";
9867 return "DW_OP_plus";
9868 case DW_OP_plus_uconst
:
9869 return "DW_OP_plus_uconst";
9875 return "DW_OP_shra";
9893 return "DW_OP_skip";
9895 return "DW_OP_lit0";
9897 return "DW_OP_lit1";
9899 return "DW_OP_lit2";
9901 return "DW_OP_lit3";
9903 return "DW_OP_lit4";
9905 return "DW_OP_lit5";
9907 return "DW_OP_lit6";
9909 return "DW_OP_lit7";
9911 return "DW_OP_lit8";
9913 return "DW_OP_lit9";
9915 return "DW_OP_lit10";
9917 return "DW_OP_lit11";
9919 return "DW_OP_lit12";
9921 return "DW_OP_lit13";
9923 return "DW_OP_lit14";
9925 return "DW_OP_lit15";
9927 return "DW_OP_lit16";
9929 return "DW_OP_lit17";
9931 return "DW_OP_lit18";
9933 return "DW_OP_lit19";
9935 return "DW_OP_lit20";
9937 return "DW_OP_lit21";
9939 return "DW_OP_lit22";
9941 return "DW_OP_lit23";
9943 return "DW_OP_lit24";
9945 return "DW_OP_lit25";
9947 return "DW_OP_lit26";
9949 return "DW_OP_lit27";
9951 return "DW_OP_lit28";
9953 return "DW_OP_lit29";
9955 return "DW_OP_lit30";
9957 return "DW_OP_lit31";
9959 return "DW_OP_reg0";
9961 return "DW_OP_reg1";
9963 return "DW_OP_reg2";
9965 return "DW_OP_reg3";
9967 return "DW_OP_reg4";
9969 return "DW_OP_reg5";
9971 return "DW_OP_reg6";
9973 return "DW_OP_reg7";
9975 return "DW_OP_reg8";
9977 return "DW_OP_reg9";
9979 return "DW_OP_reg10";
9981 return "DW_OP_reg11";
9983 return "DW_OP_reg12";
9985 return "DW_OP_reg13";
9987 return "DW_OP_reg14";
9989 return "DW_OP_reg15";
9991 return "DW_OP_reg16";
9993 return "DW_OP_reg17";
9995 return "DW_OP_reg18";
9997 return "DW_OP_reg19";
9999 return "DW_OP_reg20";
10001 return "DW_OP_reg21";
10003 return "DW_OP_reg22";
10005 return "DW_OP_reg23";
10007 return "DW_OP_reg24";
10009 return "DW_OP_reg25";
10011 return "DW_OP_reg26";
10013 return "DW_OP_reg27";
10015 return "DW_OP_reg28";
10017 return "DW_OP_reg29";
10019 return "DW_OP_reg30";
10021 return "DW_OP_reg31";
10023 return "DW_OP_breg0";
10025 return "DW_OP_breg1";
10027 return "DW_OP_breg2";
10029 return "DW_OP_breg3";
10031 return "DW_OP_breg4";
10033 return "DW_OP_breg5";
10035 return "DW_OP_breg6";
10037 return "DW_OP_breg7";
10039 return "DW_OP_breg8";
10041 return "DW_OP_breg9";
10043 return "DW_OP_breg10";
10045 return "DW_OP_breg11";
10047 return "DW_OP_breg12";
10049 return "DW_OP_breg13";
10051 return "DW_OP_breg14";
10053 return "DW_OP_breg15";
10055 return "DW_OP_breg16";
10057 return "DW_OP_breg17";
10059 return "DW_OP_breg18";
10061 return "DW_OP_breg19";
10063 return "DW_OP_breg20";
10065 return "DW_OP_breg21";
10067 return "DW_OP_breg22";
10069 return "DW_OP_breg23";
10071 return "DW_OP_breg24";
10073 return "DW_OP_breg25";
10075 return "DW_OP_breg26";
10077 return "DW_OP_breg27";
10079 return "DW_OP_breg28";
10081 return "DW_OP_breg29";
10083 return "DW_OP_breg30";
10085 return "DW_OP_breg31";
10087 return "DW_OP_regx";
10089 return "DW_OP_fbreg";
10091 return "DW_OP_bregx";
10093 return "DW_OP_piece";
10094 case DW_OP_deref_size
:
10095 return "DW_OP_deref_size";
10096 case DW_OP_xderef_size
:
10097 return "DW_OP_xderef_size";
10099 return "DW_OP_nop";
10100 /* DWARF 3 extensions. */
10101 case DW_OP_push_object_address
:
10102 return "DW_OP_push_object_address";
10104 return "DW_OP_call2";
10106 return "DW_OP_call4";
10107 case DW_OP_call_ref
:
10108 return "DW_OP_call_ref";
10109 /* GNU extensions. */
10110 case DW_OP_form_tls_address
:
10111 return "DW_OP_form_tls_address";
10112 case DW_OP_call_frame_cfa
:
10113 return "DW_OP_call_frame_cfa";
10114 case DW_OP_bit_piece
:
10115 return "DW_OP_bit_piece";
10116 case DW_OP_GNU_push_tls_address
:
10117 return "DW_OP_GNU_push_tls_address";
10118 case DW_OP_GNU_uninit
:
10119 return "DW_OP_GNU_uninit";
10120 /* HP extensions. */
10121 case DW_OP_HP_is_value
:
10122 return "DW_OP_HP_is_value";
10123 case DW_OP_HP_fltconst4
:
10124 return "DW_OP_HP_fltconst4";
10125 case DW_OP_HP_fltconst8
:
10126 return "DW_OP_HP_fltconst8";
10127 case DW_OP_HP_mod_range
:
10128 return "DW_OP_HP_mod_range";
10129 case DW_OP_HP_unmod_range
:
10130 return "DW_OP_HP_unmod_range";
10132 return "DW_OP_HP_tls";
10134 return "OP_<unknown>";
10139 dwarf_bool_name (unsigned mybool
)
10147 /* Convert a DWARF type code into its string name. */
10150 dwarf_type_encoding_name (unsigned enc
)
10155 return "DW_ATE_void";
10156 case DW_ATE_address
:
10157 return "DW_ATE_address";
10158 case DW_ATE_boolean
:
10159 return "DW_ATE_boolean";
10160 case DW_ATE_complex_float
:
10161 return "DW_ATE_complex_float";
10163 return "DW_ATE_float";
10164 case DW_ATE_signed
:
10165 return "DW_ATE_signed";
10166 case DW_ATE_signed_char
:
10167 return "DW_ATE_signed_char";
10168 case DW_ATE_unsigned
:
10169 return "DW_ATE_unsigned";
10170 case DW_ATE_unsigned_char
:
10171 return "DW_ATE_unsigned_char";
10173 case DW_ATE_imaginary_float
:
10174 return "DW_ATE_imaginary_float";
10175 case DW_ATE_packed_decimal
:
10176 return "DW_ATE_packed_decimal";
10177 case DW_ATE_numeric_string
:
10178 return "DW_ATE_numeric_string";
10179 case DW_ATE_edited
:
10180 return "DW_ATE_edited";
10181 case DW_ATE_signed_fixed
:
10182 return "DW_ATE_signed_fixed";
10183 case DW_ATE_unsigned_fixed
:
10184 return "DW_ATE_unsigned_fixed";
10185 case DW_ATE_decimal_float
:
10186 return "DW_ATE_decimal_float";
10187 /* HP extensions. */
10188 case DW_ATE_HP_float80
:
10189 return "DW_ATE_HP_float80";
10190 case DW_ATE_HP_complex_float80
:
10191 return "DW_ATE_HP_complex_float80";
10192 case DW_ATE_HP_float128
:
10193 return "DW_ATE_HP_float128";
10194 case DW_ATE_HP_complex_float128
:
10195 return "DW_ATE_HP_complex_float128";
10196 case DW_ATE_HP_floathpintel
:
10197 return "DW_ATE_HP_floathpintel";
10198 case DW_ATE_HP_imaginary_float80
:
10199 return "DW_ATE_HP_imaginary_float80";
10200 case DW_ATE_HP_imaginary_float128
:
10201 return "DW_ATE_HP_imaginary_float128";
10203 return "DW_ATE_<unknown>";
10207 /* Convert a DWARF call frame info operation to its string name. */
10211 dwarf_cfi_name (unsigned cfi_opc
)
10215 case DW_CFA_advance_loc
:
10216 return "DW_CFA_advance_loc";
10217 case DW_CFA_offset
:
10218 return "DW_CFA_offset";
10219 case DW_CFA_restore
:
10220 return "DW_CFA_restore";
10222 return "DW_CFA_nop";
10223 case DW_CFA_set_loc
:
10224 return "DW_CFA_set_loc";
10225 case DW_CFA_advance_loc1
:
10226 return "DW_CFA_advance_loc1";
10227 case DW_CFA_advance_loc2
:
10228 return "DW_CFA_advance_loc2";
10229 case DW_CFA_advance_loc4
:
10230 return "DW_CFA_advance_loc4";
10231 case DW_CFA_offset_extended
:
10232 return "DW_CFA_offset_extended";
10233 case DW_CFA_restore_extended
:
10234 return "DW_CFA_restore_extended";
10235 case DW_CFA_undefined
:
10236 return "DW_CFA_undefined";
10237 case DW_CFA_same_value
:
10238 return "DW_CFA_same_value";
10239 case DW_CFA_register
:
10240 return "DW_CFA_register";
10241 case DW_CFA_remember_state
:
10242 return "DW_CFA_remember_state";
10243 case DW_CFA_restore_state
:
10244 return "DW_CFA_restore_state";
10245 case DW_CFA_def_cfa
:
10246 return "DW_CFA_def_cfa";
10247 case DW_CFA_def_cfa_register
:
10248 return "DW_CFA_def_cfa_register";
10249 case DW_CFA_def_cfa_offset
:
10250 return "DW_CFA_def_cfa_offset";
10252 case DW_CFA_def_cfa_expression
:
10253 return "DW_CFA_def_cfa_expression";
10254 case DW_CFA_expression
:
10255 return "DW_CFA_expression";
10256 case DW_CFA_offset_extended_sf
:
10257 return "DW_CFA_offset_extended_sf";
10258 case DW_CFA_def_cfa_sf
:
10259 return "DW_CFA_def_cfa_sf";
10260 case DW_CFA_def_cfa_offset_sf
:
10261 return "DW_CFA_def_cfa_offset_sf";
10262 case DW_CFA_val_offset
:
10263 return "DW_CFA_val_offset";
10264 case DW_CFA_val_offset_sf
:
10265 return "DW_CFA_val_offset_sf";
10266 case DW_CFA_val_expression
:
10267 return "DW_CFA_val_expression";
10268 /* SGI/MIPS specific. */
10269 case DW_CFA_MIPS_advance_loc8
:
10270 return "DW_CFA_MIPS_advance_loc8";
10271 /* GNU extensions. */
10272 case DW_CFA_GNU_window_save
:
10273 return "DW_CFA_GNU_window_save";
10274 case DW_CFA_GNU_args_size
:
10275 return "DW_CFA_GNU_args_size";
10276 case DW_CFA_GNU_negative_offset_extended
:
10277 return "DW_CFA_GNU_negative_offset_extended";
10279 return "DW_CFA_<unknown>";
10285 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10289 print_spaces (indent
, f
);
10290 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10291 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10293 if (die
->parent
!= NULL
)
10295 print_spaces (indent
, f
);
10296 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10297 die
->parent
->offset
);
10300 print_spaces (indent
, f
);
10301 fprintf_unfiltered (f
, " has children: %s\n",
10302 dwarf_bool_name (die
->child
!= NULL
));
10304 print_spaces (indent
, f
);
10305 fprintf_unfiltered (f
, " attributes:\n");
10307 for (i
= 0; i
< die
->num_attrs
; ++i
)
10309 print_spaces (indent
, f
);
10310 fprintf_unfiltered (f
, " %s (%s) ",
10311 dwarf_attr_name (die
->attrs
[i
].name
),
10312 dwarf_form_name (die
->attrs
[i
].form
));
10314 switch (die
->attrs
[i
].form
)
10316 case DW_FORM_ref_addr
:
10318 fprintf_unfiltered (f
, "address: ");
10319 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10321 case DW_FORM_block2
:
10322 case DW_FORM_block4
:
10323 case DW_FORM_block
:
10324 case DW_FORM_block1
:
10325 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10327 case DW_FORM_exprloc
:
10328 fprintf_unfiltered (f
, "expression: size %u",
10329 DW_BLOCK (&die
->attrs
[i
])->size
);
10334 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10335 (long) (DW_ADDR (&die
->attrs
[i
])));
10337 case DW_FORM_data1
:
10338 case DW_FORM_data2
:
10339 case DW_FORM_data4
:
10340 case DW_FORM_data8
:
10341 case DW_FORM_udata
:
10342 case DW_FORM_sdata
:
10343 fprintf_unfiltered (f
, "constant: %s",
10344 pulongest (DW_UNSND (&die
->attrs
[i
])));
10346 case DW_FORM_sec_offset
:
10347 fprintf_unfiltered (f
, "section offset: %s",
10348 pulongest (DW_UNSND (&die
->attrs
[i
])));
10351 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10352 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10353 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10355 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10357 case DW_FORM_string
:
10359 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10360 DW_STRING (&die
->attrs
[i
])
10361 ? DW_STRING (&die
->attrs
[i
]) : "",
10362 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10365 if (DW_UNSND (&die
->attrs
[i
]))
10366 fprintf_unfiltered (f
, "flag: TRUE");
10368 fprintf_unfiltered (f
, "flag: FALSE");
10370 case DW_FORM_flag_present
:
10371 fprintf_unfiltered (f
, "flag: TRUE");
10373 case DW_FORM_indirect
:
10374 /* the reader will have reduced the indirect form to
10375 the "base form" so this form should not occur */
10376 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10379 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10380 die
->attrs
[i
].form
);
10383 fprintf_unfiltered (f
, "\n");
10388 dump_die_for_error (struct die_info
*die
)
10390 dump_die_shallow (gdb_stderr
, 0, die
);
10394 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10396 int indent
= level
* 4;
10398 gdb_assert (die
!= NULL
);
10400 if (level
>= max_level
)
10403 dump_die_shallow (f
, indent
, die
);
10405 if (die
->child
!= NULL
)
10407 print_spaces (indent
, f
);
10408 fprintf_unfiltered (f
, " Children:");
10409 if (level
+ 1 < max_level
)
10411 fprintf_unfiltered (f
, "\n");
10412 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10416 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10420 if (die
->sibling
!= NULL
&& level
> 0)
10422 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10426 /* This is called from the pdie macro in gdbinit.in.
10427 It's not static so gcc will keep a copy callable from gdb. */
10430 dump_die (struct die_info
*die
, int max_level
)
10432 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10436 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10440 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10446 is_ref_attr (struct attribute
*attr
)
10448 switch (attr
->form
)
10450 case DW_FORM_ref_addr
:
10455 case DW_FORM_ref_udata
:
10462 static unsigned int
10463 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10465 if (is_ref_attr (attr
))
10466 return DW_ADDR (attr
);
10468 complaint (&symfile_complaints
,
10469 _("unsupported die ref attribute form: '%s'"),
10470 dwarf_form_name (attr
->form
));
10474 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10475 * the value held by the attribute is not constant. */
10478 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10480 if (attr
->form
== DW_FORM_sdata
)
10481 return DW_SND (attr
);
10482 else if (attr
->form
== DW_FORM_udata
10483 || attr
->form
== DW_FORM_data1
10484 || attr
->form
== DW_FORM_data2
10485 || attr
->form
== DW_FORM_data4
10486 || attr
->form
== DW_FORM_data8
)
10487 return DW_UNSND (attr
);
10490 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10491 dwarf_form_name (attr
->form
));
10492 return default_value
;
10496 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10497 unit and add it to our queue.
10498 The result is non-zero if PER_CU was queued, otherwise the result is zero
10499 meaning either PER_CU is already queued or it is already loaded. */
10502 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10503 struct dwarf2_per_cu_data
*per_cu
)
10505 /* Mark the dependence relation so that we don't flush PER_CU
10507 dwarf2_add_dependence (this_cu
, per_cu
);
10509 /* If it's already on the queue, we have nothing to do. */
10510 if (per_cu
->queued
)
10513 /* If the compilation unit is already loaded, just mark it as
10515 if (per_cu
->cu
!= NULL
)
10517 per_cu
->cu
->last_used
= 0;
10521 /* Add it to the queue. */
10522 queue_comp_unit (per_cu
, this_cu
->objfile
);
10527 /* Follow reference or signature attribute ATTR of SRC_DIE.
10528 On entry *REF_CU is the CU of SRC_DIE.
10529 On exit *REF_CU is the CU of the result. */
10531 static struct die_info
*
10532 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10533 struct dwarf2_cu
**ref_cu
)
10535 struct die_info
*die
;
10537 if (is_ref_attr (attr
))
10538 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10539 else if (attr
->form
== DW_FORM_sig8
)
10540 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10543 dump_die_for_error (src_die
);
10544 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10545 (*ref_cu
)->objfile
->name
);
10551 /* Follow reference attribute ATTR of SRC_DIE.
10552 On entry *REF_CU is the CU of SRC_DIE.
10553 On exit *REF_CU is the CU of the result. */
10555 static struct die_info
*
10556 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10557 struct dwarf2_cu
**ref_cu
)
10559 struct die_info
*die
;
10560 unsigned int offset
;
10561 struct die_info temp_die
;
10562 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10564 gdb_assert (cu
->per_cu
!= NULL
);
10566 offset
= dwarf2_get_ref_die_offset (attr
);
10568 if (cu
->per_cu
->from_debug_types
)
10570 /* .debug_types CUs cannot reference anything outside their CU.
10571 If they need to, they have to reference a signatured type via
10573 if (! offset_in_cu_p (&cu
->header
, offset
))
10577 else if (! offset_in_cu_p (&cu
->header
, offset
))
10579 struct dwarf2_per_cu_data
*per_cu
;
10580 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10582 /* If necessary, add it to the queue and load its DIEs. */
10583 if (maybe_queue_comp_unit (cu
, per_cu
))
10584 load_full_comp_unit (per_cu
, cu
->objfile
);
10586 target_cu
= per_cu
->cu
;
10591 *ref_cu
= target_cu
;
10592 temp_die
.offset
= offset
;
10593 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10599 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10600 "at 0x%x [in module %s]"),
10601 offset
, src_die
->offset
, cu
->objfile
->name
);
10604 /* Follow the signature attribute ATTR in SRC_DIE.
10605 On entry *REF_CU is the CU of SRC_DIE.
10606 On exit *REF_CU is the CU of the result. */
10608 static struct die_info
*
10609 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10610 struct dwarf2_cu
**ref_cu
)
10612 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10613 struct die_info temp_die
;
10614 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10615 struct dwarf2_cu
*sig_cu
;
10616 struct die_info
*die
;
10618 /* sig_type will be NULL if the signatured type is missing from
10620 if (sig_type
== NULL
)
10621 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10622 "at 0x%x [in module %s]"),
10623 src_die
->offset
, objfile
->name
);
10625 /* If necessary, add it to the queue and load its DIEs. */
10627 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10628 read_signatured_type (objfile
, sig_type
);
10630 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10632 sig_cu
= sig_type
->per_cu
.cu
;
10633 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10634 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10641 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10642 "at 0x%x [in module %s]"),
10643 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10646 /* Given an offset of a signatured type, return its signatured_type. */
10648 static struct signatured_type
*
10649 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10651 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10652 unsigned int length
, initial_length_size
;
10653 unsigned int sig_offset
;
10654 struct signatured_type find_entry
, *type_sig
;
10656 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10657 sig_offset
= (initial_length_size
10659 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10660 + 1 /*address_size*/);
10661 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10662 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10664 /* This is only used to lookup previously recorded types.
10665 If we didn't find it, it's our bug. */
10666 gdb_assert (type_sig
!= NULL
);
10667 gdb_assert (offset
== type_sig
->offset
);
10672 /* Read in signatured type at OFFSET and build its CU and die(s). */
10675 read_signatured_type_at_offset (struct objfile
*objfile
,
10676 unsigned int offset
)
10678 struct signatured_type
*type_sig
;
10680 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
10682 /* We have the section offset, but we need the signature to do the
10683 hash table lookup. */
10684 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10686 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10688 read_signatured_type (objfile
, type_sig
);
10690 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10693 /* Read in a signatured type and build its CU and DIEs. */
10696 read_signatured_type (struct objfile
*objfile
,
10697 struct signatured_type
*type_sig
)
10699 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10700 struct die_reader_specs reader_specs
;
10701 struct dwarf2_cu
*cu
;
10702 ULONGEST signature
;
10703 struct cleanup
*back_to
, *free_cu_cleanup
;
10704 struct attribute
*attr
;
10706 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10708 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10709 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10710 obstack_init (&cu
->comp_unit_obstack
);
10711 cu
->objfile
= objfile
;
10712 type_sig
->per_cu
.cu
= cu
;
10713 cu
->per_cu
= &type_sig
->per_cu
;
10715 /* If an error occurs while loading, release our storage. */
10716 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10718 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10719 types_ptr
, objfile
->obfd
);
10720 gdb_assert (signature
== type_sig
->signature
);
10723 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10727 &cu
->comp_unit_obstack
,
10728 hashtab_obstack_allocate
,
10729 dummy_obstack_deallocate
);
10731 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10732 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10734 init_cu_die_reader (&reader_specs
, cu
);
10736 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10739 /* We try not to read any attributes in this function, because not
10740 all objfiles needed for references have been loaded yet, and symbol
10741 table processing isn't initialized. But we have to set the CU language,
10742 or we won't be able to build types correctly. */
10743 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10745 set_cu_language (DW_UNSND (attr
), cu
);
10747 set_cu_language (language_minimal
, cu
);
10749 do_cleanups (back_to
);
10751 /* We've successfully allocated this compilation unit. Let our caller
10752 clean it up when finished with it. */
10753 discard_cleanups (free_cu_cleanup
);
10755 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10756 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10759 /* Decode simple location descriptions.
10760 Given a pointer to a dwarf block that defines a location, compute
10761 the location and return the value.
10763 NOTE drow/2003-11-18: This function is called in two situations
10764 now: for the address of static or global variables (partial symbols
10765 only) and for offsets into structures which are expected to be
10766 (more or less) constant. The partial symbol case should go away,
10767 and only the constant case should remain. That will let this
10768 function complain more accurately. A few special modes are allowed
10769 without complaint for global variables (for instance, global
10770 register values and thread-local values).
10772 A location description containing no operations indicates that the
10773 object is optimized out. The return value is 0 for that case.
10774 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10775 callers will only want a very basic result and this can become a
10778 Note that stack[0] is unused except as a default error return.
10779 Note that stack overflow is not yet handled. */
10782 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10784 struct objfile
*objfile
= cu
->objfile
;
10786 int size
= blk
->size
;
10787 gdb_byte
*data
= blk
->data
;
10788 CORE_ADDR stack
[64];
10790 unsigned int bytes_read
, unsnd
;
10834 stack
[++stacki
] = op
- DW_OP_lit0
;
10869 stack
[++stacki
] = op
- DW_OP_reg0
;
10871 dwarf2_complex_location_expr_complaint ();
10875 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10877 stack
[++stacki
] = unsnd
;
10879 dwarf2_complex_location_expr_complaint ();
10883 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
10888 case DW_OP_const1u
:
10889 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
10893 case DW_OP_const1s
:
10894 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
10898 case DW_OP_const2u
:
10899 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
10903 case DW_OP_const2s
:
10904 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
10908 case DW_OP_const4u
:
10909 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
10913 case DW_OP_const4s
:
10914 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
10919 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
10925 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
10930 stack
[stacki
+ 1] = stack
[stacki
];
10935 stack
[stacki
- 1] += stack
[stacki
];
10939 case DW_OP_plus_uconst
:
10940 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10945 stack
[stacki
- 1] -= stack
[stacki
];
10950 /* If we're not the last op, then we definitely can't encode
10951 this using GDB's address_class enum. This is valid for partial
10952 global symbols, although the variable's address will be bogus
10955 dwarf2_complex_location_expr_complaint ();
10958 case DW_OP_GNU_push_tls_address
:
10959 /* The top of the stack has the offset from the beginning
10960 of the thread control block at which the variable is located. */
10961 /* Nothing should follow this operator, so the top of stack would
10963 /* This is valid for partial global symbols, but the variable's
10964 address will be bogus in the psymtab. */
10966 dwarf2_complex_location_expr_complaint ();
10969 case DW_OP_GNU_uninit
:
10973 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
10974 dwarf_stack_op_name (op
));
10975 return (stack
[stacki
]);
10978 return (stack
[stacki
]);
10981 /* memory allocation interface */
10983 static struct dwarf_block
*
10984 dwarf_alloc_block (struct dwarf2_cu
*cu
)
10986 struct dwarf_block
*blk
;
10988 blk
= (struct dwarf_block
*)
10989 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
10993 static struct abbrev_info
*
10994 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
10996 struct abbrev_info
*abbrev
;
10998 abbrev
= (struct abbrev_info
*)
10999 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
11000 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11004 static struct die_info
*
11005 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
11007 struct die_info
*die
;
11008 size_t size
= sizeof (struct die_info
);
11011 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
11013 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
11014 memset (die
, 0, sizeof (struct die_info
));
11019 /* Macro support. */
11022 /* Return the full name of file number I in *LH's file name table.
11023 Use COMP_DIR as the name of the current directory of the
11024 compilation. The result is allocated using xmalloc; the caller is
11025 responsible for freeing it. */
11027 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
11029 /* Is the file number a valid index into the line header's file name
11030 table? Remember that file numbers start with one, not zero. */
11031 if (1 <= file
&& file
<= lh
->num_file_names
)
11033 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11035 if (IS_ABSOLUTE_PATH (fe
->name
))
11036 return xstrdup (fe
->name
);
11044 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11050 dir_len
= strlen (dir
);
11051 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
11052 strcpy (full_name
, dir
);
11053 full_name
[dir_len
] = '/';
11054 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
11058 return xstrdup (fe
->name
);
11063 /* The compiler produced a bogus file number. We can at least
11064 record the macro definitions made in the file, even if we
11065 won't be able to find the file by name. */
11066 char fake_name
[80];
11067 sprintf (fake_name
, "<bad macro file number %d>", file
);
11069 complaint (&symfile_complaints
,
11070 _("bad file number in macro information (%d)"),
11073 return xstrdup (fake_name
);
11078 static struct macro_source_file
*
11079 macro_start_file (int file
, int line
,
11080 struct macro_source_file
*current_file
,
11081 const char *comp_dir
,
11082 struct line_header
*lh
, struct objfile
*objfile
)
11084 /* The full name of this source file. */
11085 char *full_name
= file_full_name (file
, lh
, comp_dir
);
11087 /* We don't create a macro table for this compilation unit
11088 at all until we actually get a filename. */
11089 if (! pending_macros
)
11090 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
11091 objfile
->macro_cache
);
11093 if (! current_file
)
11094 /* If we have no current file, then this must be the start_file
11095 directive for the compilation unit's main source file. */
11096 current_file
= macro_set_main (pending_macros
, full_name
);
11098 current_file
= macro_include (current_file
, line
, full_name
);
11102 return current_file
;
11106 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
11107 followed by a null byte. */
11109 copy_string (const char *buf
, int len
)
11111 char *s
= xmalloc (len
+ 1);
11112 memcpy (s
, buf
, len
);
11119 static const char *
11120 consume_improper_spaces (const char *p
, const char *body
)
11124 complaint (&symfile_complaints
,
11125 _("macro definition contains spaces in formal argument list:\n`%s'"),
11137 parse_macro_definition (struct macro_source_file
*file
, int line
,
11142 /* The body string takes one of two forms. For object-like macro
11143 definitions, it should be:
11145 <macro name> " " <definition>
11147 For function-like macro definitions, it should be:
11149 <macro name> "() " <definition>
11151 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
11153 Spaces may appear only where explicitly indicated, and in the
11156 The Dwarf 2 spec says that an object-like macro's name is always
11157 followed by a space, but versions of GCC around March 2002 omit
11158 the space when the macro's definition is the empty string.
11160 The Dwarf 2 spec says that there should be no spaces between the
11161 formal arguments in a function-like macro's formal argument list,
11162 but versions of GCC around March 2002 include spaces after the
11166 /* Find the extent of the macro name. The macro name is terminated
11167 by either a space or null character (for an object-like macro) or
11168 an opening paren (for a function-like macro). */
11169 for (p
= body
; *p
; p
++)
11170 if (*p
== ' ' || *p
== '(')
11173 if (*p
== ' ' || *p
== '\0')
11175 /* It's an object-like macro. */
11176 int name_len
= p
- body
;
11177 char *name
= copy_string (body
, name_len
);
11178 const char *replacement
;
11181 replacement
= body
+ name_len
+ 1;
11184 dwarf2_macro_malformed_definition_complaint (body
);
11185 replacement
= body
+ name_len
;
11188 macro_define_object (file
, line
, name
, replacement
);
11192 else if (*p
== '(')
11194 /* It's a function-like macro. */
11195 char *name
= copy_string (body
, p
- body
);
11198 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
11202 p
= consume_improper_spaces (p
, body
);
11204 /* Parse the formal argument list. */
11205 while (*p
&& *p
!= ')')
11207 /* Find the extent of the current argument name. */
11208 const char *arg_start
= p
;
11210 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11213 if (! *p
|| p
== arg_start
)
11214 dwarf2_macro_malformed_definition_complaint (body
);
11217 /* Make sure argv has room for the new argument. */
11218 if (argc
>= argv_size
)
11221 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11224 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11227 p
= consume_improper_spaces (p
, body
);
11229 /* Consume the comma, if present. */
11234 p
= consume_improper_spaces (p
, body
);
11243 /* Perfectly formed definition, no complaints. */
11244 macro_define_function (file
, line
, name
,
11245 argc
, (const char **) argv
,
11247 else if (*p
== '\0')
11249 /* Complain, but do define it. */
11250 dwarf2_macro_malformed_definition_complaint (body
);
11251 macro_define_function (file
, line
, name
,
11252 argc
, (const char **) argv
,
11256 /* Just complain. */
11257 dwarf2_macro_malformed_definition_complaint (body
);
11260 /* Just complain. */
11261 dwarf2_macro_malformed_definition_complaint (body
);
11267 for (i
= 0; i
< argc
; i
++)
11273 dwarf2_macro_malformed_definition_complaint (body
);
11278 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11279 char *comp_dir
, bfd
*abfd
,
11280 struct dwarf2_cu
*cu
)
11282 gdb_byte
*mac_ptr
, *mac_end
;
11283 struct macro_source_file
*current_file
= 0;
11284 enum dwarf_macinfo_record_type macinfo_type
;
11285 int at_commandline
;
11287 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11288 &dwarf2_per_objfile
->macinfo
);
11289 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11291 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11295 /* First pass: Find the name of the base filename.
11296 This filename is needed in order to process all macros whose definition
11297 (or undefinition) comes from the command line. These macros are defined
11298 before the first DW_MACINFO_start_file entry, and yet still need to be
11299 associated to the base file.
11301 To determine the base file name, we scan the macro definitions until we
11302 reach the first DW_MACINFO_start_file entry. We then initialize
11303 CURRENT_FILE accordingly so that any macro definition found before the
11304 first DW_MACINFO_start_file can still be associated to the base file. */
11306 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11307 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11308 + dwarf2_per_objfile
->macinfo
.size
;
11312 /* Do we at least have room for a macinfo type byte? */
11313 if (mac_ptr
>= mac_end
)
11315 /* Complaint is printed during the second pass as GDB will probably
11316 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11320 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11323 switch (macinfo_type
)
11325 /* A zero macinfo type indicates the end of the macro
11330 case DW_MACINFO_define
:
11331 case DW_MACINFO_undef
:
11332 /* Only skip the data by MAC_PTR. */
11334 unsigned int bytes_read
;
11336 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11337 mac_ptr
+= bytes_read
;
11338 read_string (abfd
, mac_ptr
, &bytes_read
);
11339 mac_ptr
+= bytes_read
;
11343 case DW_MACINFO_start_file
:
11345 unsigned int bytes_read
;
11348 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11349 mac_ptr
+= bytes_read
;
11350 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11351 mac_ptr
+= bytes_read
;
11353 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11358 case DW_MACINFO_end_file
:
11359 /* No data to skip by MAC_PTR. */
11362 case DW_MACINFO_vendor_ext
:
11363 /* Only skip the data by MAC_PTR. */
11365 unsigned int bytes_read
;
11367 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11368 mac_ptr
+= bytes_read
;
11369 read_string (abfd
, mac_ptr
, &bytes_read
);
11370 mac_ptr
+= bytes_read
;
11377 } while (macinfo_type
!= 0 && current_file
== NULL
);
11379 /* Second pass: Process all entries.
11381 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11382 command-line macro definitions/undefinitions. This flag is unset when we
11383 reach the first DW_MACINFO_start_file entry. */
11385 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11387 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11388 GDB is still reading the definitions from command line. First
11389 DW_MACINFO_start_file will need to be ignored as it was already executed
11390 to create CURRENT_FILE for the main source holding also the command line
11391 definitions. On first met DW_MACINFO_start_file this flag is reset to
11392 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11394 at_commandline
= 1;
11398 /* Do we at least have room for a macinfo type byte? */
11399 if (mac_ptr
>= mac_end
)
11401 dwarf2_macros_too_long_complaint ();
11405 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11408 switch (macinfo_type
)
11410 /* A zero macinfo type indicates the end of the macro
11415 case DW_MACINFO_define
:
11416 case DW_MACINFO_undef
:
11418 unsigned int bytes_read
;
11422 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11423 mac_ptr
+= bytes_read
;
11424 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11425 mac_ptr
+= bytes_read
;
11427 if (! current_file
)
11429 /* DWARF violation as no main source is present. */
11430 complaint (&symfile_complaints
,
11431 _("debug info with no main source gives macro %s "
11433 macinfo_type
== DW_MACINFO_define
?
11435 macinfo_type
== DW_MACINFO_undef
?
11436 _("undefinition") :
11437 _("something-or-other"), line
, body
);
11440 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11441 complaint (&symfile_complaints
,
11442 _("debug info gives %s macro %s with %s line %d: %s"),
11443 at_commandline
? _("command-line") : _("in-file"),
11444 macinfo_type
== DW_MACINFO_define
?
11446 macinfo_type
== DW_MACINFO_undef
?
11447 _("undefinition") :
11448 _("something-or-other"),
11449 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11451 if (macinfo_type
== DW_MACINFO_define
)
11452 parse_macro_definition (current_file
, line
, body
);
11453 else if (macinfo_type
== DW_MACINFO_undef
)
11454 macro_undef (current_file
, line
, body
);
11458 case DW_MACINFO_start_file
:
11460 unsigned int bytes_read
;
11463 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11464 mac_ptr
+= bytes_read
;
11465 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11466 mac_ptr
+= bytes_read
;
11468 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11469 complaint (&symfile_complaints
,
11470 _("debug info gives source %d included "
11471 "from %s at %s line %d"),
11472 file
, at_commandline
? _("command-line") : _("file"),
11473 line
== 0 ? _("zero") : _("non-zero"), line
);
11475 if (at_commandline
)
11477 /* This DW_MACINFO_start_file was executed in the pass one. */
11478 at_commandline
= 0;
11481 current_file
= macro_start_file (file
, line
,
11482 current_file
, comp_dir
,
11487 case DW_MACINFO_end_file
:
11488 if (! current_file
)
11489 complaint (&symfile_complaints
,
11490 _("macro debug info has an unmatched `close_file' directive"));
11493 current_file
= current_file
->included_by
;
11494 if (! current_file
)
11496 enum dwarf_macinfo_record_type next_type
;
11498 /* GCC circa March 2002 doesn't produce the zero
11499 type byte marking the end of the compilation
11500 unit. Complain if it's not there, but exit no
11503 /* Do we at least have room for a macinfo type byte? */
11504 if (mac_ptr
>= mac_end
)
11506 dwarf2_macros_too_long_complaint ();
11510 /* We don't increment mac_ptr here, so this is just
11512 next_type
= read_1_byte (abfd
, mac_ptr
);
11513 if (next_type
!= 0)
11514 complaint (&symfile_complaints
,
11515 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11522 case DW_MACINFO_vendor_ext
:
11524 unsigned int bytes_read
;
11528 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11529 mac_ptr
+= bytes_read
;
11530 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11531 mac_ptr
+= bytes_read
;
11533 /* We don't recognize any vendor extensions. */
11537 } while (macinfo_type
!= 0);
11540 /* Check if the attribute's form is a DW_FORM_block*
11541 if so return true else false. */
11543 attr_form_is_block (struct attribute
*attr
)
11545 return (attr
== NULL
? 0 :
11546 attr
->form
== DW_FORM_block1
11547 || attr
->form
== DW_FORM_block2
11548 || attr
->form
== DW_FORM_block4
11549 || attr
->form
== DW_FORM_block
11550 || attr
->form
== DW_FORM_exprloc
);
11553 /* Return non-zero if ATTR's value is a section offset --- classes
11554 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11555 You may use DW_UNSND (attr) to retrieve such offsets.
11557 Section 7.5.4, "Attribute Encodings", explains that no attribute
11558 may have a value that belongs to more than one of these classes; it
11559 would be ambiguous if we did, because we use the same forms for all
11562 attr_form_is_section_offset (struct attribute
*attr
)
11564 return (attr
->form
== DW_FORM_data4
11565 || attr
->form
== DW_FORM_data8
11566 || attr
->form
== DW_FORM_sec_offset
);
11570 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11571 zero otherwise. When this function returns true, you can apply
11572 dwarf2_get_attr_constant_value to it.
11574 However, note that for some attributes you must check
11575 attr_form_is_section_offset before using this test. DW_FORM_data4
11576 and DW_FORM_data8 are members of both the constant class, and of
11577 the classes that contain offsets into other debug sections
11578 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11579 that, if an attribute's can be either a constant or one of the
11580 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11581 taken as section offsets, not constants. */
11583 attr_form_is_constant (struct attribute
*attr
)
11585 switch (attr
->form
)
11587 case DW_FORM_sdata
:
11588 case DW_FORM_udata
:
11589 case DW_FORM_data1
:
11590 case DW_FORM_data2
:
11591 case DW_FORM_data4
:
11592 case DW_FORM_data8
:
11600 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11601 struct dwarf2_cu
*cu
)
11603 if (attr_form_is_section_offset (attr
)
11604 /* ".debug_loc" may not exist at all, or the offset may be outside
11605 the section. If so, fall through to the complaint in the
11607 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11609 struct dwarf2_loclist_baton
*baton
;
11611 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11612 sizeof (struct dwarf2_loclist_baton
));
11613 baton
->per_cu
= cu
->per_cu
;
11614 gdb_assert (baton
->per_cu
);
11616 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11617 &dwarf2_per_objfile
->loc
);
11619 /* We don't know how long the location list is, but make sure we
11620 don't run off the edge of the section. */
11621 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11622 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11623 baton
->base_address
= cu
->base_address
;
11624 if (cu
->base_known
== 0)
11625 complaint (&symfile_complaints
,
11626 _("Location list used without specifying the CU base address."));
11628 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11629 SYMBOL_LOCATION_BATON (sym
) = baton
;
11633 struct dwarf2_locexpr_baton
*baton
;
11635 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11636 sizeof (struct dwarf2_locexpr_baton
));
11637 baton
->per_cu
= cu
->per_cu
;
11638 gdb_assert (baton
->per_cu
);
11640 if (attr_form_is_block (attr
))
11642 /* Note that we're just copying the block's data pointer
11643 here, not the actual data. We're still pointing into the
11644 info_buffer for SYM's objfile; right now we never release
11645 that buffer, but when we do clean up properly this may
11647 baton
->size
= DW_BLOCK (attr
)->size
;
11648 baton
->data
= DW_BLOCK (attr
)->data
;
11652 dwarf2_invalid_attrib_class_complaint ("location description",
11653 SYMBOL_NATURAL_NAME (sym
));
11655 baton
->data
= NULL
;
11658 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11659 SYMBOL_LOCATION_BATON (sym
) = baton
;
11663 /* Return the OBJFILE associated with the compilation unit CU. */
11666 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11668 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11670 /* Return the master objfile, so that we can report and look up the
11671 correct file containing this variable. */
11672 if (objfile
->separate_debug_objfile_backlink
)
11673 objfile
= objfile
->separate_debug_objfile_backlink
;
11678 /* Return the address size given in the compilation unit header for CU. */
11681 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11684 return per_cu
->cu
->header
.addr_size
;
11687 /* If the CU is not currently read in, we re-read its header. */
11688 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11689 struct dwarf2_per_objfile
*per_objfile
11690 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11691 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11693 struct comp_unit_head cu_header
;
11694 memset (&cu_header
, 0, sizeof cu_header
);
11695 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11696 return cu_header
.addr_size
;
11700 /* Locate the .debug_info compilation unit from CU's objfile which contains
11701 the DIE at OFFSET. Raises an error on failure. */
11703 static struct dwarf2_per_cu_data
*
11704 dwarf2_find_containing_comp_unit (unsigned int offset
,
11705 struct objfile
*objfile
)
11707 struct dwarf2_per_cu_data
*this_cu
;
11711 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11714 int mid
= low
+ (high
- low
) / 2;
11715 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11720 gdb_assert (low
== high
);
11721 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11724 error (_("Dwarf Error: could not find partial DIE containing "
11725 "offset 0x%lx [in module %s]"),
11726 (long) offset
, bfd_get_filename (objfile
->obfd
));
11728 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11729 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11733 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11734 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11735 && offset
>= this_cu
->offset
+ this_cu
->length
)
11736 error (_("invalid dwarf2 offset %u"), offset
);
11737 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11742 /* Locate the compilation unit from OBJFILE which is located at exactly
11743 OFFSET. Raises an error on failure. */
11745 static struct dwarf2_per_cu_data
*
11746 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11748 struct dwarf2_per_cu_data
*this_cu
;
11749 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11750 if (this_cu
->offset
!= offset
)
11751 error (_("no compilation unit with offset %u."), offset
);
11755 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11757 static struct dwarf2_cu
*
11758 alloc_one_comp_unit (struct objfile
*objfile
)
11760 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11761 cu
->objfile
= objfile
;
11762 obstack_init (&cu
->comp_unit_obstack
);
11766 /* Release one cached compilation unit, CU. We unlink it from the tree
11767 of compilation units, but we don't remove it from the read_in_chain;
11768 the caller is responsible for that.
11769 NOTE: DATA is a void * because this function is also used as a
11770 cleanup routine. */
11773 free_one_comp_unit (void *data
)
11775 struct dwarf2_cu
*cu
= data
;
11777 if (cu
->per_cu
!= NULL
)
11778 cu
->per_cu
->cu
= NULL
;
11781 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11786 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11787 when we're finished with it. We can't free the pointer itself, but be
11788 sure to unlink it from the cache. Also release any associated storage
11789 and perform cache maintenance.
11791 Only used during partial symbol parsing. */
11794 free_stack_comp_unit (void *data
)
11796 struct dwarf2_cu
*cu
= data
;
11798 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11799 cu
->partial_dies
= NULL
;
11801 if (cu
->per_cu
!= NULL
)
11803 /* This compilation unit is on the stack in our caller, so we
11804 should not xfree it. Just unlink it. */
11805 cu
->per_cu
->cu
= NULL
;
11808 /* If we had a per-cu pointer, then we may have other compilation
11809 units loaded, so age them now. */
11810 age_cached_comp_units ();
11814 /* Free all cached compilation units. */
11817 free_cached_comp_units (void *data
)
11819 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11821 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11822 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11823 while (per_cu
!= NULL
)
11825 struct dwarf2_per_cu_data
*next_cu
;
11827 next_cu
= per_cu
->cu
->read_in_chain
;
11829 free_one_comp_unit (per_cu
->cu
);
11830 *last_chain
= next_cu
;
11836 /* Increase the age counter on each cached compilation unit, and free
11837 any that are too old. */
11840 age_cached_comp_units (void)
11842 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11844 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
11845 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11846 while (per_cu
!= NULL
)
11848 per_cu
->cu
->last_used
++;
11849 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
11850 dwarf2_mark (per_cu
->cu
);
11851 per_cu
= per_cu
->cu
->read_in_chain
;
11854 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11855 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11856 while (per_cu
!= NULL
)
11858 struct dwarf2_per_cu_data
*next_cu
;
11860 next_cu
= per_cu
->cu
->read_in_chain
;
11862 if (!per_cu
->cu
->mark
)
11864 free_one_comp_unit (per_cu
->cu
);
11865 *last_chain
= next_cu
;
11868 last_chain
= &per_cu
->cu
->read_in_chain
;
11874 /* Remove a single compilation unit from the cache. */
11877 free_one_cached_comp_unit (void *target_cu
)
11879 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11881 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11882 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11883 while (per_cu
!= NULL
)
11885 struct dwarf2_per_cu_data
*next_cu
;
11887 next_cu
= per_cu
->cu
->read_in_chain
;
11889 if (per_cu
->cu
== target_cu
)
11891 free_one_comp_unit (per_cu
->cu
);
11892 *last_chain
= next_cu
;
11896 last_chain
= &per_cu
->cu
->read_in_chain
;
11902 /* Release all extra memory associated with OBJFILE. */
11905 dwarf2_free_objfile (struct objfile
*objfile
)
11907 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
11909 if (dwarf2_per_objfile
== NULL
)
11912 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11913 free_cached_comp_units (NULL
);
11915 /* Everything else should be on the objfile obstack. */
11918 /* A pair of DIE offset and GDB type pointer. We store these
11919 in a hash table separate from the DIEs, and preserve them
11920 when the DIEs are flushed out of cache. */
11922 struct dwarf2_offset_and_type
11924 unsigned int offset
;
11928 /* Hash function for a dwarf2_offset_and_type. */
11931 offset_and_type_hash (const void *item
)
11933 const struct dwarf2_offset_and_type
*ofs
= item
;
11934 return ofs
->offset
;
11937 /* Equality function for a dwarf2_offset_and_type. */
11940 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
11942 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
11943 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
11944 return ofs_lhs
->offset
== ofs_rhs
->offset
;
11947 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11948 table if necessary. For convenience, return TYPE. */
11950 static struct type
*
11951 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11953 struct dwarf2_offset_and_type
**slot
, ofs
;
11955 /* For Ada types, make sure that the gnat-specific data is always
11956 initialized (if not already set). There are a few types where
11957 we should not be doing so, because the type-specific area is
11958 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11959 where the type-specific area is used to store the floatformat).
11960 But this is not a problem, because the gnat-specific information
11961 is actually not needed for these types. */
11962 if (need_gnat_info (cu
)
11963 && TYPE_CODE (type
) != TYPE_CODE_FUNC
11964 && TYPE_CODE (type
) != TYPE_CODE_FLT
11965 && !HAVE_GNAT_AUX_INFO (type
))
11966 INIT_GNAT_SPECIFIC (type
);
11968 if (cu
->type_hash
== NULL
)
11970 gdb_assert (cu
->per_cu
!= NULL
);
11971 cu
->per_cu
->type_hash
11972 = htab_create_alloc_ex (cu
->header
.length
/ 24,
11973 offset_and_type_hash
,
11974 offset_and_type_eq
,
11976 &cu
->objfile
->objfile_obstack
,
11977 hashtab_obstack_allocate
,
11978 dummy_obstack_deallocate
);
11979 cu
->type_hash
= cu
->per_cu
->type_hash
;
11982 ofs
.offset
= die
->offset
;
11984 slot
= (struct dwarf2_offset_and_type
**)
11985 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
11986 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
11991 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
11992 not have a saved type. */
11994 static struct type
*
11995 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11997 struct dwarf2_offset_and_type
*slot
, ofs
;
11998 htab_t type_hash
= cu
->type_hash
;
12000 if (type_hash
== NULL
)
12003 ofs
.offset
= die
->offset
;
12004 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
12011 /* Add a dependence relationship from CU to REF_PER_CU. */
12014 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
12015 struct dwarf2_per_cu_data
*ref_per_cu
)
12019 if (cu
->dependencies
== NULL
)
12021 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
12022 NULL
, &cu
->comp_unit_obstack
,
12023 hashtab_obstack_allocate
,
12024 dummy_obstack_deallocate
);
12026 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
12028 *slot
= ref_per_cu
;
12031 /* Subroutine of dwarf2_mark to pass to htab_traverse.
12032 Set the mark field in every compilation unit in the
12033 cache that we must keep because we are keeping CU. */
12036 dwarf2_mark_helper (void **slot
, void *data
)
12038 struct dwarf2_per_cu_data
*per_cu
;
12040 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
12041 if (per_cu
->cu
->mark
)
12043 per_cu
->cu
->mark
= 1;
12045 if (per_cu
->cu
->dependencies
!= NULL
)
12046 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
12051 /* Set the mark field in CU and in every other compilation unit in the
12052 cache that we must keep because we are keeping CU. */
12055 dwarf2_mark (struct dwarf2_cu
*cu
)
12060 if (cu
->dependencies
!= NULL
)
12061 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
12065 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
12069 per_cu
->cu
->mark
= 0;
12070 per_cu
= per_cu
->cu
->read_in_chain
;
12074 /* Trivial hash function for partial_die_info: the hash value of a DIE
12075 is its offset in .debug_info for this objfile. */
12078 partial_die_hash (const void *item
)
12080 const struct partial_die_info
*part_die
= item
;
12081 return part_die
->offset
;
12084 /* Trivial comparison function for partial_die_info structures: two DIEs
12085 are equal if they have the same offset. */
12088 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
12090 const struct partial_die_info
*part_die_lhs
= item_lhs
;
12091 const struct partial_die_info
*part_die_rhs
= item_rhs
;
12092 return part_die_lhs
->offset
== part_die_rhs
->offset
;
12095 static struct cmd_list_element
*set_dwarf2_cmdlist
;
12096 static struct cmd_list_element
*show_dwarf2_cmdlist
;
12099 set_dwarf2_cmd (char *args
, int from_tty
)
12101 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
12105 show_dwarf2_cmd (char *args
, int from_tty
)
12107 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
12110 /* If section described by INFO was mmapped, munmap it now. */
12113 munmap_section_buffer (struct dwarf2_section_info
*info
)
12115 if (info
->was_mmapped
)
12118 intptr_t begin
= (intptr_t) info
->buffer
;
12119 intptr_t map_begin
= begin
& ~(pagesize
- 1);
12120 size_t map_length
= info
->size
+ begin
- map_begin
;
12121 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
12123 /* Without HAVE_MMAP, we should never be here to begin with. */
12129 /* munmap debug sections for OBJFILE, if necessary. */
12132 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
12134 struct dwarf2_per_objfile
*data
= d
;
12135 munmap_section_buffer (&data
->info
);
12136 munmap_section_buffer (&data
->abbrev
);
12137 munmap_section_buffer (&data
->line
);
12138 munmap_section_buffer (&data
->str
);
12139 munmap_section_buffer (&data
->macinfo
);
12140 munmap_section_buffer (&data
->ranges
);
12141 munmap_section_buffer (&data
->loc
);
12142 munmap_section_buffer (&data
->frame
);
12143 munmap_section_buffer (&data
->eh_frame
);
12146 void _initialize_dwarf2_read (void);
12149 _initialize_dwarf2_read (void)
12151 dwarf2_objfile_data_key
12152 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
12154 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
12155 Set DWARF 2 specific variables.\n\
12156 Configure DWARF 2 variables such as the cache size"),
12157 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
12158 0/*allow-unknown*/, &maintenance_set_cmdlist
);
12160 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
12161 Show DWARF 2 specific variables\n\
12162 Show DWARF 2 variables such as the cache size"),
12163 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
12164 0/*allow-unknown*/, &maintenance_show_cmdlist
);
12166 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
12167 &dwarf2_max_cache_age
, _("\
12168 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
12169 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12170 A higher limit means that cached compilation units will be stored\n\
12171 in memory longer, and more total memory will be used. Zero disables\n\
12172 caching, which can slow down startup."),
12174 show_dwarf2_max_cache_age
,
12175 &set_dwarf2_cmdlist
,
12176 &show_dwarf2_cmdlist
);
12178 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
12179 Set debugging of the dwarf2 DIE reader."), _("\
12180 Show debugging of the dwarf2 DIE reader."), _("\
12181 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12182 The value is the maximum depth to print."),
12185 &setdebuglist
, &showdebuglist
);