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_pubnames header
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 pubnames_header
91 unsigned int length
; /* length of the .debug_pubnames
93 unsigned char version
; /* version number -- 2 for DWARF
95 unsigned int info_offset
; /* offset into .debug_info section */
96 unsigned int info_size
; /* byte size of .debug_info section
100 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
102 /* .debug_pubnames header
103 Because of alignment constraints, this structure has padding and cannot
104 be mapped directly onto the beginning of the .debug_info section. */
105 typedef struct aranges_header
107 unsigned int length
; /* byte len of the .debug_aranges
109 unsigned short version
; /* version number -- 2 for DWARF
111 unsigned int info_offset
; /* offset into .debug_info section */
112 unsigned char addr_size
; /* byte size of an address */
113 unsigned char seg_size
; /* byte size of segment descriptor */
116 #define _ACTUAL_ARANGES_HEADER_SIZE 12
118 /* .debug_line statement program prologue
119 Because of alignment constraints, this structure has padding and cannot
120 be mapped directly onto the beginning of the .debug_info section. */
121 typedef struct statement_prologue
123 unsigned int total_length
; /* byte length of the statement
125 unsigned short version
; /* version number -- 2 for DWARF
127 unsigned int prologue_length
; /* # bytes between prologue &
129 unsigned char minimum_instruction_length
; /* byte size of
131 unsigned char default_is_stmt
; /* initial value of is_stmt
134 unsigned char line_range
;
135 unsigned char opcode_base
; /* number assigned to first special
137 unsigned char *standard_opcode_lengths
;
141 /* When non-zero, dump DIEs after they are read in. */
142 static int dwarf2_die_debug
= 0;
146 /* When set, the file that we're processing is known to have debugging
147 info for C++ namespaces. GCC 3.3.x did not produce this information,
148 but later versions do. */
150 static int processing_has_namespace_info
;
152 static const struct objfile_data
*dwarf2_objfile_data_key
;
154 struct dwarf2_section_info
160 /* True if we have tried to read this section. */
164 struct dwarf2_per_objfile
166 struct dwarf2_section_info info
;
167 struct dwarf2_section_info abbrev
;
168 struct dwarf2_section_info line
;
169 struct dwarf2_section_info pubnames
;
170 struct dwarf2_section_info aranges
;
171 struct dwarf2_section_info loc
;
172 struct dwarf2_section_info macinfo
;
173 struct dwarf2_section_info str
;
174 struct dwarf2_section_info ranges
;
175 struct dwarf2_section_info types
;
176 struct dwarf2_section_info frame
;
177 struct dwarf2_section_info eh_frame
;
180 struct objfile
*objfile
;
182 /* A list of all the compilation units. This is used to locate
183 the target compilation unit of a particular reference. */
184 struct dwarf2_per_cu_data
**all_comp_units
;
186 /* The number of compilation units in ALL_COMP_UNITS. */
189 /* A chain of compilation units that are currently read in, so that
190 they can be freed later. */
191 struct dwarf2_per_cu_data
*read_in_chain
;
193 /* A table mapping .debug_types signatures to its signatured_type entry.
194 This is NULL if the .debug_types section hasn't been read in yet. */
195 htab_t signatured_types
;
197 /* A flag indicating wether this objfile has a section loaded at a
199 int has_section_at_zero
;
202 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
204 /* names of the debugging sections */
206 /* Note that if the debugging section has been compressed, it might
207 have a name like .zdebug_info. */
209 #define INFO_SECTION "debug_info"
210 #define ABBREV_SECTION "debug_abbrev"
211 #define LINE_SECTION "debug_line"
212 #define PUBNAMES_SECTION "debug_pubnames"
213 #define ARANGES_SECTION "debug_aranges"
214 #define LOC_SECTION "debug_loc"
215 #define MACINFO_SECTION "debug_macinfo"
216 #define STR_SECTION "debug_str"
217 #define RANGES_SECTION "debug_ranges"
218 #define TYPES_SECTION "debug_types"
219 #define FRAME_SECTION "debug_frame"
220 #define EH_FRAME_SECTION "eh_frame"
222 /* local data types */
224 /* We hold several abbreviation tables in memory at the same time. */
225 #ifndef ABBREV_HASH_SIZE
226 #define ABBREV_HASH_SIZE 121
229 /* The data in a compilation unit header, after target2host
230 translation, looks like this. */
231 struct comp_unit_head
235 unsigned char addr_size
;
236 unsigned char signed_addr_p
;
237 unsigned int abbrev_offset
;
239 /* Size of file offsets; either 4 or 8. */
240 unsigned int offset_size
;
242 /* Size of the length field; either 4 or 12. */
243 unsigned int initial_length_size
;
245 /* Offset to the first byte of this compilation unit header in the
246 .debug_info section, for resolving relative reference dies. */
249 /* Offset to first die in this cu from the start of the cu.
250 This will be the first byte following the compilation unit header. */
251 unsigned int first_die_offset
;
254 /* Internal state when decoding a particular compilation unit. */
257 /* The objfile containing this compilation unit. */
258 struct objfile
*objfile
;
260 /* The header of the compilation unit. */
261 struct comp_unit_head header
;
263 /* Base address of this compilation unit. */
264 CORE_ADDR base_address
;
266 /* Non-zero if base_address has been set. */
269 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
271 /* The language we are debugging. */
272 enum language language
;
273 const struct language_defn
*language_defn
;
275 const char *producer
;
277 /* The generic symbol table building routines have separate lists for
278 file scope symbols and all all other scopes (local scopes). So
279 we need to select the right one to pass to add_symbol_to_list().
280 We do it by keeping a pointer to the correct list in list_in_scope.
282 FIXME: The original dwarf code just treated the file scope as the
283 first local scope, and all other local scopes as nested local
284 scopes, and worked fine. Check to see if we really need to
285 distinguish these in buildsym.c. */
286 struct pending
**list_in_scope
;
288 /* DWARF abbreviation table associated with this compilation unit. */
289 struct abbrev_info
**dwarf2_abbrevs
;
291 /* Storage for the abbrev table. */
292 struct obstack abbrev_obstack
;
294 /* Hash table holding all the loaded partial DIEs. */
297 /* Storage for things with the same lifetime as this read-in compilation
298 unit, including partial DIEs. */
299 struct obstack comp_unit_obstack
;
301 /* When multiple dwarf2_cu structures are living in memory, this field
302 chains them all together, so that they can be released efficiently.
303 We will probably also want a generation counter so that most-recently-used
304 compilation units are cached... */
305 struct dwarf2_per_cu_data
*read_in_chain
;
307 /* Backchain to our per_cu entry if the tree has been built. */
308 struct dwarf2_per_cu_data
*per_cu
;
310 /* Pointer to the die -> type map. Although it is stored
311 permanently in per_cu, we copy it here to avoid double
315 /* How many compilation units ago was this CU last referenced? */
318 /* A hash table of die offsets for following references. */
321 /* Full DIEs if read in. */
322 struct die_info
*dies
;
324 /* A set of pointers to dwarf2_per_cu_data objects for compilation
325 units referenced by this one. Only set during full symbol processing;
326 partial symbol tables do not have dependencies. */
329 /* Header data from the line table, during full symbol processing. */
330 struct line_header
*line_header
;
332 /* Mark used when releasing cached dies. */
333 unsigned int mark
: 1;
335 /* This flag will be set if this compilation unit might include
336 inter-compilation-unit references. */
337 unsigned int has_form_ref_addr
: 1;
339 /* This flag will be set if this compilation unit includes any
340 DW_TAG_namespace DIEs. If we know that there are explicit
341 DIEs for namespaces, we don't need to try to infer them
342 from mangled names. */
343 unsigned int has_namespace_info
: 1;
346 /* Persistent data held for a compilation unit, even when not
347 processing it. We put a pointer to this structure in the
348 read_symtab_private field of the psymtab. If we encounter
349 inter-compilation-unit references, we also maintain a sorted
350 list of all compilation units. */
352 struct dwarf2_per_cu_data
354 /* The start offset and length of this compilation unit. 2**29-1
355 bytes should suffice to store the length of any compilation unit
356 - if it doesn't, GDB will fall over anyway.
357 NOTE: Unlike comp_unit_head.length, this length includes
358 initial_length_size. */
360 unsigned int length
: 29;
362 /* Flag indicating this compilation unit will be read in before
363 any of the current compilation units are processed. */
364 unsigned int queued
: 1;
366 /* This flag will be set if we need to load absolutely all DIEs
367 for this compilation unit, instead of just the ones we think
368 are interesting. It gets set if we look for a DIE in the
369 hash table and don't find it. */
370 unsigned int load_all_dies
: 1;
372 /* Non-zero if this CU is from .debug_types.
373 Otherwise it's from .debug_info. */
374 unsigned int from_debug_types
: 1;
376 /* Set iff currently read in. */
377 struct dwarf2_cu
*cu
;
379 /* If full symbols for this CU have been read in, then this field
380 holds a map of DIE offsets to types. It isn't always possible
381 to reconstruct this information later, so we have to preserve
385 /* The partial symbol table associated with this compilation unit,
386 or NULL for partial units (which do not have an associated
388 struct partial_symtab
*psymtab
;
391 /* Entry in the signatured_types hash table. */
393 struct signatured_type
397 /* Offset in .debug_types of the TU (type_unit) for this type. */
400 /* Offset in .debug_types of the type defined by this TU. */
401 unsigned int type_offset
;
403 /* The CU(/TU) of this type. */
404 struct dwarf2_per_cu_data per_cu
;
407 /* Struct used to pass misc. parameters to read_die_and_children, et. al.
408 which are used for both .debug_info and .debug_types dies.
409 All parameters here are unchanging for the life of the call.
410 This struct exists to abstract away the constant parameters of
413 struct die_reader_specs
415 /* The bfd of this objfile. */
418 /* The CU of the DIE we are parsing. */
419 struct dwarf2_cu
*cu
;
421 /* Pointer to start of section buffer.
422 This is either the start of .debug_info or .debug_types. */
423 const gdb_byte
*buffer
;
426 /* The line number information for a compilation unit (found in the
427 .debug_line section) begins with a "statement program header",
428 which contains the following information. */
431 unsigned int total_length
;
432 unsigned short version
;
433 unsigned int header_length
;
434 unsigned char minimum_instruction_length
;
435 unsigned char default_is_stmt
;
437 unsigned char line_range
;
438 unsigned char opcode_base
;
440 /* standard_opcode_lengths[i] is the number of operands for the
441 standard opcode whose value is i. This means that
442 standard_opcode_lengths[0] is unused, and the last meaningful
443 element is standard_opcode_lengths[opcode_base - 1]. */
444 unsigned char *standard_opcode_lengths
;
446 /* The include_directories table. NOTE! These strings are not
447 allocated with xmalloc; instead, they are pointers into
448 debug_line_buffer. If you try to free them, `free' will get
450 unsigned int num_include_dirs
, include_dirs_size
;
453 /* The file_names table. NOTE! These strings are not allocated
454 with xmalloc; instead, they are pointers into debug_line_buffer.
455 Don't try to free them directly. */
456 unsigned int num_file_names
, file_names_size
;
460 unsigned int dir_index
;
461 unsigned int mod_time
;
463 int included_p
; /* Non-zero if referenced by the Line Number Program. */
464 struct symtab
*symtab
; /* The associated symbol table, if any. */
467 /* The start and end of the statement program following this
468 header. These point into dwarf2_per_objfile->line_buffer. */
469 gdb_byte
*statement_program_start
, *statement_program_end
;
472 /* When we construct a partial symbol table entry we only
473 need this much information. */
474 struct partial_die_info
476 /* Offset of this DIE. */
479 /* DWARF-2 tag for this DIE. */
480 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
482 /* Assorted flags describing the data found in this DIE. */
483 unsigned int has_children
: 1;
484 unsigned int is_external
: 1;
485 unsigned int is_declaration
: 1;
486 unsigned int has_type
: 1;
487 unsigned int has_specification
: 1;
488 unsigned int has_pc_info
: 1;
490 /* Flag set if the SCOPE field of this structure has been
492 unsigned int scope_set
: 1;
494 /* Flag set if the DIE has a byte_size attribute. */
495 unsigned int has_byte_size
: 1;
497 /* The name of this DIE. Normally the value of DW_AT_name, but
498 sometimes a default name for unnamed DIEs. */
501 /* The scope to prepend to our children. This is generally
502 allocated on the comp_unit_obstack, so will disappear
503 when this compilation unit leaves the cache. */
506 /* The location description associated with this DIE, if any. */
507 struct dwarf_block
*locdesc
;
509 /* If HAS_PC_INFO, the PC range associated with this DIE. */
513 /* Pointer into the info_buffer (or types_buffer) pointing at the target of
514 DW_AT_sibling, if any. */
517 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
518 DW_AT_specification (or DW_AT_abstract_origin or
520 unsigned int spec_offset
;
522 /* Pointers to this DIE's parent, first child, and next sibling,
524 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
527 /* This data structure holds the information of an abbrev. */
530 unsigned int number
; /* number identifying abbrev */
531 enum dwarf_tag tag
; /* dwarf tag */
532 unsigned short has_children
; /* boolean */
533 unsigned short num_attrs
; /* number of attributes */
534 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
535 struct abbrev_info
*next
; /* next in chain */
540 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
541 ENUM_BITFIELD(dwarf_form
) form
: 16;
544 /* Attributes have a name and a value */
547 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
548 ENUM_BITFIELD(dwarf_form
) form
: 15;
550 /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This
551 field should be in u.str (existing only for DW_STRING) but it is kept
552 here for better struct attribute alignment. */
553 unsigned int string_is_canonical
: 1;
558 struct dwarf_block
*blk
;
562 struct signatured_type
*signatured_type
;
567 /* This data structure holds a complete die structure. */
570 /* DWARF-2 tag for this DIE. */
571 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
573 /* Number of attributes */
574 unsigned short num_attrs
;
579 /* Offset in .debug_info or .debug_types section. */
582 /* The dies in a compilation unit form an n-ary tree. PARENT
583 points to this die's parent; CHILD points to the first child of
584 this node; and all the children of a given node are chained
585 together via their SIBLING fields, terminated by a die whose
587 struct die_info
*child
; /* Its first child, if any. */
588 struct die_info
*sibling
; /* Its next sibling, if any. */
589 struct die_info
*parent
; /* Its parent, if any. */
591 /* An array of attributes, with NUM_ATTRS elements. There may be
592 zero, but it's not common and zero-sized arrays are not
593 sufficiently portable C. */
594 struct attribute attrs
[1];
597 struct function_range
600 CORE_ADDR lowpc
, highpc
;
602 struct function_range
*next
;
605 /* Get at parts of an attribute structure */
607 #define DW_STRING(attr) ((attr)->u.str)
608 #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
609 #define DW_UNSND(attr) ((attr)->u.unsnd)
610 #define DW_BLOCK(attr) ((attr)->u.blk)
611 #define DW_SND(attr) ((attr)->u.snd)
612 #define DW_ADDR(attr) ((attr)->u.addr)
613 #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type)
615 /* Blocks are a bunch of untyped bytes. */
622 #ifndef ATTR_ALLOC_CHUNK
623 #define ATTR_ALLOC_CHUNK 4
626 /* Allocate fields for structs, unions and enums in this size. */
627 #ifndef DW_FIELD_ALLOC_CHUNK
628 #define DW_FIELD_ALLOC_CHUNK 4
631 /* A zeroed version of a partial die for initialization purposes. */
632 static struct partial_die_info zeroed_partial_die
;
634 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
635 but this would require a corresponding change in unpack_field_as_long
637 static int bits_per_byte
= 8;
639 /* The routines that read and process dies for a C struct or C++ class
640 pass lists of data member fields and lists of member function fields
641 in an instance of a field_info structure, as defined below. */
644 /* List of data member and baseclasses fields. */
647 struct nextfield
*next
;
652 *fields
, *baseclasses
;
654 /* Number of fields (including baseclasses). */
657 /* Number of baseclasses. */
660 /* Set if the accesibility of one of the fields is not public. */
661 int non_public_fields
;
663 /* Member function fields array, entries are allocated in the order they
664 are encountered in the object file. */
667 struct nextfnfield
*next
;
668 struct fn_field fnfield
;
672 /* Member function fieldlist array, contains name of possibly overloaded
673 member function, number of overloaded member functions and a pointer
674 to the head of the member function field chain. */
679 struct nextfnfield
*head
;
683 /* Number of entries in the fnfieldlists array. */
687 /* One item on the queue of compilation units to read in full symbols
689 struct dwarf2_queue_item
691 struct dwarf2_per_cu_data
*per_cu
;
692 struct dwarf2_queue_item
*next
;
695 /* The current queue. */
696 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
698 /* Loaded secondary compilation units are kept in memory until they
699 have not been referenced for the processing of this many
700 compilation units. Set this to zero to disable caching. Cache
701 sizes of up to at least twenty will improve startup time for
702 typical inter-CU-reference binaries, at an obvious memory cost. */
703 static int dwarf2_max_cache_age
= 5;
705 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
706 struct cmd_list_element
*c
, const char *value
)
708 fprintf_filtered (file
, _("\
709 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
714 /* Various complaints about symbol reading that don't abort the process */
717 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
719 complaint (&symfile_complaints
,
720 _("statement list doesn't fit in .debug_line section"));
724 dwarf2_debug_line_missing_file_complaint (void)
726 complaint (&symfile_complaints
,
727 _(".debug_line section has line data without a file"));
731 dwarf2_debug_line_missing_end_sequence_complaint (void)
733 complaint (&symfile_complaints
,
734 _(".debug_line section has line program sequence without an end"));
738 dwarf2_complex_location_expr_complaint (void)
740 complaint (&symfile_complaints
, _("location expression too complex"));
744 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
747 complaint (&symfile_complaints
,
748 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
753 dwarf2_macros_too_long_complaint (void)
755 complaint (&symfile_complaints
,
756 _("macro info runs off end of `.debug_macinfo' section"));
760 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
762 complaint (&symfile_complaints
,
763 _("macro debug info contains a malformed macro definition:\n`%s'"),
768 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
770 complaint (&symfile_complaints
,
771 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
774 /* local function prototypes */
776 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
779 static void dwarf2_build_psymtabs_easy (struct objfile
*);
782 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
785 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
787 struct partial_symtab
*);
789 static void dwarf2_build_psymtabs_hard (struct objfile
*);
791 static void scan_partial_symbols (struct partial_die_info
*,
792 CORE_ADDR
*, CORE_ADDR
*,
793 int, struct dwarf2_cu
*);
795 static void add_partial_symbol (struct partial_die_info
*,
798 static void add_partial_namespace (struct partial_die_info
*pdi
,
799 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
800 int need_pc
, struct dwarf2_cu
*cu
);
802 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
803 CORE_ADDR
*highpc
, int need_pc
,
804 struct dwarf2_cu
*cu
);
806 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
807 struct dwarf2_cu
*cu
);
809 static void add_partial_subprogram (struct partial_die_info
*pdi
,
810 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
811 int need_pc
, struct dwarf2_cu
*cu
);
813 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
814 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
815 bfd
*abfd
, struct dwarf2_cu
*cu
);
817 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
819 static void psymtab_to_symtab_1 (struct partial_symtab
*);
821 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
823 static void dwarf2_free_abbrev_table (void *);
825 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
828 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
831 static struct partial_die_info
*load_partial_dies (bfd
*,
832 gdb_byte
*, gdb_byte
*,
833 int, struct dwarf2_cu
*);
835 static gdb_byte
*read_partial_die (struct partial_die_info
*,
836 struct abbrev_info
*abbrev
,
838 gdb_byte
*, gdb_byte
*,
841 static struct partial_die_info
*find_partial_die (unsigned int,
844 static void fixup_partial_die (struct partial_die_info
*,
847 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
848 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
850 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
851 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
853 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
855 static int read_1_signed_byte (bfd
*, gdb_byte
*);
857 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
859 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
861 static ULONGEST
read_8_bytes (bfd
*, gdb_byte
*);
863 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
866 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
868 static LONGEST read_checked_initial_length_and_offset
869 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
870 unsigned int *, unsigned int *);
872 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
875 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
877 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
879 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
881 static char *read_indirect_string (bfd
*, gdb_byte
*,
882 const struct comp_unit_head
*,
885 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
887 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
889 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
891 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
893 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
896 static struct attribute
*dwarf2_attr_no_follow (struct die_info
*,
900 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
901 struct dwarf2_cu
*cu
);
903 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
905 static struct die_info
*die_specification (struct die_info
*die
,
906 struct dwarf2_cu
**);
908 static void free_line_header (struct line_header
*lh
);
910 static void add_file_name (struct line_header
*, char *, unsigned int,
911 unsigned int, unsigned int);
913 static struct line_header
*(dwarf_decode_line_header
914 (unsigned int offset
,
915 bfd
*abfd
, struct dwarf2_cu
*cu
));
917 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
918 struct dwarf2_cu
*, struct partial_symtab
*);
920 static void dwarf2_start_subfile (char *, char *, char *);
922 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
925 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
928 static void dwarf2_const_value_data (struct attribute
*attr
,
932 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
934 static int need_gnat_info (struct dwarf2_cu
*);
936 static struct type
*die_descriptive_type (struct die_info
*, struct dwarf2_cu
*);
938 static void set_descriptive_type (struct type
*, struct die_info
*,
941 static struct type
*die_containing_type (struct die_info
*,
944 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
946 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
948 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
950 static char *typename_concat (struct obstack
*,
955 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
957 static void read_type_unit_scope (struct die_info
*, struct dwarf2_cu
*);
959 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
961 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
963 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
964 struct dwarf2_cu
*, struct partial_symtab
*);
966 static int dwarf2_get_pc_bounds (struct die_info
*,
967 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*,
968 struct partial_symtab
*);
970 static void get_scope_pc_bounds (struct die_info
*,
971 CORE_ADDR
*, CORE_ADDR
*,
974 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
975 CORE_ADDR
, struct dwarf2_cu
*);
977 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
980 static void dwarf2_attach_fields_to_type (struct field_info
*,
981 struct type
*, struct dwarf2_cu
*);
983 static void dwarf2_add_member_fn (struct field_info
*,
984 struct die_info
*, struct type
*,
987 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
988 struct type
*, struct dwarf2_cu
*);
990 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
992 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
994 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
996 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
998 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
1000 static const char *namespace_name (struct die_info
*die
,
1001 int *is_anonymous
, struct dwarf2_cu
*);
1003 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
1005 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
1007 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
1008 struct dwarf2_cu
*);
1010 static struct die_info
*read_comp_unit (gdb_byte
*, struct dwarf2_cu
*);
1012 static struct die_info
*read_die_and_children_1 (const struct die_reader_specs
*reader
,
1014 gdb_byte
**new_info_ptr
,
1015 struct die_info
*parent
);
1017 static struct die_info
*read_die_and_children (const struct die_reader_specs
*reader
,
1019 gdb_byte
**new_info_ptr
,
1020 struct die_info
*parent
);
1022 static struct die_info
*read_die_and_siblings (const struct die_reader_specs
*reader
,
1024 gdb_byte
**new_info_ptr
,
1025 struct die_info
*parent
);
1027 static gdb_byte
*read_full_die (const struct die_reader_specs
*reader
,
1028 struct die_info
**, gdb_byte
*,
1031 static void process_die (struct die_info
*, struct dwarf2_cu
*);
1033 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
1036 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
1038 static struct die_info
*dwarf2_extension (struct die_info
*die
,
1039 struct dwarf2_cu
**);
1041 static char *dwarf_tag_name (unsigned int);
1043 static char *dwarf_attr_name (unsigned int);
1045 static char *dwarf_form_name (unsigned int);
1047 static char *dwarf_stack_op_name (unsigned int);
1049 static char *dwarf_bool_name (unsigned int);
1051 static char *dwarf_type_encoding_name (unsigned int);
1054 static char *dwarf_cfi_name (unsigned int);
1057 static struct die_info
*sibling_die (struct die_info
*);
1059 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1061 static void dump_die_for_error (struct die_info
*);
1063 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1066 /*static*/ void dump_die (struct die_info
*, int max_level
);
1068 static void store_in_ref_table (struct die_info
*,
1069 struct dwarf2_cu
*);
1071 static int is_ref_attr (struct attribute
*);
1073 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1075 static LONGEST
dwarf2_get_attr_constant_value (struct attribute
*, int);
1077 static struct die_info
*follow_die_ref_or_sig (struct die_info
*,
1079 struct dwarf2_cu
**);
1081 static struct die_info
*follow_die_ref (struct die_info
*,
1083 struct dwarf2_cu
**);
1085 static struct die_info
*follow_die_sig (struct die_info
*,
1087 struct dwarf2_cu
**);
1089 static void read_signatured_type_at_offset (struct objfile
*objfile
,
1090 unsigned int offset
);
1092 static void read_signatured_type (struct objfile
*,
1093 struct signatured_type
*type_sig
);
1095 /* memory allocation interface */
1097 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1099 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1101 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1103 static void initialize_cu_func_list (struct dwarf2_cu
*);
1105 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1106 struct dwarf2_cu
*);
1108 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1109 char *, bfd
*, struct dwarf2_cu
*);
1111 static int attr_form_is_block (struct attribute
*);
1113 static int attr_form_is_section_offset (struct attribute
*);
1115 static int attr_form_is_constant (struct attribute
*);
1117 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1119 struct dwarf2_cu
*cu
);
1121 static gdb_byte
*skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1122 struct abbrev_info
*abbrev
,
1123 struct dwarf2_cu
*cu
);
1125 static void free_stack_comp_unit (void *);
1127 static hashval_t
partial_die_hash (const void *item
);
1129 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1131 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1132 (unsigned int offset
, struct objfile
*objfile
);
1134 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1135 (unsigned int offset
, struct objfile
*objfile
);
1137 static struct dwarf2_cu
*alloc_one_comp_unit (struct objfile
*objfile
);
1139 static void free_one_comp_unit (void *);
1141 static void free_cached_comp_units (void *);
1143 static void age_cached_comp_units (void);
1145 static void free_one_cached_comp_unit (void *);
1147 static struct type
*set_die_type (struct die_info
*, struct type
*,
1148 struct dwarf2_cu
*);
1150 static void create_all_comp_units (struct objfile
*);
1152 static void load_full_comp_unit (struct dwarf2_per_cu_data
*,
1155 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1157 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1158 struct dwarf2_per_cu_data
*);
1160 static void dwarf2_mark (struct dwarf2_cu
*);
1162 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1164 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1166 /* Try to locate the sections we need for DWARF 2 debugging
1167 information and return true if we have enough to do something. */
1170 dwarf2_has_info (struct objfile
*objfile
)
1172 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
1173 if (!dwarf2_per_objfile
)
1175 /* Initialize per-objfile state. */
1176 struct dwarf2_per_objfile
*data
1177 = obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1178 memset (data
, 0, sizeof (*data
));
1179 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1180 dwarf2_per_objfile
= data
;
1182 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1183 dwarf2_per_objfile
->objfile
= objfile
;
1185 return (dwarf2_per_objfile
->info
.asection
!= NULL
1186 && dwarf2_per_objfile
->abbrev
.asection
!= NULL
);
1189 /* When loading sections, we can either look for ".<name>", or for
1190 * ".z<name>", which indicates a compressed section. */
1193 section_is_p (const char *section_name
, const char *name
)
1195 return (section_name
[0] == '.'
1196 && (strcmp (section_name
+ 1, name
) == 0
1197 || (section_name
[1] == 'z'
1198 && strcmp (section_name
+ 2, name
) == 0)));
1201 /* This function is mapped across the sections and remembers the
1202 offset and size of each of the debugging sections we are interested
1206 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1208 if (section_is_p (sectp
->name
, INFO_SECTION
))
1210 dwarf2_per_objfile
->info
.asection
= sectp
;
1211 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1213 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1215 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1216 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1218 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1220 dwarf2_per_objfile
->line
.asection
= sectp
;
1221 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1223 else if (section_is_p (sectp
->name
, PUBNAMES_SECTION
))
1225 dwarf2_per_objfile
->pubnames
.asection
= sectp
;
1226 dwarf2_per_objfile
->pubnames
.size
= bfd_get_section_size (sectp
);
1228 else if (section_is_p (sectp
->name
, ARANGES_SECTION
))
1230 dwarf2_per_objfile
->aranges
.asection
= sectp
;
1231 dwarf2_per_objfile
->aranges
.size
= bfd_get_section_size (sectp
);
1233 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1235 dwarf2_per_objfile
->loc
.asection
= sectp
;
1236 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1238 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1240 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1241 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1243 else if (section_is_p (sectp
->name
, STR_SECTION
))
1245 dwarf2_per_objfile
->str
.asection
= sectp
;
1246 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1248 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1250 dwarf2_per_objfile
->frame
.asection
= sectp
;
1251 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1253 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1255 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1256 if (aflag
& SEC_HAS_CONTENTS
)
1258 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1259 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1262 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1264 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1265 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1267 else if (section_is_p (sectp
->name
, TYPES_SECTION
))
1269 dwarf2_per_objfile
->types
.asection
= sectp
;
1270 dwarf2_per_objfile
->types
.size
= bfd_get_section_size (sectp
);
1273 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1274 && bfd_section_vma (abfd
, sectp
) == 0)
1275 dwarf2_per_objfile
->has_section_at_zero
= 1;
1278 /* Decompress a section that was compressed using zlib. Store the
1279 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1282 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1283 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1285 bfd
*abfd
= objfile
->obfd
;
1287 error (_("Support for zlib-compressed DWARF data (from '%s') "
1288 "is disabled in this copy of GDB"),
1289 bfd_get_filename (abfd
));
1291 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1292 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1293 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1294 bfd_size_type uncompressed_size
;
1295 gdb_byte
*uncompressed_buffer
;
1298 int header_size
= 12;
1300 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1301 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1302 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1303 bfd_get_filename (abfd
));
1305 /* Read the zlib header. In this case, it should be "ZLIB" followed
1306 by the uncompressed section size, 8 bytes in big-endian order. */
1307 if (compressed_size
< header_size
1308 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1309 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1310 bfd_get_filename (abfd
));
1311 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1312 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1313 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1314 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1315 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1316 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1317 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1318 uncompressed_size
+= compressed_buffer
[11];
1320 /* It is possible the section consists of several compressed
1321 buffers concatenated together, so we uncompress in a loop. */
1325 strm
.avail_in
= compressed_size
- header_size
;
1326 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1327 strm
.avail_out
= uncompressed_size
;
1328 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1330 rc
= inflateInit (&strm
);
1331 while (strm
.avail_in
> 0)
1334 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1335 bfd_get_filename (abfd
), rc
);
1336 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1337 + (uncompressed_size
- strm
.avail_out
));
1338 rc
= inflate (&strm
, Z_FINISH
);
1339 if (rc
!= Z_STREAM_END
)
1340 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1341 bfd_get_filename (abfd
), rc
);
1342 rc
= inflateReset (&strm
);
1344 rc
= inflateEnd (&strm
);
1346 || strm
.avail_out
!= 0)
1347 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1348 bfd_get_filename (abfd
), rc
);
1350 do_cleanups (cleanup
);
1351 *outbuf
= uncompressed_buffer
;
1352 *outsize
= uncompressed_size
;
1356 /* Read the contents of the section SECTP from object file specified by
1357 OBJFILE, store info about the section into INFO.
1358 If the section is compressed, uncompress it before returning. */
1361 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1363 bfd
*abfd
= objfile
->obfd
;
1364 asection
*sectp
= info
->asection
;
1365 gdb_byte
*buf
, *retbuf
;
1366 unsigned char header
[4];
1370 info
->buffer
= NULL
;
1371 info
->was_mmapped
= 0;
1374 if (info
->asection
== NULL
|| info
->size
== 0)
1377 /* Check if the file has a 4-byte header indicating compression. */
1378 if (info
->size
> sizeof (header
)
1379 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1380 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1382 /* Upon decompression, update the buffer and its size. */
1383 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1385 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1393 pagesize
= getpagesize ();
1395 /* Only try to mmap sections which are large enough: we don't want to
1396 waste space due to fragmentation. Also, only try mmap for sections
1397 without relocations. */
1399 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1401 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1402 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1403 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1404 MAP_PRIVATE
, pg_offset
);
1406 if (retbuf
!= MAP_FAILED
)
1408 info
->was_mmapped
= 1;
1409 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1410 #if HAVE_POSIX_MADVISE
1411 posix_madvise (retbuf
, map_length
, POSIX_MADV_WILLNEED
);
1418 /* If we get here, we are a normal, not-compressed section. */
1420 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1422 /* When debugging .o files, we may need to apply relocations; see
1423 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1424 We never compress sections in .o files, so we only need to
1425 try this when the section is not compressed. */
1426 retbuf
= symfile_relocate_debug_section (objfile
, sectp
, buf
);
1429 info
->buffer
= retbuf
;
1433 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1434 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1435 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1436 bfd_get_filename (abfd
));
1439 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1443 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1444 asection
**sectp
, gdb_byte
**bufp
,
1445 bfd_size_type
*sizep
)
1447 struct dwarf2_per_objfile
*data
1448 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1449 struct dwarf2_section_info
*info
;
1450 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1451 info
= &data
->eh_frame
;
1452 else if (section_is_p (section_name
, FRAME_SECTION
))
1453 info
= &data
->frame
;
1457 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1458 /* We haven't read this section in yet. Do it now. */
1459 dwarf2_read_section (objfile
, info
);
1461 *sectp
= info
->asection
;
1462 *bufp
= info
->buffer
;
1463 *sizep
= info
->size
;
1466 /* Build a partial symbol table. */
1469 dwarf2_build_psymtabs (struct objfile
*objfile
)
1471 if (objfile
->global_psymbols
.size
== 0 && objfile
->static_psymbols
.size
== 0)
1473 init_psymbol_list (objfile
, 1024);
1477 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1479 /* Things are significantly easier if we have .debug_aranges and
1480 .debug_pubnames sections */
1482 dwarf2_build_psymtabs_easy (objfile
);
1486 /* only test this case for now */
1488 /* In this case we have to work a bit harder */
1489 dwarf2_build_psymtabs_hard (objfile
);
1494 /* Build the partial symbol table from the information in the
1495 .debug_pubnames and .debug_aranges sections. */
1498 dwarf2_build_psymtabs_easy (struct objfile
*objfile
)
1500 bfd
*abfd
= objfile
->obfd
;
1501 char *aranges_buffer
, *pubnames_buffer
;
1502 char *aranges_ptr
, *pubnames_ptr
;
1503 unsigned int entry_length
, version
, info_offset
, info_size
;
1505 pubnames_buffer
= dwarf2_read_section (objfile
,
1506 dwarf_pubnames_section
);
1507 pubnames_ptr
= pubnames_buffer
;
1508 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames
.size
)
1510 unsigned int bytes_read
;
1512 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1513 pubnames_ptr
+= bytes_read
;
1514 version
= read_1_byte (abfd
, pubnames_ptr
);
1516 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1518 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1522 aranges_buffer
= dwarf2_read_section (objfile
,
1523 dwarf_aranges_section
);
1528 /* Return TRUE if OFFSET is within CU_HEADER. */
1531 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1533 unsigned int bottom
= cu_header
->offset
;
1534 unsigned int top
= (cu_header
->offset
1536 + cu_header
->initial_length_size
);
1537 return (offset
>= bottom
&& offset
< top
);
1540 /* Read in the comp unit header information from the debug_info at info_ptr.
1541 NOTE: This leaves members offset, first_die_offset to be filled in
1545 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1546 gdb_byte
*info_ptr
, bfd
*abfd
)
1549 unsigned int bytes_read
;
1551 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1552 cu_header
->initial_length_size
= bytes_read
;
1553 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1554 info_ptr
+= bytes_read
;
1555 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1557 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1559 info_ptr
+= bytes_read
;
1560 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1562 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1563 if (signed_addr
< 0)
1564 internal_error (__FILE__
, __LINE__
,
1565 _("read_comp_unit_head: dwarf from non elf file"));
1566 cu_header
->signed_addr_p
= signed_addr
;
1572 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1573 gdb_byte
*buffer
, unsigned int buffer_size
,
1576 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1578 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1580 if (header
->version
!= 2 && header
->version
!= 3)
1581 error (_("Dwarf Error: wrong version in compilation unit header "
1582 "(is %d, should be %d) [in module %s]"), header
->version
,
1583 2, bfd_get_filename (abfd
));
1585 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1586 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1587 "(offset 0x%lx + 6) [in module %s]"),
1588 (long) header
->abbrev_offset
,
1589 (long) (beg_of_comp_unit
- buffer
),
1590 bfd_get_filename (abfd
));
1592 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1593 > buffer
+ buffer_size
)
1594 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1595 "(offset 0x%lx + 0) [in module %s]"),
1596 (long) header
->length
,
1597 (long) (beg_of_comp_unit
- buffer
),
1598 bfd_get_filename (abfd
));
1603 /* Read in the types comp unit header information from .debug_types entry at
1604 types_ptr. The result is a pointer to one past the end of the header. */
1607 read_type_comp_unit_head (struct comp_unit_head
*cu_header
,
1608 ULONGEST
*signature
,
1609 gdb_byte
*types_ptr
, bfd
*abfd
)
1611 unsigned int bytes_read
;
1612 gdb_byte
*initial_types_ptr
= types_ptr
;
1614 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->types
);
1615 cu_header
->offset
= types_ptr
- dwarf2_per_objfile
->types
.buffer
;
1617 types_ptr
= read_comp_unit_head (cu_header
, types_ptr
, abfd
);
1619 *signature
= read_8_bytes (abfd
, types_ptr
);
1621 types_ptr
+= cu_header
->offset_size
;
1622 cu_header
->first_die_offset
= types_ptr
- initial_types_ptr
;
1627 /* Allocate a new partial symtab for file named NAME and mark this new
1628 partial symtab as being an include of PST. */
1631 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1632 struct objfile
*objfile
)
1634 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1636 subpst
->section_offsets
= pst
->section_offsets
;
1637 subpst
->textlow
= 0;
1638 subpst
->texthigh
= 0;
1640 subpst
->dependencies
= (struct partial_symtab
**)
1641 obstack_alloc (&objfile
->objfile_obstack
,
1642 sizeof (struct partial_symtab
*));
1643 subpst
->dependencies
[0] = pst
;
1644 subpst
->number_of_dependencies
= 1;
1646 subpst
->globals_offset
= 0;
1647 subpst
->n_global_syms
= 0;
1648 subpst
->statics_offset
= 0;
1649 subpst
->n_static_syms
= 0;
1650 subpst
->symtab
= NULL
;
1651 subpst
->read_symtab
= pst
->read_symtab
;
1654 /* No private part is necessary for include psymtabs. This property
1655 can be used to differentiate between such include psymtabs and
1656 the regular ones. */
1657 subpst
->read_symtab_private
= NULL
;
1660 /* Read the Line Number Program data and extract the list of files
1661 included by the source file represented by PST. Build an include
1662 partial symtab for each of these included files. */
1665 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1666 struct die_info
*die
,
1667 struct partial_symtab
*pst
)
1669 struct objfile
*objfile
= cu
->objfile
;
1670 bfd
*abfd
= objfile
->obfd
;
1671 struct line_header
*lh
= NULL
;
1672 struct attribute
*attr
;
1674 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
1677 unsigned int line_offset
= DW_UNSND (attr
);
1678 lh
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
1681 return; /* No linetable, so no includes. */
1683 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1685 free_line_header (lh
);
1689 hash_type_signature (const void *item
)
1691 const struct signatured_type
*type_sig
= item
;
1692 /* This drops the top 32 bits of the signature, but is ok for a hash. */
1693 return type_sig
->signature
;
1697 eq_type_signature (const void *item_lhs
, const void *item_rhs
)
1699 const struct signatured_type
*lhs
= item_lhs
;
1700 const struct signatured_type
*rhs
= item_rhs
;
1701 return lhs
->signature
== rhs
->signature
;
1704 /* Create the hash table of all entries in the .debug_types section.
1705 The result is zero if there is an error (e.g. missing .debug_types section),
1706 otherwise non-zero. */
1709 create_debug_types_hash_table (struct objfile
*objfile
)
1714 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
1715 info_ptr
= dwarf2_per_objfile
->types
.buffer
;
1717 if (info_ptr
== NULL
)
1719 dwarf2_per_objfile
->signatured_types
= NULL
;
1723 types_htab
= htab_create_alloc_ex (41,
1724 hash_type_signature
,
1727 &objfile
->objfile_obstack
,
1728 hashtab_obstack_allocate
,
1729 dummy_obstack_deallocate
);
1731 if (dwarf2_die_debug
)
1732 fprintf_unfiltered (gdb_stdlog
, "Signatured types:\n");
1734 while (info_ptr
< dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1736 unsigned int offset
;
1737 unsigned int offset_size
;
1738 unsigned int type_offset
;
1739 unsigned int length
, initial_length_size
;
1740 unsigned short version
;
1742 struct signatured_type
*type_sig
;
1744 gdb_byte
*ptr
= info_ptr
;
1746 offset
= ptr
- dwarf2_per_objfile
->types
.buffer
;
1748 /* We need to read the type's signature in order to build the hash
1749 table, but we don't need to read anything else just yet. */
1751 /* Sanity check to ensure entire cu is present. */
1752 length
= read_initial_length (objfile
->obfd
, ptr
, &initial_length_size
);
1753 if (ptr
+ length
+ initial_length_size
1754 > dwarf2_per_objfile
->types
.buffer
+ dwarf2_per_objfile
->types
.size
)
1756 complaint (&symfile_complaints
,
1757 _("debug type entry runs off end of `.debug_types' section, ignored"));
1761 offset_size
= initial_length_size
== 4 ? 4 : 8;
1762 ptr
+= initial_length_size
;
1763 version
= bfd_get_16 (objfile
->obfd
, ptr
);
1765 ptr
+= offset_size
; /* abbrev offset */
1766 ptr
+= 1; /* address size */
1767 signature
= bfd_get_64 (objfile
->obfd
, ptr
);
1769 type_offset
= read_offset_1 (objfile
->obfd
, ptr
, offset_size
);
1771 type_sig
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*type_sig
));
1772 memset (type_sig
, 0, sizeof (*type_sig
));
1773 type_sig
->signature
= signature
;
1774 type_sig
->offset
= offset
;
1775 type_sig
->type_offset
= type_offset
;
1777 slot
= htab_find_slot (types_htab
, type_sig
, INSERT
);
1778 gdb_assert (slot
!= NULL
);
1781 if (dwarf2_die_debug
)
1782 fprintf_unfiltered (gdb_stdlog
, " offset 0x%x, signature 0x%s\n",
1783 offset
, phex (signature
, sizeof (signature
)));
1785 info_ptr
= info_ptr
+ initial_length_size
+ length
;
1788 dwarf2_per_objfile
->signatured_types
= types_htab
;
1793 /* Lookup a signature based type.
1794 Returns NULL if SIG is not present in the table. */
1796 static struct signatured_type
*
1797 lookup_signatured_type (struct objfile
*objfile
, ULONGEST sig
)
1799 struct signatured_type find_entry
, *entry
;
1801 if (dwarf2_per_objfile
->signatured_types
== NULL
)
1803 complaint (&symfile_complaints
,
1804 _("missing `.debug_types' section for DW_FORM_sig8 die"));
1808 find_entry
.signature
= sig
;
1809 entry
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
1813 /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */
1816 init_cu_die_reader (struct die_reader_specs
*reader
,
1817 struct dwarf2_cu
*cu
)
1819 reader
->abfd
= cu
->objfile
->obfd
;
1821 if (cu
->per_cu
->from_debug_types
)
1823 gdb_assert (dwarf2_per_objfile
->types
.readin
);
1824 reader
->buffer
= dwarf2_per_objfile
->types
.buffer
;
1828 gdb_assert (dwarf2_per_objfile
->info
.readin
);
1829 reader
->buffer
= dwarf2_per_objfile
->info
.buffer
;
1833 /* Find the base address of the compilation unit for range lists and
1834 location lists. It will normally be specified by DW_AT_low_pc.
1835 In DWARF-3 draft 4, the base address could be overridden by
1836 DW_AT_entry_pc. It's been removed, but GCC still uses this for
1837 compilation units with discontinuous ranges. */
1840 dwarf2_find_base_address (struct die_info
*die
, struct dwarf2_cu
*cu
)
1842 struct attribute
*attr
;
1845 cu
->base_address
= 0;
1847 attr
= dwarf2_attr (die
, DW_AT_entry_pc
, cu
);
1850 cu
->base_address
= DW_ADDR (attr
);
1855 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
1858 cu
->base_address
= DW_ADDR (attr
);
1864 /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard
1865 to combine the common parts.
1866 Process a compilation unit for a psymtab.
1867 BUFFER is a pointer to the beginning of the dwarf section buffer,
1868 either .debug_info or debug_types.
1869 INFO_PTR is a pointer to the start of the CU.
1870 Returns a pointer to the next CU. */
1873 process_psymtab_comp_unit (struct objfile
*objfile
,
1874 struct dwarf2_per_cu_data
*this_cu
,
1875 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
1876 unsigned int buffer_size
)
1878 bfd
*abfd
= objfile
->obfd
;
1879 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1880 struct die_info
*comp_unit_die
;
1881 struct partial_symtab
*pst
;
1883 struct cleanup
*back_to_inner
;
1884 struct dwarf2_cu cu
;
1885 unsigned int bytes_read
;
1886 int has_children
, has_pc_info
;
1887 struct attribute
*attr
;
1889 CORE_ADDR best_lowpc
= 0, best_highpc
= 0;
1890 struct die_reader_specs reader_specs
;
1892 memset (&cu
, 0, sizeof (cu
));
1893 cu
.objfile
= objfile
;
1894 obstack_init (&cu
.comp_unit_obstack
);
1896 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1898 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
,
1899 buffer
, buffer_size
,
1902 /* Complete the cu_header. */
1903 cu
.header
.offset
= beg_of_comp_unit
- buffer
;
1904 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1906 cu
.list_in_scope
= &file_symbols
;
1908 /* If this compilation unit was already read in, free the
1909 cached copy in order to read it in again. This is
1910 necessary because we skipped some symbols when we first
1911 read in the compilation unit (see load_partial_dies).
1912 This problem could be avoided, but the benefit is
1914 if (this_cu
->cu
!= NULL
)
1915 free_one_cached_comp_unit (this_cu
->cu
);
1917 /* Note that this is a pointer to our stack frame, being
1918 added to a global data structure. It will be cleaned up
1919 in free_stack_comp_unit when we finish with this
1920 compilation unit. */
1922 cu
.per_cu
= this_cu
;
1924 /* Read the abbrevs for this compilation unit into a table. */
1925 dwarf2_read_abbrevs (abfd
, &cu
);
1926 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1928 /* Read the compilation unit die. */
1929 if (this_cu
->from_debug_types
)
1930 info_ptr
+= 8 /*signature*/ + cu
.header
.offset_size
;
1931 init_cu_die_reader (&reader_specs
, &cu
);
1932 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
1935 if (this_cu
->from_debug_types
)
1937 /* offset,length haven't been set yet for type units. */
1938 this_cu
->offset
= cu
.header
.offset
;
1939 this_cu
->length
= cu
.header
.length
+ cu
.header
.initial_length_size
;
1941 else if (comp_unit_die
->tag
== DW_TAG_partial_unit
)
1943 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1944 + cu
.header
.initial_length_size
);
1945 do_cleanups (back_to_inner
);
1949 /* Set the language we're debugging. */
1950 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, &cu
);
1952 set_cu_language (DW_UNSND (attr
), &cu
);
1954 set_cu_language (language_minimal
, &cu
);
1956 /* Allocate a new partial symbol table structure. */
1957 attr
= dwarf2_attr (comp_unit_die
, DW_AT_name
, &cu
);
1958 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1959 (attr
!= NULL
) ? DW_STRING (attr
) : "",
1960 /* TEXTLOW and TEXTHIGH are set below. */
1962 objfile
->global_psymbols
.next
,
1963 objfile
->static_psymbols
.next
);
1965 attr
= dwarf2_attr (comp_unit_die
, DW_AT_comp_dir
, &cu
);
1967 pst
->dirname
= DW_STRING (attr
);
1969 pst
->read_symtab_private
= this_cu
;
1971 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1973 /* Store the function that reads in the rest of the symbol table */
1974 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1976 this_cu
->psymtab
= pst
;
1978 dwarf2_find_base_address (comp_unit_die
, &cu
);
1980 /* Possibly set the default values of LOWPC and HIGHPC from
1982 has_pc_info
= dwarf2_get_pc_bounds (comp_unit_die
, &best_lowpc
,
1983 &best_highpc
, &cu
, pst
);
1984 if (has_pc_info
== 1 && best_lowpc
< best_highpc
)
1985 /* Store the contiguous range if it is not empty; it can be empty for
1986 CUs with no code. */
1987 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1988 best_lowpc
+ baseaddr
,
1989 best_highpc
+ baseaddr
- 1, pst
);
1991 /* Check if comp unit has_children.
1992 If so, read the rest of the partial symbols from this comp unit.
1993 If not, there's no more debug_info for this comp unit. */
1996 struct partial_die_info
*first_die
;
1997 CORE_ADDR lowpc
, highpc
;
1999 lowpc
= ((CORE_ADDR
) -1);
2000 highpc
= ((CORE_ADDR
) 0);
2002 first_die
= load_partial_dies (abfd
, buffer
, info_ptr
, 1, &cu
);
2004 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
2005 ! has_pc_info
, &cu
);
2007 /* If we didn't find a lowpc, set it to highpc to avoid
2008 complaints from `maint check'. */
2009 if (lowpc
== ((CORE_ADDR
) -1))
2012 /* If the compilation unit didn't have an explicit address range,
2013 then use the information extracted from its child dies. */
2017 best_highpc
= highpc
;
2020 pst
->textlow
= best_lowpc
+ baseaddr
;
2021 pst
->texthigh
= best_highpc
+ baseaddr
;
2023 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
2024 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
2025 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
2026 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
2027 sort_pst_symbols (pst
);
2029 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
2030 + cu
.header
.initial_length_size
);
2032 if (this_cu
->from_debug_types
)
2034 /* It's not clear we want to do anything with stmt lists here.
2035 Waiting to see what gcc ultimately does. */
2039 /* Get the list of files included in the current compilation unit,
2040 and build a psymtab for each of them. */
2041 dwarf2_build_include_psymtabs (&cu
, comp_unit_die
, pst
);
2044 do_cleanups (back_to_inner
);
2049 /* Traversal function for htab_traverse_noresize.
2050 Process one .debug_types comp-unit. */
2053 process_type_comp_unit (void **slot
, void *info
)
2055 struct signatured_type
*entry
= (struct signatured_type
*) *slot
;
2056 struct objfile
*objfile
= (struct objfile
*) info
;
2057 struct dwarf2_per_cu_data
*this_cu
;
2059 this_cu
= &entry
->per_cu
;
2060 this_cu
->from_debug_types
= 1;
2062 gdb_assert (dwarf2_per_objfile
->types
.readin
);
2063 process_psymtab_comp_unit (objfile
, this_cu
,
2064 dwarf2_per_objfile
->types
.buffer
,
2065 dwarf2_per_objfile
->types
.buffer
+ entry
->offset
,
2066 dwarf2_per_objfile
->types
.size
);
2071 /* Subroutine of dwarf2_build_psymtabs_hard to simplify it.
2072 Build partial symbol tables for the .debug_types comp-units. */
2075 build_type_psymtabs (struct objfile
*objfile
)
2077 if (! create_debug_types_hash_table (objfile
))
2080 htab_traverse_noresize (dwarf2_per_objfile
->signatured_types
,
2081 process_type_comp_unit
, objfile
);
2084 /* Build the partial symbol table by doing a quick pass through the
2085 .debug_info and .debug_abbrev sections. */
2088 dwarf2_build_psymtabs_hard (struct objfile
*objfile
)
2090 bfd
*abfd
= objfile
->obfd
;
2092 struct cleanup
*back_to
;
2094 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2095 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2097 /* Any cached compilation units will be linked by the per-objfile
2098 read_in_chain. Make sure to free them when we're done. */
2099 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
2101 build_type_psymtabs (objfile
);
2103 create_all_comp_units (objfile
);
2105 objfile
->psymtabs_addrmap
=
2106 addrmap_create_mutable (&objfile
->objfile_obstack
);
2108 /* Since the objects we're extracting from .debug_info vary in
2109 length, only the individual functions to extract them (like
2110 read_comp_unit_head and load_partial_die) can really know whether
2111 the buffer is large enough to hold another complete object.
2113 At the moment, they don't actually check that. If .debug_info
2114 holds just one extra byte after the last compilation unit's dies,
2115 then read_comp_unit_head will happily read off the end of the
2116 buffer. read_partial_die is similarly casual. Those functions
2119 For this loop condition, simply checking whether there's any data
2120 left at all should be sufficient. */
2122 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
2123 + dwarf2_per_objfile
->info
.size
))
2125 struct dwarf2_per_cu_data
*this_cu
;
2127 this_cu
= dwarf2_find_comp_unit (info_ptr
- dwarf2_per_objfile
->info
.buffer
,
2130 info_ptr
= process_psymtab_comp_unit (objfile
, this_cu
,
2131 dwarf2_per_objfile
->info
.buffer
,
2133 dwarf2_per_objfile
->info
.size
);
2136 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
2137 &objfile
->objfile_obstack
);
2139 do_cleanups (back_to
);
2142 /* Load the partial DIEs for a secondary CU into memory. */
2145 load_partial_comp_unit (struct dwarf2_per_cu_data
*this_cu
,
2146 struct objfile
*objfile
)
2148 bfd
*abfd
= objfile
->obfd
;
2149 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
2150 struct die_info
*comp_unit_die
;
2151 struct dwarf2_cu
*cu
;
2152 unsigned int bytes_read
;
2153 struct cleanup
*back_to
;
2154 struct attribute
*attr
;
2156 struct die_reader_specs reader_specs
;
2158 gdb_assert (! this_cu
->from_debug_types
);
2160 gdb_assert (dwarf2_per_objfile
->info
.readin
);
2161 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
2162 beg_of_comp_unit
= info_ptr
;
2164 cu
= alloc_one_comp_unit (objfile
);
2166 /* ??? Missing cleanup for CU? */
2168 /* Link this compilation unit into the compilation unit tree. */
2170 cu
->per_cu
= this_cu
;
2171 cu
->type_hash
= this_cu
->type_hash
;
2173 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
,
2174 dwarf2_per_objfile
->info
.buffer
,
2175 dwarf2_per_objfile
->info
.size
,
2178 /* Complete the cu_header. */
2179 cu
->header
.offset
= this_cu
->offset
;
2180 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
2182 /* Read the abbrevs for this compilation unit into a table. */
2183 dwarf2_read_abbrevs (abfd
, cu
);
2184 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2186 /* Read the compilation unit die. */
2187 init_cu_die_reader (&reader_specs
, cu
);
2188 info_ptr
= read_full_die (&reader_specs
, &comp_unit_die
, info_ptr
,
2191 /* Set the language we're debugging. */
2192 attr
= dwarf2_attr (comp_unit_die
, DW_AT_language
, cu
);
2194 set_cu_language (DW_UNSND (attr
), cu
);
2196 set_cu_language (language_minimal
, cu
);
2198 /* Check if comp unit has_children.
2199 If so, read the rest of the partial symbols from this comp unit.
2200 If not, there's no more debug_info for this comp unit. */
2202 load_partial_dies (abfd
, dwarf2_per_objfile
->info
.buffer
, info_ptr
, 0, cu
);
2204 do_cleanups (back_to
);
2207 /* Create a list of all compilation units in OBJFILE. We do this only
2208 if an inter-comp-unit reference is found; presumably if there is one,
2209 there will be many, and one will occur early in the .debug_info section.
2210 So there's no point in building this list incrementally. */
2213 create_all_comp_units (struct objfile
*objfile
)
2217 struct dwarf2_per_cu_data
**all_comp_units
;
2220 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
2221 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
2225 all_comp_units
= xmalloc (n_allocated
2226 * sizeof (struct dwarf2_per_cu_data
*));
2228 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
2230 unsigned int length
, initial_length_size
;
2231 gdb_byte
*beg_of_comp_unit
;
2232 struct dwarf2_per_cu_data
*this_cu
;
2233 unsigned int offset
;
2235 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
2237 /* Read just enough information to find out where the next
2238 compilation unit is. */
2239 length
= read_initial_length (objfile
->obfd
, info_ptr
,
2240 &initial_length_size
);
2242 /* Save the compilation unit for later lookup. */
2243 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
2244 sizeof (struct dwarf2_per_cu_data
));
2245 memset (this_cu
, 0, sizeof (*this_cu
));
2246 this_cu
->offset
= offset
;
2247 this_cu
->length
= length
+ initial_length_size
;
2249 if (n_comp_units
== n_allocated
)
2252 all_comp_units
= xrealloc (all_comp_units
,
2254 * sizeof (struct dwarf2_per_cu_data
*));
2256 all_comp_units
[n_comp_units
++] = this_cu
;
2258 info_ptr
= info_ptr
+ this_cu
->length
;
2261 dwarf2_per_objfile
->all_comp_units
2262 = obstack_alloc (&objfile
->objfile_obstack
,
2263 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2264 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
2265 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
2266 xfree (all_comp_units
);
2267 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
2270 /* Process all loaded DIEs for compilation unit CU, starting at
2271 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
2272 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
2273 DW_AT_ranges). If NEED_PC is set, then this function will set
2274 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
2275 and record the covered ranges in the addrmap. */
2278 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
2279 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2281 struct objfile
*objfile
= cu
->objfile
;
2282 bfd
*abfd
= objfile
->obfd
;
2283 struct partial_die_info
*pdi
;
2285 /* Now, march along the PDI's, descending into ones which have
2286 interesting children but skipping the children of the other ones,
2287 until we reach the end of the compilation unit. */
2293 fixup_partial_die (pdi
, cu
);
2295 /* Anonymous namespaces have no name but have interesting
2296 children, so we need to look at them. Ditto for anonymous
2299 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
2300 || pdi
->tag
== DW_TAG_enumeration_type
)
2304 case DW_TAG_subprogram
:
2305 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2307 case DW_TAG_variable
:
2308 case DW_TAG_typedef
:
2309 case DW_TAG_union_type
:
2310 if (!pdi
->is_declaration
)
2312 add_partial_symbol (pdi
, cu
);
2315 case DW_TAG_class_type
:
2316 case DW_TAG_interface_type
:
2317 case DW_TAG_structure_type
:
2318 if (!pdi
->is_declaration
)
2320 add_partial_symbol (pdi
, cu
);
2323 case DW_TAG_enumeration_type
:
2324 if (!pdi
->is_declaration
)
2325 add_partial_enumeration (pdi
, cu
);
2327 case DW_TAG_base_type
:
2328 case DW_TAG_subrange_type
:
2329 /* File scope base type definitions are added to the partial
2331 add_partial_symbol (pdi
, cu
);
2333 case DW_TAG_namespace
:
2334 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
2337 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
2344 /* If the die has a sibling, skip to the sibling. */
2346 pdi
= pdi
->die_sibling
;
2350 /* Functions used to compute the fully scoped name of a partial DIE.
2352 Normally, this is simple. For C++, the parent DIE's fully scoped
2353 name is concatenated with "::" and the partial DIE's name. For
2354 Java, the same thing occurs except that "." is used instead of "::".
2355 Enumerators are an exception; they use the scope of their parent
2356 enumeration type, i.e. the name of the enumeration type is not
2357 prepended to the enumerator.
2359 There are two complexities. One is DW_AT_specification; in this
2360 case "parent" means the parent of the target of the specification,
2361 instead of the direct parent of the DIE. The other is compilers
2362 which do not emit DW_TAG_namespace; in this case we try to guess
2363 the fully qualified name of structure types from their members'
2364 linkage names. This must be done using the DIE's children rather
2365 than the children of any DW_AT_specification target. We only need
2366 to do this for structures at the top level, i.e. if the target of
2367 any DW_AT_specification (if any; otherwise the DIE itself) does not
2370 /* Compute the scope prefix associated with PDI's parent, in
2371 compilation unit CU. The result will be allocated on CU's
2372 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2373 field. NULL is returned if no prefix is necessary. */
2375 partial_die_parent_scope (struct partial_die_info
*pdi
,
2376 struct dwarf2_cu
*cu
)
2378 char *grandparent_scope
;
2379 struct partial_die_info
*parent
, *real_pdi
;
2381 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2382 then this means the parent of the specification DIE. */
2385 while (real_pdi
->has_specification
)
2386 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2388 parent
= real_pdi
->die_parent
;
2392 if (parent
->scope_set
)
2393 return parent
->scope
;
2395 fixup_partial_die (parent
, cu
);
2397 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2399 if (parent
->tag
== DW_TAG_namespace
2400 || parent
->tag
== DW_TAG_structure_type
2401 || parent
->tag
== DW_TAG_class_type
2402 || parent
->tag
== DW_TAG_interface_type
2403 || parent
->tag
== DW_TAG_union_type
2404 || parent
->tag
== DW_TAG_enumeration_type
)
2406 if (grandparent_scope
== NULL
)
2407 parent
->scope
= parent
->name
;
2409 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2412 else if (parent
->tag
== DW_TAG_enumerator
)
2413 /* Enumerators should not get the name of the enumeration as a prefix. */
2414 parent
->scope
= grandparent_scope
;
2417 /* FIXME drow/2004-04-01: What should we be doing with
2418 function-local names? For partial symbols, we should probably be
2420 complaint (&symfile_complaints
,
2421 _("unhandled containing DIE tag %d for DIE at %d"),
2422 parent
->tag
, pdi
->offset
);
2423 parent
->scope
= grandparent_scope
;
2426 parent
->scope_set
= 1;
2427 return parent
->scope
;
2430 /* Return the fully scoped name associated with PDI, from compilation unit
2431 CU. The result will be allocated with malloc. */
2433 partial_die_full_name (struct partial_die_info
*pdi
,
2434 struct dwarf2_cu
*cu
)
2438 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2439 if (parent_scope
== NULL
)
2442 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2446 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2448 struct objfile
*objfile
= cu
->objfile
;
2450 char *actual_name
= NULL
;
2451 const char *my_prefix
;
2452 const struct partial_symbol
*psym
= NULL
;
2454 int built_actual_name
= 0;
2456 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2458 actual_name
= partial_die_full_name (pdi
, cu
);
2460 built_actual_name
= 1;
2462 if (actual_name
== NULL
)
2463 actual_name
= pdi
->name
;
2467 case DW_TAG_subprogram
:
2468 if (pdi
->is_external
|| cu
->language
== language_ada
)
2470 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2471 of the global scope. But in Ada, we want to be able to access
2472 nested procedures globally. So all Ada subprograms are stored
2473 in the global scope. */
2474 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2475 mst_text, objfile); */
2476 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2478 VAR_DOMAIN
, LOC_BLOCK
,
2479 &objfile
->global_psymbols
,
2480 0, pdi
->lowpc
+ baseaddr
,
2481 cu
->language
, objfile
);
2485 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2486 mst_file_text, objfile); */
2487 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2489 VAR_DOMAIN
, LOC_BLOCK
,
2490 &objfile
->static_psymbols
,
2491 0, pdi
->lowpc
+ baseaddr
,
2492 cu
->language
, objfile
);
2495 case DW_TAG_variable
:
2496 if (pdi
->is_external
)
2499 Don't enter into the minimal symbol tables as there is
2500 a minimal symbol table entry from the ELF symbols already.
2501 Enter into partial symbol table if it has a location
2502 descriptor or a type.
2503 If the location descriptor is missing, new_symbol will create
2504 a LOC_UNRESOLVED symbol, the address of the variable will then
2505 be determined from the minimal symbol table whenever the variable
2507 The address for the partial symbol table entry is not
2508 used by GDB, but it comes in handy for debugging partial symbol
2512 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2513 if (pdi
->locdesc
|| pdi
->has_type
)
2514 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2516 VAR_DOMAIN
, LOC_STATIC
,
2517 &objfile
->global_psymbols
,
2519 cu
->language
, objfile
);
2523 /* Static Variable. Skip symbols without location descriptors. */
2524 if (pdi
->locdesc
== NULL
)
2526 if (built_actual_name
)
2527 xfree (actual_name
);
2530 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2531 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2532 mst_file_data, objfile); */
2533 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2535 VAR_DOMAIN
, LOC_STATIC
,
2536 &objfile
->static_psymbols
,
2538 cu
->language
, objfile
);
2541 case DW_TAG_typedef
:
2542 case DW_TAG_base_type
:
2543 case DW_TAG_subrange_type
:
2544 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2546 VAR_DOMAIN
, LOC_TYPEDEF
,
2547 &objfile
->static_psymbols
,
2548 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2550 case DW_TAG_namespace
:
2551 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2553 VAR_DOMAIN
, LOC_TYPEDEF
,
2554 &objfile
->global_psymbols
,
2555 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2557 case DW_TAG_class_type
:
2558 case DW_TAG_interface_type
:
2559 case DW_TAG_structure_type
:
2560 case DW_TAG_union_type
:
2561 case DW_TAG_enumeration_type
:
2562 /* Skip external references. The DWARF standard says in the section
2563 about "Structure, Union, and Class Type Entries": "An incomplete
2564 structure, union or class type is represented by a structure,
2565 union or class entry that does not have a byte size attribute
2566 and that has a DW_AT_declaration attribute." */
2567 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2569 if (built_actual_name
)
2570 xfree (actual_name
);
2574 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2575 static vs. global. */
2576 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2578 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2579 (cu
->language
== language_cplus
2580 || cu
->language
== language_java
)
2581 ? &objfile
->global_psymbols
2582 : &objfile
->static_psymbols
,
2583 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2586 case DW_TAG_enumerator
:
2587 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2589 VAR_DOMAIN
, LOC_CONST
,
2590 (cu
->language
== language_cplus
2591 || cu
->language
== language_java
)
2592 ? &objfile
->global_psymbols
2593 : &objfile
->static_psymbols
,
2594 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2600 if (built_actual_name
)
2601 xfree (actual_name
);
2604 /* Read a partial die corresponding to a namespace; also, add a symbol
2605 corresponding to that namespace to the symbol table. NAMESPACE is
2606 the name of the enclosing namespace. */
2609 add_partial_namespace (struct partial_die_info
*pdi
,
2610 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2611 int need_pc
, struct dwarf2_cu
*cu
)
2613 struct objfile
*objfile
= cu
->objfile
;
2615 /* Add a symbol for the namespace. */
2617 add_partial_symbol (pdi
, cu
);
2619 /* Now scan partial symbols in that namespace. */
2621 if (pdi
->has_children
)
2622 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2625 /* Read a partial die corresponding to a Fortran module. */
2628 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2629 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2631 /* Now scan partial symbols in that module.
2633 FIXME: Support the separate Fortran module namespaces. */
2635 if (pdi
->has_children
)
2636 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2639 /* Read a partial die corresponding to a subprogram and create a partial
2640 symbol for that subprogram. When the CU language allows it, this
2641 routine also defines a partial symbol for each nested subprogram
2642 that this subprogram contains.
2644 DIE my also be a lexical block, in which case we simply search
2645 recursively for suprograms defined inside that lexical block.
2646 Again, this is only performed when the CU language allows this
2647 type of definitions. */
2650 add_partial_subprogram (struct partial_die_info
*pdi
,
2651 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2652 int need_pc
, struct dwarf2_cu
*cu
)
2654 if (pdi
->tag
== DW_TAG_subprogram
)
2656 if (pdi
->has_pc_info
)
2658 if (pdi
->lowpc
< *lowpc
)
2659 *lowpc
= pdi
->lowpc
;
2660 if (pdi
->highpc
> *highpc
)
2661 *highpc
= pdi
->highpc
;
2665 struct objfile
*objfile
= cu
->objfile
;
2667 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2668 SECT_OFF_TEXT (objfile
));
2669 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2670 pdi
->lowpc
+ baseaddr
,
2671 pdi
->highpc
- 1 + baseaddr
,
2672 cu
->per_cu
->psymtab
);
2674 if (!pdi
->is_declaration
)
2675 add_partial_symbol (pdi
, cu
);
2679 if (! pdi
->has_children
)
2682 if (cu
->language
== language_ada
)
2684 pdi
= pdi
->die_child
;
2687 fixup_partial_die (pdi
, cu
);
2688 if (pdi
->tag
== DW_TAG_subprogram
2689 || pdi
->tag
== DW_TAG_lexical_block
)
2690 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2691 pdi
= pdi
->die_sibling
;
2696 /* See if we can figure out if the class lives in a namespace. We do
2697 this by looking for a member function; its demangled name will
2698 contain namespace info, if there is any. */
2701 guess_structure_name (struct partial_die_info
*struct_pdi
,
2702 struct dwarf2_cu
*cu
)
2704 if ((cu
->language
== language_cplus
2705 || cu
->language
== language_java
)
2706 && cu
->has_namespace_info
== 0
2707 && struct_pdi
->has_children
)
2709 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2710 what template types look like, because the demangler
2711 frequently doesn't give the same name as the debug info. We
2712 could fix this by only using the demangled name to get the
2713 prefix (but see comment in read_structure_type). */
2715 struct partial_die_info
*real_pdi
;
2717 /* If this DIE (this DIE's specification, if any) has a parent, then
2718 we should not do this. We'll prepend the parent's fully qualified
2719 name when we create the partial symbol. */
2721 real_pdi
= struct_pdi
;
2722 while (real_pdi
->has_specification
)
2723 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2725 if (real_pdi
->die_parent
!= NULL
)
2730 /* Read a partial die corresponding to an enumeration type. */
2733 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2734 struct dwarf2_cu
*cu
)
2736 struct objfile
*objfile
= cu
->objfile
;
2737 bfd
*abfd
= objfile
->obfd
;
2738 struct partial_die_info
*pdi
;
2740 if (enum_pdi
->name
!= NULL
)
2741 add_partial_symbol (enum_pdi
, cu
);
2743 pdi
= enum_pdi
->die_child
;
2746 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2747 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2749 add_partial_symbol (pdi
, cu
);
2750 pdi
= pdi
->die_sibling
;
2754 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2755 Return the corresponding abbrev, or NULL if the number is zero (indicating
2756 an empty DIE). In either case *BYTES_READ will be set to the length of
2757 the initial number. */
2759 static struct abbrev_info
*
2760 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2761 struct dwarf2_cu
*cu
)
2763 bfd
*abfd
= cu
->objfile
->obfd
;
2764 unsigned int abbrev_number
;
2765 struct abbrev_info
*abbrev
;
2767 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2769 if (abbrev_number
== 0)
2772 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2775 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2776 bfd_get_filename (abfd
));
2782 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2783 Returns a pointer to the end of a series of DIEs, terminated by an empty
2784 DIE. Any children of the skipped DIEs will also be skipped. */
2787 skip_children (gdb_byte
*buffer
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2789 struct abbrev_info
*abbrev
;
2790 unsigned int bytes_read
;
2794 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2796 return info_ptr
+ bytes_read
;
2798 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
2802 /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER.
2803 INFO_PTR should point just after the initial uleb128 of a DIE, and the
2804 abbrev corresponding to that skipped uleb128 should be passed in
2805 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2809 skip_one_die (gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2810 struct abbrev_info
*abbrev
, struct dwarf2_cu
*cu
)
2812 unsigned int bytes_read
;
2813 struct attribute attr
;
2814 bfd
*abfd
= cu
->objfile
->obfd
;
2815 unsigned int form
, i
;
2817 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2819 /* The only abbrev we care about is DW_AT_sibling. */
2820 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2822 read_attribute (&attr
, &abbrev
->attrs
[i
],
2823 abfd
, info_ptr
, cu
);
2824 if (attr
.form
== DW_FORM_ref_addr
)
2825 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2827 return buffer
+ dwarf2_get_ref_die_offset (&attr
);
2830 /* If it isn't DW_AT_sibling, skip this attribute. */
2831 form
= abbrev
->attrs
[i
].form
;
2835 case DW_FORM_ref_addr
:
2836 /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3
2837 and later it is offset sized. */
2838 if (cu
->header
.version
== 2)
2839 info_ptr
+= cu
->header
.addr_size
;
2841 info_ptr
+= cu
->header
.offset_size
;
2844 info_ptr
+= cu
->header
.addr_size
;
2864 case DW_FORM_string
:
2865 read_string (abfd
, info_ptr
, &bytes_read
);
2866 info_ptr
+= bytes_read
;
2869 info_ptr
+= cu
->header
.offset_size
;
2872 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2873 info_ptr
+= bytes_read
;
2875 case DW_FORM_block1
:
2876 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2878 case DW_FORM_block2
:
2879 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2881 case DW_FORM_block4
:
2882 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2886 case DW_FORM_ref_udata
:
2887 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2889 case DW_FORM_indirect
:
2890 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2891 info_ptr
+= bytes_read
;
2892 /* We need to continue parsing from here, so just go back to
2894 goto skip_attribute
;
2897 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2898 dwarf_form_name (form
),
2899 bfd_get_filename (abfd
));
2903 if (abbrev
->has_children
)
2904 return skip_children (buffer
, info_ptr
, cu
);
2909 /* Locate ORIG_PDI's sibling.
2910 INFO_PTR should point to the start of the next DIE after ORIG_PDI
2914 locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
2915 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
2916 bfd
*abfd
, struct dwarf2_cu
*cu
)
2918 /* Do we know the sibling already? */
2920 if (orig_pdi
->sibling
)
2921 return orig_pdi
->sibling
;
2923 /* Are there any children to deal with? */
2925 if (!orig_pdi
->has_children
)
2928 /* Skip the children the long way. */
2930 return skip_children (buffer
, info_ptr
, cu
);
2933 /* Expand this partial symbol table into a full symbol table. */
2936 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2938 /* FIXME: This is barely more than a stub. */
2943 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2949 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2950 gdb_flush (gdb_stdout
);
2953 /* Restore our global data. */
2954 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2955 dwarf2_objfile_data_key
);
2957 /* If this psymtab is constructed from a debug-only objfile, the
2958 has_section_at_zero flag will not necessarily be correct. We
2959 can get the correct value for this flag by looking at the data
2960 associated with the (presumably stripped) associated objfile. */
2961 if (pst
->objfile
->separate_debug_objfile_backlink
)
2963 struct dwarf2_per_objfile
*dpo_backlink
2964 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2965 dwarf2_objfile_data_key
);
2966 dwarf2_per_objfile
->has_section_at_zero
2967 = dpo_backlink
->has_section_at_zero
;
2970 psymtab_to_symtab_1 (pst
);
2972 /* Finish up the debug error message. */
2974 printf_filtered (_("done.\n"));
2979 /* Add PER_CU to the queue. */
2982 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2984 struct dwarf2_queue_item
*item
;
2987 item
= xmalloc (sizeof (*item
));
2988 item
->per_cu
= per_cu
;
2991 if (dwarf2_queue
== NULL
)
2992 dwarf2_queue
= item
;
2994 dwarf2_queue_tail
->next
= item
;
2996 dwarf2_queue_tail
= item
;
2999 /* Process the queue. */
3002 process_queue (struct objfile
*objfile
)
3004 struct dwarf2_queue_item
*item
, *next_item
;
3006 /* The queue starts out with one item, but following a DIE reference
3007 may load a new CU, adding it to the end of the queue. */
3008 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
3010 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
3011 process_full_comp_unit (item
->per_cu
);
3013 item
->per_cu
->queued
= 0;
3014 next_item
= item
->next
;
3018 dwarf2_queue_tail
= NULL
;
3021 /* Free all allocated queue entries. This function only releases anything if
3022 an error was thrown; if the queue was processed then it would have been
3023 freed as we went along. */
3026 dwarf2_release_queue (void *dummy
)
3028 struct dwarf2_queue_item
*item
, *last
;
3030 item
= dwarf2_queue
;
3033 /* Anything still marked queued is likely to be in an
3034 inconsistent state, so discard it. */
3035 if (item
->per_cu
->queued
)
3037 if (item
->per_cu
->cu
!= NULL
)
3038 free_one_cached_comp_unit (item
->per_cu
->cu
);
3039 item
->per_cu
->queued
= 0;
3047 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
3050 /* Read in full symbols for PST, and anything it depends on. */
3053 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
3055 struct dwarf2_per_cu_data
*per_cu
;
3056 struct cleanup
*back_to
;
3059 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
3060 if (!pst
->dependencies
[i
]->readin
)
3062 /* Inform about additional files that need to be read in. */
3065 /* FIXME: i18n: Need to make this a single string. */
3066 fputs_filtered (" ", gdb_stdout
);
3068 fputs_filtered ("and ", gdb_stdout
);
3070 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
3071 wrap_here (""); /* Flush output */
3072 gdb_flush (gdb_stdout
);
3074 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
3077 per_cu
= pst
->read_symtab_private
;
3081 /* It's an include file, no symbols to read for it.
3082 Everything is in the parent symtab. */
3087 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
3089 queue_comp_unit (per_cu
, pst
->objfile
);
3091 if (per_cu
->from_debug_types
)
3092 read_signatured_type_at_offset (pst
->objfile
, per_cu
->offset
);
3094 load_full_comp_unit (per_cu
, pst
->objfile
);
3096 process_queue (pst
->objfile
);
3098 /* Age the cache, releasing compilation units that have not
3099 been used recently. */
3100 age_cached_comp_units ();
3102 do_cleanups (back_to
);
3105 /* Load the DIEs associated with PER_CU into memory. */
3108 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
3110 bfd
*abfd
= objfile
->obfd
;
3111 struct dwarf2_cu
*cu
;
3112 unsigned int offset
;
3113 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
3114 struct cleanup
*back_to
, *free_cu_cleanup
;
3115 struct attribute
*attr
;
3118 gdb_assert (! per_cu
->from_debug_types
);
3120 /* Set local variables from the partial symbol table info. */
3121 offset
= per_cu
->offset
;
3123 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
3124 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
3125 beg_of_comp_unit
= info_ptr
;
3127 cu
= alloc_one_comp_unit (objfile
);
3129 /* If an error occurs while loading, release our storage. */
3130 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
3132 /* Read in the comp_unit header. */
3133 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
3135 /* Complete the cu_header. */
3136 cu
->header
.offset
= offset
;
3137 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
3139 /* Read the abbrevs for this compilation unit. */
3140 dwarf2_read_abbrevs (abfd
, cu
);
3141 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
3143 /* Link this compilation unit into the compilation unit tree. */
3145 cu
->per_cu
= per_cu
;
3146 cu
->type_hash
= per_cu
->type_hash
;
3148 cu
->dies
= read_comp_unit (info_ptr
, cu
);
3150 /* We try not to read any attributes in this function, because not
3151 all objfiles needed for references have been loaded yet, and symbol
3152 table processing isn't initialized. But we have to set the CU language,
3153 or we won't be able to build types correctly. */
3154 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
3156 set_cu_language (DW_UNSND (attr
), cu
);
3158 set_cu_language (language_minimal
, cu
);
3160 /* Link this CU into read_in_chain. */
3161 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
3162 dwarf2_per_objfile
->read_in_chain
= per_cu
;
3164 do_cleanups (back_to
);
3166 /* We've successfully allocated this compilation unit. Let our caller
3167 clean it up when finished with it. */
3168 discard_cleanups (free_cu_cleanup
);
3171 /* Generate full symbol information for PST and CU, whose DIEs have
3172 already been loaded into memory. */
3175 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
3177 struct partial_symtab
*pst
= per_cu
->psymtab
;
3178 struct dwarf2_cu
*cu
= per_cu
->cu
;
3179 struct objfile
*objfile
= pst
->objfile
;
3180 bfd
*abfd
= objfile
->obfd
;
3181 CORE_ADDR lowpc
, highpc
;
3182 struct symtab
*symtab
;
3183 struct cleanup
*back_to
;
3186 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3189 back_to
= make_cleanup (really_free_pendings
, NULL
);
3191 cu
->list_in_scope
= &file_symbols
;
3193 dwarf2_find_base_address (cu
->dies
, cu
);
3195 /* Do line number decoding in read_file_scope () */
3196 process_die (cu
->dies
, cu
);
3198 /* Some compilers don't define a DW_AT_high_pc attribute for the
3199 compilation unit. If the DW_AT_high_pc is missing, synthesize
3200 it, by scanning the DIE's below the compilation unit. */
3201 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
3203 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
3205 /* Set symtab language to language from DW_AT_language.
3206 If the compilation is from a C file generated by language preprocessors,
3207 do not set the language if it was already deduced by start_subfile. */
3209 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
3211 symtab
->language
= cu
->language
;
3213 pst
->symtab
= symtab
;
3216 do_cleanups (back_to
);
3219 /* Process a die and its children. */
3222 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
3226 case DW_TAG_padding
:
3228 case DW_TAG_compile_unit
:
3229 read_file_scope (die
, cu
);
3231 case DW_TAG_type_unit
:
3232 read_type_unit_scope (die
, cu
);
3234 case DW_TAG_subprogram
:
3235 case DW_TAG_inlined_subroutine
:
3236 read_func_scope (die
, cu
);
3238 case DW_TAG_lexical_block
:
3239 case DW_TAG_try_block
:
3240 case DW_TAG_catch_block
:
3241 read_lexical_block_scope (die
, cu
);
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 process_structure_scope (die
, cu
);
3249 case DW_TAG_enumeration_type
:
3250 process_enumeration_scope (die
, cu
);
3253 /* These dies have a type, but processing them does not create
3254 a symbol or recurse to process the children. Therefore we can
3255 read them on-demand through read_type_die. */
3256 case DW_TAG_subroutine_type
:
3257 case DW_TAG_set_type
:
3258 case DW_TAG_array_type
:
3259 case DW_TAG_pointer_type
:
3260 case DW_TAG_ptr_to_member_type
:
3261 case DW_TAG_reference_type
:
3262 case DW_TAG_string_type
:
3265 case DW_TAG_base_type
:
3266 case DW_TAG_subrange_type
:
3267 case DW_TAG_typedef
:
3268 /* Add a typedef symbol for the type definition, if it has a
3270 new_symbol (die
, read_type_die (die
, cu
), cu
);
3272 case DW_TAG_common_block
:
3273 read_common_block (die
, cu
);
3275 case DW_TAG_common_inclusion
:
3277 case DW_TAG_namespace
:
3278 processing_has_namespace_info
= 1;
3279 read_namespace (die
, cu
);
3282 read_module (die
, cu
);
3284 case DW_TAG_imported_declaration
:
3285 case DW_TAG_imported_module
:
3286 processing_has_namespace_info
= 1;
3287 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
3288 || cu
->language
!= language_fortran
))
3289 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
3290 dwarf_tag_name (die
->tag
));
3291 read_import_statement (die
, cu
);
3294 new_symbol (die
, NULL
, cu
);
3299 /* A helper function for dwarf2_compute_name which determines whether DIE
3300 needs to have the name of the scope prepended to the name listed in the
3304 die_needs_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
3308 case DW_TAG_namespace
:
3309 case DW_TAG_typedef
:
3310 case DW_TAG_class_type
:
3311 case DW_TAG_interface_type
:
3312 case DW_TAG_structure_type
:
3313 case DW_TAG_union_type
:
3314 case DW_TAG_enumeration_type
:
3315 case DW_TAG_enumerator
:
3316 case DW_TAG_subprogram
:
3320 case DW_TAG_variable
:
3321 /* We only need to prefix "globally" visible variables. These include
3322 any variable marked with DW_AT_external or any variable that
3323 lives in a namespace. [Variables in anonymous namespaces
3324 require prefixing, but they are not DW_AT_external.] */
3326 if (dwarf2_attr (die
, DW_AT_specification
, cu
))
3328 struct dwarf2_cu
*spec_cu
= cu
;
3329 return die_needs_namespace (die_specification (die
, &spec_cu
),
3333 if (dwarf2_attr (die
, DW_AT_external
, cu
)
3334 || die
->parent
->tag
== DW_TAG_namespace
)
3344 /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero,
3345 compute the physname for the object, which include a method's
3346 formal parameters (C++/Java) and return type (Java).
3348 For Ada, return the DIE's linkage name rather than the fully qualified
3349 name. PHYSNAME is ignored..
3351 The result is allocated on the objfile_obstack and canonicalized. */
3354 dwarf2_compute_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
,
3358 name
= dwarf2_name (die
, cu
);
3360 /* These are the only languages we know how to qualify names in. */
3362 && (cu
->language
== language_cplus
|| cu
->language
== language_java
))
3364 if (die_needs_namespace (die
, cu
))
3368 struct ui_file
*buf
;
3370 prefix
= determine_prefix (die
, cu
);
3371 buf
= mem_fileopen ();
3372 if (*prefix
!= '\0')
3374 char *prefixed_name
= typename_concat (NULL
, prefix
, name
, cu
);
3375 fputs_unfiltered (prefixed_name
, buf
);
3376 xfree (prefixed_name
);
3379 fputs_unfiltered (name
? name
: "", buf
);
3381 /* For Java and C++ methods, append formal parameter type
3382 information, if PHYSNAME. */
3384 if (physname
&& die
->tag
== DW_TAG_subprogram
3385 && (cu
->language
== language_cplus
3386 || cu
->language
== language_java
))
3388 struct type
*type
= read_type_die (die
, cu
);
3390 c_type_print_args (type
, buf
, 0, cu
->language
);
3392 if (cu
->language
== language_java
)
3394 /* For java, we must append the return type to method
3396 if (die
->tag
== DW_TAG_subprogram
)
3397 java_print_type (TYPE_TARGET_TYPE (type
), "", buf
,
3400 else if (cu
->language
== language_cplus
)
3402 if (TYPE_NFIELDS (type
) > 0
3403 && TYPE_FIELD_ARTIFICIAL (type
, 0)
3404 && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type
, 0))))
3405 fputs_unfiltered (" const", buf
);
3409 name
= ui_file_obsavestring (buf
, &cu
->objfile
->objfile_obstack
,
3411 ui_file_delete (buf
);
3413 if (cu
->language
== language_cplus
)
3416 = dwarf2_canonicalize_name (name
, cu
,
3417 &cu
->objfile
->objfile_obstack
);
3423 else if (cu
->language
== language_ada
)
3425 /* For Ada unit, we prefer the linkage name over the name, as
3426 the former contains the exported name, which the user expects
3427 to be able to reference. Ideally, we want the user to be able
3428 to reference this entity using either natural or linkage name,
3429 but we haven't started looking at this enhancement yet. */
3430 struct attribute
*attr
;
3432 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
3433 if (attr
&& DW_STRING (attr
))
3434 name
= DW_STRING (attr
);
3440 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3441 If scope qualifiers are appropriate they will be added. The result
3442 will be allocated on the objfile_obstack, or NULL if the DIE does
3443 not have a name. NAME may either be from a previous call to
3444 dwarf2_name or NULL.
3446 The output string will be canonicalized (if C++/Java). */
3449 dwarf2_full_name (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3451 return dwarf2_compute_name (name
, die
, cu
, 0);
3454 /* Construct a physname for the given DIE in CU. NAME may either be
3455 from a previous call to dwarf2_name or NULL. The result will be
3456 allocated on the objfile_objstack or NULL if the DIE does not have a
3459 The output string will be canonicalized (if C++/Java). */
3462 dwarf2_physname (char *name
, struct die_info
*die
, struct dwarf2_cu
*cu
)
3464 return dwarf2_compute_name (name
, die
, cu
, 1);
3467 /* Read the import statement specified by the given die and record it. */
3470 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3472 struct attribute
*import_attr
;
3473 struct die_info
*imported_die
;
3474 struct dwarf2_cu
*imported_cu
;
3475 const char *imported_name
;
3476 const char *imported_name_prefix
;
3479 const char *import_prefix
;
3480 char *canonical_name
;
3482 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3483 if (import_attr
== NULL
)
3485 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3486 dwarf_tag_name (die
->tag
));
3491 imported_die
= follow_die_ref_or_sig (die
, import_attr
, &imported_cu
);
3492 imported_name
= dwarf2_name (imported_die
, imported_cu
);
3493 if (imported_name
== NULL
)
3495 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3497 The import in the following code:
3511 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3512 <52> DW_AT_decl_file : 1
3513 <53> DW_AT_decl_line : 6
3514 <54> DW_AT_import : <0x75>
3515 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3517 <5b> DW_AT_decl_file : 1
3518 <5c> DW_AT_decl_line : 2
3519 <5d> DW_AT_type : <0x6e>
3521 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3522 <76> DW_AT_byte_size : 4
3523 <77> DW_AT_encoding : 5 (signed)
3525 imports the wrong die ( 0x75 instead of 0x58 ).
3526 This case will be ignored until the gcc bug is fixed. */
3530 /* Figure out the local name after import. */
3531 import_alias
= dwarf2_name (die
, cu
);
3533 /* Figure out where the statement is being imported to. */
3534 import_prefix
= determine_prefix (die
, cu
);
3536 /* Figure out what the scope of the imported die is and prepend it
3537 to the name of the imported die. */
3538 imported_name_prefix
= determine_prefix (imported_die
, imported_cu
);
3540 if (strlen (imported_name_prefix
) > 0)
3542 canonical_name
= alloca (strlen (imported_name_prefix
)
3543 + 2 + strlen (imported_name
) + 1);
3544 strcpy (canonical_name
, imported_name_prefix
);
3545 strcat (canonical_name
, "::");
3546 strcat (canonical_name
, imported_name
);
3550 canonical_name
= alloca (strlen (imported_name
) + 1);
3551 strcpy (canonical_name
, imported_name
);
3554 cp_add_using_directive (import_prefix
,
3557 &cu
->objfile
->objfile_obstack
);
3561 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3563 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3567 free_cu_line_header (void *arg
)
3569 struct dwarf2_cu
*cu
= arg
;
3571 free_line_header (cu
->line_header
);
3572 cu
->line_header
= NULL
;
3576 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3578 struct objfile
*objfile
= cu
->objfile
;
3579 struct comp_unit_head
*cu_header
= &cu
->header
;
3580 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3581 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3582 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3583 struct attribute
*attr
;
3585 char *comp_dir
= NULL
;
3586 struct die_info
*child_die
;
3587 bfd
*abfd
= objfile
->obfd
;
3588 struct line_header
*line_header
= 0;
3591 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3593 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3595 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3596 from finish_block. */
3597 if (lowpc
== ((CORE_ADDR
) -1))
3602 /* Find the filename. Do not use dwarf2_name here, since the filename
3603 is not a source language identifier. */
3604 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3607 name
= DW_STRING (attr
);
3610 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3612 comp_dir
= DW_STRING (attr
);
3613 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3615 comp_dir
= ldirname (name
);
3616 if (comp_dir
!= NULL
)
3617 make_cleanup (xfree
, comp_dir
);
3619 if (comp_dir
!= NULL
)
3621 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3622 directory, get rid of it. */
3623 char *cp
= strchr (comp_dir
, ':');
3625 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3632 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3635 set_cu_language (DW_UNSND (attr
), cu
);
3638 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3640 cu
->producer
= DW_STRING (attr
);
3642 /* We assume that we're processing GCC output. */
3643 processing_gcc_compilation
= 2;
3645 processing_has_namespace_info
= 0;
3647 start_symtab (name
, comp_dir
, lowpc
);
3648 record_debugformat ("DWARF 2");
3649 record_producer (cu
->producer
);
3651 initialize_cu_func_list (cu
);
3653 /* Decode line number information if present. We do this before
3654 processing child DIEs, so that the line header table is available
3655 for DW_AT_decl_file. */
3656 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3659 unsigned int line_offset
= DW_UNSND (attr
);
3660 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3663 cu
->line_header
= line_header
;
3664 make_cleanup (free_cu_line_header
, cu
);
3665 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3669 /* Process all dies in compilation unit. */
3670 if (die
->child
!= NULL
)
3672 child_die
= die
->child
;
3673 while (child_die
&& child_die
->tag
)
3675 process_die (child_die
, cu
);
3676 child_die
= sibling_die (child_die
);
3680 /* Decode macro information, if present. Dwarf 2 macro information
3681 refers to information in the line number info statement program
3682 header, so we can only read it if we've read the header
3684 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3685 if (attr
&& line_header
)
3687 unsigned int macro_offset
= DW_UNSND (attr
);
3688 dwarf_decode_macros (line_header
, macro_offset
,
3689 comp_dir
, abfd
, cu
);
3691 do_cleanups (back_to
);
3694 /* For TUs we want to skip the first top level sibling if it's not the
3695 actual type being defined by this TU. In this case the first top
3696 level sibling is there to provide context only. */
3699 read_type_unit_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3701 struct objfile
*objfile
= cu
->objfile
;
3702 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3704 struct attribute
*attr
;
3706 char *comp_dir
= NULL
;
3707 struct die_info
*child_die
;
3708 bfd
*abfd
= objfile
->obfd
;
3709 struct line_header
*line_header
= 0;
3711 /* start_symtab needs a low pc, but we don't really have one.
3712 Do what read_file_scope would do in the absence of such info. */
3713 lowpc
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3715 /* Find the filename. Do not use dwarf2_name here, since the filename
3716 is not a source language identifier. */
3717 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3719 name
= DW_STRING (attr
);
3721 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3723 comp_dir
= DW_STRING (attr
);
3724 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3726 comp_dir
= ldirname (name
);
3727 if (comp_dir
!= NULL
)
3728 make_cleanup (xfree
, comp_dir
);
3734 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3736 set_cu_language (DW_UNSND (attr
), cu
);
3738 /* This isn't technically needed today. It is done for symmetry
3739 with read_file_scope. */
3740 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3742 cu
->producer
= DW_STRING (attr
);
3744 /* We assume that we're processing GCC output. */
3745 processing_gcc_compilation
= 2;
3747 processing_has_namespace_info
= 0;
3749 start_symtab (name
, comp_dir
, lowpc
);
3750 record_debugformat ("DWARF 2");
3751 record_producer (cu
->producer
);
3753 /* Process the dies in the type unit. */
3754 if (die
->child
== NULL
)
3756 dump_die_for_error (die
);
3757 error (_("Dwarf Error: Missing children for type unit [in module %s]"),
3758 bfd_get_filename (abfd
));
3761 child_die
= die
->child
;
3763 while (child_die
&& child_die
->tag
)
3765 process_die (child_die
, cu
);
3767 child_die
= sibling_die (child_die
);
3770 do_cleanups (back_to
);
3774 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3775 struct dwarf2_cu
*cu
)
3777 struct function_range
*thisfn
;
3779 thisfn
= (struct function_range
*)
3780 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3781 thisfn
->name
= name
;
3782 thisfn
->lowpc
= lowpc
;
3783 thisfn
->highpc
= highpc
;
3784 thisfn
->seen_line
= 0;
3785 thisfn
->next
= NULL
;
3787 if (cu
->last_fn
== NULL
)
3788 cu
->first_fn
= thisfn
;
3790 cu
->last_fn
->next
= thisfn
;
3792 cu
->last_fn
= thisfn
;
3795 /* qsort helper for inherit_abstract_dies. */
3798 unsigned_int_compar (const void *ap
, const void *bp
)
3800 unsigned int a
= *(unsigned int *) ap
;
3801 unsigned int b
= *(unsigned int *) bp
;
3803 return (a
> b
) - (b
> a
);
3806 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3807 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3808 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3811 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3813 struct die_info
*child_die
;
3814 unsigned die_children_count
;
3815 /* CU offsets which were referenced by children of the current DIE. */
3817 unsigned *offsets_end
, *offsetp
;
3818 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3819 struct die_info
*origin_die
;
3820 /* Iterator of the ORIGIN_DIE children. */
3821 struct die_info
*origin_child_die
;
3822 struct cleanup
*cleanups
;
3823 struct attribute
*attr
;
3825 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3829 origin_die
= follow_die_ref (die
, attr
, &cu
);
3830 if (die
->tag
!= origin_die
->tag
3831 && !(die
->tag
== DW_TAG_inlined_subroutine
3832 && origin_die
->tag
== DW_TAG_subprogram
))
3833 complaint (&symfile_complaints
,
3834 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3835 die
->offset
, origin_die
->offset
);
3837 child_die
= die
->child
;
3838 die_children_count
= 0;
3839 while (child_die
&& child_die
->tag
)
3841 child_die
= sibling_die (child_die
);
3842 die_children_count
++;
3844 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3845 cleanups
= make_cleanup (xfree
, offsets
);
3847 offsets_end
= offsets
;
3848 child_die
= die
->child
;
3849 while (child_die
&& child_die
->tag
)
3851 /* For each CHILD_DIE, find the corresponding child of
3852 ORIGIN_DIE. If there is more than one layer of
3853 DW_AT_abstract_origin, follow them all; there shouldn't be,
3854 but GCC versions at least through 4.4 generate this (GCC PR
3856 struct die_info
*child_origin_die
= child_die
;
3859 attr
= dwarf2_attr (child_origin_die
, DW_AT_abstract_origin
, cu
);
3862 child_origin_die
= follow_die_ref (child_origin_die
, attr
, &cu
);
3865 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3866 counterpart may exist. */
3867 if (child_origin_die
!= child_die
)
3869 if (child_die
->tag
!= child_origin_die
->tag
3870 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3871 && child_origin_die
->tag
== DW_TAG_subprogram
))
3872 complaint (&symfile_complaints
,
3873 _("Child DIE 0x%x and its abstract origin 0x%x have "
3874 "different tags"), child_die
->offset
,
3875 child_origin_die
->offset
);
3876 if (child_origin_die
->parent
!= origin_die
)
3877 complaint (&symfile_complaints
,
3878 _("Child DIE 0x%x and its abstract origin 0x%x have "
3879 "different parents"), child_die
->offset
,
3880 child_origin_die
->offset
);
3882 *offsets_end
++ = child_origin_die
->offset
;
3884 child_die
= sibling_die (child_die
);
3886 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3887 unsigned_int_compar
);
3888 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3889 if (offsetp
[-1] == *offsetp
)
3890 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3891 "to DIE 0x%x as their abstract origin"),
3892 die
->offset
, *offsetp
);
3895 origin_child_die
= origin_die
->child
;
3896 while (origin_child_die
&& origin_child_die
->tag
)
3898 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3899 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3901 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3903 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3904 process_die (origin_child_die
, cu
);
3906 origin_child_die
= sibling_die (origin_child_die
);
3909 do_cleanups (cleanups
);
3913 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3915 struct objfile
*objfile
= cu
->objfile
;
3916 struct context_stack
*new;
3919 struct die_info
*child_die
;
3920 struct attribute
*attr
, *call_line
, *call_file
;
3923 struct block
*block
;
3924 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3928 /* If we do not have call site information, we can't show the
3929 caller of this inlined function. That's too confusing, so
3930 only use the scope for local variables. */
3931 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3932 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3933 if (call_line
== NULL
|| call_file
== NULL
)
3935 read_lexical_block_scope (die
, cu
);
3940 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3942 name
= dwarf2_name (die
, cu
);
3944 /* Ignore functions with missing or empty names and functions with
3945 missing or invalid low and high pc attributes. */
3946 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
3952 /* Record the function range for dwarf_decode_lines. */
3953 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3955 new = push_context (0, lowpc
);
3956 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3958 /* If there is a location expression for DW_AT_frame_base, record
3960 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3962 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3963 expression is being recorded directly in the function's symbol
3964 and not in a separate frame-base object. I guess this hack is
3965 to avoid adding some sort of frame-base adjunct/annex to the
3966 function's symbol :-(. The problem with doing this is that it
3967 results in a function symbol with a location expression that
3968 has nothing to do with the location of the function, ouch! The
3969 relationship should be: a function's symbol has-a frame base; a
3970 frame-base has-a location expression. */
3971 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3973 cu
->list_in_scope
= &local_symbols
;
3975 if (die
->child
!= NULL
)
3977 child_die
= die
->child
;
3978 while (child_die
&& child_die
->tag
)
3980 process_die (child_die
, cu
);
3981 child_die
= sibling_die (child_die
);
3985 inherit_abstract_dies (die
, cu
);
3987 new = pop_context ();
3988 /* Make a block for the local symbols within. */
3989 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3990 lowpc
, highpc
, objfile
);
3992 /* For C++, set the block's scope. */
3993 if (cu
->language
== language_cplus
)
3994 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3995 determine_prefix (die
, cu
),
3996 processing_has_namespace_info
);
3998 /* If we have address ranges, record them. */
3999 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
4001 /* In C++, we can have functions nested inside functions (e.g., when
4002 a function declares a class that has methods). This means that
4003 when we finish processing a function scope, we may need to go
4004 back to building a containing block's symbol lists. */
4005 local_symbols
= new->locals
;
4006 param_symbols
= new->params
;
4007 using_directives
= new->using_directives
;
4009 /* If we've finished processing a top-level function, subsequent
4010 symbols go in the file symbol list. */
4011 if (outermost_context_p ())
4012 cu
->list_in_scope
= &file_symbols
;
4015 /* Process all the DIES contained within a lexical block scope. Start
4016 a new scope, process the dies, and then close the scope. */
4019 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4021 struct objfile
*objfile
= cu
->objfile
;
4022 struct context_stack
*new;
4023 CORE_ADDR lowpc
, highpc
;
4024 struct die_info
*child_die
;
4027 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4029 /* Ignore blocks with missing or invalid low and high pc attributes. */
4030 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
4031 as multiple lexical blocks? Handling children in a sane way would
4032 be nasty. Might be easier to properly extend generic blocks to
4034 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
, NULL
))
4039 push_context (0, lowpc
);
4040 if (die
->child
!= NULL
)
4042 child_die
= die
->child
;
4043 while (child_die
&& child_die
->tag
)
4045 process_die (child_die
, cu
);
4046 child_die
= sibling_die (child_die
);
4049 new = pop_context ();
4051 if (local_symbols
!= NULL
|| using_directives
!= NULL
)
4054 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
4057 /* Note that recording ranges after traversing children, as we
4058 do here, means that recording a parent's ranges entails
4059 walking across all its children's ranges as they appear in
4060 the address map, which is quadratic behavior.
4062 It would be nicer to record the parent's ranges before
4063 traversing its children, simply overriding whatever you find
4064 there. But since we don't even decide whether to create a
4065 block until after we've traversed its children, that's hard
4067 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
4069 local_symbols
= new->locals
;
4070 using_directives
= new->using_directives
;
4073 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
4074 Return 1 if the attributes are present and valid, otherwise, return 0.
4075 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
4078 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
4079 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
4080 struct partial_symtab
*ranges_pst
)
4082 struct objfile
*objfile
= cu
->objfile
;
4083 struct comp_unit_head
*cu_header
= &cu
->header
;
4084 bfd
*obfd
= objfile
->obfd
;
4085 unsigned int addr_size
= cu_header
->addr_size
;
4086 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4087 /* Base address selection entry. */
4098 found_base
= cu
->base_known
;
4099 base
= cu
->base_address
;
4101 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
4102 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4104 complaint (&symfile_complaints
,
4105 _("Offset %d out of bounds for DW_AT_ranges attribute"),
4109 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4111 /* Read in the largest possible address. */
4112 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
4113 if ((marker
& mask
) == mask
)
4115 /* If we found the largest possible address, then
4116 read the base address. */
4117 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4118 buffer
+= 2 * addr_size
;
4119 offset
+= 2 * addr_size
;
4125 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
4129 CORE_ADDR range_beginning
, range_end
;
4131 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
4132 buffer
+= addr_size
;
4133 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
4134 buffer
+= addr_size
;
4135 offset
+= 2 * addr_size
;
4137 /* An end of list marker is a pair of zero addresses. */
4138 if (range_beginning
== 0 && range_end
== 0)
4139 /* Found the end of list entry. */
4142 /* Each base address selection entry is a pair of 2 values.
4143 The first is the largest possible address, the second is
4144 the base address. Check for a base address here. */
4145 if ((range_beginning
& mask
) == mask
)
4147 /* If we found the largest possible address, then
4148 read the base address. */
4149 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
4156 /* We have no valid base address for the ranges
4158 complaint (&symfile_complaints
,
4159 _("Invalid .debug_ranges data (no base address)"));
4163 range_beginning
+= base
;
4166 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
4167 addrmap_set_empty (objfile
->psymtabs_addrmap
,
4168 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
4171 /* FIXME: This is recording everything as a low-high
4172 segment of consecutive addresses. We should have a
4173 data structure for discontiguous block ranges
4177 low
= range_beginning
;
4183 if (range_beginning
< low
)
4184 low
= range_beginning
;
4185 if (range_end
> high
)
4191 /* If the first entry is an end-of-list marker, the range
4192 describes an empty scope, i.e. no instructions. */
4198 *high_return
= high
;
4202 /* Get low and high pc attributes from a die. Return 1 if the attributes
4203 are present and valid, otherwise, return 0. Return -1 if the range is
4204 discontinuous, i.e. derived from DW_AT_ranges information. */
4206 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
4207 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
,
4208 struct partial_symtab
*pst
)
4210 struct attribute
*attr
;
4215 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
4218 high
= DW_ADDR (attr
);
4219 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4221 low
= DW_ADDR (attr
);
4223 /* Found high w/o low attribute. */
4226 /* Found consecutive range of addresses. */
4231 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4234 /* Value of the DW_AT_ranges attribute is the offset in the
4235 .debug_ranges section. */
4236 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, pst
))
4238 /* Found discontinuous range of addresses. */
4246 /* When using the GNU linker, .gnu.linkonce. sections are used to
4247 eliminate duplicate copies of functions and vtables and such.
4248 The linker will arbitrarily choose one and discard the others.
4249 The AT_*_pc values for such functions refer to local labels in
4250 these sections. If the section from that file was discarded, the
4251 labels are not in the output, so the relocs get a value of 0.
4252 If this is a discarded function, mark the pc bounds as invalid,
4253 so that GDB will ignore it. */
4254 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
4262 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
4263 its low and high PC addresses. Do nothing if these addresses could not
4264 be determined. Otherwise, set LOWPC to the low address if it is smaller,
4265 and HIGHPC to the high address if greater than HIGHPC. */
4268 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
4269 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4270 struct dwarf2_cu
*cu
)
4272 CORE_ADDR low
, high
;
4273 struct die_info
*child
= die
->child
;
4275 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
, NULL
))
4277 *lowpc
= min (*lowpc
, low
);
4278 *highpc
= max (*highpc
, high
);
4281 /* If the language does not allow nested subprograms (either inside
4282 subprograms or lexical blocks), we're done. */
4283 if (cu
->language
!= language_ada
)
4286 /* Check all the children of the given DIE. If it contains nested
4287 subprograms, then check their pc bounds. Likewise, we need to
4288 check lexical blocks as well, as they may also contain subprogram
4290 while (child
&& child
->tag
)
4292 if (child
->tag
== DW_TAG_subprogram
4293 || child
->tag
== DW_TAG_lexical_block
)
4294 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
4295 child
= sibling_die (child
);
4299 /* Get the low and high pc's represented by the scope DIE, and store
4300 them in *LOWPC and *HIGHPC. If the correct values can't be
4301 determined, set *LOWPC to -1 and *HIGHPC to 0. */
4304 get_scope_pc_bounds (struct die_info
*die
,
4305 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
4306 struct dwarf2_cu
*cu
)
4308 CORE_ADDR best_low
= (CORE_ADDR
) -1;
4309 CORE_ADDR best_high
= (CORE_ADDR
) 0;
4310 CORE_ADDR current_low
, current_high
;
4312 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
, NULL
))
4314 best_low
= current_low
;
4315 best_high
= current_high
;
4319 struct die_info
*child
= die
->child
;
4321 while (child
&& child
->tag
)
4323 switch (child
->tag
) {
4324 case DW_TAG_subprogram
:
4325 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
4327 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
);
4369 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
4372 CORE_ADDR low
= DW_ADDR (attr
);
4373 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
4377 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
4380 bfd
*obfd
= cu
->objfile
->obfd
;
4382 /* The value of the DW_AT_ranges attribute is the offset of the
4383 address range list in the .debug_ranges section. */
4384 unsigned long offset
= DW_UNSND (attr
);
4385 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
4387 /* For some target architectures, but not others, the
4388 read_address function sign-extends the addresses it returns.
4389 To recognize base address selection entries, we need a
4391 unsigned int addr_size
= cu
->header
.addr_size
;
4392 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
4394 /* The base address, to which the next pair is relative. Note
4395 that this 'base' is a DWARF concept: most entries in a range
4396 list are relative, to reduce the number of relocs against the
4397 debugging information. This is separate from this function's
4398 'baseaddr' argument, which GDB uses to relocate debugging
4399 information from a shared library based on the address at
4400 which the library was loaded. */
4401 CORE_ADDR base
= cu
->base_address
;
4402 int base_known
= cu
->base_known
;
4404 gdb_assert (dwarf2_per_objfile
->ranges
.readin
);
4405 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
4407 complaint (&symfile_complaints
,
4408 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
4415 unsigned int bytes_read
;
4416 CORE_ADDR start
, end
;
4418 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4419 buffer
+= bytes_read
;
4420 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
4421 buffer
+= bytes_read
;
4423 /* Did we find the end of the range list? */
4424 if (start
== 0 && end
== 0)
4427 /* Did we find a base address selection entry? */
4428 else if ((start
& base_select_mask
) == base_select_mask
)
4434 /* We found an ordinary address range. */
4439 complaint (&symfile_complaints
,
4440 _("Invalid .debug_ranges data (no base address)"));
4444 record_block_range (block
,
4445 baseaddr
+ base
+ start
,
4446 baseaddr
+ base
+ end
- 1);
4452 /* Add an aggregate field to the field list. */
4455 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
4456 struct dwarf2_cu
*cu
)
4458 struct objfile
*objfile
= cu
->objfile
;
4459 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4460 struct nextfield
*new_field
;
4461 struct attribute
*attr
;
4463 char *fieldname
= "";
4465 /* Allocate a new field list entry and link it in. */
4466 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
4467 make_cleanup (xfree
, new_field
);
4468 memset (new_field
, 0, sizeof (struct nextfield
));
4470 if (die
->tag
== DW_TAG_inheritance
)
4472 new_field
->next
= fip
->baseclasses
;
4473 fip
->baseclasses
= new_field
;
4477 new_field
->next
= fip
->fields
;
4478 fip
->fields
= new_field
;
4482 /* Handle accessibility and virtuality of field.
4483 The default accessibility for members is public, the default
4484 accessibility for inheritance is private. */
4485 if (die
->tag
!= DW_TAG_inheritance
)
4486 new_field
->accessibility
= DW_ACCESS_public
;
4488 new_field
->accessibility
= DW_ACCESS_private
;
4489 new_field
->virtuality
= DW_VIRTUALITY_none
;
4491 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4493 new_field
->accessibility
= DW_UNSND (attr
);
4494 if (new_field
->accessibility
!= DW_ACCESS_public
)
4495 fip
->non_public_fields
= 1;
4496 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4498 new_field
->virtuality
= DW_UNSND (attr
);
4500 fp
= &new_field
->field
;
4502 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
4504 /* Data member other than a C++ static data member. */
4506 /* Get type of field. */
4507 fp
->type
= die_type (die
, cu
);
4509 SET_FIELD_BITPOS (*fp
, 0);
4511 /* Get bit size of field (zero if none). */
4512 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
4515 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
4519 FIELD_BITSIZE (*fp
) = 0;
4522 /* Get bit offset of field. */
4523 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4526 int byte_offset
= 0;
4528 if (attr_form_is_section_offset (attr
))
4529 dwarf2_complex_location_expr_complaint ();
4530 else if (attr_form_is_constant (attr
))
4531 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4532 else if (attr_form_is_block (attr
))
4533 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4535 dwarf2_complex_location_expr_complaint ();
4537 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4539 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
4542 if (gdbarch_bits_big_endian (gdbarch
))
4544 /* For big endian bits, the DW_AT_bit_offset gives the
4545 additional bit offset from the MSB of the containing
4546 anonymous object to the MSB of the field. We don't
4547 have to do anything special since we don't need to
4548 know the size of the anonymous object. */
4549 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
4553 /* For little endian bits, compute the bit offset to the
4554 MSB of the anonymous object, subtract off the number of
4555 bits from the MSB of the field to the MSB of the
4556 object, and then subtract off the number of bits of
4557 the field itself. The result is the bit offset of
4558 the LSB of the field. */
4560 int bit_offset
= DW_UNSND (attr
);
4562 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4565 /* The size of the anonymous object containing
4566 the bit field is explicit, so use the
4567 indicated size (in bytes). */
4568 anonymous_size
= DW_UNSND (attr
);
4572 /* The size of the anonymous object containing
4573 the bit field must be inferred from the type
4574 attribute of the data member containing the
4576 anonymous_size
= TYPE_LENGTH (fp
->type
);
4578 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4579 - bit_offset
- FIELD_BITSIZE (*fp
);
4583 /* Get name of field. */
4584 fieldname
= dwarf2_name (die
, cu
);
4585 if (fieldname
== NULL
)
4588 /* The name is already allocated along with this objfile, so we don't
4589 need to duplicate it for the type. */
4590 fp
->name
= fieldname
;
4592 /* Change accessibility for artificial fields (e.g. virtual table
4593 pointer or virtual base class pointer) to private. */
4594 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4596 FIELD_ARTIFICIAL (*fp
) = 1;
4597 new_field
->accessibility
= DW_ACCESS_private
;
4598 fip
->non_public_fields
= 1;
4601 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4603 /* C++ static member. */
4605 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4606 is a declaration, but all versions of G++ as of this writing
4607 (so through at least 3.2.1) incorrectly generate
4608 DW_TAG_variable tags. */
4612 /* Get name of field. */
4613 fieldname
= dwarf2_name (die
, cu
);
4614 if (fieldname
== NULL
)
4617 /* Get physical name. */
4618 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4620 /* The name is already allocated along with this objfile, so we don't
4621 need to duplicate it for the type. */
4622 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4623 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4624 FIELD_NAME (*fp
) = fieldname
;
4626 else if (die
->tag
== DW_TAG_inheritance
)
4628 /* C++ base class field. */
4629 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4632 int byte_offset
= 0;
4634 if (attr_form_is_section_offset (attr
))
4635 dwarf2_complex_location_expr_complaint ();
4636 else if (attr_form_is_constant (attr
))
4637 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
4638 else if (attr_form_is_block (attr
))
4639 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
4641 dwarf2_complex_location_expr_complaint ();
4643 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
4645 FIELD_BITSIZE (*fp
) = 0;
4646 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4647 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4648 fip
->nbaseclasses
++;
4652 /* Create the vector of fields, and attach it to the type. */
4655 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4656 struct dwarf2_cu
*cu
)
4658 int nfields
= fip
->nfields
;
4660 /* Record the field count, allocate space for the array of fields,
4661 and create blank accessibility bitfields if necessary. */
4662 TYPE_NFIELDS (type
) = nfields
;
4663 TYPE_FIELDS (type
) = (struct field
*)
4664 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4665 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4667 if (fip
->non_public_fields
&& cu
->language
!= language_ada
)
4669 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4671 TYPE_FIELD_PRIVATE_BITS (type
) =
4672 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4673 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4675 TYPE_FIELD_PROTECTED_BITS (type
) =
4676 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4677 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4679 TYPE_FIELD_IGNORE_BITS (type
) =
4680 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4681 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4684 /* If the type has baseclasses, allocate and clear a bit vector for
4685 TYPE_FIELD_VIRTUAL_BITS. */
4686 if (fip
->nbaseclasses
&& cu
->language
!= language_ada
)
4688 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4689 unsigned char *pointer
;
4691 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4692 pointer
= TYPE_ALLOC (type
, num_bytes
);
4693 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4694 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4695 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4698 /* Copy the saved-up fields into the field vector. Start from the head
4699 of the list, adding to the tail of the field array, so that they end
4700 up in the same order in the array in which they were added to the list. */
4701 while (nfields
-- > 0)
4703 struct nextfield
*fieldp
;
4707 fieldp
= fip
->fields
;
4708 fip
->fields
= fieldp
->next
;
4712 fieldp
= fip
->baseclasses
;
4713 fip
->baseclasses
= fieldp
->next
;
4716 TYPE_FIELD (type
, nfields
) = fieldp
->field
;
4717 switch (fieldp
->accessibility
)
4719 case DW_ACCESS_private
:
4720 if (cu
->language
!= language_ada
)
4721 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4724 case DW_ACCESS_protected
:
4725 if (cu
->language
!= language_ada
)
4726 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4729 case DW_ACCESS_public
:
4733 /* Unknown accessibility. Complain and treat it as public. */
4735 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4736 fieldp
->accessibility
);
4740 if (nfields
< fip
->nbaseclasses
)
4742 switch (fieldp
->virtuality
)
4744 case DW_VIRTUALITY_virtual
:
4745 case DW_VIRTUALITY_pure_virtual
:
4746 if (cu
->language
== language_ada
)
4747 error ("unexpected virtuality in component of Ada type");
4748 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4755 /* Add a member function to the proper fieldlist. */
4758 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4759 struct type
*type
, struct dwarf2_cu
*cu
)
4761 struct objfile
*objfile
= cu
->objfile
;
4762 struct attribute
*attr
;
4763 struct fnfieldlist
*flp
;
4765 struct fn_field
*fnp
;
4768 struct nextfnfield
*new_fnfield
;
4769 struct type
*this_type
;
4771 if (cu
->language
== language_ada
)
4772 error ("unexpected member function in Ada type");
4774 /* Get name of member function. */
4775 fieldname
= dwarf2_name (die
, cu
);
4776 if (fieldname
== NULL
)
4779 /* Get the mangled name. */
4780 physname
= (char *) dwarf2_physname (fieldname
, die
, cu
);
4782 /* Look up member function name in fieldlist. */
4783 for (i
= 0; i
< fip
->nfnfields
; i
++)
4785 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4789 /* Create new list element if necessary. */
4790 if (i
< fip
->nfnfields
)
4791 flp
= &fip
->fnfieldlists
[i
];
4794 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4796 fip
->fnfieldlists
= (struct fnfieldlist
*)
4797 xrealloc (fip
->fnfieldlists
,
4798 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4799 * sizeof (struct fnfieldlist
));
4800 if (fip
->nfnfields
== 0)
4801 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4803 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4804 flp
->name
= fieldname
;
4810 /* Create a new member function field and chain it to the field list
4812 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4813 make_cleanup (xfree
, new_fnfield
);
4814 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4815 new_fnfield
->next
= flp
->head
;
4816 flp
->head
= new_fnfield
;
4819 /* Fill in the member function field info. */
4820 fnp
= &new_fnfield
->fnfield
;
4821 /* The name is already allocated along with this objfile, so we don't
4822 need to duplicate it for the type. */
4823 fnp
->physname
= physname
? physname
: "";
4824 fnp
->type
= alloc_type (objfile
);
4825 this_type
= read_type_die (die
, cu
);
4826 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4828 int nparams
= TYPE_NFIELDS (this_type
);
4830 /* TYPE is the domain of this method, and THIS_TYPE is the type
4831 of the method itself (TYPE_CODE_METHOD). */
4832 smash_to_method_type (fnp
->type
, type
,
4833 TYPE_TARGET_TYPE (this_type
),
4834 TYPE_FIELDS (this_type
),
4835 TYPE_NFIELDS (this_type
),
4836 TYPE_VARARGS (this_type
));
4838 /* Handle static member functions.
4839 Dwarf2 has no clean way to discern C++ static and non-static
4840 member functions. G++ helps GDB by marking the first
4841 parameter for non-static member functions (which is the
4842 this pointer) as artificial. We obtain this information
4843 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4844 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4845 fnp
->voffset
= VOFFSET_STATIC
;
4848 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4851 /* Get fcontext from DW_AT_containing_type if present. */
4852 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4853 fnp
->fcontext
= die_containing_type (die
, cu
);
4855 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4856 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4858 /* Get accessibility. */
4859 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4862 switch (DW_UNSND (attr
))
4864 case DW_ACCESS_private
:
4865 fnp
->is_private
= 1;
4867 case DW_ACCESS_protected
:
4868 fnp
->is_protected
= 1;
4873 /* Check for artificial methods. */
4874 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4875 if (attr
&& DW_UNSND (attr
) != 0)
4876 fnp
->is_artificial
= 1;
4878 /* Get index in virtual function table if it is a virtual member
4879 function. For GCC, this is an offset in the appropriate
4880 virtual table, as specified by DW_AT_containing_type. For
4881 everyone else, it is an expression to be evaluated relative
4882 to the object address. */
4884 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4885 if (attr
&& fnp
->fcontext
)
4887 /* Support the .debug_loc offsets */
4888 if (attr_form_is_block (attr
))
4890 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4892 else if (attr_form_is_section_offset (attr
))
4894 dwarf2_complex_location_expr_complaint ();
4898 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4904 /* We only support trivial expressions here. This hack will work
4905 for v3 classes, which always start with the vtable pointer. */
4906 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
> 0
4907 && DW_BLOCK (attr
)->data
[0] == DW_OP_deref
)
4909 struct dwarf_block blk
;
4910 blk
.size
= DW_BLOCK (attr
)->size
- 1;
4911 blk
.data
= DW_BLOCK (attr
)->data
+ 1;
4912 fnp
->voffset
= decode_locdesc (&blk
, cu
);
4913 if ((fnp
->voffset
% cu
->header
.addr_size
) != 0)
4914 dwarf2_complex_location_expr_complaint ();
4916 fnp
->voffset
/= cu
->header
.addr_size
;
4918 fnp
->fcontext
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type
, 0));
4921 dwarf2_complex_location_expr_complaint ();
4925 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
4926 if (attr
&& DW_UNSND (attr
))
4928 /* GCC does this, as of 2008-08-25; PR debug/37237. */
4929 complaint (&symfile_complaints
,
4930 _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"),
4931 fieldname
, die
->offset
);
4932 TYPE_CPLUS_DYNAMIC (type
) = 1;
4937 /* Create the vector of member function fields, and attach it to the type. */
4940 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4941 struct dwarf2_cu
*cu
)
4943 struct fnfieldlist
*flp
;
4944 int total_length
= 0;
4947 if (cu
->language
== language_ada
)
4948 error ("unexpected member functions in Ada type");
4950 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4951 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4952 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4954 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4956 struct nextfnfield
*nfp
= flp
->head
;
4957 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4960 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4961 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4962 fn_flp
->fn_fields
= (struct fn_field
*)
4963 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4964 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4965 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4967 total_length
+= flp
->length
;
4970 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4971 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4974 /* Returns non-zero if NAME is the name of a vtable member in CU's
4975 language, zero otherwise. */
4977 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4979 static const char vptr
[] = "_vptr";
4980 static const char vtable
[] = "vtable";
4982 /* Look for the C++ and Java forms of the vtable. */
4983 if ((cu
->language
== language_java
4984 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4985 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4986 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4992 /* GCC outputs unnamed structures that are really pointers to member
4993 functions, with the ABI-specified layout. If TYPE describes
4994 such a structure, smash it into a member function type.
4996 GCC shouldn't do this; it should just output pointer to member DIEs.
4997 This is GCC PR debug/28767. */
5000 quirk_gcc_member_function_pointer (struct type
*type
, struct objfile
*objfile
)
5002 struct type
*pfn_type
, *domain_type
, *new_type
;
5004 /* Check for a structure with no name and two children. */
5005 if (TYPE_CODE (type
) != TYPE_CODE_STRUCT
|| TYPE_NFIELDS (type
) != 2)
5008 /* Check for __pfn and __delta members. */
5009 if (TYPE_FIELD_NAME (type
, 0) == NULL
5010 || strcmp (TYPE_FIELD_NAME (type
, 0), "__pfn") != 0
5011 || TYPE_FIELD_NAME (type
, 1) == NULL
5012 || strcmp (TYPE_FIELD_NAME (type
, 1), "__delta") != 0)
5015 /* Find the type of the method. */
5016 pfn_type
= TYPE_FIELD_TYPE (type
, 0);
5017 if (pfn_type
== NULL
5018 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
5019 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
5022 /* Look for the "this" argument. */
5023 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
5024 if (TYPE_NFIELDS (pfn_type
) == 0
5025 /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */
5026 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
5029 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
5030 new_type
= alloc_type (objfile
);
5031 smash_to_method_type (new_type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
5032 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
5033 TYPE_VARARGS (pfn_type
));
5034 smash_to_methodptr_type (type
, new_type
);
5037 /* Called when we find the DIE that starts a structure or union scope
5038 (definition) to process all dies that define the members of the
5041 NOTE: we need to call struct_type regardless of whether or not the
5042 DIE has an at_name attribute, since it might be an anonymous
5043 structure or union. This gets the type entered into our set of
5046 However, if the structure is incomplete (an opaque struct/union)
5047 then suppress creating a symbol table entry for it since gdb only
5048 wants to find the one with the complete definition. Note that if
5049 it is complete, we just call new_symbol, which does it's own
5050 checking about whether the struct/union is anonymous or not (and
5051 suppresses creating a symbol table entry itself). */
5053 static struct type
*
5054 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5056 struct objfile
*objfile
= cu
->objfile
;
5058 struct attribute
*attr
;
5060 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
5062 /* If the definition of this type lives in .debug_types, read that type.
5063 Don't follow DW_AT_specification though, that will take us back up
5064 the chain and we want to go down. */
5065 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5068 struct dwarf2_cu
*type_cu
= cu
;
5069 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5070 /* We could just recurse on read_structure_type, but we need to call
5071 get_die_type to ensure only one type for this DIE is created.
5072 This is important, for example, because for c++ classes we need
5073 TYPE_NAME set which is only done by new_symbol. Blech. */
5074 type
= read_type_die (type_die
, type_cu
);
5075 return set_die_type (die
, type
, cu
);
5078 type
= alloc_type (objfile
);
5079 INIT_CPLUS_SPECIFIC (type
);
5081 name
= dwarf2_name (die
, cu
);
5084 if (cu
->language
== language_cplus
5085 || cu
->language
== language_java
)
5087 TYPE_TAG_NAME (type
) = (char *) dwarf2_full_name (name
, die
, cu
);
5088 if (die
->tag
== DW_TAG_structure_type
5089 || die
->tag
== DW_TAG_class_type
)
5090 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5094 /* The name is already allocated along with this objfile, so
5095 we don't need to duplicate it for the type. */
5096 TYPE_TAG_NAME (type
) = (char *) name
;
5097 if (die
->tag
== DW_TAG_class_type
)
5098 TYPE_NAME (type
) = TYPE_TAG_NAME (type
);
5102 if (die
->tag
== DW_TAG_structure_type
)
5104 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
5106 else if (die
->tag
== DW_TAG_union_type
)
5108 TYPE_CODE (type
) = TYPE_CODE_UNION
;
5112 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
5115 if (cu
->language
== language_cplus
&& die
->tag
== DW_TAG_class_type
)
5116 TYPE_DECLARED_CLASS (type
) = 1;
5118 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5121 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5125 TYPE_LENGTH (type
) = 0;
5128 TYPE_STUB_SUPPORTED (type
) = 1;
5129 if (die_is_declaration (die
, cu
))
5130 TYPE_STUB (type
) = 1;
5132 set_descriptive_type (type
, die
, cu
);
5134 /* We need to add the type field to the die immediately so we don't
5135 infinitely recurse when dealing with pointers to the structure
5136 type within the structure itself. */
5137 set_die_type (die
, type
, cu
);
5139 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
5141 struct field_info fi
;
5142 struct die_info
*child_die
;
5144 memset (&fi
, 0, sizeof (struct field_info
));
5146 child_die
= die
->child
;
5148 while (child_die
&& child_die
->tag
)
5150 if (child_die
->tag
== DW_TAG_member
5151 || child_die
->tag
== DW_TAG_variable
)
5153 /* NOTE: carlton/2002-11-05: A C++ static data member
5154 should be a DW_TAG_member that is a declaration, but
5155 all versions of G++ as of this writing (so through at
5156 least 3.2.1) incorrectly generate DW_TAG_variable
5157 tags for them instead. */
5158 dwarf2_add_field (&fi
, child_die
, cu
);
5160 else if (child_die
->tag
== DW_TAG_subprogram
)
5162 /* C++ member function. */
5163 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
5165 else if (child_die
->tag
== DW_TAG_inheritance
)
5167 /* C++ base class field. */
5168 dwarf2_add_field (&fi
, child_die
, cu
);
5170 child_die
= sibling_die (child_die
);
5173 /* Attach fields and member functions to the type. */
5175 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
5178 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
5180 /* Get the type which refers to the base class (possibly this
5181 class itself) which contains the vtable pointer for the current
5182 class from the DW_AT_containing_type attribute. This use of
5183 DW_AT_containing_type is a GNU extension. */
5185 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
5187 struct type
*t
= die_containing_type (die
, cu
);
5189 TYPE_VPTR_BASETYPE (type
) = t
;
5194 /* Our own class provides vtbl ptr. */
5195 for (i
= TYPE_NFIELDS (t
) - 1;
5196 i
>= TYPE_N_BASECLASSES (t
);
5199 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
5201 if (is_vtable_name (fieldname
, cu
))
5203 TYPE_VPTR_FIELDNO (type
) = i
;
5208 /* Complain if virtual function table field not found. */
5209 if (i
< TYPE_N_BASECLASSES (t
))
5210 complaint (&symfile_complaints
,
5211 _("virtual function table pointer not found when defining class '%s'"),
5212 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
5217 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
5220 else if (cu
->producer
5221 && strncmp (cu
->producer
,
5222 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
5224 /* The IBM XLC compiler does not provide direct indication
5225 of the containing type, but the vtable pointer is
5226 always named __vfp. */
5230 for (i
= TYPE_NFIELDS (type
) - 1;
5231 i
>= TYPE_N_BASECLASSES (type
);
5234 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
5236 TYPE_VPTR_FIELDNO (type
) = i
;
5237 TYPE_VPTR_BASETYPE (type
) = type
;
5245 quirk_gcc_member_function_pointer (type
, cu
->objfile
);
5247 do_cleanups (back_to
);
5252 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5254 struct objfile
*objfile
= cu
->objfile
;
5255 struct die_info
*child_die
= die
->child
;
5256 struct type
*this_type
;
5258 this_type
= get_die_type (die
, cu
);
5259 if (this_type
== NULL
)
5260 this_type
= read_structure_type (die
, cu
);
5262 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
5263 snapshots) has been known to create a die giving a declaration
5264 for a class that has, as a child, a die giving a definition for a
5265 nested class. So we have to process our children even if the
5266 current die is a declaration. Normally, of course, a declaration
5267 won't have any children at all. */
5269 while (child_die
!= NULL
&& child_die
->tag
)
5271 if (child_die
->tag
== DW_TAG_member
5272 || child_die
->tag
== DW_TAG_variable
5273 || child_die
->tag
== DW_TAG_inheritance
)
5278 process_die (child_die
, cu
);
5280 child_die
= sibling_die (child_die
);
5283 /* Do not consider external references. According to the DWARF standard,
5284 these DIEs are identified by the fact that they have no byte_size
5285 attribute, and a declaration attribute. */
5286 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
5287 || !die_is_declaration (die
, cu
))
5288 new_symbol (die
, this_type
, cu
);
5291 /* Given a DW_AT_enumeration_type die, set its type. We do not
5292 complete the type's fields yet, or create any symbols. */
5294 static struct type
*
5295 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5297 struct objfile
*objfile
= cu
->objfile
;
5299 struct attribute
*attr
;
5302 /* If the definition of this type lives in .debug_types, read that type.
5303 Don't follow DW_AT_specification though, that will take us back up
5304 the chain and we want to go down. */
5305 attr
= dwarf2_attr_no_follow (die
, DW_AT_signature
, cu
);
5308 struct dwarf2_cu
*type_cu
= cu
;
5309 struct die_info
*type_die
= follow_die_ref_or_sig (die
, attr
, &type_cu
);
5310 type
= read_type_die (type_die
, type_cu
);
5311 return set_die_type (die
, type
, cu
);
5314 type
= alloc_type (objfile
);
5316 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
5317 name
= dwarf2_full_name (NULL
, die
, cu
);
5319 TYPE_TAG_NAME (type
) = (char *) name
;
5321 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5324 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5328 TYPE_LENGTH (type
) = 0;
5331 /* The enumeration DIE can be incomplete. In Ada, any type can be
5332 declared as private in the package spec, and then defined only
5333 inside the package body. Such types are known as Taft Amendment
5334 Types. When another package uses such a type, an incomplete DIE
5335 may be generated by the compiler. */
5336 if (die_is_declaration (die
, cu
))
5337 TYPE_STUB (type
) = 1;
5339 return set_die_type (die
, type
, cu
);
5342 /* Given a pointer to a die which begins an enumeration, process all
5343 the dies that define the members of the enumeration, and create the
5344 symbol for the enumeration type.
5346 NOTE: We reverse the order of the element list. */
5349 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
5351 struct objfile
*objfile
= cu
->objfile
;
5352 struct die_info
*child_die
;
5353 struct field
*fields
;
5356 int unsigned_enum
= 1;
5358 struct type
*this_type
;
5362 this_type
= get_die_type (die
, cu
);
5363 if (this_type
== NULL
)
5364 this_type
= read_enumeration_type (die
, cu
);
5365 if (die
->child
!= NULL
)
5367 child_die
= die
->child
;
5368 while (child_die
&& child_die
->tag
)
5370 if (child_die
->tag
!= DW_TAG_enumerator
)
5372 process_die (child_die
, cu
);
5376 name
= dwarf2_name (child_die
, cu
);
5379 sym
= new_symbol (child_die
, this_type
, cu
);
5380 if (SYMBOL_VALUE (sym
) < 0)
5383 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
5385 fields
= (struct field
*)
5387 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
5388 * sizeof (struct field
));
5391 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
5392 FIELD_TYPE (fields
[num_fields
]) = NULL
;
5393 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
5394 FIELD_BITSIZE (fields
[num_fields
]) = 0;
5400 child_die
= sibling_die (child_die
);
5405 TYPE_NFIELDS (this_type
) = num_fields
;
5406 TYPE_FIELDS (this_type
) = (struct field
*)
5407 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
5408 memcpy (TYPE_FIELDS (this_type
), fields
,
5409 sizeof (struct field
) * num_fields
);
5413 TYPE_UNSIGNED (this_type
) = 1;
5416 new_symbol (die
, this_type
, cu
);
5419 /* Extract all information from a DW_TAG_array_type DIE and put it in
5420 the DIE's type field. For now, this only handles one dimensional
5423 static struct type
*
5424 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5426 struct objfile
*objfile
= cu
->objfile
;
5427 struct die_info
*child_die
;
5428 struct type
*type
= NULL
;
5429 struct type
*element_type
, *range_type
, *index_type
;
5430 struct type
**range_types
= NULL
;
5431 struct attribute
*attr
;
5433 struct cleanup
*back_to
;
5436 element_type
= die_type (die
, cu
);
5438 /* Irix 6.2 native cc creates array types without children for
5439 arrays with unspecified length. */
5440 if (die
->child
== NULL
)
5442 index_type
= objfile_type (objfile
)->builtin_int
;
5443 range_type
= create_range_type (NULL
, index_type
, 0, -1);
5444 type
= create_array_type (NULL
, element_type
, range_type
);
5445 return set_die_type (die
, type
, cu
);
5448 back_to
= make_cleanup (null_cleanup
, NULL
);
5449 child_die
= die
->child
;
5450 while (child_die
&& child_die
->tag
)
5452 if (child_die
->tag
== DW_TAG_subrange_type
)
5454 struct type
*child_type
= read_type_die (child_die
, cu
);
5455 if (child_type
!= NULL
)
5457 /* The range type was succesfully read. Save it for
5458 the array type creation. */
5459 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
5461 range_types
= (struct type
**)
5462 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
5463 * sizeof (struct type
*));
5465 make_cleanup (free_current_contents
, &range_types
);
5467 range_types
[ndim
++] = child_type
;
5470 child_die
= sibling_die (child_die
);
5473 /* Dwarf2 dimensions are output from left to right, create the
5474 necessary array types in backwards order. */
5476 type
= element_type
;
5478 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
5482 type
= create_array_type (NULL
, type
, range_types
[i
++]);
5487 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
5490 /* Understand Dwarf2 support for vector types (like they occur on
5491 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
5492 array type. This is not part of the Dwarf2/3 standard yet, but a
5493 custom vendor extension. The main difference between a regular
5494 array and the vector variant is that vectors are passed by value
5496 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
5498 make_vector_type (type
);
5500 name
= dwarf2_name (die
, cu
);
5502 TYPE_NAME (type
) = name
;
5504 set_descriptive_type (type
, die
, cu
);
5506 do_cleanups (back_to
);
5508 /* Install the type in the die. */
5509 return set_die_type (die
, type
, cu
);
5512 static enum dwarf_array_dim_ordering
5513 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
5515 struct attribute
*attr
;
5517 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
5519 if (attr
) return DW_SND (attr
);
5522 GNU F77 is a special case, as at 08/2004 array type info is the
5523 opposite order to the dwarf2 specification, but data is still
5524 laid out as per normal fortran.
5526 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
5530 if (cu
->language
== language_fortran
5531 && cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
5533 return DW_ORD_row_major
;
5536 switch (cu
->language_defn
->la_array_ordering
)
5538 case array_column_major
:
5539 return DW_ORD_col_major
;
5540 case array_row_major
:
5542 return DW_ORD_row_major
;
5546 /* Extract all information from a DW_TAG_set_type DIE and put it in
5547 the DIE's type field. */
5549 static struct type
*
5550 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5552 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
5554 return set_die_type (die
, set_type
, cu
);
5557 /* First cut: install each common block member as a global variable. */
5560 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
5562 struct die_info
*child_die
;
5563 struct attribute
*attr
;
5565 CORE_ADDR base
= (CORE_ADDR
) 0;
5567 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
5570 /* Support the .debug_loc offsets */
5571 if (attr_form_is_block (attr
))
5573 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
5575 else if (attr_form_is_section_offset (attr
))
5577 dwarf2_complex_location_expr_complaint ();
5581 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5582 "common block member");
5585 if (die
->child
!= NULL
)
5587 child_die
= die
->child
;
5588 while (child_die
&& child_die
->tag
)
5590 sym
= new_symbol (child_die
, NULL
, cu
);
5591 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
5594 CORE_ADDR byte_offset
= 0;
5596 if (attr_form_is_section_offset (attr
))
5597 dwarf2_complex_location_expr_complaint ();
5598 else if (attr_form_is_constant (attr
))
5599 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
5600 else if (attr_form_is_block (attr
))
5601 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
5603 dwarf2_complex_location_expr_complaint ();
5605 SYMBOL_VALUE_ADDRESS (sym
) = base
+ byte_offset
;
5606 add_symbol_to_list (sym
, &global_symbols
);
5608 child_die
= sibling_die (child_die
);
5613 /* Create a type for a C++ namespace. */
5615 static struct type
*
5616 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5618 struct objfile
*objfile
= cu
->objfile
;
5619 const char *previous_prefix
, *name
;
5623 /* For extensions, reuse the type of the original namespace. */
5624 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5626 struct die_info
*ext_die
;
5627 struct dwarf2_cu
*ext_cu
= cu
;
5628 ext_die
= dwarf2_extension (die
, &ext_cu
);
5629 type
= read_type_die (ext_die
, ext_cu
);
5630 return set_die_type (die
, type
, cu
);
5633 name
= namespace_name (die
, &is_anonymous
, cu
);
5635 /* Now build the name of the current namespace. */
5637 previous_prefix
= determine_prefix (die
, cu
);
5638 if (previous_prefix
[0] != '\0')
5639 name
= typename_concat (&objfile
->objfile_obstack
,
5640 previous_prefix
, name
, cu
);
5642 /* Create the type. */
5643 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5645 TYPE_NAME (type
) = (char *) name
;
5646 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5648 set_die_type (die
, type
, cu
);
5653 /* Read a C++ namespace. */
5656 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5658 struct objfile
*objfile
= cu
->objfile
;
5662 /* Add a symbol associated to this if we haven't seen the namespace
5663 before. Also, add a using directive if it's an anonymous
5666 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5670 type
= read_type_die (die
, cu
);
5671 new_symbol (die
, type
, cu
);
5673 name
= namespace_name (die
, &is_anonymous
, cu
);
5676 const char *previous_prefix
= determine_prefix (die
, cu
);
5677 cp_add_using_directive (previous_prefix
, TYPE_NAME (type
), NULL
,
5678 &objfile
->objfile_obstack
);
5682 if (die
->child
!= NULL
)
5684 struct die_info
*child_die
= die
->child
;
5686 while (child_die
&& child_die
->tag
)
5688 process_die (child_die
, cu
);
5689 child_die
= sibling_die (child_die
);
5694 /* Read a Fortran module. */
5697 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5699 struct die_info
*child_die
= die
->child
;
5701 /* FIXME: Support the separate Fortran module namespaces. */
5703 while (child_die
&& child_die
->tag
)
5705 process_die (child_die
, cu
);
5706 child_die
= sibling_die (child_die
);
5710 /* Return the name of the namespace represented by DIE. Set
5711 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5715 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5717 struct die_info
*current_die
;
5718 const char *name
= NULL
;
5720 /* Loop through the extensions until we find a name. */
5722 for (current_die
= die
;
5723 current_die
!= NULL
;
5724 current_die
= dwarf2_extension (die
, &cu
))
5726 name
= dwarf2_name (current_die
, cu
);
5731 /* Is it an anonymous namespace? */
5733 *is_anonymous
= (name
== NULL
);
5735 name
= "(anonymous namespace)";
5740 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5741 the user defined type vector. */
5743 static struct type
*
5744 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5746 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5747 struct comp_unit_head
*cu_header
= &cu
->header
;
5749 struct attribute
*attr_byte_size
;
5750 struct attribute
*attr_address_class
;
5751 int byte_size
, addr_class
;
5753 type
= lookup_pointer_type (die_type (die
, cu
));
5755 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5757 byte_size
= DW_UNSND (attr_byte_size
);
5759 byte_size
= cu_header
->addr_size
;
5761 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5762 if (attr_address_class
)
5763 addr_class
= DW_UNSND (attr_address_class
);
5765 addr_class
= DW_ADDR_none
;
5767 /* If the pointer size or address class is different than the
5768 default, create a type variant marked as such and set the
5769 length accordingly. */
5770 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5772 if (gdbarch_address_class_type_flags_p (gdbarch
))
5776 type_flags
= gdbarch_address_class_type_flags
5777 (gdbarch
, byte_size
, addr_class
);
5778 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5780 type
= make_type_with_address_space (type
, type_flags
);
5782 else if (TYPE_LENGTH (type
) != byte_size
)
5784 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5787 /* Should we also complain about unhandled address classes? */
5791 TYPE_LENGTH (type
) = byte_size
;
5792 return set_die_type (die
, type
, cu
);
5795 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5796 the user defined type vector. */
5798 static struct type
*
5799 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5801 struct objfile
*objfile
= cu
->objfile
;
5803 struct type
*to_type
;
5804 struct type
*domain
;
5806 to_type
= die_type (die
, cu
);
5807 domain
= die_containing_type (die
, cu
);
5809 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5810 type
= lookup_methodptr_type (to_type
);
5812 type
= lookup_memberptr_type (to_type
, domain
);
5814 return set_die_type (die
, type
, cu
);
5817 /* Extract all information from a DW_TAG_reference_type DIE and add to
5818 the user defined type vector. */
5820 static struct type
*
5821 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5823 struct comp_unit_head
*cu_header
= &cu
->header
;
5825 struct attribute
*attr
;
5827 type
= lookup_reference_type (die_type (die
, cu
));
5828 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5831 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5835 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5837 return set_die_type (die
, type
, cu
);
5840 static struct type
*
5841 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5843 struct type
*base_type
, *cv_type
;
5845 base_type
= die_type (die
, cu
);
5846 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5847 return set_die_type (die
, cv_type
, cu
);
5850 static struct type
*
5851 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5853 struct type
*base_type
, *cv_type
;
5855 base_type
= die_type (die
, cu
);
5856 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5857 return set_die_type (die
, cv_type
, cu
);
5860 /* Extract all information from a DW_TAG_string_type DIE and add to
5861 the user defined type vector. It isn't really a user defined type,
5862 but it behaves like one, with other DIE's using an AT_user_def_type
5863 attribute to reference it. */
5865 static struct type
*
5866 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5868 struct objfile
*objfile
= cu
->objfile
;
5869 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5870 struct type
*type
, *range_type
, *index_type
, *char_type
;
5871 struct attribute
*attr
;
5872 unsigned int length
;
5874 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5877 length
= DW_UNSND (attr
);
5881 /* check for the DW_AT_byte_size attribute */
5882 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5885 length
= DW_UNSND (attr
);
5893 index_type
= objfile_type (objfile
)->builtin_int
;
5894 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5895 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5896 type
= create_string_type (NULL
, char_type
, range_type
);
5898 return set_die_type (die
, type
, cu
);
5901 /* Handle DIES due to C code like:
5905 int (*funcp)(int a, long l);
5909 ('funcp' generates a DW_TAG_subroutine_type DIE)
5912 static struct type
*
5913 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5915 struct type
*type
; /* Type that this function returns */
5916 struct type
*ftype
; /* Function that returns above type */
5917 struct attribute
*attr
;
5919 type
= die_type (die
, cu
);
5920 ftype
= lookup_function_type (type
);
5922 /* All functions in C++, Pascal and Java have prototypes. */
5923 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5924 if ((attr
&& (DW_UNSND (attr
) != 0))
5925 || cu
->language
== language_cplus
5926 || cu
->language
== language_java
5927 || cu
->language
== language_pascal
)
5928 TYPE_PROTOTYPED (ftype
) = 1;
5930 /* Store the calling convention in the type if it's available in
5931 the subroutine die. Otherwise set the calling convention to
5932 the default value DW_CC_normal. */
5933 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5934 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5936 /* We need to add the subroutine type to the die immediately so
5937 we don't infinitely recurse when dealing with parameters
5938 declared as the same subroutine type. */
5939 set_die_type (die
, ftype
, cu
);
5941 if (die
->child
!= NULL
)
5943 struct die_info
*child_die
;
5947 /* Count the number of parameters.
5948 FIXME: GDB currently ignores vararg functions, but knows about
5949 vararg member functions. */
5950 child_die
= die
->child
;
5951 while (child_die
&& child_die
->tag
)
5953 if (child_die
->tag
== DW_TAG_formal_parameter
)
5955 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5956 TYPE_VARARGS (ftype
) = 1;
5957 child_die
= sibling_die (child_die
);
5960 /* Allocate storage for parameters and fill them in. */
5961 TYPE_NFIELDS (ftype
) = nparams
;
5962 TYPE_FIELDS (ftype
) = (struct field
*)
5963 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5965 child_die
= die
->child
;
5966 while (child_die
&& child_die
->tag
)
5968 if (child_die
->tag
== DW_TAG_formal_parameter
)
5970 /* Dwarf2 has no clean way to discern C++ static and non-static
5971 member functions. G++ helps GDB by marking the first
5972 parameter for non-static member functions (which is the
5973 this pointer) as artificial. We pass this information
5974 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5975 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5977 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5979 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5980 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5983 child_die
= sibling_die (child_die
);
5990 static struct type
*
5991 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5993 struct objfile
*objfile
= cu
->objfile
;
5994 struct attribute
*attr
;
5995 const char *name
= NULL
;
5996 struct type
*this_type
;
5998 name
= dwarf2_full_name (NULL
, die
, cu
);
5999 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
6000 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
6001 TYPE_NAME (this_type
) = (char *) name
;
6002 set_die_type (die
, this_type
, cu
);
6003 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
6007 /* Find a representation of a given base type and install
6008 it in the TYPE field of the die. */
6010 static struct type
*
6011 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6013 struct objfile
*objfile
= cu
->objfile
;
6015 struct attribute
*attr
;
6016 int encoding
= 0, size
= 0;
6018 enum type_code code
= TYPE_CODE_INT
;
6020 struct type
*target_type
= NULL
;
6022 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
6025 encoding
= DW_UNSND (attr
);
6027 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6030 size
= DW_UNSND (attr
);
6032 name
= dwarf2_name (die
, cu
);
6035 complaint (&symfile_complaints
,
6036 _("DW_AT_name missing from DW_TAG_base_type"));
6041 case DW_ATE_address
:
6042 /* Turn DW_ATE_address into a void * pointer. */
6043 code
= TYPE_CODE_PTR
;
6044 type_flags
|= TYPE_FLAG_UNSIGNED
;
6045 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
6047 case DW_ATE_boolean
:
6048 code
= TYPE_CODE_BOOL
;
6049 type_flags
|= TYPE_FLAG_UNSIGNED
;
6051 case DW_ATE_complex_float
:
6052 code
= TYPE_CODE_COMPLEX
;
6053 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
6055 case DW_ATE_decimal_float
:
6056 code
= TYPE_CODE_DECFLOAT
;
6059 code
= TYPE_CODE_FLT
;
6063 case DW_ATE_unsigned
:
6064 type_flags
|= TYPE_FLAG_UNSIGNED
;
6066 case DW_ATE_signed_char
:
6067 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6068 || cu
->language
== language_pascal
)
6069 code
= TYPE_CODE_CHAR
;
6071 case DW_ATE_unsigned_char
:
6072 if (cu
->language
== language_ada
|| cu
->language
== language_m2
6073 || cu
->language
== language_pascal
)
6074 code
= TYPE_CODE_CHAR
;
6075 type_flags
|= TYPE_FLAG_UNSIGNED
;
6078 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
6079 dwarf_type_encoding_name (encoding
));
6083 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
6084 TYPE_NAME (type
) = name
;
6085 TYPE_TARGET_TYPE (type
) = target_type
;
6087 if (name
&& strcmp (name
, "char") == 0)
6088 TYPE_NOSIGN (type
) = 1;
6090 return set_die_type (die
, type
, cu
);
6093 /* Read the given DW_AT_subrange DIE. */
6095 static struct type
*
6096 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6098 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
6099 struct type
*base_type
;
6100 struct type
*range_type
;
6101 struct attribute
*attr
;
6105 LONGEST negative_mask
;
6107 base_type
= die_type (die
, cu
);
6108 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
6110 complaint (&symfile_complaints
,
6111 _("DW_AT_type missing from DW_TAG_subrange_type"));
6113 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
6114 0, NULL
, cu
->objfile
);
6117 if (cu
->language
== language_fortran
)
6119 /* FORTRAN implies a lower bound of 1, if not given. */
6123 /* FIXME: For variable sized arrays either of these could be
6124 a variable rather than a constant value. We'll allow it,
6125 but we don't know how to handle it. */
6126 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
6128 low
= dwarf2_get_attr_constant_value (attr
, 0);
6130 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
6133 if (attr
->form
== DW_FORM_block1
)
6135 /* GCC encodes arrays with unspecified or dynamic length
6136 with a DW_FORM_block1 attribute.
6137 FIXME: GDB does not yet know how to handle dynamic
6138 arrays properly, treat them as arrays with unspecified
6141 FIXME: jimb/2003-09-22: GDB does not really know
6142 how to handle arrays of unspecified length
6143 either; we just represent them as zero-length
6144 arrays. Choose an appropriate upper bound given
6145 the lower bound we've computed above. */
6149 high
= dwarf2_get_attr_constant_value (attr
, 1);
6153 (LONGEST
) -1 << (TYPE_LENGTH (base_type
) * TARGET_CHAR_BIT
- 1);
6154 if (!TYPE_UNSIGNED (base_type
) && (low
& negative_mask
))
6155 low
|= negative_mask
;
6156 if (!TYPE_UNSIGNED (base_type
) && (high
& negative_mask
))
6157 high
|= negative_mask
;
6159 range_type
= create_range_type (NULL
, base_type
, low
, high
);
6161 name
= dwarf2_name (die
, cu
);
6163 TYPE_NAME (range_type
) = name
;
6165 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
6167 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
6169 set_descriptive_type (range_type
, die
, cu
);
6171 return set_die_type (die
, range_type
, cu
);
6174 static struct type
*
6175 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6179 /* For now, we only support the C meaning of an unspecified type: void. */
6181 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
6182 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
6184 return set_die_type (die
, type
, cu
);
6187 /* Trivial hash function for die_info: the hash value of a DIE
6188 is its offset in .debug_info for this objfile. */
6191 die_hash (const void *item
)
6193 const struct die_info
*die
= item
;
6197 /* Trivial comparison function for die_info structures: two DIEs
6198 are equal if they have the same offset. */
6201 die_eq (const void *item_lhs
, const void *item_rhs
)
6203 const struct die_info
*die_lhs
= item_lhs
;
6204 const struct die_info
*die_rhs
= item_rhs
;
6205 return die_lhs
->offset
== die_rhs
->offset
;
6208 /* Read a whole compilation unit into a linked list of dies. */
6210 static struct die_info
*
6211 read_comp_unit (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6213 struct die_reader_specs reader_specs
;
6215 gdb_assert (cu
->die_hash
== NULL
);
6217 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6221 &cu
->comp_unit_obstack
,
6222 hashtab_obstack_allocate
,
6223 dummy_obstack_deallocate
);
6225 init_cu_die_reader (&reader_specs
, cu
);
6227 return read_die_and_children (&reader_specs
, info_ptr
, &info_ptr
, NULL
);
6230 /* Main entry point for reading a DIE and all children.
6231 Read the DIE and dump it if requested. */
6233 static struct die_info
*
6234 read_die_and_children (const struct die_reader_specs
*reader
,
6236 gdb_byte
**new_info_ptr
,
6237 struct die_info
*parent
)
6239 struct die_info
*result
= read_die_and_children_1 (reader
, info_ptr
,
6240 new_info_ptr
, parent
);
6242 if (dwarf2_die_debug
)
6244 fprintf_unfiltered (gdb_stdlog
,
6245 "\nRead die from %s of %s:\n",
6246 reader
->buffer
== dwarf2_per_objfile
->info
.buffer
6248 : reader
->buffer
== dwarf2_per_objfile
->types
.buffer
6250 : "unknown section",
6251 reader
->abfd
->filename
);
6252 dump_die (result
, dwarf2_die_debug
);
6258 /* Read a single die and all its descendents. Set the die's sibling
6259 field to NULL; set other fields in the die correctly, and set all
6260 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
6261 location of the info_ptr after reading all of those dies. PARENT
6262 is the parent of the die in question. */
6264 static struct die_info
*
6265 read_die_and_children_1 (const struct die_reader_specs
*reader
,
6267 gdb_byte
**new_info_ptr
,
6268 struct die_info
*parent
)
6270 struct die_info
*die
;
6274 cur_ptr
= read_full_die (reader
, &die
, info_ptr
, &has_children
);
6277 *new_info_ptr
= cur_ptr
;
6280 store_in_ref_table (die
, reader
->cu
);
6283 die
->child
= read_die_and_siblings (reader
, cur_ptr
, new_info_ptr
, die
);
6287 *new_info_ptr
= cur_ptr
;
6290 die
->sibling
= NULL
;
6291 die
->parent
= parent
;
6295 /* Read a die, all of its descendents, and all of its siblings; set
6296 all of the fields of all of the dies correctly. Arguments are as
6297 in read_die_and_children. */
6299 static struct die_info
*
6300 read_die_and_siblings (const struct die_reader_specs
*reader
,
6302 gdb_byte
**new_info_ptr
,
6303 struct die_info
*parent
)
6305 struct die_info
*first_die
, *last_sibling
;
6309 first_die
= last_sibling
= NULL
;
6313 struct die_info
*die
6314 = read_die_and_children_1 (reader
, cur_ptr
, &cur_ptr
, parent
);
6318 *new_info_ptr
= cur_ptr
;
6325 last_sibling
->sibling
= die
;
6331 /* Read the die from the .debug_info section buffer. Set DIEP to
6332 point to a newly allocated die with its information, except for its
6333 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6334 whether the die has children or not. */
6337 read_full_die (const struct die_reader_specs
*reader
,
6338 struct die_info
**diep
, gdb_byte
*info_ptr
,
6341 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6342 struct abbrev_info
*abbrev
;
6343 struct die_info
*die
;
6344 struct dwarf2_cu
*cu
= reader
->cu
;
6345 bfd
*abfd
= reader
->abfd
;
6347 offset
= info_ptr
- reader
->buffer
;
6348 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6349 info_ptr
+= bytes_read
;
6357 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6359 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6361 bfd_get_filename (abfd
));
6363 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6364 die
->offset
= offset
;
6365 die
->tag
= abbrev
->tag
;
6366 die
->abbrev
= abbrev_number
;
6368 die
->num_attrs
= abbrev
->num_attrs
;
6370 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6371 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6372 abfd
, info_ptr
, cu
);
6375 *has_children
= abbrev
->has_children
;
6379 /* In DWARF version 2, the description of the debugging information is
6380 stored in a separate .debug_abbrev section. Before we read any
6381 dies from a section we read in all abbreviations and install them
6382 in a hash table. This function also sets flags in CU describing
6383 the data found in the abbrev table. */
6386 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
6388 struct comp_unit_head
*cu_header
= &cu
->header
;
6389 gdb_byte
*abbrev_ptr
;
6390 struct abbrev_info
*cur_abbrev
;
6391 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
6392 unsigned int abbrev_form
, hash_number
;
6393 struct attr_abbrev
*cur_attrs
;
6394 unsigned int allocated_attrs
;
6396 /* Initialize dwarf2 abbrevs */
6397 obstack_init (&cu
->abbrev_obstack
);
6398 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
6400 * sizeof (struct abbrev_info
*)));
6401 memset (cu
->dwarf2_abbrevs
, 0,
6402 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
6404 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
6405 &dwarf2_per_objfile
->abbrev
);
6406 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
6407 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6408 abbrev_ptr
+= bytes_read
;
6410 allocated_attrs
= ATTR_ALLOC_CHUNK
;
6411 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
6413 /* loop until we reach an abbrev number of 0 */
6414 while (abbrev_number
)
6416 cur_abbrev
= dwarf_alloc_abbrev (cu
);
6418 /* read in abbrev header */
6419 cur_abbrev
->number
= abbrev_number
;
6420 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6421 abbrev_ptr
+= bytes_read
;
6422 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
6425 if (cur_abbrev
->tag
== DW_TAG_namespace
)
6426 cu
->has_namespace_info
= 1;
6428 /* now read in declarations */
6429 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6430 abbrev_ptr
+= bytes_read
;
6431 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6432 abbrev_ptr
+= bytes_read
;
6435 if (cur_abbrev
->num_attrs
== allocated_attrs
)
6437 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
6439 = xrealloc (cur_attrs
, (allocated_attrs
6440 * sizeof (struct attr_abbrev
)));
6443 /* Record whether this compilation unit might have
6444 inter-compilation-unit references. If we don't know what form
6445 this attribute will have, then it might potentially be a
6446 DW_FORM_ref_addr, so we conservatively expect inter-CU
6449 if (abbrev_form
== DW_FORM_ref_addr
6450 || abbrev_form
== DW_FORM_indirect
)
6451 cu
->has_form_ref_addr
= 1;
6453 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
6454 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
6455 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6456 abbrev_ptr
+= bytes_read
;
6457 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6458 abbrev_ptr
+= bytes_read
;
6461 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
6462 (cur_abbrev
->num_attrs
6463 * sizeof (struct attr_abbrev
)));
6464 memcpy (cur_abbrev
->attrs
, cur_attrs
,
6465 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
6467 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
6468 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
6469 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
6471 /* Get next abbreviation.
6472 Under Irix6 the abbreviations for a compilation unit are not
6473 always properly terminated with an abbrev number of 0.
6474 Exit loop if we encounter an abbreviation which we have
6475 already read (which means we are about to read the abbreviations
6476 for the next compile unit) or if the end of the abbreviation
6477 table is reached. */
6478 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
6479 >= dwarf2_per_objfile
->abbrev
.size
)
6481 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
6482 abbrev_ptr
+= bytes_read
;
6483 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
6490 /* Release the memory used by the abbrev table for a compilation unit. */
6493 dwarf2_free_abbrev_table (void *ptr_to_cu
)
6495 struct dwarf2_cu
*cu
= ptr_to_cu
;
6497 obstack_free (&cu
->abbrev_obstack
, NULL
);
6498 cu
->dwarf2_abbrevs
= NULL
;
6501 /* Lookup an abbrev_info structure in the abbrev hash table. */
6503 static struct abbrev_info
*
6504 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
6506 unsigned int hash_number
;
6507 struct abbrev_info
*abbrev
;
6509 hash_number
= number
% ABBREV_HASH_SIZE
;
6510 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
6514 if (abbrev
->number
== number
)
6517 abbrev
= abbrev
->next
;
6522 /* Returns nonzero if TAG represents a type that we might generate a partial
6526 is_type_tag_for_partial (int tag
)
6531 /* Some types that would be reasonable to generate partial symbols for,
6532 that we don't at present. */
6533 case DW_TAG_array_type
:
6534 case DW_TAG_file_type
:
6535 case DW_TAG_ptr_to_member_type
:
6536 case DW_TAG_set_type
:
6537 case DW_TAG_string_type
:
6538 case DW_TAG_subroutine_type
:
6540 case DW_TAG_base_type
:
6541 case DW_TAG_class_type
:
6542 case DW_TAG_interface_type
:
6543 case DW_TAG_enumeration_type
:
6544 case DW_TAG_structure_type
:
6545 case DW_TAG_subrange_type
:
6546 case DW_TAG_typedef
:
6547 case DW_TAG_union_type
:
6554 /* Load all DIEs that are interesting for partial symbols into memory. */
6556 static struct partial_die_info
*
6557 load_partial_dies (bfd
*abfd
, gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6558 int building_psymtab
, struct dwarf2_cu
*cu
)
6560 struct partial_die_info
*part_die
;
6561 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
6562 struct abbrev_info
*abbrev
;
6563 unsigned int bytes_read
;
6564 unsigned int load_all
= 0;
6566 int nesting_level
= 1;
6571 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
6575 = htab_create_alloc_ex (cu
->header
.length
/ 12,
6579 &cu
->comp_unit_obstack
,
6580 hashtab_obstack_allocate
,
6581 dummy_obstack_deallocate
);
6583 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6584 sizeof (struct partial_die_info
));
6588 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
6590 /* A NULL abbrev means the end of a series of children. */
6593 if (--nesting_level
== 0)
6595 /* PART_DIE was probably the last thing allocated on the
6596 comp_unit_obstack, so we could call obstack_free
6597 here. We don't do that because the waste is small,
6598 and will be cleaned up when we're done with this
6599 compilation unit. This way, we're also more robust
6600 against other users of the comp_unit_obstack. */
6603 info_ptr
+= bytes_read
;
6604 last_die
= parent_die
;
6605 parent_die
= parent_die
->die_parent
;
6609 /* Check whether this DIE is interesting enough to save. Normally
6610 we would not be interested in members here, but there may be
6611 later variables referencing them via DW_AT_specification (for
6614 && !is_type_tag_for_partial (abbrev
->tag
)
6615 && abbrev
->tag
!= DW_TAG_enumerator
6616 && abbrev
->tag
!= DW_TAG_subprogram
6617 && abbrev
->tag
!= DW_TAG_lexical_block
6618 && abbrev
->tag
!= DW_TAG_variable
6619 && abbrev
->tag
!= DW_TAG_namespace
6620 && abbrev
->tag
!= DW_TAG_member
)
6622 /* Otherwise we skip to the next sibling, if any. */
6623 info_ptr
= skip_one_die (buffer
, info_ptr
+ bytes_read
, abbrev
, cu
);
6627 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
, abfd
,
6628 buffer
, info_ptr
, cu
);
6630 /* This two-pass algorithm for processing partial symbols has a
6631 high cost in cache pressure. Thus, handle some simple cases
6632 here which cover the majority of C partial symbols. DIEs
6633 which neither have specification tags in them, nor could have
6634 specification tags elsewhere pointing at them, can simply be
6635 processed and discarded.
6637 This segment is also optional; scan_partial_symbols and
6638 add_partial_symbol will handle these DIEs if we chain
6639 them in normally. When compilers which do not emit large
6640 quantities of duplicate debug information are more common,
6641 this code can probably be removed. */
6643 /* Any complete simple types at the top level (pretty much all
6644 of them, for a language without namespaces), can be processed
6646 if (parent_die
== NULL
6647 && part_die
->has_specification
== 0
6648 && part_die
->is_declaration
== 0
6649 && (part_die
->tag
== DW_TAG_typedef
6650 || part_die
->tag
== DW_TAG_base_type
6651 || part_die
->tag
== DW_TAG_subrange_type
))
6653 if (building_psymtab
&& part_die
->name
!= NULL
)
6654 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6655 VAR_DOMAIN
, LOC_TYPEDEF
,
6656 &cu
->objfile
->static_psymbols
,
6657 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6658 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6662 /* If we're at the second level, and we're an enumerator, and
6663 our parent has no specification (meaning possibly lives in a
6664 namespace elsewhere), then we can add the partial symbol now
6665 instead of queueing it. */
6666 if (part_die
->tag
== DW_TAG_enumerator
6667 && parent_die
!= NULL
6668 && parent_die
->die_parent
== NULL
6669 && parent_die
->tag
== DW_TAG_enumeration_type
6670 && parent_die
->has_specification
== 0)
6672 if (part_die
->name
== NULL
)
6673 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
6674 else if (building_psymtab
)
6675 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
), 0,
6676 VAR_DOMAIN
, LOC_CONST
,
6677 (cu
->language
== language_cplus
6678 || cu
->language
== language_java
)
6679 ? &cu
->objfile
->global_psymbols
6680 : &cu
->objfile
->static_psymbols
,
6681 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
6683 info_ptr
= locate_pdi_sibling (part_die
, buffer
, info_ptr
, abfd
, cu
);
6687 /* We'll save this DIE so link it in. */
6688 part_die
->die_parent
= parent_die
;
6689 part_die
->die_sibling
= NULL
;
6690 part_die
->die_child
= NULL
;
6692 if (last_die
&& last_die
== parent_die
)
6693 last_die
->die_child
= part_die
;
6695 last_die
->die_sibling
= part_die
;
6697 last_die
= part_die
;
6699 if (first_die
== NULL
)
6700 first_die
= part_die
;
6702 /* Maybe add the DIE to the hash table. Not all DIEs that we
6703 find interesting need to be in the hash table, because we
6704 also have the parent/sibling/child chains; only those that we
6705 might refer to by offset later during partial symbol reading.
6707 For now this means things that might have be the target of a
6708 DW_AT_specification, DW_AT_abstract_origin, or
6709 DW_AT_extension. DW_AT_extension will refer only to
6710 namespaces; DW_AT_abstract_origin refers to functions (and
6711 many things under the function DIE, but we do not recurse
6712 into function DIEs during partial symbol reading) and
6713 possibly variables as well; DW_AT_specification refers to
6714 declarations. Declarations ought to have the DW_AT_declaration
6715 flag. It happens that GCC forgets to put it in sometimes, but
6716 only for functions, not for types.
6718 Adding more things than necessary to the hash table is harmless
6719 except for the performance cost. Adding too few will result in
6720 wasted time in find_partial_die, when we reread the compilation
6721 unit with load_all_dies set. */
6724 || abbrev
->tag
== DW_TAG_subprogram
6725 || abbrev
->tag
== DW_TAG_variable
6726 || abbrev
->tag
== DW_TAG_namespace
6727 || part_die
->is_declaration
)
6731 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6732 part_die
->offset
, INSERT
);
6736 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6737 sizeof (struct partial_die_info
));
6739 /* For some DIEs we want to follow their children (if any). For C
6740 we have no reason to follow the children of structures; for other
6741 languages we have to, both so that we can get at method physnames
6742 to infer fully qualified class names, and for DW_AT_specification.
6744 For Ada, we need to scan the children of subprograms and lexical
6745 blocks as well because Ada allows the definition of nested
6746 entities that could be interesting for the debugger, such as
6747 nested subprograms for instance. */
6748 if (last_die
->has_children
6750 || last_die
->tag
== DW_TAG_namespace
6751 || last_die
->tag
== DW_TAG_enumeration_type
6752 || (cu
->language
!= language_c
6753 && (last_die
->tag
== DW_TAG_class_type
6754 || last_die
->tag
== DW_TAG_interface_type
6755 || last_die
->tag
== DW_TAG_structure_type
6756 || last_die
->tag
== DW_TAG_union_type
))
6757 || (cu
->language
== language_ada
6758 && (last_die
->tag
== DW_TAG_subprogram
6759 || last_die
->tag
== DW_TAG_lexical_block
))))
6762 parent_die
= last_die
;
6766 /* Otherwise we skip to the next sibling, if any. */
6767 info_ptr
= locate_pdi_sibling (last_die
, buffer
, info_ptr
, abfd
, cu
);
6769 /* Back to the top, do it again. */
6773 /* Read a minimal amount of information into the minimal die structure. */
6776 read_partial_die (struct partial_die_info
*part_die
,
6777 struct abbrev_info
*abbrev
,
6778 unsigned int abbrev_len
, bfd
*abfd
,
6779 gdb_byte
*buffer
, gdb_byte
*info_ptr
,
6780 struct dwarf2_cu
*cu
)
6782 unsigned int bytes_read
, i
;
6783 struct attribute attr
;
6784 int has_low_pc_attr
= 0;
6785 int has_high_pc_attr
= 0;
6787 memset (part_die
, 0, sizeof (struct partial_die_info
));
6789 part_die
->offset
= info_ptr
- buffer
;
6791 info_ptr
+= abbrev_len
;
6796 part_die
->tag
= abbrev
->tag
;
6797 part_die
->has_children
= abbrev
->has_children
;
6799 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6801 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6803 /* Store the data if it is of an attribute we want to keep in a
6804 partial symbol table. */
6808 switch (part_die
->tag
)
6810 case DW_TAG_compile_unit
:
6811 case DW_TAG_type_unit
:
6812 /* Compilation units have a DW_AT_name that is a filename, not
6813 a source language identifier. */
6814 case DW_TAG_enumeration_type
:
6815 case DW_TAG_enumerator
:
6816 /* These tags always have simple identifiers already; no need
6817 to canonicalize them. */
6818 part_die
->name
= DW_STRING (&attr
);
6822 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6823 &cu
->objfile
->objfile_obstack
);
6827 case DW_AT_MIPS_linkage_name
:
6828 if (cu
->language
== language_ada
)
6829 part_die
->name
= DW_STRING (&attr
);
6832 has_low_pc_attr
= 1;
6833 part_die
->lowpc
= DW_ADDR (&attr
);
6836 has_high_pc_attr
= 1;
6837 part_die
->highpc
= DW_ADDR (&attr
);
6839 case DW_AT_location
:
6840 /* Support the .debug_loc offsets */
6841 if (attr_form_is_block (&attr
))
6843 part_die
->locdesc
= DW_BLOCK (&attr
);
6845 else if (attr_form_is_section_offset (&attr
))
6847 dwarf2_complex_location_expr_complaint ();
6851 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6852 "partial symbol information");
6855 case DW_AT_external
:
6856 part_die
->is_external
= DW_UNSND (&attr
);
6858 case DW_AT_declaration
:
6859 part_die
->is_declaration
= DW_UNSND (&attr
);
6862 part_die
->has_type
= 1;
6864 case DW_AT_abstract_origin
:
6865 case DW_AT_specification
:
6866 case DW_AT_extension
:
6867 part_die
->has_specification
= 1;
6868 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6871 /* Ignore absolute siblings, they might point outside of
6872 the current compile unit. */
6873 if (attr
.form
== DW_FORM_ref_addr
)
6874 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6876 part_die
->sibling
= buffer
+ dwarf2_get_ref_die_offset (&attr
);
6878 case DW_AT_byte_size
:
6879 part_die
->has_byte_size
= 1;
6881 case DW_AT_calling_convention
:
6882 /* DWARF doesn't provide a way to identify a program's source-level
6883 entry point. DW_AT_calling_convention attributes are only meant
6884 to describe functions' calling conventions.
6886 However, because it's a necessary piece of information in
6887 Fortran, and because DW_CC_program is the only piece of debugging
6888 information whose definition refers to a 'main program' at all,
6889 several compilers have begun marking Fortran main programs with
6890 DW_CC_program --- even when those functions use the standard
6891 calling conventions.
6893 So until DWARF specifies a way to provide this information and
6894 compilers pick up the new representation, we'll support this
6896 if (DW_UNSND (&attr
) == DW_CC_program
6897 && cu
->language
== language_fortran
)
6898 set_main_name (part_die
->name
);
6905 /* When using the GNU linker, .gnu.linkonce. sections are used to
6906 eliminate duplicate copies of functions and vtables and such.
6907 The linker will arbitrarily choose one and discard the others.
6908 The AT_*_pc values for such functions refer to local labels in
6909 these sections. If the section from that file was discarded, the
6910 labels are not in the output, so the relocs get a value of 0.
6911 If this is a discarded function, mark the pc bounds as invalid,
6912 so that GDB will ignore it. */
6913 if (has_low_pc_attr
&& has_high_pc_attr
6914 && part_die
->lowpc
< part_die
->highpc
6915 && (part_die
->lowpc
!= 0
6916 || dwarf2_per_objfile
->has_section_at_zero
))
6917 part_die
->has_pc_info
= 1;
6922 /* Find a cached partial DIE at OFFSET in CU. */
6924 static struct partial_die_info
*
6925 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6927 struct partial_die_info
*lookup_die
= NULL
;
6928 struct partial_die_info part_die
;
6930 part_die
.offset
= offset
;
6931 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6936 /* Find a partial DIE at OFFSET, which may or may not be in CU,
6937 except in the case of .debug_types DIEs which do not reference
6938 outside their CU (they do however referencing other types via
6941 static struct partial_die_info
*
6942 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6944 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6945 struct partial_die_info
*pd
= NULL
;
6947 if (cu
->per_cu
->from_debug_types
)
6949 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6955 if (offset_in_cu_p (&cu
->header
, offset
))
6957 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6962 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6964 if (per_cu
->cu
== NULL
)
6966 load_partial_comp_unit (per_cu
, cu
->objfile
);
6967 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6968 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6971 per_cu
->cu
->last_used
= 0;
6972 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6974 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6976 struct cleanup
*back_to
;
6977 struct partial_die_info comp_unit_die
;
6978 struct abbrev_info
*abbrev
;
6979 unsigned int bytes_read
;
6982 per_cu
->load_all_dies
= 1;
6984 /* Re-read the DIEs. */
6985 back_to
= make_cleanup (null_cleanup
, 0);
6986 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6988 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6989 make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6991 info_ptr
= (dwarf2_per_objfile
->info
.buffer
6992 + per_cu
->cu
->header
.offset
6993 + per_cu
->cu
->header
.first_die_offset
);
6994 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6995 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6996 per_cu
->cu
->objfile
->obfd
,
6997 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
6999 if (comp_unit_die
.has_children
)
7000 load_partial_dies (per_cu
->cu
->objfile
->obfd
,
7001 dwarf2_per_objfile
->info
.buffer
, info_ptr
,
7003 do_cleanups (back_to
);
7005 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
7011 internal_error (__FILE__
, __LINE__
,
7012 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
7013 offset
, bfd_get_filename (cu
->objfile
->obfd
));
7017 /* Adjust PART_DIE before generating a symbol for it. This function
7018 may set the is_external flag or change the DIE's name. */
7021 fixup_partial_die (struct partial_die_info
*part_die
,
7022 struct dwarf2_cu
*cu
)
7024 /* If we found a reference attribute and the DIE has no name, try
7025 to find a name in the referred to DIE. */
7027 if (part_die
->name
== NULL
&& part_die
->has_specification
)
7029 struct partial_die_info
*spec_die
;
7031 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
7033 fixup_partial_die (spec_die
, cu
);
7037 part_die
->name
= spec_die
->name
;
7039 /* Copy DW_AT_external attribute if it is set. */
7040 if (spec_die
->is_external
)
7041 part_die
->is_external
= spec_die
->is_external
;
7045 /* Set default names for some unnamed DIEs. */
7046 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
7047 || part_die
->tag
== DW_TAG_class_type
))
7048 part_die
->name
= "(anonymous class)";
7050 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
7051 part_die
->name
= "(anonymous namespace)";
7053 if (part_die
->tag
== DW_TAG_structure_type
7054 || part_die
->tag
== DW_TAG_class_type
7055 || part_die
->tag
== DW_TAG_union_type
)
7056 guess_structure_name (part_die
, cu
);
7059 /* Read an attribute value described by an attribute form. */
7062 read_attribute_value (struct attribute
*attr
, unsigned form
,
7063 bfd
*abfd
, gdb_byte
*info_ptr
,
7064 struct dwarf2_cu
*cu
)
7066 struct comp_unit_head
*cu_header
= &cu
->header
;
7067 unsigned int bytes_read
;
7068 struct dwarf_block
*blk
;
7073 case DW_FORM_ref_addr
:
7074 if (cu
->header
.version
== 2)
7075 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7077 DW_ADDR (attr
) = read_offset (abfd
, info_ptr
, &cu
->header
, &bytes_read
);
7078 info_ptr
+= bytes_read
;
7081 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
7082 info_ptr
+= bytes_read
;
7084 case DW_FORM_block2
:
7085 blk
= dwarf_alloc_block (cu
);
7086 blk
->size
= read_2_bytes (abfd
, info_ptr
);
7088 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7089 info_ptr
+= blk
->size
;
7090 DW_BLOCK (attr
) = blk
;
7092 case DW_FORM_block4
:
7093 blk
= dwarf_alloc_block (cu
);
7094 blk
->size
= read_4_bytes (abfd
, info_ptr
);
7096 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7097 info_ptr
+= blk
->size
;
7098 DW_BLOCK (attr
) = blk
;
7101 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
7105 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
7109 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
7112 case DW_FORM_string
:
7113 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
7114 DW_STRING_IS_CANONICAL (attr
) = 0;
7115 info_ptr
+= bytes_read
;
7118 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
7120 DW_STRING_IS_CANONICAL (attr
) = 0;
7121 info_ptr
+= bytes_read
;
7124 blk
= dwarf_alloc_block (cu
);
7125 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7126 info_ptr
+= bytes_read
;
7127 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7128 info_ptr
+= blk
->size
;
7129 DW_BLOCK (attr
) = blk
;
7131 case DW_FORM_block1
:
7132 blk
= dwarf_alloc_block (cu
);
7133 blk
->size
= read_1_byte (abfd
, info_ptr
);
7135 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
7136 info_ptr
+= blk
->size
;
7137 DW_BLOCK (attr
) = blk
;
7140 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7144 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
7148 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
7149 info_ptr
+= bytes_read
;
7152 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7153 info_ptr
+= bytes_read
;
7156 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
7160 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
7164 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
7168 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
7172 /* Convert the signature to something we can record in DW_UNSND
7174 NOTE: This is NULL if the type wasn't found. */
7175 DW_SIGNATURED_TYPE (attr
) =
7176 lookup_signatured_type (cu
->objfile
, read_8_bytes (abfd
, info_ptr
));
7179 case DW_FORM_ref_udata
:
7180 DW_ADDR (attr
) = (cu
->header
.offset
7181 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
7182 info_ptr
+= bytes_read
;
7184 case DW_FORM_indirect
:
7185 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
7186 info_ptr
+= bytes_read
;
7187 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
7190 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
7191 dwarf_form_name (form
),
7192 bfd_get_filename (abfd
));
7195 /* We have seen instances where the compiler tried to emit a byte
7196 size attribute of -1 which ended up being encoded as an unsigned
7197 0xffffffff. Although 0xffffffff is technically a valid size value,
7198 an object of this size seems pretty unlikely so we can relatively
7199 safely treat these cases as if the size attribute was invalid and
7200 treat them as zero by default. */
7201 if (attr
->name
== DW_AT_byte_size
7202 && form
== DW_FORM_data4
7203 && DW_UNSND (attr
) >= 0xffffffff)
7206 (&symfile_complaints
,
7207 _("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
7208 hex_string (DW_UNSND (attr
)));
7209 DW_UNSND (attr
) = 0;
7215 /* Read an attribute described by an abbreviated attribute. */
7218 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
7219 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
7221 attr
->name
= abbrev
->name
;
7222 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
7225 /* read dwarf information from a buffer */
7228 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
7230 return bfd_get_8 (abfd
, buf
);
7234 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
7236 return bfd_get_signed_8 (abfd
, buf
);
7240 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
7242 return bfd_get_16 (abfd
, buf
);
7246 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7248 return bfd_get_signed_16 (abfd
, buf
);
7252 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
7254 return bfd_get_32 (abfd
, buf
);
7258 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
7260 return bfd_get_signed_32 (abfd
, buf
);
7264 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
7266 return bfd_get_64 (abfd
, buf
);
7270 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
7271 unsigned int *bytes_read
)
7273 struct comp_unit_head
*cu_header
= &cu
->header
;
7274 CORE_ADDR retval
= 0;
7276 if (cu_header
->signed_addr_p
)
7278 switch (cu_header
->addr_size
)
7281 retval
= bfd_get_signed_16 (abfd
, buf
);
7284 retval
= bfd_get_signed_32 (abfd
, buf
);
7287 retval
= bfd_get_signed_64 (abfd
, buf
);
7290 internal_error (__FILE__
, __LINE__
,
7291 _("read_address: bad switch, signed [in module %s]"),
7292 bfd_get_filename (abfd
));
7297 switch (cu_header
->addr_size
)
7300 retval
= bfd_get_16 (abfd
, buf
);
7303 retval
= bfd_get_32 (abfd
, buf
);
7306 retval
= bfd_get_64 (abfd
, buf
);
7309 internal_error (__FILE__
, __LINE__
,
7310 _("read_address: bad switch, unsigned [in module %s]"),
7311 bfd_get_filename (abfd
));
7315 *bytes_read
= cu_header
->addr_size
;
7319 /* Read the initial length from a section. The (draft) DWARF 3
7320 specification allows the initial length to take up either 4 bytes
7321 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
7322 bytes describe the length and all offsets will be 8 bytes in length
7325 An older, non-standard 64-bit format is also handled by this
7326 function. The older format in question stores the initial length
7327 as an 8-byte quantity without an escape value. Lengths greater
7328 than 2^32 aren't very common which means that the initial 4 bytes
7329 is almost always zero. Since a length value of zero doesn't make
7330 sense for the 32-bit format, this initial zero can be considered to
7331 be an escape value which indicates the presence of the older 64-bit
7332 format. As written, the code can't detect (old format) lengths
7333 greater than 4GB. If it becomes necessary to handle lengths
7334 somewhat larger than 4GB, we could allow other small values (such
7335 as the non-sensical values of 1, 2, and 3) to also be used as
7336 escape values indicating the presence of the old format.
7338 The value returned via bytes_read should be used to increment the
7339 relevant pointer after calling read_initial_length().
7341 [ Note: read_initial_length() and read_offset() are based on the
7342 document entitled "DWARF Debugging Information Format", revision
7343 3, draft 8, dated November 19, 2001. This document was obtained
7346 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
7348 This document is only a draft and is subject to change. (So beware.)
7350 Details regarding the older, non-standard 64-bit format were
7351 determined empirically by examining 64-bit ELF files produced by
7352 the SGI toolchain on an IRIX 6.5 machine.
7354 - Kevin, July 16, 2002
7358 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
7360 LONGEST length
= bfd_get_32 (abfd
, buf
);
7362 if (length
== 0xffffffff)
7364 length
= bfd_get_64 (abfd
, buf
+ 4);
7367 else if (length
== 0)
7369 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
7370 length
= bfd_get_64 (abfd
, buf
);
7381 /* Cover function for read_initial_length.
7382 Returns the length of the object at BUF, and stores the size of the
7383 initial length in *BYTES_READ and stores the size that offsets will be in
7385 If the initial length size is not equivalent to that specified in
7386 CU_HEADER then issue a complaint.
7387 This is useful when reading non-comp-unit headers. */
7390 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
7391 const struct comp_unit_head
*cu_header
,
7392 unsigned int *bytes_read
,
7393 unsigned int *offset_size
)
7395 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
7397 gdb_assert (cu_header
->initial_length_size
== 4
7398 || cu_header
->initial_length_size
== 8
7399 || cu_header
->initial_length_size
== 12);
7401 if (cu_header
->initial_length_size
!= *bytes_read
)
7402 complaint (&symfile_complaints
,
7403 _("intermixed 32-bit and 64-bit DWARF sections"));
7405 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
7409 /* Read an offset from the data stream. The size of the offset is
7410 given by cu_header->offset_size. */
7413 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
7414 unsigned int *bytes_read
)
7416 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
7417 *bytes_read
= cu_header
->offset_size
;
7421 /* Read an offset from the data stream. */
7424 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
7428 switch (offset_size
)
7431 retval
= bfd_get_32 (abfd
, buf
);
7434 retval
= bfd_get_64 (abfd
, buf
);
7437 internal_error (__FILE__
, __LINE__
,
7438 _("read_offset_1: bad switch [in module %s]"),
7439 bfd_get_filename (abfd
));
7446 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
7448 /* If the size of a host char is 8 bits, we can return a pointer
7449 to the buffer, otherwise we have to copy the data to a buffer
7450 allocated on the temporary obstack. */
7451 gdb_assert (HOST_CHAR_BIT
== 8);
7456 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7458 /* If the size of a host char is 8 bits, we can return a pointer
7459 to the string, otherwise we have to copy the string to a buffer
7460 allocated on the temporary obstack. */
7461 gdb_assert (HOST_CHAR_BIT
== 8);
7464 *bytes_read_ptr
= 1;
7467 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
7468 return (char *) buf
;
7472 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
7473 const struct comp_unit_head
*cu_header
,
7474 unsigned int *bytes_read_ptr
)
7476 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
7478 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->str
);
7479 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
7481 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
7482 bfd_get_filename (abfd
));
7485 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
7487 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
7488 bfd_get_filename (abfd
));
7491 gdb_assert (HOST_CHAR_BIT
== 8);
7492 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
7494 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
7497 static unsigned long
7498 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7500 unsigned long result
;
7501 unsigned int num_read
;
7511 byte
= bfd_get_8 (abfd
, buf
);
7514 result
|= ((unsigned long)(byte
& 127) << shift
);
7515 if ((byte
& 128) == 0)
7521 *bytes_read_ptr
= num_read
;
7526 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
7529 int i
, shift
, num_read
;
7538 byte
= bfd_get_8 (abfd
, buf
);
7541 result
|= ((long)(byte
& 127) << shift
);
7543 if ((byte
& 128) == 0)
7548 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
7549 result
|= -(((long)1) << shift
);
7550 *bytes_read_ptr
= num_read
;
7554 /* Return a pointer to just past the end of an LEB128 number in BUF. */
7557 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
7563 byte
= bfd_get_8 (abfd
, buf
);
7565 if ((byte
& 128) == 0)
7571 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
7578 cu
->language
= language_c
;
7580 case DW_LANG_C_plus_plus
:
7581 cu
->language
= language_cplus
;
7583 case DW_LANG_Fortran77
:
7584 case DW_LANG_Fortran90
:
7585 case DW_LANG_Fortran95
:
7586 cu
->language
= language_fortran
;
7588 case DW_LANG_Mips_Assembler
:
7589 cu
->language
= language_asm
;
7592 cu
->language
= language_java
;
7596 cu
->language
= language_ada
;
7598 case DW_LANG_Modula2
:
7599 cu
->language
= language_m2
;
7601 case DW_LANG_Pascal83
:
7602 cu
->language
= language_pascal
;
7605 cu
->language
= language_objc
;
7607 case DW_LANG_Cobol74
:
7608 case DW_LANG_Cobol85
:
7610 cu
->language
= language_minimal
;
7613 cu
->language_defn
= language_def (cu
->language
);
7616 /* Return the named attribute or NULL if not there. */
7618 static struct attribute
*
7619 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
7622 struct attribute
*spec
= NULL
;
7624 for (i
= 0; i
< die
->num_attrs
; ++i
)
7626 if (die
->attrs
[i
].name
== name
)
7627 return &die
->attrs
[i
];
7628 if (die
->attrs
[i
].name
== DW_AT_specification
7629 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
7630 spec
= &die
->attrs
[i
];
7635 die
= follow_die_ref (die
, spec
, &cu
);
7636 return dwarf2_attr (die
, name
, cu
);
7642 /* Return the named attribute or NULL if not there,
7643 but do not follow DW_AT_specification, etc.
7644 This is for use in contexts where we're reading .debug_types dies.
7645 Following DW_AT_specification, DW_AT_abstract_origin will take us
7646 back up the chain, and we want to go down. */
7648 static struct attribute
*
7649 dwarf2_attr_no_follow (struct die_info
*die
, unsigned int name
,
7650 struct dwarf2_cu
*cu
)
7654 for (i
= 0; i
< die
->num_attrs
; ++i
)
7655 if (die
->attrs
[i
].name
== name
)
7656 return &die
->attrs
[i
];
7661 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7662 and holds a non-zero value. This function should only be used for
7663 DW_FORM_flag attributes. */
7666 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7668 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7670 return (attr
&& DW_UNSND (attr
));
7674 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7676 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7677 which value is non-zero. However, we have to be careful with
7678 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7679 (via dwarf2_flag_true_p) follows this attribute. So we may
7680 end up accidently finding a declaration attribute that belongs
7681 to a different DIE referenced by the specification attribute,
7682 even though the given DIE does not have a declaration attribute. */
7683 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7684 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7687 /* Return the die giving the specification for DIE, if there is
7688 one. *SPEC_CU is the CU containing DIE on input, and the CU
7689 containing the return value on output. If there is no
7690 specification, but there is an abstract origin, that is
7693 static struct die_info
*
7694 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7696 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7699 if (spec_attr
== NULL
)
7700 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7702 if (spec_attr
== NULL
)
7705 return follow_die_ref (die
, spec_attr
, spec_cu
);
7708 /* Free the line_header structure *LH, and any arrays and strings it
7711 free_line_header (struct line_header
*lh
)
7713 if (lh
->standard_opcode_lengths
)
7714 xfree (lh
->standard_opcode_lengths
);
7716 /* Remember that all the lh->file_names[i].name pointers are
7717 pointers into debug_line_buffer, and don't need to be freed. */
7719 xfree (lh
->file_names
);
7721 /* Similarly for the include directory names. */
7722 if (lh
->include_dirs
)
7723 xfree (lh
->include_dirs
);
7729 /* Add an entry to LH's include directory table. */
7731 add_include_dir (struct line_header
*lh
, char *include_dir
)
7733 /* Grow the array if necessary. */
7734 if (lh
->include_dirs_size
== 0)
7736 lh
->include_dirs_size
= 1; /* for testing */
7737 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7738 * sizeof (*lh
->include_dirs
));
7740 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7742 lh
->include_dirs_size
*= 2;
7743 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7744 (lh
->include_dirs_size
7745 * sizeof (*lh
->include_dirs
)));
7748 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7752 /* Add an entry to LH's file name table. */
7754 add_file_name (struct line_header
*lh
,
7756 unsigned int dir_index
,
7757 unsigned int mod_time
,
7758 unsigned int length
)
7760 struct file_entry
*fe
;
7762 /* Grow the array if necessary. */
7763 if (lh
->file_names_size
== 0)
7765 lh
->file_names_size
= 1; /* for testing */
7766 lh
->file_names
= xmalloc (lh
->file_names_size
7767 * sizeof (*lh
->file_names
));
7769 else if (lh
->num_file_names
>= lh
->file_names_size
)
7771 lh
->file_names_size
*= 2;
7772 lh
->file_names
= xrealloc (lh
->file_names
,
7773 (lh
->file_names_size
7774 * sizeof (*lh
->file_names
)));
7777 fe
= &lh
->file_names
[lh
->num_file_names
++];
7779 fe
->dir_index
= dir_index
;
7780 fe
->mod_time
= mod_time
;
7781 fe
->length
= length
;
7787 /* Read the statement program header starting at OFFSET in
7788 .debug_line, according to the endianness of ABFD. Return a pointer
7789 to a struct line_header, allocated using xmalloc.
7791 NOTE: the strings in the include directory and file name tables of
7792 the returned object point into debug_line_buffer, and must not be
7794 static struct line_header
*
7795 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7796 struct dwarf2_cu
*cu
)
7798 struct cleanup
*back_to
;
7799 struct line_header
*lh
;
7801 unsigned int bytes_read
, offset_size
;
7803 char *cur_dir
, *cur_file
;
7805 dwarf2_read_section (dwarf2_per_objfile
->objfile
, &dwarf2_per_objfile
->line
);
7806 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7808 complaint (&symfile_complaints
, _("missing .debug_line section"));
7812 /* Make sure that at least there's room for the total_length field.
7813 That could be 12 bytes long, but we're just going to fudge that. */
7814 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7816 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7820 lh
= xmalloc (sizeof (*lh
));
7821 memset (lh
, 0, sizeof (*lh
));
7822 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7825 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7827 /* Read in the header. */
7829 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7830 &bytes_read
, &offset_size
);
7831 line_ptr
+= bytes_read
;
7832 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7833 + dwarf2_per_objfile
->line
.size
))
7835 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7838 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7839 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7841 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7842 line_ptr
+= offset_size
;
7843 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7845 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7847 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7849 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7851 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7853 lh
->standard_opcode_lengths
7854 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7856 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7857 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7859 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7863 /* Read directory table. */
7864 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7866 line_ptr
+= bytes_read
;
7867 add_include_dir (lh
, cur_dir
);
7869 line_ptr
+= bytes_read
;
7871 /* Read file name table. */
7872 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7874 unsigned int dir_index
, mod_time
, length
;
7876 line_ptr
+= bytes_read
;
7877 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7878 line_ptr
+= bytes_read
;
7879 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7880 line_ptr
+= bytes_read
;
7881 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7882 line_ptr
+= bytes_read
;
7884 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7886 line_ptr
+= bytes_read
;
7887 lh
->statement_program_start
= line_ptr
;
7889 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7890 + dwarf2_per_objfile
->line
.size
))
7891 complaint (&symfile_complaints
,
7892 _("line number info header doesn't fit in `.debug_line' section"));
7894 discard_cleanups (back_to
);
7898 /* This function exists to work around a bug in certain compilers
7899 (particularly GCC 2.95), in which the first line number marker of a
7900 function does not show up until after the prologue, right before
7901 the second line number marker. This function shifts ADDRESS down
7902 to the beginning of the function if necessary, and is called on
7903 addresses passed to record_line. */
7906 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7908 struct function_range
*fn
;
7910 /* Find the function_range containing address. */
7915 cu
->cached_fn
= cu
->first_fn
;
7919 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7925 while (fn
&& fn
!= cu
->cached_fn
)
7926 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7936 if (address
!= fn
->lowpc
)
7937 complaint (&symfile_complaints
,
7938 _("misplaced first line number at 0x%lx for '%s'"),
7939 (unsigned long) address
, fn
->name
);
7944 /* Decode the Line Number Program (LNP) for the given line_header
7945 structure and CU. The actual information extracted and the type
7946 of structures created from the LNP depends on the value of PST.
7948 1. If PST is NULL, then this procedure uses the data from the program
7949 to create all necessary symbol tables, and their linetables.
7950 The compilation directory of the file is passed in COMP_DIR,
7951 and must not be NULL.
7953 2. If PST is not NULL, this procedure reads the program to determine
7954 the list of files included by the unit represented by PST, and
7955 builds all the associated partial symbol tables. In this case,
7956 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7957 is not used to compute the full name of the symtab, and therefore
7958 omitting it when building the partial symtab does not introduce
7959 the potential for inconsistency - a partial symtab and its associated
7960 symbtab having a different fullname -). */
7963 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7964 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7966 gdb_byte
*line_ptr
, *extended_end
;
7968 unsigned int bytes_read
, extended_len
;
7969 unsigned char op_code
, extended_op
, adj_opcode
;
7971 struct objfile
*objfile
= cu
->objfile
;
7972 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7973 const int decode_for_pst_p
= (pst
!= NULL
);
7974 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7976 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7978 line_ptr
= lh
->statement_program_start
;
7979 line_end
= lh
->statement_program_end
;
7981 /* Read the statement sequences until there's nothing left. */
7982 while (line_ptr
< line_end
)
7984 /* state machine registers */
7985 CORE_ADDR address
= 0;
7986 unsigned int file
= 1;
7987 unsigned int line
= 1;
7988 unsigned int column
= 0;
7989 int is_stmt
= lh
->default_is_stmt
;
7990 int basic_block
= 0;
7991 int end_sequence
= 0;
7994 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7996 /* Start a subfile for the current file of the state machine. */
7997 /* lh->include_dirs and lh->file_names are 0-based, but the
7998 directory and file name numbers in the statement program
8000 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8004 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8006 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8009 /* Decode the table. */
8010 while (!end_sequence
)
8012 op_code
= read_1_byte (abfd
, line_ptr
);
8014 if (line_ptr
> line_end
)
8016 dwarf2_debug_line_missing_end_sequence_complaint ();
8020 if (op_code
>= lh
->opcode_base
)
8022 /* Special operand. */
8023 adj_opcode
= op_code
- lh
->opcode_base
;
8024 address
+= (adj_opcode
/ lh
->line_range
)
8025 * lh
->minimum_instruction_length
;
8026 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
8027 if (lh
->num_file_names
< file
|| file
== 0)
8028 dwarf2_debug_line_missing_file_complaint ();
8031 lh
->file_names
[file
- 1].included_p
= 1;
8032 if (!decode_for_pst_p
&& is_stmt
)
8034 if (last_subfile
!= current_subfile
)
8036 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8038 record_line (last_subfile
, 0, addr
);
8039 last_subfile
= current_subfile
;
8041 /* Append row to matrix using current values. */
8042 addr
= check_cu_functions (address
, cu
);
8043 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8044 record_line (current_subfile
, line
, addr
);
8049 else switch (op_code
)
8051 case DW_LNS_extended_op
:
8052 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8053 line_ptr
+= bytes_read
;
8054 extended_end
= line_ptr
+ extended_len
;
8055 extended_op
= read_1_byte (abfd
, line_ptr
);
8057 switch (extended_op
)
8059 case DW_LNE_end_sequence
:
8062 case DW_LNE_set_address
:
8063 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
8064 line_ptr
+= bytes_read
;
8065 address
+= baseaddr
;
8067 case DW_LNE_define_file
:
8070 unsigned int dir_index
, mod_time
, length
;
8072 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
8073 line_ptr
+= bytes_read
;
8075 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8076 line_ptr
+= bytes_read
;
8078 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8079 line_ptr
+= bytes_read
;
8081 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8082 line_ptr
+= bytes_read
;
8083 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
8086 case DW_LNE_set_discriminator
:
8087 /* The discriminator is not interesting to the debugger;
8089 line_ptr
= extended_end
;
8092 complaint (&symfile_complaints
,
8093 _("mangled .debug_line section"));
8096 /* Make sure that we parsed the extended op correctly. If e.g.
8097 we expected a different address size than the producer used,
8098 we may have read the wrong number of bytes. */
8099 if (line_ptr
!= extended_end
)
8101 complaint (&symfile_complaints
,
8102 _("mangled .debug_line section"));
8107 if (lh
->num_file_names
< file
|| file
== 0)
8108 dwarf2_debug_line_missing_file_complaint ();
8111 lh
->file_names
[file
- 1].included_p
= 1;
8112 if (!decode_for_pst_p
&& is_stmt
)
8114 if (last_subfile
!= current_subfile
)
8116 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8118 record_line (last_subfile
, 0, addr
);
8119 last_subfile
= current_subfile
;
8121 addr
= check_cu_functions (address
, cu
);
8122 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
8123 record_line (current_subfile
, line
, addr
);
8128 case DW_LNS_advance_pc
:
8129 address
+= lh
->minimum_instruction_length
8130 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8131 line_ptr
+= bytes_read
;
8133 case DW_LNS_advance_line
:
8134 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
8135 line_ptr
+= bytes_read
;
8137 case DW_LNS_set_file
:
8139 /* The arrays lh->include_dirs and lh->file_names are
8140 0-based, but the directory and file name numbers in
8141 the statement program are 1-based. */
8142 struct file_entry
*fe
;
8145 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8146 line_ptr
+= bytes_read
;
8147 if (lh
->num_file_names
< file
|| file
== 0)
8148 dwarf2_debug_line_missing_file_complaint ();
8151 fe
= &lh
->file_names
[file
- 1];
8153 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8154 if (!decode_for_pst_p
)
8156 last_subfile
= current_subfile
;
8157 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8162 case DW_LNS_set_column
:
8163 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8164 line_ptr
+= bytes_read
;
8166 case DW_LNS_negate_stmt
:
8167 is_stmt
= (!is_stmt
);
8169 case DW_LNS_set_basic_block
:
8172 /* Add to the address register of the state machine the
8173 address increment value corresponding to special opcode
8174 255. I.e., this value is scaled by the minimum
8175 instruction length since special opcode 255 would have
8176 scaled the the increment. */
8177 case DW_LNS_const_add_pc
:
8178 address
+= (lh
->minimum_instruction_length
8179 * ((255 - lh
->opcode_base
) / lh
->line_range
));
8181 case DW_LNS_fixed_advance_pc
:
8182 address
+= read_2_bytes (abfd
, line_ptr
);
8187 /* Unknown standard opcode, ignore it. */
8190 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
8192 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
8193 line_ptr
+= bytes_read
;
8198 if (lh
->num_file_names
< file
|| file
== 0)
8199 dwarf2_debug_line_missing_file_complaint ();
8202 lh
->file_names
[file
- 1].included_p
= 1;
8203 if (!decode_for_pst_p
)
8205 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
8206 record_line (current_subfile
, 0, addr
);
8211 if (decode_for_pst_p
)
8215 /* Now that we're done scanning the Line Header Program, we can
8216 create the psymtab of each included file. */
8217 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
8218 if (lh
->file_names
[file_index
].included_p
== 1)
8220 const struct file_entry fe
= lh
->file_names
[file_index
];
8221 char *include_name
= fe
.name
;
8222 char *dir_name
= NULL
;
8223 char *pst_filename
= pst
->filename
;
8226 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
8228 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
8230 include_name
= concat (dir_name
, SLASH_STRING
,
8231 include_name
, (char *)NULL
);
8232 make_cleanup (xfree
, include_name
);
8235 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
8237 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
8238 pst_filename
, (char *)NULL
);
8239 make_cleanup (xfree
, pst_filename
);
8242 if (strcmp (include_name
, pst_filename
) != 0)
8243 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
8248 /* Make sure a symtab is created for every file, even files
8249 which contain only variables (i.e. no code with associated
8253 struct file_entry
*fe
;
8255 for (i
= 0; i
< lh
->num_file_names
; i
++)
8258 fe
= &lh
->file_names
[i
];
8260 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8261 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
8263 /* Skip the main file; we don't need it, and it must be
8264 allocated last, so that it will show up before the
8265 non-primary symtabs in the objfile's symtab list. */
8266 if (current_subfile
== first_subfile
)
8269 if (current_subfile
->symtab
== NULL
)
8270 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
8272 fe
->symtab
= current_subfile
->symtab
;
8277 /* Start a subfile for DWARF. FILENAME is the name of the file and
8278 DIRNAME the name of the source directory which contains FILENAME
8279 or NULL if not known. COMP_DIR is the compilation directory for the
8280 linetable's compilation unit or NULL if not known.
8281 This routine tries to keep line numbers from identical absolute and
8282 relative file names in a common subfile.
8284 Using the `list' example from the GDB testsuite, which resides in
8285 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
8286 of /srcdir/list0.c yields the following debugging information for list0.c:
8288 DW_AT_name: /srcdir/list0.c
8289 DW_AT_comp_dir: /compdir
8290 files.files[0].name: list0.h
8291 files.files[0].dir: /srcdir
8292 files.files[1].name: list0.c
8293 files.files[1].dir: /srcdir
8295 The line number information for list0.c has to end up in a single
8296 subfile, so that `break /srcdir/list0.c:1' works as expected.
8297 start_subfile will ensure that this happens provided that we pass the
8298 concatenation of files.files[1].dir and files.files[1].name as the
8302 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
8306 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
8307 `start_symtab' will always pass the contents of DW_AT_comp_dir as
8308 second argument to start_subfile. To be consistent, we do the
8309 same here. In order not to lose the line information directory,
8310 we concatenate it to the filename when it makes sense.
8311 Note that the Dwarf3 standard says (speaking of filenames in line
8312 information): ``The directory index is ignored for file names
8313 that represent full path names''. Thus ignoring dirname in the
8314 `else' branch below isn't an issue. */
8316 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
8317 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
8319 fullname
= filename
;
8321 start_subfile (fullname
, comp_dir
);
8323 if (fullname
!= filename
)
8328 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
8329 struct dwarf2_cu
*cu
)
8331 struct objfile
*objfile
= cu
->objfile
;
8332 struct comp_unit_head
*cu_header
= &cu
->header
;
8334 /* NOTE drow/2003-01-30: There used to be a comment and some special
8335 code here to turn a symbol with DW_AT_external and a
8336 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
8337 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
8338 with some versions of binutils) where shared libraries could have
8339 relocations against symbols in their debug information - the
8340 minimal symbol would have the right address, but the debug info
8341 would not. It's no longer necessary, because we will explicitly
8342 apply relocations when we read in the debug information now. */
8344 /* A DW_AT_location attribute with no contents indicates that a
8345 variable has been optimized away. */
8346 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
8348 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8352 /* Handle one degenerate form of location expression specially, to
8353 preserve GDB's previous behavior when section offsets are
8354 specified. If this is just a DW_OP_addr then mark this symbol
8357 if (attr_form_is_block (attr
)
8358 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
8359 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
8363 SYMBOL_VALUE_ADDRESS (sym
) =
8364 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
8365 SYMBOL_CLASS (sym
) = LOC_STATIC
;
8366 fixup_symbol_section (sym
, objfile
);
8367 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
8368 SYMBOL_SECTION (sym
));
8372 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
8373 expression evaluator, and use LOC_COMPUTED only when necessary
8374 (i.e. when the value of a register or memory location is
8375 referenced, or a thread-local block, etc.). Then again, it might
8376 not be worthwhile. I'm assuming that it isn't unless performance
8377 or memory numbers show me otherwise. */
8379 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
8380 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
8383 /* Given a pointer to a DWARF information entry, figure out if we need
8384 to make a symbol table entry for it, and if so, create a new entry
8385 and return a pointer to it.
8386 If TYPE is NULL, determine symbol type from the die, otherwise
8387 used the passed type. */
8389 static struct symbol
*
8390 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
8392 struct objfile
*objfile
= cu
->objfile
;
8393 struct symbol
*sym
= NULL
;
8395 struct attribute
*attr
= NULL
;
8396 struct attribute
*attr2
= NULL
;
8398 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
8400 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
8402 name
= dwarf2_name (die
, cu
);
8405 const char *linkagename
;
8407 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
8408 sizeof (struct symbol
));
8409 OBJSTAT (objfile
, n_syms
++);
8410 memset (sym
, 0, sizeof (struct symbol
));
8412 /* Cache this symbol's name and the name's demangled form (if any). */
8413 SYMBOL_LANGUAGE (sym
) = cu
->language
;
8414 linkagename
= dwarf2_physname (name
, die
, cu
);
8415 SYMBOL_SET_NAMES (sym
, linkagename
, strlen (linkagename
), 0, objfile
);
8417 /* Default assumptions.
8418 Use the passed type or decode it from the die. */
8419 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8420 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
8422 SYMBOL_TYPE (sym
) = type
;
8424 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
8425 attr
= dwarf2_attr (die
,
8426 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
8430 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
8433 attr
= dwarf2_attr (die
,
8434 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
8438 int file_index
= DW_UNSND (attr
);
8439 if (cu
->line_header
== NULL
8440 || file_index
> cu
->line_header
->num_file_names
)
8441 complaint (&symfile_complaints
,
8442 _("file index out of range"));
8443 else if (file_index
> 0)
8445 struct file_entry
*fe
;
8446 fe
= &cu
->line_header
->file_names
[file_index
- 1];
8447 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
8454 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
8457 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
8459 SYMBOL_CLASS (sym
) = LOC_LABEL
;
8461 case DW_TAG_subprogram
:
8462 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8464 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8465 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8466 if ((attr2
&& (DW_UNSND (attr2
) != 0))
8467 || cu
->language
== language_ada
)
8469 /* Subprograms marked external are stored as a global symbol.
8470 Ada subprograms, whether marked external or not, are always
8471 stored as a global symbol, because we want to be able to
8472 access them globally. For instance, we want to be able
8473 to break on a nested subprogram without having to
8474 specify the context. */
8475 add_symbol_to_list (sym
, &global_symbols
);
8479 add_symbol_to_list (sym
, cu
->list_in_scope
);
8482 case DW_TAG_inlined_subroutine
:
8483 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
8485 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
8486 SYMBOL_INLINED (sym
) = 1;
8487 /* Do not add the symbol to any lists. It will be found via
8488 BLOCK_FUNCTION from the blockvector. */
8490 case DW_TAG_variable
:
8491 /* Compilation with minimal debug info may result in variables
8492 with missing type entries. Change the misleading `void' type
8493 to something sensible. */
8494 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
8496 = objfile_type (objfile
)->nodebug_data_symbol
;
8498 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8501 dwarf2_const_value (attr
, sym
, cu
);
8502 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8503 if (attr2
&& (DW_UNSND (attr2
) != 0))
8504 add_symbol_to_list (sym
, &global_symbols
);
8506 add_symbol_to_list (sym
, cu
->list_in_scope
);
8509 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8512 var_decode_location (attr
, sym
, cu
);
8513 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8514 if (attr2
&& (DW_UNSND (attr2
) != 0))
8515 add_symbol_to_list (sym
, &global_symbols
);
8517 add_symbol_to_list (sym
, cu
->list_in_scope
);
8521 /* We do not know the address of this symbol.
8522 If it is an external symbol and we have type information
8523 for it, enter the symbol as a LOC_UNRESOLVED symbol.
8524 The address of the variable will then be determined from
8525 the minimal symbol table whenever the variable is
8527 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
8528 if (attr2
&& (DW_UNSND (attr2
) != 0)
8529 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
8531 struct pending
**list_to_add
;
8533 /* A variable with DW_AT_external is never static, but it
8534 may be block-scoped. */
8535 list_to_add
= (cu
->list_in_scope
== &file_symbols
8536 ? &global_symbols
: cu
->list_in_scope
);
8538 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
8539 add_symbol_to_list (sym
, list_to_add
);
8541 else if (!die_is_declaration (die
, cu
))
8543 /* Use the default LOC_OPTIMIZED_OUT class. */
8544 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
8545 add_symbol_to_list (sym
, cu
->list_in_scope
);
8549 case DW_TAG_formal_parameter
:
8550 /* If we are inside a function, mark this as an argument. If
8551 not, we might be looking at an argument to an inlined function
8552 when we do not have enough information to show inlined frames;
8553 pretend it's a local variable in that case so that the user can
8555 if (context_stack_depth
> 0
8556 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
8557 SYMBOL_IS_ARGUMENT (sym
) = 1;
8558 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
8561 var_decode_location (attr
, sym
, cu
);
8563 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8566 dwarf2_const_value (attr
, sym
, cu
);
8568 add_symbol_to_list (sym
, cu
->list_in_scope
);
8570 case DW_TAG_unspecified_parameters
:
8571 /* From varargs functions; gdb doesn't seem to have any
8572 interest in this information, so just ignore it for now.
8575 case DW_TAG_class_type
:
8576 case DW_TAG_interface_type
:
8577 case DW_TAG_structure_type
:
8578 case DW_TAG_union_type
:
8579 case DW_TAG_set_type
:
8580 case DW_TAG_enumeration_type
:
8581 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8582 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
8584 /* Make sure that the symbol includes appropriate enclosing
8585 classes/namespaces in its name. These are calculated in
8586 read_structure_type, and the correct name is saved in
8589 if (cu
->language
== language_cplus
8590 || cu
->language
== language_java
)
8592 struct type
*type
= SYMBOL_TYPE (sym
);
8594 if (TYPE_TAG_NAME (type
) != NULL
)
8596 /* FIXME: carlton/2003-11-10: Should this use
8597 SYMBOL_SET_NAMES instead? (The same problem also
8598 arises further down in this function.) */
8599 /* The type's name is already allocated along with
8600 this objfile, so we don't need to duplicate it
8602 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
8607 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
8608 really ever be static objects: otherwise, if you try
8609 to, say, break of a class's method and you're in a file
8610 which doesn't mention that class, it won't work unless
8611 the check for all static symbols in lookup_symbol_aux
8612 saves you. See the OtherFileClass tests in
8613 gdb.c++/namespace.exp. */
8615 struct pending
**list_to_add
;
8617 list_to_add
= (cu
->list_in_scope
== &file_symbols
8618 && (cu
->language
== language_cplus
8619 || cu
->language
== language_java
)
8620 ? &global_symbols
: cu
->list_in_scope
);
8622 add_symbol_to_list (sym
, list_to_add
);
8624 /* The semantics of C++ state that "struct foo { ... }" also
8625 defines a typedef for "foo". A Java class declaration also
8626 defines a typedef for the class. */
8627 if (cu
->language
== language_cplus
8628 || cu
->language
== language_java
8629 || cu
->language
== language_ada
)
8631 /* The symbol's name is already allocated along with
8632 this objfile, so we don't need to duplicate it for
8634 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
8635 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
8639 case DW_TAG_typedef
:
8640 SYMBOL_LINKAGE_NAME (sym
)
8641 = (char *) dwarf2_full_name (name
, die
, cu
);
8642 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8643 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8644 add_symbol_to_list (sym
, cu
->list_in_scope
);
8646 case DW_TAG_base_type
:
8647 case DW_TAG_subrange_type
:
8648 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8649 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
8650 add_symbol_to_list (sym
, cu
->list_in_scope
);
8652 case DW_TAG_enumerator
:
8653 SYMBOL_LINKAGE_NAME (sym
)
8654 = (char *) dwarf2_full_name (name
, die
, cu
);
8655 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
8658 dwarf2_const_value (attr
, sym
, cu
);
8661 /* NOTE: carlton/2003-11-10: See comment above in the
8662 DW_TAG_class_type, etc. block. */
8664 struct pending
**list_to_add
;
8666 list_to_add
= (cu
->list_in_scope
== &file_symbols
8667 && (cu
->language
== language_cplus
8668 || cu
->language
== language_java
)
8669 ? &global_symbols
: cu
->list_in_scope
);
8671 add_symbol_to_list (sym
, list_to_add
);
8674 case DW_TAG_namespace
:
8675 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8676 add_symbol_to_list (sym
, &global_symbols
);
8679 /* Not a tag we recognize. Hopefully we aren't processing
8680 trash data, but since we must specifically ignore things
8681 we don't recognize, there is nothing else we should do at
8683 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8684 dwarf_tag_name (die
->tag
));
8688 /* For the benefit of old versions of GCC, check for anonymous
8689 namespaces based on the demangled name. */
8690 if (!processing_has_namespace_info
8691 && cu
->language
== language_cplus
)
8692 cp_scan_for_anonymous_namespaces (sym
);
8697 /* Copy constant value from an attribute to a symbol. */
8700 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8701 struct dwarf2_cu
*cu
)
8703 struct objfile
*objfile
= cu
->objfile
;
8704 struct comp_unit_head
*cu_header
= &cu
->header
;
8705 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
) ?
8706 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
8707 struct dwarf_block
*blk
;
8712 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8713 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8714 cu_header
->addr_size
,
8715 TYPE_LENGTH (SYMBOL_TYPE
8717 SYMBOL_VALUE_BYTES (sym
) =
8718 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8719 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8720 it's body - store_unsigned_integer. */
8721 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8722 byte_order
, DW_ADDR (attr
));
8723 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8725 case DW_FORM_string
:
8727 /* DW_STRING is already allocated on the obstack, point directly
8729 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8730 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8732 case DW_FORM_block1
:
8733 case DW_FORM_block2
:
8734 case DW_FORM_block4
:
8736 blk
= DW_BLOCK (attr
);
8737 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8738 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8740 TYPE_LENGTH (SYMBOL_TYPE
8742 SYMBOL_VALUE_BYTES (sym
) =
8743 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8744 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8745 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8748 /* The DW_AT_const_value attributes are supposed to carry the
8749 symbol's value "represented as it would be on the target
8750 architecture." By the time we get here, it's already been
8751 converted to host endianness, so we just need to sign- or
8752 zero-extend it as appropriate. */
8754 dwarf2_const_value_data (attr
, sym
, 8);
8757 dwarf2_const_value_data (attr
, sym
, 16);
8760 dwarf2_const_value_data (attr
, sym
, 32);
8763 dwarf2_const_value_data (attr
, sym
, 64);
8767 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8768 SYMBOL_CLASS (sym
) = LOC_CONST
;
8772 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8773 SYMBOL_CLASS (sym
) = LOC_CONST
;
8777 complaint (&symfile_complaints
,
8778 _("unsupported const value attribute form: '%s'"),
8779 dwarf_form_name (attr
->form
));
8780 SYMBOL_VALUE (sym
) = 0;
8781 SYMBOL_CLASS (sym
) = LOC_CONST
;
8787 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8788 or zero-extend it as appropriate for the symbol's type. */
8790 dwarf2_const_value_data (struct attribute
*attr
,
8794 LONGEST l
= DW_UNSND (attr
);
8796 if (bits
< sizeof (l
) * 8)
8798 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8799 l
&= ((LONGEST
) 1 << bits
) - 1;
8801 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8804 SYMBOL_VALUE (sym
) = l
;
8805 SYMBOL_CLASS (sym
) = LOC_CONST
;
8809 /* Return the type of the die in question using its DW_AT_type attribute. */
8811 static struct type
*
8812 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8815 struct attribute
*type_attr
;
8816 struct die_info
*type_die
;
8818 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8821 /* A missing DW_AT_type represents a void type. */
8822 return objfile_type (cu
->objfile
)->builtin_void
;
8825 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8827 type
= tag_type_to_type (type_die
, cu
);
8830 dump_die_for_error (type_die
);
8831 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8837 /* True iff CU's producer generates GNAT Ada auxiliary information
8838 that allows to find parallel types through that information instead
8839 of having to do expensive parallel lookups by type name. */
8842 need_gnat_info (struct dwarf2_cu
*cu
)
8844 /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version
8845 of GNAT produces this auxiliary information, without any indication
8846 that it is produced. Part of enhancing the FSF version of GNAT
8847 to produce that information will be to put in place an indicator
8848 that we can use in order to determine whether the descriptive type
8849 info is available or not. One suggestion that has been made is
8850 to use a new attribute, attached to the CU die. For now, assume
8851 that the descriptive type info is not available. */
8856 /* Return the auxiliary type of the die in question using its
8857 DW_AT_GNAT_descriptive_type attribute. Returns NULL if the
8858 attribute is not present. */
8860 static struct type
*
8861 die_descriptive_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8864 struct attribute
*type_attr
;
8865 struct die_info
*type_die
;
8867 type_attr
= dwarf2_attr (die
, DW_AT_GNAT_descriptive_type
, cu
);
8871 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8872 type
= tag_type_to_type (type_die
, cu
);
8875 dump_die_for_error (type_die
);
8876 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8882 /* If DIE has a descriptive_type attribute, then set the TYPE's
8883 descriptive type accordingly. */
8886 set_descriptive_type (struct type
*type
, struct die_info
*die
,
8887 struct dwarf2_cu
*cu
)
8889 struct type
*descriptive_type
= die_descriptive_type (die
, cu
);
8891 if (descriptive_type
)
8893 ALLOCATE_GNAT_AUX_TYPE (type
);
8894 TYPE_DESCRIPTIVE_TYPE (type
) = descriptive_type
;
8898 /* Return the containing type of the die in question using its
8899 DW_AT_containing_type attribute. */
8901 static struct type
*
8902 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8904 struct type
*type
= NULL
;
8905 struct attribute
*type_attr
;
8906 struct die_info
*type_die
= NULL
;
8908 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8911 type_die
= follow_die_ref_or_sig (die
, type_attr
, &cu
);
8912 type
= tag_type_to_type (type_die
, cu
);
8917 dump_die_for_error (type_die
);
8918 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8924 static struct type
*
8925 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8927 struct type
*this_type
;
8929 this_type
= read_type_die (die
, cu
);
8932 dump_die_for_error (die
);
8933 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8939 static struct type
*
8940 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8942 struct type
*this_type
;
8944 this_type
= get_die_type (die
, cu
);
8950 case DW_TAG_class_type
:
8951 case DW_TAG_interface_type
:
8952 case DW_TAG_structure_type
:
8953 case DW_TAG_union_type
:
8954 this_type
= read_structure_type (die
, cu
);
8956 case DW_TAG_enumeration_type
:
8957 this_type
= read_enumeration_type (die
, cu
);
8959 case DW_TAG_subprogram
:
8960 case DW_TAG_subroutine_type
:
8961 case DW_TAG_inlined_subroutine
:
8962 this_type
= read_subroutine_type (die
, cu
);
8964 case DW_TAG_array_type
:
8965 this_type
= read_array_type (die
, cu
);
8967 case DW_TAG_set_type
:
8968 this_type
= read_set_type (die
, cu
);
8970 case DW_TAG_pointer_type
:
8971 this_type
= read_tag_pointer_type (die
, cu
);
8973 case DW_TAG_ptr_to_member_type
:
8974 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8976 case DW_TAG_reference_type
:
8977 this_type
= read_tag_reference_type (die
, cu
);
8979 case DW_TAG_const_type
:
8980 this_type
= read_tag_const_type (die
, cu
);
8982 case DW_TAG_volatile_type
:
8983 this_type
= read_tag_volatile_type (die
, cu
);
8985 case DW_TAG_string_type
:
8986 this_type
= read_tag_string_type (die
, cu
);
8988 case DW_TAG_typedef
:
8989 this_type
= read_typedef (die
, cu
);
8991 case DW_TAG_subrange_type
:
8992 this_type
= read_subrange_type (die
, cu
);
8994 case DW_TAG_base_type
:
8995 this_type
= read_base_type (die
, cu
);
8997 case DW_TAG_unspecified_type
:
8998 this_type
= read_unspecified_type (die
, cu
);
9000 case DW_TAG_namespace
:
9001 this_type
= read_namespace_type (die
, cu
);
9004 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
9005 dwarf_tag_name (die
->tag
));
9012 /* Return the name of the namespace/class that DIE is defined within,
9013 or "" if we can't tell. The caller should not xfree the result.
9015 For example, if we're within the method foo() in the following
9025 then determine_prefix on foo's die will return "N::C". */
9028 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
9030 struct die_info
*parent
, *spec_die
;
9031 struct dwarf2_cu
*spec_cu
;
9032 struct type
*parent_type
;
9034 if (cu
->language
!= language_cplus
9035 && cu
->language
!= language_java
)
9038 /* We have to be careful in the presence of DW_AT_specification.
9039 For example, with GCC 3.4, given the code
9043 // Definition of N::foo.
9047 then we'll have a tree of DIEs like this:
9049 1: DW_TAG_compile_unit
9050 2: DW_TAG_namespace // N
9051 3: DW_TAG_subprogram // declaration of N::foo
9052 4: DW_TAG_subprogram // definition of N::foo
9053 DW_AT_specification // refers to die #3
9055 Thus, when processing die #4, we have to pretend that we're in
9056 the context of its DW_AT_specification, namely the contex of die
9059 spec_die
= die_specification (die
, &spec_cu
);
9060 if (spec_die
== NULL
)
9061 parent
= die
->parent
;
9064 parent
= spec_die
->parent
;
9071 switch (parent
->tag
)
9073 case DW_TAG_namespace
:
9074 parent_type
= read_type_die (parent
, cu
);
9075 /* We give a name to even anonymous namespaces. */
9076 return TYPE_TAG_NAME (parent_type
);
9077 case DW_TAG_class_type
:
9078 case DW_TAG_interface_type
:
9079 case DW_TAG_structure_type
:
9080 case DW_TAG_union_type
:
9081 parent_type
= read_type_die (parent
, cu
);
9082 if (TYPE_TAG_NAME (parent_type
) != NULL
)
9083 return TYPE_TAG_NAME (parent_type
);
9085 /* An anonymous structure is only allowed non-static data
9086 members; no typedefs, no member functions, et cetera.
9087 So it does not need a prefix. */
9090 return determine_prefix (parent
, cu
);
9094 /* Return a newly-allocated string formed by concatenating PREFIX and
9095 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
9096 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
9097 perform an obconcat, otherwise allocate storage for the result. The CU argument
9098 is used to determine the language and hence, the appropriate separator. */
9100 #define MAX_SEP_LEN 2 /* sizeof ("::") */
9103 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
9104 struct dwarf2_cu
*cu
)
9108 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
9110 else if (cu
->language
== language_java
)
9122 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
9123 strcpy (retval
, prefix
);
9124 strcat (retval
, sep
);
9125 strcat (retval
, suffix
);
9130 /* We have an obstack. */
9131 return obconcat (obs
, prefix
, sep
, suffix
);
9135 /* Return sibling of die, NULL if no sibling. */
9137 static struct die_info
*
9138 sibling_die (struct die_info
*die
)
9140 return die
->sibling
;
9143 /* Get name of a die, return NULL if not found. */
9146 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
9147 struct obstack
*obstack
)
9149 if (name
&& cu
->language
== language_cplus
)
9151 char *canon_name
= cp_canonicalize_string (name
);
9153 if (canon_name
!= NULL
)
9155 if (strcmp (canon_name
, name
) != 0)
9156 name
= obsavestring (canon_name
, strlen (canon_name
),
9165 /* Get name of a die, return NULL if not found. */
9168 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
9170 struct attribute
*attr
;
9172 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
9173 if (!attr
|| !DW_STRING (attr
))
9178 case DW_TAG_compile_unit
:
9179 /* Compilation units have a DW_AT_name that is a filename, not
9180 a source language identifier. */
9181 case DW_TAG_enumeration_type
:
9182 case DW_TAG_enumerator
:
9183 /* These tags always have simple identifiers already; no need
9184 to canonicalize them. */
9185 return DW_STRING (attr
);
9187 if (!DW_STRING_IS_CANONICAL (attr
))
9190 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
9191 &cu
->objfile
->objfile_obstack
);
9192 DW_STRING_IS_CANONICAL (attr
) = 1;
9194 return DW_STRING (attr
);
9198 /* Return the die that this die in an extension of, or NULL if there
9199 is none. *EXT_CU is the CU containing DIE on input, and the CU
9200 containing the return value on output. */
9202 static struct die_info
*
9203 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
9205 struct attribute
*attr
;
9207 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
9211 return follow_die_ref (die
, attr
, ext_cu
);
9214 /* Convert a DIE tag into its string name. */
9217 dwarf_tag_name (unsigned tag
)
9221 case DW_TAG_padding
:
9222 return "DW_TAG_padding";
9223 case DW_TAG_array_type
:
9224 return "DW_TAG_array_type";
9225 case DW_TAG_class_type
:
9226 return "DW_TAG_class_type";
9227 case DW_TAG_entry_point
:
9228 return "DW_TAG_entry_point";
9229 case DW_TAG_enumeration_type
:
9230 return "DW_TAG_enumeration_type";
9231 case DW_TAG_formal_parameter
:
9232 return "DW_TAG_formal_parameter";
9233 case DW_TAG_imported_declaration
:
9234 return "DW_TAG_imported_declaration";
9236 return "DW_TAG_label";
9237 case DW_TAG_lexical_block
:
9238 return "DW_TAG_lexical_block";
9240 return "DW_TAG_member";
9241 case DW_TAG_pointer_type
:
9242 return "DW_TAG_pointer_type";
9243 case DW_TAG_reference_type
:
9244 return "DW_TAG_reference_type";
9245 case DW_TAG_compile_unit
:
9246 return "DW_TAG_compile_unit";
9247 case DW_TAG_string_type
:
9248 return "DW_TAG_string_type";
9249 case DW_TAG_structure_type
:
9250 return "DW_TAG_structure_type";
9251 case DW_TAG_subroutine_type
:
9252 return "DW_TAG_subroutine_type";
9253 case DW_TAG_typedef
:
9254 return "DW_TAG_typedef";
9255 case DW_TAG_union_type
:
9256 return "DW_TAG_union_type";
9257 case DW_TAG_unspecified_parameters
:
9258 return "DW_TAG_unspecified_parameters";
9259 case DW_TAG_variant
:
9260 return "DW_TAG_variant";
9261 case DW_TAG_common_block
:
9262 return "DW_TAG_common_block";
9263 case DW_TAG_common_inclusion
:
9264 return "DW_TAG_common_inclusion";
9265 case DW_TAG_inheritance
:
9266 return "DW_TAG_inheritance";
9267 case DW_TAG_inlined_subroutine
:
9268 return "DW_TAG_inlined_subroutine";
9270 return "DW_TAG_module";
9271 case DW_TAG_ptr_to_member_type
:
9272 return "DW_TAG_ptr_to_member_type";
9273 case DW_TAG_set_type
:
9274 return "DW_TAG_set_type";
9275 case DW_TAG_subrange_type
:
9276 return "DW_TAG_subrange_type";
9277 case DW_TAG_with_stmt
:
9278 return "DW_TAG_with_stmt";
9279 case DW_TAG_access_declaration
:
9280 return "DW_TAG_access_declaration";
9281 case DW_TAG_base_type
:
9282 return "DW_TAG_base_type";
9283 case DW_TAG_catch_block
:
9284 return "DW_TAG_catch_block";
9285 case DW_TAG_const_type
:
9286 return "DW_TAG_const_type";
9287 case DW_TAG_constant
:
9288 return "DW_TAG_constant";
9289 case DW_TAG_enumerator
:
9290 return "DW_TAG_enumerator";
9291 case DW_TAG_file_type
:
9292 return "DW_TAG_file_type";
9294 return "DW_TAG_friend";
9295 case DW_TAG_namelist
:
9296 return "DW_TAG_namelist";
9297 case DW_TAG_namelist_item
:
9298 return "DW_TAG_namelist_item";
9299 case DW_TAG_packed_type
:
9300 return "DW_TAG_packed_type";
9301 case DW_TAG_subprogram
:
9302 return "DW_TAG_subprogram";
9303 case DW_TAG_template_type_param
:
9304 return "DW_TAG_template_type_param";
9305 case DW_TAG_template_value_param
:
9306 return "DW_TAG_template_value_param";
9307 case DW_TAG_thrown_type
:
9308 return "DW_TAG_thrown_type";
9309 case DW_TAG_try_block
:
9310 return "DW_TAG_try_block";
9311 case DW_TAG_variant_part
:
9312 return "DW_TAG_variant_part";
9313 case DW_TAG_variable
:
9314 return "DW_TAG_variable";
9315 case DW_TAG_volatile_type
:
9316 return "DW_TAG_volatile_type";
9317 case DW_TAG_dwarf_procedure
:
9318 return "DW_TAG_dwarf_procedure";
9319 case DW_TAG_restrict_type
:
9320 return "DW_TAG_restrict_type";
9321 case DW_TAG_interface_type
:
9322 return "DW_TAG_interface_type";
9323 case DW_TAG_namespace
:
9324 return "DW_TAG_namespace";
9325 case DW_TAG_imported_module
:
9326 return "DW_TAG_imported_module";
9327 case DW_TAG_unspecified_type
:
9328 return "DW_TAG_unspecified_type";
9329 case DW_TAG_partial_unit
:
9330 return "DW_TAG_partial_unit";
9331 case DW_TAG_imported_unit
:
9332 return "DW_TAG_imported_unit";
9333 case DW_TAG_condition
:
9334 return "DW_TAG_condition";
9335 case DW_TAG_shared_type
:
9336 return "DW_TAG_shared_type";
9337 case DW_TAG_type_unit
:
9338 return "DW_TAG_type_unit";
9339 case DW_TAG_MIPS_loop
:
9340 return "DW_TAG_MIPS_loop";
9341 case DW_TAG_HP_array_descriptor
:
9342 return "DW_TAG_HP_array_descriptor";
9343 case DW_TAG_format_label
:
9344 return "DW_TAG_format_label";
9345 case DW_TAG_function_template
:
9346 return "DW_TAG_function_template";
9347 case DW_TAG_class_template
:
9348 return "DW_TAG_class_template";
9349 case DW_TAG_GNU_BINCL
:
9350 return "DW_TAG_GNU_BINCL";
9351 case DW_TAG_GNU_EINCL
:
9352 return "DW_TAG_GNU_EINCL";
9353 case DW_TAG_upc_shared_type
:
9354 return "DW_TAG_upc_shared_type";
9355 case DW_TAG_upc_strict_type
:
9356 return "DW_TAG_upc_strict_type";
9357 case DW_TAG_upc_relaxed_type
:
9358 return "DW_TAG_upc_relaxed_type";
9359 case DW_TAG_PGI_kanji_type
:
9360 return "DW_TAG_PGI_kanji_type";
9361 case DW_TAG_PGI_interface_block
:
9362 return "DW_TAG_PGI_interface_block";
9364 return "DW_TAG_<unknown>";
9368 /* Convert a DWARF attribute code into its string name. */
9371 dwarf_attr_name (unsigned attr
)
9376 return "DW_AT_sibling";
9377 case DW_AT_location
:
9378 return "DW_AT_location";
9380 return "DW_AT_name";
9381 case DW_AT_ordering
:
9382 return "DW_AT_ordering";
9383 case DW_AT_subscr_data
:
9384 return "DW_AT_subscr_data";
9385 case DW_AT_byte_size
:
9386 return "DW_AT_byte_size";
9387 case DW_AT_bit_offset
:
9388 return "DW_AT_bit_offset";
9389 case DW_AT_bit_size
:
9390 return "DW_AT_bit_size";
9391 case DW_AT_element_list
:
9392 return "DW_AT_element_list";
9393 case DW_AT_stmt_list
:
9394 return "DW_AT_stmt_list";
9396 return "DW_AT_low_pc";
9398 return "DW_AT_high_pc";
9399 case DW_AT_language
:
9400 return "DW_AT_language";
9402 return "DW_AT_member";
9404 return "DW_AT_discr";
9405 case DW_AT_discr_value
:
9406 return "DW_AT_discr_value";
9407 case DW_AT_visibility
:
9408 return "DW_AT_visibility";
9410 return "DW_AT_import";
9411 case DW_AT_string_length
:
9412 return "DW_AT_string_length";
9413 case DW_AT_common_reference
:
9414 return "DW_AT_common_reference";
9415 case DW_AT_comp_dir
:
9416 return "DW_AT_comp_dir";
9417 case DW_AT_const_value
:
9418 return "DW_AT_const_value";
9419 case DW_AT_containing_type
:
9420 return "DW_AT_containing_type";
9421 case DW_AT_default_value
:
9422 return "DW_AT_default_value";
9424 return "DW_AT_inline";
9425 case DW_AT_is_optional
:
9426 return "DW_AT_is_optional";
9427 case DW_AT_lower_bound
:
9428 return "DW_AT_lower_bound";
9429 case DW_AT_producer
:
9430 return "DW_AT_producer";
9431 case DW_AT_prototyped
:
9432 return "DW_AT_prototyped";
9433 case DW_AT_return_addr
:
9434 return "DW_AT_return_addr";
9435 case DW_AT_start_scope
:
9436 return "DW_AT_start_scope";
9437 case DW_AT_bit_stride
:
9438 return "DW_AT_bit_stride";
9439 case DW_AT_upper_bound
:
9440 return "DW_AT_upper_bound";
9441 case DW_AT_abstract_origin
:
9442 return "DW_AT_abstract_origin";
9443 case DW_AT_accessibility
:
9444 return "DW_AT_accessibility";
9445 case DW_AT_address_class
:
9446 return "DW_AT_address_class";
9447 case DW_AT_artificial
:
9448 return "DW_AT_artificial";
9449 case DW_AT_base_types
:
9450 return "DW_AT_base_types";
9451 case DW_AT_calling_convention
:
9452 return "DW_AT_calling_convention";
9454 return "DW_AT_count";
9455 case DW_AT_data_member_location
:
9456 return "DW_AT_data_member_location";
9457 case DW_AT_decl_column
:
9458 return "DW_AT_decl_column";
9459 case DW_AT_decl_file
:
9460 return "DW_AT_decl_file";
9461 case DW_AT_decl_line
:
9462 return "DW_AT_decl_line";
9463 case DW_AT_declaration
:
9464 return "DW_AT_declaration";
9465 case DW_AT_discr_list
:
9466 return "DW_AT_discr_list";
9467 case DW_AT_encoding
:
9468 return "DW_AT_encoding";
9469 case DW_AT_external
:
9470 return "DW_AT_external";
9471 case DW_AT_frame_base
:
9472 return "DW_AT_frame_base";
9474 return "DW_AT_friend";
9475 case DW_AT_identifier_case
:
9476 return "DW_AT_identifier_case";
9477 case DW_AT_macro_info
:
9478 return "DW_AT_macro_info";
9479 case DW_AT_namelist_items
:
9480 return "DW_AT_namelist_items";
9481 case DW_AT_priority
:
9482 return "DW_AT_priority";
9484 return "DW_AT_segment";
9485 case DW_AT_specification
:
9486 return "DW_AT_specification";
9487 case DW_AT_static_link
:
9488 return "DW_AT_static_link";
9490 return "DW_AT_type";
9491 case DW_AT_use_location
:
9492 return "DW_AT_use_location";
9493 case DW_AT_variable_parameter
:
9494 return "DW_AT_variable_parameter";
9495 case DW_AT_virtuality
:
9496 return "DW_AT_virtuality";
9497 case DW_AT_vtable_elem_location
:
9498 return "DW_AT_vtable_elem_location";
9499 /* DWARF 3 values. */
9500 case DW_AT_allocated
:
9501 return "DW_AT_allocated";
9502 case DW_AT_associated
:
9503 return "DW_AT_associated";
9504 case DW_AT_data_location
:
9505 return "DW_AT_data_location";
9506 case DW_AT_byte_stride
:
9507 return "DW_AT_byte_stride";
9508 case DW_AT_entry_pc
:
9509 return "DW_AT_entry_pc";
9510 case DW_AT_use_UTF8
:
9511 return "DW_AT_use_UTF8";
9512 case DW_AT_extension
:
9513 return "DW_AT_extension";
9515 return "DW_AT_ranges";
9516 case DW_AT_trampoline
:
9517 return "DW_AT_trampoline";
9518 case DW_AT_call_column
:
9519 return "DW_AT_call_column";
9520 case DW_AT_call_file
:
9521 return "DW_AT_call_file";
9522 case DW_AT_call_line
:
9523 return "DW_AT_call_line";
9524 case DW_AT_description
:
9525 return "DW_AT_description";
9526 case DW_AT_binary_scale
:
9527 return "DW_AT_binary_scale";
9528 case DW_AT_decimal_scale
:
9529 return "DW_AT_decimal_scale";
9531 return "DW_AT_small";
9532 case DW_AT_decimal_sign
:
9533 return "DW_AT_decimal_sign";
9534 case DW_AT_digit_count
:
9535 return "DW_AT_digit_count";
9536 case DW_AT_picture_string
:
9537 return "DW_AT_picture_string";
9539 return "DW_AT_mutable";
9540 case DW_AT_threads_scaled
:
9541 return "DW_AT_threads_scaled";
9542 case DW_AT_explicit
:
9543 return "DW_AT_explicit";
9544 case DW_AT_object_pointer
:
9545 return "DW_AT_object_pointer";
9546 case DW_AT_endianity
:
9547 return "DW_AT_endianity";
9548 case DW_AT_elemental
:
9549 return "DW_AT_elemental";
9551 return "DW_AT_pure";
9552 case DW_AT_recursive
:
9553 return "DW_AT_recursive";
9554 /* DWARF 4 values. */
9555 case DW_AT_signature
:
9556 return "DW_AT_signature";
9557 /* SGI/MIPS extensions. */
9558 #ifdef MIPS /* collides with DW_AT_HP_block_index */
9559 case DW_AT_MIPS_fde
:
9560 return "DW_AT_MIPS_fde";
9562 case DW_AT_MIPS_loop_begin
:
9563 return "DW_AT_MIPS_loop_begin";
9564 case DW_AT_MIPS_tail_loop_begin
:
9565 return "DW_AT_MIPS_tail_loop_begin";
9566 case DW_AT_MIPS_epilog_begin
:
9567 return "DW_AT_MIPS_epilog_begin";
9568 case DW_AT_MIPS_loop_unroll_factor
:
9569 return "DW_AT_MIPS_loop_unroll_factor";
9570 case DW_AT_MIPS_software_pipeline_depth
:
9571 return "DW_AT_MIPS_software_pipeline_depth";
9572 case DW_AT_MIPS_linkage_name
:
9573 return "DW_AT_MIPS_linkage_name";
9574 case DW_AT_MIPS_stride
:
9575 return "DW_AT_MIPS_stride";
9576 case DW_AT_MIPS_abstract_name
:
9577 return "DW_AT_MIPS_abstract_name";
9578 case DW_AT_MIPS_clone_origin
:
9579 return "DW_AT_MIPS_clone_origin";
9580 case DW_AT_MIPS_has_inlines
:
9581 return "DW_AT_MIPS_has_inlines";
9582 /* HP extensions. */
9583 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
9584 case DW_AT_HP_block_index
:
9585 return "DW_AT_HP_block_index";
9587 case DW_AT_HP_unmodifiable
:
9588 return "DW_AT_HP_unmodifiable";
9589 case DW_AT_HP_actuals_stmt_list
:
9590 return "DW_AT_HP_actuals_stmt_list";
9591 case DW_AT_HP_proc_per_section
:
9592 return "DW_AT_HP_proc_per_section";
9593 case DW_AT_HP_raw_data_ptr
:
9594 return "DW_AT_HP_raw_data_ptr";
9595 case DW_AT_HP_pass_by_reference
:
9596 return "DW_AT_HP_pass_by_reference";
9597 case DW_AT_HP_opt_level
:
9598 return "DW_AT_HP_opt_level";
9599 case DW_AT_HP_prof_version_id
:
9600 return "DW_AT_HP_prof_version_id";
9601 case DW_AT_HP_opt_flags
:
9602 return "DW_AT_HP_opt_flags";
9603 case DW_AT_HP_cold_region_low_pc
:
9604 return "DW_AT_HP_cold_region_low_pc";
9605 case DW_AT_HP_cold_region_high_pc
:
9606 return "DW_AT_HP_cold_region_high_pc";
9607 case DW_AT_HP_all_variables_modifiable
:
9608 return "DW_AT_HP_all_variables_modifiable";
9609 case DW_AT_HP_linkage_name
:
9610 return "DW_AT_HP_linkage_name";
9611 case DW_AT_HP_prof_flags
:
9612 return "DW_AT_HP_prof_flags";
9613 /* GNU extensions. */
9614 case DW_AT_sf_names
:
9615 return "DW_AT_sf_names";
9616 case DW_AT_src_info
:
9617 return "DW_AT_src_info";
9618 case DW_AT_mac_info
:
9619 return "DW_AT_mac_info";
9620 case DW_AT_src_coords
:
9621 return "DW_AT_src_coords";
9622 case DW_AT_body_begin
:
9623 return "DW_AT_body_begin";
9624 case DW_AT_body_end
:
9625 return "DW_AT_body_end";
9626 case DW_AT_GNU_vector
:
9627 return "DW_AT_GNU_vector";
9628 /* VMS extensions. */
9629 case DW_AT_VMS_rtnbeg_pd_address
:
9630 return "DW_AT_VMS_rtnbeg_pd_address";
9631 /* UPC extension. */
9632 case DW_AT_upc_threads_scaled
:
9633 return "DW_AT_upc_threads_scaled";
9634 /* PGI (STMicroelectronics) extensions. */
9635 case DW_AT_PGI_lbase
:
9636 return "DW_AT_PGI_lbase";
9637 case DW_AT_PGI_soffset
:
9638 return "DW_AT_PGI_soffset";
9639 case DW_AT_PGI_lstride
:
9640 return "DW_AT_PGI_lstride";
9642 return "DW_AT_<unknown>";
9646 /* Convert a DWARF value form code into its string name. */
9649 dwarf_form_name (unsigned form
)
9654 return "DW_FORM_addr";
9655 case DW_FORM_block2
:
9656 return "DW_FORM_block2";
9657 case DW_FORM_block4
:
9658 return "DW_FORM_block4";
9660 return "DW_FORM_data2";
9662 return "DW_FORM_data4";
9664 return "DW_FORM_data8";
9665 case DW_FORM_string
:
9666 return "DW_FORM_string";
9668 return "DW_FORM_block";
9669 case DW_FORM_block1
:
9670 return "DW_FORM_block1";
9672 return "DW_FORM_data1";
9674 return "DW_FORM_flag";
9676 return "DW_FORM_sdata";
9678 return "DW_FORM_strp";
9680 return "DW_FORM_udata";
9681 case DW_FORM_ref_addr
:
9682 return "DW_FORM_ref_addr";
9684 return "DW_FORM_ref1";
9686 return "DW_FORM_ref2";
9688 return "DW_FORM_ref4";
9690 return "DW_FORM_ref8";
9691 case DW_FORM_ref_udata
:
9692 return "DW_FORM_ref_udata";
9693 case DW_FORM_indirect
:
9694 return "DW_FORM_indirect";
9695 case DW_FORM_sec_offset
:
9696 return "DW_FORM_sec_offset";
9697 case DW_FORM_exprloc
:
9698 return "DW_FORM_exprloc";
9699 case DW_FORM_flag_present
:
9700 return "DW_FORM_flag_present";
9702 return "DW_FORM_sig8";
9704 return "DW_FORM_<unknown>";
9708 /* Convert a DWARF stack opcode into its string name. */
9711 dwarf_stack_op_name (unsigned op
)
9716 return "DW_OP_addr";
9718 return "DW_OP_deref";
9720 return "DW_OP_const1u";
9722 return "DW_OP_const1s";
9724 return "DW_OP_const2u";
9726 return "DW_OP_const2s";
9728 return "DW_OP_const4u";
9730 return "DW_OP_const4s";
9732 return "DW_OP_const8u";
9734 return "DW_OP_const8s";
9736 return "DW_OP_constu";
9738 return "DW_OP_consts";
9742 return "DW_OP_drop";
9744 return "DW_OP_over";
9746 return "DW_OP_pick";
9748 return "DW_OP_swap";
9752 return "DW_OP_xderef";
9760 return "DW_OP_minus";
9772 return "DW_OP_plus";
9773 case DW_OP_plus_uconst
:
9774 return "DW_OP_plus_uconst";
9780 return "DW_OP_shra";
9798 return "DW_OP_skip";
9800 return "DW_OP_lit0";
9802 return "DW_OP_lit1";
9804 return "DW_OP_lit2";
9806 return "DW_OP_lit3";
9808 return "DW_OP_lit4";
9810 return "DW_OP_lit5";
9812 return "DW_OP_lit6";
9814 return "DW_OP_lit7";
9816 return "DW_OP_lit8";
9818 return "DW_OP_lit9";
9820 return "DW_OP_lit10";
9822 return "DW_OP_lit11";
9824 return "DW_OP_lit12";
9826 return "DW_OP_lit13";
9828 return "DW_OP_lit14";
9830 return "DW_OP_lit15";
9832 return "DW_OP_lit16";
9834 return "DW_OP_lit17";
9836 return "DW_OP_lit18";
9838 return "DW_OP_lit19";
9840 return "DW_OP_lit20";
9842 return "DW_OP_lit21";
9844 return "DW_OP_lit22";
9846 return "DW_OP_lit23";
9848 return "DW_OP_lit24";
9850 return "DW_OP_lit25";
9852 return "DW_OP_lit26";
9854 return "DW_OP_lit27";
9856 return "DW_OP_lit28";
9858 return "DW_OP_lit29";
9860 return "DW_OP_lit30";
9862 return "DW_OP_lit31";
9864 return "DW_OP_reg0";
9866 return "DW_OP_reg1";
9868 return "DW_OP_reg2";
9870 return "DW_OP_reg3";
9872 return "DW_OP_reg4";
9874 return "DW_OP_reg5";
9876 return "DW_OP_reg6";
9878 return "DW_OP_reg7";
9880 return "DW_OP_reg8";
9882 return "DW_OP_reg9";
9884 return "DW_OP_reg10";
9886 return "DW_OP_reg11";
9888 return "DW_OP_reg12";
9890 return "DW_OP_reg13";
9892 return "DW_OP_reg14";
9894 return "DW_OP_reg15";
9896 return "DW_OP_reg16";
9898 return "DW_OP_reg17";
9900 return "DW_OP_reg18";
9902 return "DW_OP_reg19";
9904 return "DW_OP_reg20";
9906 return "DW_OP_reg21";
9908 return "DW_OP_reg22";
9910 return "DW_OP_reg23";
9912 return "DW_OP_reg24";
9914 return "DW_OP_reg25";
9916 return "DW_OP_reg26";
9918 return "DW_OP_reg27";
9920 return "DW_OP_reg28";
9922 return "DW_OP_reg29";
9924 return "DW_OP_reg30";
9926 return "DW_OP_reg31";
9928 return "DW_OP_breg0";
9930 return "DW_OP_breg1";
9932 return "DW_OP_breg2";
9934 return "DW_OP_breg3";
9936 return "DW_OP_breg4";
9938 return "DW_OP_breg5";
9940 return "DW_OP_breg6";
9942 return "DW_OP_breg7";
9944 return "DW_OP_breg8";
9946 return "DW_OP_breg9";
9948 return "DW_OP_breg10";
9950 return "DW_OP_breg11";
9952 return "DW_OP_breg12";
9954 return "DW_OP_breg13";
9956 return "DW_OP_breg14";
9958 return "DW_OP_breg15";
9960 return "DW_OP_breg16";
9962 return "DW_OP_breg17";
9964 return "DW_OP_breg18";
9966 return "DW_OP_breg19";
9968 return "DW_OP_breg20";
9970 return "DW_OP_breg21";
9972 return "DW_OP_breg22";
9974 return "DW_OP_breg23";
9976 return "DW_OP_breg24";
9978 return "DW_OP_breg25";
9980 return "DW_OP_breg26";
9982 return "DW_OP_breg27";
9984 return "DW_OP_breg28";
9986 return "DW_OP_breg29";
9988 return "DW_OP_breg30";
9990 return "DW_OP_breg31";
9992 return "DW_OP_regx";
9994 return "DW_OP_fbreg";
9996 return "DW_OP_bregx";
9998 return "DW_OP_piece";
9999 case DW_OP_deref_size
:
10000 return "DW_OP_deref_size";
10001 case DW_OP_xderef_size
:
10002 return "DW_OP_xderef_size";
10004 return "DW_OP_nop";
10005 /* DWARF 3 extensions. */
10006 case DW_OP_push_object_address
:
10007 return "DW_OP_push_object_address";
10009 return "DW_OP_call2";
10011 return "DW_OP_call4";
10012 case DW_OP_call_ref
:
10013 return "DW_OP_call_ref";
10014 /* GNU extensions. */
10015 case DW_OP_form_tls_address
:
10016 return "DW_OP_form_tls_address";
10017 case DW_OP_call_frame_cfa
:
10018 return "DW_OP_call_frame_cfa";
10019 case DW_OP_bit_piece
:
10020 return "DW_OP_bit_piece";
10021 case DW_OP_GNU_push_tls_address
:
10022 return "DW_OP_GNU_push_tls_address";
10023 case DW_OP_GNU_uninit
:
10024 return "DW_OP_GNU_uninit";
10025 /* HP extensions. */
10026 case DW_OP_HP_is_value
:
10027 return "DW_OP_HP_is_value";
10028 case DW_OP_HP_fltconst4
:
10029 return "DW_OP_HP_fltconst4";
10030 case DW_OP_HP_fltconst8
:
10031 return "DW_OP_HP_fltconst8";
10032 case DW_OP_HP_mod_range
:
10033 return "DW_OP_HP_mod_range";
10034 case DW_OP_HP_unmod_range
:
10035 return "DW_OP_HP_unmod_range";
10037 return "DW_OP_HP_tls";
10039 return "OP_<unknown>";
10044 dwarf_bool_name (unsigned mybool
)
10052 /* Convert a DWARF type code into its string name. */
10055 dwarf_type_encoding_name (unsigned enc
)
10060 return "DW_ATE_void";
10061 case DW_ATE_address
:
10062 return "DW_ATE_address";
10063 case DW_ATE_boolean
:
10064 return "DW_ATE_boolean";
10065 case DW_ATE_complex_float
:
10066 return "DW_ATE_complex_float";
10068 return "DW_ATE_float";
10069 case DW_ATE_signed
:
10070 return "DW_ATE_signed";
10071 case DW_ATE_signed_char
:
10072 return "DW_ATE_signed_char";
10073 case DW_ATE_unsigned
:
10074 return "DW_ATE_unsigned";
10075 case DW_ATE_unsigned_char
:
10076 return "DW_ATE_unsigned_char";
10078 case DW_ATE_imaginary_float
:
10079 return "DW_ATE_imaginary_float";
10080 case DW_ATE_packed_decimal
:
10081 return "DW_ATE_packed_decimal";
10082 case DW_ATE_numeric_string
:
10083 return "DW_ATE_numeric_string";
10084 case DW_ATE_edited
:
10085 return "DW_ATE_edited";
10086 case DW_ATE_signed_fixed
:
10087 return "DW_ATE_signed_fixed";
10088 case DW_ATE_unsigned_fixed
:
10089 return "DW_ATE_unsigned_fixed";
10090 case DW_ATE_decimal_float
:
10091 return "DW_ATE_decimal_float";
10092 /* HP extensions. */
10093 case DW_ATE_HP_float80
:
10094 return "DW_ATE_HP_float80";
10095 case DW_ATE_HP_complex_float80
:
10096 return "DW_ATE_HP_complex_float80";
10097 case DW_ATE_HP_float128
:
10098 return "DW_ATE_HP_float128";
10099 case DW_ATE_HP_complex_float128
:
10100 return "DW_ATE_HP_complex_float128";
10101 case DW_ATE_HP_floathpintel
:
10102 return "DW_ATE_HP_floathpintel";
10103 case DW_ATE_HP_imaginary_float80
:
10104 return "DW_ATE_HP_imaginary_float80";
10105 case DW_ATE_HP_imaginary_float128
:
10106 return "DW_ATE_HP_imaginary_float128";
10108 return "DW_ATE_<unknown>";
10112 /* Convert a DWARF call frame info operation to its string name. */
10116 dwarf_cfi_name (unsigned cfi_opc
)
10120 case DW_CFA_advance_loc
:
10121 return "DW_CFA_advance_loc";
10122 case DW_CFA_offset
:
10123 return "DW_CFA_offset";
10124 case DW_CFA_restore
:
10125 return "DW_CFA_restore";
10127 return "DW_CFA_nop";
10128 case DW_CFA_set_loc
:
10129 return "DW_CFA_set_loc";
10130 case DW_CFA_advance_loc1
:
10131 return "DW_CFA_advance_loc1";
10132 case DW_CFA_advance_loc2
:
10133 return "DW_CFA_advance_loc2";
10134 case DW_CFA_advance_loc4
:
10135 return "DW_CFA_advance_loc4";
10136 case DW_CFA_offset_extended
:
10137 return "DW_CFA_offset_extended";
10138 case DW_CFA_restore_extended
:
10139 return "DW_CFA_restore_extended";
10140 case DW_CFA_undefined
:
10141 return "DW_CFA_undefined";
10142 case DW_CFA_same_value
:
10143 return "DW_CFA_same_value";
10144 case DW_CFA_register
:
10145 return "DW_CFA_register";
10146 case DW_CFA_remember_state
:
10147 return "DW_CFA_remember_state";
10148 case DW_CFA_restore_state
:
10149 return "DW_CFA_restore_state";
10150 case DW_CFA_def_cfa
:
10151 return "DW_CFA_def_cfa";
10152 case DW_CFA_def_cfa_register
:
10153 return "DW_CFA_def_cfa_register";
10154 case DW_CFA_def_cfa_offset
:
10155 return "DW_CFA_def_cfa_offset";
10157 case DW_CFA_def_cfa_expression
:
10158 return "DW_CFA_def_cfa_expression";
10159 case DW_CFA_expression
:
10160 return "DW_CFA_expression";
10161 case DW_CFA_offset_extended_sf
:
10162 return "DW_CFA_offset_extended_sf";
10163 case DW_CFA_def_cfa_sf
:
10164 return "DW_CFA_def_cfa_sf";
10165 case DW_CFA_def_cfa_offset_sf
:
10166 return "DW_CFA_def_cfa_offset_sf";
10167 case DW_CFA_val_offset
:
10168 return "DW_CFA_val_offset";
10169 case DW_CFA_val_offset_sf
:
10170 return "DW_CFA_val_offset_sf";
10171 case DW_CFA_val_expression
:
10172 return "DW_CFA_val_expression";
10173 /* SGI/MIPS specific. */
10174 case DW_CFA_MIPS_advance_loc8
:
10175 return "DW_CFA_MIPS_advance_loc8";
10176 /* GNU extensions. */
10177 case DW_CFA_GNU_window_save
:
10178 return "DW_CFA_GNU_window_save";
10179 case DW_CFA_GNU_args_size
:
10180 return "DW_CFA_GNU_args_size";
10181 case DW_CFA_GNU_negative_offset_extended
:
10182 return "DW_CFA_GNU_negative_offset_extended";
10184 return "DW_CFA_<unknown>";
10190 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
10194 print_spaces (indent
, f
);
10195 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
10196 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
10198 if (die
->parent
!= NULL
)
10200 print_spaces (indent
, f
);
10201 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
10202 die
->parent
->offset
);
10205 print_spaces (indent
, f
);
10206 fprintf_unfiltered (f
, " has children: %s\n",
10207 dwarf_bool_name (die
->child
!= NULL
));
10209 print_spaces (indent
, f
);
10210 fprintf_unfiltered (f
, " attributes:\n");
10212 for (i
= 0; i
< die
->num_attrs
; ++i
)
10214 print_spaces (indent
, f
);
10215 fprintf_unfiltered (f
, " %s (%s) ",
10216 dwarf_attr_name (die
->attrs
[i
].name
),
10217 dwarf_form_name (die
->attrs
[i
].form
));
10219 switch (die
->attrs
[i
].form
)
10221 case DW_FORM_ref_addr
:
10223 fprintf_unfiltered (f
, "address: ");
10224 fputs_filtered (hex_string (DW_ADDR (&die
->attrs
[i
])), f
);
10226 case DW_FORM_block2
:
10227 case DW_FORM_block4
:
10228 case DW_FORM_block
:
10229 case DW_FORM_block1
:
10230 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
10235 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
10236 (long) (DW_ADDR (&die
->attrs
[i
])));
10238 case DW_FORM_data1
:
10239 case DW_FORM_data2
:
10240 case DW_FORM_data4
:
10241 case DW_FORM_data8
:
10242 case DW_FORM_udata
:
10243 case DW_FORM_sdata
:
10244 fprintf_unfiltered (f
, "constant: %s",
10245 pulongest (DW_UNSND (&die
->attrs
[i
])));
10248 if (DW_SIGNATURED_TYPE (&die
->attrs
[i
]) != NULL
)
10249 fprintf_unfiltered (f
, "signatured type, offset: 0x%x",
10250 DW_SIGNATURED_TYPE (&die
->attrs
[i
])->offset
);
10252 fprintf_unfiltered (f
, "signatured type, offset: unknown");
10254 case DW_FORM_string
:
10256 fprintf_unfiltered (f
, "string: \"%s\" (%s canonicalized)",
10257 DW_STRING (&die
->attrs
[i
])
10258 ? DW_STRING (&die
->attrs
[i
]) : "",
10259 DW_STRING_IS_CANONICAL (&die
->attrs
[i
]) ? "is" : "not");
10262 if (DW_UNSND (&die
->attrs
[i
]))
10263 fprintf_unfiltered (f
, "flag: TRUE");
10265 fprintf_unfiltered (f
, "flag: FALSE");
10267 case DW_FORM_indirect
:
10268 /* the reader will have reduced the indirect form to
10269 the "base form" so this form should not occur */
10270 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
10273 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
10274 die
->attrs
[i
].form
);
10277 fprintf_unfiltered (f
, "\n");
10282 dump_die_for_error (struct die_info
*die
)
10284 dump_die_shallow (gdb_stderr
, 0, die
);
10288 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
10290 int indent
= level
* 4;
10292 gdb_assert (die
!= NULL
);
10294 if (level
>= max_level
)
10297 dump_die_shallow (f
, indent
, die
);
10299 if (die
->child
!= NULL
)
10301 print_spaces (indent
, f
);
10302 fprintf_unfiltered (f
, " Children:");
10303 if (level
+ 1 < max_level
)
10305 fprintf_unfiltered (f
, "\n");
10306 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
10310 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
10314 if (die
->sibling
!= NULL
&& level
> 0)
10316 dump_die_1 (f
, level
, max_level
, die
->sibling
);
10320 /* This is called from the pdie macro in gdbinit.in.
10321 It's not static so gcc will keep a copy callable from gdb. */
10324 dump_die (struct die_info
*die
, int max_level
)
10326 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
10330 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
10334 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
10340 is_ref_attr (struct attribute
*attr
)
10342 switch (attr
->form
)
10344 case DW_FORM_ref_addr
:
10349 case DW_FORM_ref_udata
:
10356 static unsigned int
10357 dwarf2_get_ref_die_offset (struct attribute
*attr
)
10359 if (is_ref_attr (attr
))
10360 return DW_ADDR (attr
);
10362 complaint (&symfile_complaints
,
10363 _("unsupported die ref attribute form: '%s'"),
10364 dwarf_form_name (attr
->form
));
10368 /* Return the constant value held by ATTR. Return DEFAULT_VALUE if
10369 * the value held by the attribute is not constant. */
10372 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
10374 if (attr
->form
== DW_FORM_sdata
)
10375 return DW_SND (attr
);
10376 else if (attr
->form
== DW_FORM_udata
10377 || attr
->form
== DW_FORM_data1
10378 || attr
->form
== DW_FORM_data2
10379 || attr
->form
== DW_FORM_data4
10380 || attr
->form
== DW_FORM_data8
)
10381 return DW_UNSND (attr
);
10384 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
10385 dwarf_form_name (attr
->form
));
10386 return default_value
;
10390 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
10391 unit and add it to our queue.
10392 The result is non-zero if PER_CU was queued, otherwise the result is zero
10393 meaning either PER_CU is already queued or it is already loaded. */
10396 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
10397 struct dwarf2_per_cu_data
*per_cu
)
10399 /* Mark the dependence relation so that we don't flush PER_CU
10401 dwarf2_add_dependence (this_cu
, per_cu
);
10403 /* If it's already on the queue, we have nothing to do. */
10404 if (per_cu
->queued
)
10407 /* If the compilation unit is already loaded, just mark it as
10409 if (per_cu
->cu
!= NULL
)
10411 per_cu
->cu
->last_used
= 0;
10415 /* Add it to the queue. */
10416 queue_comp_unit (per_cu
, this_cu
->objfile
);
10421 /* Follow reference or signature attribute ATTR of SRC_DIE.
10422 On entry *REF_CU is the CU of SRC_DIE.
10423 On exit *REF_CU is the CU of the result. */
10425 static struct die_info
*
10426 follow_die_ref_or_sig (struct die_info
*src_die
, struct attribute
*attr
,
10427 struct dwarf2_cu
**ref_cu
)
10429 struct die_info
*die
;
10431 if (is_ref_attr (attr
))
10432 die
= follow_die_ref (src_die
, attr
, ref_cu
);
10433 else if (attr
->form
== DW_FORM_sig8
)
10434 die
= follow_die_sig (src_die
, attr
, ref_cu
);
10437 dump_die_for_error (src_die
);
10438 error (_("Dwarf Error: Expected reference attribute [in module %s]"),
10439 (*ref_cu
)->objfile
->name
);
10445 /* Follow reference attribute ATTR of SRC_DIE.
10446 On entry *REF_CU is the CU of SRC_DIE.
10447 On exit *REF_CU is the CU of the result. */
10449 static struct die_info
*
10450 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
10451 struct dwarf2_cu
**ref_cu
)
10453 struct die_info
*die
;
10454 unsigned int offset
;
10455 struct die_info temp_die
;
10456 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
10458 gdb_assert (cu
->per_cu
!= NULL
);
10460 offset
= dwarf2_get_ref_die_offset (attr
);
10462 if (cu
->per_cu
->from_debug_types
)
10464 /* .debug_types CUs cannot reference anything outside their CU.
10465 If they need to, they have to reference a signatured type via
10467 if (! offset_in_cu_p (&cu
->header
, offset
))
10471 else if (! offset_in_cu_p (&cu
->header
, offset
))
10473 struct dwarf2_per_cu_data
*per_cu
;
10474 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
10476 /* If necessary, add it to the queue and load its DIEs. */
10477 if (maybe_queue_comp_unit (cu
, per_cu
))
10478 load_full_comp_unit (per_cu
, cu
->objfile
);
10480 target_cu
= per_cu
->cu
;
10485 *ref_cu
= target_cu
;
10486 temp_die
.offset
= offset
;
10487 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
10493 error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE "
10494 "at 0x%x [in module %s]"),
10495 offset
, src_die
->offset
, cu
->objfile
->name
);
10498 /* Follow the signature attribute ATTR in SRC_DIE.
10499 On entry *REF_CU is the CU of SRC_DIE.
10500 On exit *REF_CU is the CU of the result. */
10502 static struct die_info
*
10503 follow_die_sig (struct die_info
*src_die
, struct attribute
*attr
,
10504 struct dwarf2_cu
**ref_cu
)
10506 struct objfile
*objfile
= (*ref_cu
)->objfile
;
10507 struct die_info temp_die
;
10508 struct signatured_type
*sig_type
= DW_SIGNATURED_TYPE (attr
);
10509 struct dwarf2_cu
*sig_cu
;
10510 struct die_info
*die
;
10512 /* sig_type will be NULL if the signatured type is missing from
10514 if (sig_type
== NULL
)
10515 error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE "
10516 "at 0x%x [in module %s]"),
10517 src_die
->offset
, objfile
->name
);
10519 /* If necessary, add it to the queue and load its DIEs. */
10521 if (maybe_queue_comp_unit (*ref_cu
, &sig_type
->per_cu
))
10522 read_signatured_type (objfile
, sig_type
);
10524 gdb_assert (sig_type
->per_cu
.cu
!= NULL
);
10526 sig_cu
= sig_type
->per_cu
.cu
;
10527 temp_die
.offset
= sig_cu
->header
.offset
+ sig_type
->type_offset
;
10528 die
= htab_find_with_hash (sig_cu
->die_hash
, &temp_die
, temp_die
.offset
);
10535 error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE "
10536 "at 0x%x [in module %s]"),
10537 sig_type
->type_offset
, src_die
->offset
, objfile
->name
);
10540 /* Given an offset of a signatured type, return its signatured_type. */
10542 static struct signatured_type
*
10543 lookup_signatured_type_at_offset (struct objfile
*objfile
, unsigned int offset
)
10545 gdb_byte
*info_ptr
= dwarf2_per_objfile
->types
.buffer
+ offset
;
10546 unsigned int length
, initial_length_size
;
10547 unsigned int sig_offset
;
10548 struct signatured_type find_entry
, *type_sig
;
10550 length
= read_initial_length (objfile
->obfd
, info_ptr
, &initial_length_size
);
10551 sig_offset
= (initial_length_size
10553 + (initial_length_size
== 4 ? 4 : 8) /*debug_abbrev_offset*/
10554 + 1 /*address_size*/);
10555 find_entry
.signature
= bfd_get_64 (objfile
->obfd
, info_ptr
+ sig_offset
);
10556 type_sig
= htab_find (dwarf2_per_objfile
->signatured_types
, &find_entry
);
10558 /* This is only used to lookup previously recorded types.
10559 If we didn't find it, it's our bug. */
10560 gdb_assert (type_sig
!= NULL
);
10561 gdb_assert (offset
== type_sig
->offset
);
10566 /* Read in signatured type at OFFSET and build its CU and die(s). */
10569 read_signatured_type_at_offset (struct objfile
*objfile
,
10570 unsigned int offset
)
10572 struct signatured_type
*type_sig
;
10574 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->types
);
10576 /* We have the section offset, but we need the signature to do the
10577 hash table lookup. */
10578 type_sig
= lookup_signatured_type_at_offset (objfile
, offset
);
10580 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10582 read_signatured_type (objfile
, type_sig
);
10584 gdb_assert (type_sig
->per_cu
.cu
!= NULL
);
10587 /* Read in a signatured type and build its CU and DIEs. */
10590 read_signatured_type (struct objfile
*objfile
,
10591 struct signatured_type
*type_sig
)
10593 gdb_byte
*types_ptr
= dwarf2_per_objfile
->types
.buffer
+ type_sig
->offset
;
10594 struct die_reader_specs reader_specs
;
10595 struct dwarf2_cu
*cu
;
10596 ULONGEST signature
;
10597 struct cleanup
*back_to
, *free_cu_cleanup
;
10598 struct attribute
*attr
;
10600 gdb_assert (type_sig
->per_cu
.cu
== NULL
);
10602 cu
= xmalloc (sizeof (struct dwarf2_cu
));
10603 memset (cu
, 0, sizeof (struct dwarf2_cu
));
10604 obstack_init (&cu
->comp_unit_obstack
);
10605 cu
->objfile
= objfile
;
10606 type_sig
->per_cu
.cu
= cu
;
10607 cu
->per_cu
= &type_sig
->per_cu
;
10609 /* If an error occurs while loading, release our storage. */
10610 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
10612 types_ptr
= read_type_comp_unit_head (&cu
->header
, &signature
,
10613 types_ptr
, objfile
->obfd
);
10614 gdb_assert (signature
== type_sig
->signature
);
10617 = htab_create_alloc_ex (cu
->header
.length
/ 12,
10621 &cu
->comp_unit_obstack
,
10622 hashtab_obstack_allocate
,
10623 dummy_obstack_deallocate
);
10625 dwarf2_read_abbrevs (cu
->objfile
->obfd
, cu
);
10626 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
10628 init_cu_die_reader (&reader_specs
, cu
);
10630 cu
->dies
= read_die_and_children (&reader_specs
, types_ptr
, &types_ptr
,
10633 /* We try not to read any attributes in this function, because not
10634 all objfiles needed for references have been loaded yet, and symbol
10635 table processing isn't initialized. But we have to set the CU language,
10636 or we won't be able to build types correctly. */
10637 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
10639 set_cu_language (DW_UNSND (attr
), cu
);
10641 set_cu_language (language_minimal
, cu
);
10643 do_cleanups (back_to
);
10645 /* We've successfully allocated this compilation unit. Let our caller
10646 clean it up when finished with it. */
10647 discard_cleanups (free_cu_cleanup
);
10649 type_sig
->per_cu
.cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
10650 dwarf2_per_objfile
->read_in_chain
= &type_sig
->per_cu
;
10653 /* Decode simple location descriptions.
10654 Given a pointer to a dwarf block that defines a location, compute
10655 the location and return the value.
10657 NOTE drow/2003-11-18: This function is called in two situations
10658 now: for the address of static or global variables (partial symbols
10659 only) and for offsets into structures which are expected to be
10660 (more or less) constant. The partial symbol case should go away,
10661 and only the constant case should remain. That will let this
10662 function complain more accurately. A few special modes are allowed
10663 without complaint for global variables (for instance, global
10664 register values and thread-local values).
10666 A location description containing no operations indicates that the
10667 object is optimized out. The return value is 0 for that case.
10668 FIXME drow/2003-11-16: No callers check for this case any more; soon all
10669 callers will only want a very basic result and this can become a
10672 Note that stack[0] is unused except as a default error return.
10673 Note that stack overflow is not yet handled. */
10676 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
10678 struct objfile
*objfile
= cu
->objfile
;
10679 struct comp_unit_head
*cu_header
= &cu
->header
;
10681 int size
= blk
->size
;
10682 gdb_byte
*data
= blk
->data
;
10683 CORE_ADDR stack
[64];
10685 unsigned int bytes_read
, unsnd
;
10729 stack
[++stacki
] = op
- DW_OP_lit0
;
10764 stack
[++stacki
] = op
- DW_OP_reg0
;
10766 dwarf2_complex_location_expr_complaint ();
10770 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10772 stack
[++stacki
] = unsnd
;
10774 dwarf2_complex_location_expr_complaint ();
10778 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
10783 case DW_OP_const1u
:
10784 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
10788 case DW_OP_const1s
:
10789 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
10793 case DW_OP_const2u
:
10794 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
10798 case DW_OP_const2s
:
10799 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
10803 case DW_OP_const4u
:
10804 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
10808 case DW_OP_const4s
:
10809 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
10814 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
10820 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
10825 stack
[stacki
+ 1] = stack
[stacki
];
10830 stack
[stacki
- 1] += stack
[stacki
];
10834 case DW_OP_plus_uconst
:
10835 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
10840 stack
[stacki
- 1] -= stack
[stacki
];
10845 /* If we're not the last op, then we definitely can't encode
10846 this using GDB's address_class enum. This is valid for partial
10847 global symbols, although the variable's address will be bogus
10850 dwarf2_complex_location_expr_complaint ();
10853 case DW_OP_GNU_push_tls_address
:
10854 /* The top of the stack has the offset from the beginning
10855 of the thread control block at which the variable is located. */
10856 /* Nothing should follow this operator, so the top of stack would
10858 /* This is valid for partial global symbols, but the variable's
10859 address will be bogus in the psymtab. */
10861 dwarf2_complex_location_expr_complaint ();
10864 case DW_OP_GNU_uninit
:
10868 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
10869 dwarf_stack_op_name (op
));
10870 return (stack
[stacki
]);
10873 return (stack
[stacki
]);
10876 /* memory allocation interface */
10878 static struct dwarf_block
*
10879 dwarf_alloc_block (struct dwarf2_cu
*cu
)
10881 struct dwarf_block
*blk
;
10883 blk
= (struct dwarf_block
*)
10884 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
10888 static struct abbrev_info
*
10889 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
10891 struct abbrev_info
*abbrev
;
10893 abbrev
= (struct abbrev_info
*)
10894 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
10895 memset (abbrev
, 0, sizeof (struct abbrev_info
));
10899 static struct die_info
*
10900 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
10902 struct die_info
*die
;
10903 size_t size
= sizeof (struct die_info
);
10906 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
10908 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
10909 memset (die
, 0, sizeof (struct die_info
));
10914 /* Macro support. */
10917 /* Return the full name of file number I in *LH's file name table.
10918 Use COMP_DIR as the name of the current directory of the
10919 compilation. The result is allocated using xmalloc; the caller is
10920 responsible for freeing it. */
10922 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
10924 /* Is the file number a valid index into the line header's file name
10925 table? Remember that file numbers start with one, not zero. */
10926 if (1 <= file
&& file
<= lh
->num_file_names
)
10928 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
10930 if (IS_ABSOLUTE_PATH (fe
->name
))
10931 return xstrdup (fe
->name
);
10939 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10945 dir_len
= strlen (dir
);
10946 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
10947 strcpy (full_name
, dir
);
10948 full_name
[dir_len
] = '/';
10949 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
10953 return xstrdup (fe
->name
);
10958 /* The compiler produced a bogus file number. We can at least
10959 record the macro definitions made in the file, even if we
10960 won't be able to find the file by name. */
10961 char fake_name
[80];
10962 sprintf (fake_name
, "<bad macro file number %d>", file
);
10964 complaint (&symfile_complaints
,
10965 _("bad file number in macro information (%d)"),
10968 return xstrdup (fake_name
);
10973 static struct macro_source_file
*
10974 macro_start_file (int file
, int line
,
10975 struct macro_source_file
*current_file
,
10976 const char *comp_dir
,
10977 struct line_header
*lh
, struct objfile
*objfile
)
10979 /* The full name of this source file. */
10980 char *full_name
= file_full_name (file
, lh
, comp_dir
);
10982 /* We don't create a macro table for this compilation unit
10983 at all until we actually get a filename. */
10984 if (! pending_macros
)
10985 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
10986 objfile
->macro_cache
);
10988 if (! current_file
)
10989 /* If we have no current file, then this must be the start_file
10990 directive for the compilation unit's main source file. */
10991 current_file
= macro_set_main (pending_macros
, full_name
);
10993 current_file
= macro_include (current_file
, line
, full_name
);
10997 return current_file
;
11001 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
11002 followed by a null byte. */
11004 copy_string (const char *buf
, int len
)
11006 char *s
= xmalloc (len
+ 1);
11007 memcpy (s
, buf
, len
);
11014 static const char *
11015 consume_improper_spaces (const char *p
, const char *body
)
11019 complaint (&symfile_complaints
,
11020 _("macro definition contains spaces in formal argument list:\n`%s'"),
11032 parse_macro_definition (struct macro_source_file
*file
, int line
,
11037 /* The body string takes one of two forms. For object-like macro
11038 definitions, it should be:
11040 <macro name> " " <definition>
11042 For function-like macro definitions, it should be:
11044 <macro name> "() " <definition>
11046 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
11048 Spaces may appear only where explicitly indicated, and in the
11051 The Dwarf 2 spec says that an object-like macro's name is always
11052 followed by a space, but versions of GCC around March 2002 omit
11053 the space when the macro's definition is the empty string.
11055 The Dwarf 2 spec says that there should be no spaces between the
11056 formal arguments in a function-like macro's formal argument list,
11057 but versions of GCC around March 2002 include spaces after the
11061 /* Find the extent of the macro name. The macro name is terminated
11062 by either a space or null character (for an object-like macro) or
11063 an opening paren (for a function-like macro). */
11064 for (p
= body
; *p
; p
++)
11065 if (*p
== ' ' || *p
== '(')
11068 if (*p
== ' ' || *p
== '\0')
11070 /* It's an object-like macro. */
11071 int name_len
= p
- body
;
11072 char *name
= copy_string (body
, name_len
);
11073 const char *replacement
;
11076 replacement
= body
+ name_len
+ 1;
11079 dwarf2_macro_malformed_definition_complaint (body
);
11080 replacement
= body
+ name_len
;
11083 macro_define_object (file
, line
, name
, replacement
);
11087 else if (*p
== '(')
11089 /* It's a function-like macro. */
11090 char *name
= copy_string (body
, p
- body
);
11093 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
11097 p
= consume_improper_spaces (p
, body
);
11099 /* Parse the formal argument list. */
11100 while (*p
&& *p
!= ')')
11102 /* Find the extent of the current argument name. */
11103 const char *arg_start
= p
;
11105 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
11108 if (! *p
|| p
== arg_start
)
11109 dwarf2_macro_malformed_definition_complaint (body
);
11112 /* Make sure argv has room for the new argument. */
11113 if (argc
>= argv_size
)
11116 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
11119 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
11122 p
= consume_improper_spaces (p
, body
);
11124 /* Consume the comma, if present. */
11129 p
= consume_improper_spaces (p
, body
);
11138 /* Perfectly formed definition, no complaints. */
11139 macro_define_function (file
, line
, name
,
11140 argc
, (const char **) argv
,
11142 else if (*p
== '\0')
11144 /* Complain, but do define it. */
11145 dwarf2_macro_malformed_definition_complaint (body
);
11146 macro_define_function (file
, line
, name
,
11147 argc
, (const char **) argv
,
11151 /* Just complain. */
11152 dwarf2_macro_malformed_definition_complaint (body
);
11155 /* Just complain. */
11156 dwarf2_macro_malformed_definition_complaint (body
);
11162 for (i
= 0; i
< argc
; i
++)
11168 dwarf2_macro_malformed_definition_complaint (body
);
11173 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
11174 char *comp_dir
, bfd
*abfd
,
11175 struct dwarf2_cu
*cu
)
11177 gdb_byte
*mac_ptr
, *mac_end
;
11178 struct macro_source_file
*current_file
= 0;
11179 enum dwarf_macinfo_record_type macinfo_type
;
11180 int at_commandline
;
11182 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11183 &dwarf2_per_objfile
->macinfo
);
11184 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
11186 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
11190 /* First pass: Find the name of the base filename.
11191 This filename is needed in order to process all macros whose definition
11192 (or undefinition) comes from the command line. These macros are defined
11193 before the first DW_MACINFO_start_file entry, and yet still need to be
11194 associated to the base file.
11196 To determine the base file name, we scan the macro definitions until we
11197 reach the first DW_MACINFO_start_file entry. We then initialize
11198 CURRENT_FILE accordingly so that any macro definition found before the
11199 first DW_MACINFO_start_file can still be associated to the base file. */
11201 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11202 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
11203 + dwarf2_per_objfile
->macinfo
.size
;
11207 /* Do we at least have room for a macinfo type byte? */
11208 if (mac_ptr
>= mac_end
)
11210 /* Complaint is printed during the second pass as GDB will probably
11211 stop the first pass earlier upon finding DW_MACINFO_start_file. */
11215 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11218 switch (macinfo_type
)
11220 /* A zero macinfo type indicates the end of the macro
11225 case DW_MACINFO_define
:
11226 case DW_MACINFO_undef
:
11227 /* Only skip the data by MAC_PTR. */
11229 unsigned int bytes_read
;
11231 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11232 mac_ptr
+= bytes_read
;
11233 read_string (abfd
, mac_ptr
, &bytes_read
);
11234 mac_ptr
+= bytes_read
;
11238 case DW_MACINFO_start_file
:
11240 unsigned int bytes_read
;
11243 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11244 mac_ptr
+= bytes_read
;
11245 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11246 mac_ptr
+= bytes_read
;
11248 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
11253 case DW_MACINFO_end_file
:
11254 /* No data to skip by MAC_PTR. */
11257 case DW_MACINFO_vendor_ext
:
11258 /* Only skip the data by MAC_PTR. */
11260 unsigned int bytes_read
;
11262 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11263 mac_ptr
+= bytes_read
;
11264 read_string (abfd
, mac_ptr
, &bytes_read
);
11265 mac_ptr
+= bytes_read
;
11272 } while (macinfo_type
!= 0 && current_file
== NULL
);
11274 /* Second pass: Process all entries.
11276 Use the AT_COMMAND_LINE flag to determine whether we are still processing
11277 command-line macro definitions/undefinitions. This flag is unset when we
11278 reach the first DW_MACINFO_start_file entry. */
11280 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
11282 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
11283 GDB is still reading the definitions from command line. First
11284 DW_MACINFO_start_file will need to be ignored as it was already executed
11285 to create CURRENT_FILE for the main source holding also the command line
11286 definitions. On first met DW_MACINFO_start_file this flag is reset to
11287 normally execute all the remaining DW_MACINFO_start_file macinfos. */
11289 at_commandline
= 1;
11293 /* Do we at least have room for a macinfo type byte? */
11294 if (mac_ptr
>= mac_end
)
11296 dwarf2_macros_too_long_complaint ();
11300 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
11303 switch (macinfo_type
)
11305 /* A zero macinfo type indicates the end of the macro
11310 case DW_MACINFO_define
:
11311 case DW_MACINFO_undef
:
11313 unsigned int bytes_read
;
11317 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11318 mac_ptr
+= bytes_read
;
11319 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
11320 mac_ptr
+= bytes_read
;
11322 if (! current_file
)
11324 /* DWARF violation as no main source is present. */
11325 complaint (&symfile_complaints
,
11326 _("debug info with no main source gives macro %s "
11328 macinfo_type
== DW_MACINFO_define
?
11330 macinfo_type
== DW_MACINFO_undef
?
11331 _("undefinition") :
11332 _("something-or-other"), line
, body
);
11335 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11336 complaint (&symfile_complaints
,
11337 _("debug info gives %s macro %s with %s line %d: %s"),
11338 at_commandline
? _("command-line") : _("in-file"),
11339 macinfo_type
== DW_MACINFO_define
?
11341 macinfo_type
== DW_MACINFO_undef
?
11342 _("undefinition") :
11343 _("something-or-other"),
11344 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
11346 if (macinfo_type
== DW_MACINFO_define
)
11347 parse_macro_definition (current_file
, line
, body
);
11348 else if (macinfo_type
== DW_MACINFO_undef
)
11349 macro_undef (current_file
, line
, body
);
11353 case DW_MACINFO_start_file
:
11355 unsigned int bytes_read
;
11358 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11359 mac_ptr
+= bytes_read
;
11360 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11361 mac_ptr
+= bytes_read
;
11363 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
11364 complaint (&symfile_complaints
,
11365 _("debug info gives source %d included "
11366 "from %s at %s line %d"),
11367 file
, at_commandline
? _("command-line") : _("file"),
11368 line
== 0 ? _("zero") : _("non-zero"), line
);
11370 if (at_commandline
)
11372 /* This DW_MACINFO_start_file was executed in the pass one. */
11373 at_commandline
= 0;
11376 current_file
= macro_start_file (file
, line
,
11377 current_file
, comp_dir
,
11382 case DW_MACINFO_end_file
:
11383 if (! current_file
)
11384 complaint (&symfile_complaints
,
11385 _("macro debug info has an unmatched `close_file' directive"));
11388 current_file
= current_file
->included_by
;
11389 if (! current_file
)
11391 enum dwarf_macinfo_record_type next_type
;
11393 /* GCC circa March 2002 doesn't produce the zero
11394 type byte marking the end of the compilation
11395 unit. Complain if it's not there, but exit no
11398 /* Do we at least have room for a macinfo type byte? */
11399 if (mac_ptr
>= mac_end
)
11401 dwarf2_macros_too_long_complaint ();
11405 /* We don't increment mac_ptr here, so this is just
11407 next_type
= read_1_byte (abfd
, mac_ptr
);
11408 if (next_type
!= 0)
11409 complaint (&symfile_complaints
,
11410 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
11417 case DW_MACINFO_vendor_ext
:
11419 unsigned int bytes_read
;
11423 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
11424 mac_ptr
+= bytes_read
;
11425 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
11426 mac_ptr
+= bytes_read
;
11428 /* We don't recognize any vendor extensions. */
11432 } while (macinfo_type
!= 0);
11435 /* Check if the attribute's form is a DW_FORM_block*
11436 if so return true else false. */
11438 attr_form_is_block (struct attribute
*attr
)
11440 return (attr
== NULL
? 0 :
11441 attr
->form
== DW_FORM_block1
11442 || attr
->form
== DW_FORM_block2
11443 || attr
->form
== DW_FORM_block4
11444 || attr
->form
== DW_FORM_block
);
11447 /* Return non-zero if ATTR's value is a section offset --- classes
11448 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
11449 You may use DW_UNSND (attr) to retrieve such offsets.
11451 Section 7.5.4, "Attribute Encodings", explains that no attribute
11452 may have a value that belongs to more than one of these classes; it
11453 would be ambiguous if we did, because we use the same forms for all
11456 attr_form_is_section_offset (struct attribute
*attr
)
11458 return (attr
->form
== DW_FORM_data4
11459 || attr
->form
== DW_FORM_data8
);
11463 /* Return non-zero if ATTR's value falls in the 'constant' class, or
11464 zero otherwise. When this function returns true, you can apply
11465 dwarf2_get_attr_constant_value to it.
11467 However, note that for some attributes you must check
11468 attr_form_is_section_offset before using this test. DW_FORM_data4
11469 and DW_FORM_data8 are members of both the constant class, and of
11470 the classes that contain offsets into other debug sections
11471 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
11472 that, if an attribute's can be either a constant or one of the
11473 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
11474 taken as section offsets, not constants. */
11476 attr_form_is_constant (struct attribute
*attr
)
11478 switch (attr
->form
)
11480 case DW_FORM_sdata
:
11481 case DW_FORM_udata
:
11482 case DW_FORM_data1
:
11483 case DW_FORM_data2
:
11484 case DW_FORM_data4
:
11485 case DW_FORM_data8
:
11493 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
11494 struct dwarf2_cu
*cu
)
11496 if (attr_form_is_section_offset (attr
)
11497 /* ".debug_loc" may not exist at all, or the offset may be outside
11498 the section. If so, fall through to the complaint in the
11500 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
11502 struct dwarf2_loclist_baton
*baton
;
11504 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11505 sizeof (struct dwarf2_loclist_baton
));
11506 baton
->per_cu
= cu
->per_cu
;
11507 gdb_assert (baton
->per_cu
);
11509 dwarf2_read_section (dwarf2_per_objfile
->objfile
,
11510 &dwarf2_per_objfile
->loc
);
11512 /* We don't know how long the location list is, but make sure we
11513 don't run off the edge of the section. */
11514 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
11515 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
11516 baton
->base_address
= cu
->base_address
;
11517 if (cu
->base_known
== 0)
11518 complaint (&symfile_complaints
,
11519 _("Location list used without specifying the CU base address."));
11521 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
11522 SYMBOL_LOCATION_BATON (sym
) = baton
;
11526 struct dwarf2_locexpr_baton
*baton
;
11528 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
11529 sizeof (struct dwarf2_locexpr_baton
));
11530 baton
->per_cu
= cu
->per_cu
;
11531 gdb_assert (baton
->per_cu
);
11533 if (attr_form_is_block (attr
))
11535 /* Note that we're just copying the block's data pointer
11536 here, not the actual data. We're still pointing into the
11537 info_buffer for SYM's objfile; right now we never release
11538 that buffer, but when we do clean up properly this may
11540 baton
->size
= DW_BLOCK (attr
)->size
;
11541 baton
->data
= DW_BLOCK (attr
)->data
;
11545 dwarf2_invalid_attrib_class_complaint ("location description",
11546 SYMBOL_NATURAL_NAME (sym
));
11548 baton
->data
= NULL
;
11551 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
11552 SYMBOL_LOCATION_BATON (sym
) = baton
;
11556 /* Return the OBJFILE associated with the compilation unit CU. */
11559 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
11561 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11563 /* Return the master objfile, so that we can report and look up the
11564 correct file containing this variable. */
11565 if (objfile
->separate_debug_objfile_backlink
)
11566 objfile
= objfile
->separate_debug_objfile_backlink
;
11571 /* Return the address size given in the compilation unit header for CU. */
11574 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
11577 return per_cu
->cu
->header
.addr_size
;
11580 /* If the CU is not currently read in, we re-read its header. */
11581 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
11582 struct dwarf2_per_objfile
*per_objfile
11583 = objfile_data (objfile
, dwarf2_objfile_data_key
);
11584 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
11586 struct comp_unit_head cu_header
;
11587 memset (&cu_header
, 0, sizeof cu_header
);
11588 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
11589 return cu_header
.addr_size
;
11593 /* Locate the .debug_info compilation unit from CU's objfile which contains
11594 the DIE at OFFSET. Raises an error on failure. */
11596 static struct dwarf2_per_cu_data
*
11597 dwarf2_find_containing_comp_unit (unsigned int offset
,
11598 struct objfile
*objfile
)
11600 struct dwarf2_per_cu_data
*this_cu
;
11604 high
= dwarf2_per_objfile
->n_comp_units
- 1;
11607 int mid
= low
+ (high
- low
) / 2;
11608 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
11613 gdb_assert (low
== high
);
11614 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
11617 error (_("Dwarf Error: could not find partial DIE containing "
11618 "offset 0x%lx [in module %s]"),
11619 (long) offset
, bfd_get_filename (objfile
->obfd
));
11621 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
11622 return dwarf2_per_objfile
->all_comp_units
[low
-1];
11626 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
11627 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
11628 && offset
>= this_cu
->offset
+ this_cu
->length
)
11629 error (_("invalid dwarf2 offset %u"), offset
);
11630 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
11635 /* Locate the compilation unit from OBJFILE which is located at exactly
11636 OFFSET. Raises an error on failure. */
11638 static struct dwarf2_per_cu_data
*
11639 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
11641 struct dwarf2_per_cu_data
*this_cu
;
11642 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
11643 if (this_cu
->offset
!= offset
)
11644 error (_("no compilation unit with offset %u."), offset
);
11648 /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */
11650 static struct dwarf2_cu
*
11651 alloc_one_comp_unit (struct objfile
*objfile
)
11653 struct dwarf2_cu
*cu
= xcalloc (1, sizeof (struct dwarf2_cu
));
11654 cu
->objfile
= objfile
;
11655 obstack_init (&cu
->comp_unit_obstack
);
11659 /* Release one cached compilation unit, CU. We unlink it from the tree
11660 of compilation units, but we don't remove it from the read_in_chain;
11661 the caller is responsible for that.
11662 NOTE: DATA is a void * because this function is also used as a
11663 cleanup routine. */
11666 free_one_comp_unit (void *data
)
11668 struct dwarf2_cu
*cu
= data
;
11670 if (cu
->per_cu
!= NULL
)
11671 cu
->per_cu
->cu
= NULL
;
11674 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11679 /* This cleanup function is passed the address of a dwarf2_cu on the stack
11680 when we're finished with it. We can't free the pointer itself, but be
11681 sure to unlink it from the cache. Also release any associated storage
11682 and perform cache maintenance.
11684 Only used during partial symbol parsing. */
11687 free_stack_comp_unit (void *data
)
11689 struct dwarf2_cu
*cu
= data
;
11691 obstack_free (&cu
->comp_unit_obstack
, NULL
);
11692 cu
->partial_dies
= NULL
;
11694 if (cu
->per_cu
!= NULL
)
11696 /* This compilation unit is on the stack in our caller, so we
11697 should not xfree it. Just unlink it. */
11698 cu
->per_cu
->cu
= NULL
;
11701 /* If we had a per-cu pointer, then we may have other compilation
11702 units loaded, so age them now. */
11703 age_cached_comp_units ();
11707 /* Free all cached compilation units. */
11710 free_cached_comp_units (void *data
)
11712 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11714 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11715 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11716 while (per_cu
!= NULL
)
11718 struct dwarf2_per_cu_data
*next_cu
;
11720 next_cu
= per_cu
->cu
->read_in_chain
;
11722 free_one_comp_unit (per_cu
->cu
);
11723 *last_chain
= next_cu
;
11729 /* Increase the age counter on each cached compilation unit, and free
11730 any that are too old. */
11733 age_cached_comp_units (void)
11735 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11737 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
11738 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11739 while (per_cu
!= NULL
)
11741 per_cu
->cu
->last_used
++;
11742 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
11743 dwarf2_mark (per_cu
->cu
);
11744 per_cu
= per_cu
->cu
->read_in_chain
;
11747 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11748 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11749 while (per_cu
!= NULL
)
11751 struct dwarf2_per_cu_data
*next_cu
;
11753 next_cu
= per_cu
->cu
->read_in_chain
;
11755 if (!per_cu
->cu
->mark
)
11757 free_one_comp_unit (per_cu
->cu
);
11758 *last_chain
= next_cu
;
11761 last_chain
= &per_cu
->cu
->read_in_chain
;
11767 /* Remove a single compilation unit from the cache. */
11770 free_one_cached_comp_unit (void *target_cu
)
11772 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
11774 per_cu
= dwarf2_per_objfile
->read_in_chain
;
11775 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
11776 while (per_cu
!= NULL
)
11778 struct dwarf2_per_cu_data
*next_cu
;
11780 next_cu
= per_cu
->cu
->read_in_chain
;
11782 if (per_cu
->cu
== target_cu
)
11784 free_one_comp_unit (per_cu
->cu
);
11785 *last_chain
= next_cu
;
11789 last_chain
= &per_cu
->cu
->read_in_chain
;
11795 /* Release all extra memory associated with OBJFILE. */
11798 dwarf2_free_objfile (struct objfile
*objfile
)
11800 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
11802 if (dwarf2_per_objfile
== NULL
)
11805 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
11806 free_cached_comp_units (NULL
);
11808 /* Everything else should be on the objfile obstack. */
11811 /* A pair of DIE offset and GDB type pointer. We store these
11812 in a hash table separate from the DIEs, and preserve them
11813 when the DIEs are flushed out of cache. */
11815 struct dwarf2_offset_and_type
11817 unsigned int offset
;
11821 /* Hash function for a dwarf2_offset_and_type. */
11824 offset_and_type_hash (const void *item
)
11826 const struct dwarf2_offset_and_type
*ofs
= item
;
11827 return ofs
->offset
;
11830 /* Equality function for a dwarf2_offset_and_type. */
11833 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
11835 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
11836 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
11837 return ofs_lhs
->offset
== ofs_rhs
->offset
;
11840 /* Set the type associated with DIE to TYPE. Save it in CU's hash
11841 table if necessary. For convenience, return TYPE. */
11843 static struct type
*
11844 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
11846 struct dwarf2_offset_and_type
**slot
, ofs
;
11848 /* For Ada types, make sure that the gnat-specific data is always
11849 initialized (if not already set). There are a few types where
11850 we should not be doing so, because the type-specific area is
11851 already used to hold some other piece of info (eg: TYPE_CODE_FLT
11852 where the type-specific area is used to store the floatformat).
11853 But this is not a problem, because the gnat-specific information
11854 is actually not needed for these types. */
11855 if (need_gnat_info (cu
)
11856 && TYPE_CODE (type
) != TYPE_CODE_FUNC
11857 && TYPE_CODE (type
) != TYPE_CODE_FLT
11858 && !HAVE_GNAT_AUX_INFO (type
))
11859 INIT_GNAT_SPECIFIC (type
);
11861 if (cu
->type_hash
== NULL
)
11863 gdb_assert (cu
->per_cu
!= NULL
);
11864 cu
->per_cu
->type_hash
11865 = htab_create_alloc_ex (cu
->header
.length
/ 24,
11866 offset_and_type_hash
,
11867 offset_and_type_eq
,
11869 &cu
->objfile
->objfile_obstack
,
11870 hashtab_obstack_allocate
,
11871 dummy_obstack_deallocate
);
11872 cu
->type_hash
= cu
->per_cu
->type_hash
;
11875 ofs
.offset
= die
->offset
;
11877 slot
= (struct dwarf2_offset_and_type
**)
11878 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
11879 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
11884 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
11885 not have a saved type. */
11887 static struct type
*
11888 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
11890 struct dwarf2_offset_and_type
*slot
, ofs
;
11891 htab_t type_hash
= cu
->type_hash
;
11893 if (type_hash
== NULL
)
11896 ofs
.offset
= die
->offset
;
11897 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
11904 /* Add a dependence relationship from CU to REF_PER_CU. */
11907 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
11908 struct dwarf2_per_cu_data
*ref_per_cu
)
11912 if (cu
->dependencies
== NULL
)
11914 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
11915 NULL
, &cu
->comp_unit_obstack
,
11916 hashtab_obstack_allocate
,
11917 dummy_obstack_deallocate
);
11919 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
11921 *slot
= ref_per_cu
;
11924 /* Subroutine of dwarf2_mark to pass to htab_traverse.
11925 Set the mark field in every compilation unit in the
11926 cache that we must keep because we are keeping CU. */
11929 dwarf2_mark_helper (void **slot
, void *data
)
11931 struct dwarf2_per_cu_data
*per_cu
;
11933 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
11934 if (per_cu
->cu
->mark
)
11936 per_cu
->cu
->mark
= 1;
11938 if (per_cu
->cu
->dependencies
!= NULL
)
11939 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11944 /* Set the mark field in CU and in every other compilation unit in the
11945 cache that we must keep because we are keeping CU. */
11948 dwarf2_mark (struct dwarf2_cu
*cu
)
11953 if (cu
->dependencies
!= NULL
)
11954 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
11958 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
11962 per_cu
->cu
->mark
= 0;
11963 per_cu
= per_cu
->cu
->read_in_chain
;
11967 /* Trivial hash function for partial_die_info: the hash value of a DIE
11968 is its offset in .debug_info for this objfile. */
11971 partial_die_hash (const void *item
)
11973 const struct partial_die_info
*part_die
= item
;
11974 return part_die
->offset
;
11977 /* Trivial comparison function for partial_die_info structures: two DIEs
11978 are equal if they have the same offset. */
11981 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
11983 const struct partial_die_info
*part_die_lhs
= item_lhs
;
11984 const struct partial_die_info
*part_die_rhs
= item_rhs
;
11985 return part_die_lhs
->offset
== part_die_rhs
->offset
;
11988 static struct cmd_list_element
*set_dwarf2_cmdlist
;
11989 static struct cmd_list_element
*show_dwarf2_cmdlist
;
11992 set_dwarf2_cmd (char *args
, int from_tty
)
11994 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
11998 show_dwarf2_cmd (char *args
, int from_tty
)
12000 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
12003 /* If section described by INFO was mmapped, munmap it now. */
12006 munmap_section_buffer (struct dwarf2_section_info
*info
)
12008 if (info
->was_mmapped
)
12011 intptr_t begin
= (intptr_t) info
->buffer
;
12012 intptr_t map_begin
= begin
& ~(pagesize
- 1);
12013 size_t map_length
= info
->size
+ begin
- map_begin
;
12014 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
12016 /* Without HAVE_MMAP, we should never be here to begin with. */
12022 /* munmap debug sections for OBJFILE, if necessary. */
12025 dwarf2_per_objfile_free (struct objfile
*objfile
, void *d
)
12027 struct dwarf2_per_objfile
*data
= d
;
12028 munmap_section_buffer (&data
->info
);
12029 munmap_section_buffer (&data
->abbrev
);
12030 munmap_section_buffer (&data
->line
);
12031 munmap_section_buffer (&data
->str
);
12032 munmap_section_buffer (&data
->macinfo
);
12033 munmap_section_buffer (&data
->ranges
);
12034 munmap_section_buffer (&data
->loc
);
12035 munmap_section_buffer (&data
->frame
);
12036 munmap_section_buffer (&data
->eh_frame
);
12039 void _initialize_dwarf2_read (void);
12042 _initialize_dwarf2_read (void)
12044 dwarf2_objfile_data_key
12045 = register_objfile_data_with_cleanup (NULL
, dwarf2_per_objfile_free
);
12047 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
12048 Set DWARF 2 specific variables.\n\
12049 Configure DWARF 2 variables such as the cache size"),
12050 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
12051 0/*allow-unknown*/, &maintenance_set_cmdlist
);
12053 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
12054 Show DWARF 2 specific variables\n\
12055 Show DWARF 2 variables such as the cache size"),
12056 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
12057 0/*allow-unknown*/, &maintenance_show_cmdlist
);
12059 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
12060 &dwarf2_max_cache_age
, _("\
12061 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
12062 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
12063 A higher limit means that cached compilation units will be stored\n\
12064 in memory longer, and more total memory will be used. Zero disables\n\
12065 caching, which can slow down startup."),
12067 show_dwarf2_max_cache_age
,
12068 &set_dwarf2_cmdlist
,
12069 &show_dwarf2_cmdlist
);
12071 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
12072 Set debugging of the dwarf2 DIE reader."), _("\
12073 Show debugging of the dwarf2 DIE reader."), _("\
12074 When enabled (non-zero), DIEs are dumped after they are read in.\n\
12075 The value is the maximum depth to print."),
12078 &setdebuglist
, &showdebuglist
);