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
)
8881 struct attribute
*type_attr
;
8882 struct die_info
*type_die
;
8884 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8887 /* A missing DW_AT_type represents a void type. */
8888 return objfile_type (cu
->objfile
)->builtin_void
;
8891 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8893 type
= tag_type_to_type (type_die
, cu
);
8896 dump_die_for_error (type_die
);
8897 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8903 /* True iff CU's producer generates GNAT Ada auxiliary information
8904 that allows to find parallel types through that information instead
8905 of having to do expensive parallel lookups by type name. */
8908 need_gnat_info (struct dwarf2_cu
*cu
)
8910 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8911 of GNAT produces this auxiliary information, without any indication
8912 that it is produced. Part of enhancing the FSF version of GNAT
8913 to produce that information will be to put in place an indicator
8914 that we can use in order to determine whether the descriptive type
8915 info is available or not. One suggestion that has been made is
8916 to use a new attribute, attached to the CU die. For now, assume
8917 that the descriptive type info is not available. */
8922 /* Return the auxiliary type of the die in question using its
8923 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8924 attribute is not present. */
8926 static struct type
*
8927 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8930 struct attribute
*type_attr
;
8931 struct die_info
*type_die
;
8933 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
8937 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8938 type
= tag_type_to_type (type_die
, cu
);
8941 dump_die_for_error (type_die
);
8942 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8948 /* If DIE has a descriptive_type attribute, then set the TYPE's
8949 descriptive type accordingly. */
8952 set_descriptive_type (struct type
*type
, struct die_info
*die
,
8953 struct dwarf2_cu
*cu
)
8955 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
8957 if (descriptive_type
)
8959 ALLOCATE_GNAT_AUX_TYPE (type
);
8960 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
8964 /* Return the containing type of the die in question using its
8965 DW_AT_containing_type attribute. */
8967 static struct type
*
8968 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8970 struct type
*type
= NULL
;
8971 struct attribute
*type_attr
;
8972 struct die_info
*type_die
= NULL
;
8974 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8977 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8978 type
= tag_type_to_type (type_die
, cu
);
8983 dump_die_for_error (type_die
);
8984 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8990 static struct type
*
8991 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8993 struct type
*this_type
;
8995 this_type
= read_type_die (die
, cu
);
8998 dump_die_for_error (die
);
8999 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
9005 static struct type
*
9006 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9008 struct type
*this_type
;
9010 this_type
= get_die_type (die
, cu
);
9016 case DW_TAG_class_type
:
9017 case DW_TAG_interface_type
:
9018 case DW_TAG_structure_type
:
9019 case DW_TAG_union_type
:
9020 this_type
= read_structure_type (die
, cu
);
9022 case DW_TAG_enumeration_type
:
9023 this_type
= read_enumeration_type (die
, cu
);
9025 case DW_TAG_subprogram
:
9026 case DW_TAG_subroutine_type
:
9027 case DW_TAG_inlined_subroutine
:
9028 this_type
= read_subroutine_type (die
, cu
);
9030 case DW_TAG_array_type
:
9031 this_type
= read_array_type (die
, cu
);
9033 case DW_TAG_set_type
:
9034 this_type
= read_set_type (die
, cu
);
9036 case DW_TAG_pointer_type
:
9037 this_type
= read_tag_pointer_type (die
, cu
);
9039 case DW_TAG_ptr_to_member_type
:
9040 this_type
= read_tag_ptr_to_member_type (die
, cu
);
9042 case DW_TAG_reference_type
:
9043 this_type
= read_tag_reference_type (die
, cu
);
9045 case DW_TAG_const_type
:
9046 this_type
= read_tag_const_type (die
, cu
);
9048 case DW_TAG_volatile_type
:
9049 this_type
= read_tag_volatile_type (die
, cu
);
9051 case DW_TAG_string_type
:
9052 this_type
= read_tag_string_type (die
, cu
);
9054 case DW_TAG_typedef
:
9055 this_type
= read_typedef (die
, cu
);
9057 case DW_TAG_subrange_type
:
9058 this_type
= read_subrange_type (die
, cu
);
9060 case DW_TAG_base_type
:
9061 this_type
= read_base_type (die
, cu
);
9063 case DW_TAG_unspecified_type
:
9064 this_type
= read_unspecified_type (die
, cu
);
9066 case DW_TAG_namespace
:
9067 this_type
= read_namespace_type (die
, cu
);
9070 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
9071 dwarf_tag_name (die
->tag
));
9078 /* Return the name of the namespace/class that DIE is defined within,
9079 or "" if we can't tell. The caller should not xfree the result.
9081 For example, if we're within the method foo() in the following
9091 then determine_prefix on foo's die will return "N::C". */
9094 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
9096 struct die_info
*parent
, *spec_die
;
9097 struct dwarf2_cu
*spec_cu
;
9098 struct type
*parent_type
;
9100 if (cu
->language
!= language_cplus
9101 && cu
->language
!= language_java
)
9104 /* We have to be careful in the presence of DW_AT_specification.
9105 For example, with GCC 3.4, given the code
9109 // Definition of N::foo.
9113 then we'll have a tree of DIEs like this:
9115 1: DW_TAG_compile_unit
9116 2: DW_TAG_namespace // N
9117 3: DW_TAG_subprogram // declaration of N::foo
9118 4: DW_TAG_subprogram // definition of N::foo
9119 DW_AT_specification // refers to die #3
9121 Thus, when processing die #4, we have to pretend that we're in
9122 the context of its DW_AT_specification, namely the contex of die
9125 spec_die
= die_specification (die
, &spec_cu
);
9126 if (spec_die
== NULL
)
9127 parent
= die
->parent
;
9130 parent
= spec_die
->parent
;
9137 switch (parent
->tag
)
9139 case DW_TAG_namespace
:
9140 parent_type
= read_type_die (parent
, cu
);
9141 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9142 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9143 Work around this problem here. */
9144 if (cu
->language
== language_cplus
9145 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
9147 /* We give a name to even anonymous namespaces. */
9148 return TYPE_TAG_NAME (parent_type
);
9149 case DW_TAG_class_type
:
9150 case DW_TAG_interface_type
:
9151 case DW_TAG_structure_type
:
9152 case DW_TAG_union_type
:
9153 parent_type
= read_type_die (parent
, cu
);
9154 if (TYPE_TAG_NAME (parent_type
) != NULL
)
9155 return TYPE_TAG_NAME (parent_type
);
9157 /* An anonymous structure is only allowed non-static data
9158 members; no typedefs, no member functions, et cetera.
9159 So it does not need a prefix. */
9162 return determine_prefix (parent
, cu
);
9166 /* Return a newly-allocated string formed by concatenating PREFIX and
9167 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9168 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9169 perform an obconcat, otherwise allocate storage for the result. The CU argument
9170 is used to determine the language and hence, the appropriate separator. */
9172 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9175 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9176 struct dwarf2_cu
*cu
)
9180 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9182 else if (cu
->language
== language_java
)
9194 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9195 strcpy (retval
, prefix
);
9196 strcat (retval
, sep
);
9197 strcat (retval
, suffix
);
9202 /* We have an obstack. */
9203 return obconcat (obs
, prefix
, sep
, suffix
);
9207 /* Return sibling of die, NULL if no sibling. */
9209 static struct die_info
*
9210 sibling_die (struct die_info
*die
)
9212 return die
->sibling
;
9215 /* Get name of a die, return NULL if not found. */
9218 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9219 struct obstack
*obstack
)
9221 if (name
&& cu
->language
== language_cplus
)
9223 char *canon_name
= cp_canonicalize_string (name
);
9225 if (canon_name
!= NULL
)
9227 if (strcmp (canon_name
, name
) != 0)
9228 name
= obsavestring (canon_name
, strlen (canon_name
),
9237 /* Get name of a die, return NULL if not found. */
9240 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9242 struct attribute
*attr
;
9244 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9245 if (!attr
|| !DW_STRING (attr
))
9250 case DW_TAG_compile_unit
:
9251 /* Compilation units have a DW_AT_name that is a filename, not
9252 a source language identifier. */
9253 case DW_TAG_enumeration_type
:
9254 case DW_TAG_enumerator
:
9255 /* These tags always have simple identifiers already; no need
9256 to canonicalize them. */
9257 return DW_STRING (attr
);
9259 case DW_TAG_subprogram
:
9260 /* Java constructors will all be named "<init>", so return
9261 the class name when we see this special case. */
9262 if (cu
->language
== language_java
9263 && DW_STRING (attr
) != NULL
9264 && strcmp (DW_STRING (attr
), "<init>") == 0)
9266 struct dwarf2_cu
*spec_cu
= cu
;
9267 struct die_info
*spec_die
;
9269 /* GCJ will output '<init>' for Java constructor names.
9270 For this special case, return the name of the parent class. */
9272 /* GCJ may output suprogram DIEs with AT_specification set.
9273 If so, use the name of the specified DIE. */
9274 spec_die
= die_specification (die
, &spec_cu
);
9275 if (spec_die
!= NULL
)
9276 return dwarf2_name (spec_die
, spec_cu
);
9281 if (die
->tag
== DW_TAG_class_type
)
9282 return dwarf2_name (die
, cu
);
9284 while (die
->tag
!= DW_TAG_compile_unit
);
9288 case DW_TAG_class_type
:
9289 case DW_TAG_interface_type
:
9290 case DW_TAG_structure_type
:
9291 case DW_TAG_union_type
:
9292 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
9293 structures or unions. These were of the form "._%d" in GCC 4.1,
9294 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
9295 and GCC 4.4. We work around this problem by ignoring these. */
9296 if (strncmp (DW_STRING (attr
), "._", 2) == 0
9297 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
9305 if (!DW_STRING_IS_CANONICAL (attr
))
9308 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9309 &cu
->objfile
->objfile_obstack
);
9310 DW_STRING_IS_CANONICAL (attr
) = 1;
9312 return DW_STRING (attr
);
9315 /* Return the die that this die in an extension of, or NULL if there
9316 is none. *EXT_CU is the CU containing DIE on input, and the CU
9317 containing the return value on output. */
9319 static struct die_info
*
9320 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9322 struct attribute
*attr
;
9324 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9328 return follow_die_ref (die
, attr
, ext_cu
);
9331 /* Convert a DIE tag into its string name. */
9334 dwarf_tag_name (unsigned tag
)
9338 case DW_TAG_padding
:
9339 return "DW_TAG_padding";
9340 case DW_TAG_array_type
:
9341 return "DW_TAG_array_type";
9342 case DW_TAG_class_type
:
9343 return "DW_TAG_class_type";
9344 case DW_TAG_entry_point
:
9345 return "DW_TAG_entry_point";
9346 case DW_TAG_enumeration_type
:
9347 return "DW_TAG_enumeration_type";
9348 case DW_TAG_formal_parameter
:
9349 return "DW_TAG_formal_parameter";
9350 case DW_TAG_imported_declaration
:
9351 return "DW_TAG_imported_declaration";
9353 return "DW_TAG_label";
9354 case DW_TAG_lexical_block
:
9355 return "DW_TAG_lexical_block";
9357 return "DW_TAG_member";
9358 case DW_TAG_pointer_type
:
9359 return "DW_TAG_pointer_type";
9360 case DW_TAG_reference_type
:
9361 return "DW_TAG_reference_type";
9362 case DW_TAG_compile_unit
:
9363 return "DW_TAG_compile_unit";
9364 case DW_TAG_string_type
:
9365 return "DW_TAG_string_type";
9366 case DW_TAG_structure_type
:
9367 return "DW_TAG_structure_type";
9368 case DW_TAG_subroutine_type
:
9369 return "DW_TAG_subroutine_type";
9370 case DW_TAG_typedef
:
9371 return "DW_TAG_typedef";
9372 case DW_TAG_union_type
:
9373 return "DW_TAG_union_type";
9374 case DW_TAG_unspecified_parameters
:
9375 return "DW_TAG_unspecified_parameters";
9376 case DW_TAG_variant
:
9377 return "DW_TAG_variant";
9378 case DW_TAG_common_block
:
9379 return "DW_TAG_common_block";
9380 case DW_TAG_common_inclusion
:
9381 return "DW_TAG_common_inclusion";
9382 case DW_TAG_inheritance
:
9383 return "DW_TAG_inheritance";
9384 case DW_TAG_inlined_subroutine
:
9385 return "DW_TAG_inlined_subroutine";
9387 return "DW_TAG_module";
9388 case DW_TAG_ptr_to_member_type
:
9389 return "DW_TAG_ptr_to_member_type";
9390 case DW_TAG_set_type
:
9391 return "DW_TAG_set_type";
9392 case DW_TAG_subrange_type
:
9393 return "DW_TAG_subrange_type";
9394 case DW_TAG_with_stmt
:
9395 return "DW_TAG_with_stmt";
9396 case DW_TAG_access_declaration
:
9397 return "DW_TAG_access_declaration";
9398 case DW_TAG_base_type
:
9399 return "DW_TAG_base_type";
9400 case DW_TAG_catch_block
:
9401 return "DW_TAG_catch_block";
9402 case DW_TAG_const_type
:
9403 return "DW_TAG_const_type";
9404 case DW_TAG_constant
:
9405 return "DW_TAG_constant";
9406 case DW_TAG_enumerator
:
9407 return "DW_TAG_enumerator";
9408 case DW_TAG_file_type
:
9409 return "DW_TAG_file_type";
9411 return "DW_TAG_friend";
9412 case DW_TAG_namelist
:
9413 return "DW_TAG_namelist";
9414 case DW_TAG_namelist_item
:
9415 return "DW_TAG_namelist_item";
9416 case DW_TAG_packed_type
:
9417 return "DW_TAG_packed_type";
9418 case DW_TAG_subprogram
:
9419 return "DW_TAG_subprogram";
9420 case DW_TAG_template_type_param
:
9421 return "DW_TAG_template_type_param";
9422 case DW_TAG_template_value_param
:
9423 return "DW_TAG_template_value_param";
9424 case DW_TAG_thrown_type
:
9425 return "DW_TAG_thrown_type";
9426 case DW_TAG_try_block
:
9427 return "DW_TAG_try_block";
9428 case DW_TAG_variant_part
:
9429 return "DW_TAG_variant_part";
9430 case DW_TAG_variable
:
9431 return "DW_TAG_variable";
9432 case DW_TAG_volatile_type
:
9433 return "DW_TAG_volatile_type";
9434 case DW_TAG_dwarf_procedure
:
9435 return "DW_TAG_dwarf_procedure";
9436 case DW_TAG_restrict_type
:
9437 return "DW_TAG_restrict_type";
9438 case DW_TAG_interface_type
:
9439 return "DW_TAG_interface_type";
9440 case DW_TAG_namespace
:
9441 return "DW_TAG_namespace";
9442 case DW_TAG_imported_module
:
9443 return "DW_TAG_imported_module";
9444 case DW_TAG_unspecified_type
:
9445 return "DW_TAG_unspecified_type";
9446 case DW_TAG_partial_unit
:
9447 return "DW_TAG_partial_unit";
9448 case DW_TAG_imported_unit
:
9449 return "DW_TAG_imported_unit";
9450 case DW_TAG_condition
:
9451 return "DW_TAG_condition";
9452 case DW_TAG_shared_type
:
9453 return "DW_TAG_shared_type";
9454 case DW_TAG_type_unit
:
9455 return "DW_TAG_type_unit";
9456 case DW_TAG_MIPS_loop
:
9457 return "DW_TAG_MIPS_loop";
9458 case DW_TAG_HP_array_descriptor
:
9459 return "DW_TAG_HP_array_descriptor";
9460 case DW_TAG_format_label
:
9461 return "DW_TAG_format_label";
9462 case DW_TAG_function_template
:
9463 return "DW_TAG_function_template";
9464 case DW_TAG_class_template
:
9465 return "DW_TAG_class_template";
9466 case DW_TAG_GNU_BINCL
:
9467 return "DW_TAG_GNU_BINCL";
9468 case DW_TAG_GNU_EINCL
:
9469 return "DW_TAG_GNU_EINCL";
9470 case DW_TAG_upc_shared_type
:
9471 return "DW_TAG_upc_shared_type";
9472 case DW_TAG_upc_strict_type
:
9473 return "DW_TAG_upc_strict_type";
9474 case DW_TAG_upc_relaxed_type
:
9475 return "DW_TAG_upc_relaxed_type";
9476 case DW_TAG_PGI_kanji_type
:
9477 return "DW_TAG_PGI_kanji_type";
9478 case DW_TAG_PGI_interface_block
:
9479 return "DW_TAG_PGI_interface_block";
9481 return "DW_TAG_<unknown>";
9485 /* Convert a DWARF attribute code into its string name. */
9488 dwarf_attr_name (unsigned attr
)
9493 return "DW_AT_sibling";
9494 case DW_AT_location
:
9495 return "DW_AT_location";
9497 return "DW_AT_name";
9498 case DW_AT_ordering
:
9499 return "DW_AT_ordering";
9500 case DW_AT_subscr_data
:
9501 return "DW_AT_subscr_data";
9502 case DW_AT_byte_size
:
9503 return "DW_AT_byte_size";
9504 case DW_AT_bit_offset
:
9505 return "DW_AT_bit_offset";
9506 case DW_AT_bit_size
:
9507 return "DW_AT_bit_size";
9508 case DW_AT_element_list
:
9509 return "DW_AT_element_list";
9510 case DW_AT_stmt_list
:
9511 return "DW_AT_stmt_list";
9513 return "DW_AT_low_pc";
9515 return "DW_AT_high_pc";
9516 case DW_AT_language
:
9517 return "DW_AT_language";
9519 return "DW_AT_member";
9521 return "DW_AT_discr";
9522 case DW_AT_discr_value
:
9523 return "DW_AT_discr_value";
9524 case DW_AT_visibility
:
9525 return "DW_AT_visibility";
9527 return "DW_AT_import";
9528 case DW_AT_string_length
:
9529 return "DW_AT_string_length";
9530 case DW_AT_common_reference
:
9531 return "DW_AT_common_reference";
9532 case DW_AT_comp_dir
:
9533 return "DW_AT_comp_dir";
9534 case DW_AT_const_value
:
9535 return "DW_AT_const_value";
9536 case DW_AT_containing_type
:
9537 return "DW_AT_containing_type";
9538 case DW_AT_default_value
:
9539 return "DW_AT_default_value";
9541 return "DW_AT_inline";
9542 case DW_AT_is_optional
:
9543 return "DW_AT_is_optional";
9544 case DW_AT_lower_bound
:
9545 return "DW_AT_lower_bound";
9546 case DW_AT_producer
:
9547 return "DW_AT_producer";
9548 case DW_AT_prototyped
:
9549 return "DW_AT_prototyped";
9550 case DW_AT_return_addr
:
9551 return "DW_AT_return_addr";
9552 case DW_AT_start_scope
:
9553 return "DW_AT_start_scope";
9554 case DW_AT_bit_stride
:
9555 return "DW_AT_bit_stride";
9556 case DW_AT_upper_bound
:
9557 return "DW_AT_upper_bound";
9558 case DW_AT_abstract_origin
:
9559 return "DW_AT_abstract_origin";
9560 case DW_AT_accessibility
:
9561 return "DW_AT_accessibility";
9562 case DW_AT_address_class
:
9563 return "DW_AT_address_class";
9564 case DW_AT_artificial
:
9565 return "DW_AT_artificial";
9566 case DW_AT_base_types
:
9567 return "DW_AT_base_types";
9568 case DW_AT_calling_convention
:
9569 return "DW_AT_calling_convention";
9571 return "DW_AT_count";
9572 case DW_AT_data_member_location
:
9573 return "DW_AT_data_member_location";
9574 case DW_AT_decl_column
:
9575 return "DW_AT_decl_column";
9576 case DW_AT_decl_file
:
9577 return "DW_AT_decl_file";
9578 case DW_AT_decl_line
:
9579 return "DW_AT_decl_line";
9580 case DW_AT_declaration
:
9581 return "DW_AT_declaration";
9582 case DW_AT_discr_list
:
9583 return "DW_AT_discr_list";
9584 case DW_AT_encoding
:
9585 return "DW_AT_encoding";
9586 case DW_AT_external
:
9587 return "DW_AT_external";
9588 case DW_AT_frame_base
:
9589 return "DW_AT_frame_base";
9591 return "DW_AT_friend";
9592 case DW_AT_identifier_case
:
9593 return "DW_AT_identifier_case";
9594 case DW_AT_macro_info
:
9595 return "DW_AT_macro_info";
9596 case DW_AT_namelist_items
:
9597 return "DW_AT_namelist_items";
9598 case DW_AT_priority
:
9599 return "DW_AT_priority";
9601 return "DW_AT_segment";
9602 case DW_AT_specification
:
9603 return "DW_AT_specification";
9604 case DW_AT_static_link
:
9605 return "DW_AT_static_link";
9607 return "DW_AT_type";
9608 case DW_AT_use_location
:
9609 return "DW_AT_use_location";
9610 case DW_AT_variable_parameter
:
9611 return "DW_AT_variable_parameter";
9612 case DW_AT_virtuality
:
9613 return "DW_AT_virtuality";
9614 case DW_AT_vtable_elem_location
:
9615 return "DW_AT_vtable_elem_location";
9616 /* DWARF 3 values. */
9617 case DW_AT_allocated
:
9618 return "DW_AT_allocated";
9619 case DW_AT_associated
:
9620 return "DW_AT_associated";
9621 case DW_AT_data_location
:
9622 return "DW_AT_data_location";
9623 case DW_AT_byte_stride
:
9624 return "DW_AT_byte_stride";
9625 case DW_AT_entry_pc
:
9626 return "DW_AT_entry_pc";
9627 case DW_AT_use_UTF8
:
9628 return "DW_AT_use_UTF8";
9629 case DW_AT_extension
:
9630 return "DW_AT_extension";
9632 return "DW_AT_ranges";
9633 case DW_AT_trampoline
:
9634 return "DW_AT_trampoline";
9635 case DW_AT_call_column
:
9636 return "DW_AT_call_column";
9637 case DW_AT_call_file
:
9638 return "DW_AT_call_file";
9639 case DW_AT_call_line
:
9640 return "DW_AT_call_line";
9641 case DW_AT_description
:
9642 return "DW_AT_description";
9643 case DW_AT_binary_scale
:
9644 return "DW_AT_binary_scale";
9645 case DW_AT_decimal_scale
:
9646 return "DW_AT_decimal_scale";
9648 return "DW_AT_small";
9649 case DW_AT_decimal_sign
:
9650 return "DW_AT_decimal_sign";
9651 case DW_AT_digit_count
:
9652 return "DW_AT_digit_count";
9653 case DW_AT_picture_string
:
9654 return "DW_AT_picture_string";
9656 return "DW_AT_mutable";
9657 case DW_AT_threads_scaled
:
9658 return "DW_AT_threads_scaled";
9659 case DW_AT_explicit
:
9660 return "DW_AT_explicit";
9661 case DW_AT_object_pointer
:
9662 return "DW_AT_object_pointer";
9663 case DW_AT_endianity
:
9664 return "DW_AT_endianity";
9665 case DW_AT_elemental
:
9666 return "DW_AT_elemental";
9668 return "DW_AT_pure";
9669 case DW_AT_recursive
:
9670 return "DW_AT_recursive";
9671 /* DWARF 4 values. */
9672 case DW_AT_signature
:
9673 return "DW_AT_signature";
9674 case DW_AT_linkage_name
:
9675 return "DW_AT_linkage_name";
9676 /* SGI/MIPS extensions. */
9677 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9678 case DW_AT_MIPS_fde
:
9679 return "DW_AT_MIPS_fde";
9681 case DW_AT_MIPS_loop_begin
:
9682 return "DW_AT_MIPS_loop_begin";
9683 case DW_AT_MIPS_tail_loop_begin
:
9684 return "DW_AT_MIPS_tail_loop_begin";
9685 case DW_AT_MIPS_epilog_begin
:
9686 return "DW_AT_MIPS_epilog_begin";
9687 case DW_AT_MIPS_loop_unroll_factor
:
9688 return "DW_AT_MIPS_loop_unroll_factor";
9689 case DW_AT_MIPS_software_pipeline_depth
:
9690 return "DW_AT_MIPS_software_pipeline_depth";
9691 case DW_AT_MIPS_linkage_name
:
9692 return "DW_AT_MIPS_linkage_name";
9693 case DW_AT_MIPS_stride
:
9694 return "DW_AT_MIPS_stride";
9695 case DW_AT_MIPS_abstract_name
:
9696 return "DW_AT_MIPS_abstract_name";
9697 case DW_AT_MIPS_clone_origin
:
9698 return "DW_AT_MIPS_clone_origin";
9699 case DW_AT_MIPS_has_inlines
:
9700 return "DW_AT_MIPS_has_inlines";
9701 /* HP extensions. */
9702 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9703 case DW_AT_HP_block_index
:
9704 return "DW_AT_HP_block_index";
9706 case DW_AT_HP_unmodifiable
:
9707 return "DW_AT_HP_unmodifiable";
9708 case DW_AT_HP_actuals_stmt_list
:
9709 return "DW_AT_HP_actuals_stmt_list";
9710 case DW_AT_HP_proc_per_section
:
9711 return "DW_AT_HP_proc_per_section";
9712 case DW_AT_HP_raw_data_ptr
:
9713 return "DW_AT_HP_raw_data_ptr";
9714 case DW_AT_HP_pass_by_reference
:
9715 return "DW_AT_HP_pass_by_reference";
9716 case DW_AT_HP_opt_level
:
9717 return "DW_AT_HP_opt_level";
9718 case DW_AT_HP_prof_version_id
:
9719 return "DW_AT_HP_prof_version_id";
9720 case DW_AT_HP_opt_flags
:
9721 return "DW_AT_HP_opt_flags";
9722 case DW_AT_HP_cold_region_low_pc
:
9723 return "DW_AT_HP_cold_region_low_pc";
9724 case DW_AT_HP_cold_region_high_pc
:
9725 return "DW_AT_HP_cold_region_high_pc";
9726 case DW_AT_HP_all_variables_modifiable
:
9727 return "DW_AT_HP_all_variables_modifiable";
9728 case DW_AT_HP_linkage_name
:
9729 return "DW_AT_HP_linkage_name";
9730 case DW_AT_HP_prof_flags
:
9731 return "DW_AT_HP_prof_flags";
9732 /* GNU extensions. */
9733 case DW_AT_sf_names
:
9734 return "DW_AT_sf_names";
9735 case DW_AT_src_info
:
9736 return "DW_AT_src_info";
9737 case DW_AT_mac_info
:
9738 return "DW_AT_mac_info";
9739 case DW_AT_src_coords
:
9740 return "DW_AT_src_coords";
9741 case DW_AT_body_begin
:
9742 return "DW_AT_body_begin";
9743 case DW_AT_body_end
:
9744 return "DW_AT_body_end";
9745 case DW_AT_GNU_vector
:
9746 return "DW_AT_GNU_vector";
9747 /* VMS extensions. */
9748 case DW_AT_VMS_rtnbeg_pd_address
:
9749 return "DW_AT_VMS_rtnbeg_pd_address";
9750 /* UPC extension. */
9751 case DW_AT_upc_threads_scaled
:
9752 return "DW_AT_upc_threads_scaled";
9753 /* PGI (STMicroelectronics) extensions. */
9754 case DW_AT_PGI_lbase
:
9755 return "DW_AT_PGI_lbase";
9756 case DW_AT_PGI_soffset
:
9757 return "DW_AT_PGI_soffset";
9758 case DW_AT_PGI_lstride
:
9759 return "DW_AT_PGI_lstride";
9761 return "DW_AT_<unknown>";
9765 /* Convert a DWARF value form code into its string name. */
9768 dwarf_form_name (unsigned form
)
9773 return "DW_FORM_addr";
9774 case DW_FORM_block2
:
9775 return "DW_FORM_block2";
9776 case DW_FORM_block4
:
9777 return "DW_FORM_block4";
9779 return "DW_FORM_data2";
9781 return "DW_FORM_data4";
9783 return "DW_FORM_data8";
9784 case DW_FORM_string
:
9785 return "DW_FORM_string";
9787 return "DW_FORM_block";
9788 case DW_FORM_block1
:
9789 return "DW_FORM_block1";
9791 return "DW_FORM_data1";
9793 return "DW_FORM_flag";
9795 return "DW_FORM_sdata";
9797 return "DW_FORM_strp";
9799 return "DW_FORM_udata";
9800 case DW_FORM_ref_addr
:
9801 return "DW_FORM_ref_addr";
9803 return "DW_FORM_ref1";
9805 return "DW_FORM_ref2";
9807 return "DW_FORM_ref4";
9809 return "DW_FORM_ref8";
9810 case DW_FORM_ref_udata
:
9811 return "DW_FORM_ref_udata";
9812 case DW_FORM_indirect
:
9813 return "DW_FORM_indirect";
9814 case DW_FORM_sec_offset
:
9815 return "DW_FORM_sec_offset";
9816 case DW_FORM_exprloc
:
9817 return "DW_FORM_exprloc";
9818 case DW_FORM_flag_present
:
9819 return "DW_FORM_flag_present";
9821 return "DW_FORM_sig8";
9823 return "DW_FORM_<unknown>";
9827 /* Convert a DWARF stack opcode into its string name. */
9830 dwarf_stack_op_name (unsigned op
)
9835 return "DW_OP_addr";
9837 return "DW_OP_deref";
9839 return "DW_OP_const1u";
9841 return "DW_OP_const1s";
9843 return "DW_OP_const2u";
9845 return "DW_OP_const2s";
9847 return "DW_OP_const4u";
9849 return "DW_OP_const4s";
9851 return "DW_OP_const8u";
9853 return "DW_OP_const8s";
9855 return "DW_OP_constu";
9857 return "DW_OP_consts";
9861 return "DW_OP_drop";
9863 return "DW_OP_over";
9865 return "DW_OP_pick";
9867 return "DW_OP_swap";
9871 return "DW_OP_xderef";
9879 return "DW_OP_minus";
9891 return "DW_OP_plus";
9892 case DW_OP_plus_uconst
:
9893 return "DW_OP_plus_uconst";
9899 return "DW_OP_shra";
9917 return "DW_OP_skip";
9919 return "DW_OP_lit0";
9921 return "DW_OP_lit1";
9923 return "DW_OP_lit2";
9925 return "DW_OP_lit3";
9927 return "DW_OP_lit4";
9929 return "DW_OP_lit5";
9931 return "DW_OP_lit6";
9933 return "DW_OP_lit7";
9935 return "DW_OP_lit8";
9937 return "DW_OP_lit9";
9939 return "DW_OP_lit10";
9941 return "DW_OP_lit11";
9943 return "DW_OP_lit12";
9945 return "DW_OP_lit13";
9947 return "DW_OP_lit14";
9949 return "DW_OP_lit15";
9951 return "DW_OP_lit16";
9953 return "DW_OP_lit17";
9955 return "DW_OP_lit18";
9957 return "DW_OP_lit19";
9959 return "DW_OP_lit20";
9961 return "DW_OP_lit21";
9963 return "DW_OP_lit22";
9965 return "DW_OP_lit23";
9967 return "DW_OP_lit24";
9969 return "DW_OP_lit25";
9971 return "DW_OP_lit26";
9973 return "DW_OP_lit27";
9975 return "DW_OP_lit28";
9977 return "DW_OP_lit29";
9979 return "DW_OP_lit30";
9981 return "DW_OP_lit31";
9983 return "DW_OP_reg0";
9985 return "DW_OP_reg1";
9987 return "DW_OP_reg2";
9989 return "DW_OP_reg3";
9991 return "DW_OP_reg4";
9993 return "DW_OP_reg5";
9995 return "DW_OP_reg6";
9997 return "DW_OP_reg7";
9999 return "DW_OP_reg8";
10001 return "DW_OP_reg9";
10003 return "DW_OP_reg10";
10005 return "DW_OP_reg11";
10007 return "DW_OP_reg12";
10009 return "DW_OP_reg13";
10011 return "DW_OP_reg14";
10013 return "DW_OP_reg15";
10015 return "DW_OP_reg16";
10017 return "DW_OP_reg17";
10019 return "DW_OP_reg18";
10021 return "DW_OP_reg19";
10023 return "DW_OP_reg20";
10025 return "DW_OP_reg21";
10027 return "DW_OP_reg22";
10029 return "DW_OP_reg23";
10031 return "DW_OP_reg24";
10033 return "DW_OP_reg25";
10035 return "DW_OP_reg26";
10037 return "DW_OP_reg27";
10039 return "DW_OP_reg28";
10041 return "DW_OP_reg29";
10043 return "DW_OP_reg30";
10045 return "DW_OP_reg31";
10047 return "DW_OP_breg0";
10049 return "DW_OP_breg1";
10051 return "DW_OP_breg2";
10053 return "DW_OP_breg3";
10055 return "DW_OP_breg4";
10057 return "DW_OP_breg5";
10059 return "DW_OP_breg6";
10061 return "DW_OP_breg7";
10063 return "DW_OP_breg8";
10065 return "DW_OP_breg9";
10067 return "DW_OP_breg10";
10069 return "DW_OP_breg11";
10071 return "DW_OP_breg12";
10073 return "DW_OP_breg13";
10075 return "DW_OP_breg14";
10077 return "DW_OP_breg15";
10079 return "DW_OP_breg16";
10081 return "DW_OP_breg17";
10083 return "DW_OP_breg18";
10085 return "DW_OP_breg19";
10087 return "DW_OP_breg20";
10089 return "DW_OP_breg21";
10091 return "DW_OP_breg22";
10093 return "DW_OP_breg23";
10095 return "DW_OP_breg24";
10097 return "DW_OP_breg25";
10099 return "DW_OP_breg26";
10101 return "DW_OP_breg27";
10103 return "DW_OP_breg28";
10105 return "DW_OP_breg29";
10107 return "DW_OP_breg30";
10109 return "DW_OP_breg31";
10111 return "DW_OP_regx";
10113 return "DW_OP_fbreg";
10115 return "DW_OP_bregx";
10117 return "DW_OP_piece";
10118 case DW_OP_deref_size
:
10119 return "DW_OP_deref_size";
10120 case DW_OP_xderef_size
:
10121 return "DW_OP_xderef_size";
10123 return "DW_OP_nop";
10124 /* DWARF 3 extensions. */
10125 case DW_OP_push_object_address
:
10126 return "DW_OP_push_object_address";
10128 return "DW_OP_call2";
10130 return "DW_OP_call4";
10131 case DW_OP_call_ref
:
10132 return "DW_OP_call_ref";
10133 /* GNU extensions. */
10134 case DW_OP_form_tls_address
:
10135 return "DW_OP_form_tls_address";
10136 case DW_OP_call_frame_cfa
:
10137 return "DW_OP_call_frame_cfa";
10138 case DW_OP_bit_piece
:
10139 return "DW_OP_bit_piece";
10140 case DW_OP_GNU_push_tls_address
:
10141 return "DW_OP_GNU_push_tls_address";
10142 case DW_OP_GNU_uninit
:
10143 return "DW_OP_GNU_uninit";
10144 /* HP extensions. */
10145 case DW_OP_HP_is_value
:
10146 return "DW_OP_HP_is_value";
10147 case DW_OP_HP_fltconst4
:
10148 return "DW_OP_HP_fltconst4";
10149 case DW_OP_HP_fltconst8
:
10150 return "DW_OP_HP_fltconst8";
10151 case DW_OP_HP_mod_range
:
10152 return "DW_OP_HP_mod_range";
10153 case DW_OP_HP_unmod_range
:
10154 return "DW_OP_HP_unmod_range";
10156 return "DW_OP_HP_tls";
10158 return "OP_<unknown>";
10163 dwarf_bool_name (unsigned mybool
)
10171 /* Convert a DWARF type code into its string name. */
10174 dwarf_type_encoding_name (unsigned enc
)
10179 return "DW_ATE_void";
10180 case DW_ATE_address
:
10181 return "DW_ATE_address";
10182 case DW_ATE_boolean
:
10183 return "DW_ATE_boolean";
10184 case DW_ATE_complex_float
:
10185 return "DW_ATE_complex_float";
10187 return "DW_ATE_float";
10188 case DW_ATE_signed
:
10189 return "DW_ATE_signed";
10190 case DW_ATE_signed_char
:
10191 return "DW_ATE_signed_char";
10192 case DW_ATE_unsigned
:
10193 return "DW_ATE_unsigned";
10194 case DW_ATE_unsigned_char
:
10195 return "DW_ATE_unsigned_char";
10197 case DW_ATE_imaginary_float
:
10198 return "DW_ATE_imaginary_float";
10199 case DW_ATE_packed_decimal
:
10200 return "DW_ATE_packed_decimal";
10201 case DW_ATE_numeric_string
:
10202 return "DW_ATE_numeric_string";
10203 case DW_ATE_edited
:
10204 return "DW_ATE_edited";
10205 case DW_ATE_signed_fixed
:
10206 return "DW_ATE_signed_fixed";
10207 case DW_ATE_unsigned_fixed
:
10208 return "DW_ATE_unsigned_fixed";
10209 case DW_ATE_decimal_float
:
10210 return "DW_ATE_decimal_float";
10211 /* HP extensions. */
10212 case DW_ATE_HP_float80
:
10213 return "DW_ATE_HP_float80";
10214 case DW_ATE_HP_complex_float80
:
10215 return "DW_ATE_HP_complex_float80";
10216 case DW_ATE_HP_float128
:
10217 return "DW_ATE_HP_float128";
10218 case DW_ATE_HP_complex_float128
:
10219 return "DW_ATE_HP_complex_float128";
10220 case DW_ATE_HP_floathpintel
:
10221 return "DW_ATE_HP_floathpintel";
10222 case DW_ATE_HP_imaginary_float80
:
10223 return "DW_ATE_HP_imaginary_float80";
10224 case DW_ATE_HP_imaginary_float128
:
10225 return "DW_ATE_HP_imaginary_float128";
10227 return "DW_ATE_<unknown>";
10231 /* Convert a DWARF call frame info operation to its string name. */
10235 dwarf_cfi_name (unsigned cfi_opc
)
10239 case DW_CFA_advance_loc
:
10240 return "DW_CFA_advance_loc";
10241 case DW_CFA_offset
:
10242 return "DW_CFA_offset";
10243 case DW_CFA_restore
:
10244 return "DW_CFA_restore";
10246 return "DW_CFA_nop";
10247 case DW_CFA_set_loc
:
10248 return "DW_CFA_set_loc";
10249 case DW_CFA_advance_loc1
:
10250 return "DW_CFA_advance_loc1";
10251 case DW_CFA_advance_loc2
:
10252 return "DW_CFA_advance_loc2";
10253 case DW_CFA_advance_loc4
:
10254 return "DW_CFA_advance_loc4";
10255 case DW_CFA_offset_extended
:
10256 return "DW_CFA_offset_extended";
10257 case DW_CFA_restore_extended
:
10258 return "DW_CFA_restore_extended";
10259 case DW_CFA_undefined
:
10260 return "DW_CFA_undefined";
10261 case DW_CFA_same_value
:
10262 return "DW_CFA_same_value";
10263 case DW_CFA_register
:
10264 return "DW_CFA_register";
10265 case DW_CFA_remember_state
:
10266 return "DW_CFA_remember_state";
10267 case DW_CFA_restore_state
:
10268 return "DW_CFA_restore_state";
10269 case DW_CFA_def_cfa
:
10270 return "DW_CFA_def_cfa";
10271 case DW_CFA_def_cfa_register
:
10272 return "DW_CFA_def_cfa_register";
10273 case DW_CFA_def_cfa_offset
:
10274 return "DW_CFA_def_cfa_offset";
10276 case DW_CFA_def_cfa_expression
:
10277 return "DW_CFA_def_cfa_expression";
10278 case DW_CFA_expression
:
10279 return "DW_CFA_expression";
10280 case DW_CFA_offset_extended_sf
:
10281 return "DW_CFA_offset_extended_sf";
10282 case DW_CFA_def_cfa_sf
:
10283 return "DW_CFA_def_cfa_sf";
10284 case DW_CFA_def_cfa_offset_sf
:
10285 return "DW_CFA_def_cfa_offset_sf";
10286 case DW_CFA_val_offset
:
10287 return "DW_CFA_val_offset";
10288 case DW_CFA_val_offset_sf
:
10289 return "DW_CFA_val_offset_sf";
10290 case DW_CFA_val_expression
:
10291 return "DW_CFA_val_expression";
10292 /* SGI/MIPS specific. */
10293 case DW_CFA_MIPS_advance_loc8
:
10294 return "DW_CFA_MIPS_advance_loc8";
10295 /* GNU extensions. */
10296 case DW_CFA_GNU_window_save
:
10297 return "DW_CFA_GNU_window_save";
10298 case DW_CFA_GNU_args_size
:
10299 return "DW_CFA_GNU_args_size";
10300 case DW_CFA_GNU_negative_offset_extended
:
10301 return "DW_CFA_GNU_negative_offset_extended";
10303 return "DW_CFA_<unknown>";
10309 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10313 print_spaces (indent
, f
);
10314 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10315 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10317 if (die
->parent
!= NULL
)
10319 print_spaces (indent
, f
);
10320 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10321 die
->parent
->offset
);
10324 print_spaces (indent
, f
);
10325 fprintf_unfiltered (f
, " has children: %s\n",
10326 dwarf_bool_name (die
->child
!= NULL
));
10328 print_spaces (indent
, f
);
10329 fprintf_unfiltered (f
, " attributes:\n");
10331 for (i
= 0; i
< die
->num_attrs
; ++i
)
10333 print_spaces (indent
, f
);
10334 fprintf_unfiltered (f
, " %s (%s) ",
10335 dwarf_attr_name (die
->attrs
[i
].name
),
10336 dwarf_form_name (die
->attrs
[i
].form
));
10338 switch (die
->attrs
[i
].form
)
10340 case DW_FORM_ref_addr
:
10342 fprintf_unfiltered (f
, "address: ");
10343 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10345 case DW_FORM_block2
:
10346 case DW_FORM_block4
:
10347 case DW_FORM_block
:
10348 case DW_FORM_block1
:
10349 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10351 case DW_FORM_exprloc
:
10352 fprintf_unfiltered (f
, "expression: size %u",
10353 DW_BLOCK (&die
->attrs
[i
])->size
);
10358 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10359 (long) (DW_ADDR (&die
->attrs
[i
])));
10361 case DW_FORM_data1
:
10362 case DW_FORM_data2
:
10363 case DW_FORM_data4
:
10364 case DW_FORM_data8
:
10365 case DW_FORM_udata
:
10366 case DW_FORM_sdata
:
10367 fprintf_unfiltered (f
, "constant: %s",
10368 pulongest (DW_UNSND (&die
->attrs
[i
])));
10370 case DW_FORM_sec_offset
:
10371 fprintf_unfiltered (f
, "section offset: %s",
10372 pulongest (DW_UNSND (&die
->attrs
[i
])));
10375 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10376 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10377 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10379 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10381 case DW_FORM_string
:
10383 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10384 DW_STRING (&die
->attrs
[i
])
10385 ? DW_STRING (&die
->attrs
[i
]) : "",
10386 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10389 if (DW_UNSND (&die
->attrs
[i
]))
10390 fprintf_unfiltered (f
, "flag: TRUE");
10392 fprintf_unfiltered (f
, "flag: FALSE");
10394 case DW_FORM_flag_present
:
10395 fprintf_unfiltered (f
, "flag: TRUE");
10397 case DW_FORM_indirect
:
10398 /* the reader will have reduced the indirect form to
10399 the "base form" so this form should not occur */
10400 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10403 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10404 die
->attrs
[i
].form
);
10407 fprintf_unfiltered (f
, "\n");
10412 dump_die_for_error (struct die_info
*die
)
10414 dump_die_shallow (gdb_stderr
, 0, die
);
10418 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10420 int indent
= level
* 4;
10422 gdb_assert (die
!= NULL
);
10424 if (level
>= max_level
)
10427 dump_die_shallow (f
, indent
, die
);
10429 if (die
->child
!= NULL
)
10431 print_spaces (indent
, f
);
10432 fprintf_unfiltered (f
, " Children:");
10433 if (level
+ 1 < max_level
)
10435 fprintf_unfiltered (f
, "\n");
10436 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10440 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10444 if (die
->sibling
!= NULL
&& level
> 0)
10446 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10450 /* This is called from the pdie macro in gdbinit.in.
10451 It's not static so gcc will keep a copy callable from gdb. */
10454 dump_die (struct die_info
*die
, int max_level
)
10456 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10460 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10464 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10470 is_ref_attr (struct attribute
*attr
)
10472 switch (attr
->form
)
10474 case DW_FORM_ref_addr
:
10479 case DW_FORM_ref_udata
:
10486 static unsigned int
10487 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10489 if (is_ref_attr (attr
))
10490 return DW_ADDR (attr
);
10492 complaint (&symfile_complaints
,
10493 _("unsupported die ref attribute form: '%s'"),
10494 dwarf_form_name (attr
->form
));
10498 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10499 * the value held by the attribute is not constant. */
10502 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10504 if (attr
->form
== DW_FORM_sdata
)
10505 return DW_SND (attr
);
10506 else if (attr
->form
== DW_FORM_udata
10507 || attr
->form
== DW_FORM_data1
10508 || attr
->form
== DW_FORM_data2
10509 || attr
->form
== DW_FORM_data4
10510 || attr
->form
== DW_FORM_data8
)
10511 return DW_UNSND (attr
);
10514 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10515 dwarf_form_name (attr
->form
));
10516 return default_value
;
10520 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10521 unit and add it to our queue.
10522 The result is non-zero if PER_CU was queued, otherwise the result is zero
10523 meaning either PER_CU is already queued or it is already loaded. */
10526 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10527 struct dwarf2_per_cu_data
*per_cu
)
10529 /* Mark the dependence relation so that we don't flush PER_CU
10531 dwarf2_add_dependence (this_cu
, per_cu
);
10533 /* If it's already on the queue, we have nothing to do. */
10534 if (per_cu
->queued
)
10537 /* If the compilation unit is already loaded, just mark it as
10539 if (per_cu
->cu
!= NULL
)
10541 per_cu
->cu
->last_used
= 0;
10545 /* Add it to the queue. */
10546 queue_comp_unit (per_cu
, this_cu
->objfile
);
10551 /* Follow reference or signature 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_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10557 struct dwarf2_cu
**ref_cu
)
10559 struct die_info
*die
;
10561 if (is_ref_attr (attr
))
10562 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10563 else if (attr
->form
== DW_FORM_sig8
)
10564 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10567 dump_die_for_error (src_die
);
10568 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10569 (*ref_cu
)->objfile
->name
);
10575 /* Follow reference attribute ATTR of SRC_DIE.
10576 On entry *REF_CU is the CU of SRC_DIE.
10577 On exit *REF_CU is the CU of the result. */
10579 static struct die_info
*
10580 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10581 struct dwarf2_cu
**ref_cu
)
10583 struct die_info
*die
;
10584 unsigned int offset
;
10585 struct die_info temp_die
;
10586 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10588 gdb_assert (cu
->per_cu
!= NULL
);
10590 offset
= dwarf2_get_ref_die_offset (attr
);
10592 if (cu
->per_cu
->from_debug_types
)
10594 /* .debug_types CUs cannot reference anything outside their CU.
10595 If they need to, they have to reference a signatured type via
10597 if (! offset_in_cu_p (&cu
->header
, offset
))
10601 else if (! offset_in_cu_p (&cu
->header
, offset
))
10603 struct dwarf2_per_cu_data
*per_cu
;
10604 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10606 /* If necessary, add it to the queue and load its DIEs. */
10607 if (maybe_queue_comp_unit (cu
, per_cu
))
10608 load_full_comp_unit (per_cu
, cu
->objfile
);
10610 target_cu
= per_cu
->cu
;
10615 *ref_cu
= target_cu
;
10616 temp_die
.offset
= offset
;
10617 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10623 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10624 "at 0x%x [in module %s]"),
10625 offset
, src_die
->offset
, cu
->objfile
->name
);
10628 /* Follow the signature attribute ATTR in SRC_DIE.
10629 On entry *REF_CU is the CU of SRC_DIE.
10630 On exit *REF_CU is the CU of the result. */
10632 static struct die_info
*
10633 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10634 struct dwarf2_cu
**ref_cu
)
10636 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10637 struct die_info temp_die
;
10638 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10639 struct dwarf2_cu
*sig_cu
;
10640 struct die_info
*die
;
10642 /* sig_type will be NULL if the signatured type is missing from
10644 if (sig_type
== NULL
)
10645 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10646 "at 0x%x [in module %s]"),
10647 src_die
->offset
, objfile
->name
);
10649 /* If necessary, add it to the queue and load its DIEs. */
10651 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10652 read_signatured_type (objfile
, sig_type
);
10654 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10656 sig_cu
= sig_type
->per_cu
.cu
;
10657 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10658 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10665 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10666 "at 0x%x [in module %s]"),
10667 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10670 /* Given an offset of a signatured type, return its signatured_type. */
10672 static struct signatured_type
*
10673 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10675 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10676 unsigned int length
, initial_length_size
;
10677 unsigned int sig_offset
;
10678 struct signatured_type find_entry
, *type_sig
;
10680 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10681 sig_offset
= (initial_length_size
10683 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10684 + 1 /*address_size*/);
10685 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10686 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10688 /* This is only used to lookup previously recorded types.
10689 If we didn't find it, it's our bug. */
10690 gdb_assert (type_sig
!= NULL
);
10691 gdb_assert (offset
== type_sig
->offset
);
10696 /* Read in signatured type at OFFSET and build its CU and die(s). */
10699 read_signatured_type_at_offset (struct objfile
*objfile
,
10700 unsigned int offset
)
10702 struct signatured_type
*type_sig
;
10704 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
10706 /* We have the section offset, but we need the signature to do the
10707 hash table lookup. */
10708 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10710 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10712 read_signatured_type (objfile
, type_sig
);
10714 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10717 /* Read in a signatured type and build its CU and DIEs. */
10720 read_signatured_type (struct objfile
*objfile
,
10721 struct signatured_type
*type_sig
)
10723 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10724 struct die_reader_specs reader_specs
;
10725 struct dwarf2_cu
*cu
;
10726 ULONGEST signature
;
10727 struct cleanup
*back_to
, *free_cu_cleanup
;
10728 struct attribute
*attr
;
10730 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10732 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10733 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10734 obstack_init (&cu
->comp_unit_obstack
);
10735 cu
->objfile
= objfile
;
10736 type_sig
->per_cu
.cu
= cu
;
10737 cu
->per_cu
= &type_sig
->per_cu
;
10739 /* If an error occurs while loading, release our storage. */
10740 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10742 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10743 types_ptr
, objfile
->obfd
);
10744 gdb_assert (signature
== type_sig
->signature
);
10747 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10751 &cu
->comp_unit_obstack
,
10752 hashtab_obstack_allocate
,
10753 dummy_obstack_deallocate
);
10755 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10756 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10758 init_cu_die_reader (&reader_specs
, cu
);
10760 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10763 /* We try not to read any attributes in this function, because not
10764 all objfiles needed for references have been loaded yet, and symbol
10765 table processing isn't initialized. But we have to set the CU language,
10766 or we won't be able to build types correctly. */
10767 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10769 set_cu_language (DW_UNSND (attr
), cu
);
10771 set_cu_language (language_minimal
, cu
);
10773 do_cleanups (back_to
);
10775 /* We've successfully allocated this compilation unit. Let our caller
10776 clean it up when finished with it. */
10777 discard_cleanups (free_cu_cleanup
);
10779 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10780 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10783 /* Decode simple location descriptions.
10784 Given a pointer to a dwarf block that defines a location, compute
10785 the location and return the value.
10787 NOTE drow/2003-11-18: This function is called in two situations
10788 now: for the address of static or global variables (partial symbols
10789 only) and for offsets into structures which are expected to be
10790 (more or less) constant. The partial symbol case should go away,
10791 and only the constant case should remain. That will let this
10792 function complain more accurately. A few special modes are allowed
10793 without complaint for global variables (for instance, global
10794 register values and thread-local values).
10796 A location description containing no operations indicates that the
10797 object is optimized out. The return value is 0 for that case.
10798 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10799 callers will only want a very basic result and this can become a
10802 Note that stack[0] is unused except as a default error return.
10803 Note that stack overflow is not yet handled. */
10806 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10808 struct objfile
*objfile
= cu
->objfile
;
10810 int size
= blk
->size
;
10811 gdb_byte
*data
= blk
->data
;
10812 CORE_ADDR stack
[64];
10814 unsigned int bytes_read
, unsnd
;
10858 stack
[++stacki
] = op
- DW_OP_lit0
;
10893 stack
[++stacki
] = op
- DW_OP_reg0
;
10895 dwarf2_complex_location_expr_complaint ();
10899 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10901 stack
[++stacki
] = unsnd
;
10903 dwarf2_complex_location_expr_complaint ();
10907 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
10912 case DW_OP_const1u
:
10913 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
10917 case DW_OP_const1s
:
10918 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
10922 case DW_OP_const2u
:
10923 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
10927 case DW_OP_const2s
:
10928 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
10932 case DW_OP_const4u
:
10933 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
10937 case DW_OP_const4s
:
10938 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
10943 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
10949 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
10954 stack
[stacki
+ 1] = stack
[stacki
];
10959 stack
[stacki
- 1] += stack
[stacki
];
10963 case DW_OP_plus_uconst
:
10964 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10969 stack
[stacki
- 1] -= stack
[stacki
];
10974 /* If we're not the last op, then we definitely can't encode
10975 this using GDB's address_class enum. This is valid for partial
10976 global symbols, although the variable's address will be bogus
10979 dwarf2_complex_location_expr_complaint ();
10982 case DW_OP_GNU_push_tls_address
:
10983 /* The top of the stack has the offset from the beginning
10984 of the thread control block at which the variable is located. */
10985 /* Nothing should follow this operator, so the top of stack would
10987 /* This is valid for partial global symbols, but the variable's
10988 address will be bogus in the psymtab. */
10990 dwarf2_complex_location_expr_complaint ();
10993 case DW_OP_GNU_uninit
:
10997 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
10998 dwarf_stack_op_name (op
));
10999 return (stack
[stacki
]);
11002 return (stack
[stacki
]);
11005 /* memory allocation interface */
11007 static struct dwarf_block
*
11008 dwarf_alloc_block (struct dwarf2_cu
*cu
)
11010 struct dwarf_block
*blk
;
11012 blk
= (struct dwarf_block
*)
11013 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
11017 static struct abbrev_info
*
11018 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
11020 struct abbrev_info
*abbrev
;
11022 abbrev
= (struct abbrev_info
*)
11023 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
11024 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11028 static struct die_info
*
11029 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
11031 struct die_info
*die
;
11032 size_t size
= sizeof (struct die_info
);
11035 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
11037 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
11038 memset (die
, 0, sizeof (struct die_info
));
11043 /* Macro support. */
11046 /* Return the full name of file number I in *LH's file name table.
11047 Use COMP_DIR as the name of the current directory of the
11048 compilation. The result is allocated using xmalloc; the caller is
11049 responsible for freeing it. */
11051 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
11053 /* Is the file number a valid index into the line header's file name
11054 table? Remember that file numbers start with one, not zero. */
11055 if (1 <= file
&& file
<= lh
->num_file_names
)
11057 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11059 if (IS_ABSOLUTE_PATH (fe
->name
))
11060 return xstrdup (fe
->name
);
11068 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11074 dir_len
= strlen (dir
);
11075 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
11076 strcpy (full_name
, dir
);
11077 full_name
[dir_len
] = '/';
11078 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
11082 return xstrdup (fe
->name
);
11087 /* The compiler produced a bogus file number. We can at least
11088 record the macro definitions made in the file, even if we
11089 won't be able to find the file by name. */
11090 char fake_name
[80];
11091 sprintf (fake_name
, "<bad macro file number %d>", file
);
11093 complaint (&symfile_complaints
,
11094 _("bad file number in macro information (%d)"),
11097 return xstrdup (fake_name
);
11102 static struct macro_source_file
*
11103 macro_start_file (int file
, int line
,
11104 struct macro_source_file
*current_file
,
11105 const char *comp_dir
,
11106 struct line_header
*lh
, struct objfile
*objfile
)
11108 /* The full name of this source file. */
11109 char *full_name
= file_full_name (file
, lh
, comp_dir
);
11111 /* We don't create a macro table for this compilation unit
11112 at all until we actually get a filename. */
11113 if (! pending_macros
)
11114 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
11115 objfile
->macro_cache
);
11117 if (! current_file
)
11118 /* If we have no current file, then this must be the start_file
11119 directive for the compilation unit's main source file. */
11120 current_file
= macro_set_main (pending_macros
, full_name
);
11122 current_file
= macro_include (current_file
, line
, full_name
);
11126 return current_file
;
11130 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
11131 followed by a null byte. */
11133 copy_string (const char *buf
, int len
)
11135 char *s
= xmalloc (len
+ 1);
11136 memcpy (s
, buf
, len
);
11143 static const char *
11144 consume_improper_spaces (const char *p
, const char *body
)
11148 complaint (&symfile_complaints
,
11149 _("macro definition contains spaces in formal argument list:\n`%s'"),
11161 parse_macro_definition (struct macro_source_file
*file
, int line
,
11166 /* The body string takes one of two forms. For object-like macro
11167 definitions, it should be:
11169 <macro name> " " <definition>
11171 For function-like macro definitions, it should be:
11173 <macro name> "() " <definition>
11175 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
11177 Spaces may appear only where explicitly indicated, and in the
11180 The Dwarf 2 spec says that an object-like macro's name is always
11181 followed by a space, but versions of GCC around March 2002 omit
11182 the space when the macro's definition is the empty string.
11184 The Dwarf 2 spec says that there should be no spaces between the
11185 formal arguments in a function-like macro's formal argument list,
11186 but versions of GCC around March 2002 include spaces after the
11190 /* Find the extent of the macro name. The macro name is terminated
11191 by either a space or null character (for an object-like macro) or
11192 an opening paren (for a function-like macro). */
11193 for (p
= body
; *p
; p
++)
11194 if (*p
== ' ' || *p
== '(')
11197 if (*p
== ' ' || *p
== '\0')
11199 /* It's an object-like macro. */
11200 int name_len
= p
- body
;
11201 char *name
= copy_string (body
, name_len
);
11202 const char *replacement
;
11205 replacement
= body
+ name_len
+ 1;
11208 dwarf2_macro_malformed_definition_complaint (body
);
11209 replacement
= body
+ name_len
;
11212 macro_define_object (file
, line
, name
, replacement
);
11216 else if (*p
== '(')
11218 /* It's a function-like macro. */
11219 char *name
= copy_string (body
, p
- body
);
11222 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
11226 p
= consume_improper_spaces (p
, body
);
11228 /* Parse the formal argument list. */
11229 while (*p
&& *p
!= ')')
11231 /* Find the extent of the current argument name. */
11232 const char *arg_start
= p
;
11234 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11237 if (! *p
|| p
== arg_start
)
11238 dwarf2_macro_malformed_definition_complaint (body
);
11241 /* Make sure argv has room for the new argument. */
11242 if (argc
>= argv_size
)
11245 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11248 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11251 p
= consume_improper_spaces (p
, body
);
11253 /* Consume the comma, if present. */
11258 p
= consume_improper_spaces (p
, body
);
11267 /* Perfectly formed definition, no complaints. */
11268 macro_define_function (file
, line
, name
,
11269 argc
, (const char **) argv
,
11271 else if (*p
== '\0')
11273 /* Complain, but do define it. */
11274 dwarf2_macro_malformed_definition_complaint (body
);
11275 macro_define_function (file
, line
, name
,
11276 argc
, (const char **) argv
,
11280 /* Just complain. */
11281 dwarf2_macro_malformed_definition_complaint (body
);
11284 /* Just complain. */
11285 dwarf2_macro_malformed_definition_complaint (body
);
11291 for (i
= 0; i
< argc
; i
++)
11297 dwarf2_macro_malformed_definition_complaint (body
);
11302 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11303 char *comp_dir
, bfd
*abfd
,
11304 struct dwarf2_cu
*cu
)
11306 gdb_byte
*mac_ptr
, *mac_end
;
11307 struct macro_source_file
*current_file
= 0;
11308 enum dwarf_macinfo_record_type macinfo_type
;
11309 int at_commandline
;
11311 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11312 &dwarf2_per_objfile
->macinfo
);
11313 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11315 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11319 /* First pass: Find the name of the base filename.
11320 This filename is needed in order to process all macros whose definition
11321 (or undefinition) comes from the command line. These macros are defined
11322 before the first DW_MACINFO_start_file entry, and yet still need to be
11323 associated to the base file.
11325 To determine the base file name, we scan the macro definitions until we
11326 reach the first DW_MACINFO_start_file entry. We then initialize
11327 CURRENT_FILE accordingly so that any macro definition found before the
11328 first DW_MACINFO_start_file can still be associated to the base file. */
11330 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11331 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11332 + dwarf2_per_objfile
->macinfo
.size
;
11336 /* Do we at least have room for a macinfo type byte? */
11337 if (mac_ptr
>= mac_end
)
11339 /* Complaint is printed during the second pass as GDB will probably
11340 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11344 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11347 switch (macinfo_type
)
11349 /* A zero macinfo type indicates the end of the macro
11354 case DW_MACINFO_define
:
11355 case DW_MACINFO_undef
:
11356 /* Only skip the data by MAC_PTR. */
11358 unsigned int bytes_read
;
11360 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11361 mac_ptr
+= bytes_read
;
11362 read_string (abfd
, mac_ptr
, &bytes_read
);
11363 mac_ptr
+= bytes_read
;
11367 case DW_MACINFO_start_file
:
11369 unsigned int bytes_read
;
11372 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11373 mac_ptr
+= bytes_read
;
11374 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11375 mac_ptr
+= bytes_read
;
11377 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11382 case DW_MACINFO_end_file
:
11383 /* No data to skip by MAC_PTR. */
11386 case DW_MACINFO_vendor_ext
:
11387 /* Only skip the data by MAC_PTR. */
11389 unsigned int bytes_read
;
11391 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11392 mac_ptr
+= bytes_read
;
11393 read_string (abfd
, mac_ptr
, &bytes_read
);
11394 mac_ptr
+= bytes_read
;
11401 } while (macinfo_type
!= 0 && current_file
== NULL
);
11403 /* Second pass: Process all entries.
11405 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11406 command-line macro definitions/undefinitions. This flag is unset when we
11407 reach the first DW_MACINFO_start_file entry. */
11409 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11411 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11412 GDB is still reading the definitions from command line. First
11413 DW_MACINFO_start_file will need to be ignored as it was already executed
11414 to create CURRENT_FILE for the main source holding also the command line
11415 definitions. On first met DW_MACINFO_start_file this flag is reset to
11416 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11418 at_commandline
= 1;
11422 /* Do we at least have room for a macinfo type byte? */
11423 if (mac_ptr
>= mac_end
)
11425 dwarf2_macros_too_long_complaint ();
11429 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11432 switch (macinfo_type
)
11434 /* A zero macinfo type indicates the end of the macro
11439 case DW_MACINFO_define
:
11440 case DW_MACINFO_undef
:
11442 unsigned int bytes_read
;
11446 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11447 mac_ptr
+= bytes_read
;
11448 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11449 mac_ptr
+= bytes_read
;
11451 if (! current_file
)
11453 /* DWARF violation as no main source is present. */
11454 complaint (&symfile_complaints
,
11455 _("debug info with no main source gives macro %s "
11457 macinfo_type
== DW_MACINFO_define
?
11459 macinfo_type
== DW_MACINFO_undef
?
11460 _("undefinition") :
11461 _("something-or-other"), line
, body
);
11464 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11465 complaint (&symfile_complaints
,
11466 _("debug info gives %s macro %s with %s line %d: %s"),
11467 at_commandline
? _("command-line") : _("in-file"),
11468 macinfo_type
== DW_MACINFO_define
?
11470 macinfo_type
== DW_MACINFO_undef
?
11471 _("undefinition") :
11472 _("something-or-other"),
11473 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11475 if (macinfo_type
== DW_MACINFO_define
)
11476 parse_macro_definition (current_file
, line
, body
);
11477 else if (macinfo_type
== DW_MACINFO_undef
)
11478 macro_undef (current_file
, line
, body
);
11482 case DW_MACINFO_start_file
:
11484 unsigned int bytes_read
;
11487 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11488 mac_ptr
+= bytes_read
;
11489 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11490 mac_ptr
+= bytes_read
;
11492 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11493 complaint (&symfile_complaints
,
11494 _("debug info gives source %d included "
11495 "from %s at %s line %d"),
11496 file
, at_commandline
? _("command-line") : _("file"),
11497 line
== 0 ? _("zero") : _("non-zero"), line
);
11499 if (at_commandline
)
11501 /* This DW_MACINFO_start_file was executed in the pass one. */
11502 at_commandline
= 0;
11505 current_file
= macro_start_file (file
, line
,
11506 current_file
, comp_dir
,
11511 case DW_MACINFO_end_file
:
11512 if (! current_file
)
11513 complaint (&symfile_complaints
,
11514 _("macro debug info has an unmatched `close_file' directive"));
11517 current_file
= current_file
->included_by
;
11518 if (! current_file
)
11520 enum dwarf_macinfo_record_type next_type
;
11522 /* GCC circa March 2002 doesn't produce the zero
11523 type byte marking the end of the compilation
11524 unit. Complain if it's not there, but exit no
11527 /* Do we at least have room for a macinfo type byte? */
11528 if (mac_ptr
>= mac_end
)
11530 dwarf2_macros_too_long_complaint ();
11534 /* We don't increment mac_ptr here, so this is just
11536 next_type
= read_1_byte (abfd
, mac_ptr
);
11537 if (next_type
!= 0)
11538 complaint (&symfile_complaints
,
11539 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11546 case DW_MACINFO_vendor_ext
:
11548 unsigned int bytes_read
;
11552 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11553 mac_ptr
+= bytes_read
;
11554 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11555 mac_ptr
+= bytes_read
;
11557 /* We don't recognize any vendor extensions. */
11561 } while (macinfo_type
!= 0);
11564 /* Check if the attribute's form is a DW_FORM_block*
11565 if so return true else false. */
11567 attr_form_is_block (struct attribute
*attr
)
11569 return (attr
== NULL
? 0 :
11570 attr
->form
== DW_FORM_block1
11571 || attr
->form
== DW_FORM_block2
11572 || attr
->form
== DW_FORM_block4
11573 || attr
->form
== DW_FORM_block
11574 || attr
->form
== DW_FORM_exprloc
);
11577 /* Return non-zero if ATTR's value is a section offset --- classes
11578 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11579 You may use DW_UNSND (attr) to retrieve such offsets.
11581 Section 7.5.4, "Attribute Encodings", explains that no attribute
11582 may have a value that belongs to more than one of these classes; it
11583 would be ambiguous if we did, because we use the same forms for all
11586 attr_form_is_section_offset (struct attribute
*attr
)
11588 return (attr
->form
== DW_FORM_data4
11589 || attr
->form
== DW_FORM_data8
11590 || attr
->form
== DW_FORM_sec_offset
);
11594 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11595 zero otherwise. When this function returns true, you can apply
11596 dwarf2_get_attr_constant_value to it.
11598 However, note that for some attributes you must check
11599 attr_form_is_section_offset before using this test. DW_FORM_data4
11600 and DW_FORM_data8 are members of both the constant class, and of
11601 the classes that contain offsets into other debug sections
11602 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11603 that, if an attribute's can be either a constant or one of the
11604 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11605 taken as section offsets, not constants. */
11607 attr_form_is_constant (struct attribute
*attr
)
11609 switch (attr
->form
)
11611 case DW_FORM_sdata
:
11612 case DW_FORM_udata
:
11613 case DW_FORM_data1
:
11614 case DW_FORM_data2
:
11615 case DW_FORM_data4
:
11616 case DW_FORM_data8
:
11624 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11625 struct dwarf2_cu
*cu
)
11627 if (attr_form_is_section_offset (attr
)
11628 /* ".debug_loc" may not exist at all, or the offset may be outside
11629 the section. If so, fall through to the complaint in the
11631 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11633 struct dwarf2_loclist_baton
*baton
;
11635 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11636 sizeof (struct dwarf2_loclist_baton
));
11637 baton
->per_cu
= cu
->per_cu
;
11638 gdb_assert (baton
->per_cu
);
11640 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11641 &dwarf2_per_objfile
->loc
);
11643 /* We don't know how long the location list is, but make sure we
11644 don't run off the edge of the section. */
11645 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11646 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11647 baton
->base_address
= cu
->base_address
;
11648 if (cu
->base_known
== 0)
11649 complaint (&symfile_complaints
,
11650 _("Location list used without specifying the CU base address."));
11652 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11653 SYMBOL_LOCATION_BATON (sym
) = baton
;
11657 struct dwarf2_locexpr_baton
*baton
;
11659 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11660 sizeof (struct dwarf2_locexpr_baton
));
11661 baton
->per_cu
= cu
->per_cu
;
11662 gdb_assert (baton
->per_cu
);
11664 if (attr_form_is_block (attr
))
11666 /* Note that we're just copying the block's data pointer
11667 here, not the actual data. We're still pointing into the
11668 info_buffer for SYM's objfile; right now we never release
11669 that buffer, but when we do clean up properly this may
11671 baton
->size
= DW_BLOCK (attr
)->size
;
11672 baton
->data
= DW_BLOCK (attr
)->data
;
11676 dwarf2_invalid_attrib_class_complaint ("location description",
11677 SYMBOL_NATURAL_NAME (sym
));
11679 baton
->data
= NULL
;
11682 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11683 SYMBOL_LOCATION_BATON (sym
) = baton
;
11687 /* Return the OBJFILE associated with the compilation unit CU. */
11690 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11692 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11694 /* Return the master objfile, so that we can report and look up the
11695 correct file containing this variable. */
11696 if (objfile
->separate_debug_objfile_backlink
)
11697 objfile
= objfile
->separate_debug_objfile_backlink
;
11702 /* Return the address size given in the compilation unit header for CU. */
11705 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11708 return per_cu
->cu
->header
.addr_size
;
11711 /* If the CU is not currently read in, we re-read its header. */
11712 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11713 struct dwarf2_per_objfile
*per_objfile
11714 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11715 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11717 struct comp_unit_head cu_header
;
11718 memset (&cu_header
, 0, sizeof cu_header
);
11719 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11720 return cu_header
.addr_size
;
11724 /* Locate the .debug_info compilation unit from CU's objfile which contains
11725 the DIE at OFFSET. Raises an error on failure. */
11727 static struct dwarf2_per_cu_data
*
11728 dwarf2_find_containing_comp_unit (unsigned int offset
,
11729 struct objfile
*objfile
)
11731 struct dwarf2_per_cu_data
*this_cu
;
11735 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11738 int mid
= low
+ (high
- low
) / 2;
11739 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11744 gdb_assert (low
== high
);
11745 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11748 error (_("Dwarf Error: could not find partial DIE containing "
11749 "offset 0x%lx [in module %s]"),
11750 (long) offset
, bfd_get_filename (objfile
->obfd
));
11752 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11753 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11757 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11758 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11759 && offset
>= this_cu
->offset
+ this_cu
->length
)
11760 error (_("invalid dwarf2 offset %u"), offset
);
11761 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11766 /* Locate the compilation unit from OBJFILE which is located at exactly
11767 OFFSET. Raises an error on failure. */
11769 static struct dwarf2_per_cu_data
*
11770 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11772 struct dwarf2_per_cu_data
*this_cu
;
11773 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11774 if (this_cu
->offset
!= offset
)
11775 error (_("no compilation unit with offset %u."), offset
);
11779 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11781 static struct dwarf2_cu
*
11782 alloc_one_comp_unit (struct objfile
*objfile
)
11784 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11785 cu
->objfile
= objfile
;
11786 obstack_init (&cu
->comp_unit_obstack
);
11790 /* Release one cached compilation unit, CU. We unlink it from the tree
11791 of compilation units, but we don't remove it from the read_in_chain;
11792 the caller is responsible for that.
11793 NOTE: DATA is a void * because this function is also used as a
11794 cleanup routine. */
11797 free_one_comp_unit (void *data
)
11799 struct dwarf2_cu
*cu
= data
;
11801 if (cu
->per_cu
!= NULL
)
11802 cu
->per_cu
->cu
= NULL
;
11805 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11810 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11811 when we're finished with it. We can't free the pointer itself, but be
11812 sure to unlink it from the cache. Also release any associated storage
11813 and perform cache maintenance.
11815 Only used during partial symbol parsing. */
11818 free_stack_comp_unit (void *data
)
11820 struct dwarf2_cu
*cu
= data
;
11822 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11823 cu
->partial_dies
= NULL
;
11825 if (cu
->per_cu
!= NULL
)
11827 /* This compilation unit is on the stack in our caller, so we
11828 should not xfree it. Just unlink it. */
11829 cu
->per_cu
->cu
= NULL
;
11832 /* If we had a per-cu pointer, then we may have other compilation
11833 units loaded, so age them now. */
11834 age_cached_comp_units ();
11838 /* Free all cached compilation units. */
11841 free_cached_comp_units (void *data
)
11843 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11845 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11846 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11847 while (per_cu
!= NULL
)
11849 struct dwarf2_per_cu_data
*next_cu
;
11851 next_cu
= per_cu
->cu
->read_in_chain
;
11853 free_one_comp_unit (per_cu
->cu
);
11854 *last_chain
= next_cu
;
11860 /* Increase the age counter on each cached compilation unit, and free
11861 any that are too old. */
11864 age_cached_comp_units (void)
11866 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11868 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
11869 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11870 while (per_cu
!= NULL
)
11872 per_cu
->cu
->last_used
++;
11873 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
11874 dwarf2_mark (per_cu
->cu
);
11875 per_cu
= per_cu
->cu
->read_in_chain
;
11878 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11879 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11880 while (per_cu
!= NULL
)
11882 struct dwarf2_per_cu_data
*next_cu
;
11884 next_cu
= per_cu
->cu
->read_in_chain
;
11886 if (!per_cu
->cu
->mark
)
11888 free_one_comp_unit (per_cu
->cu
);
11889 *last_chain
= next_cu
;
11892 last_chain
= &per_cu
->cu
->read_in_chain
;
11898 /* Remove a single compilation unit from the cache. */
11901 free_one_cached_comp_unit (void *target_cu
)
11903 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11905 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11906 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11907 while (per_cu
!= NULL
)
11909 struct dwarf2_per_cu_data
*next_cu
;
11911 next_cu
= per_cu
->cu
->read_in_chain
;
11913 if (per_cu
->cu
== target_cu
)
11915 free_one_comp_unit (per_cu
->cu
);
11916 *last_chain
= next_cu
;
11920 last_chain
= &per_cu
->cu
->read_in_chain
;
11926 /* Release all extra memory associated with OBJFILE. */
11929 dwarf2_free_objfile (struct objfile
*objfile
)
11931 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
11933 if (dwarf2_per_objfile
== NULL
)
11936 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11937 free_cached_comp_units (NULL
);
11939 /* Everything else should be on the objfile obstack. */
11942 /* A pair of DIE offset and GDB type pointer. We store these
11943 in a hash table separate from the DIEs, and preserve them
11944 when the DIEs are flushed out of cache. */
11946 struct dwarf2_offset_and_type
11948 unsigned int offset
;
11952 /* Hash function for a dwarf2_offset_and_type. */
11955 offset_and_type_hash (const void *item
)
11957 const struct dwarf2_offset_and_type
*ofs
= item
;
11958 return ofs
->offset
;
11961 /* Equality function for a dwarf2_offset_and_type. */
11964 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
11966 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
11967 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
11968 return ofs_lhs
->offset
== ofs_rhs
->offset
;
11971 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11972 table if necessary. For convenience, return TYPE. */
11974 static struct type
*
11975 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11977 struct dwarf2_offset_and_type
**slot
, ofs
;
11979 /* For Ada types, make sure that the gnat-specific data is always
11980 initialized (if not already set). There are a few types where
11981 we should not be doing so, because the type-specific area is
11982 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11983 where the type-specific area is used to store the floatformat).
11984 But this is not a problem, because the gnat-specific information
11985 is actually not needed for these types. */
11986 if (need_gnat_info (cu
)
11987 && TYPE_CODE (type
) != TYPE_CODE_FUNC
11988 && TYPE_CODE (type
) != TYPE_CODE_FLT
11989 && !HAVE_GNAT_AUX_INFO (type
))
11990 INIT_GNAT_SPECIFIC (type
);
11992 if (cu
->type_hash
== NULL
)
11994 gdb_assert (cu
->per_cu
!= NULL
);
11995 cu
->per_cu
->type_hash
11996 = htab_create_alloc_ex (cu
->header
.length
/ 24,
11997 offset_and_type_hash
,
11998 offset_and_type_eq
,
12000 &cu
->objfile
->objfile_obstack
,
12001 hashtab_obstack_allocate
,
12002 dummy_obstack_deallocate
);
12003 cu
->type_hash
= cu
->per_cu
->type_hash
;
12006 ofs
.offset
= die
->offset
;
12008 slot
= (struct dwarf2_offset_and_type
**)
12009 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
12010 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
12015 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
12016 not have a saved type. */
12018 static struct type
*
12019 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12021 struct dwarf2_offset_and_type
*slot
, ofs
;
12022 htab_t type_hash
= cu
->type_hash
;
12024 if (type_hash
== NULL
)
12027 ofs
.offset
= die
->offset
;
12028 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
12035 /* Add a dependence relationship from CU to REF_PER_CU. */
12038 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
12039 struct dwarf2_per_cu_data
*ref_per_cu
)
12043 if (cu
->dependencies
== NULL
)
12045 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
12046 NULL
, &cu
->comp_unit_obstack
,
12047 hashtab_obstack_allocate
,
12048 dummy_obstack_deallocate
);
12050 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
12052 *slot
= ref_per_cu
;
12055 /* Subroutine of dwarf2_mark to pass to htab_traverse.
12056 Set the mark field in every compilation unit in the
12057 cache that we must keep because we are keeping CU. */
12060 dwarf2_mark_helper (void **slot
, void *data
)
12062 struct dwarf2_per_cu_data
*per_cu
;
12064 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
12065 if (per_cu
->cu
->mark
)
12067 per_cu
->cu
->mark
= 1;
12069 if (per_cu
->cu
->dependencies
!= NULL
)
12070 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
12075 /* Set the mark field in CU and in every other compilation unit in the
12076 cache that we must keep because we are keeping CU. */
12079 dwarf2_mark (struct dwarf2_cu
*cu
)
12084 if (cu
->dependencies
!= NULL
)
12085 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
12089 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
12093 per_cu
->cu
->mark
= 0;
12094 per_cu
= per_cu
->cu
->read_in_chain
;
12098 /* Trivial hash function for partial_die_info: the hash value of a DIE
12099 is its offset in .debug_info for this objfile. */
12102 partial_die_hash (const void *item
)
12104 const struct partial_die_info
*part_die
= item
;
12105 return part_die
->offset
;
12108 /* Trivial comparison function for partial_die_info structures: two DIEs
12109 are equal if they have the same offset. */
12112 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
12114 const struct partial_die_info
*part_die_lhs
= item_lhs
;
12115 const struct partial_die_info
*part_die_rhs
= item_rhs
;
12116 return part_die_lhs
->offset
== part_die_rhs
->offset
;
12119 static struct cmd_list_element
*set_dwarf2_cmdlist
;
12120 static struct cmd_list_element
*show_dwarf2_cmdlist
;
12123 set_dwarf2_cmd (char *args
, int from_tty
)
12125 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
12129 show_dwarf2_cmd (char *args
, int from_tty
)
12131 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
12134 /* If section described by INFO was mmapped, munmap it now. */
12137 munmap_section_buffer (struct dwarf2_section_info
*info
)
12139 if (info
->was_mmapped
)
12142 intptr_t begin
= (intptr_t) info
->buffer
;
12143 intptr_t map_begin
= begin
& ~(pagesize
- 1);
12144 size_t map_length
= info
->size
+ begin
- map_begin
;
12145 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
12147 /* Without HAVE_MMAP, we should never be here to begin with. */
12153 /* munmap debug sections for OBJFILE, if necessary. */
12156 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
12158 struct dwarf2_per_objfile
*data
= d
;
12159 munmap_section_buffer (&data
->info
);
12160 munmap_section_buffer (&data
->abbrev
);
12161 munmap_section_buffer (&data
->line
);
12162 munmap_section_buffer (&data
->str
);
12163 munmap_section_buffer (&data
->macinfo
);
12164 munmap_section_buffer (&data
->ranges
);
12165 munmap_section_buffer (&data
->loc
);
12166 munmap_section_buffer (&data
->frame
);
12167 munmap_section_buffer (&data
->eh_frame
);
12170 void _initialize_dwarf2_read (void);
12173 _initialize_dwarf2_read (void)
12175 dwarf2_objfile_data_key
12176 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
12178 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
12179 Set DWARF 2 specific variables.\n\
12180 Configure DWARF 2 variables such as the cache size"),
12181 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
12182 0/*allow-unknown*/, &maintenance_set_cmdlist
);
12184 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
12185 Show DWARF 2 specific variables\n\
12186 Show DWARF 2 variables such as the cache size"),
12187 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
12188 0/*allow-unknown*/, &maintenance_show_cmdlist
);
12190 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
12191 &dwarf2_max_cache_age
, _("\
12192 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
12193 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12194 A higher limit means that cached compilation units will be stored\n\
12195 in memory longer, and more total memory will be used. Zero disables\n\
12196 caching, which can slow down startup."),
12198 show_dwarf2_max_cache_age
,
12199 &set_dwarf2_cmdlist
,
12200 &show_dwarf2_cmdlist
);
12202 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
12203 Set debugging of the dwarf2 DIE reader."), _("\
12204 Show debugging of the dwarf2 DIE reader."), _("\
12205 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12206 The value is the maximum depth to print."),
12209 &setdebuglist
, &showdebuglist
);