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
*obs
, const char *prefix
,
909 const char *suffix
, int physname
,
910 struct dwarf2_cu
*cu
);
912 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
914 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
916 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
918 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
920 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
921 struct dwarf2_cu
*, struct partial_symtab
*);
923 static int dwarf2_get_pc_bounds (struct die_info
*,
924 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
925 struct partial_symtab
*);
927 static void get_scope_pc_bounds (struct die_info
*,
928 CORE_ADDR
*, CORE_ADDR
*,
931 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
932 CORE_ADDR
, struct dwarf2_cu
*);
934 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
937 static void dwarf2_attach_fields_to_type (struct field_info
*,
938 struct type
*, struct dwarf2_cu
*);
940 static void dwarf2_add_member_fn (struct field_info
*,
941 struct die_info
*, struct type
*,
944 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
945 struct type
*, struct dwarf2_cu
*);
947 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
949 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
951 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
953 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
955 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
957 static struct type
*read_module_type (struct die_info
*die
,
958 struct dwarf2_cu
*cu
);
960 static const char *namespace_name (struct die_info
*die
,
961 int *is_anonymous
, struct dwarf2_cu
*);
963 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
965 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
967 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
970 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
972 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
974 gdb_byte
**new_info_ptr
,
975 struct die_info
*parent
);
977 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
979 gdb_byte
**new_info_ptr
,
980 struct die_info
*parent
);
982 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
984 gdb_byte
**new_info_ptr
,
985 struct die_info
*parent
);
987 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
988 struct die_info
**, gdb_byte
*,
991 static void process_die (struct die_info
*, struct dwarf2_cu
*);
993 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
996 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
998 static struct die_info
*dwarf2_extension (struct die_info
*die
,
999 struct dwarf2_cu
**);
1001 static char *dwarf_tag_name (unsigned int);
1003 static char *dwarf_attr_name (unsigned int);
1005 static char *dwarf_form_name (unsigned int);
1007 static char *dwarf_bool_name (unsigned int);
1009 static char *dwarf_type_encoding_name (unsigned int);
1012 static char *dwarf_cfi_name (unsigned int);
1015 static struct die_info
*sibling_die (struct die_info
*);
1017 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1019 static void dump_die_for_error (struct die_info
*);
1021 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1024 /*static*/ void dump_die (struct die_info
*, int max_level
);
1026 static void store_in_ref_table (struct die_info
*,
1027 struct dwarf2_cu
*);
1029 static int is_ref_attr (struct attribute
*);
1031 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1033 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1035 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1037 struct dwarf2_cu
**);
1039 static struct die_info
*follow_die_ref (struct die_info
*,
1041 struct dwarf2_cu
**);
1043 static struct die_info
*follow_die_sig (struct die_info
*,
1045 struct dwarf2_cu
**);
1047 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1048 unsigned int offset
);
1050 static void read_signatured_type (struct objfile
*,
1051 struct signatured_type
*type_sig
);
1053 /* memory allocation interface */
1055 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1057 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1059 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1061 static void initialize_cu_func_list (struct dwarf2_cu
*);
1063 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1064 struct dwarf2_cu
*);
1066 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1067 char *, bfd
*, struct dwarf2_cu
*);
1069 static int attr_form_is_block (struct attribute
*);
1071 static int attr_form_is_section_offset (struct attribute
*);
1073 static int attr_form_is_constant (struct attribute
*);
1075 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1077 struct dwarf2_cu
*cu
);
1079 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1080 struct abbrev_info
*abbrev
,
1081 struct dwarf2_cu
*cu
);
1083 static void free_stack_comp_unit (void *);
1085 static hashval_t
partial_die_hash (const void *item
);
1087 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1089 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1090 (unsigned int offset
, struct objfile
*objfile
);
1092 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1093 (unsigned int offset
, struct objfile
*objfile
);
1095 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1097 static void free_one_comp_unit (void *);
1099 static void free_cached_comp_units (void *);
1101 static void age_cached_comp_units (void);
1103 static void free_one_cached_comp_unit (void *);
1105 static struct type
*set_die_type (struct die_info
*, struct type
*,
1106 struct dwarf2_cu
*);
1108 static void create_all_comp_units (struct objfile
*);
1110 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1113 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1115 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1116 struct dwarf2_per_cu_data
*);
1118 static void dwarf2_mark (struct dwarf2_cu
*);
1120 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1122 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1124 /* Try to locate the sections we need for DWARF 2 debugging
1125 information and return true if we have enough to do something. */
1128 dwarf2_has_info (struct objfile
*objfile
)
1130 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1131 if (!dwarf2_per_objfile
)
1133 /* Initialize per-objfile state. */
1134 struct dwarf2_per_objfile
*data
1135 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1137 memset (data
, 0, sizeof (*data
));
1138 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1139 dwarf2_per_objfile
= data
;
1141 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1142 dwarf2_per_objfile
->objfile
= objfile
;
1144 return (dwarf2_per_objfile
->info
.asection
!= NULL
1145 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1148 /* When loading sections, we can either look for ".<name>", or for
1149 * ".z<name>", which indicates a compressed section. */
1152 section_is_p (const char *section_name
, const char *name
)
1154 return (section_name
[0] == '.'
1155 && (strcmp (section_name
+ 1, name
) == 0
1156 || (section_name
[1] == 'z'
1157 && strcmp (section_name
+ 2, name
) == 0)));
1160 /* This function is mapped across the sections and remembers the
1161 offset and size of each of the debugging sections we are interested
1165 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1167 if (section_is_p (sectp
->name
, INFO_SECTION
))
1169 dwarf2_per_objfile
->info
.asection
= sectp
;
1170 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1172 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1174 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1175 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1177 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1179 dwarf2_per_objfile
->line
.asection
= sectp
;
1180 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1182 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1184 dwarf2_per_objfile
->loc
.asection
= sectp
;
1185 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1187 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1189 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1190 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1192 else if (section_is_p (sectp
->name
, STR_SECTION
))
1194 dwarf2_per_objfile
->str
.asection
= sectp
;
1195 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1197 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1199 dwarf2_per_objfile
->frame
.asection
= sectp
;
1200 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1202 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1204 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1206 if (aflag
& SEC_HAS_CONTENTS
)
1208 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1209 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1212 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1214 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1215 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1217 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1219 dwarf2_per_objfile
->types
.asection
= sectp
;
1220 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1223 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1224 && bfd_section_vma (abfd
, sectp
) == 0)
1225 dwarf2_per_objfile
->has_section_at_zero
= 1;
1228 /* Decompress a section that was compressed using zlib. Store the
1229 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1232 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1233 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1235 bfd
*abfd
= objfile
->obfd
;
1237 error (_("Support for zlib-compressed DWARF data (from '%s') "
1238 "is disabled in this copy of GDB"),
1239 bfd_get_filename (abfd
));
1241 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1242 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1243 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1244 bfd_size_type uncompressed_size
;
1245 gdb_byte
*uncompressed_buffer
;
1248 int header_size
= 12;
1250 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1251 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1252 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1253 bfd_get_filename (abfd
));
1255 /* Read the zlib header. In this case, it should be "ZLIB" followed
1256 by the uncompressed section size, 8 bytes in big-endian order. */
1257 if (compressed_size
< header_size
1258 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1259 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1260 bfd_get_filename (abfd
));
1261 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1262 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1263 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1264 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1265 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1266 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1267 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1268 uncompressed_size
+= compressed_buffer
[11];
1270 /* It is possible the section consists of several compressed
1271 buffers concatenated together, so we uncompress in a loop. */
1275 strm
.avail_in
= compressed_size
- header_size
;
1276 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1277 strm
.avail_out
= uncompressed_size
;
1278 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1280 rc
= inflateInit (&strm
);
1281 while (strm
.avail_in
> 0)
1284 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1285 bfd_get_filename (abfd
), rc
);
1286 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1287 + (uncompressed_size
- strm
.avail_out
));
1288 rc
= inflate (&strm
, Z_FINISH
);
1289 if (rc
!= Z_STREAM_END
)
1290 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1291 bfd_get_filename (abfd
), rc
);
1292 rc
= inflateReset (&strm
);
1294 rc
= inflateEnd (&strm
);
1296 || strm
.avail_out
!= 0)
1297 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1298 bfd_get_filename (abfd
), rc
);
1300 do_cleanups (cleanup
);
1301 *outbuf
= uncompressed_buffer
;
1302 *outsize
= uncompressed_size
;
1306 /* Read the contents of the section SECTP from object file specified by
1307 OBJFILE, store info about the section into INFO.
1308 If the section is compressed, uncompress it before returning. */
1311 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1313 bfd
*abfd
= objfile
->obfd
;
1314 asection
*sectp
= info
->asection
;
1315 gdb_byte
*buf
, *retbuf
;
1316 unsigned char header
[4];
1320 info
->buffer
= NULL
;
1321 info
->was_mmapped
= 0;
1324 if (info
->asection
== NULL
|| info
->size
== 0)
1327 /* Check if the file has a 4-byte header indicating compression. */
1328 if (info
->size
> sizeof (header
)
1329 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1330 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1332 /* Upon decompression, update the buffer and its size. */
1333 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1335 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1343 pagesize
= getpagesize ();
1345 /* Only try to mmap sections which are large enough: we don't want to
1346 waste space due to fragmentation. Also, only try mmap for sections
1347 without relocations. */
1349 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1351 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1352 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1353 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1354 MAP_PRIVATE
, pg_offset
);
1356 if (retbuf
!= MAP_FAILED
)
1358 info
->was_mmapped
= 1;
1359 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1360 #if HAVE_POSIX_MADVISE
1361 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1368 /* If we get here, we are a normal, not-compressed section. */
1370 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1372 /* When debugging .o files, we may need to apply relocations; see
1373 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1374 We never compress sections in .o files, so we only need to
1375 try this when the section is not compressed. */
1376 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1379 info
->buffer
= retbuf
;
1383 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1384 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1385 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1386 bfd_get_filename (abfd
));
1389 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1393 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1394 asection
**sectp
, gdb_byte
**bufp
,
1395 bfd_size_type
*sizep
)
1397 struct dwarf2_per_objfile
*data
1398 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1399 struct dwarf2_section_info
*info
;
1401 /* We may see an objfile without any DWARF, in which case we just
1410 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1411 info
= &data
->eh_frame
;
1412 else if (section_is_p (section_name
, FRAME_SECTION
))
1413 info
= &data
->frame
;
1417 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1418 /* We haven't read this section in yet. Do it now. */
1419 dwarf2_read_section (objfile
, info
);
1421 *sectp
= info
->asection
;
1422 *bufp
= info
->buffer
;
1423 *sizep
= info
->size
;
1426 /* Build a partial symbol table. */
1429 dwarf2_build_psymtabs (struct objfile
*objfile
)
1431 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
1433 init_psymbol_list (objfile
, 1024);
1436 dwarf2_build_psymtabs_hard (objfile
);
1439 /* Return TRUE if OFFSET is within CU_HEADER. */
1442 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1444 unsigned int bottom
= cu_header
->offset
;
1445 unsigned int top
= (cu_header
->offset
1447 + cu_header
->initial_length_size
);
1449 return (offset
>= bottom
&& offset
< top
);
1452 /* Read in the comp unit header information from the debug_info at info_ptr.
1453 NOTE: This leaves members offset, first_die_offset to be filled in
1457 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1458 gdb_byte
*info_ptr
, bfd
*abfd
)
1461 unsigned int bytes_read
;
1463 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1464 cu_header
->initial_length_size
= bytes_read
;
1465 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1466 info_ptr
+= bytes_read
;
1467 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1469 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1471 info_ptr
+= bytes_read
;
1472 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1474 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1475 if (signed_addr
< 0)
1476 internal_error (__FILE__
, __LINE__
,
1477 _("read_comp_unit_head: dwarf from non elf file"));
1478 cu_header
->signed_addr_p
= signed_addr
;
1484 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1485 gdb_byte
*buffer
, unsigned int buffer_size
,
1488 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1490 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1492 if (header
->version
!= 2 && header
->version
!= 3 && header
->version
!= 4)
1493 error (_("Dwarf Error: wrong version in compilation unit header "
1494 "(is %d, should be 2, 3, or 4) [in module %s]"), header
->version
,
1495 bfd_get_filename (abfd
));
1497 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1498 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1499 "(offset 0x%lx + 6) [in module %s]"),
1500 (long) header
->abbrev_offset
,
1501 (long) (beg_of_comp_unit
- buffer
),
1502 bfd_get_filename (abfd
));
1504 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1505 > buffer
+ buffer_size
)
1506 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1507 "(offset 0x%lx + 0) [in module %s]"),
1508 (long) header
->length
,
1509 (long) (beg_of_comp_unit
- buffer
),
1510 bfd_get_filename (abfd
));
1515 /* Read in the types comp unit header information from .debug_types entry at
1516 types_ptr. The result is a pointer to one past the end of the header. */
1519 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
1520 ULONGEST
*signature
,
1521 gdb_byte
*types_ptr
, bfd
*abfd
)
1523 gdb_byte
*initial_types_ptr
= types_ptr
;
1525 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
1526 &dwarf2_per_objfile
->types
);
1527 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
1529 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
1531 *signature
= read_8_bytes (abfd
, types_ptr
);
1533 types_ptr
+= cu_header
->offset_size
;
1534 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
1539 /* Allocate a new partial symtab for file named NAME and mark this new
1540 partial symtab as being an include of PST. */
1543 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1544 struct objfile
*objfile
)
1546 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1548 subpst
->section_offsets
= pst
->section_offsets
;
1549 subpst
->textlow
= 0;
1550 subpst
->texthigh
= 0;
1552 subpst
->dependencies
= (struct partial_symtab
**)
1553 obstack_alloc (&objfile
->objfile_obstack
,
1554 sizeof (struct partial_symtab
*));
1555 subpst
->dependencies
[0] = pst
;
1556 subpst
->number_of_dependencies
= 1;
1558 subpst
->globals_offset
= 0;
1559 subpst
->n_global_syms
= 0;
1560 subpst
->statics_offset
= 0;
1561 subpst
->n_static_syms
= 0;
1562 subpst
->symtab
= NULL
;
1563 subpst
->read_symtab
= pst
->read_symtab
;
1566 /* No private part is necessary for include psymtabs. This property
1567 can be used to differentiate between such include psymtabs and
1568 the regular ones. */
1569 subpst
->read_symtab_private
= NULL
;
1572 /* Read the Line Number Program data and extract the list of files
1573 included by the source file represented by PST. Build an include
1574 partial symtab for each of these included files. */
1577 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1578 struct die_info
*die
,
1579 struct partial_symtab
*pst
)
1581 struct objfile
*objfile
= cu
->objfile
;
1582 bfd
*abfd
= objfile
->obfd
;
1583 struct line_header
*lh
= NULL
;
1584 struct attribute
*attr
;
1586 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
1589 unsigned int line_offset
= DW_UNSND (attr
);
1591 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
1594 return; /* No linetable, so no includes. */
1596 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1598 free_line_header (lh
);
1602 hash_type_signature (const void *item
)
1604 const struct signatured_type
*type_sig
= item
;
1606 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1607 return type_sig
->signature
;
1611 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
1613 const struct signatured_type
*lhs
= item_lhs
;
1614 const struct signatured_type
*rhs
= item_rhs
;
1616 return lhs
->signature
== rhs
->signature
;
1619 /* Create the hash table of all entries in the .debug_types section.
1620 The result is zero if there is an error (e.g. missing .debug_types section),
1621 otherwise non-zero. */
1624 create_debug_types_hash_table (struct objfile
*objfile
)
1629 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
1630 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
1632 if (info_ptr
== NULL
)
1634 dwarf2_per_objfile
->signatured_types
= NULL
;
1638 types_htab
= htab_create_alloc_ex (41,
1639 hash_type_signature
,
1642 &objfile
->objfile_obstack
,
1643 hashtab_obstack_allocate
,
1644 dummy_obstack_deallocate
);
1646 if (dwarf2_die_debug
)
1647 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
1649 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1651 unsigned int offset
;
1652 unsigned int offset_size
;
1653 unsigned int type_offset
;
1654 unsigned int length
, initial_length_size
;
1655 unsigned short version
;
1657 struct signatured_type
*type_sig
;
1659 gdb_byte
*ptr
= info_ptr
;
1661 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
1663 /* We need to read the type's signature in order to build the hash
1664 table, but we don't need to read anything else just yet. */
1666 /* Sanity check to ensure entire cu is present. */
1667 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
1668 if (ptr
+ length
+ initial_length_size
1669 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1671 complaint (&symfile_complaints
,
1672 _("debug type entry runs off end of `.debug_types' section, ignored"));
1676 offset_size
= initial_length_size
== 4 ? 4 : 8;
1677 ptr
+= initial_length_size
;
1678 version
= bfd_get_16 (objfile
->obfd
, ptr
);
1680 ptr
+= offset_size
; /* abbrev offset */
1681 ptr
+= 1; /* address size */
1682 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
1684 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
1686 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
1687 memset (type_sig
, 0, sizeof (*type_sig
));
1688 type_sig
->signature
= signature
;
1689 type_sig
->offset
= offset
;
1690 type_sig
->type_offset
= type_offset
;
1692 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
1693 gdb_assert (slot
!= NULL
);
1696 if (dwarf2_die_debug
)
1697 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
1698 offset
, phex (signature
, sizeof (signature
)));
1700 info_ptr
= info_ptr
+ initial_length_size
+ length
;
1703 dwarf2_per_objfile
->signatured_types
= types_htab
;
1708 /* Lookup a signature based type.
1709 Returns NULL if SIG is not present in the table. */
1711 static struct signatured_type
*
1712 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
1714 struct signatured_type find_entry
, *entry
;
1716 if (dwarf2_per_objfile
->signatured_types
== NULL
)
1718 complaint (&symfile_complaints
,
1719 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1723 find_entry
.signature
= sig
;
1724 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
1728 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1731 init_cu_die_reader (struct die_reader_specs
*reader
,
1732 struct dwarf2_cu
*cu
)
1734 reader
->abfd
= cu
->objfile
->obfd
;
1736 if (cu
->per_cu
->from_debug_types
)
1738 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1739 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
1743 gdb_assert (dwarf2_per_objfile
->info
.readin
);
1744 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
1748 /* Find the base address of the compilation unit for range lists and
1749 location lists. It will normally be specified by DW_AT_low_pc.
1750 In DWARF-3 draft 4, the base address could be overridden by
1751 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1752 compilation units with discontinuous ranges. */
1755 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
1757 struct attribute
*attr
;
1760 cu
->base_address
= 0;
1762 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
1765 cu
->base_address
= DW_ADDR (attr
);
1770 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
1773 cu
->base_address
= DW_ADDR (attr
);
1779 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1780 to combine the common parts.
1781 Process a compilation unit for a psymtab.
1782 BUFFER is a pointer to the beginning of the dwarf section buffer,
1783 either .debug_info or debug_types.
1784 INFO_PTR is a pointer to the start of the CU.
1785 Returns a pointer to the next CU. */
1788 process_psymtab_comp_unit (struct objfile
*objfile
,
1789 struct dwarf2_per_cu_data
*this_cu
,
1790 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1791 unsigned int buffer_size
)
1793 bfd
*abfd
= objfile
->obfd
;
1794 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1795 struct die_info
*comp_unit_die
;
1796 struct partial_symtab
*pst
;
1798 struct cleanup
*back_to_inner
;
1799 struct dwarf2_cu cu
;
1800 int has_children
, has_pc_info
;
1801 struct attribute
*attr
;
1802 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
1803 struct die_reader_specs reader_specs
;
1805 memset (&cu
, 0, sizeof (cu
));
1806 cu
.objfile
= objfile
;
1807 obstack_init (&cu
.comp_unit_obstack
);
1809 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1811 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1812 buffer
, buffer_size
,
1815 /* Complete the cu_header. */
1816 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1817 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1819 cu
.list_in_scope
= &file_symbols
;
1821 /* If this compilation unit was already read in, free the
1822 cached copy in order to read it in again. This is
1823 necessary because we skipped some symbols when we first
1824 read in the compilation unit (see load_partial_dies).
1825 This problem could be avoided, but the benefit is
1827 if (this_cu
->cu
!= NULL
)
1828 free_one_cached_comp_unit (this_cu
->cu
);
1830 /* Note that this is a pointer to our stack frame, being
1831 added to a global data structure. It will be cleaned up
1832 in free_stack_comp_unit when we finish with this
1833 compilation unit. */
1835 cu
.per_cu
= this_cu
;
1837 /* Read the abbrevs for this compilation unit into a table. */
1838 dwarf2_read_abbrevs (abfd
, &cu
);
1839 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1841 /* Read the compilation unit die. */
1842 if (this_cu
->from_debug_types
)
1843 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1844 init_cu_die_reader (&reader_specs
, &cu
);
1845 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1848 if (this_cu
->from_debug_types
)
1850 /* offset,length haven't been set yet for type units. */
1851 this_cu
->offset
= cu
.header
.offset
;
1852 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
1854 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
1856 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1857 + cu
.header
.initial_length_size
);
1858 do_cleanups (back_to_inner
);
1862 /* Set the language we're debugging. */
1863 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
1865 set_cu_language (DW_UNSND (attr
), &cu
);
1867 set_cu_language (language_minimal
, &cu
);
1869 /* Allocate a new partial symbol table structure. */
1870 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
1871 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1872 (attr
!= NULL
) ? DW_STRING (attr
) : "",
1873 /* TEXTLOW and TEXTHIGH are set below. */
1875 objfile
->global_psymbols
.next
,
1876 objfile
->static_psymbols
.next
);
1878 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
1880 pst
->dirname
= DW_STRING (attr
);
1882 pst
->read_symtab_private
= this_cu
;
1884 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1886 /* Store the function that reads in the rest of the symbol table */
1887 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1889 this_cu
->psymtab
= pst
;
1891 dwarf2_find_base_address (comp_unit_die
, &cu
);
1893 /* Possibly set the default values of LOWPC and HIGHPC from
1895 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
1896 &best_highpc
, &cu
, pst
);
1897 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
1898 /* Store the contiguous range if it is not empty; it can be empty for
1899 CUs with no code. */
1900 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1901 best_lowpc
+ baseaddr
,
1902 best_highpc
+ baseaddr
- 1, pst
);
1904 /* Check if comp unit has_children.
1905 If so, read the rest of the partial symbols from this comp unit.
1906 If not, there's no more debug_info for this comp unit. */
1909 struct partial_die_info
*first_die
;
1910 CORE_ADDR lowpc
, highpc
;
1912 lowpc
= ((CORE_ADDR
) -1);
1913 highpc
= ((CORE_ADDR
) 0);
1915 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
1917 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1918 ! has_pc_info
, &cu
);
1920 /* If we didn't find a lowpc, set it to highpc to avoid
1921 complaints from `maint check'. */
1922 if (lowpc
== ((CORE_ADDR
) -1))
1925 /* If the compilation unit didn't have an explicit address range,
1926 then use the information extracted from its child dies. */
1930 best_highpc
= highpc
;
1933 pst
->textlow
= best_lowpc
+ baseaddr
;
1934 pst
->texthigh
= best_highpc
+ baseaddr
;
1936 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1937 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1938 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1939 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1940 sort_pst_symbols (pst
);
1942 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1943 + cu
.header
.initial_length_size
);
1945 if (this_cu
->from_debug_types
)
1947 /* It's not clear we want to do anything with stmt lists here.
1948 Waiting to see what gcc ultimately does. */
1952 /* Get the list of files included in the current compilation unit,
1953 and build a psymtab for each of them. */
1954 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
1957 do_cleanups (back_to_inner
);
1962 /* Traversal function for htab_traverse_noresize.
1963 Process one .debug_types comp-unit. */
1966 process_type_comp_unit (void **slot
, void *info
)
1968 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
1969 struct objfile
*objfile
= (struct objfile
*) info
;
1970 struct dwarf2_per_cu_data
*this_cu
;
1972 this_cu
= &entry
->per_cu
;
1973 this_cu
->from_debug_types
= 1;
1975 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1976 process_psymtab_comp_unit (objfile
, this_cu
,
1977 dwarf2_per_objfile
->types
.buffer
,
1978 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
1979 dwarf2_per_objfile
->types
.size
);
1984 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
1985 Build partial symbol tables for the .debug_types comp-units. */
1988 build_type_psymtabs (struct objfile
*objfile
)
1990 if (! create_debug_types_hash_table (objfile
))
1993 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
1994 process_type_comp_unit
, objfile
);
1997 /* Build the partial symbol table by doing a quick pass through the
1998 .debug_info and .debug_abbrev sections. */
2001 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
2004 struct cleanup
*back_to
;
2006 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2007 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2009 /* Any cached compilation units will be linked by the per-objfile
2010 read_in_chain. Make sure to free them when we're done. */
2011 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2013 build_type_psymtabs (objfile
);
2015 create_all_comp_units (objfile
);
2017 objfile
->psymtabs_addrmap
=
2018 addrmap_create_mutable (&objfile
->objfile_obstack
);
2020 /* Since the objects we're extracting from .debug_info vary in
2021 length, only the individual functions to extract them (like
2022 read_comp_unit_head and load_partial_die) can really know whether
2023 the buffer is large enough to hold another complete object.
2025 At the moment, they don't actually check that. If .debug_info
2026 holds just one extra byte after the last compilation unit's dies,
2027 then read_comp_unit_head will happily read off the end of the
2028 buffer. read_partial_die is similarly casual. Those functions
2031 For this loop condition, simply checking whether there's any data
2032 left at all should be sufficient. */
2034 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
2035 + dwarf2_per_objfile
->info
.size
))
2037 struct dwarf2_per_cu_data
*this_cu
;
2039 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
2042 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
2043 dwarf2_per_objfile
->info
.buffer
,
2045 dwarf2_per_objfile
->info
.size
);
2048 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
2049 &objfile
->objfile_obstack
);
2051 do_cleanups (back_to
);
2054 /* Load the partial DIEs for a secondary CU into memory. */
2057 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
2058 struct objfile
*objfile
)
2060 bfd
*abfd
= objfile
->obfd
;
2061 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
2062 struct die_info
*comp_unit_die
;
2063 struct dwarf2_cu
*cu
;
2064 struct cleanup
*back_to
;
2065 struct attribute
*attr
;
2067 struct die_reader_specs reader_specs
;
2069 gdb_assert (! this_cu
->from_debug_types
);
2071 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2072 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
2073 beg_of_comp_unit
= info_ptr
;
2075 cu
= alloc_one_comp_unit (objfile
);
2077 /* ??? Missing cleanup for CU? */
2079 /* Link this compilation unit into the compilation unit tree. */
2081 cu
->per_cu
= this_cu
;
2082 cu
->type_hash
= this_cu
->type_hash
;
2084 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
2085 dwarf2_per_objfile
->info
.buffer
,
2086 dwarf2_per_objfile
->info
.size
,
2089 /* Complete the cu_header. */
2090 cu
->header
.offset
= this_cu
->offset
;
2091 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2093 /* Read the abbrevs for this compilation unit into a table. */
2094 dwarf2_read_abbrevs (abfd
, cu
);
2095 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2097 /* Read the compilation unit die. */
2098 init_cu_die_reader (&reader_specs
, cu
);
2099 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2102 /* Set the language we're debugging. */
2103 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
2105 set_cu_language (DW_UNSND (attr
), cu
);
2107 set_cu_language (language_minimal
, cu
);
2109 /* Check if comp unit has_children.
2110 If so, read the rest of the partial symbols from this comp unit.
2111 If not, there's no more debug_info for this comp unit. */
2113 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
2115 do_cleanups (back_to
);
2118 /* Create a list of all compilation units in OBJFILE. We do this only
2119 if an inter-comp-unit reference is found; presumably if there is one,
2120 there will be many, and one will occur early in the .debug_info section.
2121 So there's no point in building this list incrementally. */
2124 create_all_comp_units (struct objfile
*objfile
)
2128 struct dwarf2_per_cu_data
**all_comp_units
;
2131 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2132 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2136 all_comp_units
= xmalloc (n_allocated
2137 * sizeof (struct dwarf2_per_cu_data
*));
2139 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
2141 unsigned int length
, initial_length_size
;
2142 struct dwarf2_per_cu_data
*this_cu
;
2143 unsigned int offset
;
2145 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
2147 /* Read just enough information to find out where the next
2148 compilation unit is. */
2149 length
= read_initial_length (objfile
->obfd
, info_ptr
,
2150 &initial_length_size
);
2152 /* Save the compilation unit for later lookup. */
2153 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
2154 sizeof (struct dwarf2_per_cu_data
));
2155 memset (this_cu
, 0, sizeof (*this_cu
));
2156 this_cu
->offset
= offset
;
2157 this_cu
->length
= length
+ initial_length_size
;
2159 if (n_comp_units
== n_allocated
)
2162 all_comp_units
= xrealloc (all_comp_units
,
2164 * sizeof (struct dwarf2_per_cu_data
*));
2166 all_comp_units
[n_comp_units
++] = this_cu
;
2168 info_ptr
= info_ptr
+ this_cu
->length
;
2171 dwarf2_per_objfile
->all_comp_units
2172 = obstack_alloc (&objfile
->objfile_obstack
,
2173 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2174 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
2175 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2176 xfree (all_comp_units
);
2177 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
2180 /* Process all loaded DIEs for compilation unit CU, starting at
2181 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2182 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2183 DW_AT_ranges). If NEED_PC is set, then this function will set
2184 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2185 and record the covered ranges in the addrmap. */
2188 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
2189 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2191 struct partial_die_info
*pdi
;
2193 /* Now, march along the PDI's, descending into ones which have
2194 interesting children but skipping the children of the other ones,
2195 until we reach the end of the compilation unit. */
2201 fixup_partial_die (pdi
, cu
);
2203 /* Anonymous namespaces or modules have no name but have interesting
2204 children, so we need to look at them. Ditto for anonymous
2207 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
2208 || pdi
->tag
== DW_TAG_module
|| pdi
->tag
== DW_TAG_enumeration_type
)
2212 case DW_TAG_subprogram
:
2213 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2215 case DW_TAG_variable
:
2216 case DW_TAG_typedef
:
2217 case DW_TAG_union_type
:
2218 if (!pdi
->is_declaration
)
2220 add_partial_symbol (pdi
, cu
);
2223 case DW_TAG_class_type
:
2224 case DW_TAG_interface_type
:
2225 case DW_TAG_structure_type
:
2226 if (!pdi
->is_declaration
)
2228 add_partial_symbol (pdi
, cu
);
2231 case DW_TAG_enumeration_type
:
2232 if (!pdi
->is_declaration
)
2233 add_partial_enumeration (pdi
, cu
);
2235 case DW_TAG_base_type
:
2236 case DW_TAG_subrange_type
:
2237 /* File scope base type definitions are added to the partial
2239 add_partial_symbol (pdi
, cu
);
2241 case DW_TAG_namespace
:
2242 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
2245 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
2252 /* If the die has a sibling, skip to the sibling. */
2254 pdi
= pdi
->die_sibling
;
2258 /* Functions used to compute the fully scoped name of a partial DIE.
2260 Normally, this is simple. For C++, the parent DIE's fully scoped
2261 name is concatenated with "::" and the partial DIE's name. For
2262 Java, the same thing occurs except that "." is used instead of "::".
2263 Enumerators are an exception; they use the scope of their parent
2264 enumeration type, i.e. the name of the enumeration type is not
2265 prepended to the enumerator.
2267 There are two complexities. One is DW_AT_specification; in this
2268 case "parent" means the parent of the target of the specification,
2269 instead of the direct parent of the DIE. The other is compilers
2270 which do not emit DW_TAG_namespace; in this case we try to guess
2271 the fully qualified name of structure types from their members'
2272 linkage names. This must be done using the DIE's children rather
2273 than the children of any DW_AT_specification target. We only need
2274 to do this for structures at the top level, i.e. if the target of
2275 any DW_AT_specification (if any; otherwise the DIE itself) does not
2278 /* Compute the scope prefix associated with PDI's parent, in
2279 compilation unit CU. The result will be allocated on CU's
2280 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2281 field. NULL is returned if no prefix is necessary. */
2283 partial_die_parent_scope (struct partial_die_info
*pdi
,
2284 struct dwarf2_cu
*cu
)
2286 char *grandparent_scope
;
2287 struct partial_die_info
*parent
, *real_pdi
;
2289 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2290 then this means the parent of the specification DIE. */
2293 while (real_pdi
->has_specification
)
2294 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2296 parent
= real_pdi
->die_parent
;
2300 if (parent
->scope_set
)
2301 return parent
->scope
;
2303 fixup_partial_die (parent
, cu
);
2305 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2307 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
2308 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
2309 Work around this problem here. */
2310 if (cu
->language
== language_cplus
2311 && parent
->tag
== DW_TAG_namespace
2312 && strcmp (parent
->name
, "::") == 0
2313 && grandparent_scope
== NULL
)
2315 parent
->scope
= NULL
;
2316 parent
->scope_set
= 1;
2320 if (parent
->tag
== DW_TAG_namespace
2321 || parent
->tag
== DW_TAG_module
2322 || parent
->tag
== DW_TAG_structure_type
2323 || parent
->tag
== DW_TAG_class_type
2324 || parent
->tag
== DW_TAG_interface_type
2325 || parent
->tag
== DW_TAG_union_type
2326 || parent
->tag
== DW_TAG_enumeration_type
)
2328 if (grandparent_scope
== NULL
)
2329 parent
->scope
= parent
->name
;
2331 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2332 parent
->name
, 0, cu
);
2334 else if (parent
->tag
== DW_TAG_enumerator
)
2335 /* Enumerators should not get the name of the enumeration as a prefix. */
2336 parent
->scope
= grandparent_scope
;
2339 /* FIXME drow/2004-04-01: What should we be doing with
2340 function-local names? For partial symbols, we should probably be
2342 complaint (&symfile_complaints
,
2343 _("unhandled containing DIE tag %d for DIE at %d"),
2344 parent
->tag
, pdi
->offset
);
2345 parent
->scope
= grandparent_scope
;
2348 parent
->scope_set
= 1;
2349 return parent
->scope
;
2352 /* Return the fully scoped name associated with PDI, from compilation unit
2353 CU. The result will be allocated with malloc. */
2355 partial_die_full_name (struct partial_die_info
*pdi
,
2356 struct dwarf2_cu
*cu
)
2360 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2361 if (parent_scope
== NULL
)
2364 return typename_concat (NULL
, parent_scope
, pdi
->name
, 0, cu
);
2368 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2370 struct objfile
*objfile
= cu
->objfile
;
2372 char *actual_name
= NULL
;
2373 const struct partial_symbol
*psym
= NULL
;
2375 int built_actual_name
= 0;
2377 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2379 actual_name
= partial_die_full_name (pdi
, cu
);
2381 built_actual_name
= 1;
2383 if (actual_name
== NULL
)
2384 actual_name
= pdi
->name
;
2388 case DW_TAG_subprogram
:
2389 if (pdi
->is_external
|| cu
->language
== language_ada
)
2391 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2392 of the global scope. But in Ada, we want to be able to access
2393 nested procedures globally. So all Ada subprograms are stored
2394 in the global scope. */
2395 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2396 mst_text, objfile); */
2397 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2399 VAR_DOMAIN
, LOC_BLOCK
,
2400 &objfile
->global_psymbols
,
2401 0, pdi
->lowpc
+ baseaddr
,
2402 cu
->language
, objfile
);
2406 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2407 mst_file_text, objfile); */
2408 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2410 VAR_DOMAIN
, LOC_BLOCK
,
2411 &objfile
->static_psymbols
,
2412 0, pdi
->lowpc
+ baseaddr
,
2413 cu
->language
, objfile
);
2416 case DW_TAG_variable
:
2417 if (pdi
->is_external
)
2420 Don't enter into the minimal symbol tables as there is
2421 a minimal symbol table entry from the ELF symbols already.
2422 Enter into partial symbol table if it has a location
2423 descriptor or a type.
2424 If the location descriptor is missing, new_symbol will create
2425 a LOC_UNRESOLVED symbol, the address of the variable will then
2426 be determined from the minimal symbol table whenever the variable
2428 The address for the partial symbol table entry is not
2429 used by GDB, but it comes in handy for debugging partial symbol
2433 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2434 if (pdi
->locdesc
|| pdi
->has_type
)
2435 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2437 VAR_DOMAIN
, LOC_STATIC
,
2438 &objfile
->global_psymbols
,
2440 cu
->language
, objfile
);
2444 /* Static Variable. Skip symbols without location descriptors. */
2445 if (pdi
->locdesc
== NULL
)
2447 if (built_actual_name
)
2448 xfree (actual_name
);
2451 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2452 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2453 mst_file_data, objfile); */
2454 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2456 VAR_DOMAIN
, LOC_STATIC
,
2457 &objfile
->static_psymbols
,
2459 cu
->language
, objfile
);
2462 case DW_TAG_typedef
:
2463 case DW_TAG_base_type
:
2464 case DW_TAG_subrange_type
:
2465 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2467 VAR_DOMAIN
, LOC_TYPEDEF
,
2468 &objfile
->static_psymbols
,
2469 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2471 case DW_TAG_namespace
:
2472 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2474 VAR_DOMAIN
, LOC_TYPEDEF
,
2475 &objfile
->global_psymbols
,
2476 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2478 case DW_TAG_class_type
:
2479 case DW_TAG_interface_type
:
2480 case DW_TAG_structure_type
:
2481 case DW_TAG_union_type
:
2482 case DW_TAG_enumeration_type
:
2483 /* Skip external references. The DWARF standard says in the section
2484 about "Structure, Union, and Class Type Entries": "An incomplete
2485 structure, union or class type is represented by a structure,
2486 union or class entry that does not have a byte size attribute
2487 and that has a DW_AT_declaration attribute." */
2488 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2490 if (built_actual_name
)
2491 xfree (actual_name
);
2495 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2496 static vs. global. */
2497 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2499 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2500 (cu
->language
== language_cplus
2501 || cu
->language
== language_java
)
2502 ? &objfile
->global_psymbols
2503 : &objfile
->static_psymbols
,
2504 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2507 case DW_TAG_enumerator
:
2508 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2510 VAR_DOMAIN
, LOC_CONST
,
2511 (cu
->language
== language_cplus
2512 || cu
->language
== language_java
)
2513 ? &objfile
->global_psymbols
2514 : &objfile
->static_psymbols
,
2515 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2521 if (built_actual_name
)
2522 xfree (actual_name
);
2525 /* Read a partial die corresponding to a namespace; also, add a symbol
2526 corresponding to that namespace to the symbol table. NAMESPACE is
2527 the name of the enclosing namespace. */
2530 add_partial_namespace (struct partial_die_info
*pdi
,
2531 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2532 int need_pc
, struct dwarf2_cu
*cu
)
2534 /* Add a symbol for the namespace. */
2536 add_partial_symbol (pdi
, cu
);
2538 /* Now scan partial symbols in that namespace. */
2540 if (pdi
->has_children
)
2541 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2544 /* Read a partial die corresponding to a Fortran module. */
2547 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2548 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2550 /* Now scan partial symbols in that module. */
2552 if (pdi
->has_children
)
2553 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2556 /* Read a partial die corresponding to a subprogram and create a partial
2557 symbol for that subprogram. When the CU language allows it, this
2558 routine also defines a partial symbol for each nested subprogram
2559 that this subprogram contains.
2561 DIE my also be a lexical block, in which case we simply search
2562 recursively for suprograms defined inside that lexical block.
2563 Again, this is only performed when the CU language allows this
2564 type of definitions. */
2567 add_partial_subprogram (struct partial_die_info
*pdi
,
2568 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2569 int need_pc
, struct dwarf2_cu
*cu
)
2571 if (pdi
->tag
== DW_TAG_subprogram
)
2573 if (pdi
->has_pc_info
)
2575 if (pdi
->lowpc
< *lowpc
)
2576 *lowpc
= pdi
->lowpc
;
2577 if (pdi
->highpc
> *highpc
)
2578 *highpc
= pdi
->highpc
;
2582 struct objfile
*objfile
= cu
->objfile
;
2584 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2585 SECT_OFF_TEXT (objfile
));
2586 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2587 pdi
->lowpc
+ baseaddr
,
2588 pdi
->highpc
- 1 + baseaddr
,
2589 cu
->per_cu
->psymtab
);
2591 if (!pdi
->is_declaration
)
2592 /* Ignore subprogram DIEs that do not have a name, they are
2593 illegal. Do not emit a complaint at this point, we will
2594 do so when we convert this psymtab into a symtab. */
2596 add_partial_symbol (pdi
, cu
);
2600 if (! pdi
->has_children
)
2603 if (cu
->language
== language_ada
)
2605 pdi
= pdi
->die_child
;
2608 fixup_partial_die (pdi
, cu
);
2609 if (pdi
->tag
== DW_TAG_subprogram
2610 || pdi
->tag
== DW_TAG_lexical_block
)
2611 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2612 pdi
= pdi
->die_sibling
;
2617 /* See if we can figure out if the class lives in a namespace. We do
2618 this by looking for a member function; its demangled name will
2619 contain namespace info, if there is any. */
2622 guess_structure_name (struct partial_die_info
*struct_pdi
,
2623 struct dwarf2_cu
*cu
)
2625 if ((cu
->language
== language_cplus
2626 || cu
->language
== language_java
)
2627 && cu
->has_namespace_info
== 0
2628 && struct_pdi
->has_children
)
2630 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2631 what template types look like, because the demangler
2632 frequently doesn't give the same name as the debug info. We
2633 could fix this by only using the demangled name to get the
2634 prefix (but see comment in read_structure_type). */
2636 struct partial_die_info
*real_pdi
;
2638 /* If this DIE (this DIE's specification, if any) has a parent, then
2639 we should not do this. We'll prepend the parent's fully qualified
2640 name when we create the partial symbol. */
2642 real_pdi
= struct_pdi
;
2643 while (real_pdi
->has_specification
)
2644 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2646 if (real_pdi
->die_parent
!= NULL
)
2651 /* Read a partial die corresponding to an enumeration type. */
2654 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2655 struct dwarf2_cu
*cu
)
2657 struct partial_die_info
*pdi
;
2659 if (enum_pdi
->name
!= NULL
)
2660 add_partial_symbol (enum_pdi
, cu
);
2662 pdi
= enum_pdi
->die_child
;
2665 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2666 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2668 add_partial_symbol (pdi
, cu
);
2669 pdi
= pdi
->die_sibling
;
2673 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2674 Return the corresponding abbrev, or NULL if the number is zero (indicating
2675 an empty DIE). In either case *BYTES_READ will be set to the length of
2676 the initial number. */
2678 static struct abbrev_info
*
2679 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2680 struct dwarf2_cu
*cu
)
2682 bfd
*abfd
= cu
->objfile
->obfd
;
2683 unsigned int abbrev_number
;
2684 struct abbrev_info
*abbrev
;
2686 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2688 if (abbrev_number
== 0)
2691 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2694 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2695 bfd_get_filename (abfd
));
2701 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2702 Returns a pointer to the end of a series of DIEs, terminated by an empty
2703 DIE. Any children of the skipped DIEs will also be skipped. */
2706 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2708 struct abbrev_info
*abbrev
;
2709 unsigned int bytes_read
;
2713 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2715 return info_ptr
+ bytes_read
;
2717 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
2721 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2722 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2723 abbrev corresponding to that skipped uleb128 should be passed in
2724 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2728 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2729 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
2731 unsigned int bytes_read
;
2732 struct attribute attr
;
2733 bfd
*abfd
= cu
->objfile
->obfd
;
2734 unsigned int form
, i
;
2736 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2738 /* The only abbrev we care about is DW_AT_sibling. */
2739 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2741 read_attribute (&attr
, &abbrev
->attrs
[i
],
2742 abfd
, info_ptr
, cu
);
2743 if (attr
.form
== DW_FORM_ref_addr
)
2744 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2746 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
2749 /* If it isn't DW_AT_sibling, skip this attribute. */
2750 form
= abbrev
->attrs
[i
].form
;
2754 case DW_FORM_ref_addr
:
2755 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2756 and later it is offset sized. */
2757 if (cu
->header
.version
== 2)
2758 info_ptr
+= cu
->header
.addr_size
;
2760 info_ptr
+= cu
->header
.offset_size
;
2763 info_ptr
+= cu
->header
.addr_size
;
2770 case DW_FORM_flag_present
:
2785 case DW_FORM_string
:
2786 read_string (abfd
, info_ptr
, &bytes_read
);
2787 info_ptr
+= bytes_read
;
2789 case DW_FORM_sec_offset
:
2791 info_ptr
+= cu
->header
.offset_size
;
2793 case DW_FORM_exprloc
:
2795 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2796 info_ptr
+= bytes_read
;
2798 case DW_FORM_block1
:
2799 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2801 case DW_FORM_block2
:
2802 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2804 case DW_FORM_block4
:
2805 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2809 case DW_FORM_ref_udata
:
2810 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2812 case DW_FORM_indirect
:
2813 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2814 info_ptr
+= bytes_read
;
2815 /* We need to continue parsing from here, so just go back to
2817 goto skip_attribute
;
2820 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2821 dwarf_form_name (form
),
2822 bfd_get_filename (abfd
));
2826 if (abbrev
->has_children
)
2827 return skip_children (buffer
, info_ptr
, cu
);
2832 /* Locate ORIG_PDI's sibling.
2833 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2837 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
2838 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2839 bfd
*abfd
, struct dwarf2_cu
*cu
)
2841 /* Do we know the sibling already? */
2843 if (orig_pdi
->sibling
)
2844 return orig_pdi
->sibling
;
2846 /* Are there any children to deal with? */
2848 if (!orig_pdi
->has_children
)
2851 /* Skip the children the long way. */
2853 return skip_children (buffer
, info_ptr
, cu
);
2856 /* Expand this partial symbol table into a full symbol table. */
2859 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2861 /* FIXME: This is barely more than a stub. */
2866 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2872 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2873 gdb_flush (gdb_stdout
);
2876 /* Restore our global data. */
2877 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2878 dwarf2_objfile_data_key
);
2880 /* If this psymtab is constructed from a debug-only objfile, the
2881 has_section_at_zero flag will not necessarily be correct. We
2882 can get the correct value for this flag by looking at the data
2883 associated with the (presumably stripped) associated objfile. */
2884 if (pst
->objfile
->separate_debug_objfile_backlink
)
2886 struct dwarf2_per_objfile
*dpo_backlink
2887 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2888 dwarf2_objfile_data_key
);
2890 dwarf2_per_objfile
->has_section_at_zero
2891 = dpo_backlink
->has_section_at_zero
;
2894 psymtab_to_symtab_1 (pst
);
2896 /* Finish up the debug error message. */
2898 printf_filtered (_("done.\n"));
2903 /* Add PER_CU to the queue. */
2906 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2908 struct dwarf2_queue_item
*item
;
2911 item
= xmalloc (sizeof (*item
));
2912 item
->per_cu
= per_cu
;
2915 if (dwarf2_queue
== NULL
)
2916 dwarf2_queue
= item
;
2918 dwarf2_queue_tail
->next
= item
;
2920 dwarf2_queue_tail
= item
;
2923 /* Process the queue. */
2926 process_queue (struct objfile
*objfile
)
2928 struct dwarf2_queue_item
*item
, *next_item
;
2930 /* The queue starts out with one item, but following a DIE reference
2931 may load a new CU, adding it to the end of the queue. */
2932 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2934 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2935 process_full_comp_unit (item
->per_cu
);
2937 item
->per_cu
->queued
= 0;
2938 next_item
= item
->next
;
2942 dwarf2_queue_tail
= NULL
;
2945 /* Free all allocated queue entries. This function only releases anything if
2946 an error was thrown; if the queue was processed then it would have been
2947 freed as we went along. */
2950 dwarf2_release_queue (void *dummy
)
2952 struct dwarf2_queue_item
*item
, *last
;
2954 item
= dwarf2_queue
;
2957 /* Anything still marked queued is likely to be in an
2958 inconsistent state, so discard it. */
2959 if (item
->per_cu
->queued
)
2961 if (item
->per_cu
->cu
!= NULL
)
2962 free_one_cached_comp_unit (item
->per_cu
->cu
);
2963 item
->per_cu
->queued
= 0;
2971 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2974 /* Read in full symbols for PST, and anything it depends on. */
2977 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2979 struct dwarf2_per_cu_data
*per_cu
;
2980 struct cleanup
*back_to
;
2983 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2984 if (!pst
->dependencies
[i
]->readin
)
2986 /* Inform about additional files that need to be read in. */
2989 /* FIXME: i18n: Need to make this a single string. */
2990 fputs_filtered (" ", gdb_stdout
);
2992 fputs_filtered ("and ", gdb_stdout
);
2994 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2995 wrap_here (""); /* Flush output */
2996 gdb_flush (gdb_stdout
);
2998 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
3001 per_cu
= pst
->read_symtab_private
;
3005 /* It's an include file, no symbols to read for it.
3006 Everything is in the parent symtab. */
3011 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
3013 queue_comp_unit (per_cu
, pst
->objfile
);
3015 if (per_cu
->from_debug_types
)
3016 read_signatured_type_at_offset (pst
->objfile
, per_cu
->offset
);
3018 load_full_comp_unit (per_cu
, pst
->objfile
);
3020 process_queue (pst
->objfile
);
3022 /* Age the cache, releasing compilation units that have not
3023 been used recently. */
3024 age_cached_comp_units ();
3026 do_cleanups (back_to
);
3029 /* Load the DIEs associated with PER_CU into memory. */
3032 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3034 bfd
*abfd
= objfile
->obfd
;
3035 struct dwarf2_cu
*cu
;
3036 unsigned int offset
;
3037 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3038 struct cleanup
*back_to
, *free_cu_cleanup
;
3039 struct attribute
*attr
;
3041 gdb_assert (! per_cu
->from_debug_types
);
3043 /* Set local variables from the partial symbol table info. */
3044 offset
= per_cu
->offset
;
3046 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3047 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
3048 beg_of_comp_unit
= info_ptr
;
3050 cu
= alloc_one_comp_unit (objfile
);
3052 /* If an error occurs while loading, release our storage. */
3053 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3055 /* Read in the comp_unit header. */
3056 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
3058 /* Complete the cu_header. */
3059 cu
->header
.offset
= offset
;
3060 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3062 /* Read the abbrevs for this compilation unit. */
3063 dwarf2_read_abbrevs (abfd
, cu
);
3064 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3066 /* Link this compilation unit into the compilation unit tree. */
3068 cu
->per_cu
= per_cu
;
3069 cu
->type_hash
= per_cu
->type_hash
;
3071 cu
->dies
= read_comp_unit (info_ptr
, cu
);
3073 /* We try not to read any attributes in this function, because not
3074 all objfiles needed for references have been loaded yet, and symbol
3075 table processing isn't initialized. But we have to set the CU language,
3076 or we won't be able to build types correctly. */
3077 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
3079 set_cu_language (DW_UNSND (attr
), cu
);
3081 set_cu_language (language_minimal
, cu
);
3083 /* Similarly, if we do not read the producer, we can not apply
3084 producer-specific interpretation. */
3085 attr
= dwarf2_attr (cu
->dies
, DW_AT_producer
, cu
);
3087 cu
->producer
= DW_STRING (attr
);
3089 /* Link this CU into read_in_chain. */
3090 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3091 dwarf2_per_objfile
->read_in_chain
= per_cu
;
3093 do_cleanups (back_to
);
3095 /* We've successfully allocated this compilation unit. Let our caller
3096 clean it up when finished with it. */
3097 discard_cleanups (free_cu_cleanup
);
3100 /* Generate full symbol information for PST and CU, whose DIEs have
3101 already been loaded into memory. */
3104 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
3106 struct partial_symtab
*pst
= per_cu
->psymtab
;
3107 struct dwarf2_cu
*cu
= per_cu
->cu
;
3108 struct objfile
*objfile
= pst
->objfile
;
3109 CORE_ADDR lowpc
, highpc
;
3110 struct symtab
*symtab
;
3111 struct cleanup
*back_to
;
3114 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3117 back_to
= make_cleanup (really_free_pendings
, NULL
);
3119 cu
->list_in_scope
= &file_symbols
;
3121 dwarf2_find_base_address (cu
->dies
, cu
);
3123 /* Do line number decoding in read_file_scope () */
3124 process_die (cu
->dies
, cu
);
3126 /* Some compilers don't define a DW_AT_high_pc attribute for the
3127 compilation unit. If the DW_AT_high_pc is missing, synthesize
3128 it, by scanning the DIE's below the compilation unit. */
3129 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
3131 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
3133 /* Set symtab language to language from DW_AT_language.
3134 If the compilation is from a C file generated by language preprocessors,
3135 do not set the language if it was already deduced by start_subfile. */
3137 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
3139 symtab
->language
= cu
->language
;
3141 pst
->symtab
= symtab
;
3144 do_cleanups (back_to
);
3147 /* Process a die and its children. */
3150 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
3154 case DW_TAG_padding
:
3156 case DW_TAG_compile_unit
:
3157 read_file_scope (die
, cu
);
3159 case DW_TAG_type_unit
:
3160 read_type_unit_scope (die
, cu
);
3162 case DW_TAG_subprogram
:
3163 case DW_TAG_inlined_subroutine
:
3164 read_func_scope (die
, cu
);
3166 case DW_TAG_lexical_block
:
3167 case DW_TAG_try_block
:
3168 case DW_TAG_catch_block
:
3169 read_lexical_block_scope (die
, cu
);
3171 case DW_TAG_class_type
:
3172 case DW_TAG_interface_type
:
3173 case DW_TAG_structure_type
:
3174 case DW_TAG_union_type
:
3175 process_structure_scope (die
, cu
);
3177 case DW_TAG_enumeration_type
:
3178 process_enumeration_scope (die
, cu
);
3181 /* These dies have a type, but processing them does not create
3182 a symbol or recurse to process the children. Therefore we can
3183 read them on-demand through read_type_die. */
3184 case DW_TAG_subroutine_type
:
3185 case DW_TAG_set_type
:
3186 case DW_TAG_array_type
:
3187 case DW_TAG_pointer_type
:
3188 case DW_TAG_ptr_to_member_type
:
3189 case DW_TAG_reference_type
:
3190 case DW_TAG_string_type
:
3193 case DW_TAG_base_type
:
3194 case DW_TAG_subrange_type
:
3195 case DW_TAG_typedef
:
3196 case DW_TAG_const_type
:
3197 case DW_TAG_volatile_type
:
3198 /* Add a typedef symbol for the type definition, if it has a
3200 new_symbol (die
, read_type_die (die
, cu
), cu
);
3202 case DW_TAG_common_block
:
3203 read_common_block (die
, cu
);
3205 case DW_TAG_common_inclusion
:
3207 case DW_TAG_namespace
:
3208 processing_has_namespace_info
= 1;
3209 read_namespace (die
, cu
);
3212 processing_has_namespace_info
= 1;
3213 read_module (die
, cu
);
3215 case DW_TAG_imported_declaration
:
3216 case DW_TAG_imported_module
:
3217 processing_has_namespace_info
= 1;
3218 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
3219 || cu
->language
!= language_fortran
))
3220 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
3221 dwarf_tag_name (die
->tag
));
3222 read_import_statement (die
, cu
);
3225 new_symbol (die
, NULL
, cu
);
3230 /* A helper function for dwarf2_compute_name which determines whether DIE
3231 needs to have the name of the scope prepended to the name listed in the
3235 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3237 struct attribute
*attr
;
3241 case DW_TAG_namespace
:
3242 case DW_TAG_typedef
:
3243 case DW_TAG_class_type
:
3244 case DW_TAG_interface_type
:
3245 case DW_TAG_structure_type
:
3246 case DW_TAG_union_type
:
3247 case DW_TAG_enumeration_type
:
3248 case DW_TAG_enumerator
:
3249 case DW_TAG_subprogram
:
3253 case DW_TAG_variable
:
3254 /* We only need to prefix "globally" visible variables. These include
3255 any variable marked with DW_AT_external or any variable that
3256 lives in a namespace. [Variables in anonymous namespaces
3257 require prefixing, but they are not DW_AT_external.] */
3259 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
3261 struct dwarf2_cu
*spec_cu
= cu
;
3263 return die_needs_namespace (die_specification (die
, &spec_cu
),
3267 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
3268 if (attr
== NULL
&& die
->parent
->tag
!= DW_TAG_namespace
3269 && die
->parent
->tag
!= DW_TAG_module
)
3271 /* A variable in a lexical block of some kind does not need a
3272 namespace, even though in C++ such variables may be external
3273 and have a mangled name. */
3274 if (die
->parent
->tag
== DW_TAG_lexical_block
3275 || die
->parent
->tag
== DW_TAG_try_block
3276 || die
->parent
->tag
== DW_TAG_catch_block
3277 || die
->parent
->tag
== DW_TAG_subprogram
)
3286 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3287 compute the physname for the object, which include a method's
3288 formal parameters (C++/Java) and return type (Java).
3290 For Ada, return the DIE's linkage name rather than the fully qualified
3291 name. PHYSNAME is ignored..
3293 The result is allocated on the objfile_obstack and canonicalized. */
3296 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
3300 name
= dwarf2_name (die
, cu
);
3302 /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise
3303 compute it by typename_concat inside GDB. */
3304 if (cu
->language
== language_ada
3305 || (cu
->language
== language_fortran
&& physname
))
3307 /* For Ada unit, we prefer the linkage name over the name, as
3308 the former contains the exported name, which the user expects
3309 to be able to reference. Ideally, we want the user to be able
3310 to reference this entity using either natural or linkage name,
3311 but we haven't started looking at this enhancement yet. */
3312 struct attribute
*attr
;
3314 attr
= dwarf2_attr (die
, DW_AT_linkage_name
, cu
);
3316 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
3317 if (attr
&& DW_STRING (attr
))
3318 return DW_STRING (attr
);
3321 /* These are the only languages we know how to qualify names in. */
3323 && (cu
->language
== language_cplus
|| cu
->language
== language_java
3324 || cu
->language
== language_fortran
))
3326 if (die_needs_namespace (die
, cu
))
3330 struct ui_file
*buf
;
3332 prefix
= determine_prefix (die
, cu
);
3333 buf
= mem_fileopen ();
3334 if (*prefix
!= '\0')
3336 char *prefixed_name
= typename_concat (NULL
, prefix
, name
,
3339 fputs_unfiltered (prefixed_name
, buf
);
3340 xfree (prefixed_name
);
3343 fputs_unfiltered (name
? name
: "", buf
);
3345 /* For Java and C++ methods, append formal parameter type
3346 information, if PHYSNAME. */
3348 if (physname
&& die
->tag
== DW_TAG_subprogram
3349 && (cu
->language
== language_cplus
3350 || cu
->language
== language_java
))
3352 struct type
*type
= read_type_die (die
, cu
);
3354 c_type_print_args (type
, buf
, 0, cu
->language
);
3356 if (cu
->language
== language_java
)
3358 /* For java, we must append the return type to method
3360 if (die
->tag
== DW_TAG_subprogram
)
3361 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
3364 else if (cu
->language
== language_cplus
)
3366 if (TYPE_NFIELDS (type
) > 0
3367 && TYPE_FIELD_ARTIFICIAL (type
, 0)
3368 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
3369 fputs_unfiltered (" const", buf
);
3373 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
3375 ui_file_delete (buf
);
3377 if (cu
->language
== language_cplus
)
3380 = dwarf2_canonicalize_name (name
, cu
,
3381 &cu
->objfile
->objfile_obstack
);
3392 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3393 If scope qualifiers are appropriate they will be added. The result
3394 will be allocated on the objfile_obstack, or NULL if the DIE does
3395 not have a name. NAME may either be from a previous call to
3396 dwarf2_name or NULL.
3398 The output string will be canonicalized (if C++/Java). */
3401 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3403 return dwarf2_compute_name (name
, die
, cu
, 0);
3406 /* Construct a physname for the given DIE in CU. NAME may either be
3407 from a previous call to dwarf2_name or NULL. The result will be
3408 allocated on the objfile_objstack or NULL if the DIE does not have a
3411 The output string will be canonicalized (if C++/Java). */
3414 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3416 return dwarf2_compute_name (name
, die
, cu
, 1);
3419 /* Read the import statement specified by the given die and record it. */
3422 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3424 struct attribute
*import_attr
;
3425 struct die_info
*imported_die
;
3426 struct dwarf2_cu
*imported_cu
;
3427 const char *imported_name
;
3428 const char *imported_name_prefix
;
3429 const char *canonical_name
;
3430 const char *import_alias
;
3431 const char *imported_declaration
= NULL
;
3432 const char *import_prefix
;
3436 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3437 if (import_attr
== NULL
)
3439 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3440 dwarf_tag_name (die
->tag
));
3445 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
3446 imported_name
= dwarf2_name (imported_die
, imported_cu
);
3447 if (imported_name
== NULL
)
3449 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3451 The import in the following code:
3465 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3466 <52> DW_AT_decl_file : 1
3467 <53> DW_AT_decl_line : 6
3468 <54> DW_AT_import : <0x75>
3469 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3471 <5b> DW_AT_decl_file : 1
3472 <5c> DW_AT_decl_line : 2
3473 <5d> DW_AT_type : <0x6e>
3475 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3476 <76> DW_AT_byte_size : 4
3477 <77> DW_AT_encoding : 5 (signed)
3479 imports the wrong die ( 0x75 instead of 0x58 ).
3480 This case will be ignored until the gcc bug is fixed. */
3484 /* Figure out the local name after import. */
3485 import_alias
= dwarf2_name (die
, cu
);
3487 /* Figure out where the statement is being imported to. */
3488 import_prefix
= determine_prefix (die
, cu
);
3490 /* Figure out what the scope of the imported die is and prepend it
3491 to the name of the imported die. */
3492 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
3494 if (imported_die
->tag
!= DW_TAG_namespace
3495 && imported_die
->tag
!= DW_TAG_module
)
3497 imported_declaration
= imported_name
;
3498 canonical_name
= imported_name_prefix
;
3500 else if (strlen (imported_name_prefix
) > 0)
3502 temp
= alloca (strlen (imported_name_prefix
)
3503 + 2 + strlen (imported_name
) + 1);
3504 strcpy (temp
, imported_name_prefix
);
3505 strcat (temp
, "::");
3506 strcat (temp
, imported_name
);
3507 canonical_name
= temp
;
3510 canonical_name
= imported_name
;
3512 cp_add_using_directive (import_prefix
,
3515 imported_declaration
,
3516 &cu
->objfile
->objfile_obstack
);
3520 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3522 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3526 free_cu_line_header (void *arg
)
3528 struct dwarf2_cu
*cu
= arg
;
3530 free_line_header (cu
->line_header
);
3531 cu
->line_header
= NULL
;
3535 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3537 struct objfile
*objfile
= cu
->objfile
;
3538 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3539 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3540 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3541 struct attribute
*attr
;
3543 char *comp_dir
= NULL
;
3544 struct die_info
*child_die
;
3545 bfd
*abfd
= objfile
->obfd
;
3546 struct line_header
*line_header
= 0;
3549 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3551 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3553 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3554 from finish_block. */
3555 if (lowpc
== ((CORE_ADDR
) -1))
3560 /* Find the filename. Do not use dwarf2_name here, since the filename
3561 is not a source language identifier. */
3562 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3565 name
= DW_STRING (attr
);
3568 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3570 comp_dir
= DW_STRING (attr
);
3571 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3573 comp_dir
= ldirname (name
);
3574 if (comp_dir
!= NULL
)
3575 make_cleanup (xfree
, comp_dir
);
3577 if (comp_dir
!= NULL
)
3579 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3580 directory, get rid of it. */
3581 char *cp
= strchr (comp_dir
, ':');
3583 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3590 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3593 set_cu_language (DW_UNSND (attr
), cu
);
3596 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3598 cu
->producer
= DW_STRING (attr
);
3600 /* We assume that we're processing GCC output. */
3601 processing_gcc_compilation
= 2;
3603 processing_has_namespace_info
= 0;
3605 start_symtab (name
, comp_dir
, lowpc
);
3606 record_debugformat ("DWARF 2");
3607 record_producer (cu
->producer
);
3609 initialize_cu_func_list (cu
);
3611 /* Decode line number information if present. We do this before
3612 processing child DIEs, so that the line header table is available
3613 for DW_AT_decl_file. */
3614 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3617 unsigned int line_offset
= DW_UNSND (attr
);
3618 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3621 cu
->line_header
= line_header
;
3622 make_cleanup (free_cu_line_header
, cu
);
3623 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3627 /* Process all dies in compilation unit. */
3628 if (die
->child
!= NULL
)
3630 child_die
= die
->child
;
3631 while (child_die
&& child_die
->tag
)
3633 process_die (child_die
, cu
);
3634 child_die
= sibling_die (child_die
);
3638 /* Decode macro information, if present. Dwarf 2 macro information
3639 refers to information in the line number info statement program
3640 header, so we can only read it if we've read the header
3642 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3643 if (attr
&& line_header
)
3645 unsigned int macro_offset
= DW_UNSND (attr
);
3647 dwarf_decode_macros (line_header
, macro_offset
,
3648 comp_dir
, abfd
, cu
);
3650 do_cleanups (back_to
);
3653 /* For TUs we want to skip the first top level sibling if it's not the
3654 actual type being defined by this TU. In this case the first top
3655 level sibling is there to provide context only. */
3658 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3660 struct objfile
*objfile
= cu
->objfile
;
3661 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3663 struct attribute
*attr
;
3665 char *comp_dir
= NULL
;
3666 struct die_info
*child_die
;
3667 bfd
*abfd
= objfile
->obfd
;
3669 /* start_symtab needs a low pc, but we don't really have one.
3670 Do what read_file_scope would do in the absence of such info. */
3671 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3673 /* Find the filename. Do not use dwarf2_name here, since the filename
3674 is not a source language identifier. */
3675 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3677 name
= DW_STRING (attr
);
3679 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3681 comp_dir
= DW_STRING (attr
);
3682 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3684 comp_dir
= ldirname (name
);
3685 if (comp_dir
!= NULL
)
3686 make_cleanup (xfree
, comp_dir
);
3692 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3694 set_cu_language (DW_UNSND (attr
), cu
);
3696 /* This isn't technically needed today. It is done for symmetry
3697 with read_file_scope. */
3698 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3700 cu
->producer
= DW_STRING (attr
);
3702 /* We assume that we're processing GCC output. */
3703 processing_gcc_compilation
= 2;
3705 processing_has_namespace_info
= 0;
3707 start_symtab (name
, comp_dir
, lowpc
);
3708 record_debugformat ("DWARF 2");
3709 record_producer (cu
->producer
);
3711 /* Process the dies in the type unit. */
3712 if (die
->child
== NULL
)
3714 dump_die_for_error (die
);
3715 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3716 bfd_get_filename (abfd
));
3719 child_die
= die
->child
;
3721 while (child_die
&& child_die
->tag
)
3723 process_die (child_die
, cu
);
3725 child_die
= sibling_die (child_die
);
3728 do_cleanups (back_to
);
3732 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3733 struct dwarf2_cu
*cu
)
3735 struct function_range
*thisfn
;
3737 thisfn
= (struct function_range
*)
3738 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3739 thisfn
->name
= name
;
3740 thisfn
->lowpc
= lowpc
;
3741 thisfn
->highpc
= highpc
;
3742 thisfn
->seen_line
= 0;
3743 thisfn
->next
= NULL
;
3745 if (cu
->last_fn
== NULL
)
3746 cu
->first_fn
= thisfn
;
3748 cu
->last_fn
->next
= thisfn
;
3750 cu
->last_fn
= thisfn
;
3753 /* qsort helper for inherit_abstract_dies. */
3756 unsigned_int_compar (const void *ap
, const void *bp
)
3758 unsigned int a
= *(unsigned int *) ap
;
3759 unsigned int b
= *(unsigned int *) bp
;
3761 return (a
> b
) - (b
> a
);
3764 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3765 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3766 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3769 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3771 struct die_info
*child_die
;
3772 unsigned die_children_count
;
3773 /* CU offsets which were referenced by children of the current DIE. */
3775 unsigned *offsets_end
, *offsetp
;
3776 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3777 struct die_info
*origin_die
;
3778 /* Iterator of the ORIGIN_DIE children. */
3779 struct die_info
*origin_child_die
;
3780 struct cleanup
*cleanups
;
3781 struct attribute
*attr
;
3783 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3787 origin_die
= follow_die_ref (die
, attr
, &cu
);
3788 if (die
->tag
!= origin_die
->tag
3789 && !(die
->tag
== DW_TAG_inlined_subroutine
3790 && origin_die
->tag
== DW_TAG_subprogram
))
3791 complaint (&symfile_complaints
,
3792 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3793 die
->offset
, origin_die
->offset
);
3795 child_die
= die
->child
;
3796 die_children_count
= 0;
3797 while (child_die
&& child_die
->tag
)
3799 child_die
= sibling_die (child_die
);
3800 die_children_count
++;
3802 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3803 cleanups
= make_cleanup (xfree
, offsets
);
3805 offsets_end
= offsets
;
3806 child_die
= die
->child
;
3807 while (child_die
&& child_die
->tag
)
3809 /* For each CHILD_DIE, find the corresponding child of
3810 ORIGIN_DIE. If there is more than one layer of
3811 DW_AT_abstract_origin, follow them all; there shouldn't be,
3812 but GCC versions at least through 4.4 generate this (GCC PR
3814 struct die_info
*child_origin_die
= child_die
;
3818 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
3821 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
3824 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3825 counterpart may exist. */
3826 if (child_origin_die
!= child_die
)
3828 if (child_die
->tag
!= child_origin_die
->tag
3829 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3830 && child_origin_die
->tag
== DW_TAG_subprogram
))
3831 complaint (&symfile_complaints
,
3832 _("Child DIE 0x%x and its abstract origin 0x%x have "
3833 "different tags"), child_die
->offset
,
3834 child_origin_die
->offset
);
3835 if (child_origin_die
->parent
!= origin_die
)
3836 complaint (&symfile_complaints
,
3837 _("Child DIE 0x%x and its abstract origin 0x%x have "
3838 "different parents"), child_die
->offset
,
3839 child_origin_die
->offset
);
3841 *offsets_end
++ = child_origin_die
->offset
;
3843 child_die
= sibling_die (child_die
);
3845 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3846 unsigned_int_compar
);
3847 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3848 if (offsetp
[-1] == *offsetp
)
3849 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3850 "to DIE 0x%x as their abstract origin"),
3851 die
->offset
, *offsetp
);
3854 origin_child_die
= origin_die
->child
;
3855 while (origin_child_die
&& origin_child_die
->tag
)
3857 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3858 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3860 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3862 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3863 process_die (origin_child_die
, cu
);
3865 origin_child_die
= sibling_die (origin_child_die
);
3868 do_cleanups (cleanups
);
3872 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3874 struct objfile
*objfile
= cu
->objfile
;
3875 struct context_stack
*new;
3878 struct die_info
*child_die
;
3879 struct attribute
*attr
, *call_line
, *call_file
;
3882 struct block
*block
;
3883 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3887 /* If we do not have call site information, we can't show the
3888 caller of this inlined function. That's too confusing, so
3889 only use the scope for local variables. */
3890 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3891 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3892 if (call_line
== NULL
|| call_file
== NULL
)
3894 read_lexical_block_scope (die
, cu
);
3899 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3901 name
= dwarf2_name (die
, cu
);
3903 /* Ignore functions with missing or empty names. These are actually
3904 illegal according to the DWARF standard. */
3907 complaint (&symfile_complaints
,
3908 _("missing name for subprogram DIE at %d"), die
->offset
);
3912 /* Ignore functions with missing or invalid low and high pc attributes. */
3913 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3915 attr
= dwarf2_attr (die
, DW_AT_external
, cu
);
3916 if (!attr
|| !DW_UNSND (attr
))
3917 complaint (&symfile_complaints
,
3918 _("cannot get low and high bounds for subprogram DIE at %d"),
3926 /* Record the function range for dwarf_decode_lines. */
3927 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3929 new = push_context (0, lowpc
);
3930 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3932 /* If there is a location expression for DW_AT_frame_base, record
3934 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3936 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3937 expression is being recorded directly in the function's symbol
3938 and not in a separate frame-base object. I guess this hack is
3939 to avoid adding some sort of frame-base adjunct/annex to the
3940 function's symbol :-(. The problem with doing this is that it
3941 results in a function symbol with a location expression that
3942 has nothing to do with the location of the function, ouch! The
3943 relationship should be: a function's symbol has-a frame base; a
3944 frame-base has-a location expression. */
3945 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3947 cu
->list_in_scope
= &local_symbols
;
3949 if (die
->child
!= NULL
)
3951 child_die
= die
->child
;
3952 while (child_die
&& child_die
->tag
)
3954 process_die (child_die
, cu
);
3955 child_die
= sibling_die (child_die
);
3959 inherit_abstract_dies (die
, cu
);
3961 /* If we have a DW_AT_specification, we might need to import using
3962 directives from the context of the specification DIE. See the
3963 comment in determine_prefix. */
3964 if (cu
->language
== language_cplus
3965 && dwarf2_attr (die
, DW_AT_specification
, cu
))
3967 struct dwarf2_cu
*spec_cu
= cu
;
3968 struct die_info
*spec_die
= die_specification (die
, &spec_cu
);
3972 child_die
= spec_die
->child
;
3973 while (child_die
&& child_die
->tag
)
3975 if (child_die
->tag
== DW_TAG_imported_module
)
3976 process_die (child_die
, spec_cu
);
3977 child_die
= sibling_die (child_die
);
3980 /* In some cases, GCC generates specification DIEs that
3981 themselves contain DW_AT_specification attributes. */
3982 spec_die
= die_specification (spec_die
, &spec_cu
);
3986 new = pop_context ();
3987 /* Make a block for the local symbols within. */
3988 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3989 lowpc
, highpc
, objfile
);
3991 /* For C++, set the block's scope. */
3992 if (cu
->language
== language_cplus
|| cu
->language
== language_fortran
)
3993 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3994 determine_prefix (die
, cu
),
3995 processing_has_namespace_info
);
3997 /* If we have address ranges, record them. */
3998 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
4000 /* In C++, we can have functions nested inside functions (e.g., when
4001 a function declares a class that has methods). This means that
4002 when we finish processing a function scope, we may need to go
4003 back to building a containing block's symbol lists. */
4004 local_symbols
= new->locals
;
4005 param_symbols
= new->params
;
4006 using_directives
= new->using_directives
;
4008 /* If we've finished processing a top-level function, subsequent
4009 symbols go in the file symbol list. */
4010 if (outermost_context_p ())
4011 cu
->list_in_scope
= &file_symbols
;
4014 /* Process all the DIES contained within a lexical block scope. Start
4015 a new scope, process the dies, and then close the scope. */
4018 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4020 struct objfile
*objfile
= cu
->objfile
;
4021 struct context_stack
*new;
4022 CORE_ADDR lowpc
, highpc
;
4023 struct die_info
*child_die
;
4026 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4028 /* Ignore blocks with missing or invalid low and high pc attributes. */
4029 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
4030 as multiple lexical blocks? Handling children in a sane way would
4031 be nasty. Might be easier to properly extend generic blocks to
4033 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
4038 push_context (0, lowpc
);
4039 if (die
->child
!= NULL
)
4041 child_die
= die
->child
;
4042 while (child_die
&& child_die
->tag
)
4044 process_die (child_die
, cu
);
4045 child_die
= sibling_die (child_die
);
4048 new = pop_context ();
4050 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
4053 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
4056 /* Note that recording ranges after traversing children, as we
4057 do here, means that recording a parent's ranges entails
4058 walking across all its children's ranges as they appear in
4059 the address map, which is quadratic behavior.
4061 It would be nicer to record the parent's ranges before
4062 traversing its children, simply overriding whatever you find
4063 there. But since we don't even decide whether to create a
4064 block until after we've traversed its children, that's hard
4066 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
4068 local_symbols
= new->locals
;
4069 using_directives
= new->using_directives
;
4072 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
4073 Return 1 if the attributes are present and valid, otherwise, return 0.
4074 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
4077 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
4078 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
4079 struct partial_symtab
*ranges_pst
)
4081 struct objfile
*objfile
= cu
->objfile
;
4082 struct comp_unit_head
*cu_header
= &cu
->header
;
4083 bfd
*obfd
= objfile
->obfd
;
4084 unsigned int addr_size
= cu_header
->addr_size
;
4085 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4086 /* Base address selection entry. */
4097 found_base
= cu
->base_known
;
4098 base
= cu
->base_address
;
4100 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
4101 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4103 complaint (&symfile_complaints
,
4104 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4108 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4110 /* Read in the largest possible address. */
4111 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
4112 if ((marker
& mask
) == mask
)
4114 /* If we found the largest possible address, then
4115 read the base address. */
4116 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4117 buffer
+= 2 * addr_size
;
4118 offset
+= 2 * addr_size
;
4124 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4128 CORE_ADDR range_beginning
, range_end
;
4130 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
4131 buffer
+= addr_size
;
4132 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
4133 buffer
+= addr_size
;
4134 offset
+= 2 * addr_size
;
4136 /* An end of list marker is a pair of zero addresses. */
4137 if (range_beginning
== 0 && range_end
== 0)
4138 /* Found the end of list entry. */
4141 /* Each base address selection entry is a pair of 2 values.
4142 The first is the largest possible address, the second is
4143 the base address. Check for a base address here. */
4144 if ((range_beginning
& mask
) == mask
)
4146 /* If we found the largest possible address, then
4147 read the base address. */
4148 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4155 /* We have no valid base address for the ranges
4157 complaint (&symfile_complaints
,
4158 _("Invalid .debug_ranges data (no base address)"));
4162 range_beginning
+= base
;
4165 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
4166 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4167 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
4170 /* FIXME: This is recording everything as a low-high
4171 segment of consecutive addresses. We should have a
4172 data structure for discontiguous block ranges
4176 low
= range_beginning
;
4182 if (range_beginning
< low
)
4183 low
= range_beginning
;
4184 if (range_end
> high
)
4190 /* If the first entry is an end-of-list marker, the range
4191 describes an empty scope, i.e. no instructions. */
4197 *high_return
= high
;
4201 /* Get low and high pc attributes from a die. Return 1 if the attributes
4202 are present and valid, otherwise, return 0. Return -1 if the range is
4203 discontinuous, i.e. derived from DW_AT_ranges information. */
4205 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
4206 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
4207 struct partial_symtab
*pst
)
4209 struct attribute
*attr
;
4214 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4217 high
= DW_ADDR (attr
);
4218 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4220 low
= DW_ADDR (attr
);
4222 /* Found high w/o low attribute. */
4225 /* Found consecutive range of addresses. */
4230 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4233 /* Value of the DW_AT_ranges attribute is the offset in the
4234 .debug_ranges section. */
4235 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
4237 /* Found discontinuous range of addresses. */
4245 /* When using the GNU linker, .gnu.linkonce. sections are used to
4246 eliminate duplicate copies of functions and vtables and such.
4247 The linker will arbitrarily choose one and discard the others.
4248 The AT_*_pc values for such functions refer to local labels in
4249 these sections. If the section from that file was discarded, the
4250 labels are not in the output, so the relocs get a value of 0.
4251 If this is a discarded function, mark the pc bounds as invalid,
4252 so that GDB will ignore it. */
4253 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
4261 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4262 its low and high PC addresses. Do nothing if these addresses could not
4263 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4264 and HIGHPC to the high address if greater than HIGHPC. */
4267 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
4268 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4269 struct dwarf2_cu
*cu
)
4271 CORE_ADDR low
, high
;
4272 struct die_info
*child
= die
->child
;
4274 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
4276 *lowpc
= min (*lowpc
, low
);
4277 *highpc
= max (*highpc
, high
);
4280 /* If the language does not allow nested subprograms (either inside
4281 subprograms or lexical blocks), we're done. */
4282 if (cu
->language
!= language_ada
)
4285 /* Check all the children of the given DIE. If it contains nested
4286 subprograms, then check their pc bounds. Likewise, we need to
4287 check lexical blocks as well, as they may also contain subprogram
4289 while (child
&& child
->tag
)
4291 if (child
->tag
== DW_TAG_subprogram
4292 || child
->tag
== DW_TAG_lexical_block
)
4293 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
4294 child
= sibling_die (child
);
4298 /* Get the low and high pc's represented by the scope DIE, and store
4299 them in *LOWPC and *HIGHPC. If the correct values can't be
4300 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4303 get_scope_pc_bounds (struct die_info
*die
,
4304 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4305 struct dwarf2_cu
*cu
)
4307 CORE_ADDR best_low
= (CORE_ADDR
) -1;
4308 CORE_ADDR best_high
= (CORE_ADDR
) 0;
4309 CORE_ADDR current_low
, current_high
;
4311 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
4313 best_low
= current_low
;
4314 best_high
= current_high
;
4318 struct die_info
*child
= die
->child
;
4320 while (child
&& child
->tag
)
4322 switch (child
->tag
) {
4323 case DW_TAG_subprogram
:
4324 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
4326 case DW_TAG_namespace
:
4328 /* FIXME: carlton/2004-01-16: Should we do this for
4329 DW_TAG_class_type/DW_TAG_structure_type, too? I think
4330 that current GCC's always emit the DIEs corresponding
4331 to definitions of methods of classes as children of a
4332 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
4333 the DIEs giving the declarations, which could be
4334 anywhere). But I don't see any reason why the
4335 standards says that they have to be there. */
4336 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
4338 if (current_low
!= ((CORE_ADDR
) -1))
4340 best_low
= min (best_low
, current_low
);
4341 best_high
= max (best_high
, current_high
);
4349 child
= sibling_die (child
);
4354 *highpc
= best_high
;
4357 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
4360 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
4361 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
4363 struct attribute
*attr
;
4365 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4368 CORE_ADDR high
= DW_ADDR (attr
);
4370 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4373 CORE_ADDR low
= DW_ADDR (attr
);
4375 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
4379 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4382 bfd
*obfd
= cu
->objfile
->obfd
;
4384 /* The value of the DW_AT_ranges attribute is the offset of the
4385 address range list in the .debug_ranges section. */
4386 unsigned long offset
= DW_UNSND (attr
);
4387 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4389 /* For some target architectures, but not others, the
4390 read_address function sign-extends the addresses it returns.
4391 To recognize base address selection entries, we need a
4393 unsigned int addr_size
= cu
->header
.addr_size
;
4394 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4396 /* The base address, to which the next pair is relative. Note
4397 that this 'base' is a DWARF concept: most entries in a range
4398 list are relative, to reduce the number of relocs against the
4399 debugging information. This is separate from this function's
4400 'baseaddr' argument, which GDB uses to relocate debugging
4401 information from a shared library based on the address at
4402 which the library was loaded. */
4403 CORE_ADDR base
= cu
->base_address
;
4404 int base_known
= cu
->base_known
;
4406 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
4407 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4409 complaint (&symfile_complaints
,
4410 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4417 unsigned int bytes_read
;
4418 CORE_ADDR start
, end
;
4420 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4421 buffer
+= bytes_read
;
4422 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4423 buffer
+= bytes_read
;
4425 /* Did we find the end of the range list? */
4426 if (start
== 0 && end
== 0)
4429 /* Did we find a base address selection entry? */
4430 else if ((start
& base_select_mask
) == base_select_mask
)
4436 /* We found an ordinary address range. */
4441 complaint (&symfile_complaints
,
4442 _("Invalid .debug_ranges data (no base address)"));
4446 record_block_range (block
,
4447 baseaddr
+ base
+ start
,
4448 baseaddr
+ base
+ end
- 1);
4454 /* Add an aggregate field to the field list. */
4457 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
4458 struct dwarf2_cu
*cu
)
4460 struct objfile
*objfile
= cu
->objfile
;
4461 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4462 struct nextfield
*new_field
;
4463 struct attribute
*attr
;
4465 char *fieldname
= "";
4467 /* Allocate a new field list entry and link it in. */
4468 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
4469 make_cleanup (xfree
, new_field
);
4470 memset (new_field
, 0, sizeof (struct nextfield
));
4472 if (die
->tag
== DW_TAG_inheritance
)
4474 new_field
->next
= fip
->baseclasses
;
4475 fip
->baseclasses
= new_field
;
4479 new_field
->next
= fip
->fields
;
4480 fip
->fields
= new_field
;
4484 /* Handle accessibility and virtuality of field.
4485 The default accessibility for members is public, the default
4486 accessibility for inheritance is private. */
4487 if (die
->tag
!= DW_TAG_inheritance
)
4488 new_field
->accessibility
= DW_ACCESS_public
;
4490 new_field
->accessibility
= DW_ACCESS_private
;
4491 new_field
->virtuality
= DW_VIRTUALITY_none
;
4493 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4495 new_field
->accessibility
= DW_UNSND (attr
);
4496 if (new_field
->accessibility
!= DW_ACCESS_public
)
4497 fip
->non_public_fields
= 1;
4498 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4500 new_field
->virtuality
= DW_UNSND (attr
);
4502 fp
= &new_field
->field
;
4504 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
4506 /* Data member other than a C++ static data member. */
4508 /* Get type of field. */
4509 fp
->type
= die_type (die
, cu
);
4511 SET_FIELD_BITPOS (*fp
, 0);
4513 /* Get bit size of field (zero if none). */
4514 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
4517 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
4521 FIELD_BITSIZE (*fp
) = 0;
4524 /* Get bit offset of field. */
4525 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4528 int byte_offset
= 0;
4530 if (attr_form_is_section_offset (attr
))
4531 dwarf2_complex_location_expr_complaint ();
4532 else if (attr_form_is_constant (attr
))
4533 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4534 else if (attr_form_is_block (attr
))
4535 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4537 dwarf2_complex_location_expr_complaint ();
4539 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4541 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
4544 if (gdbarch_bits_big_endian (gdbarch
))
4546 /* For big endian bits, the DW_AT_bit_offset gives the
4547 additional bit offset from the MSB of the containing
4548 anonymous object to the MSB of the field. We don't
4549 have to do anything special since we don't need to
4550 know the size of the anonymous object. */
4551 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
4555 /* For little endian bits, compute the bit offset to the
4556 MSB of the anonymous object, subtract off the number of
4557 bits from the MSB of the field to the MSB of the
4558 object, and then subtract off the number of bits of
4559 the field itself. The result is the bit offset of
4560 the LSB of the field. */
4562 int bit_offset
= DW_UNSND (attr
);
4564 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4567 /* The size of the anonymous object containing
4568 the bit field is explicit, so use the
4569 indicated size (in bytes). */
4570 anonymous_size
= DW_UNSND (attr
);
4574 /* The size of the anonymous object containing
4575 the bit field must be inferred from the type
4576 attribute of the data member containing the
4578 anonymous_size
= TYPE_LENGTH (fp
->type
);
4580 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4581 - bit_offset
- FIELD_BITSIZE (*fp
);
4585 /* Get name of field. */
4586 fieldname
= dwarf2_name (die
, cu
);
4587 if (fieldname
== NULL
)
4590 /* The name is already allocated along with this objfile, so we don't
4591 need to duplicate it for the type. */
4592 fp
->name
= fieldname
;
4594 /* Change accessibility for artificial fields (e.g. virtual table
4595 pointer or virtual base class pointer) to private. */
4596 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4598 FIELD_ARTIFICIAL (*fp
) = 1;
4599 new_field
->accessibility
= DW_ACCESS_private
;
4600 fip
->non_public_fields
= 1;
4603 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4605 /* C++ static member. */
4607 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4608 is a declaration, but all versions of G++ as of this writing
4609 (so through at least 3.2.1) incorrectly generate
4610 DW_TAG_variable tags. */
4614 /* Get name of field. */
4615 fieldname
= dwarf2_name (die
, cu
);
4616 if (fieldname
== NULL
)
4619 /* Get physical name. */
4620 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4622 /* The name is already allocated along with this objfile, so we don't
4623 need to duplicate it for the type. */
4624 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4625 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4626 FIELD_NAME (*fp
) = fieldname
;
4628 else if (die
->tag
== DW_TAG_inheritance
)
4630 /* C++ base class field. */
4631 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4634 int byte_offset
= 0;
4636 if (attr_form_is_section_offset (attr
))
4637 dwarf2_complex_location_expr_complaint ();
4638 else if (attr_form_is_constant (attr
))
4639 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4640 else if (attr_form_is_block (attr
))
4641 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4643 dwarf2_complex_location_expr_complaint ();
4645 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4647 FIELD_BITSIZE (*fp
) = 0;
4648 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4649 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4650 fip
->nbaseclasses
++;
4654 /* Create the vector of fields, and attach it to the type. */
4657 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4658 struct dwarf2_cu
*cu
)
4660 int nfields
= fip
->nfields
;
4662 /* Record the field count, allocate space for the array of fields,
4663 and create blank accessibility bitfields if necessary. */
4664 TYPE_NFIELDS (type
) = nfields
;
4665 TYPE_FIELDS (type
) = (struct field
*)
4666 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4667 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4669 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
4671 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4673 TYPE_FIELD_PRIVATE_BITS (type
) =
4674 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4675 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4677 TYPE_FIELD_PROTECTED_BITS (type
) =
4678 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4679 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4681 TYPE_FIELD_IGNORE_BITS (type
) =
4682 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4683 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4686 /* If the type has baseclasses, allocate and clear a bit vector for
4687 TYPE_FIELD_VIRTUAL_BITS. */
4688 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
4690 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4691 unsigned char *pointer
;
4693 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4694 pointer
= TYPE_ALLOC (type
, num_bytes
);
4695 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4696 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4697 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4700 /* Copy the saved-up fields into the field vector. Start from the head
4701 of the list, adding to the tail of the field array, so that they end
4702 up in the same order in the array in which they were added to the list. */
4703 while (nfields
-- > 0)
4705 struct nextfield
*fieldp
;
4709 fieldp
= fip
->fields
;
4710 fip
->fields
= fieldp
->next
;
4714 fieldp
= fip
->baseclasses
;
4715 fip
->baseclasses
= fieldp
->next
;
4718 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
4719 switch (fieldp
->accessibility
)
4721 case DW_ACCESS_private
:
4722 if (cu
->language
!= language_ada
)
4723 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4726 case DW_ACCESS_protected
:
4727 if (cu
->language
!= language_ada
)
4728 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4731 case DW_ACCESS_public
:
4735 /* Unknown accessibility. Complain and treat it as public. */
4737 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4738 fieldp
->accessibility
);
4742 if (nfields
< fip
->nbaseclasses
)
4744 switch (fieldp
->virtuality
)
4746 case DW_VIRTUALITY_virtual
:
4747 case DW_VIRTUALITY_pure_virtual
:
4748 if (cu
->language
== language_ada
)
4749 error ("unexpected virtuality in component of Ada type");
4750 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4757 /* Add a member function to the proper fieldlist. */
4760 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4761 struct type
*type
, struct dwarf2_cu
*cu
)
4763 struct objfile
*objfile
= cu
->objfile
;
4764 struct attribute
*attr
;
4765 struct fnfieldlist
*flp
;
4767 struct fn_field
*fnp
;
4770 struct nextfnfield
*new_fnfield
;
4771 struct type
*this_type
;
4773 if (cu
->language
== language_ada
)
4774 error ("unexpected member function in Ada type");
4776 /* Get name of member function. */
4777 fieldname
= dwarf2_name (die
, cu
);
4778 if (fieldname
== NULL
)
4781 /* Get the mangled name. */
4782 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4784 /* Look up member function name in fieldlist. */
4785 for (i
= 0; i
< fip
->nfnfields
; i
++)
4787 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4791 /* Create new list element if necessary. */
4792 if (i
< fip
->nfnfields
)
4793 flp
= &fip
->fnfieldlists
[i
];
4796 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4798 fip
->fnfieldlists
= (struct fnfieldlist
*)
4799 xrealloc (fip
->fnfieldlists
,
4800 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4801 * sizeof (struct fnfieldlist
));
4802 if (fip
->nfnfields
== 0)
4803 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4805 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4806 flp
->name
= fieldname
;
4812 /* Create a new member function field and chain it to the field list
4814 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4815 make_cleanup (xfree
, new_fnfield
);
4816 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4817 new_fnfield
->next
= flp
->head
;
4818 flp
->head
= new_fnfield
;
4821 /* Fill in the member function field info. */
4822 fnp
= &new_fnfield
->fnfield
;
4823 /* The name is already allocated along with this objfile, so we don't
4824 need to duplicate it for the type. */
4825 fnp
->physname
= physname
? physname
: "";
4826 fnp
->type
= alloc_type (objfile
);
4827 this_type
= read_type_die (die
, cu
);
4828 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4830 int nparams
= TYPE_NFIELDS (this_type
);
4832 /* TYPE is the domain of this method, and THIS_TYPE is the type
4833 of the method itself (TYPE_CODE_METHOD). */
4834 smash_to_method_type (fnp
->type
, type
,
4835 TYPE_TARGET_TYPE (this_type
),
4836 TYPE_FIELDS (this_type
),
4837 TYPE_NFIELDS (this_type
),
4838 TYPE_VARARGS (this_type
));
4840 /* Handle static member functions.
4841 Dwarf2 has no clean way to discern C++ static and non-static
4842 member functions. G++ helps GDB by marking the first
4843 parameter for non-static member functions (which is the
4844 this pointer) as artificial. We obtain this information
4845 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4846 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4847 fnp
->voffset
= VOFFSET_STATIC
;
4850 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4853 /* Get fcontext from DW_AT_containing_type if present. */
4854 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4855 fnp
->fcontext
= die_containing_type (die
, cu
);
4857 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4858 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4860 /* Get accessibility. */
4861 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4864 switch (DW_UNSND (attr
))
4866 case DW_ACCESS_private
:
4867 fnp
->is_private
= 1;
4869 case DW_ACCESS_protected
:
4870 fnp
->is_protected
= 1;
4875 /* Check for artificial methods. */
4876 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4877 if (attr
&& DW_UNSND (attr
) != 0)
4878 fnp
->is_artificial
= 1;
4880 /* Get index in virtual function table if it is a virtual member
4881 function. For GCC, this is an offset in the appropriate
4882 virtual table, as specified by DW_AT_containing_type. For
4883 everyone else, it is an expression to be evaluated relative
4884 to the object address. */
4886 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4887 if (attr
&& fnp
->fcontext
)
4889 /* Support the .debug_loc offsets */
4890 if (attr_form_is_block (attr
))
4892 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4894 else if (attr_form_is_section_offset (attr
))
4896 dwarf2_complex_location_expr_complaint ();
4900 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4906 /* We only support trivial expressions here. This hack will work
4907 for v3 classes, which always start with the vtable pointer. */
4908 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0
4909 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref
)
4911 struct dwarf_block blk
;
4913 blk
.size
= DW_BLOCK (attr
)->size
- 1;
4914 blk
.data
= DW_BLOCK (attr
)->data
+ 1;
4915 fnp
->voffset
= decode_locdesc (&blk
, cu
);
4916 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
4917 dwarf2_complex_location_expr_complaint ();
4919 fnp
->voffset
/= cu
->header
.addr_size
;
4921 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
4924 dwarf2_complex_location_expr_complaint ();
4928 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4929 if (attr
&& DW_UNSND (attr
))
4931 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4932 complaint (&symfile_complaints
,
4933 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4934 fieldname
, die
->offset
);
4935 TYPE_CPLUS_DYNAMIC (type
) = 1;
4940 /* Create the vector of member function fields, and attach it to the type. */
4943 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4944 struct dwarf2_cu
*cu
)
4946 struct fnfieldlist
*flp
;
4947 int total_length
= 0;
4950 if (cu
->language
== language_ada
)
4951 error ("unexpected member functions in Ada type");
4953 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4954 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4955 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4957 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4959 struct nextfnfield
*nfp
= flp
->head
;
4960 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4963 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4964 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4965 fn_flp
->fn_fields
= (struct fn_field
*)
4966 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4967 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4968 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4970 total_length
+= flp
->length
;
4973 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4974 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4977 /* Returns non-zero if NAME is the name of a vtable member in CU's
4978 language, zero otherwise. */
4980 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4982 static const char vptr
[] = "_vptr";
4983 static const char vtable
[] = "vtable";
4985 /* Look for the C++ and Java forms of the vtable. */
4986 if ((cu
->language
== language_java
4987 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4988 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4989 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4995 /* GCC outputs unnamed structures that are really pointers to member
4996 functions, with the ABI-specified layout. If TYPE describes
4997 such a structure, smash it into a member function type.
4999 GCC shouldn't do this; it should just output pointer to member DIEs.
5000 This is GCC PR debug/28767. */
5003 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
5005 struct type
*pfn_type
, *domain_type
, *new_type
;
5007 /* Check for a structure with no name and two children. */
5008 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
5011 /* Check for __pfn and __delta members. */
5012 if (TYPE_FIELD_NAME (type
, 0) == NULL
5013 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
5014 || TYPE_FIELD_NAME (type
, 1) == NULL
5015 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
5018 /* Find the type of the method. */
5019 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
5020 if (pfn_type
== NULL
5021 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
5022 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
5025 /* Look for the "this" argument. */
5026 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
5027 if (TYPE_NFIELDS (pfn_type
) == 0
5028 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
5029 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
5032 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
5033 new_type
= alloc_type (objfile
);
5034 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
5035 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
5036 TYPE_VARARGS (pfn_type
));
5037 smash_to_methodptr_type (type
, new_type
);
5040 /* Called when we find the DIE that starts a structure or union scope
5041 (definition) to process all dies that define the members of the
5044 NOTE: we need to call struct_type regardless of whether or not the
5045 DIE has an at_name attribute, since it might be an anonymous
5046 structure or union. This gets the type entered into our set of
5049 However, if the structure is incomplete (an opaque struct/union)
5050 then suppress creating a symbol table entry for it since gdb only
5051 wants to find the one with the complete definition. Note that if
5052 it is complete, we just call new_symbol, which does it's own
5053 checking about whether the struct/union is anonymous or not (and
5054 suppresses creating a symbol table entry itself). */
5056 static struct type
*
5057 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5059 struct objfile
*objfile
= cu
->objfile
;
5061 struct attribute
*attr
;
5063 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5065 /* If the definition of this type lives in .debug_types, read that type.
5066 Don't follow DW_AT_specification though, that will take us back up
5067 the chain and we want to go down. */
5068 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5071 struct dwarf2_cu
*type_cu
= cu
;
5072 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5074 /* We could just recurse on read_structure_type, but we need to call
5075 get_die_type to ensure only one type for this DIE is created.
5076 This is important, for example, because for c++ classes we need
5077 TYPE_NAME set which is only done by new_symbol. Blech. */
5078 type
= read_type_die (type_die
, type_cu
);
5079 return set_die_type (die
, type
, cu
);
5082 type
= alloc_type (objfile
);
5083 INIT_CPLUS_SPECIFIC (type
);
5085 name
= dwarf2_name (die
, cu
);
5088 if (cu
->language
== language_cplus
5089 || cu
->language
== language_java
)
5091 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
5092 if (die
->tag
== DW_TAG_structure_type
5093 || die
->tag
== DW_TAG_class_type
)
5094 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5098 /* The name is already allocated along with this objfile, so
5099 we don't need to duplicate it for the type. */
5100 TYPE_TAG_NAME (type
) = (char *) name
;
5101 if (die
->tag
== DW_TAG_class_type
)
5102 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5106 if (die
->tag
== DW_TAG_structure_type
)
5108 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
5110 else if (die
->tag
== DW_TAG_union_type
)
5112 TYPE_CODE (type
) = TYPE_CODE_UNION
;
5116 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
5119 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
5120 TYPE_DECLARED_CLASS (type
) = 1;
5122 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5125 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5129 TYPE_LENGTH (type
) = 0;
5132 TYPE_STUB_SUPPORTED (type
) = 1;
5133 if (die_is_declaration (die
, cu
))
5134 TYPE_STUB (type
) = 1;
5135 else if (attr
== NULL
&& die
->child
== NULL
5136 && producer_is_realview (cu
->producer
))
5137 /* RealView does not output the required DW_AT_declaration
5138 on incomplete types. */
5139 TYPE_STUB (type
) = 1;
5141 set_descriptive_type (type
, die
, cu
);
5143 /* We need to add the type field to the die immediately so we don't
5144 infinitely recurse when dealing with pointers to the structure
5145 type within the structure itself. */
5146 set_die_type (die
, type
, cu
);
5148 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
5150 struct field_info fi
;
5151 struct die_info
*child_die
;
5153 memset (&fi
, 0, sizeof (struct field_info
));
5155 child_die
= die
->child
;
5157 while (child_die
&& child_die
->tag
)
5159 if (child_die
->tag
== DW_TAG_member
5160 || child_die
->tag
== DW_TAG_variable
)
5162 /* NOTE: carlton/2002-11-05: A C++ static data member
5163 should be a DW_TAG_member that is a declaration, but
5164 all versions of G++ as of this writing (so through at
5165 least 3.2.1) incorrectly generate DW_TAG_variable
5166 tags for them instead. */
5167 dwarf2_add_field (&fi
, child_die
, cu
);
5169 else if (child_die
->tag
== DW_TAG_subprogram
)
5171 /* C++ member function. */
5172 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
5174 else if (child_die
->tag
== DW_TAG_inheritance
)
5176 /* C++ base class field. */
5177 dwarf2_add_field (&fi
, child_die
, cu
);
5179 child_die
= sibling_die (child_die
);
5182 /* Attach fields and member functions to the type. */
5184 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
5187 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
5189 /* Get the type which refers to the base class (possibly this
5190 class itself) which contains the vtable pointer for the current
5191 class from the DW_AT_containing_type attribute. This use of
5192 DW_AT_containing_type is a GNU extension. */
5194 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5196 struct type
*t
= die_containing_type (die
, cu
);
5198 TYPE_VPTR_BASETYPE (type
) = t
;
5203 /* Our own class provides vtbl ptr. */
5204 for (i
= TYPE_NFIELDS (t
) - 1;
5205 i
>= TYPE_N_BASECLASSES (t
);
5208 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
5210 if (is_vtable_name (fieldname
, cu
))
5212 TYPE_VPTR_FIELDNO (type
) = i
;
5217 /* Complain if virtual function table field not found. */
5218 if (i
< TYPE_N_BASECLASSES (t
))
5219 complaint (&symfile_complaints
,
5220 _("virtual function table pointer not found when defining class '%s'"),
5221 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
5226 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
5229 else if (cu
->producer
5230 && strncmp (cu
->producer
,
5231 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5233 /* The IBM XLC compiler does not provide direct indication
5234 of the containing type, but the vtable pointer is
5235 always named __vfp. */
5239 for (i
= TYPE_NFIELDS (type
) - 1;
5240 i
>= TYPE_N_BASECLASSES (type
);
5243 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
5245 TYPE_VPTR_FIELDNO (type
) = i
;
5246 TYPE_VPTR_BASETYPE (type
) = type
;
5254 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
5256 do_cleanups (back_to
);
5261 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5263 struct die_info
*child_die
= die
->child
;
5264 struct type
*this_type
;
5266 this_type
= get_die_type (die
, cu
);
5267 if (this_type
== NULL
)
5268 this_type
= read_structure_type (die
, cu
);
5270 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5271 snapshots) has been known to create a die giving a declaration
5272 for a class that has, as a child, a die giving a definition for a
5273 nested class. So we have to process our children even if the
5274 current die is a declaration. Normally, of course, a declaration
5275 won't have any children at all. */
5277 while (child_die
!= NULL
&& child_die
->tag
)
5279 if (child_die
->tag
== DW_TAG_member
5280 || child_die
->tag
== DW_TAG_variable
5281 || child_die
->tag
== DW_TAG_inheritance
)
5286 process_die (child_die
, cu
);
5288 child_die
= sibling_die (child_die
);
5291 /* Do not consider external references. According to the DWARF standard,
5292 these DIEs are identified by the fact that they have no byte_size
5293 attribute, and a declaration attribute. */
5294 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
5295 || !die_is_declaration (die
, cu
))
5296 new_symbol (die
, this_type
, cu
);
5299 /* Given a DW_AT_enumeration_type die, set its type. We do not
5300 complete the type's fields yet, or create any symbols. */
5302 static struct type
*
5303 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5305 struct objfile
*objfile
= cu
->objfile
;
5307 struct attribute
*attr
;
5310 /* If the definition of this type lives in .debug_types, read that type.
5311 Don't follow DW_AT_specification though, that will take us back up
5312 the chain and we want to go down. */
5313 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5316 struct dwarf2_cu
*type_cu
= cu
;
5317 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5319 type
= read_type_die (type_die
, type_cu
);
5320 return set_die_type (die
, type
, cu
);
5323 type
= alloc_type (objfile
);
5325 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
5326 name
= dwarf2_full_name (NULL
, die
, cu
);
5328 TYPE_TAG_NAME (type
) = (char *) name
;
5330 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5333 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5337 TYPE_LENGTH (type
) = 0;
5340 /* The enumeration DIE can be incomplete. In Ada, any type can be
5341 declared as private in the package spec, and then defined only
5342 inside the package body. Such types are known as Taft Amendment
5343 Types. When another package uses such a type, an incomplete DIE
5344 may be generated by the compiler. */
5345 if (die_is_declaration (die
, cu
))
5346 TYPE_STUB (type
) = 1;
5348 return set_die_type (die
, type
, cu
);
5351 /* Given a pointer to a die which begins an enumeration, process all
5352 the dies that define the members of the enumeration, and create the
5353 symbol for the enumeration type.
5355 NOTE: We reverse the order of the element list. */
5358 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5360 struct die_info
*child_die
;
5361 struct field
*fields
;
5364 int unsigned_enum
= 1;
5366 struct type
*this_type
;
5370 this_type
= get_die_type (die
, cu
);
5371 if (this_type
== NULL
)
5372 this_type
= read_enumeration_type (die
, cu
);
5373 if (die
->child
!= NULL
)
5375 child_die
= die
->child
;
5376 while (child_die
&& child_die
->tag
)
5378 if (child_die
->tag
!= DW_TAG_enumerator
)
5380 process_die (child_die
, cu
);
5384 name
= dwarf2_name (child_die
, cu
);
5387 sym
= new_symbol (child_die
, this_type
, cu
);
5388 if (SYMBOL_VALUE (sym
) < 0)
5391 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5393 fields
= (struct field
*)
5395 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
5396 * sizeof (struct field
));
5399 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
5400 FIELD_TYPE (fields
[num_fields
]) = NULL
;
5401 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
5402 FIELD_BITSIZE (fields
[num_fields
]) = 0;
5408 child_die
= sibling_die (child_die
);
5413 TYPE_NFIELDS (this_type
) = num_fields
;
5414 TYPE_FIELDS (this_type
) = (struct field
*)
5415 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
5416 memcpy (TYPE_FIELDS (this_type
), fields
,
5417 sizeof (struct field
) * num_fields
);
5421 TYPE_UNSIGNED (this_type
) = 1;
5424 new_symbol (die
, this_type
, cu
);
5427 /* Extract all information from a DW_TAG_array_type DIE and put it in
5428 the DIE's type field. For now, this only handles one dimensional
5431 static struct type
*
5432 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5434 struct objfile
*objfile
= cu
->objfile
;
5435 struct die_info
*child_die
;
5436 struct type
*type
= NULL
;
5437 struct type
*element_type
, *range_type
, *index_type
;
5438 struct type
**range_types
= NULL
;
5439 struct attribute
*attr
;
5441 struct cleanup
*back_to
;
5444 element_type
= die_type (die
, cu
);
5446 /* Irix 6.2 native cc creates array types without children for
5447 arrays with unspecified length. */
5448 if (die
->child
== NULL
)
5450 index_type
= objfile_type (objfile
)->builtin_int
;
5451 range_type
= create_range_type (NULL
, index_type
, 0, -1);
5452 type
= create_array_type (NULL
, element_type
, range_type
);
5453 return set_die_type (die
, type
, cu
);
5456 back_to
= make_cleanup (null_cleanup
, NULL
);
5457 child_die
= die
->child
;
5458 while (child_die
&& child_die
->tag
)
5460 if (child_die
->tag
== DW_TAG_subrange_type
)
5462 struct type
*child_type
= read_type_die (child_die
, cu
);
5464 if (child_type
!= NULL
)
5466 /* The range type was succesfully read. Save it for
5467 the array type creation. */
5468 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
5470 range_types
= (struct type
**)
5471 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
5472 * sizeof (struct type
*));
5474 make_cleanup (free_current_contents
, &range_types
);
5476 range_types
[ndim
++] = child_type
;
5479 child_die
= sibling_die (child_die
);
5482 /* Dwarf2 dimensions are output from left to right, create the
5483 necessary array types in backwards order. */
5485 type
= element_type
;
5487 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
5492 type
= create_array_type (NULL
, type
, range_types
[i
++]);
5497 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
5500 /* Understand Dwarf2 support for vector types (like they occur on
5501 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5502 array type. This is not part of the Dwarf2/3 standard yet, but a
5503 custom vendor extension. The main difference between a regular
5504 array and the vector variant is that vectors are passed by value
5506 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
5508 make_vector_type (type
);
5510 name
= dwarf2_name (die
, cu
);
5512 TYPE_NAME (type
) = name
;
5514 set_descriptive_type (type
, die
, cu
);
5516 do_cleanups (back_to
);
5518 /* Install the type in the die. */
5519 return set_die_type (die
, type
, cu
);
5522 static enum dwarf_array_dim_ordering
5523 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
5525 struct attribute
*attr
;
5527 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
5529 if (attr
) return DW_SND (attr
);
5532 GNU F77 is a special case, as at 08/2004 array type info is the
5533 opposite order to the dwarf2 specification, but data is still
5534 laid out as per normal fortran.
5536 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5540 if (cu
->language
== language_fortran
5541 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
5543 return DW_ORD_row_major
;
5546 switch (cu
->language_defn
->la_array_ordering
)
5548 case array_column_major
:
5549 return DW_ORD_col_major
;
5550 case array_row_major
:
5552 return DW_ORD_row_major
;
5556 /* Extract all information from a DW_TAG_set_type DIE and put it in
5557 the DIE's type field. */
5559 static struct type
*
5560 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5562 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
5563 struct attribute
*attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5566 TYPE_LENGTH (set_type
) = DW_UNSND (attr
);
5567 return set_die_type (die
, set_type
, cu
);
5570 /* First cut: install each common block member as a global variable. */
5573 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
5575 struct die_info
*child_die
;
5576 struct attribute
*attr
;
5578 CORE_ADDR base
= (CORE_ADDR
) 0;
5580 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5583 /* Support the .debug_loc offsets */
5584 if (attr_form_is_block (attr
))
5586 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
5588 else if (attr_form_is_section_offset (attr
))
5590 dwarf2_complex_location_expr_complaint ();
5594 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5595 "common block member");
5598 if (die
->child
!= NULL
)
5600 child_die
= die
->child
;
5601 while (child_die
&& child_die
->tag
)
5603 sym
= new_symbol (child_die
, NULL
, cu
);
5604 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
5607 CORE_ADDR byte_offset
= 0;
5609 if (attr_form_is_section_offset (attr
))
5610 dwarf2_complex_location_expr_complaint ();
5611 else if (attr_form_is_constant (attr
))
5612 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5613 else if (attr_form_is_block (attr
))
5614 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5616 dwarf2_complex_location_expr_complaint ();
5618 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
5619 add_symbol_to_list (sym
, &global_symbols
);
5621 child_die
= sibling_die (child_die
);
5626 /* Create a type for a C++ namespace. */
5628 static struct type
*
5629 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5631 struct objfile
*objfile
= cu
->objfile
;
5632 const char *previous_prefix
, *name
;
5636 /* For extensions, reuse the type of the original namespace. */
5637 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5639 struct die_info
*ext_die
;
5640 struct dwarf2_cu
*ext_cu
= cu
;
5642 ext_die
= dwarf2_extension (die
, &ext_cu
);
5643 type
= read_type_die (ext_die
, ext_cu
);
5644 return set_die_type (die
, type
, cu
);
5647 name
= namespace_name (die
, &is_anonymous
, cu
);
5649 /* Now build the name of the current namespace. */
5651 previous_prefix
= determine_prefix (die
, cu
);
5652 if (previous_prefix
[0] != '\0')
5653 name
= typename_concat (&objfile
->objfile_obstack
,
5654 previous_prefix
, name
, 0, cu
);
5656 /* Create the type. */
5657 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5659 TYPE_NAME (type
) = (char *) name
;
5660 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5662 return set_die_type (die
, type
, cu
);
5665 /* Read a C++ namespace. */
5668 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5670 struct objfile
*objfile
= cu
->objfile
;
5674 /* Add a symbol associated to this if we haven't seen the namespace
5675 before. Also, add a using directive if it's an anonymous
5678 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5682 type
= read_type_die (die
, cu
);
5683 new_symbol (die
, type
, cu
);
5685 name
= namespace_name (die
, &is_anonymous
, cu
);
5688 const char *previous_prefix
= determine_prefix (die
, cu
);
5690 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
5691 NULL
, &objfile
->objfile_obstack
);
5695 if (die
->child
!= NULL
)
5697 struct die_info
*child_die
= die
->child
;
5699 while (child_die
&& child_die
->tag
)
5701 process_die (child_die
, cu
);
5702 child_die
= sibling_die (child_die
);
5707 /* Read a Fortran module as type. This DIE can be only a declaration used for
5708 imported module. Still we need that type as local Fortran "use ... only"
5709 declaration imports depend on the created type in determine_prefix. */
5711 static struct type
*
5712 read_module_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5714 struct objfile
*objfile
= cu
->objfile
;
5718 module_name
= dwarf2_name (die
, cu
);
5720 complaint (&symfile_complaints
, _("DW_TAG_module has no name, offset 0x%x"),
5722 type
= init_type (TYPE_CODE_MODULE
, 0, 0, module_name
, objfile
);
5724 /* determine_prefix uses TYPE_TAG_NAME. */
5725 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5727 return set_die_type (die
, type
, cu
);
5730 /* Read a Fortran module. */
5733 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5735 struct die_info
*child_die
= die
->child
;
5737 while (child_die
&& child_die
->tag
)
5739 process_die (child_die
, cu
);
5740 child_die
= sibling_die (child_die
);
5744 /* Return the name of the namespace represented by DIE. Set
5745 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5749 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5751 struct die_info
*current_die
;
5752 const char *name
= NULL
;
5754 /* Loop through the extensions until we find a name. */
5756 for (current_die
= die
;
5757 current_die
!= NULL
;
5758 current_die
= dwarf2_extension (die
, &cu
))
5760 name
= dwarf2_name (current_die
, cu
);
5765 /* Is it an anonymous namespace? */
5767 *is_anonymous
= (name
== NULL
);
5769 name
= "(anonymous namespace)";
5774 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5775 the user defined type vector. */
5777 static struct type
*
5778 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5780 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5781 struct comp_unit_head
*cu_header
= &cu
->header
;
5783 struct attribute
*attr_byte_size
;
5784 struct attribute
*attr_address_class
;
5785 int byte_size
, addr_class
;
5787 type
= lookup_pointer_type (die_type (die
, cu
));
5789 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5791 byte_size
= DW_UNSND (attr_byte_size
);
5793 byte_size
= cu_header
->addr_size
;
5795 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5796 if (attr_address_class
)
5797 addr_class
= DW_UNSND (attr_address_class
);
5799 addr_class
= DW_ADDR_none
;
5801 /* If the pointer size or address class is different than the
5802 default, create a type variant marked as such and set the
5803 length accordingly. */
5804 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5806 if (gdbarch_address_class_type_flags_p (gdbarch
))
5810 type_flags
= gdbarch_address_class_type_flags
5811 (gdbarch
, byte_size
, addr_class
);
5812 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5814 type
= make_type_with_address_space (type
, type_flags
);
5816 else if (TYPE_LENGTH (type
) != byte_size
)
5818 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5822 /* Should we also complain about unhandled address classes? */
5826 TYPE_LENGTH (type
) = byte_size
;
5827 return set_die_type (die
, type
, cu
);
5830 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5831 the user defined type vector. */
5833 static struct type
*
5834 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5837 struct type
*to_type
;
5838 struct type
*domain
;
5840 to_type
= die_type (die
, cu
);
5841 domain
= die_containing_type (die
, cu
);
5843 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5844 type
= lookup_methodptr_type (to_type
);
5846 type
= lookup_memberptr_type (to_type
, domain
);
5848 return set_die_type (die
, type
, cu
);
5851 /* Extract all information from a DW_TAG_reference_type DIE and add to
5852 the user defined type vector. */
5854 static struct type
*
5855 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5857 struct comp_unit_head
*cu_header
= &cu
->header
;
5859 struct attribute
*attr
;
5861 type
= lookup_reference_type (die_type (die
, cu
));
5862 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5865 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5869 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5871 return set_die_type (die
, type
, cu
);
5874 static struct type
*
5875 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5877 struct type
*base_type
, *cv_type
;
5879 base_type
= die_type (die
, cu
);
5880 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5881 return set_die_type (die
, cv_type
, cu
);
5884 static struct type
*
5885 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5887 struct type
*base_type
, *cv_type
;
5889 base_type
= die_type (die
, cu
);
5890 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5891 return set_die_type (die
, cv_type
, cu
);
5894 /* Extract all information from a DW_TAG_string_type DIE and add to
5895 the user defined type vector. It isn't really a user defined type,
5896 but it behaves like one, with other DIE's using an AT_user_def_type
5897 attribute to reference it. */
5899 static struct type
*
5900 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5902 struct objfile
*objfile
= cu
->objfile
;
5903 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5904 struct type
*type
, *range_type
, *index_type
, *char_type
;
5905 struct attribute
*attr
;
5906 unsigned int length
;
5908 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5911 length
= DW_UNSND (attr
);
5915 /* check for the DW_AT_byte_size attribute */
5916 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5919 length
= DW_UNSND (attr
);
5927 index_type
= objfile_type (objfile
)->builtin_int
;
5928 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5929 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5930 type
= create_string_type (NULL
, char_type
, range_type
);
5932 return set_die_type (die
, type
, cu
);
5935 /* Handle DIES due to C code like:
5939 int (*funcp)(int a, long l);
5943 ('funcp' generates a DW_TAG_subroutine_type DIE)
5946 static struct type
*
5947 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5949 struct type
*type
; /* Type that this function returns */
5950 struct type
*ftype
; /* Function that returns above type */
5951 struct attribute
*attr
;
5953 type
= die_type (die
, cu
);
5954 ftype
= lookup_function_type (type
);
5956 /* All functions in C++, Pascal and Java have prototypes. */
5957 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5958 if ((attr
&& (DW_UNSND (attr
) != 0))
5959 || cu
->language
== language_cplus
5960 || cu
->language
== language_java
5961 || cu
->language
== language_pascal
)
5962 TYPE_PROTOTYPED (ftype
) = 1;
5963 else if (producer_is_realview (cu
->producer
))
5964 /* RealView does not emit DW_AT_prototyped. We can not
5965 distinguish prototyped and unprototyped functions; default to
5966 prototyped, since that is more common in modern code (and
5967 RealView warns about unprototyped functions). */
5968 TYPE_PROTOTYPED (ftype
) = 1;
5970 /* Store the calling convention in the type if it's available in
5971 the subroutine die. Otherwise set the calling convention to
5972 the default value DW_CC_normal. */
5973 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5974 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5976 /* We need to add the subroutine type to the die immediately so
5977 we don't infinitely recurse when dealing with parameters
5978 declared as the same subroutine type. */
5979 set_die_type (die
, ftype
, cu
);
5981 if (die
->child
!= NULL
)
5983 struct type
*void_type
= objfile_type (cu
->objfile
)->builtin_void
;
5984 struct die_info
*child_die
;
5985 int nparams
, iparams
;
5987 /* Count the number of parameters.
5988 FIXME: GDB currently ignores vararg functions, but knows about
5989 vararg member functions. */
5991 child_die
= die
->child
;
5992 while (child_die
&& child_die
->tag
)
5994 if (child_die
->tag
== DW_TAG_formal_parameter
)
5996 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5997 TYPE_VARARGS (ftype
) = 1;
5998 child_die
= sibling_die (child_die
);
6001 /* Allocate storage for parameters and fill them in. */
6002 TYPE_NFIELDS (ftype
) = nparams
;
6003 TYPE_FIELDS (ftype
) = (struct field
*)
6004 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
6006 /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
6007 even if we error out during the parameters reading below. */
6008 for (iparams
= 0; iparams
< nparams
; iparams
++)
6009 TYPE_FIELD_TYPE (ftype
, iparams
) = void_type
;
6012 child_die
= die
->child
;
6013 while (child_die
&& child_die
->tag
)
6015 if (child_die
->tag
== DW_TAG_formal_parameter
)
6017 /* Dwarf2 has no clean way to discern C++ static and non-static
6018 member functions. G++ helps GDB by marking the first
6019 parameter for non-static member functions (which is the
6020 this pointer) as artificial. We pass this information
6021 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
6022 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
6024 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
6027 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
6029 /* GCC/43521: In java, the formal parameter
6030 "this" is sometimes not marked with DW_AT_artificial. */
6031 if (cu
->language
== language_java
)
6033 const char *name
= dwarf2_name (child_die
, cu
);
6035 if (name
&& !strcmp (name
, "this"))
6036 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 1;
6039 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
6042 child_die
= sibling_die (child_die
);
6049 static struct type
*
6050 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
6052 struct objfile
*objfile
= cu
->objfile
;
6053 const char *name
= NULL
;
6054 struct type
*this_type
;
6056 name
= dwarf2_full_name (NULL
, die
, cu
);
6057 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
6058 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
6059 TYPE_NAME (this_type
) = (char *) name
;
6060 set_die_type (die
, this_type
, cu
);
6061 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
6065 /* Find a representation of a given base type and install
6066 it in the TYPE field of the die. */
6068 static struct type
*
6069 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6071 struct objfile
*objfile
= cu
->objfile
;
6073 struct attribute
*attr
;
6074 int encoding
= 0, size
= 0;
6076 enum type_code code
= TYPE_CODE_INT
;
6078 struct type
*target_type
= NULL
;
6080 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
6083 encoding
= DW_UNSND (attr
);
6085 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6088 size
= DW_UNSND (attr
);
6090 name
= dwarf2_name (die
, cu
);
6093 complaint (&symfile_complaints
,
6094 _("DW_AT_name missing from DW_TAG_base_type"));
6099 case DW_ATE_address
:
6100 /* Turn DW_ATE_address into a void * pointer. */
6101 code
= TYPE_CODE_PTR
;
6102 type_flags
|= TYPE_FLAG_UNSIGNED
;
6103 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
6105 case DW_ATE_boolean
:
6106 code
= TYPE_CODE_BOOL
;
6107 type_flags
|= TYPE_FLAG_UNSIGNED
;
6109 case DW_ATE_complex_float
:
6110 code
= TYPE_CODE_COMPLEX
;
6111 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
6113 case DW_ATE_decimal_float
:
6114 code
= TYPE_CODE_DECFLOAT
;
6117 code
= TYPE_CODE_FLT
;
6121 case DW_ATE_unsigned
:
6122 type_flags
|= TYPE_FLAG_UNSIGNED
;
6124 case DW_ATE_signed_char
:
6125 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6126 || cu
->language
== language_pascal
)
6127 code
= TYPE_CODE_CHAR
;
6129 case DW_ATE_unsigned_char
:
6130 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6131 || cu
->language
== language_pascal
)
6132 code
= TYPE_CODE_CHAR
;
6133 type_flags
|= TYPE_FLAG_UNSIGNED
;
6136 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
6137 dwarf_type_encoding_name (encoding
));
6141 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
6142 TYPE_NAME (type
) = name
;
6143 TYPE_TARGET_TYPE (type
) = target_type
;
6145 if (name
&& strcmp (name
, "char") == 0)
6146 TYPE_NOSIGN (type
) = 1;
6148 return set_die_type (die
, type
, cu
);
6151 /* Read the given DW_AT_subrange DIE. */
6153 static struct type
*
6154 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6156 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6157 struct type
*base_type
;
6158 struct type
*range_type
;
6159 struct attribute
*attr
;
6163 LONGEST negative_mask
;
6165 base_type
= die_type (die
, cu
);
6167 if (cu
->language
== language_fortran
)
6169 /* FORTRAN implies a lower bound of 1, if not given. */
6173 /* FIXME: For variable sized arrays either of these could be
6174 a variable rather than a constant value. We'll allow it,
6175 but we don't know how to handle it. */
6176 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
6178 low
= dwarf2_get_attr_constant_value (attr
, 0);
6180 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
6183 if (attr
->form
== DW_FORM_block1
|| is_ref_attr (attr
))
6185 /* GCC encodes arrays with unspecified or dynamic length
6186 with a DW_FORM_block1 attribute or a reference attribute.
6187 FIXME: GDB does not yet know how to handle dynamic
6188 arrays properly, treat them as arrays with unspecified
6191 FIXME: jimb/2003-09-22: GDB does not really know
6192 how to handle arrays of unspecified length
6193 either; we just represent them as zero-length
6194 arrays. Choose an appropriate upper bound given
6195 the lower bound we've computed above. */
6199 high
= dwarf2_get_attr_constant_value (attr
, 1);
6203 attr
= dwarf2_attr (die
, DW_AT_count
, cu
);
6206 int count
= dwarf2_get_attr_constant_value (attr
, 1);
6207 high
= low
+ count
- 1;
6211 /* Dwarf-2 specifications explicitly allows to create subrange types
6212 without specifying a base type.
6213 In that case, the base type must be set to the type of
6214 the lower bound, upper bound or count, in that order, if any of these
6215 three attributes references an object that has a type.
6216 If no base type is found, the Dwarf-2 specifications say that
6217 a signed integer type of size equal to the size of an address should
6219 For the following C code: `extern char gdb_int [];'
6220 GCC produces an empty range DIE.
6221 FIXME: muller/2010-05-28: Possible references to object for low bound,
6222 high bound or count are not yet handled by this code.
6224 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
6226 struct objfile
*objfile
= cu
->objfile
;
6227 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
6228 int addr_size
= gdbarch_addr_bit (gdbarch
) /8;
6229 struct type
*int_type
= objfile_type (objfile
)->builtin_int
;
6231 /* Test "int", "long int", and "long long int" objfile types,
6232 and select the first one having a size above or equal to the
6233 architecture address size. */
6234 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
6235 base_type
= int_type
;
6238 int_type
= objfile_type (objfile
)->builtin_long
;
6239 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
6240 base_type
= int_type
;
6243 int_type
= objfile_type (objfile
)->builtin_long_long
;
6244 if (int_type
&& TYPE_LENGTH (int_type
) >= addr_size
)
6245 base_type
= int_type
;
6251 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
6252 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
6253 low
|= negative_mask
;
6254 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
6255 high
|= negative_mask
;
6257 range_type
= create_range_type (NULL
, base_type
, low
, high
);
6259 /* Mark arrays with dynamic length at least as an array of unspecified
6260 length. GDB could check the boundary but before it gets implemented at
6261 least allow accessing the array elements. */
6262 if (attr
&& attr
->form
== DW_FORM_block1
)
6263 TYPE_HIGH_BOUND_UNDEFINED (range_type
) = 1;
6265 name
= dwarf2_name (die
, cu
);
6267 TYPE_NAME (range_type
) = name
;
6269 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6271 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
6273 set_descriptive_type (range_type
, die
, cu
);
6275 return set_die_type (die
, range_type
, cu
);
6278 static struct type
*
6279 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6283 /* For now, we only support the C meaning of an unspecified type: void. */
6285 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
6286 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
6288 return set_die_type (die
, type
, cu
);
6291 /* Trivial hash function for die_info: the hash value of a DIE
6292 is its offset in .debug_info for this objfile. */
6295 die_hash (const void *item
)
6297 const struct die_info
*die
= item
;
6302 /* Trivial comparison function for die_info structures: two DIEs
6303 are equal if they have the same offset. */
6306 die_eq (const void *item_lhs
, const void *item_rhs
)
6308 const struct die_info
*die_lhs
= item_lhs
;
6309 const struct die_info
*die_rhs
= item_rhs
;
6311 return die_lhs
->offset
== die_rhs
->offset
;
6314 /* Read a whole compilation unit into a linked list of dies. */
6316 static struct die_info
*
6317 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6319 struct die_reader_specs reader_specs
;
6321 gdb_assert (cu
->die_hash
== NULL
);
6323 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6327 &cu
->comp_unit_obstack
,
6328 hashtab_obstack_allocate
,
6329 dummy_obstack_deallocate
);
6331 init_cu_die_reader (&reader_specs
, cu
);
6333 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
6336 /* Main entry point for reading a DIE and all children.
6337 Read the DIE and dump it if requested. */
6339 static struct die_info
*
6340 read_die_and_children (const struct die_reader_specs
*reader
,
6342 gdb_byte
**new_info_ptr
,
6343 struct die_info
*parent
)
6345 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
6346 new_info_ptr
, parent
);
6348 if (dwarf2_die_debug
)
6350 fprintf_unfiltered (gdb_stdlog
,
6351 "\nRead die from %s of %s:\n",
6352 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
6354 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
6356 : "unknown section",
6357 reader
->abfd
->filename
);
6358 dump_die (result
, dwarf2_die_debug
);
6364 /* Read a single die and all its descendents. Set the die's sibling
6365 field to NULL; set other fields in the die correctly, and set all
6366 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6367 location of the info_ptr after reading all of those dies. PARENT
6368 is the parent of the die in question. */
6370 static struct die_info
*
6371 read_die_and_children_1 (const struct die_reader_specs
*reader
,
6373 gdb_byte
**new_info_ptr
,
6374 struct die_info
*parent
)
6376 struct die_info
*die
;
6380 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
6383 *new_info_ptr
= cur_ptr
;
6386 store_in_ref_table (die
, reader
->cu
);
6389 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
6393 *new_info_ptr
= cur_ptr
;
6396 die
->sibling
= NULL
;
6397 die
->parent
= parent
;
6401 /* Read a die, all of its descendents, and all of its siblings; set
6402 all of the fields of all of the dies correctly. Arguments are as
6403 in read_die_and_children. */
6405 static struct die_info
*
6406 read_die_and_siblings (const struct die_reader_specs
*reader
,
6408 gdb_byte
**new_info_ptr
,
6409 struct die_info
*parent
)
6411 struct die_info
*first_die
, *last_sibling
;
6415 first_die
= last_sibling
= NULL
;
6419 struct die_info
*die
6420 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
6424 *new_info_ptr
= cur_ptr
;
6431 last_sibling
->sibling
= die
;
6437 /* Read the die from the .debug_info section buffer. Set DIEP to
6438 point to a newly allocated die with its information, except for its
6439 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6440 whether the die has children or not. */
6443 read_full_die (const struct die_reader_specs
*reader
,
6444 struct die_info
**diep
, gdb_byte
*info_ptr
,
6447 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6448 struct abbrev_info
*abbrev
;
6449 struct die_info
*die
;
6450 struct dwarf2_cu
*cu
= reader
->cu
;
6451 bfd
*abfd
= reader
->abfd
;
6453 offset
= info_ptr
- reader
->buffer
;
6454 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6455 info_ptr
+= bytes_read
;
6463 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6465 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6467 bfd_get_filename (abfd
));
6469 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6470 die
->offset
= offset
;
6471 die
->tag
= abbrev
->tag
;
6472 die
->abbrev
= abbrev_number
;
6474 die
->num_attrs
= abbrev
->num_attrs
;
6476 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6477 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6478 abfd
, info_ptr
, cu
);
6481 *has_children
= abbrev
->has_children
;
6485 /* In DWARF version 2, the description of the debugging information is
6486 stored in a separate .debug_abbrev section. Before we read any
6487 dies from a section we read in all abbreviations and install them
6488 in a hash table. This function also sets flags in CU describing
6489 the data found in the abbrev table. */
6492 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
6494 struct comp_unit_head
*cu_header
= &cu
->header
;
6495 gdb_byte
*abbrev_ptr
;
6496 struct abbrev_info
*cur_abbrev
;
6497 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
6498 unsigned int abbrev_form
, hash_number
;
6499 struct attr_abbrev
*cur_attrs
;
6500 unsigned int allocated_attrs
;
6502 /* Initialize dwarf2 abbrevs */
6503 obstack_init (&cu
->abbrev_obstack
);
6504 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
6506 * sizeof (struct abbrev_info
*)));
6507 memset (cu
->dwarf2_abbrevs
, 0,
6508 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
6510 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
6511 &dwarf2_per_objfile
->abbrev
);
6512 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
6513 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6514 abbrev_ptr
+= bytes_read
;
6516 allocated_attrs
= ATTR_ALLOC_CHUNK
;
6517 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
6519 /* loop until we reach an abbrev number of 0 */
6520 while (abbrev_number
)
6522 cur_abbrev
= dwarf_alloc_abbrev (cu
);
6524 /* read in abbrev header */
6525 cur_abbrev
->number
= abbrev_number
;
6526 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6527 abbrev_ptr
+= bytes_read
;
6528 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
6531 if (cur_abbrev
->tag
== DW_TAG_namespace
)
6532 cu
->has_namespace_info
= 1;
6534 /* now read in declarations */
6535 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6536 abbrev_ptr
+= bytes_read
;
6537 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6538 abbrev_ptr
+= bytes_read
;
6541 if (cur_abbrev
->num_attrs
== allocated_attrs
)
6543 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
6545 = xrealloc (cur_attrs
, (allocated_attrs
6546 * sizeof (struct attr_abbrev
)));
6549 /* Record whether this compilation unit might have
6550 inter-compilation-unit references. If we don't know what form
6551 this attribute will have, then it might potentially be a
6552 DW_FORM_ref_addr, so we conservatively expect inter-CU
6555 if (abbrev_form
== DW_FORM_ref_addr
6556 || abbrev_form
== DW_FORM_indirect
)
6557 cu
->has_form_ref_addr
= 1;
6559 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
6560 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
6561 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6562 abbrev_ptr
+= bytes_read
;
6563 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6564 abbrev_ptr
+= bytes_read
;
6567 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
6568 (cur_abbrev
->num_attrs
6569 * sizeof (struct attr_abbrev
)));
6570 memcpy (cur_abbrev
->attrs
, cur_attrs
,
6571 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
6573 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
6574 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
6575 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
6577 /* Get next abbreviation.
6578 Under Irix6 the abbreviations for a compilation unit are not
6579 always properly terminated with an abbrev number of 0.
6580 Exit loop if we encounter an abbreviation which we have
6581 already read (which means we are about to read the abbreviations
6582 for the next compile unit) or if the end of the abbreviation
6583 table is reached. */
6584 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
6585 >= dwarf2_per_objfile
->abbrev
.size
)
6587 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6588 abbrev_ptr
+= bytes_read
;
6589 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
6596 /* Release the memory used by the abbrev table for a compilation unit. */
6599 dwarf2_free_abbrev_table (void *ptr_to_cu
)
6601 struct dwarf2_cu
*cu
= ptr_to_cu
;
6603 obstack_free (&cu
->abbrev_obstack
, NULL
);
6604 cu
->dwarf2_abbrevs
= NULL
;
6607 /* Lookup an abbrev_info structure in the abbrev hash table. */
6609 static struct abbrev_info
*
6610 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
6612 unsigned int hash_number
;
6613 struct abbrev_info
*abbrev
;
6615 hash_number
= number
% ABBREV_HASH_SIZE
;
6616 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
6620 if (abbrev
->number
== number
)
6623 abbrev
= abbrev
->next
;
6628 /* Returns nonzero if TAG represents a type that we might generate a partial
6632 is_type_tag_for_partial (int tag
)
6637 /* Some types that would be reasonable to generate partial symbols for,
6638 that we don't at present. */
6639 case DW_TAG_array_type
:
6640 case DW_TAG_file_type
:
6641 case DW_TAG_ptr_to_member_type
:
6642 case DW_TAG_set_type
:
6643 case DW_TAG_string_type
:
6644 case DW_TAG_subroutine_type
:
6646 case DW_TAG_base_type
:
6647 case DW_TAG_class_type
:
6648 case DW_TAG_interface_type
:
6649 case DW_TAG_enumeration_type
:
6650 case DW_TAG_structure_type
:
6651 case DW_TAG_subrange_type
:
6652 case DW_TAG_typedef
:
6653 case DW_TAG_union_type
:
6660 /* Load all DIEs that are interesting for partial symbols into memory. */
6662 static struct partial_die_info
*
6663 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6664 int building_psymtab
, struct dwarf2_cu
*cu
)
6666 struct partial_die_info
*part_die
;
6667 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
6668 struct abbrev_info
*abbrev
;
6669 unsigned int bytes_read
;
6670 unsigned int load_all
= 0;
6672 int nesting_level
= 1;
6677 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
6681 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6685 &cu
->comp_unit_obstack
,
6686 hashtab_obstack_allocate
,
6687 dummy_obstack_deallocate
);
6689 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6690 sizeof (struct partial_die_info
));
6694 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6696 /* A NULL abbrev means the end of a series of children. */
6699 if (--nesting_level
== 0)
6701 /* PART_DIE was probably the last thing allocated on the
6702 comp_unit_obstack, so we could call obstack_free
6703 here. We don't do that because the waste is small,
6704 and will be cleaned up when we're done with this
6705 compilation unit. This way, we're also more robust
6706 against other users of the comp_unit_obstack. */
6709 info_ptr
+= bytes_read
;
6710 last_die
= parent_die
;
6711 parent_die
= parent_die
->die_parent
;
6715 /* Check whether this DIE is interesting enough to save. Normally
6716 we would not be interested in members here, but there may be
6717 later variables referencing them via DW_AT_specification (for
6720 && !is_type_tag_for_partial (abbrev
->tag
)
6721 && abbrev
->tag
!= DW_TAG_enumerator
6722 && abbrev
->tag
!= DW_TAG_subprogram
6723 && abbrev
->tag
!= DW_TAG_lexical_block
6724 && abbrev
->tag
!= DW_TAG_variable
6725 && abbrev
->tag
!= DW_TAG_namespace
6726 && abbrev
->tag
!= DW_TAG_module
6727 && abbrev
->tag
!= DW_TAG_member
)
6729 /* Otherwise we skip to the next sibling, if any. */
6730 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
6734 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
6735 buffer
, info_ptr
, cu
);
6737 /* This two-pass algorithm for processing partial symbols has a
6738 high cost in cache pressure. Thus, handle some simple cases
6739 here which cover the majority of C partial symbols. DIEs
6740 which neither have specification tags in them, nor could have
6741 specification tags elsewhere pointing at them, can simply be
6742 processed and discarded.
6744 This segment is also optional; scan_partial_symbols and
6745 add_partial_symbol will handle these DIEs if we chain
6746 them in normally. When compilers which do not emit large
6747 quantities of duplicate debug information are more common,
6748 this code can probably be removed. */
6750 /* Any complete simple types at the top level (pretty much all
6751 of them, for a language without namespaces), can be processed
6753 if (parent_die
== NULL
6754 && part_die
->has_specification
== 0
6755 && part_die
->is_declaration
== 0
6756 && (part_die
->tag
== DW_TAG_typedef
6757 || part_die
->tag
== DW_TAG_base_type
6758 || part_die
->tag
== DW_TAG_subrange_type
))
6760 if (building_psymtab
&& part_die
->name
!= NULL
)
6761 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6762 VAR_DOMAIN
, LOC_TYPEDEF
,
6763 &cu
->objfile
->static_psymbols
,
6764 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6765 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6769 /* If we're at the second level, and we're an enumerator, and
6770 our parent has no specification (meaning possibly lives in a
6771 namespace elsewhere), then we can add the partial symbol now
6772 instead of queueing it. */
6773 if (part_die
->tag
== DW_TAG_enumerator
6774 && parent_die
!= NULL
6775 && parent_die
->die_parent
== NULL
6776 && parent_die
->tag
== DW_TAG_enumeration_type
6777 && parent_die
->has_specification
== 0)
6779 if (part_die
->name
== NULL
)
6780 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6781 else if (building_psymtab
)
6782 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6783 VAR_DOMAIN
, LOC_CONST
,
6784 (cu
->language
== language_cplus
6785 || cu
->language
== language_java
)
6786 ? &cu
->objfile
->global_psymbols
6787 : &cu
->objfile
->static_psymbols
,
6788 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6790 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6794 /* We'll save this DIE so link it in. */
6795 part_die
->die_parent
= parent_die
;
6796 part_die
->die_sibling
= NULL
;
6797 part_die
->die_child
= NULL
;
6799 if (last_die
&& last_die
== parent_die
)
6800 last_die
->die_child
= part_die
;
6802 last_die
->die_sibling
= part_die
;
6804 last_die
= part_die
;
6806 if (first_die
== NULL
)
6807 first_die
= part_die
;
6809 /* Maybe add the DIE to the hash table. Not all DIEs that we
6810 find interesting need to be in the hash table, because we
6811 also have the parent/sibling/child chains; only those that we
6812 might refer to by offset later during partial symbol reading.
6814 For now this means things that might have be the target of a
6815 DW_AT_specification, DW_AT_abstract_origin, or
6816 DW_AT_extension. DW_AT_extension will refer only to
6817 namespaces; DW_AT_abstract_origin refers to functions (and
6818 many things under the function DIE, but we do not recurse
6819 into function DIEs during partial symbol reading) and
6820 possibly variables as well; DW_AT_specification refers to
6821 declarations. Declarations ought to have the DW_AT_declaration
6822 flag. It happens that GCC forgets to put it in sometimes, but
6823 only for functions, not for types.
6825 Adding more things than necessary to the hash table is harmless
6826 except for the performance cost. Adding too few will result in
6827 wasted time in find_partial_die, when we reread the compilation
6828 unit with load_all_dies set. */
6831 || abbrev
->tag
== DW_TAG_subprogram
6832 || abbrev
->tag
== DW_TAG_variable
6833 || abbrev
->tag
== DW_TAG_namespace
6834 || part_die
->is_declaration
)
6838 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6839 part_die
->offset
, INSERT
);
6843 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6844 sizeof (struct partial_die_info
));
6846 /* For some DIEs we want to follow their children (if any). For C
6847 we have no reason to follow the children of structures; for other
6848 languages we have to, both so that we can get at method physnames
6849 to infer fully qualified class names, and for DW_AT_specification.
6851 For Ada, we need to scan the children of subprograms and lexical
6852 blocks as well because Ada allows the definition of nested
6853 entities that could be interesting for the debugger, such as
6854 nested subprograms for instance. */
6855 if (last_die
->has_children
6857 || last_die
->tag
== DW_TAG_namespace
6858 || last_die
->tag
== DW_TAG_module
6859 || last_die
->tag
== DW_TAG_enumeration_type
6860 || (cu
->language
!= language_c
6861 && (last_die
->tag
== DW_TAG_class_type
6862 || last_die
->tag
== DW_TAG_interface_type
6863 || last_die
->tag
== DW_TAG_structure_type
6864 || last_die
->tag
== DW_TAG_union_type
))
6865 || (cu
->language
== language_ada
6866 && (last_die
->tag
== DW_TAG_subprogram
6867 || last_die
->tag
== DW_TAG_lexical_block
))))
6870 parent_die
= last_die
;
6874 /* Otherwise we skip to the next sibling, if any. */
6875 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
6877 /* Back to the top, do it again. */
6881 /* Read a minimal amount of information into the minimal die structure. */
6884 read_partial_die (struct partial_die_info
*part_die
,
6885 struct abbrev_info
*abbrev
,
6886 unsigned int abbrev_len
, bfd
*abfd
,
6887 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6888 struct dwarf2_cu
*cu
)
6891 struct attribute attr
;
6892 int has_low_pc_attr
= 0;
6893 int has_high_pc_attr
= 0;
6895 memset (part_die
, 0, sizeof (struct partial_die_info
));
6897 part_die
->offset
= info_ptr
- buffer
;
6899 info_ptr
+= abbrev_len
;
6904 part_die
->tag
= abbrev
->tag
;
6905 part_die
->has_children
= abbrev
->has_children
;
6907 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6909 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6911 /* Store the data if it is of an attribute we want to keep in a
6912 partial symbol table. */
6916 switch (part_die
->tag
)
6918 case DW_TAG_compile_unit
:
6919 case DW_TAG_type_unit
:
6920 /* Compilation units have a DW_AT_name that is a filename, not
6921 a source language identifier. */
6922 case DW_TAG_enumeration_type
:
6923 case DW_TAG_enumerator
:
6924 /* These tags always have simple identifiers already; no need
6925 to canonicalize them. */
6926 part_die
->name
= DW_STRING (&attr
);
6930 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6931 &cu
->objfile
->objfile_obstack
);
6935 case DW_AT_linkage_name
:
6936 case DW_AT_MIPS_linkage_name
:
6937 /* Note that both forms of linkage name might appear. We
6938 assume they will be the same, and we only store the last
6940 if (cu
->language
== language_ada
)
6941 part_die
->name
= DW_STRING (&attr
);
6944 has_low_pc_attr
= 1;
6945 part_die
->lowpc
= DW_ADDR (&attr
);
6948 has_high_pc_attr
= 1;
6949 part_die
->highpc
= DW_ADDR (&attr
);
6951 case DW_AT_location
:
6952 /* Support the .debug_loc offsets */
6953 if (attr_form_is_block (&attr
))
6955 part_die
->locdesc
= DW_BLOCK (&attr
);
6957 else if (attr_form_is_section_offset (&attr
))
6959 dwarf2_complex_location_expr_complaint ();
6963 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6964 "partial symbol information");
6967 case DW_AT_external
:
6968 part_die
->is_external
= DW_UNSND (&attr
);
6970 case DW_AT_declaration
:
6971 part_die
->is_declaration
= DW_UNSND (&attr
);
6974 part_die
->has_type
= 1;
6976 case DW_AT_abstract_origin
:
6977 case DW_AT_specification
:
6978 case DW_AT_extension
:
6979 part_die
->has_specification
= 1;
6980 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6983 /* Ignore absolute siblings, they might point outside of
6984 the current compile unit. */
6985 if (attr
.form
== DW_FORM_ref_addr
)
6986 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6988 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
6990 case DW_AT_byte_size
:
6991 part_die
->has_byte_size
= 1;
6993 case DW_AT_calling_convention
:
6994 /* DWARF doesn't provide a way to identify a program's source-level
6995 entry point. DW_AT_calling_convention attributes are only meant
6996 to describe functions' calling conventions.
6998 However, because it's a necessary piece of information in
6999 Fortran, and because DW_CC_program is the only piece of debugging
7000 information whose definition refers to a 'main program' at all,
7001 several compilers have begun marking Fortran main programs with
7002 DW_CC_program --- even when those functions use the standard
7003 calling conventions.
7005 So until DWARF specifies a way to provide this information and
7006 compilers pick up the new representation, we'll support this
7008 if (DW_UNSND (&attr
) == DW_CC_program
7009 && cu
->language
== language_fortran
)
7010 set_main_name (part_die
->name
);
7017 /* When using the GNU linker, .gnu.linkonce. sections are used to
7018 eliminate duplicate copies of functions and vtables and such.
7019 The linker will arbitrarily choose one and discard the others.
7020 The AT_*_pc values for such functions refer to local labels in
7021 these sections. If the section from that file was discarded, the
7022 labels are not in the output, so the relocs get a value of 0.
7023 If this is a discarded function, mark the pc bounds as invalid,
7024 so that GDB will ignore it. */
7025 if (has_low_pc_attr
&& has_high_pc_attr
7026 && part_die
->lowpc
< part_die
->highpc
7027 && (part_die
->lowpc
!= 0
7028 || dwarf2_per_objfile
->has_section_at_zero
))
7029 part_die
->has_pc_info
= 1;
7034 /* Find a cached partial DIE at OFFSET in CU. */
7036 static struct partial_die_info
*
7037 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
7039 struct partial_die_info
*lookup_die
= NULL
;
7040 struct partial_die_info part_die
;
7042 part_die
.offset
= offset
;
7043 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
7048 /* Find a partial DIE at OFFSET, which may or may not be in CU,
7049 except in the case of .debug_types DIEs which do not reference
7050 outside their CU (they do however referencing other types via
7053 static struct partial_die_info
*
7054 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
7056 struct dwarf2_per_cu_data
*per_cu
= NULL
;
7057 struct partial_die_info
*pd
= NULL
;
7059 if (cu
->per_cu
->from_debug_types
)
7061 pd
= find_partial_die_in_comp_unit (offset
, cu
);
7067 if (offset_in_cu_p (&cu
->header
, offset
))
7069 pd
= find_partial_die_in_comp_unit (offset
, cu
);
7074 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
7076 if (per_cu
->cu
== NULL
)
7078 load_partial_comp_unit (per_cu
, cu
->objfile
);
7079 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
7080 dwarf2_per_objfile
->read_in_chain
= per_cu
;
7083 per_cu
->cu
->last_used
= 0;
7084 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
7086 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
7088 struct cleanup
*back_to
;
7089 struct partial_die_info comp_unit_die
;
7090 struct abbrev_info
*abbrev
;
7091 unsigned int bytes_read
;
7094 per_cu
->load_all_dies
= 1;
7096 /* Re-read the DIEs. */
7097 back_to
= make_cleanup (null_cleanup
, 0);
7098 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
7100 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
7101 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
7103 info_ptr
= (dwarf2_per_objfile
->info
.buffer
7104 + per_cu
->cu
->header
.offset
7105 + per_cu
->cu
->header
.first_die_offset
);
7106 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
7107 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
7108 per_cu
->cu
->objfile
->obfd
,
7109 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
7111 if (comp_unit_die
.has_children
)
7112 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
7113 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
7115 do_cleanups (back_to
);
7117 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
7123 internal_error (__FILE__
, __LINE__
,
7124 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
7125 offset
, bfd_get_filename (cu
->objfile
->obfd
));
7129 /* Adjust PART_DIE before generating a symbol for it. This function
7130 may set the is_external flag or change the DIE's name. */
7133 fixup_partial_die (struct partial_die_info
*part_die
,
7134 struct dwarf2_cu
*cu
)
7136 /* If we found a reference attribute and the DIE has no name, try
7137 to find a name in the referred to DIE. */
7139 if (part_die
->name
== NULL
&& part_die
->has_specification
)
7141 struct partial_die_info
*spec_die
;
7143 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
7145 fixup_partial_die (spec_die
, cu
);
7149 part_die
->name
= spec_die
->name
;
7151 /* Copy DW_AT_external attribute if it is set. */
7152 if (spec_die
->is_external
)
7153 part_die
->is_external
= spec_die
->is_external
;
7157 /* Set default names for some unnamed DIEs. */
7158 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
7159 || part_die
->tag
== DW_TAG_class_type
))
7160 part_die
->name
= "(anonymous class)";
7162 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
7163 part_die
->name
= "(anonymous namespace)";
7165 if (part_die
->tag
== DW_TAG_structure_type
7166 || part_die
->tag
== DW_TAG_class_type
7167 || part_die
->tag
== DW_TAG_union_type
)
7168 guess_structure_name (part_die
, cu
);
7171 /* Read an attribute value described by an attribute form. */
7174 read_attribute_value (struct attribute
*attr
, unsigned form
,
7175 bfd
*abfd
, gdb_byte
*info_ptr
,
7176 struct dwarf2_cu
*cu
)
7178 struct comp_unit_head
*cu_header
= &cu
->header
;
7179 unsigned int bytes_read
;
7180 struct dwarf_block
*blk
;
7185 case DW_FORM_ref_addr
:
7186 if (cu
->header
.version
== 2)
7187 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7189 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
7190 info_ptr
+= bytes_read
;
7193 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7194 info_ptr
+= bytes_read
;
7196 case DW_FORM_block2
:
7197 blk
= dwarf_alloc_block (cu
);
7198 blk
->size
= read_2_bytes (abfd
, info_ptr
);
7200 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7201 info_ptr
+= blk
->size
;
7202 DW_BLOCK (attr
) = blk
;
7204 case DW_FORM_block4
:
7205 blk
= dwarf_alloc_block (cu
);
7206 blk
->size
= read_4_bytes (abfd
, info_ptr
);
7208 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7209 info_ptr
+= blk
->size
;
7210 DW_BLOCK (attr
) = blk
;
7213 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
7217 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
7221 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
7224 case DW_FORM_sec_offset
:
7225 DW_UNSND (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
7226 info_ptr
+= bytes_read
;
7228 case DW_FORM_string
:
7229 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
7230 DW_STRING_IS_CANONICAL (attr
) = 0;
7231 info_ptr
+= bytes_read
;
7234 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
7236 DW_STRING_IS_CANONICAL (attr
) = 0;
7237 info_ptr
+= bytes_read
;
7239 case DW_FORM_exprloc
:
7241 blk
= dwarf_alloc_block (cu
);
7242 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7243 info_ptr
+= bytes_read
;
7244 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7245 info_ptr
+= blk
->size
;
7246 DW_BLOCK (attr
) = blk
;
7248 case DW_FORM_block1
:
7249 blk
= dwarf_alloc_block (cu
);
7250 blk
->size
= read_1_byte (abfd
, info_ptr
);
7252 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7253 info_ptr
+= blk
->size
;
7254 DW_BLOCK (attr
) = blk
;
7257 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7261 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7264 case DW_FORM_flag_present
:
7265 DW_UNSND (attr
) = 1;
7268 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
7269 info_ptr
+= bytes_read
;
7272 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7273 info_ptr
+= bytes_read
;
7276 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
7280 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
7284 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
7288 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
7292 /* Convert the signature to something we can record in DW_UNSND
7294 NOTE: This is NULL if the type wasn't found. */
7295 DW_SIGNATURED_TYPE (attr
) =
7296 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
7299 case DW_FORM_ref_udata
:
7300 DW_ADDR (attr
) = (cu
->header
.offset
7301 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
7302 info_ptr
+= bytes_read
;
7304 case DW_FORM_indirect
:
7305 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7306 info_ptr
+= bytes_read
;
7307 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
7310 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7311 dwarf_form_name (form
),
7312 bfd_get_filename (abfd
));
7315 /* We have seen instances where the compiler tried to emit a byte
7316 size attribute of -1 which ended up being encoded as an unsigned
7317 0xffffffff. Although 0xffffffff is technically a valid size value,
7318 an object of this size seems pretty unlikely so we can relatively
7319 safely treat these cases as if the size attribute was invalid and
7320 treat them as zero by default. */
7321 if (attr
->name
== DW_AT_byte_size
7322 && form
== DW_FORM_data4
7323 && DW_UNSND (attr
) >= 0xffffffff)
7326 (&symfile_complaints
,
7327 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7328 hex_string (DW_UNSND (attr
)));
7329 DW_UNSND (attr
) = 0;
7335 /* Read an attribute described by an abbreviated attribute. */
7338 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
7339 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7341 attr
->name
= abbrev
->name
;
7342 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
7345 /* read dwarf information from a buffer */
7348 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
7350 return bfd_get_8 (abfd
, buf
);
7354 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
7356 return bfd_get_signed_8 (abfd
, buf
);
7360 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
7362 return bfd_get_16 (abfd
, buf
);
7366 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7368 return bfd_get_signed_16 (abfd
, buf
);
7372 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
7374 return bfd_get_32 (abfd
, buf
);
7378 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7380 return bfd_get_signed_32 (abfd
, buf
);
7384 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
7386 return bfd_get_64 (abfd
, buf
);
7390 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
7391 unsigned int *bytes_read
)
7393 struct comp_unit_head
*cu_header
= &cu
->header
;
7394 CORE_ADDR retval
= 0;
7396 if (cu_header
->signed_addr_p
)
7398 switch (cu_header
->addr_size
)
7401 retval
= bfd_get_signed_16 (abfd
, buf
);
7404 retval
= bfd_get_signed_32 (abfd
, buf
);
7407 retval
= bfd_get_signed_64 (abfd
, buf
);
7410 internal_error (__FILE__
, __LINE__
,
7411 _("read_address: bad switch, signed [in module %s]"),
7412 bfd_get_filename (abfd
));
7417 switch (cu_header
->addr_size
)
7420 retval
= bfd_get_16 (abfd
, buf
);
7423 retval
= bfd_get_32 (abfd
, buf
);
7426 retval
= bfd_get_64 (abfd
, buf
);
7429 internal_error (__FILE__
, __LINE__
,
7430 _("read_address: bad switch, unsigned [in module %s]"),
7431 bfd_get_filename (abfd
));
7435 *bytes_read
= cu_header
->addr_size
;
7439 /* Read the initial length from a section. The (draft) DWARF 3
7440 specification allows the initial length to take up either 4 bytes
7441 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7442 bytes describe the length and all offsets will be 8 bytes in length
7445 An older, non-standard 64-bit format is also handled by this
7446 function. The older format in question stores the initial length
7447 as an 8-byte quantity without an escape value. Lengths greater
7448 than 2^32 aren't very common which means that the initial 4 bytes
7449 is almost always zero. Since a length value of zero doesn't make
7450 sense for the 32-bit format, this initial zero can be considered to
7451 be an escape value which indicates the presence of the older 64-bit
7452 format. As written, the code can't detect (old format) lengths
7453 greater than 4GB. If it becomes necessary to handle lengths
7454 somewhat larger than 4GB, we could allow other small values (such
7455 as the non-sensical values of 1, 2, and 3) to also be used as
7456 escape values indicating the presence of the old format.
7458 The value returned via bytes_read should be used to increment the
7459 relevant pointer after calling read_initial_length().
7461 [ Note: read_initial_length() and read_offset() are based on the
7462 document entitled "DWARF Debugging Information Format", revision
7463 3, draft 8, dated November 19, 2001. This document was obtained
7466 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7468 This document is only a draft and is subject to change. (So beware.)
7470 Details regarding the older, non-standard 64-bit format were
7471 determined empirically by examining 64-bit ELF files produced by
7472 the SGI toolchain on an IRIX 6.5 machine.
7474 - Kevin, July 16, 2002
7478 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
7480 LONGEST length
= bfd_get_32 (abfd
, buf
);
7482 if (length
== 0xffffffff)
7484 length
= bfd_get_64 (abfd
, buf
+ 4);
7487 else if (length
== 0)
7489 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7490 length
= bfd_get_64 (abfd
, buf
);
7501 /* Cover function for read_initial_length.
7502 Returns the length of the object at BUF, and stores the size of the
7503 initial length in *BYTES_READ and stores the size that offsets will be in
7505 If the initial length size is not equivalent to that specified in
7506 CU_HEADER then issue a complaint.
7507 This is useful when reading non-comp-unit headers. */
7510 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
7511 const struct comp_unit_head
*cu_header
,
7512 unsigned int *bytes_read
,
7513 unsigned int *offset_size
)
7515 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
7517 gdb_assert (cu_header
->initial_length_size
== 4
7518 || cu_header
->initial_length_size
== 8
7519 || cu_header
->initial_length_size
== 12);
7521 if (cu_header
->initial_length_size
!= *bytes_read
)
7522 complaint (&symfile_complaints
,
7523 _("intermixed 32-bit and 64-bit DWARF sections"));
7525 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
7529 /* Read an offset from the data stream. The size of the offset is
7530 given by cu_header->offset_size. */
7533 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
7534 unsigned int *bytes_read
)
7536 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
7538 *bytes_read
= cu_header
->offset_size
;
7542 /* Read an offset from the data stream. */
7545 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
7549 switch (offset_size
)
7552 retval
= bfd_get_32 (abfd
, buf
);
7555 retval
= bfd_get_64 (abfd
, buf
);
7558 internal_error (__FILE__
, __LINE__
,
7559 _("read_offset_1: bad switch [in module %s]"),
7560 bfd_get_filename (abfd
));
7567 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
7569 /* If the size of a host char is 8 bits, we can return a pointer
7570 to the buffer, otherwise we have to copy the data to a buffer
7571 allocated on the temporary obstack. */
7572 gdb_assert (HOST_CHAR_BIT
== 8);
7577 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7579 /* If the size of a host char is 8 bits, we can return a pointer
7580 to the string, otherwise we have to copy the string to a buffer
7581 allocated on the temporary obstack. */
7582 gdb_assert (HOST_CHAR_BIT
== 8);
7585 *bytes_read_ptr
= 1;
7588 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
7589 return (char *) buf
;
7593 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
7594 const struct comp_unit_head
*cu_header
,
7595 unsigned int *bytes_read_ptr
)
7597 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
7599 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
7600 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
7602 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7603 bfd_get_filename (abfd
));
7606 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
7608 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7609 bfd_get_filename (abfd
));
7612 gdb_assert (HOST_CHAR_BIT
== 8);
7613 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
7615 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
7618 static unsigned long
7619 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7621 unsigned long result
;
7622 unsigned int num_read
;
7632 byte
= bfd_get_8 (abfd
, buf
);
7635 result
|= ((unsigned long)(byte
& 127) << shift
);
7636 if ((byte
& 128) == 0)
7642 *bytes_read_ptr
= num_read
;
7647 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7650 int i
, shift
, num_read
;
7659 byte
= bfd_get_8 (abfd
, buf
);
7662 result
|= ((long)(byte
& 127) << shift
);
7664 if ((byte
& 128) == 0)
7669 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
7670 result
|= -(((long)1) << shift
);
7671 *bytes_read_ptr
= num_read
;
7675 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7678 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
7684 byte
= bfd_get_8 (abfd
, buf
);
7686 if ((byte
& 128) == 0)
7692 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
7699 cu
->language
= language_c
;
7701 case DW_LANG_C_plus_plus
:
7702 cu
->language
= language_cplus
;
7705 cu
->language
= language_d
;
7707 case DW_LANG_Fortran77
:
7708 case DW_LANG_Fortran90
:
7709 case DW_LANG_Fortran95
:
7710 cu
->language
= language_fortran
;
7712 case DW_LANG_Mips_Assembler
:
7713 cu
->language
= language_asm
;
7716 cu
->language
= language_java
;
7720 cu
->language
= language_ada
;
7722 case DW_LANG_Modula2
:
7723 cu
->language
= language_m2
;
7725 case DW_LANG_Pascal83
:
7726 cu
->language
= language_pascal
;
7729 cu
->language
= language_objc
;
7731 case DW_LANG_Cobol74
:
7732 case DW_LANG_Cobol85
:
7734 cu
->language
= language_minimal
;
7737 cu
->language_defn
= language_def (cu
->language
);
7740 /* Return the named attribute or NULL if not there. */
7742 static struct attribute
*
7743 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
7746 struct attribute
*spec
= NULL
;
7748 for (i
= 0; i
< die
->num_attrs
; ++i
)
7750 if (die
->attrs
[i
].name
== name
)
7751 return &die
->attrs
[i
];
7752 if (die
->attrs
[i
].name
== DW_AT_specification
7753 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
7754 spec
= &die
->attrs
[i
];
7759 die
= follow_die_ref (die
, spec
, &cu
);
7760 return dwarf2_attr (die
, name
, cu
);
7766 /* Return the named attribute or NULL if not there,
7767 but do not follow DW_AT_specification, etc.
7768 This is for use in contexts where we're reading .debug_types dies.
7769 Following DW_AT_specification, DW_AT_abstract_origin will take us
7770 back up the chain, and we want to go down. */
7772 static struct attribute
*
7773 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
7774 struct dwarf2_cu
*cu
)
7778 for (i
= 0; i
< die
->num_attrs
; ++i
)
7779 if (die
->attrs
[i
].name
== name
)
7780 return &die
->attrs
[i
];
7785 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7786 and holds a non-zero value. This function should only be used for
7787 DW_FORM_flag or DW_FORM_flag_present attributes. */
7790 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7792 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7794 return (attr
&& DW_UNSND (attr
));
7798 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7800 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7801 which value is non-zero. However, we have to be careful with
7802 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7803 (via dwarf2_flag_true_p) follows this attribute. So we may
7804 end up accidently finding a declaration attribute that belongs
7805 to a different DIE referenced by the specification attribute,
7806 even though the given DIE does not have a declaration attribute. */
7807 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7808 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7811 /* Return the die giving the specification for DIE, if there is
7812 one. *SPEC_CU is the CU containing DIE on input, and the CU
7813 containing the return value on output. If there is no
7814 specification, but there is an abstract origin, that is
7817 static struct die_info
*
7818 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7820 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7823 if (spec_attr
== NULL
)
7824 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7826 if (spec_attr
== NULL
)
7829 return follow_die_ref (die
, spec_attr
, spec_cu
);
7832 /* Free the line_header structure *LH, and any arrays and strings it
7835 free_line_header (struct line_header
*lh
)
7837 if (lh
->standard_opcode_lengths
)
7838 xfree (lh
->standard_opcode_lengths
);
7840 /* Remember that all the lh->file_names[i].name pointers are
7841 pointers into debug_line_buffer, and don't need to be freed. */
7843 xfree (lh
->file_names
);
7845 /* Similarly for the include directory names. */
7846 if (lh
->include_dirs
)
7847 xfree (lh
->include_dirs
);
7853 /* Add an entry to LH's include directory table. */
7855 add_include_dir (struct line_header
*lh
, char *include_dir
)
7857 /* Grow the array if necessary. */
7858 if (lh
->include_dirs_size
== 0)
7860 lh
->include_dirs_size
= 1; /* for testing */
7861 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7862 * sizeof (*lh
->include_dirs
));
7864 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7866 lh
->include_dirs_size
*= 2;
7867 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7868 (lh
->include_dirs_size
7869 * sizeof (*lh
->include_dirs
)));
7872 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7876 /* Add an entry to LH's file name table. */
7878 add_file_name (struct line_header
*lh
,
7880 unsigned int dir_index
,
7881 unsigned int mod_time
,
7882 unsigned int length
)
7884 struct file_entry
*fe
;
7886 /* Grow the array if necessary. */
7887 if (lh
->file_names_size
== 0)
7889 lh
->file_names_size
= 1; /* for testing */
7890 lh
->file_names
= xmalloc (lh
->file_names_size
7891 * sizeof (*lh
->file_names
));
7893 else if (lh
->num_file_names
>= lh
->file_names_size
)
7895 lh
->file_names_size
*= 2;
7896 lh
->file_names
= xrealloc (lh
->file_names
,
7897 (lh
->file_names_size
7898 * sizeof (*lh
->file_names
)));
7901 fe
= &lh
->file_names
[lh
->num_file_names
++];
7903 fe
->dir_index
= dir_index
;
7904 fe
->mod_time
= mod_time
;
7905 fe
->length
= length
;
7911 /* Read the statement program header starting at OFFSET in
7912 .debug_line, according to the endianness of ABFD. Return a pointer
7913 to a struct line_header, allocated using xmalloc.
7915 NOTE: the strings in the include directory and file name tables of
7916 the returned object point into debug_line_buffer, and must not be
7918 static struct line_header
*
7919 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7920 struct dwarf2_cu
*cu
)
7922 struct cleanup
*back_to
;
7923 struct line_header
*lh
;
7925 unsigned int bytes_read
, offset_size
;
7927 char *cur_dir
, *cur_file
;
7929 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
7930 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7932 complaint (&symfile_complaints
, _("missing .debug_line section"));
7936 /* Make sure that at least there's room for the total_length field.
7937 That could be 12 bytes long, but we're just going to fudge that. */
7938 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7940 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7944 lh
= xmalloc (sizeof (*lh
));
7945 memset (lh
, 0, sizeof (*lh
));
7946 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7949 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7951 /* Read in the header. */
7953 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7954 &bytes_read
, &offset_size
);
7955 line_ptr
+= bytes_read
;
7956 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7957 + dwarf2_per_objfile
->line
.size
))
7959 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7962 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7963 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7965 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7966 line_ptr
+= offset_size
;
7967 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7969 if (lh
->version
>= 4)
7971 lh
->maximum_ops_per_instruction
= read_1_byte (abfd
, line_ptr
);
7975 lh
->maximum_ops_per_instruction
= 1;
7977 if (lh
->maximum_ops_per_instruction
== 0)
7979 lh
->maximum_ops_per_instruction
= 1;
7980 complaint (&symfile_complaints
,
7981 _("invalid maximum_ops_per_instruction in `.debug_line' section"));
7984 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7986 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7988 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7990 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7992 lh
->standard_opcode_lengths
7993 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7995 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7996 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7998 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
8002 /* Read directory table. */
8003 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
8005 line_ptr
+= bytes_read
;
8006 add_include_dir (lh
, cur_dir
);
8008 line_ptr
+= bytes_read
;
8010 /* Read file name table. */
8011 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
8013 unsigned int dir_index
, mod_time
, length
;
8015 line_ptr
+= bytes_read
;
8016 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8017 line_ptr
+= bytes_read
;
8018 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8019 line_ptr
+= bytes_read
;
8020 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8021 line_ptr
+= bytes_read
;
8023 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
8025 line_ptr
+= bytes_read
;
8026 lh
->statement_program_start
= line_ptr
;
8028 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
8029 + dwarf2_per_objfile
->line
.size
))
8030 complaint (&symfile_complaints
,
8031 _("line number info header doesn't fit in `.debug_line' section"));
8033 discard_cleanups (back_to
);
8037 /* This function exists to work around a bug in certain compilers
8038 (particularly GCC 2.95), in which the first line number marker of a
8039 function does not show up until after the prologue, right before
8040 the second line number marker. This function shifts ADDRESS down
8041 to the beginning of the function if necessary, and is called on
8042 addresses passed to record_line. */
8045 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
8047 struct function_range
*fn
;
8049 /* Find the function_range containing address. */
8054 cu
->cached_fn
= cu
->first_fn
;
8058 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
8064 while (fn
&& fn
!= cu
->cached_fn
)
8065 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
8075 if (address
!= fn
->lowpc
)
8076 complaint (&symfile_complaints
,
8077 _("misplaced first line number at 0x%lx for '%s'"),
8078 (unsigned long) address
, fn
->name
);
8083 /* Decode the Line Number Program (LNP) for the given line_header
8084 structure and CU. The actual information extracted and the type
8085 of structures created from the LNP depends on the value of PST.
8087 1. If PST is NULL, then this procedure uses the data from the program
8088 to create all necessary symbol tables, and their linetables.
8089 The compilation directory of the file is passed in COMP_DIR,
8090 and must not be NULL.
8092 2. If PST is not NULL, this procedure reads the program to determine
8093 the list of files included by the unit represented by PST, and
8094 builds all the associated partial symbol tables. In this case,
8095 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
8096 is not used to compute the full name of the symtab, and therefore
8097 omitting it when building the partial symtab does not introduce
8098 the potential for inconsistency - a partial symtab and its associated
8099 symbtab having a different fullname -). */
8102 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
8103 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
8105 gdb_byte
*line_ptr
, *extended_end
;
8107 unsigned int bytes_read
, extended_len
;
8108 unsigned char op_code
, extended_op
, adj_opcode
;
8110 struct objfile
*objfile
= cu
->objfile
;
8111 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
8112 const int decode_for_pst_p
= (pst
!= NULL
);
8113 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
8115 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8117 line_ptr
= lh
->statement_program_start
;
8118 line_end
= lh
->statement_program_end
;
8120 /* Read the statement sequences until there's nothing left. */
8121 while (line_ptr
< line_end
)
8123 /* state machine registers */
8124 CORE_ADDR address
= 0;
8125 unsigned int file
= 1;
8126 unsigned int line
= 1;
8127 unsigned int column
= 0;
8128 int is_stmt
= lh
->default_is_stmt
;
8129 int basic_block
= 0;
8130 int end_sequence
= 0;
8132 unsigned char op_index
= 0;
8134 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
8136 /* Start a subfile for the current file of the state machine. */
8137 /* lh->include_dirs and lh->file_names are 0-based, but the
8138 directory and file name numbers in the statement program
8140 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8144 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8146 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8149 /* Decode the table. */
8150 while (!end_sequence
)
8152 op_code
= read_1_byte (abfd
, line_ptr
);
8154 if (line_ptr
> line_end
)
8156 dwarf2_debug_line_missing_end_sequence_complaint ();
8160 if (op_code
>= lh
->opcode_base
)
8162 /* Special operand. */
8163 adj_opcode
= op_code
- lh
->opcode_base
;
8164 address
+= (((op_index
+ (adj_opcode
/ lh
->line_range
))
8165 / lh
->maximum_ops_per_instruction
)
8166 * lh
->minimum_instruction_length
);
8167 op_index
= ((op_index
+ (adj_opcode
/ lh
->line_range
))
8168 % lh
->maximum_ops_per_instruction
);
8169 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
8170 if (lh
->num_file_names
< file
|| file
== 0)
8171 dwarf2_debug_line_missing_file_complaint ();
8172 /* For now we ignore lines not starting on an
8173 instruction boundary. */
8174 else if (op_index
== 0)
8176 lh
->file_names
[file
- 1].included_p
= 1;
8177 if (!decode_for_pst_p
&& is_stmt
)
8179 if (last_subfile
!= current_subfile
)
8181 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8183 record_line (last_subfile
, 0, addr
);
8184 last_subfile
= current_subfile
;
8186 /* Append row to matrix using current values. */
8187 addr
= check_cu_functions (address
, cu
);
8188 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8189 record_line (current_subfile
, line
, addr
);
8194 else switch (op_code
)
8196 case DW_LNS_extended_op
:
8197 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8198 line_ptr
+= bytes_read
;
8199 extended_end
= line_ptr
+ extended_len
;
8200 extended_op
= read_1_byte (abfd
, line_ptr
);
8202 switch (extended_op
)
8204 case DW_LNE_end_sequence
:
8207 case DW_LNE_set_address
:
8208 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
8210 line_ptr
+= bytes_read
;
8211 address
+= baseaddr
;
8213 case DW_LNE_define_file
:
8216 unsigned int dir_index
, mod_time
, length
;
8218 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
8219 line_ptr
+= bytes_read
;
8221 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8222 line_ptr
+= bytes_read
;
8224 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8225 line_ptr
+= bytes_read
;
8227 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8228 line_ptr
+= bytes_read
;
8229 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
8232 case DW_LNE_set_discriminator
:
8233 /* The discriminator is not interesting to the debugger;
8235 line_ptr
= extended_end
;
8238 complaint (&symfile_complaints
,
8239 _("mangled .debug_line section"));
8242 /* Make sure that we parsed the extended op correctly. If e.g.
8243 we expected a different address size than the producer used,
8244 we may have read the wrong number of bytes. */
8245 if (line_ptr
!= extended_end
)
8247 complaint (&symfile_complaints
,
8248 _("mangled .debug_line section"));
8253 if (lh
->num_file_names
< file
|| file
== 0)
8254 dwarf2_debug_line_missing_file_complaint ();
8257 lh
->file_names
[file
- 1].included_p
= 1;
8258 if (!decode_for_pst_p
&& is_stmt
)
8260 if (last_subfile
!= current_subfile
)
8262 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8264 record_line (last_subfile
, 0, addr
);
8265 last_subfile
= current_subfile
;
8267 addr
= check_cu_functions (address
, cu
);
8268 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8269 record_line (current_subfile
, line
, addr
);
8274 case DW_LNS_advance_pc
:
8277 = read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8279 address
+= (((op_index
+ adjust
)
8280 / lh
->maximum_ops_per_instruction
)
8281 * lh
->minimum_instruction_length
);
8282 op_index
= ((op_index
+ adjust
)
8283 % lh
->maximum_ops_per_instruction
);
8284 line_ptr
+= bytes_read
;
8287 case DW_LNS_advance_line
:
8288 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
8289 line_ptr
+= bytes_read
;
8291 case DW_LNS_set_file
:
8293 /* The arrays lh->include_dirs and lh->file_names are
8294 0-based, but the directory and file name numbers in
8295 the statement program are 1-based. */
8296 struct file_entry
*fe
;
8299 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8300 line_ptr
+= bytes_read
;
8301 if (lh
->num_file_names
< file
|| file
== 0)
8302 dwarf2_debug_line_missing_file_complaint ();
8305 fe
= &lh
->file_names
[file
- 1];
8307 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8308 if (!decode_for_pst_p
)
8310 last_subfile
= current_subfile
;
8311 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8316 case DW_LNS_set_column
:
8317 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8318 line_ptr
+= bytes_read
;
8320 case DW_LNS_negate_stmt
:
8321 is_stmt
= (!is_stmt
);
8323 case DW_LNS_set_basic_block
:
8326 /* Add to the address register of the state machine the
8327 address increment value corresponding to special opcode
8328 255. I.e., this value is scaled by the minimum
8329 instruction length since special opcode 255 would have
8330 scaled the the increment. */
8331 case DW_LNS_const_add_pc
:
8333 CORE_ADDR adjust
= (255 - lh
->opcode_base
) / lh
->line_range
;
8335 address
+= (((op_index
+ adjust
)
8336 / lh
->maximum_ops_per_instruction
)
8337 * lh
->minimum_instruction_length
);
8338 op_index
= ((op_index
+ adjust
)
8339 % lh
->maximum_ops_per_instruction
);
8342 case DW_LNS_fixed_advance_pc
:
8343 address
+= read_2_bytes (abfd
, line_ptr
);
8349 /* Unknown standard opcode, ignore it. */
8352 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
8354 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8355 line_ptr
+= bytes_read
;
8360 if (lh
->num_file_names
< file
|| file
== 0)
8361 dwarf2_debug_line_missing_file_complaint ();
8364 lh
->file_names
[file
- 1].included_p
= 1;
8365 if (!decode_for_pst_p
)
8367 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8368 record_line (current_subfile
, 0, addr
);
8373 if (decode_for_pst_p
)
8377 /* Now that we're done scanning the Line Header Program, we can
8378 create the psymtab of each included file. */
8379 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
8380 if (lh
->file_names
[file_index
].included_p
== 1)
8382 const struct file_entry fe
= lh
->file_names
[file_index
];
8383 char *include_name
= fe
.name
;
8384 char *dir_name
= NULL
;
8385 char *pst_filename
= pst
->filename
;
8388 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
8390 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
8392 include_name
= concat (dir_name
, SLASH_STRING
,
8393 include_name
, (char *)NULL
);
8394 make_cleanup (xfree
, include_name
);
8397 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
8399 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
8400 pst_filename
, (char *)NULL
);
8401 make_cleanup (xfree
, pst_filename
);
8404 if (strcmp (include_name
, pst_filename
) != 0)
8405 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
8410 /* Make sure a symtab is created for every file, even files
8411 which contain only variables (i.e. no code with associated
8415 struct file_entry
*fe
;
8417 for (i
= 0; i
< lh
->num_file_names
; i
++)
8421 fe
= &lh
->file_names
[i
];
8423 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8424 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8426 /* Skip the main file; we don't need it, and it must be
8427 allocated last, so that it will show up before the
8428 non-primary symtabs in the objfile's symtab list. */
8429 if (current_subfile
== first_subfile
)
8432 if (current_subfile
->symtab
== NULL
)
8433 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8435 fe
->symtab
= current_subfile
->symtab
;
8440 /* Start a subfile for DWARF. FILENAME is the name of the file and
8441 DIRNAME the name of the source directory which contains FILENAME
8442 or NULL if not known. COMP_DIR is the compilation directory for the
8443 linetable's compilation unit or NULL if not known.
8444 This routine tries to keep line numbers from identical absolute and
8445 relative file names in a common subfile.
8447 Using the `list' example from the GDB testsuite, which resides in
8448 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8449 of /srcdir/list0.c yields the following debugging information for list0.c:
8451 DW_AT_name: /srcdir/list0.c
8452 DW_AT_comp_dir: /compdir
8453 files.files[0].name: list0.h
8454 files.files[0].dir: /srcdir
8455 files.files[1].name: list0.c
8456 files.files[1].dir: /srcdir
8458 The line number information for list0.c has to end up in a single
8459 subfile, so that `break /srcdir/list0.c:1' works as expected.
8460 start_subfile will ensure that this happens provided that we pass the
8461 concatenation of files.files[1].dir and files.files[1].name as the
8465 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
8469 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8470 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8471 second argument to start_subfile. To be consistent, we do the
8472 same here. In order not to lose the line information directory,
8473 we concatenate it to the filename when it makes sense.
8474 Note that the Dwarf3 standard says (speaking of filenames in line
8475 information): ``The directory index is ignored for file names
8476 that represent full path names''. Thus ignoring dirname in the
8477 `else' branch below isn't an issue. */
8479 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
8480 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
8482 fullname
= filename
;
8484 start_subfile (fullname
, comp_dir
);
8486 if (fullname
!= filename
)
8491 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
8492 struct dwarf2_cu
*cu
)
8494 struct objfile
*objfile
= cu
->objfile
;
8495 struct comp_unit_head
*cu_header
= &cu
->header
;
8497 /* NOTE drow/2003-01-30: There used to be a comment and some special
8498 code here to turn a symbol with DW_AT_external and a
8499 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8500 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8501 with some versions of binutils) where shared libraries could have
8502 relocations against symbols in their debug information - the
8503 minimal symbol would have the right address, but the debug info
8504 would not. It's no longer necessary, because we will explicitly
8505 apply relocations when we read in the debug information now. */
8507 /* A DW_AT_location attribute with no contents indicates that a
8508 variable has been optimized away. */
8509 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
8511 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8515 /* Handle one degenerate form of location expression specially, to
8516 preserve GDB's previous behavior when section offsets are
8517 specified. If this is just a DW_OP_addr then mark this symbol
8520 if (attr_form_is_block (attr
)
8521 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
8522 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
8526 SYMBOL_VALUE_ADDRESS (sym
) =
8527 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
8528 SYMBOL_CLASS (sym
) = LOC_STATIC
;
8529 fixup_symbol_section (sym
, objfile
);
8530 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
8531 SYMBOL_SECTION (sym
));
8535 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8536 expression evaluator, and use LOC_COMPUTED only when necessary
8537 (i.e. when the value of a register or memory location is
8538 referenced, or a thread-local block, etc.). Then again, it might
8539 not be worthwhile. I'm assuming that it isn't unless performance
8540 or memory numbers show me otherwise. */
8542 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
8543 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
8546 /* Given a pointer to a DWARF information entry, figure out if we need
8547 to make a symbol table entry for it, and if so, create a new entry
8548 and return a pointer to it.
8549 If TYPE is NULL, determine symbol type from the die, otherwise
8550 used the passed type. */
8552 static struct symbol
*
8553 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
8555 struct objfile
*objfile
= cu
->objfile
;
8556 struct symbol
*sym
= NULL
;
8558 struct attribute
*attr
= NULL
;
8559 struct attribute
*attr2
= NULL
;
8561 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8563 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8565 name
= dwarf2_name (die
, cu
);
8568 const char *linkagename
;
8570 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
8571 sizeof (struct symbol
));
8572 OBJSTAT (objfile
, n_syms
++);
8573 memset (sym
, 0, sizeof (struct symbol
));
8575 /* Cache this symbol's name and the name's demangled form (if any). */
8576 SYMBOL_LANGUAGE (sym
) = cu
->language
;
8577 linkagename
= dwarf2_physname (name
, die
, cu
);
8578 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
8580 /* Fortran does not have mangling standard and the mangling does differ
8581 between gfortran, iFort etc. */
8582 if (cu
->language
== language_fortran
8583 && sym
->ginfo
.language_specific
.cplus_specific
.demangled_name
== NULL
)
8584 sym
->ginfo
.language_specific
.cplus_specific
.demangled_name
8585 = (char *) dwarf2_full_name (name
, die
, cu
);
8587 /* Default assumptions.
8588 Use the passed type or decode it from the die. */
8589 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8590 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8592 SYMBOL_TYPE (sym
) = type
;
8594 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
8595 attr
= dwarf2_attr (die
,
8596 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
8600 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
8603 attr
= dwarf2_attr (die
,
8604 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
8608 int file_index
= DW_UNSND (attr
);
8610 if (cu
->line_header
== NULL
8611 || file_index
> cu
->line_header
->num_file_names
)
8612 complaint (&symfile_complaints
,
8613 _("file index out of range"));
8614 else if (file_index
> 0)
8616 struct file_entry
*fe
;
8618 fe
= &cu
->line_header
->file_names
[file_index
- 1];
8619 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
8626 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8629 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
8631 SYMBOL_CLASS (sym
) = LOC_LABEL
;
8633 case DW_TAG_subprogram
:
8634 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8636 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8637 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8638 if ((attr2
&& (DW_UNSND (attr2
) != 0))
8639 || cu
->language
== language_ada
)
8641 /* Subprograms marked external are stored as a global symbol.
8642 Ada subprograms, whether marked external or not, are always
8643 stored as a global symbol, because we want to be able to
8644 access them globally. For instance, we want to be able
8645 to break on a nested subprogram without having to
8646 specify the context. */
8647 add_symbol_to_list (sym
, &global_symbols
);
8651 add_symbol_to_list (sym
, cu
->list_in_scope
);
8654 case DW_TAG_inlined_subroutine
:
8655 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8657 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8658 SYMBOL_INLINED (sym
) = 1;
8659 /* Do not add the symbol to any lists. It will be found via
8660 BLOCK_FUNCTION from the blockvector. */
8662 case DW_TAG_variable
:
8663 /* Compilation with minimal debug info may result in variables
8664 with missing type entries. Change the misleading `void' type
8665 to something sensible. */
8666 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
8668 = objfile_type (objfile
)->nodebug_data_symbol
;
8670 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8673 dwarf2_const_value (attr
, sym
, cu
);
8674 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8675 if (attr2
&& (DW_UNSND (attr2
) != 0))
8676 add_symbol_to_list (sym
, &global_symbols
);
8678 add_symbol_to_list (sym
, cu
->list_in_scope
);
8681 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8684 var_decode_location (attr
, sym
, cu
);
8685 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8686 if (attr2
&& (DW_UNSND (attr2
) != 0))
8688 struct pending
**list_to_add
;
8690 /* Workaround gfortran PR debug/40040 - it uses
8691 DW_AT_location for variables in -fPIC libraries which may
8692 get overriden by other libraries/executable and get
8693 a different address. Resolve it by the minimal symbol
8694 which may come from inferior's executable using copy
8695 relocation. Make this workaround only for gfortran as for
8696 other compilers GDB cannot guess the minimal symbol
8697 Fortran mangling kind. */
8698 if (cu
->language
== language_fortran
&& die
->parent
8699 && die
->parent
->tag
== DW_TAG_module
8701 && strncmp (cu
->producer
, "GNU Fortran ", 12) == 0)
8702 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8704 /* A variable with DW_AT_external is never static,
8705 but it may be block-scoped. */
8706 list_to_add
= (cu
->list_in_scope
== &file_symbols
8707 ? &global_symbols
: cu
->list_in_scope
);
8708 add_symbol_to_list (sym
, list_to_add
);
8711 add_symbol_to_list (sym
, cu
->list_in_scope
);
8715 /* We do not know the address of this symbol.
8716 If it is an external symbol and we have type information
8717 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8718 The address of the variable will then be determined from
8719 the minimal symbol table whenever the variable is
8721 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8722 if (attr2
&& (DW_UNSND (attr2
) != 0)
8723 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
8725 struct pending
**list_to_add
;
8727 /* A variable with DW_AT_external is never static, but it
8728 may be block-scoped. */
8729 list_to_add
= (cu
->list_in_scope
== &file_symbols
8730 ? &global_symbols
: cu
->list_in_scope
);
8732 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8733 add_symbol_to_list (sym
, list_to_add
);
8735 else if (!die_is_declaration (die
, cu
))
8737 /* Use the default LOC_OPTIMIZED_OUT class. */
8738 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
8739 add_symbol_to_list (sym
, cu
->list_in_scope
);
8743 case DW_TAG_formal_parameter
:
8744 /* If we are inside a function, mark this as an argument. If
8745 not, we might be looking at an argument to an inlined function
8746 when we do not have enough information to show inlined frames;
8747 pretend it's a local variable in that case so that the user can
8749 if (context_stack_depth
> 0
8750 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
8751 SYMBOL_IS_ARGUMENT (sym
) = 1;
8752 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8755 var_decode_location (attr
, sym
, cu
);
8757 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8760 dwarf2_const_value (attr
, sym
, cu
);
8762 attr
= dwarf2_attr (die
, DW_AT_variable_parameter
, cu
);
8763 if (attr
&& DW_UNSND (attr
))
8765 struct type
*ref_type
;
8767 ref_type
= lookup_reference_type (SYMBOL_TYPE (sym
));
8768 SYMBOL_TYPE (sym
) = ref_type
;
8771 add_symbol_to_list (sym
, cu
->list_in_scope
);
8773 case DW_TAG_unspecified_parameters
:
8774 /* From varargs functions; gdb doesn't seem to have any
8775 interest in this information, so just ignore it for now.
8778 case DW_TAG_class_type
:
8779 case DW_TAG_interface_type
:
8780 case DW_TAG_structure_type
:
8781 case DW_TAG_union_type
:
8782 case DW_TAG_set_type
:
8783 case DW_TAG_enumeration_type
:
8784 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8785 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8787 /* Make sure that the symbol includes appropriate enclosing
8788 classes/namespaces in its name. These are calculated in
8789 read_structure_type, and the correct name is saved in
8792 if (cu
->language
== language_cplus
8793 || cu
->language
== language_java
)
8795 struct type
*type
= SYMBOL_TYPE (sym
);
8797 if (TYPE_TAG_NAME (type
) != NULL
)
8799 /* FIXME: carlton/2003-11-10: Should this use
8800 SYMBOL_SET_NAMES instead? (The same problem also
8801 arises further down in this function.) */
8802 /* The type's name is already allocated along with
8803 this objfile, so we don't need to duplicate it
8805 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
8810 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8811 really ever be static objects: otherwise, if you try
8812 to, say, break of a class's method and you're in a file
8813 which doesn't mention that class, it won't work unless
8814 the check for all static symbols in lookup_symbol_aux
8815 saves you. See the OtherFileClass tests in
8816 gdb.c++/namespace.exp. */
8818 struct pending
**list_to_add
;
8820 list_to_add
= (cu
->list_in_scope
== &file_symbols
8821 && (cu
->language
== language_cplus
8822 || cu
->language
== language_java
)
8823 ? &global_symbols
: cu
->list_in_scope
);
8825 add_symbol_to_list (sym
, list_to_add
);
8827 /* The semantics of C++ state that "struct foo { ... }" also
8828 defines a typedef for "foo". A Java class declaration also
8829 defines a typedef for the class. */
8830 if (cu
->language
== language_cplus
8831 || cu
->language
== language_java
8832 || cu
->language
== language_ada
)
8834 /* The symbol's name is already allocated along with
8835 this objfile, so we don't need to duplicate it for
8837 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
8838 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
8842 case DW_TAG_typedef
:
8843 SYMBOL_LINKAGE_NAME (sym
)
8844 = (char *) dwarf2_full_name (name
, die
, cu
);
8845 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8846 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8847 add_symbol_to_list (sym
, cu
->list_in_scope
);
8849 case DW_TAG_base_type
:
8850 case DW_TAG_subrange_type
:
8851 case DW_TAG_const_type
:
8852 case DW_TAG_volatile_type
:
8853 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8854 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8855 add_symbol_to_list (sym
, cu
->list_in_scope
);
8857 case DW_TAG_enumerator
:
8858 SYMBOL_LINKAGE_NAME (sym
)
8859 = (char *) dwarf2_full_name (name
, die
, cu
);
8860 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8863 dwarf2_const_value (attr
, sym
, cu
);
8866 /* NOTE: carlton/2003-11-10: See comment above in the
8867 DW_TAG_class_type, etc. block. */
8869 struct pending
**list_to_add
;
8871 list_to_add
= (cu
->list_in_scope
== &file_symbols
8872 && (cu
->language
== language_cplus
8873 || cu
->language
== language_java
)
8874 ? &global_symbols
: cu
->list_in_scope
);
8876 add_symbol_to_list (sym
, list_to_add
);
8879 case DW_TAG_namespace
:
8880 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8881 add_symbol_to_list (sym
, &global_symbols
);
8884 /* Not a tag we recognize. Hopefully we aren't processing
8885 trash data, but since we must specifically ignore things
8886 we don't recognize, there is nothing else we should do at
8888 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8889 dwarf_tag_name (die
->tag
));
8893 /* For the benefit of old versions of GCC, check for anonymous
8894 namespaces based on the demangled name. */
8895 if (!processing_has_namespace_info
8896 && cu
->language
== language_cplus
)
8897 cp_scan_for_anonymous_namespaces (sym
);
8902 /* Copy constant value from an attribute to a symbol. */
8905 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8906 struct dwarf2_cu
*cu
)
8908 struct objfile
*objfile
= cu
->objfile
;
8909 struct comp_unit_head
*cu_header
= &cu
->header
;
8910 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
8911 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
8912 struct dwarf_block
*blk
;
8917 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8918 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8919 cu_header
->addr_size
,
8920 TYPE_LENGTH (SYMBOL_TYPE
8922 SYMBOL_VALUE_BYTES (sym
) =
8923 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8924 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8925 it's body - store_unsigned_integer. */
8926 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8927 byte_order
, DW_ADDR (attr
));
8928 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8930 case DW_FORM_string
:
8932 /* DW_STRING is already allocated on the obstack, point directly
8934 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8935 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8937 case DW_FORM_block1
:
8938 case DW_FORM_block2
:
8939 case DW_FORM_block4
:
8941 case DW_FORM_exprloc
:
8942 blk
= DW_BLOCK (attr
);
8943 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8944 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8946 TYPE_LENGTH (SYMBOL_TYPE
8948 SYMBOL_VALUE_BYTES (sym
) =
8949 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8950 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8951 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8954 /* The DW_AT_const_value attributes are supposed to carry the
8955 symbol's value "represented as it would be on the target
8956 architecture." By the time we get here, it's already been
8957 converted to host endianness, so we just need to sign- or
8958 zero-extend it as appropriate. */
8960 dwarf2_const_value_data (attr
, sym
, 8);
8963 dwarf2_const_value_data (attr
, sym
, 16);
8966 dwarf2_const_value_data (attr
, sym
, 32);
8969 dwarf2_const_value_data (attr
, sym
, 64);
8973 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8974 SYMBOL_CLASS (sym
) = LOC_CONST
;
8978 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8979 SYMBOL_CLASS (sym
) = LOC_CONST
;
8983 complaint (&symfile_complaints
,
8984 _("unsupported const value attribute form: '%s'"),
8985 dwarf_form_name (attr
->form
));
8986 SYMBOL_VALUE (sym
) = 0;
8987 SYMBOL_CLASS (sym
) = LOC_CONST
;
8993 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8994 or zero-extend it as appropriate for the symbol's type. */
8996 dwarf2_const_value_data (struct attribute
*attr
,
9000 LONGEST l
= DW_UNSND (attr
);
9002 if (bits
< sizeof (l
) * 8)
9004 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
9005 l
&= ((LONGEST
) 1 << bits
) - 1;
9007 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
9010 SYMBOL_VALUE (sym
) = l
;
9011 SYMBOL_CLASS (sym
) = LOC_CONST
;
9015 /* Return the type of the die in question using its DW_AT_type attribute. */
9017 static struct type
*
9018 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9020 struct attribute
*type_attr
;
9021 struct die_info
*type_die
;
9023 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
9026 /* A missing DW_AT_type represents a void type. */
9027 return objfile_type (cu
->objfile
)->builtin_void
;
9030 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
9032 return tag_type_to_type (type_die
, cu
);
9035 /* True iff CU's producer generates GNAT Ada auxiliary information
9036 that allows to find parallel types through that information instead
9037 of having to do expensive parallel lookups by type name. */
9040 need_gnat_info (struct dwarf2_cu
*cu
)
9042 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
9043 of GNAT produces this auxiliary information, without any indication
9044 that it is produced. Part of enhancing the FSF version of GNAT
9045 to produce that information will be to put in place an indicator
9046 that we can use in order to determine whether the descriptive type
9047 info is available or not. One suggestion that has been made is
9048 to use a new attribute, attached to the CU die. For now, assume
9049 that the descriptive type info is not available. */
9054 /* Return the auxiliary type of the die in question using its
9055 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
9056 attribute is not present. */
9058 static struct type
*
9059 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9061 struct attribute
*type_attr
;
9062 struct die_info
*type_die
;
9064 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
9068 type_die
= follow_die_ref (die
, type_attr
, &cu
);
9069 return tag_type_to_type (type_die
, cu
);
9072 /* If DIE has a descriptive_type attribute, then set the TYPE's
9073 descriptive type accordingly. */
9076 set_descriptive_type (struct type
*type
, struct die_info
*die
,
9077 struct dwarf2_cu
*cu
)
9079 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
9081 if (descriptive_type
)
9083 ALLOCATE_GNAT_AUX_TYPE (type
);
9084 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
9088 /* Return the containing type of the die in question using its
9089 DW_AT_containing_type attribute. */
9091 static struct type
*
9092 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9094 struct attribute
*type_attr
;
9095 struct die_info
*type_die
;
9097 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
9099 error (_("Dwarf Error: Problem turning containing type into gdb type "
9100 "[in module %s]"), cu
->objfile
->name
);
9102 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
9103 return tag_type_to_type (type_die
, cu
);
9106 static struct type
*
9107 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
9109 struct type
*this_type
;
9111 this_type
= read_type_die (die
, cu
);
9114 dump_die_for_error (die
);
9115 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
9121 static struct type
*
9122 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
9124 struct type
*this_type
;
9126 this_type
= get_die_type (die
, cu
);
9132 case DW_TAG_class_type
:
9133 case DW_TAG_interface_type
:
9134 case DW_TAG_structure_type
:
9135 case DW_TAG_union_type
:
9136 this_type
= read_structure_type (die
, cu
);
9138 case DW_TAG_enumeration_type
:
9139 this_type
= read_enumeration_type (die
, cu
);
9141 case DW_TAG_subprogram
:
9142 case DW_TAG_subroutine_type
:
9143 case DW_TAG_inlined_subroutine
:
9144 this_type
= read_subroutine_type (die
, cu
);
9146 case DW_TAG_array_type
:
9147 this_type
= read_array_type (die
, cu
);
9149 case DW_TAG_set_type
:
9150 this_type
= read_set_type (die
, cu
);
9152 case DW_TAG_pointer_type
:
9153 this_type
= read_tag_pointer_type (die
, cu
);
9155 case DW_TAG_ptr_to_member_type
:
9156 this_type
= read_tag_ptr_to_member_type (die
, cu
);
9158 case DW_TAG_reference_type
:
9159 this_type
= read_tag_reference_type (die
, cu
);
9161 case DW_TAG_const_type
:
9162 this_type
= read_tag_const_type (die
, cu
);
9164 case DW_TAG_volatile_type
:
9165 this_type
= read_tag_volatile_type (die
, cu
);
9167 case DW_TAG_string_type
:
9168 this_type
= read_tag_string_type (die
, cu
);
9170 case DW_TAG_typedef
:
9171 this_type
= read_typedef (die
, cu
);
9173 case DW_TAG_subrange_type
:
9174 this_type
= read_subrange_type (die
, cu
);
9176 case DW_TAG_base_type
:
9177 this_type
= read_base_type (die
, cu
);
9179 case DW_TAG_unspecified_type
:
9180 this_type
= read_unspecified_type (die
, cu
);
9182 case DW_TAG_namespace
:
9183 this_type
= read_namespace_type (die
, cu
);
9186 this_type
= read_module_type (die
, cu
);
9189 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
9190 dwarf_tag_name (die
->tag
));
9197 /* Return the name of the namespace/class that DIE is defined within,
9198 or "" if we can't tell. The caller should not xfree the result.
9200 For example, if we're within the method foo() in the following
9210 then determine_prefix on foo's die will return "N::C". */
9213 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
9215 struct die_info
*parent
, *spec_die
;
9216 struct dwarf2_cu
*spec_cu
;
9217 struct type
*parent_type
;
9219 if (cu
->language
!= language_cplus
&& cu
->language
!= language_java
9220 && cu
->language
!= language_fortran
)
9223 /* We have to be careful in the presence of DW_AT_specification.
9224 For example, with GCC 3.4, given the code
9228 // Definition of N::foo.
9232 then we'll have a tree of DIEs like this:
9234 1: DW_TAG_compile_unit
9235 2: DW_TAG_namespace // N
9236 3: DW_TAG_subprogram // declaration of N::foo
9237 4: DW_TAG_subprogram // definition of N::foo
9238 DW_AT_specification // refers to die #3
9240 Thus, when processing die #4, we have to pretend that we're in
9241 the context of its DW_AT_specification, namely the contex of die
9244 spec_die
= die_specification (die
, &spec_cu
);
9245 if (spec_die
== NULL
)
9246 parent
= die
->parent
;
9249 parent
= spec_die
->parent
;
9256 switch (parent
->tag
)
9258 case DW_TAG_namespace
:
9259 parent_type
= read_type_die (parent
, cu
);
9260 /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus
9261 DW_TAG_namespace DIEs with a name of "::" for the global namespace.
9262 Work around this problem here. */
9263 if (cu
->language
== language_cplus
9264 && strcmp (TYPE_TAG_NAME (parent_type
), "::") == 0)
9266 /* We give a name to even anonymous namespaces. */
9267 return TYPE_TAG_NAME (parent_type
);
9268 case DW_TAG_class_type
:
9269 case DW_TAG_interface_type
:
9270 case DW_TAG_structure_type
:
9271 case DW_TAG_union_type
:
9273 parent_type
= read_type_die (parent
, cu
);
9274 if (TYPE_TAG_NAME (parent_type
) != NULL
)
9275 return TYPE_TAG_NAME (parent_type
);
9277 /* An anonymous structure is only allowed non-static data
9278 members; no typedefs, no member functions, et cetera.
9279 So it does not need a prefix. */
9282 return determine_prefix (parent
, cu
);
9286 /* Return a newly-allocated string formed by concatenating PREFIX and
9287 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9288 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9289 perform an obconcat, otherwise allocate storage for the result. The CU argument
9290 is used to determine the language and hence, the appropriate separator. */
9292 #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */
9295 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9296 int physname
, struct dwarf2_cu
*cu
)
9298 const char *lead
= "";
9301 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9303 else if (cu
->language
== language_java
)
9305 else if (cu
->language
== language_fortran
&& physname
)
9307 /* This is gfortran specific mangling. Normally DW_AT_linkage_name or
9308 DW_AT_MIPS_linkage_name is preferred and used instead. */
9323 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9325 strcpy (retval
, lead
);
9326 strcat (retval
, prefix
);
9327 strcat (retval
, sep
);
9328 strcat (retval
, suffix
);
9333 /* We have an obstack. */
9334 return obconcat (obs
, lead
, prefix
, sep
, suffix
, (char *) NULL
);
9338 /* Return sibling of die, NULL if no sibling. */
9340 static struct die_info
*
9341 sibling_die (struct die_info
*die
)
9343 return die
->sibling
;
9346 /* Get name of a die, return NULL if not found. */
9349 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9350 struct obstack
*obstack
)
9352 if (name
&& cu
->language
== language_cplus
)
9354 char *canon_name
= cp_canonicalize_string (name
);
9356 if (canon_name
!= NULL
)
9358 if (strcmp (canon_name
, name
) != 0)
9359 name
= obsavestring (canon_name
, strlen (canon_name
),
9368 /* Get name of a die, return NULL if not found. */
9371 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9373 struct attribute
*attr
;
9375 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9376 if (!attr
|| !DW_STRING (attr
))
9381 case DW_TAG_compile_unit
:
9382 /* Compilation units have a DW_AT_name that is a filename, not
9383 a source language identifier. */
9384 case DW_TAG_enumeration_type
:
9385 case DW_TAG_enumerator
:
9386 /* These tags always have simple identifiers already; no need
9387 to canonicalize them. */
9388 return DW_STRING (attr
);
9390 case DW_TAG_subprogram
:
9391 /* Java constructors will all be named "<init>", so return
9392 the class name when we see this special case. */
9393 if (cu
->language
== language_java
9394 && DW_STRING (attr
) != NULL
9395 && strcmp (DW_STRING (attr
), "<init>") == 0)
9397 struct dwarf2_cu
*spec_cu
= cu
;
9398 struct die_info
*spec_die
;
9400 /* GCJ will output '<init>' for Java constructor names.
9401 For this special case, return the name of the parent class. */
9403 /* GCJ may output suprogram DIEs with AT_specification set.
9404 If so, use the name of the specified DIE. */
9405 spec_die
= die_specification (die
, &spec_cu
);
9406 if (spec_die
!= NULL
)
9407 return dwarf2_name (spec_die
, spec_cu
);
9412 if (die
->tag
== DW_TAG_class_type
)
9413 return dwarf2_name (die
, cu
);
9415 while (die
->tag
!= DW_TAG_compile_unit
);
9419 case DW_TAG_class_type
:
9420 case DW_TAG_interface_type
:
9421 case DW_TAG_structure_type
:
9422 case DW_TAG_union_type
:
9423 /* Some GCC versions emit spurious DW_AT_name attributes for unnamed
9424 structures or unions. These were of the form "._%d" in GCC 4.1,
9425 or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3
9426 and GCC 4.4. We work around this problem by ignoring these. */
9427 if (strncmp (DW_STRING (attr
), "._", 2) == 0
9428 || strncmp (DW_STRING (attr
), "<anonymous", 10) == 0)
9436 if (!DW_STRING_IS_CANONICAL (attr
))
9439 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9440 &cu
->objfile
->objfile_obstack
);
9441 DW_STRING_IS_CANONICAL (attr
) = 1;
9443 return DW_STRING (attr
);
9446 /* Return the die that this die in an extension of, or NULL if there
9447 is none. *EXT_CU is the CU containing DIE on input, and the CU
9448 containing the return value on output. */
9450 static struct die_info
*
9451 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9453 struct attribute
*attr
;
9455 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9459 return follow_die_ref (die
, attr
, ext_cu
);
9462 /* Convert a DIE tag into its string name. */
9465 dwarf_tag_name (unsigned tag
)
9469 case DW_TAG_padding
:
9470 return "DW_TAG_padding";
9471 case DW_TAG_array_type
:
9472 return "DW_TAG_array_type";
9473 case DW_TAG_class_type
:
9474 return "DW_TAG_class_type";
9475 case DW_TAG_entry_point
:
9476 return "DW_TAG_entry_point";
9477 case DW_TAG_enumeration_type
:
9478 return "DW_TAG_enumeration_type";
9479 case DW_TAG_formal_parameter
:
9480 return "DW_TAG_formal_parameter";
9481 case DW_TAG_imported_declaration
:
9482 return "DW_TAG_imported_declaration";
9484 return "DW_TAG_label";
9485 case DW_TAG_lexical_block
:
9486 return "DW_TAG_lexical_block";
9488 return "DW_TAG_member";
9489 case DW_TAG_pointer_type
:
9490 return "DW_TAG_pointer_type";
9491 case DW_TAG_reference_type
:
9492 return "DW_TAG_reference_type";
9493 case DW_TAG_compile_unit
:
9494 return "DW_TAG_compile_unit";
9495 case DW_TAG_string_type
:
9496 return "DW_TAG_string_type";
9497 case DW_TAG_structure_type
:
9498 return "DW_TAG_structure_type";
9499 case DW_TAG_subroutine_type
:
9500 return "DW_TAG_subroutine_type";
9501 case DW_TAG_typedef
:
9502 return "DW_TAG_typedef";
9503 case DW_TAG_union_type
:
9504 return "DW_TAG_union_type";
9505 case DW_TAG_unspecified_parameters
:
9506 return "DW_TAG_unspecified_parameters";
9507 case DW_TAG_variant
:
9508 return "DW_TAG_variant";
9509 case DW_TAG_common_block
:
9510 return "DW_TAG_common_block";
9511 case DW_TAG_common_inclusion
:
9512 return "DW_TAG_common_inclusion";
9513 case DW_TAG_inheritance
:
9514 return "DW_TAG_inheritance";
9515 case DW_TAG_inlined_subroutine
:
9516 return "DW_TAG_inlined_subroutine";
9518 return "DW_TAG_module";
9519 case DW_TAG_ptr_to_member_type
:
9520 return "DW_TAG_ptr_to_member_type";
9521 case DW_TAG_set_type
:
9522 return "DW_TAG_set_type";
9523 case DW_TAG_subrange_type
:
9524 return "DW_TAG_subrange_type";
9525 case DW_TAG_with_stmt
:
9526 return "DW_TAG_with_stmt";
9527 case DW_TAG_access_declaration
:
9528 return "DW_TAG_access_declaration";
9529 case DW_TAG_base_type
:
9530 return "DW_TAG_base_type";
9531 case DW_TAG_catch_block
:
9532 return "DW_TAG_catch_block";
9533 case DW_TAG_const_type
:
9534 return "DW_TAG_const_type";
9535 case DW_TAG_constant
:
9536 return "DW_TAG_constant";
9537 case DW_TAG_enumerator
:
9538 return "DW_TAG_enumerator";
9539 case DW_TAG_file_type
:
9540 return "DW_TAG_file_type";
9542 return "DW_TAG_friend";
9543 case DW_TAG_namelist
:
9544 return "DW_TAG_namelist";
9545 case DW_TAG_namelist_item
:
9546 return "DW_TAG_namelist_item";
9547 case DW_TAG_packed_type
:
9548 return "DW_TAG_packed_type";
9549 case DW_TAG_subprogram
:
9550 return "DW_TAG_subprogram";
9551 case DW_TAG_template_type_param
:
9552 return "DW_TAG_template_type_param";
9553 case DW_TAG_template_value_param
:
9554 return "DW_TAG_template_value_param";
9555 case DW_TAG_thrown_type
:
9556 return "DW_TAG_thrown_type";
9557 case DW_TAG_try_block
:
9558 return "DW_TAG_try_block";
9559 case DW_TAG_variant_part
:
9560 return "DW_TAG_variant_part";
9561 case DW_TAG_variable
:
9562 return "DW_TAG_variable";
9563 case DW_TAG_volatile_type
:
9564 return "DW_TAG_volatile_type";
9565 case DW_TAG_dwarf_procedure
:
9566 return "DW_TAG_dwarf_procedure";
9567 case DW_TAG_restrict_type
:
9568 return "DW_TAG_restrict_type";
9569 case DW_TAG_interface_type
:
9570 return "DW_TAG_interface_type";
9571 case DW_TAG_namespace
:
9572 return "DW_TAG_namespace";
9573 case DW_TAG_imported_module
:
9574 return "DW_TAG_imported_module";
9575 case DW_TAG_unspecified_type
:
9576 return "DW_TAG_unspecified_type";
9577 case DW_TAG_partial_unit
:
9578 return "DW_TAG_partial_unit";
9579 case DW_TAG_imported_unit
:
9580 return "DW_TAG_imported_unit";
9581 case DW_TAG_condition
:
9582 return "DW_TAG_condition";
9583 case DW_TAG_shared_type
:
9584 return "DW_TAG_shared_type";
9585 case DW_TAG_type_unit
:
9586 return "DW_TAG_type_unit";
9587 case DW_TAG_MIPS_loop
:
9588 return "DW_TAG_MIPS_loop";
9589 case DW_TAG_HP_array_descriptor
:
9590 return "DW_TAG_HP_array_descriptor";
9591 case DW_TAG_format_label
:
9592 return "DW_TAG_format_label";
9593 case DW_TAG_function_template
:
9594 return "DW_TAG_function_template";
9595 case DW_TAG_class_template
:
9596 return "DW_TAG_class_template";
9597 case DW_TAG_GNU_BINCL
:
9598 return "DW_TAG_GNU_BINCL";
9599 case DW_TAG_GNU_EINCL
:
9600 return "DW_TAG_GNU_EINCL";
9601 case DW_TAG_upc_shared_type
:
9602 return "DW_TAG_upc_shared_type";
9603 case DW_TAG_upc_strict_type
:
9604 return "DW_TAG_upc_strict_type";
9605 case DW_TAG_upc_relaxed_type
:
9606 return "DW_TAG_upc_relaxed_type";
9607 case DW_TAG_PGI_kanji_type
:
9608 return "DW_TAG_PGI_kanji_type";
9609 case DW_TAG_PGI_interface_block
:
9610 return "DW_TAG_PGI_interface_block";
9612 return "DW_TAG_<unknown>";
9616 /* Convert a DWARF attribute code into its string name. */
9619 dwarf_attr_name (unsigned attr
)
9624 return "DW_AT_sibling";
9625 case DW_AT_location
:
9626 return "DW_AT_location";
9628 return "DW_AT_name";
9629 case DW_AT_ordering
:
9630 return "DW_AT_ordering";
9631 case DW_AT_subscr_data
:
9632 return "DW_AT_subscr_data";
9633 case DW_AT_byte_size
:
9634 return "DW_AT_byte_size";
9635 case DW_AT_bit_offset
:
9636 return "DW_AT_bit_offset";
9637 case DW_AT_bit_size
:
9638 return "DW_AT_bit_size";
9639 case DW_AT_element_list
:
9640 return "DW_AT_element_list";
9641 case DW_AT_stmt_list
:
9642 return "DW_AT_stmt_list";
9644 return "DW_AT_low_pc";
9646 return "DW_AT_high_pc";
9647 case DW_AT_language
:
9648 return "DW_AT_language";
9650 return "DW_AT_member";
9652 return "DW_AT_discr";
9653 case DW_AT_discr_value
:
9654 return "DW_AT_discr_value";
9655 case DW_AT_visibility
:
9656 return "DW_AT_visibility";
9658 return "DW_AT_import";
9659 case DW_AT_string_length
:
9660 return "DW_AT_string_length";
9661 case DW_AT_common_reference
:
9662 return "DW_AT_common_reference";
9663 case DW_AT_comp_dir
:
9664 return "DW_AT_comp_dir";
9665 case DW_AT_const_value
:
9666 return "DW_AT_const_value";
9667 case DW_AT_containing_type
:
9668 return "DW_AT_containing_type";
9669 case DW_AT_default_value
:
9670 return "DW_AT_default_value";
9672 return "DW_AT_inline";
9673 case DW_AT_is_optional
:
9674 return "DW_AT_is_optional";
9675 case DW_AT_lower_bound
:
9676 return "DW_AT_lower_bound";
9677 case DW_AT_producer
:
9678 return "DW_AT_producer";
9679 case DW_AT_prototyped
:
9680 return "DW_AT_prototyped";
9681 case DW_AT_return_addr
:
9682 return "DW_AT_return_addr";
9683 case DW_AT_start_scope
:
9684 return "DW_AT_start_scope";
9685 case DW_AT_bit_stride
:
9686 return "DW_AT_bit_stride";
9687 case DW_AT_upper_bound
:
9688 return "DW_AT_upper_bound";
9689 case DW_AT_abstract_origin
:
9690 return "DW_AT_abstract_origin";
9691 case DW_AT_accessibility
:
9692 return "DW_AT_accessibility";
9693 case DW_AT_address_class
:
9694 return "DW_AT_address_class";
9695 case DW_AT_artificial
:
9696 return "DW_AT_artificial";
9697 case DW_AT_base_types
:
9698 return "DW_AT_base_types";
9699 case DW_AT_calling_convention
:
9700 return "DW_AT_calling_convention";
9702 return "DW_AT_count";
9703 case DW_AT_data_member_location
:
9704 return "DW_AT_data_member_location";
9705 case DW_AT_decl_column
:
9706 return "DW_AT_decl_column";
9707 case DW_AT_decl_file
:
9708 return "DW_AT_decl_file";
9709 case DW_AT_decl_line
:
9710 return "DW_AT_decl_line";
9711 case DW_AT_declaration
:
9712 return "DW_AT_declaration";
9713 case DW_AT_discr_list
:
9714 return "DW_AT_discr_list";
9715 case DW_AT_encoding
:
9716 return "DW_AT_encoding";
9717 case DW_AT_external
:
9718 return "DW_AT_external";
9719 case DW_AT_frame_base
:
9720 return "DW_AT_frame_base";
9722 return "DW_AT_friend";
9723 case DW_AT_identifier_case
:
9724 return "DW_AT_identifier_case";
9725 case DW_AT_macro_info
:
9726 return "DW_AT_macro_info";
9727 case DW_AT_namelist_items
:
9728 return "DW_AT_namelist_items";
9729 case DW_AT_priority
:
9730 return "DW_AT_priority";
9732 return "DW_AT_segment";
9733 case DW_AT_specification
:
9734 return "DW_AT_specification";
9735 case DW_AT_static_link
:
9736 return "DW_AT_static_link";
9738 return "DW_AT_type";
9739 case DW_AT_use_location
:
9740 return "DW_AT_use_location";
9741 case DW_AT_variable_parameter
:
9742 return "DW_AT_variable_parameter";
9743 case DW_AT_virtuality
:
9744 return "DW_AT_virtuality";
9745 case DW_AT_vtable_elem_location
:
9746 return "DW_AT_vtable_elem_location";
9747 /* DWARF 3 values. */
9748 case DW_AT_allocated
:
9749 return "DW_AT_allocated";
9750 case DW_AT_associated
:
9751 return "DW_AT_associated";
9752 case DW_AT_data_location
:
9753 return "DW_AT_data_location";
9754 case DW_AT_byte_stride
:
9755 return "DW_AT_byte_stride";
9756 case DW_AT_entry_pc
:
9757 return "DW_AT_entry_pc";
9758 case DW_AT_use_UTF8
:
9759 return "DW_AT_use_UTF8";
9760 case DW_AT_extension
:
9761 return "DW_AT_extension";
9763 return "DW_AT_ranges";
9764 case DW_AT_trampoline
:
9765 return "DW_AT_trampoline";
9766 case DW_AT_call_column
:
9767 return "DW_AT_call_column";
9768 case DW_AT_call_file
:
9769 return "DW_AT_call_file";
9770 case DW_AT_call_line
:
9771 return "DW_AT_call_line";
9772 case DW_AT_description
:
9773 return "DW_AT_description";
9774 case DW_AT_binary_scale
:
9775 return "DW_AT_binary_scale";
9776 case DW_AT_decimal_scale
:
9777 return "DW_AT_decimal_scale";
9779 return "DW_AT_small";
9780 case DW_AT_decimal_sign
:
9781 return "DW_AT_decimal_sign";
9782 case DW_AT_digit_count
:
9783 return "DW_AT_digit_count";
9784 case DW_AT_picture_string
:
9785 return "DW_AT_picture_string";
9787 return "DW_AT_mutable";
9788 case DW_AT_threads_scaled
:
9789 return "DW_AT_threads_scaled";
9790 case DW_AT_explicit
:
9791 return "DW_AT_explicit";
9792 case DW_AT_object_pointer
:
9793 return "DW_AT_object_pointer";
9794 case DW_AT_endianity
:
9795 return "DW_AT_endianity";
9796 case DW_AT_elemental
:
9797 return "DW_AT_elemental";
9799 return "DW_AT_pure";
9800 case DW_AT_recursive
:
9801 return "DW_AT_recursive";
9802 /* DWARF 4 values. */
9803 case DW_AT_signature
:
9804 return "DW_AT_signature";
9805 case DW_AT_linkage_name
:
9806 return "DW_AT_linkage_name";
9807 /* SGI/MIPS extensions. */
9808 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9809 case DW_AT_MIPS_fde
:
9810 return "DW_AT_MIPS_fde";
9812 case DW_AT_MIPS_loop_begin
:
9813 return "DW_AT_MIPS_loop_begin";
9814 case DW_AT_MIPS_tail_loop_begin
:
9815 return "DW_AT_MIPS_tail_loop_begin";
9816 case DW_AT_MIPS_epilog_begin
:
9817 return "DW_AT_MIPS_epilog_begin";
9818 case DW_AT_MIPS_loop_unroll_factor
:
9819 return "DW_AT_MIPS_loop_unroll_factor";
9820 case DW_AT_MIPS_software_pipeline_depth
:
9821 return "DW_AT_MIPS_software_pipeline_depth";
9822 case DW_AT_MIPS_linkage_name
:
9823 return "DW_AT_MIPS_linkage_name";
9824 case DW_AT_MIPS_stride
:
9825 return "DW_AT_MIPS_stride";
9826 case DW_AT_MIPS_abstract_name
:
9827 return "DW_AT_MIPS_abstract_name";
9828 case DW_AT_MIPS_clone_origin
:
9829 return "DW_AT_MIPS_clone_origin";
9830 case DW_AT_MIPS_has_inlines
:
9831 return "DW_AT_MIPS_has_inlines";
9832 /* HP extensions. */
9833 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9834 case DW_AT_HP_block_index
:
9835 return "DW_AT_HP_block_index";
9837 case DW_AT_HP_unmodifiable
:
9838 return "DW_AT_HP_unmodifiable";
9839 case DW_AT_HP_actuals_stmt_list
:
9840 return "DW_AT_HP_actuals_stmt_list";
9841 case DW_AT_HP_proc_per_section
:
9842 return "DW_AT_HP_proc_per_section";
9843 case DW_AT_HP_raw_data_ptr
:
9844 return "DW_AT_HP_raw_data_ptr";
9845 case DW_AT_HP_pass_by_reference
:
9846 return "DW_AT_HP_pass_by_reference";
9847 case DW_AT_HP_opt_level
:
9848 return "DW_AT_HP_opt_level";
9849 case DW_AT_HP_prof_version_id
:
9850 return "DW_AT_HP_prof_version_id";
9851 case DW_AT_HP_opt_flags
:
9852 return "DW_AT_HP_opt_flags";
9853 case DW_AT_HP_cold_region_low_pc
:
9854 return "DW_AT_HP_cold_region_low_pc";
9855 case DW_AT_HP_cold_region_high_pc
:
9856 return "DW_AT_HP_cold_region_high_pc";
9857 case DW_AT_HP_all_variables_modifiable
:
9858 return "DW_AT_HP_all_variables_modifiable";
9859 case DW_AT_HP_linkage_name
:
9860 return "DW_AT_HP_linkage_name";
9861 case DW_AT_HP_prof_flags
:
9862 return "DW_AT_HP_prof_flags";
9863 /* GNU extensions. */
9864 case DW_AT_sf_names
:
9865 return "DW_AT_sf_names";
9866 case DW_AT_src_info
:
9867 return "DW_AT_src_info";
9868 case DW_AT_mac_info
:
9869 return "DW_AT_mac_info";
9870 case DW_AT_src_coords
:
9871 return "DW_AT_src_coords";
9872 case DW_AT_body_begin
:
9873 return "DW_AT_body_begin";
9874 case DW_AT_body_end
:
9875 return "DW_AT_body_end";
9876 case DW_AT_GNU_vector
:
9877 return "DW_AT_GNU_vector";
9878 /* VMS extensions. */
9879 case DW_AT_VMS_rtnbeg_pd_address
:
9880 return "DW_AT_VMS_rtnbeg_pd_address";
9881 /* UPC extension. */
9882 case DW_AT_upc_threads_scaled
:
9883 return "DW_AT_upc_threads_scaled";
9884 /* PGI (STMicroelectronics) extensions. */
9885 case DW_AT_PGI_lbase
:
9886 return "DW_AT_PGI_lbase";
9887 case DW_AT_PGI_soffset
:
9888 return "DW_AT_PGI_soffset";
9889 case DW_AT_PGI_lstride
:
9890 return "DW_AT_PGI_lstride";
9892 return "DW_AT_<unknown>";
9896 /* Convert a DWARF value form code into its string name. */
9899 dwarf_form_name (unsigned form
)
9904 return "DW_FORM_addr";
9905 case DW_FORM_block2
:
9906 return "DW_FORM_block2";
9907 case DW_FORM_block4
:
9908 return "DW_FORM_block4";
9910 return "DW_FORM_data2";
9912 return "DW_FORM_data4";
9914 return "DW_FORM_data8";
9915 case DW_FORM_string
:
9916 return "DW_FORM_string";
9918 return "DW_FORM_block";
9919 case DW_FORM_block1
:
9920 return "DW_FORM_block1";
9922 return "DW_FORM_data1";
9924 return "DW_FORM_flag";
9926 return "DW_FORM_sdata";
9928 return "DW_FORM_strp";
9930 return "DW_FORM_udata";
9931 case DW_FORM_ref_addr
:
9932 return "DW_FORM_ref_addr";
9934 return "DW_FORM_ref1";
9936 return "DW_FORM_ref2";
9938 return "DW_FORM_ref4";
9940 return "DW_FORM_ref8";
9941 case DW_FORM_ref_udata
:
9942 return "DW_FORM_ref_udata";
9943 case DW_FORM_indirect
:
9944 return "DW_FORM_indirect";
9945 case DW_FORM_sec_offset
:
9946 return "DW_FORM_sec_offset";
9947 case DW_FORM_exprloc
:
9948 return "DW_FORM_exprloc";
9949 case DW_FORM_flag_present
:
9950 return "DW_FORM_flag_present";
9952 return "DW_FORM_sig8";
9954 return "DW_FORM_<unknown>";
9958 /* Convert a DWARF stack opcode into its string name. */
9961 dwarf_stack_op_name (unsigned op
, int def
)
9966 return "DW_OP_addr";
9968 return "DW_OP_deref";
9970 return "DW_OP_const1u";
9972 return "DW_OP_const1s";
9974 return "DW_OP_const2u";
9976 return "DW_OP_const2s";
9978 return "DW_OP_const4u";
9980 return "DW_OP_const4s";
9982 return "DW_OP_const8u";
9984 return "DW_OP_const8s";
9986 return "DW_OP_constu";
9988 return "DW_OP_consts";
9992 return "DW_OP_drop";
9994 return "DW_OP_over";
9996 return "DW_OP_pick";
9998 return "DW_OP_swap";
10000 return "DW_OP_rot";
10002 return "DW_OP_xderef";
10004 return "DW_OP_abs";
10006 return "DW_OP_and";
10008 return "DW_OP_div";
10010 return "DW_OP_minus";
10012 return "DW_OP_mod";
10014 return "DW_OP_mul";
10016 return "DW_OP_neg";
10018 return "DW_OP_not";
10022 return "DW_OP_plus";
10023 case DW_OP_plus_uconst
:
10024 return "DW_OP_plus_uconst";
10026 return "DW_OP_shl";
10028 return "DW_OP_shr";
10030 return "DW_OP_shra";
10032 return "DW_OP_xor";
10034 return "DW_OP_bra";
10048 return "DW_OP_skip";
10050 return "DW_OP_lit0";
10052 return "DW_OP_lit1";
10054 return "DW_OP_lit2";
10056 return "DW_OP_lit3";
10058 return "DW_OP_lit4";
10060 return "DW_OP_lit5";
10062 return "DW_OP_lit6";
10064 return "DW_OP_lit7";
10066 return "DW_OP_lit8";
10068 return "DW_OP_lit9";
10070 return "DW_OP_lit10";
10072 return "DW_OP_lit11";
10074 return "DW_OP_lit12";
10076 return "DW_OP_lit13";
10078 return "DW_OP_lit14";
10080 return "DW_OP_lit15";
10082 return "DW_OP_lit16";
10084 return "DW_OP_lit17";
10086 return "DW_OP_lit18";
10088 return "DW_OP_lit19";
10090 return "DW_OP_lit20";
10092 return "DW_OP_lit21";
10094 return "DW_OP_lit22";
10096 return "DW_OP_lit23";
10098 return "DW_OP_lit24";
10100 return "DW_OP_lit25";
10102 return "DW_OP_lit26";
10104 return "DW_OP_lit27";
10106 return "DW_OP_lit28";
10108 return "DW_OP_lit29";
10110 return "DW_OP_lit30";
10112 return "DW_OP_lit31";
10114 return "DW_OP_reg0";
10116 return "DW_OP_reg1";
10118 return "DW_OP_reg2";
10120 return "DW_OP_reg3";
10122 return "DW_OP_reg4";
10124 return "DW_OP_reg5";
10126 return "DW_OP_reg6";
10128 return "DW_OP_reg7";
10130 return "DW_OP_reg8";
10132 return "DW_OP_reg9";
10134 return "DW_OP_reg10";
10136 return "DW_OP_reg11";
10138 return "DW_OP_reg12";
10140 return "DW_OP_reg13";
10142 return "DW_OP_reg14";
10144 return "DW_OP_reg15";
10146 return "DW_OP_reg16";
10148 return "DW_OP_reg17";
10150 return "DW_OP_reg18";
10152 return "DW_OP_reg19";
10154 return "DW_OP_reg20";
10156 return "DW_OP_reg21";
10158 return "DW_OP_reg22";
10160 return "DW_OP_reg23";
10162 return "DW_OP_reg24";
10164 return "DW_OP_reg25";
10166 return "DW_OP_reg26";
10168 return "DW_OP_reg27";
10170 return "DW_OP_reg28";
10172 return "DW_OP_reg29";
10174 return "DW_OP_reg30";
10176 return "DW_OP_reg31";
10178 return "DW_OP_breg0";
10180 return "DW_OP_breg1";
10182 return "DW_OP_breg2";
10184 return "DW_OP_breg3";
10186 return "DW_OP_breg4";
10188 return "DW_OP_breg5";
10190 return "DW_OP_breg6";
10192 return "DW_OP_breg7";
10194 return "DW_OP_breg8";
10196 return "DW_OP_breg9";
10198 return "DW_OP_breg10";
10200 return "DW_OP_breg11";
10202 return "DW_OP_breg12";
10204 return "DW_OP_breg13";
10206 return "DW_OP_breg14";
10208 return "DW_OP_breg15";
10210 return "DW_OP_breg16";
10212 return "DW_OP_breg17";
10214 return "DW_OP_breg18";
10216 return "DW_OP_breg19";
10218 return "DW_OP_breg20";
10220 return "DW_OP_breg21";
10222 return "DW_OP_breg22";
10224 return "DW_OP_breg23";
10226 return "DW_OP_breg24";
10228 return "DW_OP_breg25";
10230 return "DW_OP_breg26";
10232 return "DW_OP_breg27";
10234 return "DW_OP_breg28";
10236 return "DW_OP_breg29";
10238 return "DW_OP_breg30";
10240 return "DW_OP_breg31";
10242 return "DW_OP_regx";
10244 return "DW_OP_fbreg";
10246 return "DW_OP_bregx";
10248 return "DW_OP_piece";
10249 case DW_OP_deref_size
:
10250 return "DW_OP_deref_size";
10251 case DW_OP_xderef_size
:
10252 return "DW_OP_xderef_size";
10254 return "DW_OP_nop";
10255 /* DWARF 3 extensions. */
10256 case DW_OP_push_object_address
:
10257 return "DW_OP_push_object_address";
10259 return "DW_OP_call2";
10261 return "DW_OP_call4";
10262 case DW_OP_call_ref
:
10263 return "DW_OP_call_ref";
10264 case DW_OP_form_tls_address
:
10265 return "DW_OP_form_tls_address";
10266 case DW_OP_call_frame_cfa
:
10267 return "DW_OP_call_frame_cfa";
10268 case DW_OP_bit_piece
:
10269 return "DW_OP_bit_piece";
10270 /* DWARF 4 extensions. */
10271 case DW_OP_implicit_value
:
10272 return "DW_OP_implicit_value";
10273 case DW_OP_stack_value
:
10274 return "DW_OP_stack_value";
10275 /* GNU extensions. */
10276 case DW_OP_GNU_push_tls_address
:
10277 return "DW_OP_GNU_push_tls_address";
10278 case DW_OP_GNU_uninit
:
10279 return "DW_OP_GNU_uninit";
10281 return def
? "OP_<unknown>" : NULL
;
10286 dwarf_bool_name (unsigned mybool
)
10294 /* Convert a DWARF type code into its string name. */
10297 dwarf_type_encoding_name (unsigned enc
)
10302 return "DW_ATE_void";
10303 case DW_ATE_address
:
10304 return "DW_ATE_address";
10305 case DW_ATE_boolean
:
10306 return "DW_ATE_boolean";
10307 case DW_ATE_complex_float
:
10308 return "DW_ATE_complex_float";
10310 return "DW_ATE_float";
10311 case DW_ATE_signed
:
10312 return "DW_ATE_signed";
10313 case DW_ATE_signed_char
:
10314 return "DW_ATE_signed_char";
10315 case DW_ATE_unsigned
:
10316 return "DW_ATE_unsigned";
10317 case DW_ATE_unsigned_char
:
10318 return "DW_ATE_unsigned_char";
10320 case DW_ATE_imaginary_float
:
10321 return "DW_ATE_imaginary_float";
10322 case DW_ATE_packed_decimal
:
10323 return "DW_ATE_packed_decimal";
10324 case DW_ATE_numeric_string
:
10325 return "DW_ATE_numeric_string";
10326 case DW_ATE_edited
:
10327 return "DW_ATE_edited";
10328 case DW_ATE_signed_fixed
:
10329 return "DW_ATE_signed_fixed";
10330 case DW_ATE_unsigned_fixed
:
10331 return "DW_ATE_unsigned_fixed";
10332 case DW_ATE_decimal_float
:
10333 return "DW_ATE_decimal_float";
10334 /* HP extensions. */
10335 case DW_ATE_HP_float80
:
10336 return "DW_ATE_HP_float80";
10337 case DW_ATE_HP_complex_float80
:
10338 return "DW_ATE_HP_complex_float80";
10339 case DW_ATE_HP_float128
:
10340 return "DW_ATE_HP_float128";
10341 case DW_ATE_HP_complex_float128
:
10342 return "DW_ATE_HP_complex_float128";
10343 case DW_ATE_HP_floathpintel
:
10344 return "DW_ATE_HP_floathpintel";
10345 case DW_ATE_HP_imaginary_float80
:
10346 return "DW_ATE_HP_imaginary_float80";
10347 case DW_ATE_HP_imaginary_float128
:
10348 return "DW_ATE_HP_imaginary_float128";
10350 return "DW_ATE_<unknown>";
10354 /* Convert a DWARF call frame info operation to its string name. */
10358 dwarf_cfi_name (unsigned cfi_opc
)
10362 case DW_CFA_advance_loc
:
10363 return "DW_CFA_advance_loc";
10364 case DW_CFA_offset
:
10365 return "DW_CFA_offset";
10366 case DW_CFA_restore
:
10367 return "DW_CFA_restore";
10369 return "DW_CFA_nop";
10370 case DW_CFA_set_loc
:
10371 return "DW_CFA_set_loc";
10372 case DW_CFA_advance_loc1
:
10373 return "DW_CFA_advance_loc1";
10374 case DW_CFA_advance_loc2
:
10375 return "DW_CFA_advance_loc2";
10376 case DW_CFA_advance_loc4
:
10377 return "DW_CFA_advance_loc4";
10378 case DW_CFA_offset_extended
:
10379 return "DW_CFA_offset_extended";
10380 case DW_CFA_restore_extended
:
10381 return "DW_CFA_restore_extended";
10382 case DW_CFA_undefined
:
10383 return "DW_CFA_undefined";
10384 case DW_CFA_same_value
:
10385 return "DW_CFA_same_value";
10386 case DW_CFA_register
:
10387 return "DW_CFA_register";
10388 case DW_CFA_remember_state
:
10389 return "DW_CFA_remember_state";
10390 case DW_CFA_restore_state
:
10391 return "DW_CFA_restore_state";
10392 case DW_CFA_def_cfa
:
10393 return "DW_CFA_def_cfa";
10394 case DW_CFA_def_cfa_register
:
10395 return "DW_CFA_def_cfa_register";
10396 case DW_CFA_def_cfa_offset
:
10397 return "DW_CFA_def_cfa_offset";
10399 case DW_CFA_def_cfa_expression
:
10400 return "DW_CFA_def_cfa_expression";
10401 case DW_CFA_expression
:
10402 return "DW_CFA_expression";
10403 case DW_CFA_offset_extended_sf
:
10404 return "DW_CFA_offset_extended_sf";
10405 case DW_CFA_def_cfa_sf
:
10406 return "DW_CFA_def_cfa_sf";
10407 case DW_CFA_def_cfa_offset_sf
:
10408 return "DW_CFA_def_cfa_offset_sf";
10409 case DW_CFA_val_offset
:
10410 return "DW_CFA_val_offset";
10411 case DW_CFA_val_offset_sf
:
10412 return "DW_CFA_val_offset_sf";
10413 case DW_CFA_val_expression
:
10414 return "DW_CFA_val_expression";
10415 /* SGI/MIPS specific. */
10416 case DW_CFA_MIPS_advance_loc8
:
10417 return "DW_CFA_MIPS_advance_loc8";
10418 /* GNU extensions. */
10419 case DW_CFA_GNU_window_save
:
10420 return "DW_CFA_GNU_window_save";
10421 case DW_CFA_GNU_args_size
:
10422 return "DW_CFA_GNU_args_size";
10423 case DW_CFA_GNU_negative_offset_extended
:
10424 return "DW_CFA_GNU_negative_offset_extended";
10426 return "DW_CFA_<unknown>";
10432 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10436 print_spaces (indent
, f
);
10437 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10438 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10440 if (die
->parent
!= NULL
)
10442 print_spaces (indent
, f
);
10443 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10444 die
->parent
->offset
);
10447 print_spaces (indent
, f
);
10448 fprintf_unfiltered (f
, " has children: %s\n",
10449 dwarf_bool_name (die
->child
!= NULL
));
10451 print_spaces (indent
, f
);
10452 fprintf_unfiltered (f
, " attributes:\n");
10454 for (i
= 0; i
< die
->num_attrs
; ++i
)
10456 print_spaces (indent
, f
);
10457 fprintf_unfiltered (f
, " %s (%s) ",
10458 dwarf_attr_name (die
->attrs
[i
].name
),
10459 dwarf_form_name (die
->attrs
[i
].form
));
10461 switch (die
->attrs
[i
].form
)
10463 case DW_FORM_ref_addr
:
10465 fprintf_unfiltered (f
, "address: ");
10466 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10468 case DW_FORM_block2
:
10469 case DW_FORM_block4
:
10470 case DW_FORM_block
:
10471 case DW_FORM_block1
:
10472 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10474 case DW_FORM_exprloc
:
10475 fprintf_unfiltered (f
, "expression: size %u",
10476 DW_BLOCK (&die
->attrs
[i
])->size
);
10481 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10482 (long) (DW_ADDR (&die
->attrs
[i
])));
10484 case DW_FORM_data1
:
10485 case DW_FORM_data2
:
10486 case DW_FORM_data4
:
10487 case DW_FORM_data8
:
10488 case DW_FORM_udata
:
10489 case DW_FORM_sdata
:
10490 fprintf_unfiltered (f
, "constant: %s",
10491 pulongest (DW_UNSND (&die
->attrs
[i
])));
10493 case DW_FORM_sec_offset
:
10494 fprintf_unfiltered (f
, "section offset: %s",
10495 pulongest (DW_UNSND (&die
->attrs
[i
])));
10498 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10499 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10500 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10502 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10504 case DW_FORM_string
:
10506 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10507 DW_STRING (&die
->attrs
[i
])
10508 ? DW_STRING (&die
->attrs
[i
]) : "",
10509 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10512 if (DW_UNSND (&die
->attrs
[i
]))
10513 fprintf_unfiltered (f
, "flag: TRUE");
10515 fprintf_unfiltered (f
, "flag: FALSE");
10517 case DW_FORM_flag_present
:
10518 fprintf_unfiltered (f
, "flag: TRUE");
10520 case DW_FORM_indirect
:
10521 /* the reader will have reduced the indirect form to
10522 the "base form" so this form should not occur */
10523 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10526 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10527 die
->attrs
[i
].form
);
10530 fprintf_unfiltered (f
, "\n");
10535 dump_die_for_error (struct die_info
*die
)
10537 dump_die_shallow (gdb_stderr
, 0, die
);
10541 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10543 int indent
= level
* 4;
10545 gdb_assert (die
!= NULL
);
10547 if (level
>= max_level
)
10550 dump_die_shallow (f
, indent
, die
);
10552 if (die
->child
!= NULL
)
10554 print_spaces (indent
, f
);
10555 fprintf_unfiltered (f
, " Children:");
10556 if (level
+ 1 < max_level
)
10558 fprintf_unfiltered (f
, "\n");
10559 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10563 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10567 if (die
->sibling
!= NULL
&& level
> 0)
10569 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10573 /* This is called from the pdie macro in gdbinit.in.
10574 It's not static so gcc will keep a copy callable from gdb. */
10577 dump_die (struct die_info
*die
, int max_level
)
10579 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10583 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10587 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10593 is_ref_attr (struct attribute
*attr
)
10595 switch (attr
->form
)
10597 case DW_FORM_ref_addr
:
10602 case DW_FORM_ref_udata
:
10609 static unsigned int
10610 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10612 if (is_ref_attr (attr
))
10613 return DW_ADDR (attr
);
10615 complaint (&symfile_complaints
,
10616 _("unsupported die ref attribute form: '%s'"),
10617 dwarf_form_name (attr
->form
));
10621 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10622 * the value held by the attribute is not constant. */
10625 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10627 if (attr
->form
== DW_FORM_sdata
)
10628 return DW_SND (attr
);
10629 else if (attr
->form
== DW_FORM_udata
10630 || attr
->form
== DW_FORM_data1
10631 || attr
->form
== DW_FORM_data2
10632 || attr
->form
== DW_FORM_data4
10633 || attr
->form
== DW_FORM_data8
)
10634 return DW_UNSND (attr
);
10637 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10638 dwarf_form_name (attr
->form
));
10639 return default_value
;
10643 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10644 unit and add it to our queue.
10645 The result is non-zero if PER_CU was queued, otherwise the result is zero
10646 meaning either PER_CU is already queued or it is already loaded. */
10649 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10650 struct dwarf2_per_cu_data
*per_cu
)
10652 /* Mark the dependence relation so that we don't flush PER_CU
10654 dwarf2_add_dependence (this_cu
, per_cu
);
10656 /* If it's already on the queue, we have nothing to do. */
10657 if (per_cu
->queued
)
10660 /* If the compilation unit is already loaded, just mark it as
10662 if (per_cu
->cu
!= NULL
)
10664 per_cu
->cu
->last_used
= 0;
10668 /* Add it to the queue. */
10669 queue_comp_unit (per_cu
, this_cu
->objfile
);
10674 /* Follow reference or signature attribute ATTR of SRC_DIE.
10675 On entry *REF_CU is the CU of SRC_DIE.
10676 On exit *REF_CU is the CU of the result. */
10678 static struct die_info
*
10679 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10680 struct dwarf2_cu
**ref_cu
)
10682 struct die_info
*die
;
10684 if (is_ref_attr (attr
))
10685 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10686 else if (attr
->form
== DW_FORM_sig8
)
10687 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10690 dump_die_for_error (src_die
);
10691 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10692 (*ref_cu
)->objfile
->name
);
10698 /* Follow reference attribute ATTR of SRC_DIE.
10699 On entry *REF_CU is the CU of SRC_DIE.
10700 On exit *REF_CU is the CU of the result. */
10702 static struct die_info
*
10703 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10704 struct dwarf2_cu
**ref_cu
)
10706 struct die_info
*die
;
10707 unsigned int offset
;
10708 struct die_info temp_die
;
10709 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10711 gdb_assert (cu
->per_cu
!= NULL
);
10713 offset
= dwarf2_get_ref_die_offset (attr
);
10715 if (cu
->per_cu
->from_debug_types
)
10717 /* .debug_types CUs cannot reference anything outside their CU.
10718 If they need to, they have to reference a signatured type via
10720 if (! offset_in_cu_p (&cu
->header
, offset
))
10724 else if (! offset_in_cu_p (&cu
->header
, offset
))
10726 struct dwarf2_per_cu_data
*per_cu
;
10728 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10730 /* If necessary, add it to the queue and load its DIEs. */
10731 if (maybe_queue_comp_unit (cu
, per_cu
))
10732 load_full_comp_unit (per_cu
, cu
->objfile
);
10734 target_cu
= per_cu
->cu
;
10739 *ref_cu
= target_cu
;
10740 temp_die
.offset
= offset
;
10741 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10747 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10748 "at 0x%x [in module %s]"),
10749 offset
, src_die
->offset
, cu
->objfile
->name
);
10752 /* Follow the signature attribute ATTR in SRC_DIE.
10753 On entry *REF_CU is the CU of SRC_DIE.
10754 On exit *REF_CU is the CU of the result. */
10756 static struct die_info
*
10757 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10758 struct dwarf2_cu
**ref_cu
)
10760 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10761 struct die_info temp_die
;
10762 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10763 struct dwarf2_cu
*sig_cu
;
10764 struct die_info
*die
;
10766 /* sig_type will be NULL if the signatured type is missing from
10768 if (sig_type
== NULL
)
10769 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10770 "at 0x%x [in module %s]"),
10771 src_die
->offset
, objfile
->name
);
10773 /* If necessary, add it to the queue and load its DIEs. */
10775 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10776 read_signatured_type (objfile
, sig_type
);
10778 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10780 sig_cu
= sig_type
->per_cu
.cu
;
10781 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10782 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10789 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10790 "at 0x%x [in module %s]"),
10791 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10794 /* Given an offset of a signatured type, return its signatured_type. */
10796 static struct signatured_type
*
10797 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10799 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10800 unsigned int length
, initial_length_size
;
10801 unsigned int sig_offset
;
10802 struct signatured_type find_entry
, *type_sig
;
10804 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10805 sig_offset
= (initial_length_size
10807 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10808 + 1 /*address_size*/);
10809 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10810 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10812 /* This is only used to lookup previously recorded types.
10813 If we didn't find it, it's our bug. */
10814 gdb_assert (type_sig
!= NULL
);
10815 gdb_assert (offset
== type_sig
->offset
);
10820 /* Read in signatured type at OFFSET and build its CU and die(s). */
10823 read_signatured_type_at_offset (struct objfile
*objfile
,
10824 unsigned int offset
)
10826 struct signatured_type
*type_sig
;
10828 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
10830 /* We have the section offset, but we need the signature to do the
10831 hash table lookup. */
10832 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10834 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10836 read_signatured_type (objfile
, type_sig
);
10838 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10841 /* Read in a signatured type and build its CU and DIEs. */
10844 read_signatured_type (struct objfile
*objfile
,
10845 struct signatured_type
*type_sig
)
10847 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10848 struct die_reader_specs reader_specs
;
10849 struct dwarf2_cu
*cu
;
10850 ULONGEST signature
;
10851 struct cleanup
*back_to
, *free_cu_cleanup
;
10852 struct attribute
*attr
;
10854 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10856 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10857 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10858 obstack_init (&cu
->comp_unit_obstack
);
10859 cu
->objfile
= objfile
;
10860 type_sig
->per_cu
.cu
= cu
;
10861 cu
->per_cu
= &type_sig
->per_cu
;
10863 /* If an error occurs while loading, release our storage. */
10864 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10866 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10867 types_ptr
, objfile
->obfd
);
10868 gdb_assert (signature
== type_sig
->signature
);
10871 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10875 &cu
->comp_unit_obstack
,
10876 hashtab_obstack_allocate
,
10877 dummy_obstack_deallocate
);
10879 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10880 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10882 init_cu_die_reader (&reader_specs
, cu
);
10884 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10887 /* We try not to read any attributes in this function, because not
10888 all objfiles needed for references have been loaded yet, and symbol
10889 table processing isn't initialized. But we have to set the CU language,
10890 or we won't be able to build types correctly. */
10891 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10893 set_cu_language (DW_UNSND (attr
), cu
);
10895 set_cu_language (language_minimal
, cu
);
10897 do_cleanups (back_to
);
10899 /* We've successfully allocated this compilation unit. Let our caller
10900 clean it up when finished with it. */
10901 discard_cleanups (free_cu_cleanup
);
10903 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10904 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10907 /* Decode simple location descriptions.
10908 Given a pointer to a dwarf block that defines a location, compute
10909 the location and return the value.
10911 NOTE drow/2003-11-18: This function is called in two situations
10912 now: for the address of static or global variables (partial symbols
10913 only) and for offsets into structures which are expected to be
10914 (more or less) constant. The partial symbol case should go away,
10915 and only the constant case should remain. That will let this
10916 function complain more accurately. A few special modes are allowed
10917 without complaint for global variables (for instance, global
10918 register values and thread-local values).
10920 A location description containing no operations indicates that the
10921 object is optimized out. The return value is 0 for that case.
10922 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10923 callers will only want a very basic result and this can become a
10926 Note that stack[0] is unused except as a default error return.
10927 Note that stack overflow is not yet handled. */
10930 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10932 struct objfile
*objfile
= cu
->objfile
;
10934 int size
= blk
->size
;
10935 gdb_byte
*data
= blk
->data
;
10936 CORE_ADDR stack
[64];
10938 unsigned int bytes_read
, unsnd
;
10982 stack
[++stacki
] = op
- DW_OP_lit0
;
11017 stack
[++stacki
] = op
- DW_OP_reg0
;
11019 dwarf2_complex_location_expr_complaint ();
11023 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
11025 stack
[++stacki
] = unsnd
;
11027 dwarf2_complex_location_expr_complaint ();
11031 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
11036 case DW_OP_const1u
:
11037 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
11041 case DW_OP_const1s
:
11042 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
11046 case DW_OP_const2u
:
11047 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
11051 case DW_OP_const2s
:
11052 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
11056 case DW_OP_const4u
:
11057 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
11061 case DW_OP_const4s
:
11062 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
11067 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
11073 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
11078 stack
[stacki
+ 1] = stack
[stacki
];
11083 stack
[stacki
- 1] += stack
[stacki
];
11087 case DW_OP_plus_uconst
:
11088 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
11093 stack
[stacki
- 1] -= stack
[stacki
];
11098 /* If we're not the last op, then we definitely can't encode
11099 this using GDB's address_class enum. This is valid for partial
11100 global symbols, although the variable's address will be bogus
11103 dwarf2_complex_location_expr_complaint ();
11106 case DW_OP_GNU_push_tls_address
:
11107 /* The top of the stack has the offset from the beginning
11108 of the thread control block at which the variable is located. */
11109 /* Nothing should follow this operator, so the top of stack would
11111 /* This is valid for partial global symbols, but the variable's
11112 address will be bogus in the psymtab. */
11114 dwarf2_complex_location_expr_complaint ();
11117 case DW_OP_GNU_uninit
:
11121 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
11122 dwarf_stack_op_name (op
, 1));
11123 return (stack
[stacki
]);
11126 return (stack
[stacki
]);
11129 /* memory allocation interface */
11131 static struct dwarf_block
*
11132 dwarf_alloc_block (struct dwarf2_cu
*cu
)
11134 struct dwarf_block
*blk
;
11136 blk
= (struct dwarf_block
*)
11137 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
11141 static struct abbrev_info
*
11142 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
11144 struct abbrev_info
*abbrev
;
11146 abbrev
= (struct abbrev_info
*)
11147 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
11148 memset (abbrev
, 0, sizeof (struct abbrev_info
));
11152 static struct die_info
*
11153 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
11155 struct die_info
*die
;
11156 size_t size
= sizeof (struct die_info
);
11159 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
11161 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
11162 memset (die
, 0, sizeof (struct die_info
));
11167 /* Macro support. */
11170 /* Return the full name of file number I in *LH's file name table.
11171 Use COMP_DIR as the name of the current directory of the
11172 compilation. The result is allocated using xmalloc; the caller is
11173 responsible for freeing it. */
11175 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
11177 /* Is the file number a valid index into the line header's file name
11178 table? Remember that file numbers start with one, not zero. */
11179 if (1 <= file
&& file
<= lh
->num_file_names
)
11181 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
11183 if (IS_ABSOLUTE_PATH (fe
->name
))
11184 return xstrdup (fe
->name
);
11192 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
11198 dir_len
= strlen (dir
);
11199 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
11200 strcpy (full_name
, dir
);
11201 full_name
[dir_len
] = '/';
11202 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
11206 return xstrdup (fe
->name
);
11211 /* The compiler produced a bogus file number. We can at least
11212 record the macro definitions made in the file, even if we
11213 won't be able to find the file by name. */
11214 char fake_name
[80];
11216 sprintf (fake_name
, "<bad macro file number %d>", file
);
11218 complaint (&symfile_complaints
,
11219 _("bad file number in macro information (%d)"),
11222 return xstrdup (fake_name
);
11227 static struct macro_source_file
*
11228 macro_start_file (int file
, int line
,
11229 struct macro_source_file
*current_file
,
11230 const char *comp_dir
,
11231 struct line_header
*lh
, struct objfile
*objfile
)
11233 /* The full name of this source file. */
11234 char *full_name
= file_full_name (file
, lh
, comp_dir
);
11236 /* We don't create a macro table for this compilation unit
11237 at all until we actually get a filename. */
11238 if (! pending_macros
)
11239 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
11240 objfile
->macro_cache
);
11242 if (! current_file
)
11243 /* If we have no current file, then this must be the start_file
11244 directive for the compilation unit's main source file. */
11245 current_file
= macro_set_main (pending_macros
, full_name
);
11247 current_file
= macro_include (current_file
, line
, full_name
);
11251 return current_file
;
11255 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
11256 followed by a null byte. */
11258 copy_string (const char *buf
, int len
)
11260 char *s
= xmalloc (len
+ 1);
11262 memcpy (s
, buf
, len
);
11268 static const char *
11269 consume_improper_spaces (const char *p
, const char *body
)
11273 complaint (&symfile_complaints
,
11274 _("macro definition contains spaces in formal argument list:\n`%s'"),
11286 parse_macro_definition (struct macro_source_file
*file
, int line
,
11291 /* The body string takes one of two forms. For object-like macro
11292 definitions, it should be:
11294 <macro name> " " <definition>
11296 For function-like macro definitions, it should be:
11298 <macro name> "() " <definition>
11300 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
11302 Spaces may appear only where explicitly indicated, and in the
11305 The Dwarf 2 spec says that an object-like macro's name is always
11306 followed by a space, but versions of GCC around March 2002 omit
11307 the space when the macro's definition is the empty string.
11309 The Dwarf 2 spec says that there should be no spaces between the
11310 formal arguments in a function-like macro's formal argument list,
11311 but versions of GCC around March 2002 include spaces after the
11315 /* Find the extent of the macro name. The macro name is terminated
11316 by either a space or null character (for an object-like macro) or
11317 an opening paren (for a function-like macro). */
11318 for (p
= body
; *p
; p
++)
11319 if (*p
== ' ' || *p
== '(')
11322 if (*p
== ' ' || *p
== '\0')
11324 /* It's an object-like macro. */
11325 int name_len
= p
- body
;
11326 char *name
= copy_string (body
, name_len
);
11327 const char *replacement
;
11330 replacement
= body
+ name_len
+ 1;
11333 dwarf2_macro_malformed_definition_complaint (body
);
11334 replacement
= body
+ name_len
;
11337 macro_define_object (file
, line
, name
, replacement
);
11341 else if (*p
== '(')
11343 /* It's a function-like macro. */
11344 char *name
= copy_string (body
, p
- body
);
11347 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
11351 p
= consume_improper_spaces (p
, body
);
11353 /* Parse the formal argument list. */
11354 while (*p
&& *p
!= ')')
11356 /* Find the extent of the current argument name. */
11357 const char *arg_start
= p
;
11359 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11362 if (! *p
|| p
== arg_start
)
11363 dwarf2_macro_malformed_definition_complaint (body
);
11366 /* Make sure argv has room for the new argument. */
11367 if (argc
>= argv_size
)
11370 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11373 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11376 p
= consume_improper_spaces (p
, body
);
11378 /* Consume the comma, if present. */
11383 p
= consume_improper_spaces (p
, body
);
11392 /* Perfectly formed definition, no complaints. */
11393 macro_define_function (file
, line
, name
,
11394 argc
, (const char **) argv
,
11396 else if (*p
== '\0')
11398 /* Complain, but do define it. */
11399 dwarf2_macro_malformed_definition_complaint (body
);
11400 macro_define_function (file
, line
, name
,
11401 argc
, (const char **) argv
,
11405 /* Just complain. */
11406 dwarf2_macro_malformed_definition_complaint (body
);
11409 /* Just complain. */
11410 dwarf2_macro_malformed_definition_complaint (body
);
11416 for (i
= 0; i
< argc
; i
++)
11422 dwarf2_macro_malformed_definition_complaint (body
);
11427 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11428 char *comp_dir
, bfd
*abfd
,
11429 struct dwarf2_cu
*cu
)
11431 gdb_byte
*mac_ptr
, *mac_end
;
11432 struct macro_source_file
*current_file
= 0;
11433 enum dwarf_macinfo_record_type macinfo_type
;
11434 int at_commandline
;
11436 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11437 &dwarf2_per_objfile
->macinfo
);
11438 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11440 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11444 /* First pass: Find the name of the base filename.
11445 This filename is needed in order to process all macros whose definition
11446 (or undefinition) comes from the command line. These macros are defined
11447 before the first DW_MACINFO_start_file entry, and yet still need to be
11448 associated to the base file.
11450 To determine the base file name, we scan the macro definitions until we
11451 reach the first DW_MACINFO_start_file entry. We then initialize
11452 CURRENT_FILE accordingly so that any macro definition found before the
11453 first DW_MACINFO_start_file can still be associated to the base file. */
11455 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11456 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11457 + dwarf2_per_objfile
->macinfo
.size
;
11461 /* Do we at least have room for a macinfo type byte? */
11462 if (mac_ptr
>= mac_end
)
11464 /* Complaint is printed during the second pass as GDB will probably
11465 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11469 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11472 switch (macinfo_type
)
11474 /* A zero macinfo type indicates the end of the macro
11479 case DW_MACINFO_define
:
11480 case DW_MACINFO_undef
:
11481 /* Only skip the data by MAC_PTR. */
11483 unsigned int bytes_read
;
11485 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11486 mac_ptr
+= bytes_read
;
11487 read_string (abfd
, mac_ptr
, &bytes_read
);
11488 mac_ptr
+= bytes_read
;
11492 case DW_MACINFO_start_file
:
11494 unsigned int bytes_read
;
11497 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11498 mac_ptr
+= bytes_read
;
11499 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11500 mac_ptr
+= bytes_read
;
11502 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11507 case DW_MACINFO_end_file
:
11508 /* No data to skip by MAC_PTR. */
11511 case DW_MACINFO_vendor_ext
:
11512 /* Only skip the data by MAC_PTR. */
11514 unsigned int bytes_read
;
11516 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11517 mac_ptr
+= bytes_read
;
11518 read_string (abfd
, mac_ptr
, &bytes_read
);
11519 mac_ptr
+= bytes_read
;
11526 } while (macinfo_type
!= 0 && current_file
== NULL
);
11528 /* Second pass: Process all entries.
11530 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11531 command-line macro definitions/undefinitions. This flag is unset when we
11532 reach the first DW_MACINFO_start_file entry. */
11534 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11536 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11537 GDB is still reading the definitions from command line. First
11538 DW_MACINFO_start_file will need to be ignored as it was already executed
11539 to create CURRENT_FILE for the main source holding also the command line
11540 definitions. On first met DW_MACINFO_start_file this flag is reset to
11541 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11543 at_commandline
= 1;
11547 /* Do we at least have room for a macinfo type byte? */
11548 if (mac_ptr
>= mac_end
)
11550 dwarf2_macros_too_long_complaint ();
11554 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11557 switch (macinfo_type
)
11559 /* A zero macinfo type indicates the end of the macro
11564 case DW_MACINFO_define
:
11565 case DW_MACINFO_undef
:
11567 unsigned int bytes_read
;
11571 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11572 mac_ptr
+= bytes_read
;
11573 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11574 mac_ptr
+= bytes_read
;
11576 if (! current_file
)
11578 /* DWARF violation as no main source is present. */
11579 complaint (&symfile_complaints
,
11580 _("debug info with no main source gives macro %s "
11582 macinfo_type
== DW_MACINFO_define
?
11584 macinfo_type
== DW_MACINFO_undef
?
11585 _("undefinition") :
11586 _("something-or-other"), line
, body
);
11589 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11590 complaint (&symfile_complaints
,
11591 _("debug info gives %s macro %s with %s line %d: %s"),
11592 at_commandline
? _("command-line") : _("in-file"),
11593 macinfo_type
== DW_MACINFO_define
?
11595 macinfo_type
== DW_MACINFO_undef
?
11596 _("undefinition") :
11597 _("something-or-other"),
11598 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11600 if (macinfo_type
== DW_MACINFO_define
)
11601 parse_macro_definition (current_file
, line
, body
);
11602 else if (macinfo_type
== DW_MACINFO_undef
)
11603 macro_undef (current_file
, line
, body
);
11607 case DW_MACINFO_start_file
:
11609 unsigned int bytes_read
;
11612 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11613 mac_ptr
+= bytes_read
;
11614 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11615 mac_ptr
+= bytes_read
;
11617 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11618 complaint (&symfile_complaints
,
11619 _("debug info gives source %d included "
11620 "from %s at %s line %d"),
11621 file
, at_commandline
? _("command-line") : _("file"),
11622 line
== 0 ? _("zero") : _("non-zero"), line
);
11624 if (at_commandline
)
11626 /* This DW_MACINFO_start_file was executed in the pass one. */
11627 at_commandline
= 0;
11630 current_file
= macro_start_file (file
, line
,
11631 current_file
, comp_dir
,
11636 case DW_MACINFO_end_file
:
11637 if (! current_file
)
11638 complaint (&symfile_complaints
,
11639 _("macro debug info has an unmatched `close_file' directive"));
11642 current_file
= current_file
->included_by
;
11643 if (! current_file
)
11645 enum dwarf_macinfo_record_type next_type
;
11647 /* GCC circa March 2002 doesn't produce the zero
11648 type byte marking the end of the compilation
11649 unit. Complain if it's not there, but exit no
11652 /* Do we at least have room for a macinfo type byte? */
11653 if (mac_ptr
>= mac_end
)
11655 dwarf2_macros_too_long_complaint ();
11659 /* We don't increment mac_ptr here, so this is just
11661 next_type
= read_1_byte (abfd
, mac_ptr
);
11662 if (next_type
!= 0)
11663 complaint (&symfile_complaints
,
11664 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11671 case DW_MACINFO_vendor_ext
:
11673 unsigned int bytes_read
;
11677 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11678 mac_ptr
+= bytes_read
;
11679 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11680 mac_ptr
+= bytes_read
;
11682 /* We don't recognize any vendor extensions. */
11686 } while (macinfo_type
!= 0);
11689 /* Check if the attribute's form is a DW_FORM_block*
11690 if so return true else false. */
11692 attr_form_is_block (struct attribute
*attr
)
11694 return (attr
== NULL
? 0 :
11695 attr
->form
== DW_FORM_block1
11696 || attr
->form
== DW_FORM_block2
11697 || attr
->form
== DW_FORM_block4
11698 || attr
->form
== DW_FORM_block
11699 || attr
->form
== DW_FORM_exprloc
);
11702 /* Return non-zero if ATTR's value is a section offset --- classes
11703 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11704 You may use DW_UNSND (attr) to retrieve such offsets.
11706 Section 7.5.4, "Attribute Encodings", explains that no attribute
11707 may have a value that belongs to more than one of these classes; it
11708 would be ambiguous if we did, because we use the same forms for all
11711 attr_form_is_section_offset (struct attribute
*attr
)
11713 return (attr
->form
== DW_FORM_data4
11714 || attr
->form
== DW_FORM_data8
11715 || attr
->form
== DW_FORM_sec_offset
);
11719 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11720 zero otherwise. When this function returns true, you can apply
11721 dwarf2_get_attr_constant_value to it.
11723 However, note that for some attributes you must check
11724 attr_form_is_section_offset before using this test. DW_FORM_data4
11725 and DW_FORM_data8 are members of both the constant class, and of
11726 the classes that contain offsets into other debug sections
11727 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11728 that, if an attribute's can be either a constant or one of the
11729 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11730 taken as section offsets, not constants. */
11732 attr_form_is_constant (struct attribute
*attr
)
11734 switch (attr
->form
)
11736 case DW_FORM_sdata
:
11737 case DW_FORM_udata
:
11738 case DW_FORM_data1
:
11739 case DW_FORM_data2
:
11740 case DW_FORM_data4
:
11741 case DW_FORM_data8
:
11749 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11750 struct dwarf2_cu
*cu
)
11752 if (attr_form_is_section_offset (attr
)
11753 /* ".debug_loc" may not exist at all, or the offset may be outside
11754 the section. If so, fall through to the complaint in the
11756 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11758 struct dwarf2_loclist_baton
*baton
;
11760 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11761 sizeof (struct dwarf2_loclist_baton
));
11762 baton
->per_cu
= cu
->per_cu
;
11763 gdb_assert (baton
->per_cu
);
11765 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11766 &dwarf2_per_objfile
->loc
);
11768 /* We don't know how long the location list is, but make sure we
11769 don't run off the edge of the section. */
11770 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11771 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11772 baton
->base_address
= cu
->base_address
;
11773 if (cu
->base_known
== 0)
11774 complaint (&symfile_complaints
,
11775 _("Location list used without specifying the CU base address."));
11777 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11778 SYMBOL_LOCATION_BATON (sym
) = baton
;
11782 struct dwarf2_locexpr_baton
*baton
;
11784 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11785 sizeof (struct dwarf2_locexpr_baton
));
11786 baton
->per_cu
= cu
->per_cu
;
11787 gdb_assert (baton
->per_cu
);
11789 if (attr_form_is_block (attr
))
11791 /* Note that we're just copying the block's data pointer
11792 here, not the actual data. We're still pointing into the
11793 info_buffer for SYM's objfile; right now we never release
11794 that buffer, but when we do clean up properly this may
11796 baton
->size
= DW_BLOCK (attr
)->size
;
11797 baton
->data
= DW_BLOCK (attr
)->data
;
11801 dwarf2_invalid_attrib_class_complaint ("location description",
11802 SYMBOL_NATURAL_NAME (sym
));
11804 baton
->data
= NULL
;
11807 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11808 SYMBOL_LOCATION_BATON (sym
) = baton
;
11812 /* Return the OBJFILE associated with the compilation unit CU. */
11815 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11817 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11819 /* Return the master objfile, so that we can report and look up the
11820 correct file containing this variable. */
11821 if (objfile
->separate_debug_objfile_backlink
)
11822 objfile
= objfile
->separate_debug_objfile_backlink
;
11827 /* Return the address size given in the compilation unit header for CU. */
11830 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11833 return per_cu
->cu
->header
.addr_size
;
11836 /* If the CU is not currently read in, we re-read its header. */
11837 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11838 struct dwarf2_per_objfile
*per_objfile
11839 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11840 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11841 struct comp_unit_head cu_header
;
11843 memset (&cu_header
, 0, sizeof cu_header
);
11844 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11845 return cu_header
.addr_size
;
11849 /* Return the offset size given in the compilation unit header for CU. */
11852 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data
*per_cu
)
11855 return per_cu
->cu
->header
.offset_size
;
11858 /* If the CU is not currently read in, we re-read its header. */
11859 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11860 struct dwarf2_per_objfile
*per_objfile
11861 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11862 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11863 struct comp_unit_head cu_header
;
11865 memset (&cu_header
, 0, sizeof cu_header
);
11866 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11867 return cu_header
.offset_size
;
11871 /* Locate the .debug_info compilation unit from CU's objfile which contains
11872 the DIE at OFFSET. Raises an error on failure. */
11874 static struct dwarf2_per_cu_data
*
11875 dwarf2_find_containing_comp_unit (unsigned int offset
,
11876 struct objfile
*objfile
)
11878 struct dwarf2_per_cu_data
*this_cu
;
11882 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11885 int mid
= low
+ (high
- low
) / 2;
11887 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11892 gdb_assert (low
== high
);
11893 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11896 error (_("Dwarf Error: could not find partial DIE containing "
11897 "offset 0x%lx [in module %s]"),
11898 (long) offset
, bfd_get_filename (objfile
->obfd
));
11900 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11901 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11905 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11906 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11907 && offset
>= this_cu
->offset
+ this_cu
->length
)
11908 error (_("invalid dwarf2 offset %u"), offset
);
11909 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11914 /* Locate the compilation unit from OBJFILE which is located at exactly
11915 OFFSET. Raises an error on failure. */
11917 static struct dwarf2_per_cu_data
*
11918 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11920 struct dwarf2_per_cu_data
*this_cu
;
11922 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11923 if (this_cu
->offset
!= offset
)
11924 error (_("no compilation unit with offset %u."), offset
);
11928 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11930 static struct dwarf2_cu
*
11931 alloc_one_comp_unit (struct objfile
*objfile
)
11933 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11934 cu
->objfile
= objfile
;
11935 obstack_init (&cu
->comp_unit_obstack
);
11939 /* Release one cached compilation unit, CU. We unlink it from the tree
11940 of compilation units, but we don't remove it from the read_in_chain;
11941 the caller is responsible for that.
11942 NOTE: DATA is a void * because this function is also used as a
11943 cleanup routine. */
11946 free_one_comp_unit (void *data
)
11948 struct dwarf2_cu
*cu
= data
;
11950 if (cu
->per_cu
!= NULL
)
11951 cu
->per_cu
->cu
= NULL
;
11954 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11959 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11960 when we're finished with it. We can't free the pointer itself, but be
11961 sure to unlink it from the cache. Also release any associated storage
11962 and perform cache maintenance.
11964 Only used during partial symbol parsing. */
11967 free_stack_comp_unit (void *data
)
11969 struct dwarf2_cu
*cu
= data
;
11971 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11972 cu
->partial_dies
= NULL
;
11974 if (cu
->per_cu
!= NULL
)
11976 /* This compilation unit is on the stack in our caller, so we
11977 should not xfree it. Just unlink it. */
11978 cu
->per_cu
->cu
= NULL
;
11981 /* If we had a per-cu pointer, then we may have other compilation
11982 units loaded, so age them now. */
11983 age_cached_comp_units ();
11987 /* Free all cached compilation units. */
11990 free_cached_comp_units (void *data
)
11992 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11994 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11995 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11996 while (per_cu
!= NULL
)
11998 struct dwarf2_per_cu_data
*next_cu
;
12000 next_cu
= per_cu
->cu
->read_in_chain
;
12002 free_one_comp_unit (per_cu
->cu
);
12003 *last_chain
= next_cu
;
12009 /* Increase the age counter on each cached compilation unit, and free
12010 any that are too old. */
12013 age_cached_comp_units (void)
12015 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
12017 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
12018 per_cu
= dwarf2_per_objfile
->read_in_chain
;
12019 while (per_cu
!= NULL
)
12021 per_cu
->cu
->last_used
++;
12022 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
12023 dwarf2_mark (per_cu
->cu
);
12024 per_cu
= per_cu
->cu
->read_in_chain
;
12027 per_cu
= dwarf2_per_objfile
->read_in_chain
;
12028 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
12029 while (per_cu
!= NULL
)
12031 struct dwarf2_per_cu_data
*next_cu
;
12033 next_cu
= per_cu
->cu
->read_in_chain
;
12035 if (!per_cu
->cu
->mark
)
12037 free_one_comp_unit (per_cu
->cu
);
12038 *last_chain
= next_cu
;
12041 last_chain
= &per_cu
->cu
->read_in_chain
;
12047 /* Remove a single compilation unit from the cache. */
12050 free_one_cached_comp_unit (void *target_cu
)
12052 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
12054 per_cu
= dwarf2_per_objfile
->read_in_chain
;
12055 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
12056 while (per_cu
!= NULL
)
12058 struct dwarf2_per_cu_data
*next_cu
;
12060 next_cu
= per_cu
->cu
->read_in_chain
;
12062 if (per_cu
->cu
== target_cu
)
12064 free_one_comp_unit (per_cu
->cu
);
12065 *last_chain
= next_cu
;
12069 last_chain
= &per_cu
->cu
->read_in_chain
;
12075 /* Release all extra memory associated with OBJFILE. */
12078 dwarf2_free_objfile (struct objfile
*objfile
)
12080 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
12082 if (dwarf2_per_objfile
== NULL
)
12085 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
12086 free_cached_comp_units (NULL
);
12088 /* Everything else should be on the objfile obstack. */
12091 /* A pair of DIE offset and GDB type pointer. We store these
12092 in a hash table separate from the DIEs, and preserve them
12093 when the DIEs are flushed out of cache. */
12095 struct dwarf2_offset_and_type
12097 unsigned int offset
;
12101 /* Hash function for a dwarf2_offset_and_type. */
12104 offset_and_type_hash (const void *item
)
12106 const struct dwarf2_offset_and_type
*ofs
= item
;
12108 return ofs
->offset
;
12111 /* Equality function for a dwarf2_offset_and_type. */
12114 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
12116 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
12117 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
12119 return ofs_lhs
->offset
== ofs_rhs
->offset
;
12122 /* Set the type associated with DIE to TYPE. Save it in CU's hash
12123 table if necessary. For convenience, return TYPE. */
12125 static struct type
*
12126 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
12128 struct dwarf2_offset_and_type
**slot
, ofs
;
12130 /* For Ada types, make sure that the gnat-specific data is always
12131 initialized (if not already set). There are a few types where
12132 we should not be doing so, because the type-specific area is
12133 already used to hold some other piece of info (eg: TYPE_CODE_FLT
12134 where the type-specific area is used to store the floatformat).
12135 But this is not a problem, because the gnat-specific information
12136 is actually not needed for these types. */
12137 if (need_gnat_info (cu
)
12138 && TYPE_CODE (type
) != TYPE_CODE_FUNC
12139 && TYPE_CODE (type
) != TYPE_CODE_FLT
12140 && !HAVE_GNAT_AUX_INFO (type
))
12141 INIT_GNAT_SPECIFIC (type
);
12143 if (cu
->type_hash
== NULL
)
12145 gdb_assert (cu
->per_cu
!= NULL
);
12146 cu
->per_cu
->type_hash
12147 = htab_create_alloc_ex (cu
->header
.length
/ 24,
12148 offset_and_type_hash
,
12149 offset_and_type_eq
,
12151 &cu
->objfile
->objfile_obstack
,
12152 hashtab_obstack_allocate
,
12153 dummy_obstack_deallocate
);
12154 cu
->type_hash
= cu
->per_cu
->type_hash
;
12157 ofs
.offset
= die
->offset
;
12159 slot
= (struct dwarf2_offset_and_type
**)
12160 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
12161 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
12166 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
12167 not have a saved type. */
12169 static struct type
*
12170 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
12172 struct dwarf2_offset_and_type
*slot
, ofs
;
12173 htab_t type_hash
= cu
->type_hash
;
12175 if (type_hash
== NULL
)
12178 ofs
.offset
= die
->offset
;
12179 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
12186 /* Add a dependence relationship from CU to REF_PER_CU. */
12189 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
12190 struct dwarf2_per_cu_data
*ref_per_cu
)
12194 if (cu
->dependencies
== NULL
)
12196 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
12197 NULL
, &cu
->comp_unit_obstack
,
12198 hashtab_obstack_allocate
,
12199 dummy_obstack_deallocate
);
12201 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
12203 *slot
= ref_per_cu
;
12206 /* Subroutine of dwarf2_mark to pass to htab_traverse.
12207 Set the mark field in every compilation unit in the
12208 cache that we must keep because we are keeping CU. */
12211 dwarf2_mark_helper (void **slot
, void *data
)
12213 struct dwarf2_per_cu_data
*per_cu
;
12215 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
12216 if (per_cu
->cu
->mark
)
12218 per_cu
->cu
->mark
= 1;
12220 if (per_cu
->cu
->dependencies
!= NULL
)
12221 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
12226 /* Set the mark field in CU and in every other compilation unit in the
12227 cache that we must keep because we are keeping CU. */
12230 dwarf2_mark (struct dwarf2_cu
*cu
)
12235 if (cu
->dependencies
!= NULL
)
12236 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
12240 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
12244 per_cu
->cu
->mark
= 0;
12245 per_cu
= per_cu
->cu
->read_in_chain
;
12249 /* Trivial hash function for partial_die_info: the hash value of a DIE
12250 is its offset in .debug_info for this objfile. */
12253 partial_die_hash (const void *item
)
12255 const struct partial_die_info
*part_die
= item
;
12257 return part_die
->offset
;
12260 /* Trivial comparison function for partial_die_info structures: two DIEs
12261 are equal if they have the same offset. */
12264 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
12266 const struct partial_die_info
*part_die_lhs
= item_lhs
;
12267 const struct partial_die_info
*part_die_rhs
= item_rhs
;
12269 return part_die_lhs
->offset
== part_die_rhs
->offset
;
12272 static struct cmd_list_element
*set_dwarf2_cmdlist
;
12273 static struct cmd_list_element
*show_dwarf2_cmdlist
;
12276 set_dwarf2_cmd (char *args
, int from_tty
)
12278 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
12282 show_dwarf2_cmd (char *args
, int from_tty
)
12284 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
12287 /* If section described by INFO was mmapped, munmap it now. */
12290 munmap_section_buffer (struct dwarf2_section_info
*info
)
12292 if (info
->was_mmapped
)
12295 intptr_t begin
= (intptr_t) info
->buffer
;
12296 intptr_t map_begin
= begin
& ~(pagesize
- 1);
12297 size_t map_length
= info
->size
+ begin
- map_begin
;
12299 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
12301 /* Without HAVE_MMAP, we should never be here to begin with. */
12307 /* munmap debug sections for OBJFILE, if necessary. */
12310 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
12312 struct dwarf2_per_objfile
*data
= d
;
12314 munmap_section_buffer (&data
->info
);
12315 munmap_section_buffer (&data
->abbrev
);
12316 munmap_section_buffer (&data
->line
);
12317 munmap_section_buffer (&data
->str
);
12318 munmap_section_buffer (&data
->macinfo
);
12319 munmap_section_buffer (&data
->ranges
);
12320 munmap_section_buffer (&data
->loc
);
12321 munmap_section_buffer (&data
->frame
);
12322 munmap_section_buffer (&data
->eh_frame
);
12325 int dwarf2_always_disassemble
;
12328 show_dwarf2_always_disassemble (struct ui_file
*file
, int from_tty
,
12329 struct cmd_list_element
*c
, const char *value
)
12331 fprintf_filtered (file
, _("\
12332 Whether to always disassemble DWARF expressions is %s.\n"),
12336 void _initialize_dwarf2_read (void);
12339 _initialize_dwarf2_read (void)
12341 dwarf2_objfile_data_key
12342 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
12344 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
12345 Set DWARF 2 specific variables.\n\
12346 Configure DWARF 2 variables such as the cache size"),
12347 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
12348 0/*allow-unknown*/, &maintenance_set_cmdlist
);
12350 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
12351 Show DWARF 2 specific variables\n\
12352 Show DWARF 2 variables such as the cache size"),
12353 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
12354 0/*allow-unknown*/, &maintenance_show_cmdlist
);
12356 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
12357 &dwarf2_max_cache_age
, _("\
12358 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
12359 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12360 A higher limit means that cached compilation units will be stored\n\
12361 in memory longer, and more total memory will be used. Zero disables\n\
12362 caching, which can slow down startup."),
12364 show_dwarf2_max_cache_age
,
12365 &set_dwarf2_cmdlist
,
12366 &show_dwarf2_cmdlist
);
12368 add_setshow_boolean_cmd ("always-disassemble", class_obscure
,
12369 &dwarf2_always_disassemble
, _("\
12370 Set whether `info address' always disassembles DWARF expressions."), _("\
12371 Show whether `info address' always disassembles DWARF expressions."), _("\
12372 When enabled, DWARF expressions are always printed in an assembly-like\n\
12373 syntax. When disabled, expressions will be printed in a more\n\
12374 conversational style, when possible."),
12376 show_dwarf2_always_disassemble
,
12377 &set_dwarf2_cmdlist
,
12378 &show_dwarf2_cmdlist
);
12380 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
12381 Set debugging of the dwarf2 DIE reader."), _("\
12382 Show debugging of the dwarf2 DIE reader."), _("\
12383 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12384 The value is the maximum depth to print."),
12387 &setdebuglist
, &showdebuglist
);