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
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/>. */
34 #include "elf/dwarf2.h"
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"
53 #include "gdb_string.h"
54 #include "gdb_assert.h"
55 #include <sys/types.h>
64 /* .debug_info header for a compilation unit
65 Because of alignment constraints, this structure has padding and cannot
66 be mapped directly onto the beginning of the .debug_info section. */
67 typedef struct comp_unit_header
69 unsigned int length
; /* length of the .debug_info
71 unsigned short version
; /* version number -- 2 for DWARF
73 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
74 unsigned char addr_size
; /* byte size of an address -- 4 */
77 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
80 /* .debug_pubnames header
81 Because of alignment constraints, this structure has padding and cannot
82 be mapped directly onto the beginning of the .debug_info section. */
83 typedef struct pubnames_header
85 unsigned int length
; /* length of the .debug_pubnames
87 unsigned char version
; /* version number -- 2 for DWARF
89 unsigned int info_offset
; /* offset into .debug_info section */
90 unsigned int info_size
; /* byte size of .debug_info section
94 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
96 /* .debug_pubnames header
97 Because of alignment constraints, this structure has padding and cannot
98 be mapped directly onto the beginning of the .debug_info section. */
99 typedef struct aranges_header
101 unsigned int length
; /* byte len of the .debug_aranges
103 unsigned short version
; /* version number -- 2 for DWARF
105 unsigned int info_offset
; /* offset into .debug_info section */
106 unsigned char addr_size
; /* byte size of an address */
107 unsigned char seg_size
; /* byte size of segment descriptor */
110 #define _ACTUAL_ARANGES_HEADER_SIZE 12
112 /* .debug_line statement program prologue
113 Because of alignment constraints, this structure has padding and cannot
114 be mapped directly onto the beginning of the .debug_info section. */
115 typedef struct statement_prologue
117 unsigned int total_length
; /* byte length of the statement
119 unsigned short version
; /* version number -- 2 for DWARF
121 unsigned int prologue_length
; /* # bytes between prologue &
123 unsigned char minimum_instruction_length
; /* byte size of
125 unsigned char default_is_stmt
; /* initial value of is_stmt
128 unsigned char line_range
;
129 unsigned char opcode_base
; /* number assigned to first special
131 unsigned char *standard_opcode_lengths
;
135 /* When non-zero, dump DIEs after they are read in. */
136 static int dwarf2_die_debug
= 0;
140 /* When set, the file that we're processing is known to have debugging
141 info for C++ namespaces. GCC 3.3.x did not produce this information,
142 but later versions do. */
144 static int processing_has_namespace_info
;
146 static const struct objfile_data
*dwarf2_objfile_data_key
;
148 struct dwarf2_section_info
156 struct dwarf2_per_objfile
158 struct dwarf2_section_info info
;
159 struct dwarf2_section_info abbrev
;
160 struct dwarf2_section_info line
;
161 struct dwarf2_section_info pubnames
;
162 struct dwarf2_section_info aranges
;
163 struct dwarf2_section_info loc
;
164 struct dwarf2_section_info macinfo
;
165 struct dwarf2_section_info str
;
166 struct dwarf2_section_info ranges
;
167 struct dwarf2_section_info frame
;
168 struct dwarf2_section_info eh_frame
;
170 /* A list of all the compilation units. This is used to locate
171 the target compilation unit of a particular reference. */
172 struct dwarf2_per_cu_data
**all_comp_units
;
174 /* The number of compilation units in ALL_COMP_UNITS. */
177 /* A chain of compilation units that are currently read in, so that
178 they can be freed later. */
179 struct dwarf2_per_cu_data
*read_in_chain
;
181 /* A flag indicating wether this objfile has a section loaded at a
183 int has_section_at_zero
;
186 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
188 /* names of the debugging sections */
190 /* Note that if the debugging section has been compressed, it might
191 have a name like .zdebug_info. */
193 #define INFO_SECTION "debug_info"
194 #define ABBREV_SECTION "debug_abbrev"
195 #define LINE_SECTION "debug_line"
196 #define PUBNAMES_SECTION "debug_pubnames"
197 #define ARANGES_SECTION "debug_aranges"
198 #define LOC_SECTION "debug_loc"
199 #define MACINFO_SECTION "debug_macinfo"
200 #define STR_SECTION "debug_str"
201 #define RANGES_SECTION "debug_ranges"
202 #define FRAME_SECTION "debug_frame"
203 #define EH_FRAME_SECTION "eh_frame"
205 /* local data types */
207 /* We hold several abbreviation tables in memory at the same time. */
208 #ifndef ABBREV_HASH_SIZE
209 #define ABBREV_HASH_SIZE 121
212 /* The data in a compilation unit header, after target2host
213 translation, looks like this. */
214 struct comp_unit_head
218 unsigned char addr_size
;
219 unsigned char signed_addr_p
;
220 unsigned int abbrev_offset
;
222 /* Size of file offsets; either 4 or 8. */
223 unsigned int offset_size
;
225 /* Size of the length field; either 4 or 12. */
226 unsigned int initial_length_size
;
228 /* Offset to the first byte of this compilation unit header in the
229 .debug_info section, for resolving relative reference dies. */
232 /* Offset to first die in this cu from the start of the cu.
233 This will be the first byte following the compilation unit header. */
234 unsigned int first_die_offset
;
237 /* Internal state when decoding a particular compilation unit. */
240 /* The objfile containing this compilation unit. */
241 struct objfile
*objfile
;
243 /* The header of the compilation unit. */
244 struct comp_unit_head header
;
246 /* Base address of this compilation unit. */
247 CORE_ADDR base_address
;
249 /* Non-zero if base_address has been set. */
252 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
254 /* The language we are debugging. */
255 enum language language
;
256 const struct language_defn
*language_defn
;
258 const char *producer
;
260 /* The generic symbol table building routines have separate lists for
261 file scope symbols and all all other scopes (local scopes). So
262 we need to select the right one to pass to add_symbol_to_list().
263 We do it by keeping a pointer to the correct list in list_in_scope.
265 FIXME: The original dwarf code just treated the file scope as the
266 first local scope, and all other local scopes as nested local
267 scopes, and worked fine. Check to see if we really need to
268 distinguish these in buildsym.c. */
269 struct pending
**list_in_scope
;
271 /* DWARF abbreviation table associated with this compilation unit. */
272 struct abbrev_info
**dwarf2_abbrevs
;
274 /* Storage for the abbrev table. */
275 struct obstack abbrev_obstack
;
277 /* Hash table holding all the loaded partial DIEs. */
280 /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */
281 unsigned int ranges_offset
;
283 /* Storage for things with the same lifetime as this read-in compilation
284 unit, including partial DIEs. */
285 struct obstack comp_unit_obstack
;
287 /* When multiple dwarf2_cu structures are living in memory, this field
288 chains them all together, so that they can be released efficiently.
289 We will probably also want a generation counter so that most-recently-used
290 compilation units are cached... */
291 struct dwarf2_per_cu_data
*read_in_chain
;
293 /* Backchain to our per_cu entry if the tree has been built. */
294 struct dwarf2_per_cu_data
*per_cu
;
296 /* Pointer to the die -> type map. Although it is stored
297 permanently in per_cu, we copy it here to avoid double
301 /* How many compilation units ago was this CU last referenced? */
304 /* A hash table of die offsets for following references. */
307 /* Full DIEs if read in. */
308 struct die_info
*dies
;
310 /* A set of pointers to dwarf2_per_cu_data objects for compilation
311 units referenced by this one. Only set during full symbol processing;
312 partial symbol tables do not have dependencies. */
315 /* Header data from the line table, during full symbol processing. */
316 struct line_header
*line_header
;
318 /* Mark used when releasing cached dies. */
319 unsigned int mark
: 1;
321 /* This flag will be set if this compilation unit might include
322 inter-compilation-unit references. */
323 unsigned int has_form_ref_addr
: 1;
325 /* This flag will be set if this compilation unit includes any
326 DW_TAG_namespace DIEs. If we know that there are explicit
327 DIEs for namespaces, we don't need to try to infer them
328 from mangled names. */
329 unsigned int has_namespace_info
: 1;
331 /* Field `ranges_offset' is filled in; flag as the value may be zero. */
332 unsigned int has_ranges_offset
: 1;
335 /* Persistent data held for a compilation unit, even when not
336 processing it. We put a pointer to this structure in the
337 read_symtab_private field of the psymtab. If we encounter
338 inter-compilation-unit references, we also maintain a sorted
339 list of all compilation units. */
341 struct dwarf2_per_cu_data
343 /* The start offset and length of this compilation unit. 2**30-1
344 bytes should suffice to store the length of any compilation unit
345 - if it doesn't, GDB will fall over anyway.
346 NOTE: Unlike comp_unit_head.length, this length includes
347 initial_length_size. */
349 unsigned int length
: 30;
351 /* Flag indicating this compilation unit will be read in before
352 any of the current compilation units are processed. */
353 unsigned int queued
: 1;
355 /* This flag will be set if we need to load absolutely all DIEs
356 for this compilation unit, instead of just the ones we think
357 are interesting. It gets set if we look for a DIE in the
358 hash table and don't find it. */
359 unsigned int load_all_dies
: 1;
361 /* Set iff currently read in. */
362 struct dwarf2_cu
*cu
;
364 /* If full symbols for this CU have been read in, then this field
365 holds a map of DIE offsets to types. It isn't always possible
366 to reconstruct this information later, so we have to preserve
370 /* The partial symbol table associated with this compilation unit,
371 or NULL for partial units (which do not have an associated
373 struct partial_symtab
*psymtab
;
376 /* The line number information for a compilation unit (found in the
377 .debug_line section) begins with a "statement program header",
378 which contains the following information. */
381 unsigned int total_length
;
382 unsigned short version
;
383 unsigned int header_length
;
384 unsigned char minimum_instruction_length
;
385 unsigned char default_is_stmt
;
387 unsigned char line_range
;
388 unsigned char opcode_base
;
390 /* standard_opcode_lengths[i] is the number of operands for the
391 standard opcode whose value is i. This means that
392 standard_opcode_lengths[0] is unused, and the last meaningful
393 element is standard_opcode_lengths[opcode_base - 1]. */
394 unsigned char *standard_opcode_lengths
;
396 /* The include_directories table. NOTE! These strings are not
397 allocated with xmalloc; instead, they are pointers into
398 debug_line_buffer. If you try to free them, `free' will get
400 unsigned int num_include_dirs
, include_dirs_size
;
403 /* The file_names table. NOTE! These strings are not allocated
404 with xmalloc; instead, they are pointers into debug_line_buffer.
405 Don't try to free them directly. */
406 unsigned int num_file_names
, file_names_size
;
410 unsigned int dir_index
;
411 unsigned int mod_time
;
413 int included_p
; /* Non-zero if referenced by the Line Number Program. */
414 struct symtab
*symtab
; /* The associated symbol table, if any. */
417 /* The start and end of the statement program following this
418 header. These point into dwarf2_per_objfile->line_buffer. */
419 gdb_byte
*statement_program_start
, *statement_program_end
;
422 /* When we construct a partial symbol table entry we only
423 need this much information. */
424 struct partial_die_info
426 /* Offset of this DIE. */
429 /* DWARF-2 tag for this DIE. */
430 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
432 /* Language code associated with this DIE. This is only used
433 for the compilation unit DIE. */
434 unsigned int language
: 8;
436 /* Assorted flags describing the data found in this DIE. */
437 unsigned int has_children
: 1;
438 unsigned int is_external
: 1;
439 unsigned int is_declaration
: 1;
440 unsigned int has_type
: 1;
441 unsigned int has_specification
: 1;
442 unsigned int has_stmt_list
: 1;
443 unsigned int has_pc_info
: 1;
445 /* Flag set if the SCOPE field of this structure has been
447 unsigned int scope_set
: 1;
449 /* Flag set if the DIE has a byte_size attribute. */
450 unsigned int has_byte_size
: 1;
452 /* The name of this DIE. Normally the value of DW_AT_name, but
453 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
458 /* The scope to prepend to our children. This is generally
459 allocated on the comp_unit_obstack, so will disappear
460 when this compilation unit leaves the cache. */
463 /* The location description associated with this DIE, if any. */
464 struct dwarf_block
*locdesc
;
466 /* If HAS_PC_INFO, the PC range associated with this DIE. */
470 /* Pointer into the info_buffer pointing at the target of
471 DW_AT_sibling, if any. */
474 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
475 DW_AT_specification (or DW_AT_abstract_origin or
477 unsigned int spec_offset
;
479 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
480 unsigned int line_offset
;
482 /* Pointers to this DIE's parent, first child, and next sibling,
484 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
487 /* This data structure holds the information of an abbrev. */
490 unsigned int number
; /* number identifying abbrev */
491 enum dwarf_tag tag
; /* dwarf tag */
492 unsigned short has_children
; /* boolean */
493 unsigned short num_attrs
; /* number of attributes */
494 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
495 struct abbrev_info
*next
; /* next in chain */
500 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
501 ENUM_BITFIELD(dwarf_form
) form
: 16;
504 /* Additional GDB-specific attribute forms. */
507 /* A string which has been updated to GDB's internal
508 representation (e.g. converted to canonical form) and does not
509 need to be updated again. */
510 GDB_FORM_cached_string
= 0xff
513 /* Attributes have a name and a value */
516 ENUM_BITFIELD(dwarf_attribute
) name
: 16;
517 ENUM_BITFIELD(dwarf_form
) form
: 16;
521 struct dwarf_block
*blk
;
529 /* This data structure holds a complete die structure. */
532 /* DWARF-2 tag for this DIE. */
533 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
535 /* Number of attributes */
536 unsigned short num_attrs
;
541 /* Offset in .debug_info section */
544 /* The dies in a compilation unit form an n-ary tree. PARENT
545 points to this die's parent; CHILD points to the first child of
546 this node; and all the children of a given node are chained
547 together via their SIBLING fields, terminated by a die whose
549 struct die_info
*child
; /* Its first child, if any. */
550 struct die_info
*sibling
; /* Its next sibling, if any. */
551 struct die_info
*parent
; /* Its parent, if any. */
553 /* An array of attributes, with NUM_ATTRS elements. There may be
554 zero, but it's not common and zero-sized arrays are not
555 sufficiently portable C. */
556 struct attribute attrs
[1];
559 struct function_range
562 CORE_ADDR lowpc
, highpc
;
564 struct function_range
*next
;
567 /* Get at parts of an attribute structure */
569 #define DW_STRING(attr) ((attr)->u.str)
570 #define DW_UNSND(attr) ((attr)->u.unsnd)
571 #define DW_BLOCK(attr) ((attr)->u.blk)
572 #define DW_SND(attr) ((attr)->u.snd)
573 #define DW_ADDR(attr) ((attr)->u.addr)
575 /* Blocks are a bunch of untyped bytes. */
582 #ifndef ATTR_ALLOC_CHUNK
583 #define ATTR_ALLOC_CHUNK 4
586 /* Allocate fields for structs, unions and enums in this size. */
587 #ifndef DW_FIELD_ALLOC_CHUNK
588 #define DW_FIELD_ALLOC_CHUNK 4
591 /* A zeroed version of a partial die for initialization purposes. */
592 static struct partial_die_info zeroed_partial_die
;
594 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
595 but this would require a corresponding change in unpack_field_as_long
597 static int bits_per_byte
= 8;
599 /* The routines that read and process dies for a C struct or C++ class
600 pass lists of data member fields and lists of member function fields
601 in an instance of a field_info structure, as defined below. */
604 /* List of data member and baseclasses fields. */
607 struct nextfield
*next
;
614 /* Number of fields. */
617 /* Number of baseclasses. */
620 /* Set if the accesibility of one of the fields is not public. */
621 int non_public_fields
;
623 /* Member function fields array, entries are allocated in the order they
624 are encountered in the object file. */
627 struct nextfnfield
*next
;
628 struct fn_field fnfield
;
632 /* Member function fieldlist array, contains name of possibly overloaded
633 member function, number of overloaded member functions and a pointer
634 to the head of the member function field chain. */
639 struct nextfnfield
*head
;
643 /* Number of entries in the fnfieldlists array. */
647 /* One item on the queue of compilation units to read in full symbols
649 struct dwarf2_queue_item
651 struct dwarf2_per_cu_data
*per_cu
;
652 struct dwarf2_queue_item
*next
;
655 /* The current queue. */
656 static struct dwarf2_queue_item
*dwarf2_queue
, *dwarf2_queue_tail
;
658 /* Loaded secondary compilation units are kept in memory until they
659 have not been referenced for the processing of this many
660 compilation units. Set this to zero to disable caching. Cache
661 sizes of up to at least twenty will improve startup time for
662 typical inter-CU-reference binaries, at an obvious memory cost. */
663 static int dwarf2_max_cache_age
= 5;
665 show_dwarf2_max_cache_age (struct ui_file
*file
, int from_tty
,
666 struct cmd_list_element
*c
, const char *value
)
668 fprintf_filtered (file
, _("\
669 The upper bound on the age of cached dwarf2 compilation units is %s.\n"),
674 /* Various complaints about symbol reading that don't abort the process */
677 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
679 complaint (&symfile_complaints
,
680 _("statement list doesn't fit in .debug_line section"));
684 dwarf2_debug_line_missing_file_complaint (void)
686 complaint (&symfile_complaints
,
687 _(".debug_line section has line data without a file"));
691 dwarf2_debug_line_missing_end_sequence_complaint (void)
693 complaint (&symfile_complaints
,
694 _(".debug_line section has line program sequence without an end"));
698 dwarf2_complex_location_expr_complaint (void)
700 complaint (&symfile_complaints
, _("location expression too complex"));
704 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
707 complaint (&symfile_complaints
,
708 _("const value length mismatch for '%s', got %d, expected %d"), arg1
,
713 dwarf2_macros_too_long_complaint (void)
715 complaint (&symfile_complaints
,
716 _("macro info runs off end of `.debug_macinfo' section"));
720 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
722 complaint (&symfile_complaints
,
723 _("macro debug info contains a malformed macro definition:\n`%s'"),
728 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
730 complaint (&symfile_complaints
,
731 _("invalid attribute class or form for '%s' in '%s'"), arg1
, arg2
);
734 /* local function prototypes */
736 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
739 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
742 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
745 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
746 struct partial_die_info
*,
747 struct partial_symtab
*);
749 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
751 static void scan_partial_symbols (struct partial_die_info
*,
752 CORE_ADDR
*, CORE_ADDR
*,
753 int, struct dwarf2_cu
*);
755 static void add_partial_symbol (struct partial_die_info
*,
758 static int pdi_needs_namespace (enum dwarf_tag tag
);
760 static void add_partial_namespace (struct partial_die_info
*pdi
,
761 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
762 int need_pc
, struct dwarf2_cu
*cu
);
764 static void add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
765 CORE_ADDR
*highpc
, int need_pc
,
766 struct dwarf2_cu
*cu
);
768 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
769 struct dwarf2_cu
*cu
);
771 static void add_partial_subprogram (struct partial_die_info
*pdi
,
772 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
773 int need_pc
, struct dwarf2_cu
*cu
);
775 static gdb_byte
*locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
778 struct dwarf2_cu
*cu
);
780 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
782 static void psymtab_to_symtab_1 (struct partial_symtab
*);
784 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
786 static void dwarf2_free_abbrev_table (void *);
788 static struct abbrev_info
*peek_die_abbrev (gdb_byte
*, unsigned int *,
791 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
794 static struct partial_die_info
*load_partial_dies (bfd
*, gdb_byte
*, int,
797 static gdb_byte
*read_partial_die (struct partial_die_info
*,
798 struct abbrev_info
*abbrev
, unsigned int,
799 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
801 static struct partial_die_info
*find_partial_die (unsigned int,
804 static void fixup_partial_die (struct partial_die_info
*,
807 static gdb_byte
*read_full_die (struct die_info
**, bfd
*, gdb_byte
*,
808 struct dwarf2_cu
*, int *);
810 static gdb_byte
*read_attribute (struct attribute
*, struct attr_abbrev
*,
811 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
813 static gdb_byte
*read_attribute_value (struct attribute
*, unsigned,
814 bfd
*, gdb_byte
*, struct dwarf2_cu
*);
816 static unsigned int read_1_byte (bfd
*, gdb_byte
*);
818 static int read_1_signed_byte (bfd
*, gdb_byte
*);
820 static unsigned int read_2_bytes (bfd
*, gdb_byte
*);
822 static unsigned int read_4_bytes (bfd
*, gdb_byte
*);
824 static unsigned long read_8_bytes (bfd
*, gdb_byte
*);
826 static CORE_ADDR
read_address (bfd
*, gdb_byte
*ptr
, struct dwarf2_cu
*,
829 static LONGEST
read_initial_length (bfd
*, gdb_byte
*, unsigned int *);
831 static LONGEST read_checked_initial_length_and_offset
832 (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
833 unsigned int *, unsigned int *);
835 static LONGEST
read_offset (bfd
*, gdb_byte
*, const struct comp_unit_head
*,
838 static LONGEST
read_offset_1 (bfd
*, gdb_byte
*, unsigned int);
840 static gdb_byte
*read_n_bytes (bfd
*, gdb_byte
*, unsigned int);
842 static char *read_string (bfd
*, gdb_byte
*, unsigned int *);
844 static char *read_indirect_string (bfd
*, gdb_byte
*,
845 const struct comp_unit_head
*,
848 static unsigned long read_unsigned_leb128 (bfd
*, gdb_byte
*, unsigned int *);
850 static long read_signed_leb128 (bfd
*, gdb_byte
*, unsigned int *);
852 static gdb_byte
*skip_leb128 (bfd
*, gdb_byte
*);
854 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
856 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
859 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
860 struct dwarf2_cu
*cu
);
862 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
864 static struct die_info
*die_specification (struct die_info
*die
,
865 struct dwarf2_cu
**);
867 static void free_line_header (struct line_header
*lh
);
869 static void add_file_name (struct line_header
*, char *, unsigned int,
870 unsigned int, unsigned int);
872 static struct line_header
*(dwarf_decode_line_header
873 (unsigned int offset
,
874 bfd
*abfd
, struct dwarf2_cu
*cu
));
876 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
877 struct dwarf2_cu
*, struct partial_symtab
*);
879 static void dwarf2_start_subfile (char *, char *, char *);
881 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
884 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
887 static void dwarf2_const_value_data (struct attribute
*attr
,
891 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
893 static struct type
*die_containing_type (struct die_info
*,
896 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
898 static struct type
*read_type_die (struct die_info
*, struct dwarf2_cu
*);
900 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
902 static char *typename_concat (struct obstack
*,
907 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
909 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
911 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
913 static int dwarf2_ranges_read (unsigned, CORE_ADDR
*, CORE_ADDR
*,
914 struct dwarf2_cu
*, struct partial_symtab
*);
916 static int dwarf2_get_pc_bounds (struct die_info
*,
917 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
919 static void get_scope_pc_bounds (struct die_info
*,
920 CORE_ADDR
*, CORE_ADDR
*,
923 static void dwarf2_record_block_ranges (struct die_info
*, struct block
*,
924 CORE_ADDR
, struct dwarf2_cu
*);
926 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
929 static void dwarf2_attach_fields_to_type (struct field_info
*,
930 struct type
*, struct dwarf2_cu
*);
932 static void dwarf2_add_member_fn (struct field_info
*,
933 struct die_info
*, struct type
*,
936 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
937 struct type
*, struct dwarf2_cu
*);
939 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
941 static const char *determine_class_name (struct die_info
*die
,
942 struct dwarf2_cu
*cu
);
944 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
946 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
948 static void read_module (struct die_info
*die
, struct dwarf2_cu
*cu
);
950 static void read_import_statement (struct die_info
*die
, struct dwarf2_cu
*);
952 static const char *namespace_name (struct die_info
*die
,
953 int *is_anonymous
, struct dwarf2_cu
*);
955 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
957 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
959 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
962 static struct die_info
*read_comp_unit (gdb_byte
*, bfd
*, struct dwarf2_cu
*);
964 static struct die_info
*read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
966 gdb_byte
**new_info_ptr
,
967 struct die_info
*parent
);
969 static struct die_info
*read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
971 gdb_byte
**new_info_ptr
,
972 struct die_info
*parent
);
974 static struct die_info
*read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
976 gdb_byte
**new_info_ptr
,
977 struct die_info
*parent
);
979 static void process_die (struct die_info
*, struct dwarf2_cu
*);
981 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
983 static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu
*,
986 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
988 static struct die_info
*dwarf2_extension (struct die_info
*die
,
989 struct dwarf2_cu
**);
991 static char *dwarf_tag_name (unsigned int);
993 static char *dwarf_attr_name (unsigned int);
995 static char *dwarf_form_name (unsigned int);
997 static char *dwarf_stack_op_name (unsigned int);
999 static char *dwarf_bool_name (unsigned int);
1001 static char *dwarf_type_encoding_name (unsigned int);
1004 static char *dwarf_cfi_name (unsigned int);
1007 static struct die_info
*sibling_die (struct die_info
*);
1009 static void dump_die_shallow (struct ui_file
*, int indent
, struct die_info
*);
1011 static void dump_die_for_error (struct die_info
*);
1013 static void dump_die_1 (struct ui_file
*, int level
, int max_level
,
1016 /*static*/ void dump_die (struct die_info
*, int max_level
);
1018 static void store_in_ref_table (struct die_info
*,
1019 struct dwarf2_cu
*);
1021 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
1023 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
1025 static struct die_info
*follow_die_ref (struct die_info
*,
1027 struct dwarf2_cu
**);
1029 /* memory allocation interface */
1031 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1033 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1035 static struct die_info
*dwarf_alloc_die (struct dwarf2_cu
*, int);
1037 static void initialize_cu_func_list (struct dwarf2_cu
*);
1039 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1040 struct dwarf2_cu
*);
1042 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1043 char *, bfd
*, struct dwarf2_cu
*);
1045 static int attr_form_is_block (struct attribute
*);
1047 static int attr_form_is_section_offset (struct attribute
*);
1049 static int attr_form_is_constant (struct attribute
*);
1051 static void dwarf2_symbol_mark_computed (struct attribute
*attr
,
1053 struct dwarf2_cu
*cu
);
1055 static gdb_byte
*skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
1056 struct dwarf2_cu
*cu
);
1058 static void free_stack_comp_unit (void *);
1060 static hashval_t
partial_die_hash (const void *item
);
1062 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1064 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1065 (unsigned int offset
, struct objfile
*objfile
);
1067 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1068 (unsigned int offset
, struct objfile
*objfile
);
1070 static void free_one_comp_unit (void *);
1072 static void free_cached_comp_units (void *);
1074 static void age_cached_comp_units (void);
1076 static void free_one_cached_comp_unit (void *);
1078 static struct type
*set_die_type (struct die_info
*, struct type
*,
1079 struct dwarf2_cu
*);
1081 static void create_all_comp_units (struct objfile
*);
1083 static struct dwarf2_cu
*load_full_comp_unit (struct dwarf2_per_cu_data
*,
1086 static void process_full_comp_unit (struct dwarf2_per_cu_data
*);
1088 static void dwarf2_add_dependence (struct dwarf2_cu
*,
1089 struct dwarf2_per_cu_data
*);
1091 static void dwarf2_mark (struct dwarf2_cu
*);
1093 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1095 static struct type
*get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
1097 /* Try to locate the sections we need for DWARF 2 debugging
1098 information and return true if we have enough to do something. */
1101 dwarf2_has_info (struct objfile
*objfile
)
1103 struct dwarf2_per_objfile
*data
;
1105 /* Initialize per-objfile state. */
1106 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1107 memset (data
, 0, sizeof (*data
));
1108 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1109 dwarf2_per_objfile
= data
;
1111 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1112 return (data
->info
.asection
!= NULL
&& data
->abbrev
.asection
!= NULL
);
1115 /* When loading sections, we can either look for ".<name>", or for
1116 * ".z<name>", which indicates a compressed section. */
1119 section_is_p (const char *section_name
, const char *name
)
1121 return (section_name
[0] == '.'
1122 && (strcmp (section_name
+ 1, name
) == 0
1123 || (section_name
[1] == 'z'
1124 && strcmp (section_name
+ 2, name
) == 0)));
1127 /* This function is mapped across the sections and remembers the
1128 offset and size of each of the debugging sections we are interested
1132 dwarf2_locate_sections (bfd
*abfd
, asection
*sectp
, void *ignore_ptr
)
1134 if (section_is_p (sectp
->name
, INFO_SECTION
))
1136 dwarf2_per_objfile
->info
.asection
= sectp
;
1137 dwarf2_per_objfile
->info
.size
= bfd_get_section_size (sectp
);
1139 else if (section_is_p (sectp
->name
, ABBREV_SECTION
))
1141 dwarf2_per_objfile
->abbrev
.asection
= sectp
;
1142 dwarf2_per_objfile
->abbrev
.size
= bfd_get_section_size (sectp
);
1144 else if (section_is_p (sectp
->name
, LINE_SECTION
))
1146 dwarf2_per_objfile
->line
.asection
= sectp
;
1147 dwarf2_per_objfile
->line
.size
= bfd_get_section_size (sectp
);
1149 else if (section_is_p (sectp
->name
, PUBNAMES_SECTION
))
1151 dwarf2_per_objfile
->pubnames
.asection
= sectp
;
1152 dwarf2_per_objfile
->pubnames
.size
= bfd_get_section_size (sectp
);
1154 else if (section_is_p (sectp
->name
, ARANGES_SECTION
))
1156 dwarf2_per_objfile
->aranges
.asection
= sectp
;
1157 dwarf2_per_objfile
->aranges
.size
= bfd_get_section_size (sectp
);
1159 else if (section_is_p (sectp
->name
, LOC_SECTION
))
1161 dwarf2_per_objfile
->loc
.asection
= sectp
;
1162 dwarf2_per_objfile
->loc
.size
= bfd_get_section_size (sectp
);
1164 else if (section_is_p (sectp
->name
, MACINFO_SECTION
))
1166 dwarf2_per_objfile
->macinfo
.asection
= sectp
;
1167 dwarf2_per_objfile
->macinfo
.size
= bfd_get_section_size (sectp
);
1169 else if (section_is_p (sectp
->name
, STR_SECTION
))
1171 dwarf2_per_objfile
->str
.asection
= sectp
;
1172 dwarf2_per_objfile
->str
.size
= bfd_get_section_size (sectp
);
1174 else if (section_is_p (sectp
->name
, FRAME_SECTION
))
1176 dwarf2_per_objfile
->frame
.asection
= sectp
;
1177 dwarf2_per_objfile
->frame
.size
= bfd_get_section_size (sectp
);
1179 else if (section_is_p (sectp
->name
, EH_FRAME_SECTION
))
1181 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1182 if (aflag
& SEC_HAS_CONTENTS
)
1184 dwarf2_per_objfile
->eh_frame
.asection
= sectp
;
1185 dwarf2_per_objfile
->eh_frame
.size
= bfd_get_section_size (sectp
);
1188 else if (section_is_p (sectp
->name
, RANGES_SECTION
))
1190 dwarf2_per_objfile
->ranges
.asection
= sectp
;
1191 dwarf2_per_objfile
->ranges
.size
= bfd_get_section_size (sectp
);
1194 if ((bfd_get_section_flags (abfd
, sectp
) & SEC_LOAD
)
1195 && bfd_section_vma (abfd
, sectp
) == 0)
1196 dwarf2_per_objfile
->has_section_at_zero
= 1;
1199 /* Decompress a section that was compressed using zlib. Store the
1200 decompressed buffer, and its size, in OUTBUF and OUTSIZE. */
1203 zlib_decompress_section (struct objfile
*objfile
, asection
*sectp
,
1204 gdb_byte
**outbuf
, bfd_size_type
*outsize
)
1206 bfd
*abfd
= objfile
->obfd
;
1208 error (_("Support for zlib-compressed DWARF data (from '%s') "
1209 "is disabled in this copy of GDB"),
1210 bfd_get_filename (abfd
));
1212 bfd_size_type compressed_size
= bfd_get_section_size (sectp
);
1213 gdb_byte
*compressed_buffer
= xmalloc (compressed_size
);
1214 struct cleanup
*cleanup
= make_cleanup (xfree
, compressed_buffer
);
1215 bfd_size_type uncompressed_size
;
1216 gdb_byte
*uncompressed_buffer
;
1219 int header_size
= 12;
1221 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1222 || bfd_bread (compressed_buffer
, compressed_size
, abfd
) != compressed_size
)
1223 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1224 bfd_get_filename (abfd
));
1226 /* Read the zlib header. In this case, it should be "ZLIB" followed
1227 by the uncompressed section size, 8 bytes in big-endian order. */
1228 if (compressed_size
< header_size
1229 || strncmp (compressed_buffer
, "ZLIB", 4) != 0)
1230 error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"),
1231 bfd_get_filename (abfd
));
1232 uncompressed_size
= compressed_buffer
[4]; uncompressed_size
<<= 8;
1233 uncompressed_size
+= compressed_buffer
[5]; uncompressed_size
<<= 8;
1234 uncompressed_size
+= compressed_buffer
[6]; uncompressed_size
<<= 8;
1235 uncompressed_size
+= compressed_buffer
[7]; uncompressed_size
<<= 8;
1236 uncompressed_size
+= compressed_buffer
[8]; uncompressed_size
<<= 8;
1237 uncompressed_size
+= compressed_buffer
[9]; uncompressed_size
<<= 8;
1238 uncompressed_size
+= compressed_buffer
[10]; uncompressed_size
<<= 8;
1239 uncompressed_size
+= compressed_buffer
[11];
1241 /* It is possible the section consists of several compressed
1242 buffers concatenated together, so we uncompress in a loop. */
1246 strm
.avail_in
= compressed_size
- header_size
;
1247 strm
.next_in
= (Bytef
*) compressed_buffer
+ header_size
;
1248 strm
.avail_out
= uncompressed_size
;
1249 uncompressed_buffer
= obstack_alloc (&objfile
->objfile_obstack
,
1251 rc
= inflateInit (&strm
);
1252 while (strm
.avail_in
> 0)
1255 error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"),
1256 bfd_get_filename (abfd
), rc
);
1257 strm
.next_out
= ((Bytef
*) uncompressed_buffer
1258 + (uncompressed_size
- strm
.avail_out
));
1259 rc
= inflate (&strm
, Z_FINISH
);
1260 if (rc
!= Z_STREAM_END
)
1261 error (_("Dwarf Error: zlib error uncompressing from '%s': %d"),
1262 bfd_get_filename (abfd
), rc
);
1263 rc
= inflateReset (&strm
);
1265 rc
= inflateEnd (&strm
);
1267 || strm
.avail_out
!= 0)
1268 error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"),
1269 bfd_get_filename (abfd
), rc
);
1271 do_cleanups (cleanup
);
1272 *outbuf
= uncompressed_buffer
;
1273 *outsize
= uncompressed_size
;
1277 /* Read the contents of the section SECTP from object file specified by
1278 OBJFILE, store info about the section into INFO.
1279 If the section is compressed, uncompress it before returning. */
1282 dwarf2_read_section (struct objfile
*objfile
, struct dwarf2_section_info
*info
)
1284 bfd
*abfd
= objfile
->obfd
;
1285 asection
*sectp
= info
->asection
;
1286 gdb_byte
*buf
, *retbuf
;
1287 unsigned char header
[4];
1289 info
->buffer
= NULL
;
1290 info
->was_mmapped
= 0;
1292 if (info
->asection
== NULL
|| info
->size
== 0)
1295 /* Check if the file has a 4-byte header indicating compression. */
1296 if (info
->size
> sizeof (header
)
1297 && bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) == 0
1298 && bfd_bread (header
, sizeof (header
), abfd
) == sizeof (header
))
1300 /* Upon decompression, update the buffer and its size. */
1301 if (strncmp (header
, "ZLIB", sizeof (header
)) == 0)
1303 zlib_decompress_section (objfile
, sectp
, &info
->buffer
,
1311 pagesize
= getpagesize ();
1313 /* Only try to mmap sections which are large enough: we don't want to
1314 waste space due to fragmentation. Also, only try mmap for sections
1315 without relocations. */
1317 if (info
->size
> 4 * pagesize
&& (sectp
->flags
& SEC_RELOC
) == 0)
1319 off_t pg_offset
= sectp
->filepos
& ~(pagesize
- 1);
1320 size_t map_length
= info
->size
+ sectp
->filepos
- pg_offset
;
1321 caddr_t retbuf
= bfd_mmap (abfd
, 0, map_length
, PROT_READ
,
1322 MAP_PRIVATE
, pg_offset
);
1324 if (retbuf
!= MAP_FAILED
)
1326 info
->was_mmapped
= 1;
1327 info
->buffer
= retbuf
+ (sectp
->filepos
& (pagesize
- 1)) ;
1333 /* If we get here, we are a normal, not-compressed section. */
1335 = obstack_alloc (&objfile
->objfile_obstack
, info
->size
);
1337 /* When debugging .o files, we may need to apply relocations; see
1338 http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
1339 We never compress sections in .o files, so we only need to
1340 try this when the section is not compressed. */
1341 retbuf
= symfile_relocate_debug_section (abfd
, sectp
, buf
);
1344 info
->buffer
= retbuf
;
1348 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
1349 || bfd_bread (buf
, info
->size
, abfd
) != info
->size
)
1350 error (_("Dwarf Error: Can't read DWARF data from '%s'"),
1351 bfd_get_filename (abfd
));
1354 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
1358 dwarf2_get_section_info (struct objfile
*objfile
, const char *section_name
,
1359 asection
**sectp
, gdb_byte
**bufp
,
1360 bfd_size_type
*sizep
)
1362 struct dwarf2_per_objfile
*data
1363 = objfile_data (objfile
, dwarf2_objfile_data_key
);
1364 struct dwarf2_section_info
*info
;
1365 if (section_is_p (section_name
, EH_FRAME_SECTION
))
1366 info
= &data
->eh_frame
;
1367 else if (section_is_p (section_name
, FRAME_SECTION
))
1368 info
= &data
->frame
;
1372 if (info
->asection
!= NULL
&& info
->size
!= 0 && info
->buffer
== NULL
)
1373 /* We haven't read this section in yet. Do it now. */
1374 dwarf2_read_section (objfile
, info
);
1376 *sectp
= info
->asection
;
1377 *bufp
= info
->buffer
;
1378 *sizep
= info
->size
;
1381 /* Build a partial symbol table. */
1384 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1386 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->info
);
1387 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->abbrev
);
1388 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->line
);
1389 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->str
);
1390 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->macinfo
);
1391 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->ranges
);
1392 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->loc
);
1393 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->eh_frame
);
1394 dwarf2_read_section (objfile
, &dwarf2_per_objfile
->frame
);
1397 || (objfile
->global_psymbols
.size
== 0
1398 && objfile
->static_psymbols
.size
== 0))
1400 init_psymbol_list (objfile
, 1024);
1404 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1406 /* Things are significantly easier if we have .debug_aranges and
1407 .debug_pubnames sections */
1409 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1413 /* only test this case for now */
1415 /* In this case we have to work a bit harder */
1416 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1421 /* Build the partial symbol table from the information in the
1422 .debug_pubnames and .debug_aranges sections. */
1425 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1427 bfd
*abfd
= objfile
->obfd
;
1428 char *aranges_buffer
, *pubnames_buffer
;
1429 char *aranges_ptr
, *pubnames_ptr
;
1430 unsigned int entry_length
, version
, info_offset
, info_size
;
1432 pubnames_buffer
= dwarf2_read_section (objfile
,
1433 dwarf_pubnames_section
);
1434 pubnames_ptr
= pubnames_buffer
;
1435 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames
.size
)
1437 unsigned int bytes_read
;
1439 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &bytes_read
);
1440 pubnames_ptr
+= bytes_read
;
1441 version
= read_1_byte (abfd
, pubnames_ptr
);
1443 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1445 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1449 aranges_buffer
= dwarf2_read_section (objfile
,
1450 dwarf_aranges_section
);
1455 /* Return TRUE if OFFSET is within CU_HEADER. */
1458 offset_in_cu_p (const struct comp_unit_head
*cu_header
, unsigned int offset
)
1460 unsigned int bottom
= cu_header
->offset
;
1461 unsigned int top
= (cu_header
->offset
1463 + cu_header
->initial_length_size
);
1464 return (offset
>= bottom
&& offset
< top
);
1467 /* Read in the comp unit header information from the debug_info at
1471 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1472 gdb_byte
*info_ptr
, bfd
*abfd
)
1475 unsigned int bytes_read
;
1477 cu_header
->length
= read_initial_length (abfd
, info_ptr
, &bytes_read
);
1478 cu_header
->initial_length_size
= bytes_read
;
1479 cu_header
->offset_size
= (bytes_read
== 4) ? 4 : 8;
1480 info_ptr
+= bytes_read
;
1481 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1483 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1485 info_ptr
+= bytes_read
;
1486 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1488 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1489 if (signed_addr
< 0)
1490 internal_error (__FILE__
, __LINE__
,
1491 _("read_comp_unit_head: dwarf from non elf file"));
1492 cu_header
->signed_addr_p
= signed_addr
;
1498 partial_read_comp_unit_head (struct comp_unit_head
*header
, gdb_byte
*info_ptr
,
1501 gdb_byte
*beg_of_comp_unit
= info_ptr
;
1503 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1505 if (header
->version
!= 2 && header
->version
!= 3)
1506 error (_("Dwarf Error: wrong version in compilation unit header "
1507 "(is %d, should be %d) [in module %s]"), header
->version
,
1508 2, bfd_get_filename (abfd
));
1510 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev
.size
)
1511 error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1512 "(offset 0x%lx + 6) [in module %s]"),
1513 (long) header
->abbrev_offset
,
1514 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
),
1515 bfd_get_filename (abfd
));
1517 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1518 > dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
1519 error (_("Dwarf Error: bad length (0x%lx) in compilation unit header "
1520 "(offset 0x%lx + 0) [in module %s]"),
1521 (long) header
->length
,
1522 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
),
1523 bfd_get_filename (abfd
));
1528 /* Allocate a new partial symtab for file named NAME and mark this new
1529 partial symtab as being an include of PST. */
1532 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1533 struct objfile
*objfile
)
1535 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1537 subpst
->section_offsets
= pst
->section_offsets
;
1538 subpst
->textlow
= 0;
1539 subpst
->texthigh
= 0;
1541 subpst
->dependencies
= (struct partial_symtab
**)
1542 obstack_alloc (&objfile
->objfile_obstack
,
1543 sizeof (struct partial_symtab
*));
1544 subpst
->dependencies
[0] = pst
;
1545 subpst
->number_of_dependencies
= 1;
1547 subpst
->globals_offset
= 0;
1548 subpst
->n_global_syms
= 0;
1549 subpst
->statics_offset
= 0;
1550 subpst
->n_static_syms
= 0;
1551 subpst
->symtab
= NULL
;
1552 subpst
->read_symtab
= pst
->read_symtab
;
1555 /* No private part is necessary for include psymtabs. This property
1556 can be used to differentiate between such include psymtabs and
1557 the regular ones. */
1558 subpst
->read_symtab_private
= NULL
;
1561 /* Read the Line Number Program data and extract the list of files
1562 included by the source file represented by PST. Build an include
1563 partial symtab for each of these included files.
1565 This procedure assumes that there *is* a Line Number Program in
1566 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1567 before calling this procedure. */
1570 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1571 struct partial_die_info
*pdi
,
1572 struct partial_symtab
*pst
)
1574 struct objfile
*objfile
= cu
->objfile
;
1575 bfd
*abfd
= objfile
->obfd
;
1576 struct line_header
*lh
;
1578 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1580 return; /* No linetable, so no includes. */
1582 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1584 free_line_header (lh
);
1588 /* Build the partial symbol table by doing a quick pass through the
1589 .debug_info and .debug_abbrev sections. */
1592 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1594 /* Instead of reading this into a big buffer, we should probably use
1595 mmap() on architectures that support it. (FIXME) */
1596 bfd
*abfd
= objfile
->obfd
;
1598 gdb_byte
*beg_of_comp_unit
;
1599 struct partial_die_info comp_unit_die
;
1600 struct partial_symtab
*pst
;
1601 struct cleanup
*back_to
;
1604 info_ptr
= dwarf2_per_objfile
->info
.buffer
;
1606 /* Any cached compilation units will be linked by the per-objfile
1607 read_in_chain. Make sure to free them when we're done. */
1608 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1610 create_all_comp_units (objfile
);
1612 objfile
->psymtabs_addrmap
= addrmap_create_mutable
1613 (&objfile
->objfile_obstack
);
1615 /* Since the objects we're extracting from .debug_info vary in
1616 length, only the individual functions to extract them (like
1617 read_comp_unit_head and load_partial_die) can really know whether
1618 the buffer is large enough to hold another complete object.
1620 At the moment, they don't actually check that. If .debug_info
1621 holds just one extra byte after the last compilation unit's dies,
1622 then read_comp_unit_head will happily read off the end of the
1623 buffer. read_partial_die is similarly casual. Those functions
1626 For this loop condition, simply checking whether there's any data
1627 left at all should be sufficient. */
1628 while (info_ptr
< (dwarf2_per_objfile
->info
.buffer
1629 + dwarf2_per_objfile
->info
.size
))
1631 struct cleanup
*back_to_inner
;
1632 struct dwarf2_cu cu
;
1633 struct abbrev_info
*abbrev
;
1634 unsigned int bytes_read
;
1635 struct dwarf2_per_cu_data
*this_cu
;
1637 beg_of_comp_unit
= info_ptr
;
1639 memset (&cu
, 0, sizeof (cu
));
1641 obstack_init (&cu
.comp_unit_obstack
);
1643 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1645 cu
.objfile
= objfile
;
1646 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1648 /* Complete the cu_header */
1649 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
;
1650 cu
.header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1652 cu
.list_in_scope
= &file_symbols
;
1654 /* Read the abbrevs for this compilation unit into a table */
1655 dwarf2_read_abbrevs (abfd
, &cu
);
1656 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1658 this_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1660 /* Read the compilation unit die */
1661 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1662 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1663 abfd
, info_ptr
, &cu
);
1665 if (comp_unit_die
.tag
== DW_TAG_partial_unit
)
1667 info_ptr
= (beg_of_comp_unit
+ cu
.header
.length
1668 + cu
.header
.initial_length_size
);
1669 do_cleanups (back_to_inner
);
1673 /* Set the language we're debugging */
1674 set_cu_language (comp_unit_die
.language
, &cu
);
1676 /* Allocate a new partial symbol table structure */
1677 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1678 comp_unit_die
.name
? comp_unit_die
.name
: "",
1679 /* TEXTLOW and TEXTHIGH are set below. */
1681 objfile
->global_psymbols
.next
,
1682 objfile
->static_psymbols
.next
);
1684 if (comp_unit_die
.dirname
)
1685 pst
->dirname
= obsavestring (comp_unit_die
.dirname
,
1686 strlen (comp_unit_die
.dirname
),
1687 &objfile
->objfile_obstack
);
1689 pst
->read_symtab_private
= (char *) this_cu
;
1691 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1693 /* Store the function that reads in the rest of the symbol table */
1694 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1696 /* If this compilation unit was already read in, free the
1697 cached copy in order to read it in again. This is
1698 necessary because we skipped some symbols when we first
1699 read in the compilation unit (see load_partial_dies).
1700 This problem could be avoided, but the benefit is
1702 if (this_cu
->cu
!= NULL
)
1703 free_one_cached_comp_unit (this_cu
->cu
);
1705 cu
.per_cu
= this_cu
;
1707 /* Note that this is a pointer to our stack frame, being
1708 added to a global data structure. It will be cleaned up
1709 in free_stack_comp_unit when we finish with this
1710 compilation unit. */
1713 this_cu
->psymtab
= pst
;
1715 /* Possibly set the default values of LOWPC and HIGHPC from
1717 if (cu
.has_ranges_offset
)
1719 if (dwarf2_ranges_read (cu
.ranges_offset
, &comp_unit_die
.lowpc
,
1720 &comp_unit_die
.highpc
, &cu
, pst
))
1721 comp_unit_die
.has_pc_info
= 1;
1723 else if (comp_unit_die
.has_pc_info
1724 && comp_unit_die
.lowpc
< comp_unit_die
.highpc
)
1725 /* Store the contiguous range if it is not empty; it can be empty for
1726 CUs with no code. */
1727 addrmap_set_empty (objfile
->psymtabs_addrmap
,
1728 comp_unit_die
.lowpc
+ baseaddr
,
1729 comp_unit_die
.highpc
+ baseaddr
- 1, pst
);
1731 /* Check if comp unit has_children.
1732 If so, read the rest of the partial symbols from this comp unit.
1733 If not, there's no more debug_info for this comp unit. */
1734 if (comp_unit_die
.has_children
)
1736 struct partial_die_info
*first_die
;
1737 CORE_ADDR lowpc
, highpc
;
1739 lowpc
= ((CORE_ADDR
) -1);
1740 highpc
= ((CORE_ADDR
) 0);
1742 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1744 scan_partial_symbols (first_die
, &lowpc
, &highpc
,
1745 ! comp_unit_die
.has_pc_info
, &cu
);
1747 /* If we didn't find a lowpc, set it to highpc to avoid
1748 complaints from `maint check'. */
1749 if (lowpc
== ((CORE_ADDR
) -1))
1752 /* If the compilation unit didn't have an explicit address range,
1753 then use the information extracted from its child dies. */
1754 if (! comp_unit_die
.has_pc_info
)
1756 comp_unit_die
.lowpc
= lowpc
;
1757 comp_unit_die
.highpc
= highpc
;
1760 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1761 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1763 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1764 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1765 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1766 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1767 sort_pst_symbols (pst
);
1769 /* If there is already a psymtab or symtab for a file of this
1770 name, remove it. (If there is a symtab, more drastic things
1771 also happen.) This happens in VxWorks. */
1772 free_named_symtabs (pst
->filename
);
1774 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1775 + cu
.header
.initial_length_size
;
1777 if (comp_unit_die
.has_stmt_list
)
1779 /* Get the list of files included in the current compilation unit,
1780 and build a psymtab for each of them. */
1781 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1784 do_cleanups (back_to_inner
);
1787 objfile
->psymtabs_addrmap
= addrmap_create_fixed (objfile
->psymtabs_addrmap
,
1788 &objfile
->objfile_obstack
);
1790 do_cleanups (back_to
);
1793 /* Load the DIEs for a secondary CU into memory. */
1796 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1798 bfd
*abfd
= objfile
->obfd
;
1799 gdb_byte
*info_ptr
, *beg_of_comp_unit
;
1800 struct partial_die_info comp_unit_die
;
1801 struct dwarf2_cu
*cu
;
1802 struct abbrev_info
*abbrev
;
1803 unsigned int bytes_read
;
1804 struct cleanup
*back_to
;
1806 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ this_cu
->offset
;
1807 beg_of_comp_unit
= info_ptr
;
1809 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1810 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1812 obstack_init (&cu
->comp_unit_obstack
);
1814 cu
->objfile
= objfile
;
1815 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1817 /* Complete the cu_header. */
1818 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info
.buffer
;
1819 cu
->header
.first_die_offset
= info_ptr
- beg_of_comp_unit
;
1821 /* Read the abbrevs for this compilation unit into a table. */
1822 dwarf2_read_abbrevs (abfd
, cu
);
1823 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1825 /* Read the compilation unit die. */
1826 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1827 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1828 abfd
, info_ptr
, cu
);
1830 /* Set the language we're debugging. */
1831 set_cu_language (comp_unit_die
.language
, cu
);
1833 /* Link this compilation unit into the compilation unit tree. */
1835 cu
->per_cu
= this_cu
;
1836 cu
->type_hash
= cu
->per_cu
->type_hash
;
1838 /* Check if comp unit has_children.
1839 If so, read the rest of the partial symbols from this comp unit.
1840 If not, there's no more debug_info for this comp unit. */
1841 if (comp_unit_die
.has_children
)
1842 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1844 do_cleanups (back_to
);
1847 /* Create a list of all compilation units in OBJFILE. We do this only
1848 if an inter-comp-unit reference is found; presumably if there is one,
1849 there will be many, and one will occur early in the .debug_info section.
1850 So there's no point in building this list incrementally. */
1853 create_all_comp_units (struct objfile
*objfile
)
1857 struct dwarf2_per_cu_data
**all_comp_units
;
1858 gdb_byte
*info_ptr
= dwarf2_per_objfile
->info
.buffer
;
1862 all_comp_units
= xmalloc (n_allocated
1863 * sizeof (struct dwarf2_per_cu_data
*));
1865 while (info_ptr
< dwarf2_per_objfile
->info
.buffer
+ dwarf2_per_objfile
->info
.size
)
1867 unsigned int length
, initial_length_size
;
1868 gdb_byte
*beg_of_comp_unit
;
1869 struct dwarf2_per_cu_data
*this_cu
;
1870 unsigned int offset
;
1872 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
1874 /* Read just enough information to find out where the next
1875 compilation unit is. */
1876 length
= read_initial_length (objfile
->obfd
, info_ptr
,
1877 &initial_length_size
);
1879 /* Save the compilation unit for later lookup. */
1880 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1881 sizeof (struct dwarf2_per_cu_data
));
1882 memset (this_cu
, 0, sizeof (*this_cu
));
1883 this_cu
->offset
= offset
;
1884 this_cu
->length
= length
+ initial_length_size
;
1886 if (n_comp_units
== n_allocated
)
1889 all_comp_units
= xrealloc (all_comp_units
,
1891 * sizeof (struct dwarf2_per_cu_data
*));
1893 all_comp_units
[n_comp_units
++] = this_cu
;
1895 info_ptr
= info_ptr
+ this_cu
->length
;
1898 dwarf2_per_objfile
->all_comp_units
1899 = obstack_alloc (&objfile
->objfile_obstack
,
1900 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1901 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1902 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1903 xfree (all_comp_units
);
1904 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1907 /* Process all loaded DIEs for compilation unit CU, starting at
1908 FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation
1909 unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or
1910 DW_AT_ranges). If NEED_PC is set, then this function will set
1911 *LOWPC and *HIGHPC to the lowest and highest PC values found in CU
1912 and record the covered ranges in the addrmap. */
1915 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1916 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
1918 struct objfile
*objfile
= cu
->objfile
;
1919 bfd
*abfd
= objfile
->obfd
;
1920 struct partial_die_info
*pdi
;
1922 /* Now, march along the PDI's, descending into ones which have
1923 interesting children but skipping the children of the other ones,
1924 until we reach the end of the compilation unit. */
1930 fixup_partial_die (pdi
, cu
);
1932 /* Anonymous namespaces have no name but have interesting
1933 children, so we need to look at them. Ditto for anonymous
1936 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1937 || pdi
->tag
== DW_TAG_enumeration_type
)
1941 case DW_TAG_subprogram
:
1942 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
1944 case DW_TAG_variable
:
1945 case DW_TAG_typedef
:
1946 case DW_TAG_union_type
:
1947 if (!pdi
->is_declaration
)
1949 add_partial_symbol (pdi
, cu
);
1952 case DW_TAG_class_type
:
1953 case DW_TAG_interface_type
:
1954 case DW_TAG_structure_type
:
1955 if (!pdi
->is_declaration
)
1957 add_partial_symbol (pdi
, cu
);
1960 case DW_TAG_enumeration_type
:
1961 if (!pdi
->is_declaration
)
1962 add_partial_enumeration (pdi
, cu
);
1964 case DW_TAG_base_type
:
1965 case DW_TAG_subrange_type
:
1966 /* File scope base type definitions are added to the partial
1968 add_partial_symbol (pdi
, cu
);
1970 case DW_TAG_namespace
:
1971 add_partial_namespace (pdi
, lowpc
, highpc
, need_pc
, cu
);
1974 add_partial_module (pdi
, lowpc
, highpc
, need_pc
, cu
);
1981 /* If the die has a sibling, skip to the sibling. */
1983 pdi
= pdi
->die_sibling
;
1987 /* Functions used to compute the fully scoped name of a partial DIE.
1989 Normally, this is simple. For C++, the parent DIE's fully scoped
1990 name is concatenated with "::" and the partial DIE's name. For
1991 Java, the same thing occurs except that "." is used instead of "::".
1992 Enumerators are an exception; they use the scope of their parent
1993 enumeration type, i.e. the name of the enumeration type is not
1994 prepended to the enumerator.
1996 There are two complexities. One is DW_AT_specification; in this
1997 case "parent" means the parent of the target of the specification,
1998 instead of the direct parent of the DIE. The other is compilers
1999 which do not emit DW_TAG_namespace; in this case we try to guess
2000 the fully qualified name of structure types from their members'
2001 linkage names. This must be done using the DIE's children rather
2002 than the children of any DW_AT_specification target. We only need
2003 to do this for structures at the top level, i.e. if the target of
2004 any DW_AT_specification (if any; otherwise the DIE itself) does not
2007 /* Compute the scope prefix associated with PDI's parent, in
2008 compilation unit CU. The result will be allocated on CU's
2009 comp_unit_obstack, or a copy of the already allocated PDI->NAME
2010 field. NULL is returned if no prefix is necessary. */
2012 partial_die_parent_scope (struct partial_die_info
*pdi
,
2013 struct dwarf2_cu
*cu
)
2015 char *grandparent_scope
;
2016 struct partial_die_info
*parent
, *real_pdi
;
2018 /* We need to look at our parent DIE; if we have a DW_AT_specification,
2019 then this means the parent of the specification DIE. */
2022 while (real_pdi
->has_specification
)
2023 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2025 parent
= real_pdi
->die_parent
;
2029 if (parent
->scope_set
)
2030 return parent
->scope
;
2032 fixup_partial_die (parent
, cu
);
2034 grandparent_scope
= partial_die_parent_scope (parent
, cu
);
2036 if (parent
->tag
== DW_TAG_namespace
2037 || parent
->tag
== DW_TAG_structure_type
2038 || parent
->tag
== DW_TAG_class_type
2039 || parent
->tag
== DW_TAG_interface_type
2040 || parent
->tag
== DW_TAG_union_type
)
2042 if (grandparent_scope
== NULL
)
2043 parent
->scope
= parent
->name
;
2045 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
2048 else if (parent
->tag
== DW_TAG_enumeration_type
)
2049 /* Enumerators should not get the name of the enumeration as a prefix. */
2050 parent
->scope
= grandparent_scope
;
2053 /* FIXME drow/2004-04-01: What should we be doing with
2054 function-local names? For partial symbols, we should probably be
2056 complaint (&symfile_complaints
,
2057 _("unhandled containing DIE tag %d for DIE at %d"),
2058 parent
->tag
, pdi
->offset
);
2059 parent
->scope
= grandparent_scope
;
2062 parent
->scope_set
= 1;
2063 return parent
->scope
;
2066 /* Return the fully scoped name associated with PDI, from compilation unit
2067 CU. The result will be allocated with malloc. */
2069 partial_die_full_name (struct partial_die_info
*pdi
,
2070 struct dwarf2_cu
*cu
)
2074 parent_scope
= partial_die_parent_scope (pdi
, cu
);
2075 if (parent_scope
== NULL
)
2078 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
2082 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
2084 struct objfile
*objfile
= cu
->objfile
;
2086 char *actual_name
= NULL
;
2087 const char *my_prefix
;
2088 const struct partial_symbol
*psym
= NULL
;
2090 int built_actual_name
= 0;
2092 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2094 if (pdi_needs_namespace (pdi
->tag
))
2096 actual_name
= partial_die_full_name (pdi
, cu
);
2098 built_actual_name
= 1;
2101 if (actual_name
== NULL
)
2102 actual_name
= pdi
->name
;
2106 case DW_TAG_subprogram
:
2107 if (pdi
->is_external
|| cu
->language
== language_ada
)
2109 /* brobecker/2007-12-26: Normally, only "external" DIEs are part
2110 of the global scope. But in Ada, we want to be able to access
2111 nested procedures globally. So all Ada subprograms are stored
2112 in the global scope. */
2113 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2114 mst_text, objfile); */
2115 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2116 VAR_DOMAIN
, LOC_BLOCK
,
2117 &objfile
->global_psymbols
,
2118 0, pdi
->lowpc
+ baseaddr
,
2119 cu
->language
, objfile
);
2123 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
2124 mst_file_text, objfile); */
2125 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2126 VAR_DOMAIN
, LOC_BLOCK
,
2127 &objfile
->static_psymbols
,
2128 0, pdi
->lowpc
+ baseaddr
,
2129 cu
->language
, objfile
);
2132 case DW_TAG_variable
:
2133 if (pdi
->is_external
)
2136 Don't enter into the minimal symbol tables as there is
2137 a minimal symbol table entry from the ELF symbols already.
2138 Enter into partial symbol table if it has a location
2139 descriptor or a type.
2140 If the location descriptor is missing, new_symbol will create
2141 a LOC_UNRESOLVED symbol, the address of the variable will then
2142 be determined from the minimal symbol table whenever the variable
2144 The address for the partial symbol table entry is not
2145 used by GDB, but it comes in handy for debugging partial symbol
2149 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2150 if (pdi
->locdesc
|| pdi
->has_type
)
2151 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2152 VAR_DOMAIN
, LOC_STATIC
,
2153 &objfile
->global_psymbols
,
2155 cu
->language
, objfile
);
2159 /* Static Variable. Skip symbols without location descriptors. */
2160 if (pdi
->locdesc
== NULL
)
2162 if (built_actual_name
)
2163 xfree (actual_name
);
2166 addr
= decode_locdesc (pdi
->locdesc
, cu
);
2167 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
2168 mst_file_data, objfile); */
2169 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
2170 VAR_DOMAIN
, LOC_STATIC
,
2171 &objfile
->static_psymbols
,
2173 cu
->language
, objfile
);
2176 case DW_TAG_typedef
:
2177 case DW_TAG_base_type
:
2178 case DW_TAG_subrange_type
:
2179 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2180 VAR_DOMAIN
, LOC_TYPEDEF
,
2181 &objfile
->static_psymbols
,
2182 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2184 case DW_TAG_namespace
:
2185 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2186 VAR_DOMAIN
, LOC_TYPEDEF
,
2187 &objfile
->global_psymbols
,
2188 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2190 case DW_TAG_class_type
:
2191 case DW_TAG_interface_type
:
2192 case DW_TAG_structure_type
:
2193 case DW_TAG_union_type
:
2194 case DW_TAG_enumeration_type
:
2195 /* Skip external references. The DWARF standard says in the section
2196 about "Structure, Union, and Class Type Entries": "An incomplete
2197 structure, union or class type is represented by a structure,
2198 union or class entry that does not have a byte size attribute
2199 and that has a DW_AT_declaration attribute." */
2200 if (!pdi
->has_byte_size
&& pdi
->is_declaration
)
2202 if (built_actual_name
)
2203 xfree (actual_name
);
2207 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
2208 static vs. global. */
2209 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2210 STRUCT_DOMAIN
, LOC_TYPEDEF
,
2211 (cu
->language
== language_cplus
2212 || cu
->language
== language_java
)
2213 ? &objfile
->global_psymbols
2214 : &objfile
->static_psymbols
,
2215 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2218 case DW_TAG_enumerator
:
2219 add_psymbol_to_list (actual_name
, strlen (actual_name
),
2220 VAR_DOMAIN
, LOC_CONST
,
2221 (cu
->language
== language_cplus
2222 || cu
->language
== language_java
)
2223 ? &objfile
->global_psymbols
2224 : &objfile
->static_psymbols
,
2225 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
2231 /* Check to see if we should scan the name for possible namespace
2232 info. Only do this if this is C++, if we don't have namespace
2233 debugging info in the file, if the psym is of an appropriate type
2234 (otherwise we'll have psym == NULL), and if we actually had a
2235 mangled name to begin with. */
2237 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
2238 cases which do not set PSYM above? */
2240 if (cu
->language
== language_cplus
2241 && cu
->has_namespace_info
== 0
2243 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2244 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2247 if (built_actual_name
)
2248 xfree (actual_name
);
2251 /* Determine whether a die of type TAG living in a C++ class or
2252 namespace needs to have the name of the scope prepended to the
2253 name listed in the die. */
2256 pdi_needs_namespace (enum dwarf_tag tag
)
2260 case DW_TAG_namespace
:
2261 case DW_TAG_typedef
:
2262 case DW_TAG_class_type
:
2263 case DW_TAG_interface_type
:
2264 case DW_TAG_structure_type
:
2265 case DW_TAG_union_type
:
2266 case DW_TAG_enumeration_type
:
2267 case DW_TAG_enumerator
:
2274 /* Read a partial die corresponding to a namespace; also, add a symbol
2275 corresponding to that namespace to the symbol table. NAMESPACE is
2276 the name of the enclosing namespace. */
2279 add_partial_namespace (struct partial_die_info
*pdi
,
2280 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2281 int need_pc
, struct dwarf2_cu
*cu
)
2283 struct objfile
*objfile
= cu
->objfile
;
2285 /* Add a symbol for the namespace. */
2287 add_partial_symbol (pdi
, cu
);
2289 /* Now scan partial symbols in that namespace. */
2291 if (pdi
->has_children
)
2292 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2295 /* Read a partial die corresponding to a Fortran module. */
2298 add_partial_module (struct partial_die_info
*pdi
, CORE_ADDR
*lowpc
,
2299 CORE_ADDR
*highpc
, int need_pc
, struct dwarf2_cu
*cu
)
2301 /* Now scan partial symbols in that module.
2303 FIXME: Support the separate Fortran module namespaces. */
2305 if (pdi
->has_children
)
2306 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, need_pc
, cu
);
2309 /* Read a partial die corresponding to a subprogram and create a partial
2310 symbol for that subprogram. When the CU language allows it, this
2311 routine also defines a partial symbol for each nested subprogram
2312 that this subprogram contains.
2314 DIE my also be a lexical block, in which case we simply search
2315 recursively for suprograms defined inside that lexical block.
2316 Again, this is only performed when the CU language allows this
2317 type of definitions. */
2320 add_partial_subprogram (struct partial_die_info
*pdi
,
2321 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2322 int need_pc
, struct dwarf2_cu
*cu
)
2324 if (pdi
->tag
== DW_TAG_subprogram
)
2326 if (pdi
->has_pc_info
)
2328 if (pdi
->lowpc
< *lowpc
)
2329 *lowpc
= pdi
->lowpc
;
2330 if (pdi
->highpc
> *highpc
)
2331 *highpc
= pdi
->highpc
;
2335 struct objfile
*objfile
= cu
->objfile
;
2337 baseaddr
= ANOFFSET (objfile
->section_offsets
,
2338 SECT_OFF_TEXT (objfile
));
2339 addrmap_set_empty (objfile
->psymtabs_addrmap
,
2340 pdi
->lowpc
, pdi
->highpc
- 1,
2341 cu
->per_cu
->psymtab
);
2343 if (!pdi
->is_declaration
)
2344 add_partial_symbol (pdi
, cu
);
2348 if (! pdi
->has_children
)
2351 if (cu
->language
== language_ada
)
2353 pdi
= pdi
->die_child
;
2356 fixup_partial_die (pdi
, cu
);
2357 if (pdi
->tag
== DW_TAG_subprogram
2358 || pdi
->tag
== DW_TAG_lexical_block
)
2359 add_partial_subprogram (pdi
, lowpc
, highpc
, need_pc
, cu
);
2360 pdi
= pdi
->die_sibling
;
2365 /* See if we can figure out if the class lives in a namespace. We do
2366 this by looking for a member function; its demangled name will
2367 contain namespace info, if there is any. */
2370 guess_structure_name (struct partial_die_info
*struct_pdi
,
2371 struct dwarf2_cu
*cu
)
2373 if ((cu
->language
== language_cplus
2374 || cu
->language
== language_java
)
2375 && cu
->has_namespace_info
== 0
2376 && struct_pdi
->has_children
)
2378 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2379 what template types look like, because the demangler
2380 frequently doesn't give the same name as the debug info. We
2381 could fix this by only using the demangled name to get the
2382 prefix (but see comment in read_structure_type). */
2384 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2385 struct partial_die_info
*real_pdi
;
2387 /* If this DIE (this DIE's specification, if any) has a parent, then
2388 we should not do this. We'll prepend the parent's fully qualified
2389 name when we create the partial symbol. */
2391 real_pdi
= struct_pdi
;
2392 while (real_pdi
->has_specification
)
2393 real_pdi
= find_partial_die (real_pdi
->spec_offset
, cu
);
2395 if (real_pdi
->die_parent
!= NULL
)
2398 while (child_pdi
!= NULL
)
2400 if (child_pdi
->tag
== DW_TAG_subprogram
)
2402 char *actual_class_name
2403 = language_class_name_from_physname (cu
->language_defn
,
2405 if (actual_class_name
!= NULL
)
2408 = obsavestring (actual_class_name
,
2409 strlen (actual_class_name
),
2410 &cu
->comp_unit_obstack
);
2411 xfree (actual_class_name
);
2416 child_pdi
= child_pdi
->die_sibling
;
2421 /* Read a partial die corresponding to an enumeration type. */
2424 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2425 struct dwarf2_cu
*cu
)
2427 struct objfile
*objfile
= cu
->objfile
;
2428 bfd
*abfd
= objfile
->obfd
;
2429 struct partial_die_info
*pdi
;
2431 if (enum_pdi
->name
!= NULL
)
2432 add_partial_symbol (enum_pdi
, cu
);
2434 pdi
= enum_pdi
->die_child
;
2437 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2438 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
2440 add_partial_symbol (pdi
, cu
);
2441 pdi
= pdi
->die_sibling
;
2445 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2446 Return the corresponding abbrev, or NULL if the number is zero (indicating
2447 an empty DIE). In either case *BYTES_READ will be set to the length of
2448 the initial number. */
2450 static struct abbrev_info
*
2451 peek_die_abbrev (gdb_byte
*info_ptr
, unsigned int *bytes_read
,
2452 struct dwarf2_cu
*cu
)
2454 bfd
*abfd
= cu
->objfile
->obfd
;
2455 unsigned int abbrev_number
;
2456 struct abbrev_info
*abbrev
;
2458 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2460 if (abbrev_number
== 0)
2463 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2466 error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number
,
2467 bfd_get_filename (abfd
));
2473 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2474 pointer to the end of a series of DIEs, terminated by an empty
2475 DIE. Any children of the skipped DIEs will also be skipped. */
2478 skip_children (gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
2480 struct abbrev_info
*abbrev
;
2481 unsigned int bytes_read
;
2485 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2487 return info_ptr
+ bytes_read
;
2489 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2493 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2494 should point just after the initial uleb128 of a DIE, and the
2495 abbrev corresponding to that skipped uleb128 should be passed in
2496 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2500 skip_one_die (gdb_byte
*info_ptr
, struct abbrev_info
*abbrev
,
2501 struct dwarf2_cu
*cu
)
2503 unsigned int bytes_read
;
2504 struct attribute attr
;
2505 bfd
*abfd
= cu
->objfile
->obfd
;
2506 unsigned int form
, i
;
2508 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2510 /* The only abbrev we care about is DW_AT_sibling. */
2511 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2513 read_attribute (&attr
, &abbrev
->attrs
[i
],
2514 abfd
, info_ptr
, cu
);
2515 if (attr
.form
== DW_FORM_ref_addr
)
2516 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
2518 return dwarf2_per_objfile
->info
.buffer
2519 + dwarf2_get_ref_die_offset (&attr
);
2522 /* If it isn't DW_AT_sibling, skip this attribute. */
2523 form
= abbrev
->attrs
[i
].form
;
2528 case DW_FORM_ref_addr
:
2529 info_ptr
+= cu
->header
.addr_size
;
2548 case DW_FORM_string
:
2549 read_string (abfd
, info_ptr
, &bytes_read
);
2550 info_ptr
+= bytes_read
;
2553 info_ptr
+= cu
->header
.offset_size
;
2556 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2557 info_ptr
+= bytes_read
;
2559 case DW_FORM_block1
:
2560 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2562 case DW_FORM_block2
:
2563 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2565 case DW_FORM_block4
:
2566 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2570 case DW_FORM_ref_udata
:
2571 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2573 case DW_FORM_indirect
:
2574 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2575 info_ptr
+= bytes_read
;
2576 /* We need to continue parsing from here, so just go back to
2578 goto skip_attribute
;
2581 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
2582 dwarf_form_name (form
),
2583 bfd_get_filename (abfd
));
2587 if (abbrev
->has_children
)
2588 return skip_children (info_ptr
, cu
);
2593 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2594 the next DIE after ORIG_PDI. */
2597 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, gdb_byte
*info_ptr
,
2598 bfd
*abfd
, struct dwarf2_cu
*cu
)
2600 /* Do we know the sibling already? */
2602 if (orig_pdi
->sibling
)
2603 return orig_pdi
->sibling
;
2605 /* Are there any children to deal with? */
2607 if (!orig_pdi
->has_children
)
2610 /* Skip the children the long way. */
2612 return skip_children (info_ptr
, cu
);
2615 /* Expand this partial symbol table into a full symbol table. */
2618 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2620 /* FIXME: This is barely more than a stub. */
2625 warning (_("bug: psymtab for %s is already read in."), pst
->filename
);
2631 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
2632 gdb_flush (gdb_stdout
);
2635 /* Restore our global data. */
2636 dwarf2_per_objfile
= objfile_data (pst
->objfile
,
2637 dwarf2_objfile_data_key
);
2639 /* If this psymtab is constructed from a debug-only objfile, the
2640 has_section_at_zero flag will not necessarily be correct. We
2641 can get the correct value for this flag by looking at the data
2642 associated with the (presumably stripped) associated objfile. */
2643 if (pst
->objfile
->separate_debug_objfile_backlink
)
2645 struct dwarf2_per_objfile
*dpo_backlink
2646 = objfile_data (pst
->objfile
->separate_debug_objfile_backlink
,
2647 dwarf2_objfile_data_key
);
2648 dwarf2_per_objfile
->has_section_at_zero
2649 = dpo_backlink
->has_section_at_zero
;
2652 psymtab_to_symtab_1 (pst
);
2654 /* Finish up the debug error message. */
2656 printf_filtered (_("done.\n"));
2661 /* Add PER_CU to the queue. */
2664 queue_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2666 struct dwarf2_queue_item
*item
;
2669 item
= xmalloc (sizeof (*item
));
2670 item
->per_cu
= per_cu
;
2673 if (dwarf2_queue
== NULL
)
2674 dwarf2_queue
= item
;
2676 dwarf2_queue_tail
->next
= item
;
2678 dwarf2_queue_tail
= item
;
2680 /* Either PER_CU is the CU we want to process, or we're following a reference
2681 pointing into PER_CU. Either way, we need its DIEs now. */
2682 load_full_comp_unit (item
->per_cu
, objfile
);
2683 item
->per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
2684 dwarf2_per_objfile
->read_in_chain
= item
->per_cu
;
2687 /* Process the queue. */
2690 process_queue (struct objfile
*objfile
)
2692 struct dwarf2_queue_item
*item
, *next_item
;
2694 /* The queue starts out with one item, but following a DIE reference
2695 may load a new CU, adding it to the end of the queue. */
2696 for (item
= dwarf2_queue
; item
!= NULL
; dwarf2_queue
= item
= next_item
)
2698 if (item
->per_cu
->psymtab
&& !item
->per_cu
->psymtab
->readin
)
2699 process_full_comp_unit (item
->per_cu
);
2701 item
->per_cu
->queued
= 0;
2702 next_item
= item
->next
;
2706 dwarf2_queue_tail
= NULL
;
2709 /* Free all allocated queue entries. This function only releases anything if
2710 an error was thrown; if the queue was processed then it would have been
2711 freed as we went along. */
2714 dwarf2_release_queue (void *dummy
)
2716 struct dwarf2_queue_item
*item
, *last
;
2718 item
= dwarf2_queue
;
2721 /* Anything still marked queued is likely to be in an
2722 inconsistent state, so discard it. */
2723 if (item
->per_cu
->queued
)
2725 if (item
->per_cu
->cu
!= NULL
)
2726 free_one_cached_comp_unit (item
->per_cu
->cu
);
2727 item
->per_cu
->queued
= 0;
2735 dwarf2_queue
= dwarf2_queue_tail
= NULL
;
2738 /* Read in full symbols for PST, and anything it depends on. */
2741 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2743 struct dwarf2_per_cu_data
*per_cu
;
2744 struct cleanup
*back_to
;
2747 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2748 if (!pst
->dependencies
[i
]->readin
)
2750 /* Inform about additional files that need to be read in. */
2753 /* FIXME: i18n: Need to make this a single string. */
2754 fputs_filtered (" ", gdb_stdout
);
2756 fputs_filtered ("and ", gdb_stdout
);
2758 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2759 wrap_here (""); /* Flush output */
2760 gdb_flush (gdb_stdout
);
2762 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2765 per_cu
= (struct dwarf2_per_cu_data
*) pst
->read_symtab_private
;
2769 /* It's an include file, no symbols to read for it.
2770 Everything is in the parent symtab. */
2775 back_to
= make_cleanup (dwarf2_release_queue
, NULL
);
2777 queue_comp_unit (per_cu
, pst
->objfile
);
2779 process_queue (pst
->objfile
);
2781 /* Age the cache, releasing compilation units that have not
2782 been used recently. */
2783 age_cached_comp_units ();
2785 do_cleanups (back_to
);
2788 /* Load the DIEs associated with PST and PER_CU into memory. */
2790 static struct dwarf2_cu
*
2791 load_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
, struct objfile
*objfile
)
2793 bfd
*abfd
= objfile
->obfd
;
2794 struct dwarf2_cu
*cu
;
2795 unsigned int offset
;
2797 struct cleanup
*back_to
, *free_cu_cleanup
;
2798 struct attribute
*attr
;
2801 /* Set local variables from the partial symbol table info. */
2802 offset
= per_cu
->offset
;
2804 info_ptr
= dwarf2_per_objfile
->info
.buffer
+ offset
;
2806 cu
= xmalloc (sizeof (struct dwarf2_cu
));
2807 memset (cu
, 0, sizeof (struct dwarf2_cu
));
2809 /* If an error occurs while loading, release our storage. */
2810 free_cu_cleanup
= make_cleanup (free_one_comp_unit
, cu
);
2812 cu
->objfile
= objfile
;
2814 /* read in the comp_unit header */
2815 info_ptr
= read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
2817 /* Read the abbrevs for this compilation unit */
2818 dwarf2_read_abbrevs (abfd
, cu
);
2819 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
2821 cu
->header
.offset
= offset
;
2823 cu
->per_cu
= per_cu
;
2825 cu
->type_hash
= per_cu
->type_hash
;
2827 /* We use this obstack for block values in dwarf_alloc_block. */
2828 obstack_init (&cu
->comp_unit_obstack
);
2830 cu
->dies
= read_comp_unit (info_ptr
, abfd
, cu
);
2832 /* We try not to read any attributes in this function, because not
2833 all objfiles needed for references have been loaded yet, and symbol
2834 table processing isn't initialized. But we have to set the CU language,
2835 or we won't be able to build types correctly. */
2836 attr
= dwarf2_attr (cu
->dies
, DW_AT_language
, cu
);
2838 set_cu_language (DW_UNSND (attr
), cu
);
2840 set_cu_language (language_minimal
, cu
);
2842 do_cleanups (back_to
);
2844 /* We've successfully allocated this compilation unit. Let our caller
2845 clean it up when finished with it. */
2846 discard_cleanups (free_cu_cleanup
);
2851 /* Generate full symbol information for PST and CU, whose DIEs have
2852 already been loaded into memory. */
2855 process_full_comp_unit (struct dwarf2_per_cu_data
*per_cu
)
2857 struct partial_symtab
*pst
= per_cu
->psymtab
;
2858 struct dwarf2_cu
*cu
= per_cu
->cu
;
2859 struct objfile
*objfile
= pst
->objfile
;
2860 bfd
*abfd
= objfile
->obfd
;
2861 CORE_ADDR lowpc
, highpc
;
2862 struct symtab
*symtab
;
2863 struct cleanup
*back_to
;
2864 struct attribute
*attr
;
2867 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2870 back_to
= make_cleanup (really_free_pendings
, NULL
);
2872 cu
->list_in_scope
= &file_symbols
;
2874 /* Find the base address of the compilation unit for range lists and
2875 location lists. It will normally be specified by DW_AT_low_pc.
2876 In DWARF-3 draft 4, the base address could be overridden by
2877 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2878 compilation units with discontinuous ranges. */
2881 cu
->base_address
= 0;
2883 attr
= dwarf2_attr (cu
->dies
, DW_AT_entry_pc
, cu
);
2886 cu
->base_address
= DW_ADDR (attr
);
2891 attr
= dwarf2_attr (cu
->dies
, DW_AT_low_pc
, cu
);
2894 cu
->base_address
= DW_ADDR (attr
);
2899 /* Do line number decoding in read_file_scope () */
2900 process_die (cu
->dies
, cu
);
2902 /* Some compilers don't define a DW_AT_high_pc attribute for the
2903 compilation unit. If the DW_AT_high_pc is missing, synthesize
2904 it, by scanning the DIE's below the compilation unit. */
2905 get_scope_pc_bounds (cu
->dies
, &lowpc
, &highpc
, cu
);
2907 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2909 /* Set symtab language to language from DW_AT_language.
2910 If the compilation is from a C file generated by language preprocessors,
2911 do not set the language if it was already deduced by start_subfile. */
2913 && !(cu
->language
== language_c
&& symtab
->language
!= language_c
))
2915 symtab
->language
= cu
->language
;
2917 pst
->symtab
= symtab
;
2920 do_cleanups (back_to
);
2923 /* Process a die and its children. */
2926 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2930 case DW_TAG_padding
:
2932 case DW_TAG_compile_unit
:
2933 read_file_scope (die
, cu
);
2935 case DW_TAG_subprogram
:
2936 case DW_TAG_inlined_subroutine
:
2937 read_func_scope (die
, cu
);
2939 case DW_TAG_lexical_block
:
2940 case DW_TAG_try_block
:
2941 case DW_TAG_catch_block
:
2942 read_lexical_block_scope (die
, cu
);
2944 case DW_TAG_class_type
:
2945 case DW_TAG_interface_type
:
2946 case DW_TAG_structure_type
:
2947 case DW_TAG_union_type
:
2948 process_structure_scope (die
, cu
);
2950 case DW_TAG_enumeration_type
:
2951 process_enumeration_scope (die
, cu
);
2954 /* These dies have a type, but processing them does not create
2955 a symbol or recurse to process the children. Therefore we can
2956 read them on-demand through read_type_die. */
2957 case DW_TAG_subroutine_type
:
2958 case DW_TAG_set_type
:
2959 case DW_TAG_array_type
:
2960 case DW_TAG_pointer_type
:
2961 case DW_TAG_ptr_to_member_type
:
2962 case DW_TAG_reference_type
:
2963 case DW_TAG_string_type
:
2966 case DW_TAG_base_type
:
2967 case DW_TAG_subrange_type
:
2968 case DW_TAG_typedef
:
2969 /* Add a typedef symbol for the type definition, if it has a
2971 new_symbol (die
, read_type_die (die
, cu
), cu
);
2973 case DW_TAG_common_block
:
2974 read_common_block (die
, cu
);
2976 case DW_TAG_common_inclusion
:
2978 case DW_TAG_namespace
:
2979 processing_has_namespace_info
= 1;
2980 read_namespace (die
, cu
);
2983 read_module (die
, cu
);
2985 case DW_TAG_imported_declaration
:
2986 case DW_TAG_imported_module
:
2987 processing_has_namespace_info
= 1;
2988 if (die
->child
!= NULL
&& (die
->tag
== DW_TAG_imported_declaration
2989 || cu
->language
!= language_fortran
))
2990 complaint (&symfile_complaints
, _("Tag '%s' has unexpected children"),
2991 dwarf_tag_name (die
->tag
));
2992 read_import_statement (die
, cu
);
2995 new_symbol (die
, NULL
, cu
);
3000 /* Return the fully qualified name of DIE, based on its DW_AT_name.
3001 If scope qualifiers are appropriate they will be added. The result
3002 will be allocated on the objfile_obstack, or NULL if the DIE does
3006 dwarf2_full_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3008 struct attribute
*attr
;
3009 char *prefix
, *name
;
3010 struct ui_file
*buf
= NULL
;
3012 name
= dwarf2_name (die
, cu
);
3016 /* These are the only languages we know how to qualify names in. */
3017 if (cu
->language
!= language_cplus
3018 && cu
->language
!= language_java
)
3021 /* If no prefix is necessary for this type of DIE, return the
3022 unqualified name. The other three tags listed could be handled
3023 in pdi_needs_namespace, but that requires broader changes. */
3024 if (!pdi_needs_namespace (die
->tag
)
3025 && die
->tag
!= DW_TAG_subprogram
3026 && die
->tag
!= DW_TAG_variable
3027 && die
->tag
!= DW_TAG_member
)
3030 prefix
= determine_prefix (die
, cu
);
3031 if (*prefix
!= '\0')
3032 name
= typename_concat (&cu
->objfile
->objfile_obstack
, prefix
,
3038 /* Read the import statement specified by the given die and record it. */
3041 read_import_statement (struct die_info
*die
, struct dwarf2_cu
*cu
)
3043 struct attribute
*import_attr
;
3044 struct die_info
*imported_die
;
3045 const char *imported_name
;
3047 import_attr
= dwarf2_attr (die
, DW_AT_import
, cu
);
3048 if (import_attr
== NULL
)
3050 complaint (&symfile_complaints
, _("Tag '%s' has no DW_AT_import"),
3051 dwarf_tag_name (die
->tag
));
3055 imported_die
= follow_die_ref (die
, import_attr
, &cu
);
3056 imported_name
= dwarf2_name (imported_die
, cu
);
3057 if (imported_name
== NULL
)
3059 /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524
3061 The import in the following code:
3075 <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration)
3076 <52> DW_AT_decl_file : 1
3077 <53> DW_AT_decl_line : 6
3078 <54> DW_AT_import : <0x75>
3079 <2><58>: Abbrev Number: 4 (DW_TAG_typedef)
3081 <5b> DW_AT_decl_file : 1
3082 <5c> DW_AT_decl_line : 2
3083 <5d> DW_AT_type : <0x6e>
3085 <1><75>: Abbrev Number: 7 (DW_TAG_base_type)
3086 <76> DW_AT_byte_size : 4
3087 <77> DW_AT_encoding : 5 (signed)
3089 imports the wrong die ( 0x75 instead of 0x58 ).
3090 This case will be ignored until the gcc bug is fixed. */
3094 /* FIXME: dwarf2_name (die); for the local name after import. */
3096 using_directives
= cp_add_using (imported_name
, strlen (imported_name
), 0,
3101 initialize_cu_func_list (struct dwarf2_cu
*cu
)
3103 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
3107 free_cu_line_header (void *arg
)
3109 struct dwarf2_cu
*cu
= arg
;
3111 free_line_header (cu
->line_header
);
3112 cu
->line_header
= NULL
;
3116 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3118 struct objfile
*objfile
= cu
->objfile
;
3119 struct comp_unit_head
*cu_header
= &cu
->header
;
3120 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
3121 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
3122 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
3123 struct attribute
*attr
;
3125 char *comp_dir
= NULL
;
3126 struct die_info
*child_die
;
3127 bfd
*abfd
= objfile
->obfd
;
3128 struct line_header
*line_header
= 0;
3131 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3133 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
3135 /* If we didn't find a lowpc, set it to highpc to avoid complaints
3136 from finish_block. */
3137 if (lowpc
== ((CORE_ADDR
) -1))
3142 /* Find the filename. Do not use dwarf2_name here, since the filename
3143 is not a source language identifier. */
3144 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3147 name
= DW_STRING (attr
);
3150 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
3152 comp_dir
= DW_STRING (attr
);
3153 else if (name
!= NULL
&& IS_ABSOLUTE_PATH (name
))
3155 comp_dir
= ldirname (name
);
3156 if (comp_dir
!= NULL
)
3157 make_cleanup (xfree
, comp_dir
);
3159 if (comp_dir
!= NULL
)
3161 /* Irix 6.2 native cc prepends <machine>.: to the compilation
3162 directory, get rid of it. */
3163 char *cp
= strchr (comp_dir
, ':');
3165 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
3172 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
3175 set_cu_language (DW_UNSND (attr
), cu
);
3178 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
3180 cu
->producer
= DW_STRING (attr
);
3182 /* We assume that we're processing GCC output. */
3183 processing_gcc_compilation
= 2;
3185 processing_has_namespace_info
= 0;
3187 start_symtab (name
, comp_dir
, lowpc
);
3188 record_debugformat ("DWARF 2");
3189 record_producer (cu
->producer
);
3191 initialize_cu_func_list (cu
);
3193 /* Decode line number information if present. We do this before
3194 processing child DIEs, so that the line header table is available
3195 for DW_AT_decl_file. */
3196 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
3199 unsigned int line_offset
= DW_UNSND (attr
);
3200 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
3203 cu
->line_header
= line_header
;
3204 make_cleanup (free_cu_line_header
, cu
);
3205 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
3209 /* Process all dies in compilation unit. */
3210 if (die
->child
!= NULL
)
3212 child_die
= die
->child
;
3213 while (child_die
&& child_die
->tag
)
3215 process_die (child_die
, cu
);
3216 child_die
= sibling_die (child_die
);
3220 /* Decode macro information, if present. Dwarf 2 macro information
3221 refers to information in the line number info statement program
3222 header, so we can only read it if we've read the header
3224 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
3225 if (attr
&& line_header
)
3227 unsigned int macro_offset
= DW_UNSND (attr
);
3228 dwarf_decode_macros (line_header
, macro_offset
,
3229 comp_dir
, abfd
, cu
);
3231 do_cleanups (back_to
);
3235 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
3236 struct dwarf2_cu
*cu
)
3238 struct function_range
*thisfn
;
3240 thisfn
= (struct function_range
*)
3241 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
3242 thisfn
->name
= name
;
3243 thisfn
->lowpc
= lowpc
;
3244 thisfn
->highpc
= highpc
;
3245 thisfn
->seen_line
= 0;
3246 thisfn
->next
= NULL
;
3248 if (cu
->last_fn
== NULL
)
3249 cu
->first_fn
= thisfn
;
3251 cu
->last_fn
->next
= thisfn
;
3253 cu
->last_fn
= thisfn
;
3256 /* qsort helper for inherit_abstract_dies. */
3259 unsigned_int_compar (const void *ap
, const void *bp
)
3261 unsigned int a
= *(unsigned int *) ap
;
3262 unsigned int b
= *(unsigned int *) bp
;
3264 return (a
> b
) - (b
> a
);
3267 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
3268 Inherit only the children of the DW_AT_abstract_origin DIE not being already
3269 referenced by DW_AT_abstract_origin from the children of the current DIE. */
3272 inherit_abstract_dies (struct die_info
*die
, struct dwarf2_cu
*cu
)
3274 struct die_info
*child_die
;
3275 unsigned die_children_count
;
3276 /* CU offsets which were referenced by children of the current DIE. */
3278 unsigned *offsets_end
, *offsetp
;
3279 /* Parent of DIE - referenced by DW_AT_abstract_origin. */
3280 struct die_info
*origin_die
;
3281 /* Iterator of the ORIGIN_DIE children. */
3282 struct die_info
*origin_child_die
;
3283 struct cleanup
*cleanups
;
3284 struct attribute
*attr
;
3286 attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, cu
);
3290 origin_die
= follow_die_ref (die
, attr
, &cu
);
3291 if (die
->tag
!= origin_die
->tag
3292 && !(die
->tag
== DW_TAG_inlined_subroutine
3293 && origin_die
->tag
== DW_TAG_subprogram
))
3294 complaint (&symfile_complaints
,
3295 _("DIE 0x%x and its abstract origin 0x%x have different tags"),
3296 die
->offset
, origin_die
->offset
);
3298 child_die
= die
->child
;
3299 die_children_count
= 0;
3300 while (child_die
&& child_die
->tag
)
3302 child_die
= sibling_die (child_die
);
3303 die_children_count
++;
3305 offsets
= xmalloc (sizeof (*offsets
) * die_children_count
);
3306 cleanups
= make_cleanup (xfree
, offsets
);
3308 offsets_end
= offsets
;
3309 child_die
= die
->child
;
3310 while (child_die
&& child_die
->tag
)
3312 attr
= dwarf2_attr (child_die
, DW_AT_abstract_origin
, cu
);
3313 /* According to DWARF3 3.3.8.2 #3 new entries without their abstract
3314 counterpart may exist. */
3317 struct die_info
*child_origin_die
;
3319 child_origin_die
= follow_die_ref (child_die
, attr
, &cu
);
3320 if (child_die
->tag
!= child_origin_die
->tag
3321 && !(child_die
->tag
== DW_TAG_inlined_subroutine
3322 && child_origin_die
->tag
== DW_TAG_subprogram
))
3323 complaint (&symfile_complaints
,
3324 _("Child DIE 0x%x and its abstract origin 0x%x have "
3325 "different tags"), child_die
->offset
,
3326 child_origin_die
->offset
);
3327 *offsets_end
++ = child_origin_die
->offset
;
3329 child_die
= sibling_die (child_die
);
3331 qsort (offsets
, offsets_end
- offsets
, sizeof (*offsets
),
3332 unsigned_int_compar
);
3333 for (offsetp
= offsets
+ 1; offsetp
< offsets_end
; offsetp
++)
3334 if (offsetp
[-1] == *offsetp
)
3335 complaint (&symfile_complaints
, _("Multiple children of DIE 0x%x refer "
3336 "to DIE 0x%x as their abstract origin"),
3337 die
->offset
, *offsetp
);
3340 origin_child_die
= origin_die
->child
;
3341 while (origin_child_die
&& origin_child_die
->tag
)
3343 /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */
3344 while (offsetp
< offsets_end
&& *offsetp
< origin_child_die
->offset
)
3346 if (offsetp
>= offsets_end
|| *offsetp
> origin_child_die
->offset
)
3348 /* Found that ORIGIN_CHILD_DIE is really not referenced. */
3349 process_die (origin_child_die
, cu
);
3351 origin_child_die
= sibling_die (origin_child_die
);
3354 do_cleanups (cleanups
);
3358 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3360 struct objfile
*objfile
= cu
->objfile
;
3361 struct context_stack
*new;
3364 struct die_info
*child_die
;
3365 struct attribute
*attr
, *call_line
, *call_file
;
3368 struct block
*block
;
3369 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
3373 /* If we do not have call site information, we can't show the
3374 caller of this inlined function. That's too confusing, so
3375 only use the scope for local variables. */
3376 call_line
= dwarf2_attr (die
, DW_AT_call_line
, cu
);
3377 call_file
= dwarf2_attr (die
, DW_AT_call_file
, cu
);
3378 if (call_line
== NULL
|| call_file
== NULL
)
3380 read_lexical_block_scope (die
, cu
);
3385 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3387 name
= dwarf2_linkage_name (die
, cu
);
3389 /* Ignore functions with missing or empty names and functions with
3390 missing or invalid low and high pc attributes. */
3391 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3397 /* Record the function range for dwarf_decode_lines. */
3398 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
3400 new = push_context (0, lowpc
);
3401 new->name
= new_symbol (die
, read_type_die (die
, cu
), cu
);
3403 /* If there is a location expression for DW_AT_frame_base, record
3405 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
3407 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
3408 expression is being recorded directly in the function's symbol
3409 and not in a separate frame-base object. I guess this hack is
3410 to avoid adding some sort of frame-base adjunct/annex to the
3411 function's symbol :-(. The problem with doing this is that it
3412 results in a function symbol with a location expression that
3413 has nothing to do with the location of the function, ouch! The
3414 relationship should be: a function's symbol has-a frame base; a
3415 frame-base has-a location expression. */
3416 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
3418 cu
->list_in_scope
= &local_symbols
;
3420 if (die
->child
!= NULL
)
3422 child_die
= die
->child
;
3423 while (child_die
&& child_die
->tag
)
3425 process_die (child_die
, cu
);
3426 child_die
= sibling_die (child_die
);
3430 inherit_abstract_dies (die
, cu
);
3432 new = pop_context ();
3433 /* Make a block for the local symbols within. */
3434 block
= finish_block (new->name
, &local_symbols
, new->old_blocks
,
3435 lowpc
, highpc
, objfile
);
3437 /* For C++, set the block's scope. */
3438 if (cu
->language
== language_cplus
)
3439 cp_set_block_scope (new->name
, block
, &objfile
->objfile_obstack
,
3440 determine_prefix (die
, cu
),
3441 processing_has_namespace_info
);
3443 /* If we have address ranges, record them. */
3444 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3446 /* In C++, we can have functions nested inside functions (e.g., when
3447 a function declares a class that has methods). This means that
3448 when we finish processing a function scope, we may need to go
3449 back to building a containing block's symbol lists. */
3450 local_symbols
= new->locals
;
3451 param_symbols
= new->params
;
3452 using_directives
= new->using_directives
;
3454 /* If we've finished processing a top-level function, subsequent
3455 symbols go in the file symbol list. */
3456 if (outermost_context_p ())
3457 cu
->list_in_scope
= &file_symbols
;
3460 /* Process all the DIES contained within a lexical block scope. Start
3461 a new scope, process the dies, and then close the scope. */
3464 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3466 struct objfile
*objfile
= cu
->objfile
;
3467 struct context_stack
*new;
3468 CORE_ADDR lowpc
, highpc
;
3469 struct die_info
*child_die
;
3472 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3474 /* Ignore blocks with missing or invalid low and high pc attributes. */
3475 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
3476 as multiple lexical blocks? Handling children in a sane way would
3477 be nasty. Might be easier to properly extend generic blocks to
3479 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
3484 push_context (0, lowpc
);
3485 if (die
->child
!= NULL
)
3487 child_die
= die
->child
;
3488 while (child_die
&& child_die
->tag
)
3490 process_die (child_die
, cu
);
3491 child_die
= sibling_die (child_die
);
3494 new = pop_context ();
3496 if (local_symbols
!= NULL
)
3499 = finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
3502 /* Note that recording ranges after traversing children, as we
3503 do here, means that recording a parent's ranges entails
3504 walking across all its children's ranges as they appear in
3505 the address map, which is quadratic behavior.
3507 It would be nicer to record the parent's ranges before
3508 traversing its children, simply overriding whatever you find
3509 there. But since we don't even decide whether to create a
3510 block until after we've traversed its children, that's hard
3512 dwarf2_record_block_ranges (die
, block
, baseaddr
, cu
);
3514 local_symbols
= new->locals
;
3515 using_directives
= new->using_directives
;
3518 /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
3519 Return 1 if the attributes are present and valid, otherwise, return 0.
3520 If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
3523 dwarf2_ranges_read (unsigned offset
, CORE_ADDR
*low_return
,
3524 CORE_ADDR
*high_return
, struct dwarf2_cu
*cu
,
3525 struct partial_symtab
*ranges_pst
)
3527 struct objfile
*objfile
= cu
->objfile
;
3528 struct comp_unit_head
*cu_header
= &cu
->header
;
3529 bfd
*obfd
= objfile
->obfd
;
3530 unsigned int addr_size
= cu_header
->addr_size
;
3531 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3532 /* Base address selection entry. */
3543 found_base
= cu
->base_known
;
3544 base
= cu
->base_address
;
3546 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
3548 complaint (&symfile_complaints
,
3549 _("Offset %d out of bounds for DW_AT_ranges attribute"),
3553 buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
3555 /* Read in the largest possible address. */
3556 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
3557 if ((marker
& mask
) == mask
)
3559 /* If we found the largest possible address, then
3560 read the base address. */
3561 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3562 buffer
+= 2 * addr_size
;
3563 offset
+= 2 * addr_size
;
3569 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3573 CORE_ADDR range_beginning
, range_end
;
3575 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
3576 buffer
+= addr_size
;
3577 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
3578 buffer
+= addr_size
;
3579 offset
+= 2 * addr_size
;
3581 /* An end of list marker is a pair of zero addresses. */
3582 if (range_beginning
== 0 && range_end
== 0)
3583 /* Found the end of list entry. */
3586 /* Each base address selection entry is a pair of 2 values.
3587 The first is the largest possible address, the second is
3588 the base address. Check for a base address here. */
3589 if ((range_beginning
& mask
) == mask
)
3591 /* If we found the largest possible address, then
3592 read the base address. */
3593 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
3600 /* We have no valid base address for the ranges
3602 complaint (&symfile_complaints
,
3603 _("Invalid .debug_ranges data (no base address)"));
3607 range_beginning
+= base
;
3610 if (ranges_pst
!= NULL
&& range_beginning
< range_end
)
3611 addrmap_set_empty (objfile
->psymtabs_addrmap
,
3612 range_beginning
+ baseaddr
, range_end
- 1 + baseaddr
,
3615 /* FIXME: This is recording everything as a low-high
3616 segment of consecutive addresses. We should have a
3617 data structure for discontiguous block ranges
3621 low
= range_beginning
;
3627 if (range_beginning
< low
)
3628 low
= range_beginning
;
3629 if (range_end
> high
)
3635 /* If the first entry is an end-of-list marker, the range
3636 describes an empty scope, i.e. no instructions. */
3642 *high_return
= high
;
3646 /* Get low and high pc attributes from a die. Return 1 if the attributes
3647 are present and valid, otherwise, return 0. Return -1 if the range is
3648 discontinuous, i.e. derived from DW_AT_ranges information. */
3650 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
3651 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
3653 struct attribute
*attr
;
3658 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3661 high
= DW_ADDR (attr
);
3662 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3664 low
= DW_ADDR (attr
);
3666 /* Found high w/o low attribute. */
3669 /* Found consecutive range of addresses. */
3674 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3677 /* Value of the DW_AT_ranges attribute is the offset in the
3678 .debug_ranges section. */
3679 if (!dwarf2_ranges_read (DW_UNSND (attr
), &low
, &high
, cu
, NULL
))
3681 /* Found discontinuous range of addresses. */
3689 /* When using the GNU linker, .gnu.linkonce. sections are used to
3690 eliminate duplicate copies of functions and vtables and such.
3691 The linker will arbitrarily choose one and discard the others.
3692 The AT_*_pc values for such functions refer to local labels in
3693 these sections. If the section from that file was discarded, the
3694 labels are not in the output, so the relocs get a value of 0.
3695 If this is a discarded function, mark the pc bounds as invalid,
3696 so that GDB will ignore it. */
3697 if (low
== 0 && !dwarf2_per_objfile
->has_section_at_zero
)
3705 /* Assuming that DIE represents a subprogram DIE or a lexical block, get
3706 its low and high PC addresses. Do nothing if these addresses could not
3707 be determined. Otherwise, set LOWPC to the low address if it is smaller,
3708 and HIGHPC to the high address if greater than HIGHPC. */
3711 dwarf2_get_subprogram_pc_bounds (struct die_info
*die
,
3712 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3713 struct dwarf2_cu
*cu
)
3715 CORE_ADDR low
, high
;
3716 struct die_info
*child
= die
->child
;
3718 if (dwarf2_get_pc_bounds (die
, &low
, &high
, cu
))
3720 *lowpc
= min (*lowpc
, low
);
3721 *highpc
= max (*highpc
, high
);
3724 /* If the language does not allow nested subprograms (either inside
3725 subprograms or lexical blocks), we're done. */
3726 if (cu
->language
!= language_ada
)
3729 /* Check all the children of the given DIE. If it contains nested
3730 subprograms, then check their pc bounds. Likewise, we need to
3731 check lexical blocks as well, as they may also contain subprogram
3733 while (child
&& child
->tag
)
3735 if (child
->tag
== DW_TAG_subprogram
3736 || child
->tag
== DW_TAG_lexical_block
)
3737 dwarf2_get_subprogram_pc_bounds (child
, lowpc
, highpc
, cu
);
3738 child
= sibling_die (child
);
3742 /* Get the low and high pc's represented by the scope DIE, and store
3743 them in *LOWPC and *HIGHPC. If the correct values can't be
3744 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3747 get_scope_pc_bounds (struct die_info
*die
,
3748 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3749 struct dwarf2_cu
*cu
)
3751 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3752 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3753 CORE_ADDR current_low
, current_high
;
3755 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3757 best_low
= current_low
;
3758 best_high
= current_high
;
3762 struct die_info
*child
= die
->child
;
3764 while (child
&& child
->tag
)
3766 switch (child
->tag
) {
3767 case DW_TAG_subprogram
:
3768 dwarf2_get_subprogram_pc_bounds (child
, &best_low
, &best_high
, cu
);
3770 case DW_TAG_namespace
:
3771 /* FIXME: carlton/2004-01-16: Should we do this for
3772 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3773 that current GCC's always emit the DIEs corresponding
3774 to definitions of methods of classes as children of a
3775 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3776 the DIEs giving the declarations, which could be
3777 anywhere). But I don't see any reason why the
3778 standards says that they have to be there. */
3779 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3781 if (current_low
!= ((CORE_ADDR
) -1))
3783 best_low
= min (best_low
, current_low
);
3784 best_high
= max (best_high
, current_high
);
3792 child
= sibling_die (child
);
3797 *highpc
= best_high
;
3800 /* Record the address ranges for BLOCK, offset by BASEADDR, as given
3803 dwarf2_record_block_ranges (struct die_info
*die
, struct block
*block
,
3804 CORE_ADDR baseaddr
, struct dwarf2_cu
*cu
)
3806 struct attribute
*attr
;
3808 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
3811 CORE_ADDR high
= DW_ADDR (attr
);
3812 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
3815 CORE_ADDR low
= DW_ADDR (attr
);
3816 record_block_range (block
, baseaddr
+ low
, baseaddr
+ high
- 1);
3820 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
3823 bfd
*obfd
= cu
->objfile
->obfd
;
3825 /* The value of the DW_AT_ranges attribute is the offset of the
3826 address range list in the .debug_ranges section. */
3827 unsigned long offset
= DW_UNSND (attr
);
3828 gdb_byte
*buffer
= dwarf2_per_objfile
->ranges
.buffer
+ offset
;
3830 /* For some target architectures, but not others, the
3831 read_address function sign-extends the addresses it returns.
3832 To recognize base address selection entries, we need a
3834 unsigned int addr_size
= cu
->header
.addr_size
;
3835 CORE_ADDR base_select_mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
3837 /* The base address, to which the next pair is relative. Note
3838 that this 'base' is a DWARF concept: most entries in a range
3839 list are relative, to reduce the number of relocs against the
3840 debugging information. This is separate from this function's
3841 'baseaddr' argument, which GDB uses to relocate debugging
3842 information from a shared library based on the address at
3843 which the library was loaded. */
3844 CORE_ADDR base
= cu
->base_address
;
3845 int base_known
= cu
->base_known
;
3847 if (offset
>= dwarf2_per_objfile
->ranges
.size
)
3849 complaint (&symfile_complaints
,
3850 _("Offset %lu out of bounds for DW_AT_ranges attribute"),
3857 unsigned int bytes_read
;
3858 CORE_ADDR start
, end
;
3860 start
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3861 buffer
+= bytes_read
;
3862 end
= read_address (obfd
, buffer
, cu
, &bytes_read
);
3863 buffer
+= bytes_read
;
3865 /* Did we find the end of the range list? */
3866 if (start
== 0 && end
== 0)
3869 /* Did we find a base address selection entry? */
3870 else if ((start
& base_select_mask
) == base_select_mask
)
3876 /* We found an ordinary address range. */
3881 complaint (&symfile_complaints
,
3882 _("Invalid .debug_ranges data (no base address)"));
3886 record_block_range (block
,
3887 baseaddr
+ base
+ start
,
3888 baseaddr
+ base
+ end
- 1);
3894 /* Add an aggregate field to the field list. */
3897 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3898 struct dwarf2_cu
*cu
)
3900 struct objfile
*objfile
= cu
->objfile
;
3901 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3902 struct nextfield
*new_field
;
3903 struct attribute
*attr
;
3905 char *fieldname
= "";
3907 /* Allocate a new field list entry and link it in. */
3908 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3909 make_cleanup (xfree
, new_field
);
3910 memset (new_field
, 0, sizeof (struct nextfield
));
3911 new_field
->next
= fip
->fields
;
3912 fip
->fields
= new_field
;
3915 /* Handle accessibility and virtuality of field.
3916 The default accessibility for members is public, the default
3917 accessibility for inheritance is private. */
3918 if (die
->tag
!= DW_TAG_inheritance
)
3919 new_field
->accessibility
= DW_ACCESS_public
;
3921 new_field
->accessibility
= DW_ACCESS_private
;
3922 new_field
->virtuality
= DW_VIRTUALITY_none
;
3924 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3926 new_field
->accessibility
= DW_UNSND (attr
);
3927 if (new_field
->accessibility
!= DW_ACCESS_public
)
3928 fip
->non_public_fields
= 1;
3929 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3931 new_field
->virtuality
= DW_UNSND (attr
);
3933 fp
= &new_field
->field
;
3935 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3937 /* Data member other than a C++ static data member. */
3939 /* Get type of field. */
3940 fp
->type
= die_type (die
, cu
);
3942 SET_FIELD_BITPOS (*fp
, 0);
3944 /* Get bit size of field (zero if none). */
3945 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3948 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3952 FIELD_BITSIZE (*fp
) = 0;
3955 /* Get bit offset of field. */
3956 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3961 if (attr_form_is_section_offset (attr
))
3963 dwarf2_complex_location_expr_complaint ();
3966 else if (attr_form_is_constant (attr
))
3967 byte_offset
= dwarf2_get_attr_constant_value (attr
, 0);
3969 byte_offset
= decode_locdesc (DW_BLOCK (attr
), cu
);
3971 SET_FIELD_BITPOS (*fp
, byte_offset
* bits_per_byte
);
3973 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3976 if (gdbarch_bits_big_endian (gdbarch
))
3978 /* For big endian bits, the DW_AT_bit_offset gives the
3979 additional bit offset from the MSB of the containing
3980 anonymous object to the MSB of the field. We don't
3981 have to do anything special since we don't need to
3982 know the size of the anonymous object. */
3983 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3987 /* For little endian bits, compute the bit offset to the
3988 MSB of the anonymous object, subtract off the number of
3989 bits from the MSB of the field to the MSB of the
3990 object, and then subtract off the number of bits of
3991 the field itself. The result is the bit offset of
3992 the LSB of the field. */
3994 int bit_offset
= DW_UNSND (attr
);
3996 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3999 /* The size of the anonymous object containing
4000 the bit field is explicit, so use the
4001 indicated size (in bytes). */
4002 anonymous_size
= DW_UNSND (attr
);
4006 /* The size of the anonymous object containing
4007 the bit field must be inferred from the type
4008 attribute of the data member containing the
4010 anonymous_size
= TYPE_LENGTH (fp
->type
);
4012 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
4013 - bit_offset
- FIELD_BITSIZE (*fp
);
4017 /* Get name of field. */
4018 fieldname
= dwarf2_name (die
, cu
);
4019 if (fieldname
== NULL
)
4022 /* The name is already allocated along with this objfile, so we don't
4023 need to duplicate it for the type. */
4024 fp
->name
= fieldname
;
4026 /* Change accessibility for artificial fields (e.g. virtual table
4027 pointer or virtual base class pointer) to private. */
4028 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
4030 new_field
->accessibility
= DW_ACCESS_private
;
4031 fip
->non_public_fields
= 1;
4034 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
4036 /* C++ static member. */
4038 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
4039 is a declaration, but all versions of G++ as of this writing
4040 (so through at least 3.2.1) incorrectly generate
4041 DW_TAG_variable tags. */
4045 /* Get name of field. */
4046 fieldname
= dwarf2_name (die
, cu
);
4047 if (fieldname
== NULL
)
4050 /* Get physical name. */
4051 physname
= dwarf2_linkage_name (die
, cu
);
4053 /* The name is already allocated along with this objfile, so we don't
4054 need to duplicate it for the type. */
4055 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
4056 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4057 FIELD_NAME (*fp
) = fieldname
;
4059 else if (die
->tag
== DW_TAG_inheritance
)
4061 /* C++ base class field. */
4062 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
4064 SET_FIELD_BITPOS (*fp
, decode_locdesc (DW_BLOCK (attr
), cu
)
4066 FIELD_BITSIZE (*fp
) = 0;
4067 FIELD_TYPE (*fp
) = die_type (die
, cu
);
4068 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
4069 fip
->nbaseclasses
++;
4073 /* Create the vector of fields, and attach it to the type. */
4076 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
4077 struct dwarf2_cu
*cu
)
4079 int nfields
= fip
->nfields
;
4081 /* Record the field count, allocate space for the array of fields,
4082 and create blank accessibility bitfields if necessary. */
4083 TYPE_NFIELDS (type
) = nfields
;
4084 TYPE_FIELDS (type
) = (struct field
*)
4085 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4086 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4088 if (fip
->non_public_fields
)
4090 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4092 TYPE_FIELD_PRIVATE_BITS (type
) =
4093 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4094 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4096 TYPE_FIELD_PROTECTED_BITS (type
) =
4097 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4098 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4100 TYPE_FIELD_IGNORE_BITS (type
) =
4101 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4102 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4105 /* If the type has baseclasses, allocate and clear a bit vector for
4106 TYPE_FIELD_VIRTUAL_BITS. */
4107 if (fip
->nbaseclasses
)
4109 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
4110 unsigned char *pointer
;
4112 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4113 pointer
= TYPE_ALLOC (type
, num_bytes
);
4114 TYPE_FIELD_VIRTUAL_BITS (type
) = pointer
;
4115 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
4116 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
4119 /* Copy the saved-up fields into the field vector. Start from the head
4120 of the list, adding to the tail of the field array, so that they end
4121 up in the same order in the array in which they were added to the list. */
4122 while (nfields
-- > 0)
4124 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
4125 switch (fip
->fields
->accessibility
)
4127 case DW_ACCESS_private
:
4128 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4131 case DW_ACCESS_protected
:
4132 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4135 case DW_ACCESS_public
:
4139 /* Unknown accessibility. Complain and treat it as public. */
4141 complaint (&symfile_complaints
, _("unsupported accessibility %d"),
4142 fip
->fields
->accessibility
);
4146 if (nfields
< fip
->nbaseclasses
)
4148 switch (fip
->fields
->virtuality
)
4150 case DW_VIRTUALITY_virtual
:
4151 case DW_VIRTUALITY_pure_virtual
:
4152 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
4156 fip
->fields
= fip
->fields
->next
;
4160 /* Add a member function to the proper fieldlist. */
4163 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
4164 struct type
*type
, struct dwarf2_cu
*cu
)
4166 struct objfile
*objfile
= cu
->objfile
;
4167 struct attribute
*attr
;
4168 struct fnfieldlist
*flp
;
4170 struct fn_field
*fnp
;
4173 struct nextfnfield
*new_fnfield
;
4174 struct type
*this_type
;
4176 /* Get name of member function. */
4177 fieldname
= dwarf2_name (die
, cu
);
4178 if (fieldname
== NULL
)
4181 /* Get the mangled name. */
4182 physname
= dwarf2_linkage_name (die
, cu
);
4184 /* Look up member function name in fieldlist. */
4185 for (i
= 0; i
< fip
->nfnfields
; i
++)
4187 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
4191 /* Create new list element if necessary. */
4192 if (i
< fip
->nfnfields
)
4193 flp
= &fip
->fnfieldlists
[i
];
4196 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4198 fip
->fnfieldlists
= (struct fnfieldlist
*)
4199 xrealloc (fip
->fnfieldlists
,
4200 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
4201 * sizeof (struct fnfieldlist
));
4202 if (fip
->nfnfields
== 0)
4203 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
4205 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
4206 flp
->name
= fieldname
;
4212 /* Create a new member function field and chain it to the field list
4214 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
4215 make_cleanup (xfree
, new_fnfield
);
4216 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
4217 new_fnfield
->next
= flp
->head
;
4218 flp
->head
= new_fnfield
;
4221 /* Fill in the member function field info. */
4222 fnp
= &new_fnfield
->fnfield
;
4223 /* The name is already allocated along with this objfile, so we don't
4224 need to duplicate it for the type. */
4225 fnp
->physname
= physname
? physname
: "";
4226 fnp
->type
= alloc_type (objfile
);
4227 this_type
= read_type_die (die
, cu
);
4228 if (this_type
&& TYPE_CODE (this_type
) == TYPE_CODE_FUNC
)
4230 int nparams
= TYPE_NFIELDS (this_type
);
4232 /* TYPE is the domain of this method, and THIS_TYPE is the type
4233 of the method itself (TYPE_CODE_METHOD). */
4234 smash_to_method_type (fnp
->type
, type
,
4235 TYPE_TARGET_TYPE (this_type
),
4236 TYPE_FIELDS (this_type
),
4237 TYPE_NFIELDS (this_type
),
4238 TYPE_VARARGS (this_type
));
4240 /* Handle static member functions.
4241 Dwarf2 has no clean way to discern C++ static and non-static
4242 member functions. G++ helps GDB by marking the first
4243 parameter for non-static member functions (which is the
4244 this pointer) as artificial. We obtain this information
4245 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
4246 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (this_type
, 0) == 0)
4247 fnp
->voffset
= VOFFSET_STATIC
;
4250 complaint (&symfile_complaints
, _("member function type missing for '%s'"),
4253 /* Get fcontext from DW_AT_containing_type if present. */
4254 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4255 fnp
->fcontext
= die_containing_type (die
, cu
);
4257 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
4258 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
4260 /* Get accessibility. */
4261 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
4264 switch (DW_UNSND (attr
))
4266 case DW_ACCESS_private
:
4267 fnp
->is_private
= 1;
4269 case DW_ACCESS_protected
:
4270 fnp
->is_protected
= 1;
4275 /* Check for artificial methods. */
4276 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
4277 if (attr
&& DW_UNSND (attr
) != 0)
4278 fnp
->is_artificial
= 1;
4280 /* Get index in virtual function table if it is a virtual member function. */
4281 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
4284 /* Support the .debug_loc offsets */
4285 if (attr_form_is_block (attr
))
4287 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
4289 else if (attr_form_is_section_offset (attr
))
4291 dwarf2_complex_location_expr_complaint ();
4295 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
4301 /* Create the vector of member function fields, and attach it to the type. */
4304 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
4305 struct dwarf2_cu
*cu
)
4307 struct fnfieldlist
*flp
;
4308 int total_length
= 0;
4311 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4312 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
4313 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
4315 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
4317 struct nextfnfield
*nfp
= flp
->head
;
4318 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
4321 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
4322 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
4323 fn_flp
->fn_fields
= (struct fn_field
*)
4324 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
4325 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
4326 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
4328 total_length
+= flp
->length
;
4331 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
4332 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4335 /* Returns non-zero if NAME is the name of a vtable member in CU's
4336 language, zero otherwise. */
4338 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
4340 static const char vptr
[] = "_vptr";
4341 static const char vtable
[] = "vtable";
4343 /* Look for the C++ and Java forms of the vtable. */
4344 if ((cu
->language
== language_java
4345 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
4346 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
4347 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
4353 /* GCC outputs unnamed structures that are really pointers to member
4354 functions, with the ABI-specified layout. If DIE (from CU) describes
4355 such a structure, set its type, and return nonzero. Otherwise return
4358 GCC shouldn't do this; it should just output pointer to member DIEs.
4359 This is GCC PR debug/28767. */
4361 static struct type
*
4362 quirk_gcc_member_function_pointer (struct die_info
*die
, struct dwarf2_cu
*cu
)
4364 struct objfile
*objfile
= cu
->objfile
;
4366 struct die_info
*pfn_die
, *delta_die
;
4367 struct attribute
*pfn_name
, *delta_name
;
4368 struct type
*pfn_type
, *domain_type
;
4370 /* Check for a structure with no name and two children. */
4371 if (die
->tag
!= DW_TAG_structure_type
4372 || dwarf2_attr (die
, DW_AT_name
, cu
) != NULL
4373 || die
->child
== NULL
4374 || die
->child
->sibling
== NULL
4375 || (die
->child
->sibling
->sibling
!= NULL
4376 && die
->child
->sibling
->sibling
->tag
!= DW_TAG_padding
))
4379 /* Check for __pfn and __delta members. */
4380 pfn_die
= die
->child
;
4381 pfn_name
= dwarf2_attr (pfn_die
, DW_AT_name
, cu
);
4382 if (pfn_die
->tag
!= DW_TAG_member
4384 || DW_STRING (pfn_name
) == NULL
4385 || strcmp ("__pfn", DW_STRING (pfn_name
)) != 0)
4388 delta_die
= pfn_die
->sibling
;
4389 delta_name
= dwarf2_attr (delta_die
, DW_AT_name
, cu
);
4390 if (delta_die
->tag
!= DW_TAG_member
4391 || delta_name
== NULL
4392 || DW_STRING (delta_name
) == NULL
4393 || strcmp ("__delta", DW_STRING (delta_name
)) != 0)
4396 /* Find the type of the method. */
4397 pfn_type
= die_type (pfn_die
, cu
);
4398 if (pfn_type
== NULL
4399 || TYPE_CODE (pfn_type
) != TYPE_CODE_PTR
4400 || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type
)) != TYPE_CODE_FUNC
)
4403 /* Look for the "this" argument. */
4404 pfn_type
= TYPE_TARGET_TYPE (pfn_type
);
4405 if (TYPE_NFIELDS (pfn_type
) == 0
4406 || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type
, 0)) != TYPE_CODE_PTR
)
4409 domain_type
= TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type
, 0));
4410 type
= alloc_type (objfile
);
4411 smash_to_method_type (type
, domain_type
, TYPE_TARGET_TYPE (pfn_type
),
4412 TYPE_FIELDS (pfn_type
), TYPE_NFIELDS (pfn_type
),
4413 TYPE_VARARGS (pfn_type
));
4414 type
= lookup_methodptr_type (type
);
4415 return set_die_type (die
, type
, cu
);
4418 /* Called when we find the DIE that starts a structure or union scope
4419 (definition) to process all dies that define the members of the
4422 NOTE: we need to call struct_type regardless of whether or not the
4423 DIE has an at_name attribute, since it might be an anonymous
4424 structure or union. This gets the type entered into our set of
4427 However, if the structure is incomplete (an opaque struct/union)
4428 then suppress creating a symbol table entry for it since gdb only
4429 wants to find the one with the complete definition. Note that if
4430 it is complete, we just call new_symbol, which does it's own
4431 checking about whether the struct/union is anonymous or not (and
4432 suppresses creating a symbol table entry itself). */
4434 static struct type
*
4435 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4437 struct objfile
*objfile
= cu
->objfile
;
4439 struct attribute
*attr
;
4441 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4443 type
= quirk_gcc_member_function_pointer (die
, cu
);
4447 type
= alloc_type (objfile
);
4448 INIT_CPLUS_SPECIFIC (type
);
4449 name
= dwarf2_name (die
, cu
);
4452 if (cu
->language
== language_cplus
4453 || cu
->language
== language_java
)
4455 const char *new_prefix
= determine_class_name (die
, cu
);
4456 TYPE_TAG_NAME (type
) = (char *) new_prefix
;
4460 /* The name is already allocated along with this objfile, so
4461 we don't need to duplicate it for the type. */
4462 TYPE_TAG_NAME (type
) = name
;
4466 if (die
->tag
== DW_TAG_structure_type
)
4468 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4470 else if (die
->tag
== DW_TAG_union_type
)
4472 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4476 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
4478 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
4481 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4484 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4488 TYPE_LENGTH (type
) = 0;
4491 TYPE_STUB_SUPPORTED (type
) = 1;
4492 if (die_is_declaration (die
, cu
))
4493 TYPE_STUB (type
) = 1;
4495 /* We need to add the type field to the die immediately so we don't
4496 infinitely recurse when dealing with pointers to the structure
4497 type within the structure itself. */
4498 set_die_type (die
, type
, cu
);
4500 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
4502 struct field_info fi
;
4503 struct die_info
*child_die
;
4505 memset (&fi
, 0, sizeof (struct field_info
));
4507 child_die
= die
->child
;
4509 while (child_die
&& child_die
->tag
)
4511 if (child_die
->tag
== DW_TAG_member
4512 || child_die
->tag
== DW_TAG_variable
)
4514 /* NOTE: carlton/2002-11-05: A C++ static data member
4515 should be a DW_TAG_member that is a declaration, but
4516 all versions of G++ as of this writing (so through at
4517 least 3.2.1) incorrectly generate DW_TAG_variable
4518 tags for them instead. */
4519 dwarf2_add_field (&fi
, child_die
, cu
);
4521 else if (child_die
->tag
== DW_TAG_subprogram
)
4523 /* C++ member function. */
4524 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
4526 else if (child_die
->tag
== DW_TAG_inheritance
)
4528 /* C++ base class field. */
4529 dwarf2_add_field (&fi
, child_die
, cu
);
4531 child_die
= sibling_die (child_die
);
4534 /* Attach fields and member functions to the type. */
4536 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
4539 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
4541 /* Get the type which refers to the base class (possibly this
4542 class itself) which contains the vtable pointer for the current
4543 class from the DW_AT_containing_type attribute. */
4545 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
4547 struct type
*t
= die_containing_type (die
, cu
);
4549 TYPE_VPTR_BASETYPE (type
) = t
;
4554 /* Our own class provides vtbl ptr. */
4555 for (i
= TYPE_NFIELDS (t
) - 1;
4556 i
>= TYPE_N_BASECLASSES (t
);
4559 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
4561 if (is_vtable_name (fieldname
, cu
))
4563 TYPE_VPTR_FIELDNO (type
) = i
;
4568 /* Complain if virtual function table field not found. */
4569 if (i
< TYPE_N_BASECLASSES (t
))
4570 complaint (&symfile_complaints
,
4571 _("virtual function table pointer not found when defining class '%s'"),
4572 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
4577 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4580 else if (cu
->producer
4581 && strncmp (cu
->producer
,
4582 "IBM(R) XL C/C++ Advanced Edition", 32) == 0)
4584 /* The IBM XLC compiler does not provide direct indication
4585 of the containing type, but the vtable pointer is
4586 always named __vfp. */
4590 for (i
= TYPE_NFIELDS (type
) - 1;
4591 i
>= TYPE_N_BASECLASSES (type
);
4594 if (strcmp (TYPE_FIELD_NAME (type
, i
), "__vfp") == 0)
4596 TYPE_VPTR_FIELDNO (type
) = i
;
4597 TYPE_VPTR_BASETYPE (type
) = type
;
4605 do_cleanups (back_to
);
4610 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4612 struct objfile
*objfile
= cu
->objfile
;
4613 struct die_info
*child_die
= die
->child
;
4614 struct type
*this_type
;
4616 this_type
= get_die_type (die
, cu
);
4617 if (this_type
== NULL
)
4618 this_type
= read_structure_type (die
, cu
);
4620 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
4621 snapshots) has been known to create a die giving a declaration
4622 for a class that has, as a child, a die giving a definition for a
4623 nested class. So we have to process our children even if the
4624 current die is a declaration. Normally, of course, a declaration
4625 won't have any children at all. */
4627 while (child_die
!= NULL
&& child_die
->tag
)
4629 if (child_die
->tag
== DW_TAG_member
4630 || child_die
->tag
== DW_TAG_variable
4631 || child_die
->tag
== DW_TAG_inheritance
)
4636 process_die (child_die
, cu
);
4638 child_die
= sibling_die (child_die
);
4641 /* Do not consider external references. According to the DWARF standard,
4642 these DIEs are identified by the fact that they have no byte_size
4643 attribute, and a declaration attribute. */
4644 if (dwarf2_attr (die
, DW_AT_byte_size
, cu
) != NULL
4645 || !die_is_declaration (die
, cu
))
4646 new_symbol (die
, this_type
, cu
);
4649 /* Given a DW_AT_enumeration_type die, set its type. We do not
4650 complete the type's fields yet, or create any symbols. */
4652 static struct type
*
4653 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4655 struct objfile
*objfile
= cu
->objfile
;
4657 struct attribute
*attr
;
4660 type
= alloc_type (objfile
);
4662 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4663 name
= dwarf2_full_name (die
, cu
);
4665 TYPE_TAG_NAME (type
) = (char *) name
;
4667 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4670 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4674 TYPE_LENGTH (type
) = 0;
4677 /* The enumeration DIE can be incomplete. In Ada, any type can be
4678 declared as private in the package spec, and then defined only
4679 inside the package body. Such types are known as Taft Amendment
4680 Types. When another package uses such a type, an incomplete DIE
4681 may be generated by the compiler. */
4682 if (die_is_declaration (die
, cu
))
4683 TYPE_STUB (type
) = 1;
4685 return set_die_type (die
, type
, cu
);
4688 /* Determine the name of the type represented by DIE, which should be
4689 a named C++ or Java compound type. Return the name in question,
4690 allocated on the objfile obstack. */
4693 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
4695 const char *new_prefix
= NULL
;
4697 /* If we don't have namespace debug info, guess the name by trying
4698 to demangle the names of members, just like we did in
4699 guess_structure_name. */
4700 if (!processing_has_namespace_info
)
4702 struct die_info
*child
;
4704 for (child
= die
->child
;
4705 child
!= NULL
&& child
->tag
!= 0;
4706 child
= sibling_die (child
))
4708 if (child
->tag
== DW_TAG_subprogram
)
4711 = language_class_name_from_physname (cu
->language_defn
,
4715 if (phys_prefix
!= NULL
)
4718 = obsavestring (phys_prefix
, strlen (phys_prefix
),
4719 &cu
->objfile
->objfile_obstack
);
4720 xfree (phys_prefix
);
4727 if (new_prefix
== NULL
)
4728 new_prefix
= dwarf2_full_name (die
, cu
);
4733 /* Given a pointer to a die which begins an enumeration, process all
4734 the dies that define the members of the enumeration, and create the
4735 symbol for the enumeration type.
4737 NOTE: We reverse the order of the element list. */
4740 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
4742 struct objfile
*objfile
= cu
->objfile
;
4743 struct die_info
*child_die
;
4744 struct field
*fields
;
4747 int unsigned_enum
= 1;
4749 struct type
*this_type
;
4753 this_type
= get_die_type (die
, cu
);
4754 if (this_type
== NULL
)
4755 this_type
= read_enumeration_type (die
, cu
);
4756 if (die
->child
!= NULL
)
4758 child_die
= die
->child
;
4759 while (child_die
&& child_die
->tag
)
4761 if (child_die
->tag
!= DW_TAG_enumerator
)
4763 process_die (child_die
, cu
);
4767 name
= dwarf2_name (child_die
, cu
);
4770 sym
= new_symbol (child_die
, this_type
, cu
);
4771 if (SYMBOL_VALUE (sym
) < 0)
4774 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
4776 fields
= (struct field
*)
4778 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
4779 * sizeof (struct field
));
4782 FIELD_NAME (fields
[num_fields
]) = SYMBOL_LINKAGE_NAME (sym
);
4783 FIELD_TYPE (fields
[num_fields
]) = NULL
;
4784 SET_FIELD_BITPOS (fields
[num_fields
], SYMBOL_VALUE (sym
));
4785 FIELD_BITSIZE (fields
[num_fields
]) = 0;
4791 child_die
= sibling_die (child_die
);
4796 TYPE_NFIELDS (this_type
) = num_fields
;
4797 TYPE_FIELDS (this_type
) = (struct field
*)
4798 TYPE_ALLOC (this_type
, sizeof (struct field
) * num_fields
);
4799 memcpy (TYPE_FIELDS (this_type
), fields
,
4800 sizeof (struct field
) * num_fields
);
4804 TYPE_UNSIGNED (this_type
) = 1;
4807 new_symbol (die
, this_type
, cu
);
4810 /* Extract all information from a DW_TAG_array_type DIE and put it in
4811 the DIE's type field. For now, this only handles one dimensional
4814 static struct type
*
4815 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4817 struct objfile
*objfile
= cu
->objfile
;
4818 struct die_info
*child_die
;
4819 struct type
*type
= NULL
;
4820 struct type
*element_type
, *range_type
, *index_type
;
4821 struct type
**range_types
= NULL
;
4822 struct attribute
*attr
;
4824 struct cleanup
*back_to
;
4827 element_type
= die_type (die
, cu
);
4829 /* Irix 6.2 native cc creates array types without children for
4830 arrays with unspecified length. */
4831 if (die
->child
== NULL
)
4833 index_type
= objfile_type (objfile
)->builtin_int
;
4834 range_type
= create_range_type (NULL
, index_type
, 0, -1);
4835 type
= create_array_type (NULL
, element_type
, range_type
);
4836 return set_die_type (die
, type
, cu
);
4839 back_to
= make_cleanup (null_cleanup
, NULL
);
4840 child_die
= die
->child
;
4841 while (child_die
&& child_die
->tag
)
4843 if (child_die
->tag
== DW_TAG_subrange_type
)
4845 struct type
*child_type
= read_type_die (child_die
, cu
);
4846 if (child_type
!= NULL
)
4848 /* The range type was succesfully read. Save it for
4849 the array type creation. */
4850 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
4852 range_types
= (struct type
**)
4853 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
4854 * sizeof (struct type
*));
4856 make_cleanup (free_current_contents
, &range_types
);
4858 range_types
[ndim
++] = child_type
;
4861 child_die
= sibling_die (child_die
);
4864 /* Dwarf2 dimensions are output from left to right, create the
4865 necessary array types in backwards order. */
4867 type
= element_type
;
4869 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4873 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4878 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4881 /* Understand Dwarf2 support for vector types (like they occur on
4882 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4883 array type. This is not part of the Dwarf2/3 standard yet, but a
4884 custom vendor extension. The main difference between a regular
4885 array and the vector variant is that vectors are passed by value
4887 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4889 make_vector_type (type
);
4891 name
= dwarf2_name (die
, cu
);
4893 TYPE_NAME (type
) = name
;
4895 do_cleanups (back_to
);
4897 /* Install the type in the die. */
4898 return set_die_type (die
, type
, cu
);
4901 static enum dwarf_array_dim_ordering
4902 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4904 struct attribute
*attr
;
4906 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4908 if (attr
) return DW_SND (attr
);
4911 GNU F77 is a special case, as at 08/2004 array type info is the
4912 opposite order to the dwarf2 specification, but data is still
4913 laid out as per normal fortran.
4915 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4919 if (cu
->language
== language_fortran
&&
4920 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4922 return DW_ORD_row_major
;
4925 switch (cu
->language_defn
->la_array_ordering
)
4927 case array_column_major
:
4928 return DW_ORD_col_major
;
4929 case array_row_major
:
4931 return DW_ORD_row_major
;
4935 /* Extract all information from a DW_TAG_set_type DIE and put it in
4936 the DIE's type field. */
4938 static struct type
*
4939 read_set_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4941 struct type
*set_type
= create_set_type (NULL
, die_type (die
, cu
));
4943 return set_die_type (die
, set_type
, cu
);
4946 /* First cut: install each common block member as a global variable. */
4949 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4951 struct die_info
*child_die
;
4952 struct attribute
*attr
;
4954 CORE_ADDR base
= (CORE_ADDR
) 0;
4956 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4959 /* Support the .debug_loc offsets */
4960 if (attr_form_is_block (attr
))
4962 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4964 else if (attr_form_is_section_offset (attr
))
4966 dwarf2_complex_location_expr_complaint ();
4970 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4971 "common block member");
4974 if (die
->child
!= NULL
)
4976 child_die
= die
->child
;
4977 while (child_die
&& child_die
->tag
)
4979 sym
= new_symbol (child_die
, NULL
, cu
);
4980 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4983 SYMBOL_VALUE_ADDRESS (sym
) =
4984 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4985 add_symbol_to_list (sym
, &global_symbols
);
4987 child_die
= sibling_die (child_die
);
4992 /* Create a type for a C++ namespace. */
4994 static struct type
*
4995 read_namespace_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4997 struct objfile
*objfile
= cu
->objfile
;
4998 const char *previous_prefix
, *name
;
5002 /* For extensions, reuse the type of the original namespace. */
5003 if (dwarf2_attr (die
, DW_AT_extension
, cu
) != NULL
)
5005 struct die_info
*ext_die
;
5006 struct dwarf2_cu
*ext_cu
= cu
;
5007 ext_die
= dwarf2_extension (die
, &ext_cu
);
5008 type
= read_type_die (ext_die
, ext_cu
);
5009 return set_die_type (die
, type
, cu
);
5012 name
= namespace_name (die
, &is_anonymous
, cu
);
5014 /* Now build the name of the current namespace. */
5016 previous_prefix
= determine_prefix (die
, cu
);
5017 if (previous_prefix
[0] != '\0')
5018 name
= typename_concat (&objfile
->objfile_obstack
,
5019 previous_prefix
, name
, cu
);
5021 /* Create the type. */
5022 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0, NULL
,
5024 TYPE_NAME (type
) = (char *) name
;
5025 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
5027 set_die_type (die
, type
, cu
);
5032 /* Read a C++ namespace. */
5035 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
5037 struct objfile
*objfile
= cu
->objfile
;
5041 /* Add a symbol associated to this if we haven't seen the namespace
5042 before. Also, add a using directive if it's an anonymous
5045 if (dwarf2_attr (die
, DW_AT_extension
, cu
) == NULL
)
5049 type
= read_type_die (die
, cu
);
5050 new_symbol (die
, type
, cu
);
5052 name
= namespace_name (die
, &is_anonymous
, cu
);
5055 const char *previous_prefix
= determine_prefix (die
, cu
);
5056 cp_add_using_directive (TYPE_NAME (type
),
5057 strlen (previous_prefix
),
5058 strlen (TYPE_NAME (type
)));
5062 if (die
->child
!= NULL
)
5064 struct die_info
*child_die
= die
->child
;
5066 while (child_die
&& child_die
->tag
)
5068 process_die (child_die
, cu
);
5069 child_die
= sibling_die (child_die
);
5074 /* Read a Fortran module. */
5077 read_module (struct die_info
*die
, struct dwarf2_cu
*cu
)
5079 struct die_info
*child_die
= die
->child
;
5081 /* FIXME: Support the separate Fortran module namespaces. */
5083 while (child_die
&& child_die
->tag
)
5085 process_die (child_die
, cu
);
5086 child_die
= sibling_die (child_die
);
5090 /* Return the name of the namespace represented by DIE. Set
5091 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
5095 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
5097 struct die_info
*current_die
;
5098 const char *name
= NULL
;
5100 /* Loop through the extensions until we find a name. */
5102 for (current_die
= die
;
5103 current_die
!= NULL
;
5104 current_die
= dwarf2_extension (die
, &cu
))
5106 name
= dwarf2_name (current_die
, cu
);
5111 /* Is it an anonymous namespace? */
5113 *is_anonymous
= (name
== NULL
);
5115 name
= "(anonymous namespace)";
5120 /* Extract all information from a DW_TAG_pointer_type DIE and add to
5121 the user defined type vector. */
5123 static struct type
*
5124 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5126 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5127 struct comp_unit_head
*cu_header
= &cu
->header
;
5129 struct attribute
*attr_byte_size
;
5130 struct attribute
*attr_address_class
;
5131 int byte_size
, addr_class
;
5133 type
= lookup_pointer_type (die_type (die
, cu
));
5135 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5137 byte_size
= DW_UNSND (attr_byte_size
);
5139 byte_size
= cu_header
->addr_size
;
5141 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
5142 if (attr_address_class
)
5143 addr_class
= DW_UNSND (attr_address_class
);
5145 addr_class
= DW_ADDR_none
;
5147 /* If the pointer size or address class is different than the
5148 default, create a type variant marked as such and set the
5149 length accordingly. */
5150 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
5152 if (gdbarch_address_class_type_flags_p (gdbarch
))
5156 type_flags
= gdbarch_address_class_type_flags
5157 (gdbarch
, byte_size
, addr_class
);
5158 gdb_assert ((type_flags
& ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL
)
5160 type
= make_type_with_address_space (type
, type_flags
);
5162 else if (TYPE_LENGTH (type
) != byte_size
)
5164 complaint (&symfile_complaints
, _("invalid pointer size %d"), byte_size
);
5167 /* Should we also complain about unhandled address classes? */
5171 TYPE_LENGTH (type
) = byte_size
;
5172 return set_die_type (die
, type
, cu
);
5175 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
5176 the user defined type vector. */
5178 static struct type
*
5179 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5181 struct objfile
*objfile
= cu
->objfile
;
5183 struct type
*to_type
;
5184 struct type
*domain
;
5186 to_type
= die_type (die
, cu
);
5187 domain
= die_containing_type (die
, cu
);
5189 if (TYPE_CODE (check_typedef (to_type
)) == TYPE_CODE_METHOD
)
5190 type
= lookup_methodptr_type (to_type
);
5192 type
= lookup_memberptr_type (to_type
, domain
);
5194 return set_die_type (die
, type
, cu
);
5197 /* Extract all information from a DW_TAG_reference_type DIE and add to
5198 the user defined type vector. */
5200 static struct type
*
5201 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5203 struct comp_unit_head
*cu_header
= &cu
->header
;
5205 struct attribute
*attr
;
5207 type
= lookup_reference_type (die_type (die
, cu
));
5208 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5211 TYPE_LENGTH (type
) = DW_UNSND (attr
);
5215 TYPE_LENGTH (type
) = cu_header
->addr_size
;
5217 return set_die_type (die
, type
, cu
);
5220 static struct type
*
5221 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5223 struct type
*base_type
, *cv_type
;
5225 base_type
= die_type (die
, cu
);
5226 cv_type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
5227 return set_die_type (die
, cv_type
, cu
);
5230 static struct type
*
5231 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5233 struct type
*base_type
, *cv_type
;
5235 base_type
= die_type (die
, cu
);
5236 cv_type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
5237 return set_die_type (die
, cv_type
, cu
);
5240 /* Extract all information from a DW_TAG_string_type DIE and add to
5241 the user defined type vector. It isn't really a user defined type,
5242 but it behaves like one, with other DIE's using an AT_user_def_type
5243 attribute to reference it. */
5245 static struct type
*
5246 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5248 struct objfile
*objfile
= cu
->objfile
;
5249 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
5250 struct type
*type
, *range_type
, *index_type
, *char_type
;
5251 struct attribute
*attr
;
5252 unsigned int length
;
5254 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
5257 length
= DW_UNSND (attr
);
5261 /* check for the DW_AT_byte_size attribute */
5262 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5265 length
= DW_UNSND (attr
);
5273 index_type
= objfile_type (objfile
)->builtin_int
;
5274 range_type
= create_range_type (NULL
, index_type
, 1, length
);
5275 char_type
= language_string_char_type (cu
->language_defn
, gdbarch
);
5276 type
= create_string_type (NULL
, char_type
, range_type
);
5278 return set_die_type (die
, type
, cu
);
5281 /* Handle DIES due to C code like:
5285 int (*funcp)(int a, long l);
5289 ('funcp' generates a DW_TAG_subroutine_type DIE)
5292 static struct type
*
5293 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5295 struct type
*type
; /* Type that this function returns */
5296 struct type
*ftype
; /* Function that returns above type */
5297 struct attribute
*attr
;
5299 type
= die_type (die
, cu
);
5300 ftype
= lookup_function_type (type
);
5302 /* All functions in C++, Pascal and Java have prototypes. */
5303 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
5304 if ((attr
&& (DW_UNSND (attr
) != 0))
5305 || cu
->language
== language_cplus
5306 || cu
->language
== language_java
5307 || cu
->language
== language_pascal
)
5308 TYPE_PROTOTYPED (ftype
) = 1;
5310 /* Store the calling convention in the type if it's available in
5311 the subroutine die. Otherwise set the calling convention to
5312 the default value DW_CC_normal. */
5313 attr
= dwarf2_attr (die
, DW_AT_calling_convention
, cu
);
5314 TYPE_CALLING_CONVENTION (ftype
) = attr
? DW_UNSND (attr
) : DW_CC_normal
;
5316 if (die
->child
!= NULL
)
5318 struct die_info
*child_die
;
5322 /* Count the number of parameters.
5323 FIXME: GDB currently ignores vararg functions, but knows about
5324 vararg member functions. */
5325 child_die
= die
->child
;
5326 while (child_die
&& child_die
->tag
)
5328 if (child_die
->tag
== DW_TAG_formal_parameter
)
5330 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
5331 TYPE_VARARGS (ftype
) = 1;
5332 child_die
= sibling_die (child_die
);
5335 /* Allocate storage for parameters and fill them in. */
5336 TYPE_NFIELDS (ftype
) = nparams
;
5337 TYPE_FIELDS (ftype
) = (struct field
*)
5338 TYPE_ZALLOC (ftype
, nparams
* sizeof (struct field
));
5340 child_die
= die
->child
;
5341 while (child_die
&& child_die
->tag
)
5343 if (child_die
->tag
== DW_TAG_formal_parameter
)
5345 /* Dwarf2 has no clean way to discern C++ static and non-static
5346 member functions. G++ helps GDB by marking the first
5347 parameter for non-static member functions (which is the
5348 this pointer) as artificial. We pass this information
5349 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
5350 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
5352 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
5354 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
5355 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
5358 child_die
= sibling_die (child_die
);
5362 return set_die_type (die
, ftype
, cu
);
5365 static struct type
*
5366 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
5368 struct objfile
*objfile
= cu
->objfile
;
5369 struct attribute
*attr
;
5370 const char *name
= NULL
;
5371 struct type
*this_type
;
5373 name
= dwarf2_full_name (die
, cu
);
5374 this_type
= init_type (TYPE_CODE_TYPEDEF
, 0,
5375 TYPE_FLAG_TARGET_STUB
, NULL
, objfile
);
5376 TYPE_NAME (this_type
) = (char *) name
;
5377 set_die_type (die
, this_type
, cu
);
5378 TYPE_TARGET_TYPE (this_type
) = die_type (die
, cu
);
5382 /* Find a representation of a given base type and install
5383 it in the TYPE field of the die. */
5385 static struct type
*
5386 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5388 struct objfile
*objfile
= cu
->objfile
;
5390 struct attribute
*attr
;
5391 int encoding
= 0, size
= 0;
5393 enum type_code code
= TYPE_CODE_INT
;
5395 struct type
*target_type
= NULL
;
5397 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
5400 encoding
= DW_UNSND (attr
);
5402 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5405 size
= DW_UNSND (attr
);
5407 name
= dwarf2_name (die
, cu
);
5410 complaint (&symfile_complaints
,
5411 _("DW_AT_name missing from DW_TAG_base_type"));
5416 case DW_ATE_address
:
5417 /* Turn DW_ATE_address into a void * pointer. */
5418 code
= TYPE_CODE_PTR
;
5419 type_flags
|= TYPE_FLAG_UNSIGNED
;
5420 target_type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
5422 case DW_ATE_boolean
:
5423 code
= TYPE_CODE_BOOL
;
5424 type_flags
|= TYPE_FLAG_UNSIGNED
;
5426 case DW_ATE_complex_float
:
5427 code
= TYPE_CODE_COMPLEX
;
5428 target_type
= init_type (TYPE_CODE_FLT
, size
/ 2, 0, NULL
, objfile
);
5430 case DW_ATE_decimal_float
:
5431 code
= TYPE_CODE_DECFLOAT
;
5434 code
= TYPE_CODE_FLT
;
5438 case DW_ATE_unsigned
:
5439 type_flags
|= TYPE_FLAG_UNSIGNED
;
5441 case DW_ATE_signed_char
:
5442 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5443 || cu
->language
== language_pascal
)
5444 code
= TYPE_CODE_CHAR
;
5446 case DW_ATE_unsigned_char
:
5447 if (cu
->language
== language_ada
|| cu
->language
== language_m2
5448 || cu
->language
== language_pascal
)
5449 code
= TYPE_CODE_CHAR
;
5450 type_flags
|= TYPE_FLAG_UNSIGNED
;
5453 complaint (&symfile_complaints
, _("unsupported DW_AT_encoding: '%s'"),
5454 dwarf_type_encoding_name (encoding
));
5458 type
= init_type (code
, size
, type_flags
, NULL
, objfile
);
5459 TYPE_NAME (type
) = name
;
5460 TYPE_TARGET_TYPE (type
) = target_type
;
5462 if (name
&& strcmp (name
, "char") == 0)
5463 TYPE_NOSIGN (type
) = 1;
5465 return set_die_type (die
, type
, cu
);
5468 /* Read the given DW_AT_subrange DIE. */
5470 static struct type
*
5471 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5473 struct gdbarch
*gdbarch
= get_objfile_arch (cu
->objfile
);
5474 struct type
*base_type
;
5475 struct type
*range_type
;
5476 struct attribute
*attr
;
5481 base_type
= die_type (die
, cu
);
5482 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
5484 complaint (&symfile_complaints
,
5485 _("DW_AT_type missing from DW_TAG_subrange_type"));
5487 = init_type (TYPE_CODE_INT
, gdbarch_addr_bit (gdbarch
) / 8,
5488 0, NULL
, cu
->objfile
);
5491 if (cu
->language
== language_fortran
)
5493 /* FORTRAN implies a lower bound of 1, if not given. */
5497 /* FIXME: For variable sized arrays either of these could be
5498 a variable rather than a constant value. We'll allow it,
5499 but we don't know how to handle it. */
5500 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
5502 low
= dwarf2_get_attr_constant_value (attr
, 0);
5504 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
5507 if (attr
->form
== DW_FORM_block1
)
5509 /* GCC encodes arrays with unspecified or dynamic length
5510 with a DW_FORM_block1 attribute.
5511 FIXME: GDB does not yet know how to handle dynamic
5512 arrays properly, treat them as arrays with unspecified
5515 FIXME: jimb/2003-09-22: GDB does not really know
5516 how to handle arrays of unspecified length
5517 either; we just represent them as zero-length
5518 arrays. Choose an appropriate upper bound given
5519 the lower bound we've computed above. */
5523 high
= dwarf2_get_attr_constant_value (attr
, 1);
5526 range_type
= create_range_type (NULL
, base_type
, low
, high
);
5528 name
= dwarf2_name (die
, cu
);
5530 TYPE_NAME (range_type
) = name
;
5532 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
5534 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
5536 return set_die_type (die
, range_type
, cu
);
5539 static struct type
*
5540 read_unspecified_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
5544 /* For now, we only support the C meaning of an unspecified type: void. */
5546 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, cu
->objfile
);
5547 TYPE_NAME (type
) = dwarf2_name (die
, cu
);
5549 return set_die_type (die
, type
, cu
);
5552 /* Trivial hash function for die_info: the hash value of a DIE
5553 is its offset in .debug_info for this objfile. */
5556 die_hash (const void *item
)
5558 const struct die_info
*die
= item
;
5562 /* Trivial comparison function for die_info structures: two DIEs
5563 are equal if they have the same offset. */
5566 die_eq (const void *item_lhs
, const void *item_rhs
)
5568 const struct die_info
*die_lhs
= item_lhs
;
5569 const struct die_info
*die_rhs
= item_rhs
;
5570 return die_lhs
->offset
== die_rhs
->offset
;
5573 /* Read a whole compilation unit into a linked list of dies. */
5575 static struct die_info
*
5576 read_comp_unit (gdb_byte
*info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
5579 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5583 &cu
->comp_unit_obstack
,
5584 hashtab_obstack_allocate
,
5585 dummy_obstack_deallocate
);
5587 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
5590 /* Main entry point for reading a DIE and all children.
5591 Read the DIE and dump it if requested. */
5593 static struct die_info
*
5594 read_die_and_children (gdb_byte
*info_ptr
, bfd
*abfd
,
5595 struct dwarf2_cu
*cu
,
5596 gdb_byte
**new_info_ptr
,
5597 struct die_info
*parent
)
5599 struct die_info
*result
= read_die_and_children_1 (info_ptr
, abfd
, cu
,
5600 new_info_ptr
, parent
);
5602 if (dwarf2_die_debug
)
5604 fprintf_unfiltered (gdb_stdlog
, "Read die from .debug_info:\n");
5605 dump_die (result
, dwarf2_die_debug
);
5611 /* Read a single die and all its descendents. Set the die's sibling
5612 field to NULL; set other fields in the die correctly, and set all
5613 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
5614 location of the info_ptr after reading all of those dies. PARENT
5615 is the parent of the die in question. */
5617 static struct die_info
*
5618 read_die_and_children_1 (gdb_byte
*info_ptr
, bfd
*abfd
,
5619 struct dwarf2_cu
*cu
,
5620 gdb_byte
**new_info_ptr
,
5621 struct die_info
*parent
)
5623 struct die_info
*die
;
5627 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
5630 *new_info_ptr
= cur_ptr
;
5633 store_in_ref_table (die
, cu
);
5637 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
5643 *new_info_ptr
= cur_ptr
;
5646 die
->sibling
= NULL
;
5647 die
->parent
= parent
;
5651 /* Read a die, all of its descendents, and all of its siblings; set
5652 all of the fields of all of the dies correctly. Arguments are as
5653 in read_die_and_children. */
5655 static struct die_info
*
5656 read_die_and_siblings (gdb_byte
*info_ptr
, bfd
*abfd
,
5657 struct dwarf2_cu
*cu
,
5658 gdb_byte
**new_info_ptr
,
5659 struct die_info
*parent
)
5661 struct die_info
*first_die
, *last_sibling
;
5665 first_die
= last_sibling
= NULL
;
5669 struct die_info
*die
5670 = read_die_and_children_1 (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
5674 *new_info_ptr
= cur_ptr
;
5681 last_sibling
->sibling
= die
;
5687 /* In DWARF version 2, the description of the debugging information is
5688 stored in a separate .debug_abbrev section. Before we read any
5689 dies from a section we read in all abbreviations and install them
5690 in a hash table. This function also sets flags in CU describing
5691 the data found in the abbrev table. */
5694 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
5696 struct comp_unit_head
*cu_header
= &cu
->header
;
5697 gdb_byte
*abbrev_ptr
;
5698 struct abbrev_info
*cur_abbrev
;
5699 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
5700 unsigned int abbrev_form
, hash_number
;
5701 struct attr_abbrev
*cur_attrs
;
5702 unsigned int allocated_attrs
;
5704 /* Initialize dwarf2 abbrevs */
5705 obstack_init (&cu
->abbrev_obstack
);
5706 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
5708 * sizeof (struct abbrev_info
*)));
5709 memset (cu
->dwarf2_abbrevs
, 0,
5710 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
5712 abbrev_ptr
= dwarf2_per_objfile
->abbrev
.buffer
+ cu_header
->abbrev_offset
;
5713 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5714 abbrev_ptr
+= bytes_read
;
5716 allocated_attrs
= ATTR_ALLOC_CHUNK
;
5717 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
5719 /* loop until we reach an abbrev number of 0 */
5720 while (abbrev_number
)
5722 cur_abbrev
= dwarf_alloc_abbrev (cu
);
5724 /* read in abbrev header */
5725 cur_abbrev
->number
= abbrev_number
;
5726 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5727 abbrev_ptr
+= bytes_read
;
5728 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
5731 if (cur_abbrev
->tag
== DW_TAG_namespace
)
5732 cu
->has_namespace_info
= 1;
5734 /* now read in declarations */
5735 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5736 abbrev_ptr
+= bytes_read
;
5737 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5738 abbrev_ptr
+= bytes_read
;
5741 if (cur_abbrev
->num_attrs
== allocated_attrs
)
5743 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
5745 = xrealloc (cur_attrs
, (allocated_attrs
5746 * sizeof (struct attr_abbrev
)));
5749 /* Record whether this compilation unit might have
5750 inter-compilation-unit references. If we don't know what form
5751 this attribute will have, then it might potentially be a
5752 DW_FORM_ref_addr, so we conservatively expect inter-CU
5755 if (abbrev_form
== DW_FORM_ref_addr
5756 || abbrev_form
== DW_FORM_indirect
)
5757 cu
->has_form_ref_addr
= 1;
5759 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
5760 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
5761 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5762 abbrev_ptr
+= bytes_read
;
5763 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5764 abbrev_ptr
+= bytes_read
;
5767 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
5768 (cur_abbrev
->num_attrs
5769 * sizeof (struct attr_abbrev
)));
5770 memcpy (cur_abbrev
->attrs
, cur_attrs
,
5771 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
5773 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
5774 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
5775 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
5777 /* Get next abbreviation.
5778 Under Irix6 the abbreviations for a compilation unit are not
5779 always properly terminated with an abbrev number of 0.
5780 Exit loop if we encounter an abbreviation which we have
5781 already read (which means we are about to read the abbreviations
5782 for the next compile unit) or if the end of the abbreviation
5783 table is reached. */
5784 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev
.buffer
)
5785 >= dwarf2_per_objfile
->abbrev
.size
)
5787 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
5788 abbrev_ptr
+= bytes_read
;
5789 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
5796 /* Release the memory used by the abbrev table for a compilation unit. */
5799 dwarf2_free_abbrev_table (void *ptr_to_cu
)
5801 struct dwarf2_cu
*cu
= ptr_to_cu
;
5803 obstack_free (&cu
->abbrev_obstack
, NULL
);
5804 cu
->dwarf2_abbrevs
= NULL
;
5807 /* Lookup an abbrev_info structure in the abbrev hash table. */
5809 static struct abbrev_info
*
5810 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
5812 unsigned int hash_number
;
5813 struct abbrev_info
*abbrev
;
5815 hash_number
= number
% ABBREV_HASH_SIZE
;
5816 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
5820 if (abbrev
->number
== number
)
5823 abbrev
= abbrev
->next
;
5828 /* Returns nonzero if TAG represents a type that we might generate a partial
5832 is_type_tag_for_partial (int tag
)
5837 /* Some types that would be reasonable to generate partial symbols for,
5838 that we don't at present. */
5839 case DW_TAG_array_type
:
5840 case DW_TAG_file_type
:
5841 case DW_TAG_ptr_to_member_type
:
5842 case DW_TAG_set_type
:
5843 case DW_TAG_string_type
:
5844 case DW_TAG_subroutine_type
:
5846 case DW_TAG_base_type
:
5847 case DW_TAG_class_type
:
5848 case DW_TAG_interface_type
:
5849 case DW_TAG_enumeration_type
:
5850 case DW_TAG_structure_type
:
5851 case DW_TAG_subrange_type
:
5852 case DW_TAG_typedef
:
5853 case DW_TAG_union_type
:
5860 /* Load all DIEs that are interesting for partial symbols into memory. */
5862 static struct partial_die_info
*
5863 load_partial_dies (bfd
*abfd
, gdb_byte
*info_ptr
, int building_psymtab
,
5864 struct dwarf2_cu
*cu
)
5866 struct partial_die_info
*part_die
;
5867 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
5868 struct abbrev_info
*abbrev
;
5869 unsigned int bytes_read
;
5870 unsigned int load_all
= 0;
5872 int nesting_level
= 1;
5877 if (cu
->per_cu
&& cu
->per_cu
->load_all_dies
)
5881 = htab_create_alloc_ex (cu
->header
.length
/ 12,
5885 &cu
->comp_unit_obstack
,
5886 hashtab_obstack_allocate
,
5887 dummy_obstack_deallocate
);
5889 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5890 sizeof (struct partial_die_info
));
5894 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5896 /* A NULL abbrev means the end of a series of children. */
5899 if (--nesting_level
== 0)
5901 /* PART_DIE was probably the last thing allocated on the
5902 comp_unit_obstack, so we could call obstack_free
5903 here. We don't do that because the waste is small,
5904 and will be cleaned up when we're done with this
5905 compilation unit. This way, we're also more robust
5906 against other users of the comp_unit_obstack. */
5909 info_ptr
+= bytes_read
;
5910 last_die
= parent_die
;
5911 parent_die
= parent_die
->die_parent
;
5915 /* Check whether this DIE is interesting enough to save. Normally
5916 we would not be interested in members here, but there may be
5917 later variables referencing them via DW_AT_specification (for
5920 && !is_type_tag_for_partial (abbrev
->tag
)
5921 && abbrev
->tag
!= DW_TAG_enumerator
5922 && abbrev
->tag
!= DW_TAG_subprogram
5923 && abbrev
->tag
!= DW_TAG_lexical_block
5924 && abbrev
->tag
!= DW_TAG_variable
5925 && abbrev
->tag
!= DW_TAG_namespace
5926 && abbrev
->tag
!= DW_TAG_member
)
5928 /* Otherwise we skip to the next sibling, if any. */
5929 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5933 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5934 abfd
, info_ptr
, cu
);
5936 /* This two-pass algorithm for processing partial symbols has a
5937 high cost in cache pressure. Thus, handle some simple cases
5938 here which cover the majority of C partial symbols. DIEs
5939 which neither have specification tags in them, nor could have
5940 specification tags elsewhere pointing at them, can simply be
5941 processed and discarded.
5943 This segment is also optional; scan_partial_symbols and
5944 add_partial_symbol will handle these DIEs if we chain
5945 them in normally. When compilers which do not emit large
5946 quantities of duplicate debug information are more common,
5947 this code can probably be removed. */
5949 /* Any complete simple types at the top level (pretty much all
5950 of them, for a language without namespaces), can be processed
5952 if (parent_die
== NULL
5953 && part_die
->has_specification
== 0
5954 && part_die
->is_declaration
== 0
5955 && (part_die
->tag
== DW_TAG_typedef
5956 || part_die
->tag
== DW_TAG_base_type
5957 || part_die
->tag
== DW_TAG_subrange_type
))
5959 if (building_psymtab
&& part_die
->name
!= NULL
)
5960 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5961 VAR_DOMAIN
, LOC_TYPEDEF
,
5962 &cu
->objfile
->static_psymbols
,
5963 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5964 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5968 /* If we're at the second level, and we're an enumerator, and
5969 our parent has no specification (meaning possibly lives in a
5970 namespace elsewhere), then we can add the partial symbol now
5971 instead of queueing it. */
5972 if (part_die
->tag
== DW_TAG_enumerator
5973 && parent_die
!= NULL
5974 && parent_die
->die_parent
== NULL
5975 && parent_die
->tag
== DW_TAG_enumeration_type
5976 && parent_die
->has_specification
== 0)
5978 if (part_die
->name
== NULL
)
5979 complaint (&symfile_complaints
, _("malformed enumerator DIE ignored"));
5980 else if (building_psymtab
)
5981 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5982 VAR_DOMAIN
, LOC_CONST
,
5983 (cu
->language
== language_cplus
5984 || cu
->language
== language_java
)
5985 ? &cu
->objfile
->global_psymbols
5986 : &cu
->objfile
->static_psymbols
,
5987 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5989 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5993 /* We'll save this DIE so link it in. */
5994 part_die
->die_parent
= parent_die
;
5995 part_die
->die_sibling
= NULL
;
5996 part_die
->die_child
= NULL
;
5998 if (last_die
&& last_die
== parent_die
)
5999 last_die
->die_child
= part_die
;
6001 last_die
->die_sibling
= part_die
;
6003 last_die
= part_die
;
6005 if (first_die
== NULL
)
6006 first_die
= part_die
;
6008 /* Maybe add the DIE to the hash table. Not all DIEs that we
6009 find interesting need to be in the hash table, because we
6010 also have the parent/sibling/child chains; only those that we
6011 might refer to by offset later during partial symbol reading.
6013 For now this means things that might have be the target of a
6014 DW_AT_specification, DW_AT_abstract_origin, or
6015 DW_AT_extension. DW_AT_extension will refer only to
6016 namespaces; DW_AT_abstract_origin refers to functions (and
6017 many things under the function DIE, but we do not recurse
6018 into function DIEs during partial symbol reading) and
6019 possibly variables as well; DW_AT_specification refers to
6020 declarations. Declarations ought to have the DW_AT_declaration
6021 flag. It happens that GCC forgets to put it in sometimes, but
6022 only for functions, not for types.
6024 Adding more things than necessary to the hash table is harmless
6025 except for the performance cost. Adding too few will result in
6026 wasted time in find_partial_die, when we reread the compilation
6027 unit with load_all_dies set. */
6030 || abbrev
->tag
== DW_TAG_subprogram
6031 || abbrev
->tag
== DW_TAG_variable
6032 || abbrev
->tag
== DW_TAG_namespace
6033 || part_die
->is_declaration
)
6037 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
6038 part_die
->offset
, INSERT
);
6042 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
6043 sizeof (struct partial_die_info
));
6045 /* For some DIEs we want to follow their children (if any). For C
6046 we have no reason to follow the children of structures; for other
6047 languages we have to, both so that we can get at method physnames
6048 to infer fully qualified class names, and for DW_AT_specification.
6050 For Ada, we need to scan the children of subprograms and lexical
6051 blocks as well because Ada allows the definition of nested
6052 entities that could be interesting for the debugger, such as
6053 nested subprograms for instance. */
6054 if (last_die
->has_children
6056 || last_die
->tag
== DW_TAG_namespace
6057 || last_die
->tag
== DW_TAG_enumeration_type
6058 || (cu
->language
!= language_c
6059 && (last_die
->tag
== DW_TAG_class_type
6060 || last_die
->tag
== DW_TAG_interface_type
6061 || last_die
->tag
== DW_TAG_structure_type
6062 || last_die
->tag
== DW_TAG_union_type
))
6063 || (cu
->language
== language_ada
6064 && (last_die
->tag
== DW_TAG_subprogram
6065 || last_die
->tag
== DW_TAG_lexical_block
))))
6068 parent_die
= last_die
;
6072 /* Otherwise we skip to the next sibling, if any. */
6073 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
6075 /* Back to the top, do it again. */
6079 /* Read a minimal amount of information into the minimal die structure. */
6082 read_partial_die (struct partial_die_info
*part_die
,
6083 struct abbrev_info
*abbrev
,
6084 unsigned int abbrev_len
, bfd
*abfd
,
6085 gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6087 unsigned int bytes_read
, i
;
6088 struct attribute attr
;
6089 int has_low_pc_attr
= 0;
6090 int has_high_pc_attr
= 0;
6091 CORE_ADDR base_address
= 0;
6095 base_address_low_pc
,
6096 /* Overrides BASE_ADDRESS_LOW_PC. */
6097 base_address_entry_pc
6099 base_address_type
= base_address_none
;
6101 memset (part_die
, 0, sizeof (struct partial_die_info
));
6103 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
6105 info_ptr
+= abbrev_len
;
6110 part_die
->tag
= abbrev
->tag
;
6111 part_die
->has_children
= abbrev
->has_children
;
6113 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6115 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
6117 /* Store the data if it is of an attribute we want to keep in a
6118 partial symbol table. */
6122 switch (part_die
->tag
)
6124 case DW_TAG_compile_unit
:
6125 /* Compilation units have a DW_AT_name that is a filename, not
6126 a source language identifier. */
6127 case DW_TAG_enumeration_type
:
6128 case DW_TAG_enumerator
:
6129 /* These tags always have simple identifiers already; no need
6130 to canonicalize them. */
6131 part_die
->name
= DW_STRING (&attr
);
6135 = dwarf2_canonicalize_name (DW_STRING (&attr
), cu
,
6136 &cu
->comp_unit_obstack
);
6140 case DW_AT_comp_dir
:
6141 if (part_die
->dirname
== NULL
)
6142 part_die
->dirname
= DW_STRING (&attr
);
6144 case DW_AT_MIPS_linkage_name
:
6145 part_die
->name
= DW_STRING (&attr
);
6148 has_low_pc_attr
= 1;
6149 part_die
->lowpc
= DW_ADDR (&attr
);
6150 if (part_die
->tag
== DW_TAG_compile_unit
6151 && base_address_type
< base_address_low_pc
)
6153 base_address
= DW_ADDR (&attr
);
6154 base_address_type
= base_address_low_pc
;
6158 has_high_pc_attr
= 1;
6159 part_die
->highpc
= DW_ADDR (&attr
);
6161 case DW_AT_entry_pc
:
6162 if (part_die
->tag
== DW_TAG_compile_unit
6163 && base_address_type
< base_address_entry_pc
)
6165 base_address
= DW_ADDR (&attr
);
6166 base_address_type
= base_address_entry_pc
;
6170 if (part_die
->tag
== DW_TAG_compile_unit
)
6172 cu
->ranges_offset
= DW_UNSND (&attr
);
6173 cu
->has_ranges_offset
= 1;
6176 case DW_AT_location
:
6177 /* Support the .debug_loc offsets */
6178 if (attr_form_is_block (&attr
))
6180 part_die
->locdesc
= DW_BLOCK (&attr
);
6182 else if (attr_form_is_section_offset (&attr
))
6184 dwarf2_complex_location_expr_complaint ();
6188 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
6189 "partial symbol information");
6192 case DW_AT_language
:
6193 part_die
->language
= DW_UNSND (&attr
);
6195 case DW_AT_external
:
6196 part_die
->is_external
= DW_UNSND (&attr
);
6198 case DW_AT_declaration
:
6199 part_die
->is_declaration
= DW_UNSND (&attr
);
6202 part_die
->has_type
= 1;
6204 case DW_AT_abstract_origin
:
6205 case DW_AT_specification
:
6206 case DW_AT_extension
:
6207 part_die
->has_specification
= 1;
6208 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
);
6211 /* Ignore absolute siblings, they might point outside of
6212 the current compile unit. */
6213 if (attr
.form
== DW_FORM_ref_addr
)
6214 complaint (&symfile_complaints
, _("ignoring absolute DW_AT_sibling"));
6216 part_die
->sibling
= dwarf2_per_objfile
->info
.buffer
6217 + dwarf2_get_ref_die_offset (&attr
);
6219 case DW_AT_stmt_list
:
6220 part_die
->has_stmt_list
= 1;
6221 part_die
->line_offset
= DW_UNSND (&attr
);
6223 case DW_AT_byte_size
:
6224 part_die
->has_byte_size
= 1;
6226 case DW_AT_calling_convention
:
6227 /* DWARF doesn't provide a way to identify a program's source-level
6228 entry point. DW_AT_calling_convention attributes are only meant
6229 to describe functions' calling conventions.
6231 However, because it's a necessary piece of information in
6232 Fortran, and because DW_CC_program is the only piece of debugging
6233 information whose definition refers to a 'main program' at all,
6234 several compilers have begun marking Fortran main programs with
6235 DW_CC_program --- even when those functions use the standard
6236 calling conventions.
6238 So until DWARF specifies a way to provide this information and
6239 compilers pick up the new representation, we'll support this
6241 if (DW_UNSND (&attr
) == DW_CC_program
6242 && cu
->language
== language_fortran
)
6243 set_main_name (part_die
->name
);
6250 /* When using the GNU linker, .gnu.linkonce. sections are used to
6251 eliminate duplicate copies of functions and vtables and such.
6252 The linker will arbitrarily choose one and discard the others.
6253 The AT_*_pc values for such functions refer to local labels in
6254 these sections. If the section from that file was discarded, the
6255 labels are not in the output, so the relocs get a value of 0.
6256 If this is a discarded function, mark the pc bounds as invalid,
6257 so that GDB will ignore it. */
6258 if (has_low_pc_attr
&& has_high_pc_attr
6259 && part_die
->lowpc
< part_die
->highpc
6260 && (part_die
->lowpc
!= 0
6261 || dwarf2_per_objfile
->has_section_at_zero
))
6262 part_die
->has_pc_info
= 1;
6264 if (base_address_type
!= base_address_none
&& !cu
->base_known
)
6266 gdb_assert (part_die
->tag
== DW_TAG_compile_unit
);
6268 cu
->base_address
= base_address
;
6274 /* Find a cached partial DIE at OFFSET in CU. */
6276 static struct partial_die_info
*
6277 find_partial_die_in_comp_unit (unsigned int offset
, struct dwarf2_cu
*cu
)
6279 struct partial_die_info
*lookup_die
= NULL
;
6280 struct partial_die_info part_die
;
6282 part_die
.offset
= offset
;
6283 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
6288 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
6290 static struct partial_die_info
*
6291 find_partial_die (unsigned int offset
, struct dwarf2_cu
*cu
)
6293 struct dwarf2_per_cu_data
*per_cu
= NULL
;
6294 struct partial_die_info
*pd
= NULL
;
6296 if (offset_in_cu_p (&cu
->header
, offset
))
6298 pd
= find_partial_die_in_comp_unit (offset
, cu
);
6303 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
6305 if (per_cu
->cu
== NULL
)
6307 load_comp_unit (per_cu
, cu
->objfile
);
6308 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
6309 dwarf2_per_objfile
->read_in_chain
= per_cu
;
6312 per_cu
->cu
->last_used
= 0;
6313 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6315 if (pd
== NULL
&& per_cu
->load_all_dies
== 0)
6317 struct cleanup
*back_to
;
6318 struct partial_die_info comp_unit_die
;
6319 struct abbrev_info
*abbrev
;
6320 unsigned int bytes_read
;
6323 per_cu
->load_all_dies
= 1;
6325 /* Re-read the DIEs. */
6326 back_to
= make_cleanup (null_cleanup
, 0);
6327 if (per_cu
->cu
->dwarf2_abbrevs
== NULL
)
6329 dwarf2_read_abbrevs (per_cu
->cu
->objfile
->obfd
, per_cu
->cu
);
6330 back_to
= make_cleanup (dwarf2_free_abbrev_table
, per_cu
->cu
);
6332 info_ptr
= (dwarf2_per_objfile
->info
.buffer
6333 + per_cu
->cu
->header
.offset
6334 + per_cu
->cu
->header
.first_die_offset
);
6335 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, per_cu
->cu
);
6336 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
6337 per_cu
->cu
->objfile
->obfd
, info_ptr
,
6339 if (comp_unit_die
.has_children
)
6340 load_partial_dies (per_cu
->cu
->objfile
->obfd
, info_ptr
, 0, per_cu
->cu
);
6341 do_cleanups (back_to
);
6343 pd
= find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
6347 internal_error (__FILE__
, __LINE__
,
6348 _("could not find partial DIE 0x%x in cache [from module %s]\n"),
6349 offset
, bfd_get_filename (cu
->objfile
->obfd
));
6353 /* Adjust PART_DIE before generating a symbol for it. This function
6354 may set the is_external flag or change the DIE's name. */
6357 fixup_partial_die (struct partial_die_info
*part_die
,
6358 struct dwarf2_cu
*cu
)
6360 /* If we found a reference attribute and the DIE has no name, try
6361 to find a name in the referred to DIE. */
6363 if (part_die
->name
== NULL
&& part_die
->has_specification
)
6365 struct partial_die_info
*spec_die
;
6367 spec_die
= find_partial_die (part_die
->spec_offset
, cu
);
6369 fixup_partial_die (spec_die
, cu
);
6373 part_die
->name
= spec_die
->name
;
6375 /* Copy DW_AT_external attribute if it is set. */
6376 if (spec_die
->is_external
)
6377 part_die
->is_external
= spec_die
->is_external
;
6381 /* Set default names for some unnamed DIEs. */
6382 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
6383 || part_die
->tag
== DW_TAG_class_type
))
6384 part_die
->name
= "(anonymous class)";
6386 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
6387 part_die
->name
= "(anonymous namespace)";
6389 if (part_die
->tag
== DW_TAG_structure_type
6390 || part_die
->tag
== DW_TAG_class_type
6391 || part_die
->tag
== DW_TAG_union_type
)
6392 guess_structure_name (part_die
, cu
);
6395 /* Read the die from the .debug_info section buffer. Set DIEP to
6396 point to a newly allocated die with its information, except for its
6397 child, sibling, and parent fields. Set HAS_CHILDREN to tell
6398 whether the die has children or not. */
6401 read_full_die (struct die_info
**diep
, bfd
*abfd
, gdb_byte
*info_ptr
,
6402 struct dwarf2_cu
*cu
, int *has_children
)
6404 unsigned int abbrev_number
, bytes_read
, i
, offset
;
6405 struct abbrev_info
*abbrev
;
6406 struct die_info
*die
;
6408 offset
= info_ptr
- dwarf2_per_objfile
->info
.buffer
;
6409 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6410 info_ptr
+= bytes_read
;
6418 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
6421 error (_("Dwarf Error: could not find abbrev number %d [in module %s]"),
6423 bfd_get_filename (abfd
));
6425 die
= dwarf_alloc_die (cu
, abbrev
->num_attrs
);
6426 die
->offset
= offset
;
6427 die
->tag
= abbrev
->tag
;
6428 die
->abbrev
= abbrev_number
;
6430 die
->num_attrs
= abbrev
->num_attrs
;
6432 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
6433 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
6434 abfd
, info_ptr
, cu
);
6437 *has_children
= abbrev
->has_children
;
6441 /* Read an attribute value described by an attribute form. */
6444 read_attribute_value (struct attribute
*attr
, unsigned form
,
6445 bfd
*abfd
, gdb_byte
*info_ptr
,
6446 struct dwarf2_cu
*cu
)
6448 struct comp_unit_head
*cu_header
= &cu
->header
;
6449 unsigned int bytes_read
;
6450 struct dwarf_block
*blk
;
6456 case DW_FORM_ref_addr
:
6457 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
6458 info_ptr
+= bytes_read
;
6460 case DW_FORM_block2
:
6461 blk
= dwarf_alloc_block (cu
);
6462 blk
->size
= read_2_bytes (abfd
, info_ptr
);
6464 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6465 info_ptr
+= blk
->size
;
6466 DW_BLOCK (attr
) = blk
;
6468 case DW_FORM_block4
:
6469 blk
= dwarf_alloc_block (cu
);
6470 blk
->size
= read_4_bytes (abfd
, info_ptr
);
6472 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6473 info_ptr
+= blk
->size
;
6474 DW_BLOCK (attr
) = blk
;
6477 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
6481 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
6485 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
6488 case DW_FORM_string
:
6489 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
6490 info_ptr
+= bytes_read
;
6493 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
6495 info_ptr
+= bytes_read
;
6498 blk
= dwarf_alloc_block (cu
);
6499 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6500 info_ptr
+= bytes_read
;
6501 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6502 info_ptr
+= blk
->size
;
6503 DW_BLOCK (attr
) = blk
;
6505 case DW_FORM_block1
:
6506 blk
= dwarf_alloc_block (cu
);
6507 blk
->size
= read_1_byte (abfd
, info_ptr
);
6509 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
6510 info_ptr
+= blk
->size
;
6511 DW_BLOCK (attr
) = blk
;
6514 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6518 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
6522 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
6523 info_ptr
+= bytes_read
;
6526 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6527 info_ptr
+= bytes_read
;
6530 DW_ADDR (attr
) = cu
->header
.offset
+ read_1_byte (abfd
, info_ptr
);
6534 DW_ADDR (attr
) = cu
->header
.offset
+ read_2_bytes (abfd
, info_ptr
);
6538 DW_ADDR (attr
) = cu
->header
.offset
+ read_4_bytes (abfd
, info_ptr
);
6542 DW_ADDR (attr
) = cu
->header
.offset
+ read_8_bytes (abfd
, info_ptr
);
6545 case DW_FORM_ref_udata
:
6546 DW_ADDR (attr
) = (cu
->header
.offset
6547 + read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
));
6548 info_ptr
+= bytes_read
;
6550 case DW_FORM_indirect
:
6551 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
6552 info_ptr
+= bytes_read
;
6553 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
6556 error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"),
6557 dwarf_form_name (form
),
6558 bfd_get_filename (abfd
));
6561 /* We have seen instances where the compiler tried to emit a byte
6562 size attribute of -1 which ended up being encoded as an unsigned
6563 0xffffffff. Although 0xffffffff is technically a valid size value,
6564 an object of this size seems pretty unlikely so we can relatively
6565 safely treat these cases as if the size attribute was invalid and
6566 treat them as zero by default. */
6567 if (attr
->name
== DW_AT_byte_size
6568 && form
== DW_FORM_data4
6569 && DW_UNSND (attr
) >= 0xffffffff)
6572 (&symfile_complaints
,
6573 _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"),
6575 DW_UNSND (attr
) = 0;
6581 /* Read an attribute described by an abbreviated attribute. */
6584 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
6585 bfd
*abfd
, gdb_byte
*info_ptr
, struct dwarf2_cu
*cu
)
6587 attr
->name
= abbrev
->name
;
6588 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
6591 /* read dwarf information from a buffer */
6594 read_1_byte (bfd
*abfd
, gdb_byte
*buf
)
6596 return bfd_get_8 (abfd
, buf
);
6600 read_1_signed_byte (bfd
*abfd
, gdb_byte
*buf
)
6602 return bfd_get_signed_8 (abfd
, buf
);
6606 read_2_bytes (bfd
*abfd
, gdb_byte
*buf
)
6608 return bfd_get_16 (abfd
, buf
);
6612 read_2_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6614 return bfd_get_signed_16 (abfd
, buf
);
6618 read_4_bytes (bfd
*abfd
, gdb_byte
*buf
)
6620 return bfd_get_32 (abfd
, buf
);
6624 read_4_signed_bytes (bfd
*abfd
, gdb_byte
*buf
)
6626 return bfd_get_signed_32 (abfd
, buf
);
6629 static unsigned long
6630 read_8_bytes (bfd
*abfd
, gdb_byte
*buf
)
6632 return bfd_get_64 (abfd
, buf
);
6636 read_address (bfd
*abfd
, gdb_byte
*buf
, struct dwarf2_cu
*cu
,
6637 unsigned int *bytes_read
)
6639 struct comp_unit_head
*cu_header
= &cu
->header
;
6640 CORE_ADDR retval
= 0;
6642 if (cu_header
->signed_addr_p
)
6644 switch (cu_header
->addr_size
)
6647 retval
= bfd_get_signed_16 (abfd
, buf
);
6650 retval
= bfd_get_signed_32 (abfd
, buf
);
6653 retval
= bfd_get_signed_64 (abfd
, buf
);
6656 internal_error (__FILE__
, __LINE__
,
6657 _("read_address: bad switch, signed [in module %s]"),
6658 bfd_get_filename (abfd
));
6663 switch (cu_header
->addr_size
)
6666 retval
= bfd_get_16 (abfd
, buf
);
6669 retval
= bfd_get_32 (abfd
, buf
);
6672 retval
= bfd_get_64 (abfd
, buf
);
6675 internal_error (__FILE__
, __LINE__
,
6676 _("read_address: bad switch, unsigned [in module %s]"),
6677 bfd_get_filename (abfd
));
6681 *bytes_read
= cu_header
->addr_size
;
6685 /* Read the initial length from a section. The (draft) DWARF 3
6686 specification allows the initial length to take up either 4 bytes
6687 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
6688 bytes describe the length and all offsets will be 8 bytes in length
6691 An older, non-standard 64-bit format is also handled by this
6692 function. The older format in question stores the initial length
6693 as an 8-byte quantity without an escape value. Lengths greater
6694 than 2^32 aren't very common which means that the initial 4 bytes
6695 is almost always zero. Since a length value of zero doesn't make
6696 sense for the 32-bit format, this initial zero can be considered to
6697 be an escape value which indicates the presence of the older 64-bit
6698 format. As written, the code can't detect (old format) lengths
6699 greater than 4GB. If it becomes necessary to handle lengths
6700 somewhat larger than 4GB, we could allow other small values (such
6701 as the non-sensical values of 1, 2, and 3) to also be used as
6702 escape values indicating the presence of the old format.
6704 The value returned via bytes_read should be used to increment the
6705 relevant pointer after calling read_initial_length().
6707 [ Note: read_initial_length() and read_offset() are based on the
6708 document entitled "DWARF Debugging Information Format", revision
6709 3, draft 8, dated November 19, 2001. This document was obtained
6712 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
6714 This document is only a draft and is subject to change. (So beware.)
6716 Details regarding the older, non-standard 64-bit format were
6717 determined empirically by examining 64-bit ELF files produced by
6718 the SGI toolchain on an IRIX 6.5 machine.
6720 - Kevin, July 16, 2002
6724 read_initial_length (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read
)
6726 LONGEST length
= bfd_get_32 (abfd
, buf
);
6728 if (length
== 0xffffffff)
6730 length
= bfd_get_64 (abfd
, buf
+ 4);
6733 else if (length
== 0)
6735 /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */
6736 length
= bfd_get_64 (abfd
, buf
);
6747 /* Cover function for read_initial_length.
6748 Returns the length of the object at BUF, and stores the size of the
6749 initial length in *BYTES_READ and stores the size that offsets will be in
6751 If the initial length size is not equivalent to that specified in
6752 CU_HEADER then issue a complaint.
6753 This is useful when reading non-comp-unit headers. */
6756 read_checked_initial_length_and_offset (bfd
*abfd
, gdb_byte
*buf
,
6757 const struct comp_unit_head
*cu_header
,
6758 unsigned int *bytes_read
,
6759 unsigned int *offset_size
)
6761 LONGEST length
= read_initial_length (abfd
, buf
, bytes_read
);
6763 gdb_assert (cu_header
->initial_length_size
== 4
6764 || cu_header
->initial_length_size
== 8
6765 || cu_header
->initial_length_size
== 12);
6767 if (cu_header
->initial_length_size
!= *bytes_read
)
6768 complaint (&symfile_complaints
,
6769 _("intermixed 32-bit and 64-bit DWARF sections"));
6771 *offset_size
= (*bytes_read
== 4) ? 4 : 8;
6775 /* Read an offset from the data stream. The size of the offset is
6776 given by cu_header->offset_size. */
6779 read_offset (bfd
*abfd
, gdb_byte
*buf
, const struct comp_unit_head
*cu_header
,
6780 unsigned int *bytes_read
)
6782 LONGEST offset
= read_offset_1 (abfd
, buf
, cu_header
->offset_size
);
6783 *bytes_read
= cu_header
->offset_size
;
6787 /* Read an offset from the data stream. */
6790 read_offset_1 (bfd
*abfd
, gdb_byte
*buf
, unsigned int offset_size
)
6794 switch (offset_size
)
6797 retval
= bfd_get_32 (abfd
, buf
);
6800 retval
= bfd_get_64 (abfd
, buf
);
6803 internal_error (__FILE__
, __LINE__
,
6804 _("read_offset_1: bad switch [in module %s]"),
6805 bfd_get_filename (abfd
));
6812 read_n_bytes (bfd
*abfd
, gdb_byte
*buf
, unsigned int size
)
6814 /* If the size of a host char is 8 bits, we can return a pointer
6815 to the buffer, otherwise we have to copy the data to a buffer
6816 allocated on the temporary obstack. */
6817 gdb_assert (HOST_CHAR_BIT
== 8);
6822 read_string (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6824 /* If the size of a host char is 8 bits, we can return a pointer
6825 to the string, otherwise we have to copy the string to a buffer
6826 allocated on the temporary obstack. */
6827 gdb_assert (HOST_CHAR_BIT
== 8);
6830 *bytes_read_ptr
= 1;
6833 *bytes_read_ptr
= strlen ((char *) buf
) + 1;
6834 return (char *) buf
;
6838 read_indirect_string (bfd
*abfd
, gdb_byte
*buf
,
6839 const struct comp_unit_head
*cu_header
,
6840 unsigned int *bytes_read_ptr
)
6842 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
, bytes_read_ptr
);
6844 if (dwarf2_per_objfile
->str
.buffer
== NULL
)
6846 error (_("DW_FORM_strp used without .debug_str section [in module %s]"),
6847 bfd_get_filename (abfd
));
6850 if (str_offset
>= dwarf2_per_objfile
->str
.size
)
6852 error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"),
6853 bfd_get_filename (abfd
));
6856 gdb_assert (HOST_CHAR_BIT
== 8);
6857 if (dwarf2_per_objfile
->str
.buffer
[str_offset
] == '\0')
6859 return (char *) (dwarf2_per_objfile
->str
.buffer
+ str_offset
);
6862 static unsigned long
6863 read_unsigned_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6865 unsigned long result
;
6866 unsigned int num_read
;
6876 byte
= bfd_get_8 (abfd
, buf
);
6879 result
|= ((unsigned long)(byte
& 127) << shift
);
6880 if ((byte
& 128) == 0)
6886 *bytes_read_ptr
= num_read
;
6891 read_signed_leb128 (bfd
*abfd
, gdb_byte
*buf
, unsigned int *bytes_read_ptr
)
6894 int i
, shift
, num_read
;
6903 byte
= bfd_get_8 (abfd
, buf
);
6906 result
|= ((long)(byte
& 127) << shift
);
6908 if ((byte
& 128) == 0)
6913 if ((shift
< 8 * sizeof (result
)) && (byte
& 0x40))
6914 result
|= -(((long)1) << shift
);
6915 *bytes_read_ptr
= num_read
;
6919 /* Return a pointer to just past the end of an LEB128 number in BUF. */
6922 skip_leb128 (bfd
*abfd
, gdb_byte
*buf
)
6928 byte
= bfd_get_8 (abfd
, buf
);
6930 if ((byte
& 128) == 0)
6936 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
6943 cu
->language
= language_c
;
6945 case DW_LANG_C_plus_plus
:
6946 cu
->language
= language_cplus
;
6948 case DW_LANG_Fortran77
:
6949 case DW_LANG_Fortran90
:
6950 case DW_LANG_Fortran95
:
6951 cu
->language
= language_fortran
;
6953 case DW_LANG_Mips_Assembler
:
6954 cu
->language
= language_asm
;
6957 cu
->language
= language_java
;
6961 cu
->language
= language_ada
;
6963 case DW_LANG_Modula2
:
6964 cu
->language
= language_m2
;
6966 case DW_LANG_Pascal83
:
6967 cu
->language
= language_pascal
;
6970 cu
->language
= language_objc
;
6972 case DW_LANG_Cobol74
:
6973 case DW_LANG_Cobol85
:
6975 cu
->language
= language_minimal
;
6978 cu
->language_defn
= language_def (cu
->language
);
6981 /* Return the named attribute or NULL if not there. */
6983 static struct attribute
*
6984 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
6987 struct attribute
*spec
= NULL
;
6989 for (i
= 0; i
< die
->num_attrs
; ++i
)
6991 if (die
->attrs
[i
].name
== name
)
6992 return &die
->attrs
[i
];
6993 if (die
->attrs
[i
].name
== DW_AT_specification
6994 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
6995 spec
= &die
->attrs
[i
];
7000 die
= follow_die_ref (die
, spec
, &cu
);
7001 return dwarf2_attr (die
, name
, cu
);
7007 /* Return non-zero iff the attribute NAME is defined for the given DIE,
7008 and holds a non-zero value. This function should only be used for
7009 DW_FORM_flag attributes. */
7012 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
7014 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
7016 return (attr
&& DW_UNSND (attr
));
7020 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
7022 /* A DIE is a declaration if it has a DW_AT_declaration attribute
7023 which value is non-zero. However, we have to be careful with
7024 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
7025 (via dwarf2_flag_true_p) follows this attribute. So we may
7026 end up accidently finding a declaration attribute that belongs
7027 to a different DIE referenced by the specification attribute,
7028 even though the given DIE does not have a declaration attribute. */
7029 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
7030 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
7033 /* Return the die giving the specification for DIE, if there is
7034 one. *SPEC_CU is the CU containing DIE on input, and the CU
7035 containing the return value on output. If there is no
7036 specification, but there is an abstract origin, that is
7039 static struct die_info
*
7040 die_specification (struct die_info
*die
, struct dwarf2_cu
**spec_cu
)
7042 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
,
7045 if (spec_attr
== NULL
)
7046 spec_attr
= dwarf2_attr (die
, DW_AT_abstract_origin
, *spec_cu
);
7048 if (spec_attr
== NULL
)
7051 return follow_die_ref (die
, spec_attr
, spec_cu
);
7054 /* Free the line_header structure *LH, and any arrays and strings it
7057 free_line_header (struct line_header
*lh
)
7059 if (lh
->standard_opcode_lengths
)
7060 xfree (lh
->standard_opcode_lengths
);
7062 /* Remember that all the lh->file_names[i].name pointers are
7063 pointers into debug_line_buffer, and don't need to be freed. */
7065 xfree (lh
->file_names
);
7067 /* Similarly for the include directory names. */
7068 if (lh
->include_dirs
)
7069 xfree (lh
->include_dirs
);
7075 /* Add an entry to LH's include directory table. */
7077 add_include_dir (struct line_header
*lh
, char *include_dir
)
7079 /* Grow the array if necessary. */
7080 if (lh
->include_dirs_size
== 0)
7082 lh
->include_dirs_size
= 1; /* for testing */
7083 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
7084 * sizeof (*lh
->include_dirs
));
7086 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
7088 lh
->include_dirs_size
*= 2;
7089 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
7090 (lh
->include_dirs_size
7091 * sizeof (*lh
->include_dirs
)));
7094 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
7098 /* Add an entry to LH's file name table. */
7100 add_file_name (struct line_header
*lh
,
7102 unsigned int dir_index
,
7103 unsigned int mod_time
,
7104 unsigned int length
)
7106 struct file_entry
*fe
;
7108 /* Grow the array if necessary. */
7109 if (lh
->file_names_size
== 0)
7111 lh
->file_names_size
= 1; /* for testing */
7112 lh
->file_names
= xmalloc (lh
->file_names_size
7113 * sizeof (*lh
->file_names
));
7115 else if (lh
->num_file_names
>= lh
->file_names_size
)
7117 lh
->file_names_size
*= 2;
7118 lh
->file_names
= xrealloc (lh
->file_names
,
7119 (lh
->file_names_size
7120 * sizeof (*lh
->file_names
)));
7123 fe
= &lh
->file_names
[lh
->num_file_names
++];
7125 fe
->dir_index
= dir_index
;
7126 fe
->mod_time
= mod_time
;
7127 fe
->length
= length
;
7133 /* Read the statement program header starting at OFFSET in
7134 .debug_line, according to the endianness of ABFD. Return a pointer
7135 to a struct line_header, allocated using xmalloc.
7137 NOTE: the strings in the include directory and file name tables of
7138 the returned object point into debug_line_buffer, and must not be
7140 static struct line_header
*
7141 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
7142 struct dwarf2_cu
*cu
)
7144 struct cleanup
*back_to
;
7145 struct line_header
*lh
;
7147 unsigned int bytes_read
, offset_size
;
7149 char *cur_dir
, *cur_file
;
7151 if (dwarf2_per_objfile
->line
.buffer
== NULL
)
7153 complaint (&symfile_complaints
, _("missing .debug_line section"));
7157 /* Make sure that at least there's room for the total_length field.
7158 That could be 12 bytes long, but we're just going to fudge that. */
7159 if (offset
+ 4 >= dwarf2_per_objfile
->line
.size
)
7161 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7165 lh
= xmalloc (sizeof (*lh
));
7166 memset (lh
, 0, sizeof (*lh
));
7167 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
7170 line_ptr
= dwarf2_per_objfile
->line
.buffer
+ offset
;
7172 /* Read in the header. */
7174 read_checked_initial_length_and_offset (abfd
, line_ptr
, &cu
->header
,
7175 &bytes_read
, &offset_size
);
7176 line_ptr
+= bytes_read
;
7177 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line
.buffer
7178 + dwarf2_per_objfile
->line
.size
))
7180 dwarf2_statement_list_fits_in_line_number_section_complaint ();
7183 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
7184 lh
->version
= read_2_bytes (abfd
, line_ptr
);
7186 lh
->header_length
= read_offset_1 (abfd
, line_ptr
, offset_size
);
7187 line_ptr
+= offset_size
;
7188 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
7190 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
7192 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
7194 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
7196 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
7198 lh
->standard_opcode_lengths
7199 = xmalloc (lh
->opcode_base
* sizeof (lh
->standard_opcode_lengths
[0]));
7201 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
7202 for (i
= 1; i
< lh
->opcode_base
; ++i
)
7204 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
7208 /* Read directory table. */
7209 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7211 line_ptr
+= bytes_read
;
7212 add_include_dir (lh
, cur_dir
);
7214 line_ptr
+= bytes_read
;
7216 /* Read file name table. */
7217 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
7219 unsigned int dir_index
, mod_time
, length
;
7221 line_ptr
+= bytes_read
;
7222 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7223 line_ptr
+= bytes_read
;
7224 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7225 line_ptr
+= bytes_read
;
7226 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7227 line_ptr
+= bytes_read
;
7229 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7231 line_ptr
+= bytes_read
;
7232 lh
->statement_program_start
= line_ptr
;
7234 if (line_ptr
> (dwarf2_per_objfile
->line
.buffer
7235 + dwarf2_per_objfile
->line
.size
))
7236 complaint (&symfile_complaints
,
7237 _("line number info header doesn't fit in `.debug_line' section"));
7239 discard_cleanups (back_to
);
7243 /* This function exists to work around a bug in certain compilers
7244 (particularly GCC 2.95), in which the first line number marker of a
7245 function does not show up until after the prologue, right before
7246 the second line number marker. This function shifts ADDRESS down
7247 to the beginning of the function if necessary, and is called on
7248 addresses passed to record_line. */
7251 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
7253 struct function_range
*fn
;
7255 /* Find the function_range containing address. */
7260 cu
->cached_fn
= cu
->first_fn
;
7264 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7270 while (fn
&& fn
!= cu
->cached_fn
)
7271 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
7281 if (address
!= fn
->lowpc
)
7282 complaint (&symfile_complaints
,
7283 _("misplaced first line number at 0x%lx for '%s'"),
7284 (unsigned long) address
, fn
->name
);
7289 /* Decode the Line Number Program (LNP) for the given line_header
7290 structure and CU. The actual information extracted and the type
7291 of structures created from the LNP depends on the value of PST.
7293 1. If PST is NULL, then this procedure uses the data from the program
7294 to create all necessary symbol tables, and their linetables.
7295 The compilation directory of the file is passed in COMP_DIR,
7296 and must not be NULL.
7298 2. If PST is not NULL, this procedure reads the program to determine
7299 the list of files included by the unit represented by PST, and
7300 builds all the associated partial symbol tables. In this case,
7301 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
7302 is not used to compute the full name of the symtab, and therefore
7303 omitting it when building the partial symtab does not introduce
7304 the potential for inconsistency - a partial symtab and its associated
7305 symbtab having a different fullname -). */
7308 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
7309 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
7311 gdb_byte
*line_ptr
, *extended_end
;
7313 unsigned int bytes_read
, extended_len
;
7314 unsigned char op_code
, extended_op
, adj_opcode
;
7316 struct objfile
*objfile
= cu
->objfile
;
7317 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
7318 const int decode_for_pst_p
= (pst
!= NULL
);
7319 struct subfile
*last_subfile
= NULL
, *first_subfile
= current_subfile
;
7321 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7323 line_ptr
= lh
->statement_program_start
;
7324 line_end
= lh
->statement_program_end
;
7326 /* Read the statement sequences until there's nothing left. */
7327 while (line_ptr
< line_end
)
7329 /* state machine registers */
7330 CORE_ADDR address
= 0;
7331 unsigned int file
= 1;
7332 unsigned int line
= 1;
7333 unsigned int column
= 0;
7334 int is_stmt
= lh
->default_is_stmt
;
7335 int basic_block
= 0;
7336 int end_sequence
= 0;
7339 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
7341 /* Start a subfile for the current file of the state machine. */
7342 /* lh->include_dirs and lh->file_names are 0-based, but the
7343 directory and file name numbers in the statement program
7345 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
7349 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7351 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7354 /* Decode the table. */
7355 while (!end_sequence
)
7357 op_code
= read_1_byte (abfd
, line_ptr
);
7359 if (line_ptr
> line_end
)
7361 dwarf2_debug_line_missing_end_sequence_complaint ();
7365 if (op_code
>= lh
->opcode_base
)
7367 /* Special operand. */
7368 adj_opcode
= op_code
- lh
->opcode_base
;
7369 address
+= (adj_opcode
/ lh
->line_range
)
7370 * lh
->minimum_instruction_length
;
7371 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
7372 if (lh
->num_file_names
< file
|| file
== 0)
7373 dwarf2_debug_line_missing_file_complaint ();
7376 lh
->file_names
[file
- 1].included_p
= 1;
7377 if (!decode_for_pst_p
&& is_stmt
)
7379 if (last_subfile
!= current_subfile
)
7381 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7383 record_line (last_subfile
, 0, addr
);
7384 last_subfile
= current_subfile
;
7386 /* Append row to matrix using current values. */
7387 addr
= check_cu_functions (address
, cu
);
7388 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7389 record_line (current_subfile
, line
, addr
);
7394 else switch (op_code
)
7396 case DW_LNS_extended_op
:
7397 extended_len
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7398 line_ptr
+= bytes_read
;
7399 extended_end
= line_ptr
+ extended_len
;
7400 extended_op
= read_1_byte (abfd
, line_ptr
);
7402 switch (extended_op
)
7404 case DW_LNE_end_sequence
:
7407 case DW_LNE_set_address
:
7408 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
7409 line_ptr
+= bytes_read
;
7410 address
+= baseaddr
;
7412 case DW_LNE_define_file
:
7415 unsigned int dir_index
, mod_time
, length
;
7417 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
7418 line_ptr
+= bytes_read
;
7420 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7421 line_ptr
+= bytes_read
;
7423 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7424 line_ptr
+= bytes_read
;
7426 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7427 line_ptr
+= bytes_read
;
7428 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
7431 case DW_LNE_set_discriminator
:
7432 /* The discriminator is not interesting to the debugger;
7434 line_ptr
= extended_end
;
7437 complaint (&symfile_complaints
,
7438 _("mangled .debug_line section"));
7441 /* Make sure that we parsed the extended op correctly. If e.g.
7442 we expected a different address size than the producer used,
7443 we may have read the wrong number of bytes. */
7444 if (line_ptr
!= extended_end
)
7446 complaint (&symfile_complaints
,
7447 _("mangled .debug_line section"));
7452 if (lh
->num_file_names
< file
|| file
== 0)
7453 dwarf2_debug_line_missing_file_complaint ();
7456 lh
->file_names
[file
- 1].included_p
= 1;
7457 if (!decode_for_pst_p
&& is_stmt
)
7459 if (last_subfile
!= current_subfile
)
7461 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7463 record_line (last_subfile
, 0, addr
);
7464 last_subfile
= current_subfile
;
7466 addr
= check_cu_functions (address
, cu
);
7467 addr
= gdbarch_addr_bits_remove (gdbarch
, addr
);
7468 record_line (current_subfile
, line
, addr
);
7473 case DW_LNS_advance_pc
:
7474 address
+= lh
->minimum_instruction_length
7475 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7476 line_ptr
+= bytes_read
;
7478 case DW_LNS_advance_line
:
7479 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
7480 line_ptr
+= bytes_read
;
7482 case DW_LNS_set_file
:
7484 /* The arrays lh->include_dirs and lh->file_names are
7485 0-based, but the directory and file name numbers in
7486 the statement program are 1-based. */
7487 struct file_entry
*fe
;
7490 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7491 line_ptr
+= bytes_read
;
7492 if (lh
->num_file_names
< file
|| file
== 0)
7493 dwarf2_debug_line_missing_file_complaint ();
7496 fe
= &lh
->file_names
[file
- 1];
7498 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7499 if (!decode_for_pst_p
)
7501 last_subfile
= current_subfile
;
7502 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7507 case DW_LNS_set_column
:
7508 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7509 line_ptr
+= bytes_read
;
7511 case DW_LNS_negate_stmt
:
7512 is_stmt
= (!is_stmt
);
7514 case DW_LNS_set_basic_block
:
7517 /* Add to the address register of the state machine the
7518 address increment value corresponding to special opcode
7519 255. I.e., this value is scaled by the minimum
7520 instruction length since special opcode 255 would have
7521 scaled the the increment. */
7522 case DW_LNS_const_add_pc
:
7523 address
+= (lh
->minimum_instruction_length
7524 * ((255 - lh
->opcode_base
) / lh
->line_range
));
7526 case DW_LNS_fixed_advance_pc
:
7527 address
+= read_2_bytes (abfd
, line_ptr
);
7532 /* Unknown standard opcode, ignore it. */
7535 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
7537 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
7538 line_ptr
+= bytes_read
;
7543 if (lh
->num_file_names
< file
|| file
== 0)
7544 dwarf2_debug_line_missing_file_complaint ();
7547 lh
->file_names
[file
- 1].included_p
= 1;
7548 if (!decode_for_pst_p
)
7550 addr
= gdbarch_addr_bits_remove (gdbarch
, address
);
7551 record_line (current_subfile
, 0, addr
);
7556 if (decode_for_pst_p
)
7560 /* Now that we're done scanning the Line Header Program, we can
7561 create the psymtab of each included file. */
7562 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
7563 if (lh
->file_names
[file_index
].included_p
== 1)
7565 const struct file_entry fe
= lh
->file_names
[file_index
];
7566 char *include_name
= fe
.name
;
7567 char *dir_name
= NULL
;
7568 char *pst_filename
= pst
->filename
;
7571 dir_name
= lh
->include_dirs
[fe
.dir_index
- 1];
7573 if (!IS_ABSOLUTE_PATH (include_name
) && dir_name
!= NULL
)
7575 include_name
= concat (dir_name
, SLASH_STRING
,
7576 include_name
, (char *)NULL
);
7577 make_cleanup (xfree
, include_name
);
7580 if (!IS_ABSOLUTE_PATH (pst_filename
) && pst
->dirname
!= NULL
)
7582 pst_filename
= concat (pst
->dirname
, SLASH_STRING
,
7583 pst_filename
, (char *)NULL
);
7584 make_cleanup (xfree
, pst_filename
);
7587 if (strcmp (include_name
, pst_filename
) != 0)
7588 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
7593 /* Make sure a symtab is created for every file, even files
7594 which contain only variables (i.e. no code with associated
7598 struct file_entry
*fe
;
7600 for (i
= 0; i
< lh
->num_file_names
; i
++)
7603 fe
= &lh
->file_names
[i
];
7605 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
7606 dwarf2_start_subfile (fe
->name
, dir
, comp_dir
);
7608 /* Skip the main file; we don't need it, and it must be
7609 allocated last, so that it will show up before the
7610 non-primary symtabs in the objfile's symtab list. */
7611 if (current_subfile
== first_subfile
)
7614 if (current_subfile
->symtab
== NULL
)
7615 current_subfile
->symtab
= allocate_symtab (current_subfile
->name
,
7617 fe
->symtab
= current_subfile
->symtab
;
7622 /* Start a subfile for DWARF. FILENAME is the name of the file and
7623 DIRNAME the name of the source directory which contains FILENAME
7624 or NULL if not known. COMP_DIR is the compilation directory for the
7625 linetable's compilation unit or NULL if not known.
7626 This routine tries to keep line numbers from identical absolute and
7627 relative file names in a common subfile.
7629 Using the `list' example from the GDB testsuite, which resides in
7630 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
7631 of /srcdir/list0.c yields the following debugging information for list0.c:
7633 DW_AT_name: /srcdir/list0.c
7634 DW_AT_comp_dir: /compdir
7635 files.files[0].name: list0.h
7636 files.files[0].dir: /srcdir
7637 files.files[1].name: list0.c
7638 files.files[1].dir: /srcdir
7640 The line number information for list0.c has to end up in a single
7641 subfile, so that `break /srcdir/list0.c:1' works as expected.
7642 start_subfile will ensure that this happens provided that we pass the
7643 concatenation of files.files[1].dir and files.files[1].name as the
7647 dwarf2_start_subfile (char *filename
, char *dirname
, char *comp_dir
)
7651 /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir).
7652 `start_symtab' will always pass the contents of DW_AT_comp_dir as
7653 second argument to start_subfile. To be consistent, we do the
7654 same here. In order not to lose the line information directory,
7655 we concatenate it to the filename when it makes sense.
7656 Note that the Dwarf3 standard says (speaking of filenames in line
7657 information): ``The directory index is ignored for file names
7658 that represent full path names''. Thus ignoring dirname in the
7659 `else' branch below isn't an issue. */
7661 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
7662 fullname
= concat (dirname
, SLASH_STRING
, filename
, (char *)NULL
);
7664 fullname
= filename
;
7666 start_subfile (fullname
, comp_dir
);
7668 if (fullname
!= filename
)
7673 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
7674 struct dwarf2_cu
*cu
)
7676 struct objfile
*objfile
= cu
->objfile
;
7677 struct comp_unit_head
*cu_header
= &cu
->header
;
7679 /* NOTE drow/2003-01-30: There used to be a comment and some special
7680 code here to turn a symbol with DW_AT_external and a
7681 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
7682 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
7683 with some versions of binutils) where shared libraries could have
7684 relocations against symbols in their debug information - the
7685 minimal symbol would have the right address, but the debug info
7686 would not. It's no longer necessary, because we will explicitly
7687 apply relocations when we read in the debug information now. */
7689 /* A DW_AT_location attribute with no contents indicates that a
7690 variable has been optimized away. */
7691 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
7693 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7697 /* Handle one degenerate form of location expression specially, to
7698 preserve GDB's previous behavior when section offsets are
7699 specified. If this is just a DW_OP_addr then mark this symbol
7702 if (attr_form_is_block (attr
)
7703 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
7704 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
7708 SYMBOL_VALUE_ADDRESS (sym
) =
7709 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
7710 SYMBOL_CLASS (sym
) = LOC_STATIC
;
7711 fixup_symbol_section (sym
, objfile
);
7712 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
7713 SYMBOL_SECTION (sym
));
7717 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
7718 expression evaluator, and use LOC_COMPUTED only when necessary
7719 (i.e. when the value of a register or memory location is
7720 referenced, or a thread-local block, etc.). Then again, it might
7721 not be worthwhile. I'm assuming that it isn't unless performance
7722 or memory numbers show me otherwise. */
7724 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
7725 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
7728 /* Given a pointer to a DWARF information entry, figure out if we need
7729 to make a symbol table entry for it, and if so, create a new entry
7730 and return a pointer to it.
7731 If TYPE is NULL, determine symbol type from the die, otherwise
7732 used the passed type. */
7734 static struct symbol
*
7735 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
7737 struct objfile
*objfile
= cu
->objfile
;
7738 struct symbol
*sym
= NULL
;
7740 struct attribute
*attr
= NULL
;
7741 struct attribute
*attr2
= NULL
;
7743 int inlined_func
= (die
->tag
== DW_TAG_inlined_subroutine
);
7745 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
7747 if (die
->tag
!= DW_TAG_namespace
)
7748 name
= dwarf2_linkage_name (die
, cu
);
7750 name
= TYPE_NAME (type
);
7754 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
7755 sizeof (struct symbol
));
7756 OBJSTAT (objfile
, n_syms
++);
7757 memset (sym
, 0, sizeof (struct symbol
));
7759 /* Cache this symbol's name and the name's demangled form (if any). */
7760 SYMBOL_LANGUAGE (sym
) = cu
->language
;
7761 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
7763 /* Default assumptions.
7764 Use the passed type or decode it from the die. */
7765 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7766 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
7768 SYMBOL_TYPE (sym
) = type
;
7770 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
7771 attr
= dwarf2_attr (die
,
7772 inlined_func
? DW_AT_call_line
: DW_AT_decl_line
,
7776 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
7779 attr
= dwarf2_attr (die
,
7780 inlined_func
? DW_AT_call_file
: DW_AT_decl_file
,
7784 int file_index
= DW_UNSND (attr
);
7785 if (cu
->line_header
== NULL
7786 || file_index
> cu
->line_header
->num_file_names
)
7787 complaint (&symfile_complaints
,
7788 _("file index out of range"));
7789 else if (file_index
> 0)
7791 struct file_entry
*fe
;
7792 fe
= &cu
->line_header
->file_names
[file_index
- 1];
7793 SYMBOL_SYMTAB (sym
) = fe
->symtab
;
7800 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
7803 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
7805 SYMBOL_CLASS (sym
) = LOC_LABEL
;
7807 case DW_TAG_subprogram
:
7808 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7810 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7811 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7812 if ((attr2
&& (DW_UNSND (attr2
) != 0))
7813 || cu
->language
== language_ada
)
7815 /* Subprograms marked external are stored as a global symbol.
7816 Ada subprograms, whether marked external or not, are always
7817 stored as a global symbol, because we want to be able to
7818 access them globally. For instance, we want to be able
7819 to break on a nested subprogram without having to
7820 specify the context. */
7821 add_symbol_to_list (sym
, &global_symbols
);
7825 add_symbol_to_list (sym
, cu
->list_in_scope
);
7828 case DW_TAG_inlined_subroutine
:
7829 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
7831 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
7832 SYMBOL_INLINED (sym
) = 1;
7833 /* Do not add the symbol to any lists. It will be found via
7834 BLOCK_FUNCTION from the blockvector. */
7836 case DW_TAG_variable
:
7837 /* Compilation with minimal debug info may result in variables
7838 with missing type entries. Change the misleading `void' type
7839 to something sensible. */
7840 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
7842 = objfile_type (objfile
)->nodebug_data_symbol
;
7844 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7847 dwarf2_const_value (attr
, sym
, cu
);
7848 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7849 if (attr2
&& (DW_UNSND (attr2
) != 0))
7850 add_symbol_to_list (sym
, &global_symbols
);
7852 add_symbol_to_list (sym
, cu
->list_in_scope
);
7855 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7858 var_decode_location (attr
, sym
, cu
);
7859 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7860 if (attr2
&& (DW_UNSND (attr2
) != 0))
7861 add_symbol_to_list (sym
, &global_symbols
);
7863 add_symbol_to_list (sym
, cu
->list_in_scope
);
7867 /* We do not know the address of this symbol.
7868 If it is an external symbol and we have type information
7869 for it, enter the symbol as a LOC_UNRESOLVED symbol.
7870 The address of the variable will then be determined from
7871 the minimal symbol table whenever the variable is
7873 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
7874 if (attr2
&& (DW_UNSND (attr2
) != 0)
7875 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
7877 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
7878 add_symbol_to_list (sym
, cu
->list_in_scope
);
7880 else if (!die_is_declaration (die
, cu
))
7882 /* Use the default LOC_OPTIMIZED_OUT class. */
7883 gdb_assert (SYMBOL_CLASS (sym
) == LOC_OPTIMIZED_OUT
);
7884 add_symbol_to_list (sym
, cu
->list_in_scope
);
7888 case DW_TAG_formal_parameter
:
7889 /* If we are inside a function, mark this as an argument. If
7890 not, we might be looking at an argument to an inlined function
7891 when we do not have enough information to show inlined frames;
7892 pretend it's a local variable in that case so that the user can
7894 if (context_stack_depth
> 0
7895 && context_stack
[context_stack_depth
- 1].name
!= NULL
)
7896 SYMBOL_IS_ARGUMENT (sym
) = 1;
7897 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
7900 var_decode_location (attr
, sym
, cu
);
7902 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7905 dwarf2_const_value (attr
, sym
, cu
);
7907 add_symbol_to_list (sym
, cu
->list_in_scope
);
7909 case DW_TAG_unspecified_parameters
:
7910 /* From varargs functions; gdb doesn't seem to have any
7911 interest in this information, so just ignore it for now.
7914 case DW_TAG_class_type
:
7915 case DW_TAG_interface_type
:
7916 case DW_TAG_structure_type
:
7917 case DW_TAG_union_type
:
7918 case DW_TAG_set_type
:
7919 case DW_TAG_enumeration_type
:
7920 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7921 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
7923 /* Make sure that the symbol includes appropriate enclosing
7924 classes/namespaces in its name. These are calculated in
7925 read_structure_type, and the correct name is saved in
7928 if (cu
->language
== language_cplus
7929 || cu
->language
== language_java
)
7931 struct type
*type
= SYMBOL_TYPE (sym
);
7933 if (TYPE_TAG_NAME (type
) != NULL
)
7935 /* FIXME: carlton/2003-11-10: Should this use
7936 SYMBOL_SET_NAMES instead? (The same problem also
7937 arises further down in this function.) */
7938 /* The type's name is already allocated along with
7939 this objfile, so we don't need to duplicate it
7941 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
7946 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
7947 really ever be static objects: otherwise, if you try
7948 to, say, break of a class's method and you're in a file
7949 which doesn't mention that class, it won't work unless
7950 the check for all static symbols in lookup_symbol_aux
7951 saves you. See the OtherFileClass tests in
7952 gdb.c++/namespace.exp. */
7954 struct pending
**list_to_add
;
7956 list_to_add
= (cu
->list_in_scope
== &file_symbols
7957 && (cu
->language
== language_cplus
7958 || cu
->language
== language_java
)
7959 ? &global_symbols
: cu
->list_in_scope
);
7961 add_symbol_to_list (sym
, list_to_add
);
7963 /* The semantics of C++ state that "struct foo { ... }" also
7964 defines a typedef for "foo". A Java class declaration also
7965 defines a typedef for the class. */
7966 if (cu
->language
== language_cplus
7967 || cu
->language
== language_java
7968 || cu
->language
== language_ada
)
7970 /* The symbol's name is already allocated along with
7971 this objfile, so we don't need to duplicate it for
7973 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
7974 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_SEARCH_NAME (sym
);
7978 case DW_TAG_typedef
:
7979 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7980 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7981 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7982 add_symbol_to_list (sym
, cu
->list_in_scope
);
7984 case DW_TAG_base_type
:
7985 case DW_TAG_subrange_type
:
7986 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
7987 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
7988 add_symbol_to_list (sym
, cu
->list_in_scope
);
7990 case DW_TAG_enumerator
:
7991 SYMBOL_LINKAGE_NAME (sym
) = (char *) dwarf2_full_name (die
, cu
);
7992 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
7995 dwarf2_const_value (attr
, sym
, cu
);
7998 /* NOTE: carlton/2003-11-10: See comment above in the
7999 DW_TAG_class_type, etc. block. */
8001 struct pending
**list_to_add
;
8003 list_to_add
= (cu
->list_in_scope
== &file_symbols
8004 && (cu
->language
== language_cplus
8005 || cu
->language
== language_java
)
8006 ? &global_symbols
: cu
->list_in_scope
);
8008 add_symbol_to_list (sym
, list_to_add
);
8011 case DW_TAG_namespace
:
8012 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
8013 add_symbol_to_list (sym
, &global_symbols
);
8016 /* Not a tag we recognize. Hopefully we aren't processing
8017 trash data, but since we must specifically ignore things
8018 we don't recognize, there is nothing else we should do at
8020 complaint (&symfile_complaints
, _("unsupported tag: '%s'"),
8021 dwarf_tag_name (die
->tag
));
8025 /* For the benefit of old versions of GCC, check for anonymous
8026 namespaces based on the demangled name. */
8027 if (!processing_has_namespace_info
8028 && cu
->language
== language_cplus
8029 && dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
) != NULL
)
8030 cp_scan_for_anonymous_namespaces (sym
);
8035 /* Copy constant value from an attribute to a symbol. */
8038 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
8039 struct dwarf2_cu
*cu
)
8041 struct objfile
*objfile
= cu
->objfile
;
8042 struct comp_unit_head
*cu_header
= &cu
->header
;
8043 struct dwarf_block
*blk
;
8048 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
8049 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8050 cu_header
->addr_size
,
8051 TYPE_LENGTH (SYMBOL_TYPE
8053 SYMBOL_VALUE_BYTES (sym
) =
8054 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
8055 /* NOTE: cagney/2003-05-09: In-lined store_address call with
8056 it's body - store_unsigned_integer. */
8057 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
8059 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8061 case DW_FORM_string
:
8063 /* DW_STRING is already allocated on the obstack, point directly
8065 SYMBOL_VALUE_BYTES (sym
) = (gdb_byte
*) DW_STRING (attr
);
8066 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8068 case DW_FORM_block1
:
8069 case DW_FORM_block2
:
8070 case DW_FORM_block4
:
8072 blk
= DW_BLOCK (attr
);
8073 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
8074 dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym
),
8076 TYPE_LENGTH (SYMBOL_TYPE
8078 SYMBOL_VALUE_BYTES (sym
) =
8079 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
8080 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
8081 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
8084 /* The DW_AT_const_value attributes are supposed to carry the
8085 symbol's value "represented as it would be on the target
8086 architecture." By the time we get here, it's already been
8087 converted to host endianness, so we just need to sign- or
8088 zero-extend it as appropriate. */
8090 dwarf2_const_value_data (attr
, sym
, 8);
8093 dwarf2_const_value_data (attr
, sym
, 16);
8096 dwarf2_const_value_data (attr
, sym
, 32);
8099 dwarf2_const_value_data (attr
, sym
, 64);
8103 SYMBOL_VALUE (sym
) = DW_SND (attr
);
8104 SYMBOL_CLASS (sym
) = LOC_CONST
;
8108 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
8109 SYMBOL_CLASS (sym
) = LOC_CONST
;
8113 complaint (&symfile_complaints
,
8114 _("unsupported const value attribute form: '%s'"),
8115 dwarf_form_name (attr
->form
));
8116 SYMBOL_VALUE (sym
) = 0;
8117 SYMBOL_CLASS (sym
) = LOC_CONST
;
8123 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
8124 or zero-extend it as appropriate for the symbol's type. */
8126 dwarf2_const_value_data (struct attribute
*attr
,
8130 LONGEST l
= DW_UNSND (attr
);
8132 if (bits
< sizeof (l
) * 8)
8134 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
8135 l
&= ((LONGEST
) 1 << bits
) - 1;
8137 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
8140 SYMBOL_VALUE (sym
) = l
;
8141 SYMBOL_CLASS (sym
) = LOC_CONST
;
8145 /* Return the type of the die in question using its DW_AT_type attribute. */
8147 static struct type
*
8148 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8151 struct attribute
*type_attr
;
8152 struct die_info
*type_die
;
8154 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
8157 /* A missing DW_AT_type represents a void type. */
8158 return objfile_type (cu
->objfile
)->builtin_void
;
8161 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8163 type
= tag_type_to_type (type_die
, cu
);
8166 dump_die_for_error (type_die
);
8167 error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"),
8173 /* Return the containing type of the die in question using its
8174 DW_AT_containing_type attribute. */
8176 static struct type
*
8177 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8179 struct type
*type
= NULL
;
8180 struct attribute
*type_attr
;
8181 struct die_info
*type_die
= NULL
;
8183 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
8186 type_die
= follow_die_ref (die
, type_attr
, &cu
);
8187 type
= tag_type_to_type (type_die
, cu
);
8192 dump_die_for_error (type_die
);
8193 error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"),
8199 static struct type
*
8200 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
8202 struct type
*this_type
;
8204 this_type
= read_type_die (die
, cu
);
8207 dump_die_for_error (die
);
8208 error (_("Dwarf Error: Cannot find type of die [in module %s]"),
8214 static struct type
*
8215 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
8217 struct type
*this_type
;
8219 this_type
= get_die_type (die
, cu
);
8225 case DW_TAG_class_type
:
8226 case DW_TAG_interface_type
:
8227 case DW_TAG_structure_type
:
8228 case DW_TAG_union_type
:
8229 this_type
= read_structure_type (die
, cu
);
8231 case DW_TAG_enumeration_type
:
8232 this_type
= read_enumeration_type (die
, cu
);
8234 case DW_TAG_subprogram
:
8235 case DW_TAG_subroutine_type
:
8236 case DW_TAG_inlined_subroutine
:
8237 this_type
= read_subroutine_type (die
, cu
);
8239 case DW_TAG_array_type
:
8240 this_type
= read_array_type (die
, cu
);
8242 case DW_TAG_set_type
:
8243 this_type
= read_set_type (die
, cu
);
8245 case DW_TAG_pointer_type
:
8246 this_type
= read_tag_pointer_type (die
, cu
);
8248 case DW_TAG_ptr_to_member_type
:
8249 this_type
= read_tag_ptr_to_member_type (die
, cu
);
8251 case DW_TAG_reference_type
:
8252 this_type
= read_tag_reference_type (die
, cu
);
8254 case DW_TAG_const_type
:
8255 this_type
= read_tag_const_type (die
, cu
);
8257 case DW_TAG_volatile_type
:
8258 this_type
= read_tag_volatile_type (die
, cu
);
8260 case DW_TAG_string_type
:
8261 this_type
= read_tag_string_type (die
, cu
);
8263 case DW_TAG_typedef
:
8264 this_type
= read_typedef (die
, cu
);
8266 case DW_TAG_subrange_type
:
8267 this_type
= read_subrange_type (die
, cu
);
8269 case DW_TAG_base_type
:
8270 this_type
= read_base_type (die
, cu
);
8272 case DW_TAG_unspecified_type
:
8273 this_type
= read_unspecified_type (die
, cu
);
8275 case DW_TAG_namespace
:
8276 this_type
= read_namespace_type (die
, cu
);
8279 complaint (&symfile_complaints
, _("unexpected tag in read_type_die: '%s'"),
8280 dwarf_tag_name (die
->tag
));
8287 /* Return the name of the namespace/class that DIE is defined within,
8288 or "" if we can't tell. The caller should not xfree the result.
8290 For example, if we're within the method foo() in the following
8300 then determine_prefix on foo's die will return "N::C". */
8303 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
8305 struct die_info
*parent
, *spec_die
;
8306 struct dwarf2_cu
*spec_cu
;
8307 struct type
*parent_type
;
8309 if (cu
->language
!= language_cplus
8310 && cu
->language
!= language_java
)
8313 /* We have to be careful in the presence of DW_AT_specification.
8314 For example, with GCC 3.4, given the code
8318 // Definition of N::foo.
8322 then we'll have a tree of DIEs like this:
8324 1: DW_TAG_compile_unit
8325 2: DW_TAG_namespace // N
8326 3: DW_TAG_subprogram // declaration of N::foo
8327 4: DW_TAG_subprogram // definition of N::foo
8328 DW_AT_specification // refers to die #3
8330 Thus, when processing die #4, we have to pretend that we're in
8331 the context of its DW_AT_specification, namely the contex of die
8334 spec_die
= die_specification (die
, &spec_cu
);
8335 if (spec_die
== NULL
)
8336 parent
= die
->parent
;
8339 parent
= spec_die
->parent
;
8346 switch (parent
->tag
)
8348 case DW_TAG_namespace
:
8349 parent_type
= read_type_die (parent
, cu
);
8350 /* We give a name to even anonymous namespaces. */
8351 return TYPE_TAG_NAME (parent_type
);
8352 case DW_TAG_class_type
:
8353 case DW_TAG_interface_type
:
8354 case DW_TAG_structure_type
:
8355 case DW_TAG_union_type
:
8356 parent_type
= read_type_die (parent
, cu
);
8357 if (TYPE_TAG_NAME (parent_type
) != NULL
)
8358 return TYPE_TAG_NAME (parent_type
);
8360 /* An anonymous structure is only allowed non-static data
8361 members; no typedefs, no member functions, et cetera.
8362 So it does not need a prefix. */
8365 return determine_prefix (parent
, cu
);
8369 /* Return a newly-allocated string formed by concatenating PREFIX and
8370 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
8371 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
8372 perform an obconcat, otherwise allocate storage for the result. The CU argument
8373 is used to determine the language and hence, the appropriate separator. */
8375 #define MAX_SEP_LEN 2 /* sizeof ("::") */
8378 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
8379 struct dwarf2_cu
*cu
)
8383 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
8385 else if (cu
->language
== language_java
)
8397 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
8398 strcpy (retval
, prefix
);
8399 strcat (retval
, sep
);
8400 strcat (retval
, suffix
);
8405 /* We have an obstack. */
8406 return obconcat (obs
, prefix
, sep
, suffix
);
8410 /* Return sibling of die, NULL if no sibling. */
8412 static struct die_info
*
8413 sibling_die (struct die_info
*die
)
8415 return die
->sibling
;
8418 /* Get linkage name of a die, return NULL if not found. */
8421 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8423 struct attribute
*attr
;
8425 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
8426 if (attr
&& DW_STRING (attr
))
8427 return DW_STRING (attr
);
8428 return dwarf2_name (die
, cu
);
8431 /* Get name of a die, return NULL if not found. */
8434 dwarf2_canonicalize_name (char *name
, struct dwarf2_cu
*cu
,
8435 struct obstack
*obstack
)
8437 if (name
&& cu
->language
== language_cplus
)
8439 char *canon_name
= cp_canonicalize_string (name
);
8441 if (canon_name
!= NULL
)
8443 if (strcmp (canon_name
, name
) != 0)
8444 name
= obsavestring (canon_name
, strlen (canon_name
),
8453 /* Get name of a die, return NULL if not found. */
8456 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
8458 struct attribute
*attr
;
8460 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
8461 if (!attr
|| !DW_STRING (attr
))
8466 case DW_TAG_compile_unit
:
8467 /* Compilation units have a DW_AT_name that is a filename, not
8468 a source language identifier. */
8469 case DW_TAG_enumeration_type
:
8470 case DW_TAG_enumerator
:
8471 /* These tags always have simple identifiers already; no need
8472 to canonicalize them. */
8473 return DW_STRING (attr
);
8475 if (attr
->form
!= GDB_FORM_cached_string
)
8478 = dwarf2_canonicalize_name (DW_STRING (attr
), cu
,
8479 &cu
->objfile
->objfile_obstack
);
8480 attr
->form
= GDB_FORM_cached_string
;
8482 return DW_STRING (attr
);
8486 /* Return the die that this die in an extension of, or NULL if there
8487 is none. *EXT_CU is the CU containing DIE on input, and the CU
8488 containing the return value on output. */
8490 static struct die_info
*
8491 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
**ext_cu
)
8493 struct attribute
*attr
;
8495 attr
= dwarf2_attr (die
, DW_AT_extension
, *ext_cu
);
8499 return follow_die_ref (die
, attr
, ext_cu
);
8502 /* Convert a DIE tag into its string name. */
8505 dwarf_tag_name (unsigned tag
)
8509 case DW_TAG_padding
:
8510 return "DW_TAG_padding";
8511 case DW_TAG_array_type
:
8512 return "DW_TAG_array_type";
8513 case DW_TAG_class_type
:
8514 return "DW_TAG_class_type";
8515 case DW_TAG_entry_point
:
8516 return "DW_TAG_entry_point";
8517 case DW_TAG_enumeration_type
:
8518 return "DW_TAG_enumeration_type";
8519 case DW_TAG_formal_parameter
:
8520 return "DW_TAG_formal_parameter";
8521 case DW_TAG_imported_declaration
:
8522 return "DW_TAG_imported_declaration";
8524 return "DW_TAG_label";
8525 case DW_TAG_lexical_block
:
8526 return "DW_TAG_lexical_block";
8528 return "DW_TAG_member";
8529 case DW_TAG_pointer_type
:
8530 return "DW_TAG_pointer_type";
8531 case DW_TAG_reference_type
:
8532 return "DW_TAG_reference_type";
8533 case DW_TAG_compile_unit
:
8534 return "DW_TAG_compile_unit";
8535 case DW_TAG_string_type
:
8536 return "DW_TAG_string_type";
8537 case DW_TAG_structure_type
:
8538 return "DW_TAG_structure_type";
8539 case DW_TAG_subroutine_type
:
8540 return "DW_TAG_subroutine_type";
8541 case DW_TAG_typedef
:
8542 return "DW_TAG_typedef";
8543 case DW_TAG_union_type
:
8544 return "DW_TAG_union_type";
8545 case DW_TAG_unspecified_parameters
:
8546 return "DW_TAG_unspecified_parameters";
8547 case DW_TAG_variant
:
8548 return "DW_TAG_variant";
8549 case DW_TAG_common_block
:
8550 return "DW_TAG_common_block";
8551 case DW_TAG_common_inclusion
:
8552 return "DW_TAG_common_inclusion";
8553 case DW_TAG_inheritance
:
8554 return "DW_TAG_inheritance";
8555 case DW_TAG_inlined_subroutine
:
8556 return "DW_TAG_inlined_subroutine";
8558 return "DW_TAG_module";
8559 case DW_TAG_ptr_to_member_type
:
8560 return "DW_TAG_ptr_to_member_type";
8561 case DW_TAG_set_type
:
8562 return "DW_TAG_set_type";
8563 case DW_TAG_subrange_type
:
8564 return "DW_TAG_subrange_type";
8565 case DW_TAG_with_stmt
:
8566 return "DW_TAG_with_stmt";
8567 case DW_TAG_access_declaration
:
8568 return "DW_TAG_access_declaration";
8569 case DW_TAG_base_type
:
8570 return "DW_TAG_base_type";
8571 case DW_TAG_catch_block
:
8572 return "DW_TAG_catch_block";
8573 case DW_TAG_const_type
:
8574 return "DW_TAG_const_type";
8575 case DW_TAG_constant
:
8576 return "DW_TAG_constant";
8577 case DW_TAG_enumerator
:
8578 return "DW_TAG_enumerator";
8579 case DW_TAG_file_type
:
8580 return "DW_TAG_file_type";
8582 return "DW_TAG_friend";
8583 case DW_TAG_namelist
:
8584 return "DW_TAG_namelist";
8585 case DW_TAG_namelist_item
:
8586 return "DW_TAG_namelist_item";
8587 case DW_TAG_packed_type
:
8588 return "DW_TAG_packed_type";
8589 case DW_TAG_subprogram
:
8590 return "DW_TAG_subprogram";
8591 case DW_TAG_template_type_param
:
8592 return "DW_TAG_template_type_param";
8593 case DW_TAG_template_value_param
:
8594 return "DW_TAG_template_value_param";
8595 case DW_TAG_thrown_type
:
8596 return "DW_TAG_thrown_type";
8597 case DW_TAG_try_block
:
8598 return "DW_TAG_try_block";
8599 case DW_TAG_variant_part
:
8600 return "DW_TAG_variant_part";
8601 case DW_TAG_variable
:
8602 return "DW_TAG_variable";
8603 case DW_TAG_volatile_type
:
8604 return "DW_TAG_volatile_type";
8605 case DW_TAG_dwarf_procedure
:
8606 return "DW_TAG_dwarf_procedure";
8607 case DW_TAG_restrict_type
:
8608 return "DW_TAG_restrict_type";
8609 case DW_TAG_interface_type
:
8610 return "DW_TAG_interface_type";
8611 case DW_TAG_namespace
:
8612 return "DW_TAG_namespace";
8613 case DW_TAG_imported_module
:
8614 return "DW_TAG_imported_module";
8615 case DW_TAG_unspecified_type
:
8616 return "DW_TAG_unspecified_type";
8617 case DW_TAG_partial_unit
:
8618 return "DW_TAG_partial_unit";
8619 case DW_TAG_imported_unit
:
8620 return "DW_TAG_imported_unit";
8621 case DW_TAG_condition
:
8622 return "DW_TAG_condition";
8623 case DW_TAG_shared_type
:
8624 return "DW_TAG_shared_type";
8625 case DW_TAG_MIPS_loop
:
8626 return "DW_TAG_MIPS_loop";
8627 case DW_TAG_HP_array_descriptor
:
8628 return "DW_TAG_HP_array_descriptor";
8629 case DW_TAG_format_label
:
8630 return "DW_TAG_format_label";
8631 case DW_TAG_function_template
:
8632 return "DW_TAG_function_template";
8633 case DW_TAG_class_template
:
8634 return "DW_TAG_class_template";
8635 case DW_TAG_GNU_BINCL
:
8636 return "DW_TAG_GNU_BINCL";
8637 case DW_TAG_GNU_EINCL
:
8638 return "DW_TAG_GNU_EINCL";
8639 case DW_TAG_upc_shared_type
:
8640 return "DW_TAG_upc_shared_type";
8641 case DW_TAG_upc_strict_type
:
8642 return "DW_TAG_upc_strict_type";
8643 case DW_TAG_upc_relaxed_type
:
8644 return "DW_TAG_upc_relaxed_type";
8645 case DW_TAG_PGI_kanji_type
:
8646 return "DW_TAG_PGI_kanji_type";
8647 case DW_TAG_PGI_interface_block
:
8648 return "DW_TAG_PGI_interface_block";
8650 return "DW_TAG_<unknown>";
8654 /* Convert a DWARF attribute code into its string name. */
8657 dwarf_attr_name (unsigned attr
)
8662 return "DW_AT_sibling";
8663 case DW_AT_location
:
8664 return "DW_AT_location";
8666 return "DW_AT_name";
8667 case DW_AT_ordering
:
8668 return "DW_AT_ordering";
8669 case DW_AT_subscr_data
:
8670 return "DW_AT_subscr_data";
8671 case DW_AT_byte_size
:
8672 return "DW_AT_byte_size";
8673 case DW_AT_bit_offset
:
8674 return "DW_AT_bit_offset";
8675 case DW_AT_bit_size
:
8676 return "DW_AT_bit_size";
8677 case DW_AT_element_list
:
8678 return "DW_AT_element_list";
8679 case DW_AT_stmt_list
:
8680 return "DW_AT_stmt_list";
8682 return "DW_AT_low_pc";
8684 return "DW_AT_high_pc";
8685 case DW_AT_language
:
8686 return "DW_AT_language";
8688 return "DW_AT_member";
8690 return "DW_AT_discr";
8691 case DW_AT_discr_value
:
8692 return "DW_AT_discr_value";
8693 case DW_AT_visibility
:
8694 return "DW_AT_visibility";
8696 return "DW_AT_import";
8697 case DW_AT_string_length
:
8698 return "DW_AT_string_length";
8699 case DW_AT_common_reference
:
8700 return "DW_AT_common_reference";
8701 case DW_AT_comp_dir
:
8702 return "DW_AT_comp_dir";
8703 case DW_AT_const_value
:
8704 return "DW_AT_const_value";
8705 case DW_AT_containing_type
:
8706 return "DW_AT_containing_type";
8707 case DW_AT_default_value
:
8708 return "DW_AT_default_value";
8710 return "DW_AT_inline";
8711 case DW_AT_is_optional
:
8712 return "DW_AT_is_optional";
8713 case DW_AT_lower_bound
:
8714 return "DW_AT_lower_bound";
8715 case DW_AT_producer
:
8716 return "DW_AT_producer";
8717 case DW_AT_prototyped
:
8718 return "DW_AT_prototyped";
8719 case DW_AT_return_addr
:
8720 return "DW_AT_return_addr";
8721 case DW_AT_start_scope
:
8722 return "DW_AT_start_scope";
8723 case DW_AT_bit_stride
:
8724 return "DW_AT_bit_stride";
8725 case DW_AT_upper_bound
:
8726 return "DW_AT_upper_bound";
8727 case DW_AT_abstract_origin
:
8728 return "DW_AT_abstract_origin";
8729 case DW_AT_accessibility
:
8730 return "DW_AT_accessibility";
8731 case DW_AT_address_class
:
8732 return "DW_AT_address_class";
8733 case DW_AT_artificial
:
8734 return "DW_AT_artificial";
8735 case DW_AT_base_types
:
8736 return "DW_AT_base_types";
8737 case DW_AT_calling_convention
:
8738 return "DW_AT_calling_convention";
8740 return "DW_AT_count";
8741 case DW_AT_data_member_location
:
8742 return "DW_AT_data_member_location";
8743 case DW_AT_decl_column
:
8744 return "DW_AT_decl_column";
8745 case DW_AT_decl_file
:
8746 return "DW_AT_decl_file";
8747 case DW_AT_decl_line
:
8748 return "DW_AT_decl_line";
8749 case DW_AT_declaration
:
8750 return "DW_AT_declaration";
8751 case DW_AT_discr_list
:
8752 return "DW_AT_discr_list";
8753 case DW_AT_encoding
:
8754 return "DW_AT_encoding";
8755 case DW_AT_external
:
8756 return "DW_AT_external";
8757 case DW_AT_frame_base
:
8758 return "DW_AT_frame_base";
8760 return "DW_AT_friend";
8761 case DW_AT_identifier_case
:
8762 return "DW_AT_identifier_case";
8763 case DW_AT_macro_info
:
8764 return "DW_AT_macro_info";
8765 case DW_AT_namelist_items
:
8766 return "DW_AT_namelist_items";
8767 case DW_AT_priority
:
8768 return "DW_AT_priority";
8770 return "DW_AT_segment";
8771 case DW_AT_specification
:
8772 return "DW_AT_specification";
8773 case DW_AT_static_link
:
8774 return "DW_AT_static_link";
8776 return "DW_AT_type";
8777 case DW_AT_use_location
:
8778 return "DW_AT_use_location";
8779 case DW_AT_variable_parameter
:
8780 return "DW_AT_variable_parameter";
8781 case DW_AT_virtuality
:
8782 return "DW_AT_virtuality";
8783 case DW_AT_vtable_elem_location
:
8784 return "DW_AT_vtable_elem_location";
8785 /* DWARF 3 values. */
8786 case DW_AT_allocated
:
8787 return "DW_AT_allocated";
8788 case DW_AT_associated
:
8789 return "DW_AT_associated";
8790 case DW_AT_data_location
:
8791 return "DW_AT_data_location";
8792 case DW_AT_byte_stride
:
8793 return "DW_AT_byte_stride";
8794 case DW_AT_entry_pc
:
8795 return "DW_AT_entry_pc";
8796 case DW_AT_use_UTF8
:
8797 return "DW_AT_use_UTF8";
8798 case DW_AT_extension
:
8799 return "DW_AT_extension";
8801 return "DW_AT_ranges";
8802 case DW_AT_trampoline
:
8803 return "DW_AT_trampoline";
8804 case DW_AT_call_column
:
8805 return "DW_AT_call_column";
8806 case DW_AT_call_file
:
8807 return "DW_AT_call_file";
8808 case DW_AT_call_line
:
8809 return "DW_AT_call_line";
8810 case DW_AT_description
:
8811 return "DW_AT_description";
8812 case DW_AT_binary_scale
:
8813 return "DW_AT_binary_scale";
8814 case DW_AT_decimal_scale
:
8815 return "DW_AT_decimal_scale";
8817 return "DW_AT_small";
8818 case DW_AT_decimal_sign
:
8819 return "DW_AT_decimal_sign";
8820 case DW_AT_digit_count
:
8821 return "DW_AT_digit_count";
8822 case DW_AT_picture_string
:
8823 return "DW_AT_picture_string";
8825 return "DW_AT_mutable";
8826 case DW_AT_threads_scaled
:
8827 return "DW_AT_threads_scaled";
8828 case DW_AT_explicit
:
8829 return "DW_AT_explicit";
8830 case DW_AT_object_pointer
:
8831 return "DW_AT_object_pointer";
8832 case DW_AT_endianity
:
8833 return "DW_AT_endianity";
8834 case DW_AT_elemental
:
8835 return "DW_AT_elemental";
8837 return "DW_AT_pure";
8838 case DW_AT_recursive
:
8839 return "DW_AT_recursive";
8840 /* SGI/MIPS extensions. */
8841 #ifdef MIPS /* collides with DW_AT_HP_block_index */
8842 case DW_AT_MIPS_fde
:
8843 return "DW_AT_MIPS_fde";
8845 case DW_AT_MIPS_loop_begin
:
8846 return "DW_AT_MIPS_loop_begin";
8847 case DW_AT_MIPS_tail_loop_begin
:
8848 return "DW_AT_MIPS_tail_loop_begin";
8849 case DW_AT_MIPS_epilog_begin
:
8850 return "DW_AT_MIPS_epilog_begin";
8851 case DW_AT_MIPS_loop_unroll_factor
:
8852 return "DW_AT_MIPS_loop_unroll_factor";
8853 case DW_AT_MIPS_software_pipeline_depth
:
8854 return "DW_AT_MIPS_software_pipeline_depth";
8855 case DW_AT_MIPS_linkage_name
:
8856 return "DW_AT_MIPS_linkage_name";
8857 case DW_AT_MIPS_stride
:
8858 return "DW_AT_MIPS_stride";
8859 case DW_AT_MIPS_abstract_name
:
8860 return "DW_AT_MIPS_abstract_name";
8861 case DW_AT_MIPS_clone_origin
:
8862 return "DW_AT_MIPS_clone_origin";
8863 case DW_AT_MIPS_has_inlines
:
8864 return "DW_AT_MIPS_has_inlines";
8865 /* HP extensions. */
8866 #ifndef MIPS /* collides with DW_AT_MIPS_fde */
8867 case DW_AT_HP_block_index
:
8868 return "DW_AT_HP_block_index";
8870 case DW_AT_HP_unmodifiable
:
8871 return "DW_AT_HP_unmodifiable";
8872 case DW_AT_HP_actuals_stmt_list
:
8873 return "DW_AT_HP_actuals_stmt_list";
8874 case DW_AT_HP_proc_per_section
:
8875 return "DW_AT_HP_proc_per_section";
8876 case DW_AT_HP_raw_data_ptr
:
8877 return "DW_AT_HP_raw_data_ptr";
8878 case DW_AT_HP_pass_by_reference
:
8879 return "DW_AT_HP_pass_by_reference";
8880 case DW_AT_HP_opt_level
:
8881 return "DW_AT_HP_opt_level";
8882 case DW_AT_HP_prof_version_id
:
8883 return "DW_AT_HP_prof_version_id";
8884 case DW_AT_HP_opt_flags
:
8885 return "DW_AT_HP_opt_flags";
8886 case DW_AT_HP_cold_region_low_pc
:
8887 return "DW_AT_HP_cold_region_low_pc";
8888 case DW_AT_HP_cold_region_high_pc
:
8889 return "DW_AT_HP_cold_region_high_pc";
8890 case DW_AT_HP_all_variables_modifiable
:
8891 return "DW_AT_HP_all_variables_modifiable";
8892 case DW_AT_HP_linkage_name
:
8893 return "DW_AT_HP_linkage_name";
8894 case DW_AT_HP_prof_flags
:
8895 return "DW_AT_HP_prof_flags";
8896 /* GNU extensions. */
8897 case DW_AT_sf_names
:
8898 return "DW_AT_sf_names";
8899 case DW_AT_src_info
:
8900 return "DW_AT_src_info";
8901 case DW_AT_mac_info
:
8902 return "DW_AT_mac_info";
8903 case DW_AT_src_coords
:
8904 return "DW_AT_src_coords";
8905 case DW_AT_body_begin
:
8906 return "DW_AT_body_begin";
8907 case DW_AT_body_end
:
8908 return "DW_AT_body_end";
8909 case DW_AT_GNU_vector
:
8910 return "DW_AT_GNU_vector";
8911 /* VMS extensions. */
8912 case DW_AT_VMS_rtnbeg_pd_address
:
8913 return "DW_AT_VMS_rtnbeg_pd_address";
8914 /* UPC extension. */
8915 case DW_AT_upc_threads_scaled
:
8916 return "DW_AT_upc_threads_scaled";
8917 /* PGI (STMicroelectronics) extensions. */
8918 case DW_AT_PGI_lbase
:
8919 return "DW_AT_PGI_lbase";
8920 case DW_AT_PGI_soffset
:
8921 return "DW_AT_PGI_soffset";
8922 case DW_AT_PGI_lstride
:
8923 return "DW_AT_PGI_lstride";
8925 return "DW_AT_<unknown>";
8929 /* Convert a DWARF value form code into its string name. */
8932 dwarf_form_name (unsigned form
)
8937 return "DW_FORM_addr";
8938 case DW_FORM_block2
:
8939 return "DW_FORM_block2";
8940 case DW_FORM_block4
:
8941 return "DW_FORM_block4";
8943 return "DW_FORM_data2";
8945 return "DW_FORM_data4";
8947 return "DW_FORM_data8";
8948 case DW_FORM_string
:
8949 return "DW_FORM_string";
8951 return "DW_FORM_block";
8952 case DW_FORM_block1
:
8953 return "DW_FORM_block1";
8955 return "DW_FORM_data1";
8957 return "DW_FORM_flag";
8959 return "DW_FORM_sdata";
8961 return "DW_FORM_strp";
8963 return "DW_FORM_udata";
8964 case DW_FORM_ref_addr
:
8965 return "DW_FORM_ref_addr";
8967 return "DW_FORM_ref1";
8969 return "DW_FORM_ref2";
8971 return "DW_FORM_ref4";
8973 return "DW_FORM_ref8";
8974 case DW_FORM_ref_udata
:
8975 return "DW_FORM_ref_udata";
8976 case DW_FORM_indirect
:
8977 return "DW_FORM_indirect";
8978 case GDB_FORM_cached_string
:
8979 return "GDB_FORM_cached_string";
8981 return "DW_FORM_<unknown>";
8985 /* Convert a DWARF stack opcode into its string name. */
8988 dwarf_stack_op_name (unsigned op
)
8993 return "DW_OP_addr";
8995 return "DW_OP_deref";
8997 return "DW_OP_const1u";
8999 return "DW_OP_const1s";
9001 return "DW_OP_const2u";
9003 return "DW_OP_const2s";
9005 return "DW_OP_const4u";
9007 return "DW_OP_const4s";
9009 return "DW_OP_const8u";
9011 return "DW_OP_const8s";
9013 return "DW_OP_constu";
9015 return "DW_OP_consts";
9019 return "DW_OP_drop";
9021 return "DW_OP_over";
9023 return "DW_OP_pick";
9025 return "DW_OP_swap";
9029 return "DW_OP_xderef";
9037 return "DW_OP_minus";
9049 return "DW_OP_plus";
9050 case DW_OP_plus_uconst
:
9051 return "DW_OP_plus_uconst";
9057 return "DW_OP_shra";
9075 return "DW_OP_skip";
9077 return "DW_OP_lit0";
9079 return "DW_OP_lit1";
9081 return "DW_OP_lit2";
9083 return "DW_OP_lit3";
9085 return "DW_OP_lit4";
9087 return "DW_OP_lit5";
9089 return "DW_OP_lit6";
9091 return "DW_OP_lit7";
9093 return "DW_OP_lit8";
9095 return "DW_OP_lit9";
9097 return "DW_OP_lit10";
9099 return "DW_OP_lit11";
9101 return "DW_OP_lit12";
9103 return "DW_OP_lit13";
9105 return "DW_OP_lit14";
9107 return "DW_OP_lit15";
9109 return "DW_OP_lit16";
9111 return "DW_OP_lit17";
9113 return "DW_OP_lit18";
9115 return "DW_OP_lit19";
9117 return "DW_OP_lit20";
9119 return "DW_OP_lit21";
9121 return "DW_OP_lit22";
9123 return "DW_OP_lit23";
9125 return "DW_OP_lit24";
9127 return "DW_OP_lit25";
9129 return "DW_OP_lit26";
9131 return "DW_OP_lit27";
9133 return "DW_OP_lit28";
9135 return "DW_OP_lit29";
9137 return "DW_OP_lit30";
9139 return "DW_OP_lit31";
9141 return "DW_OP_reg0";
9143 return "DW_OP_reg1";
9145 return "DW_OP_reg2";
9147 return "DW_OP_reg3";
9149 return "DW_OP_reg4";
9151 return "DW_OP_reg5";
9153 return "DW_OP_reg6";
9155 return "DW_OP_reg7";
9157 return "DW_OP_reg8";
9159 return "DW_OP_reg9";
9161 return "DW_OP_reg10";
9163 return "DW_OP_reg11";
9165 return "DW_OP_reg12";
9167 return "DW_OP_reg13";
9169 return "DW_OP_reg14";
9171 return "DW_OP_reg15";
9173 return "DW_OP_reg16";
9175 return "DW_OP_reg17";
9177 return "DW_OP_reg18";
9179 return "DW_OP_reg19";
9181 return "DW_OP_reg20";
9183 return "DW_OP_reg21";
9185 return "DW_OP_reg22";
9187 return "DW_OP_reg23";
9189 return "DW_OP_reg24";
9191 return "DW_OP_reg25";
9193 return "DW_OP_reg26";
9195 return "DW_OP_reg27";
9197 return "DW_OP_reg28";
9199 return "DW_OP_reg29";
9201 return "DW_OP_reg30";
9203 return "DW_OP_reg31";
9205 return "DW_OP_breg0";
9207 return "DW_OP_breg1";
9209 return "DW_OP_breg2";
9211 return "DW_OP_breg3";
9213 return "DW_OP_breg4";
9215 return "DW_OP_breg5";
9217 return "DW_OP_breg6";
9219 return "DW_OP_breg7";
9221 return "DW_OP_breg8";
9223 return "DW_OP_breg9";
9225 return "DW_OP_breg10";
9227 return "DW_OP_breg11";
9229 return "DW_OP_breg12";
9231 return "DW_OP_breg13";
9233 return "DW_OP_breg14";
9235 return "DW_OP_breg15";
9237 return "DW_OP_breg16";
9239 return "DW_OP_breg17";
9241 return "DW_OP_breg18";
9243 return "DW_OP_breg19";
9245 return "DW_OP_breg20";
9247 return "DW_OP_breg21";
9249 return "DW_OP_breg22";
9251 return "DW_OP_breg23";
9253 return "DW_OP_breg24";
9255 return "DW_OP_breg25";
9257 return "DW_OP_breg26";
9259 return "DW_OP_breg27";
9261 return "DW_OP_breg28";
9263 return "DW_OP_breg29";
9265 return "DW_OP_breg30";
9267 return "DW_OP_breg31";
9269 return "DW_OP_regx";
9271 return "DW_OP_fbreg";
9273 return "DW_OP_bregx";
9275 return "DW_OP_piece";
9276 case DW_OP_deref_size
:
9277 return "DW_OP_deref_size";
9278 case DW_OP_xderef_size
:
9279 return "DW_OP_xderef_size";
9282 /* DWARF 3 extensions. */
9283 case DW_OP_push_object_address
:
9284 return "DW_OP_push_object_address";
9286 return "DW_OP_call2";
9288 return "DW_OP_call4";
9289 case DW_OP_call_ref
:
9290 return "DW_OP_call_ref";
9291 /* GNU extensions. */
9292 case DW_OP_form_tls_address
:
9293 return "DW_OP_form_tls_address";
9294 case DW_OP_call_frame_cfa
:
9295 return "DW_OP_call_frame_cfa";
9296 case DW_OP_bit_piece
:
9297 return "DW_OP_bit_piece";
9298 case DW_OP_GNU_push_tls_address
:
9299 return "DW_OP_GNU_push_tls_address";
9300 case DW_OP_GNU_uninit
:
9301 return "DW_OP_GNU_uninit";
9302 /* HP extensions. */
9303 case DW_OP_HP_is_value
:
9304 return "DW_OP_HP_is_value";
9305 case DW_OP_HP_fltconst4
:
9306 return "DW_OP_HP_fltconst4";
9307 case DW_OP_HP_fltconst8
:
9308 return "DW_OP_HP_fltconst8";
9309 case DW_OP_HP_mod_range
:
9310 return "DW_OP_HP_mod_range";
9311 case DW_OP_HP_unmod_range
:
9312 return "DW_OP_HP_unmod_range";
9314 return "DW_OP_HP_tls";
9316 return "OP_<unknown>";
9321 dwarf_bool_name (unsigned mybool
)
9329 /* Convert a DWARF type code into its string name. */
9332 dwarf_type_encoding_name (unsigned enc
)
9337 return "DW_ATE_void";
9338 case DW_ATE_address
:
9339 return "DW_ATE_address";
9340 case DW_ATE_boolean
:
9341 return "DW_ATE_boolean";
9342 case DW_ATE_complex_float
:
9343 return "DW_ATE_complex_float";
9345 return "DW_ATE_float";
9347 return "DW_ATE_signed";
9348 case DW_ATE_signed_char
:
9349 return "DW_ATE_signed_char";
9350 case DW_ATE_unsigned
:
9351 return "DW_ATE_unsigned";
9352 case DW_ATE_unsigned_char
:
9353 return "DW_ATE_unsigned_char";
9355 case DW_ATE_imaginary_float
:
9356 return "DW_ATE_imaginary_float";
9357 case DW_ATE_packed_decimal
:
9358 return "DW_ATE_packed_decimal";
9359 case DW_ATE_numeric_string
:
9360 return "DW_ATE_numeric_string";
9362 return "DW_ATE_edited";
9363 case DW_ATE_signed_fixed
:
9364 return "DW_ATE_signed_fixed";
9365 case DW_ATE_unsigned_fixed
:
9366 return "DW_ATE_unsigned_fixed";
9367 case DW_ATE_decimal_float
:
9368 return "DW_ATE_decimal_float";
9369 /* HP extensions. */
9370 case DW_ATE_HP_float80
:
9371 return "DW_ATE_HP_float80";
9372 case DW_ATE_HP_complex_float80
:
9373 return "DW_ATE_HP_complex_float80";
9374 case DW_ATE_HP_float128
:
9375 return "DW_ATE_HP_float128";
9376 case DW_ATE_HP_complex_float128
:
9377 return "DW_ATE_HP_complex_float128";
9378 case DW_ATE_HP_floathpintel
:
9379 return "DW_ATE_HP_floathpintel";
9380 case DW_ATE_HP_imaginary_float80
:
9381 return "DW_ATE_HP_imaginary_float80";
9382 case DW_ATE_HP_imaginary_float128
:
9383 return "DW_ATE_HP_imaginary_float128";
9385 return "DW_ATE_<unknown>";
9389 /* Convert a DWARF call frame info operation to its string name. */
9393 dwarf_cfi_name (unsigned cfi_opc
)
9397 case DW_CFA_advance_loc
:
9398 return "DW_CFA_advance_loc";
9400 return "DW_CFA_offset";
9401 case DW_CFA_restore
:
9402 return "DW_CFA_restore";
9404 return "DW_CFA_nop";
9405 case DW_CFA_set_loc
:
9406 return "DW_CFA_set_loc";
9407 case DW_CFA_advance_loc1
:
9408 return "DW_CFA_advance_loc1";
9409 case DW_CFA_advance_loc2
:
9410 return "DW_CFA_advance_loc2";
9411 case DW_CFA_advance_loc4
:
9412 return "DW_CFA_advance_loc4";
9413 case DW_CFA_offset_extended
:
9414 return "DW_CFA_offset_extended";
9415 case DW_CFA_restore_extended
:
9416 return "DW_CFA_restore_extended";
9417 case DW_CFA_undefined
:
9418 return "DW_CFA_undefined";
9419 case DW_CFA_same_value
:
9420 return "DW_CFA_same_value";
9421 case DW_CFA_register
:
9422 return "DW_CFA_register";
9423 case DW_CFA_remember_state
:
9424 return "DW_CFA_remember_state";
9425 case DW_CFA_restore_state
:
9426 return "DW_CFA_restore_state";
9427 case DW_CFA_def_cfa
:
9428 return "DW_CFA_def_cfa";
9429 case DW_CFA_def_cfa_register
:
9430 return "DW_CFA_def_cfa_register";
9431 case DW_CFA_def_cfa_offset
:
9432 return "DW_CFA_def_cfa_offset";
9434 case DW_CFA_def_cfa_expression
:
9435 return "DW_CFA_def_cfa_expression";
9436 case DW_CFA_expression
:
9437 return "DW_CFA_expression";
9438 case DW_CFA_offset_extended_sf
:
9439 return "DW_CFA_offset_extended_sf";
9440 case DW_CFA_def_cfa_sf
:
9441 return "DW_CFA_def_cfa_sf";
9442 case DW_CFA_def_cfa_offset_sf
:
9443 return "DW_CFA_def_cfa_offset_sf";
9444 case DW_CFA_val_offset
:
9445 return "DW_CFA_val_offset";
9446 case DW_CFA_val_offset_sf
:
9447 return "DW_CFA_val_offset_sf";
9448 case DW_CFA_val_expression
:
9449 return "DW_CFA_val_expression";
9450 /* SGI/MIPS specific. */
9451 case DW_CFA_MIPS_advance_loc8
:
9452 return "DW_CFA_MIPS_advance_loc8";
9453 /* GNU extensions. */
9454 case DW_CFA_GNU_window_save
:
9455 return "DW_CFA_GNU_window_save";
9456 case DW_CFA_GNU_args_size
:
9457 return "DW_CFA_GNU_args_size";
9458 case DW_CFA_GNU_negative_offset_extended
:
9459 return "DW_CFA_GNU_negative_offset_extended";
9461 return "DW_CFA_<unknown>";
9467 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
9471 print_spaces (indent
, f
);
9472 fprintf_unfiltered (f
, "Die: %s (abbrev %d, offset 0x%x)\n",
9473 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
9475 if (die
->parent
!= NULL
)
9477 print_spaces (indent
, f
);
9478 fprintf_unfiltered (f
, " parent at offset: 0x%x\n",
9479 die
->parent
->offset
);
9482 print_spaces (indent
, f
);
9483 fprintf_unfiltered (f
, " has children: %s\n",
9484 dwarf_bool_name (die
->child
!= NULL
));
9486 print_spaces (indent
, f
);
9487 fprintf_unfiltered (f
, " attributes:\n");
9489 for (i
= 0; i
< die
->num_attrs
; ++i
)
9491 print_spaces (indent
, f
);
9492 fprintf_unfiltered (f
, " %s (%s) ",
9493 dwarf_attr_name (die
->attrs
[i
].name
),
9494 dwarf_form_name (die
->attrs
[i
].form
));
9496 switch (die
->attrs
[i
].form
)
9498 case DW_FORM_ref_addr
:
9500 fprintf_unfiltered (f
, "address: ");
9501 fputs_filtered (paddress (DW_ADDR (&die
->attrs
[i
])), f
);
9503 case DW_FORM_block2
:
9504 case DW_FORM_block4
:
9506 case DW_FORM_block1
:
9507 fprintf_unfiltered (f
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
9512 fprintf_unfiltered (f
, "constant ref: 0x%lx (adjusted)",
9513 (long) (DW_ADDR (&die
->attrs
[i
])));
9521 fprintf_unfiltered (f
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
9523 case DW_FORM_string
:
9525 case GDB_FORM_cached_string
:
9526 fprintf_unfiltered (f
, "string: \"%s\"",
9527 DW_STRING (&die
->attrs
[i
])
9528 ? DW_STRING (&die
->attrs
[i
]) : "");
9531 if (DW_UNSND (&die
->attrs
[i
]))
9532 fprintf_unfiltered (f
, "flag: TRUE");
9534 fprintf_unfiltered (f
, "flag: FALSE");
9536 case DW_FORM_indirect
:
9537 /* the reader will have reduced the indirect form to
9538 the "base form" so this form should not occur */
9539 fprintf_unfiltered (f
, "unexpected attribute form: DW_FORM_indirect");
9542 fprintf_unfiltered (f
, "unsupported attribute form: %d.",
9543 die
->attrs
[i
].form
);
9546 fprintf_unfiltered (f
, "\n");
9551 dump_die_for_error (struct die_info
*die
)
9553 dump_die_shallow (gdb_stderr
, 0, die
);
9557 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
9559 int indent
= level
* 4;
9561 gdb_assert (die
!= NULL
);
9563 if (level
>= max_level
)
9566 dump_die_shallow (f
, indent
, die
);
9568 if (die
->child
!= NULL
)
9570 print_spaces (indent
, f
);
9571 fprintf_unfiltered (f
, " Children:");
9572 if (level
+ 1 < max_level
)
9574 fprintf_unfiltered (f
, "\n");
9575 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
9579 fprintf_unfiltered (f
, " [not printed, max nesting level reached]\n");
9583 if (die
->sibling
!= NULL
&& level
> 0)
9585 dump_die_1 (f
, level
, max_level
, die
->sibling
);
9589 /* This is called from the pdie macro in gdbinit.in.
9590 It's not static so gcc will keep a copy callable from gdb. */
9593 dump_die (struct die_info
*die
, int max_level
)
9595 dump_die_1 (gdb_stdlog
, 0, max_level
, die
);
9599 store_in_ref_table (struct die_info
*die
, struct dwarf2_cu
*cu
)
9603 slot
= htab_find_slot_with_hash (cu
->die_hash
, die
, die
->offset
, INSERT
);
9609 dwarf2_get_ref_die_offset (struct attribute
*attr
)
9611 unsigned int result
= 0;
9615 case DW_FORM_ref_addr
:
9620 case DW_FORM_ref_udata
:
9621 result
= DW_ADDR (attr
);
9624 complaint (&symfile_complaints
,
9625 _("unsupported die ref attribute form: '%s'"),
9626 dwarf_form_name (attr
->form
));
9631 /* Return the constant value held by the given attribute. Return -1
9632 if the value held by the attribute is not constant. */
9635 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
9637 if (attr
->form
== DW_FORM_sdata
)
9638 return DW_SND (attr
);
9639 else if (attr
->form
== DW_FORM_udata
9640 || attr
->form
== DW_FORM_data1
9641 || attr
->form
== DW_FORM_data2
9642 || attr
->form
== DW_FORM_data4
9643 || attr
->form
== DW_FORM_data8
)
9644 return DW_UNSND (attr
);
9647 complaint (&symfile_complaints
, _("Attribute value is not a constant (%s)"),
9648 dwarf_form_name (attr
->form
));
9649 return default_value
;
9653 /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation
9654 unit and add it to our queue. */
9657 maybe_queue_comp_unit (struct dwarf2_cu
*this_cu
,
9658 struct dwarf2_per_cu_data
*per_cu
)
9660 /* Mark the dependence relation so that we don't flush PER_CU
9662 dwarf2_add_dependence (this_cu
, per_cu
);
9664 /* If it's already on the queue, we have nothing to do. */
9668 /* If the compilation unit is already loaded, just mark it as
9670 if (per_cu
->cu
!= NULL
)
9672 per_cu
->cu
->last_used
= 0;
9676 /* Add it to the queue. */
9677 queue_comp_unit (per_cu
, this_cu
->objfile
);
9680 /* Follow reference attribute ATTR of SRC_DIE.
9681 On entry *REF_CU is the CU of SRC_DIE.
9682 On exit *REF_CU is the CU of the result. */
9684 static struct die_info
*
9685 follow_die_ref (struct die_info
*src_die
, struct attribute
*attr
,
9686 struct dwarf2_cu
**ref_cu
)
9688 struct die_info
*die
;
9689 unsigned int offset
;
9690 struct die_info temp_die
;
9691 struct dwarf2_cu
*target_cu
, *cu
= *ref_cu
;
9693 offset
= dwarf2_get_ref_die_offset (attr
);
9695 if (! offset_in_cu_p (&cu
->header
, offset
))
9697 struct dwarf2_per_cu_data
*per_cu
;
9698 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
9700 /* If necessary, add it to the queue and load its DIEs. */
9701 maybe_queue_comp_unit (cu
, per_cu
);
9703 target_cu
= per_cu
->cu
;
9708 *ref_cu
= target_cu
;
9709 temp_die
.offset
= offset
;
9710 die
= htab_find_with_hash (target_cu
->die_hash
, &temp_die
, offset
);
9714 error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE "
9715 "at 0x%lx [in module %s]"),
9716 (long) offset
, (long) src_die
->offset
, cu
->objfile
->name
);
9719 /* Decode simple location descriptions.
9720 Given a pointer to a dwarf block that defines a location, compute
9721 the location and return the value.
9723 NOTE drow/2003-11-18: This function is called in two situations
9724 now: for the address of static or global variables (partial symbols
9725 only) and for offsets into structures which are expected to be
9726 (more or less) constant. The partial symbol case should go away,
9727 and only the constant case should remain. That will let this
9728 function complain more accurately. A few special modes are allowed
9729 without complaint for global variables (for instance, global
9730 register values and thread-local values).
9732 A location description containing no operations indicates that the
9733 object is optimized out. The return value is 0 for that case.
9734 FIXME drow/2003-11-16: No callers check for this case any more; soon all
9735 callers will only want a very basic result and this can become a
9738 Note that stack[0] is unused except as a default error return.
9739 Note that stack overflow is not yet handled. */
9742 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
9744 struct objfile
*objfile
= cu
->objfile
;
9745 struct comp_unit_head
*cu_header
= &cu
->header
;
9747 int size
= blk
->size
;
9748 gdb_byte
*data
= blk
->data
;
9749 CORE_ADDR stack
[64];
9751 unsigned int bytes_read
, unsnd
;
9795 stack
[++stacki
] = op
- DW_OP_lit0
;
9830 stack
[++stacki
] = op
- DW_OP_reg0
;
9832 dwarf2_complex_location_expr_complaint ();
9836 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9838 stack
[++stacki
] = unsnd
;
9840 dwarf2_complex_location_expr_complaint ();
9844 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
9850 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
9855 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
9860 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
9865 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
9870 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
9875 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
9880 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
9886 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
9891 stack
[stacki
+ 1] = stack
[stacki
];
9896 stack
[stacki
- 1] += stack
[stacki
];
9900 case DW_OP_plus_uconst
:
9901 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
9906 stack
[stacki
- 1] -= stack
[stacki
];
9911 /* If we're not the last op, then we definitely can't encode
9912 this using GDB's address_class enum. This is valid for partial
9913 global symbols, although the variable's address will be bogus
9916 dwarf2_complex_location_expr_complaint ();
9919 case DW_OP_GNU_push_tls_address
:
9920 /* The top of the stack has the offset from the beginning
9921 of the thread control block at which the variable is located. */
9922 /* Nothing should follow this operator, so the top of stack would
9924 /* This is valid for partial global symbols, but the variable's
9925 address will be bogus in the psymtab. */
9927 dwarf2_complex_location_expr_complaint ();
9930 case DW_OP_GNU_uninit
:
9934 complaint (&symfile_complaints
, _("unsupported stack op: '%s'"),
9935 dwarf_stack_op_name (op
));
9936 return (stack
[stacki
]);
9939 return (stack
[stacki
]);
9942 /* memory allocation interface */
9944 static struct dwarf_block
*
9945 dwarf_alloc_block (struct dwarf2_cu
*cu
)
9947 struct dwarf_block
*blk
;
9949 blk
= (struct dwarf_block
*)
9950 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
9954 static struct abbrev_info
*
9955 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
9957 struct abbrev_info
*abbrev
;
9959 abbrev
= (struct abbrev_info
*)
9960 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
9961 memset (abbrev
, 0, sizeof (struct abbrev_info
));
9965 static struct die_info
*
9966 dwarf_alloc_die (struct dwarf2_cu
*cu
, int num_attrs
)
9968 struct die_info
*die
;
9969 size_t size
= sizeof (struct die_info
);
9972 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
9974 die
= (struct die_info
*) obstack_alloc (&cu
->comp_unit_obstack
, size
);
9975 memset (die
, 0, sizeof (struct die_info
));
9980 /* Macro support. */
9983 /* Return the full name of file number I in *LH's file name table.
9984 Use COMP_DIR as the name of the current directory of the
9985 compilation. The result is allocated using xmalloc; the caller is
9986 responsible for freeing it. */
9988 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
9990 /* Is the file number a valid index into the line header's file name
9991 table? Remember that file numbers start with one, not zero. */
9992 if (1 <= file
&& file
<= lh
->num_file_names
)
9994 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
9996 if (IS_ABSOLUTE_PATH (fe
->name
))
9997 return xstrdup (fe
->name
);
10005 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
10011 dir_len
= strlen (dir
);
10012 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
10013 strcpy (full_name
, dir
);
10014 full_name
[dir_len
] = '/';
10015 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
10019 return xstrdup (fe
->name
);
10024 /* The compiler produced a bogus file number. We can at least
10025 record the macro definitions made in the file, even if we
10026 won't be able to find the file by name. */
10027 char fake_name
[80];
10028 sprintf (fake_name
, "<bad macro file number %d>", file
);
10030 complaint (&symfile_complaints
,
10031 _("bad file number in macro information (%d)"),
10034 return xstrdup (fake_name
);
10039 static struct macro_source_file
*
10040 macro_start_file (int file
, int line
,
10041 struct macro_source_file
*current_file
,
10042 const char *comp_dir
,
10043 struct line_header
*lh
, struct objfile
*objfile
)
10045 /* The full name of this source file. */
10046 char *full_name
= file_full_name (file
, lh
, comp_dir
);
10048 /* We don't create a macro table for this compilation unit
10049 at all until we actually get a filename. */
10050 if (! pending_macros
)
10051 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
10052 objfile
->macro_cache
);
10054 if (! current_file
)
10055 /* If we have no current file, then this must be the start_file
10056 directive for the compilation unit's main source file. */
10057 current_file
= macro_set_main (pending_macros
, full_name
);
10059 current_file
= macro_include (current_file
, line
, full_name
);
10063 return current_file
;
10067 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
10068 followed by a null byte. */
10070 copy_string (const char *buf
, int len
)
10072 char *s
= xmalloc (len
+ 1);
10073 memcpy (s
, buf
, len
);
10080 static const char *
10081 consume_improper_spaces (const char *p
, const char *body
)
10085 complaint (&symfile_complaints
,
10086 _("macro definition contains spaces in formal argument list:\n`%s'"),
10098 parse_macro_definition (struct macro_source_file
*file
, int line
,
10103 /* The body string takes one of two forms. For object-like macro
10104 definitions, it should be:
10106 <macro name> " " <definition>
10108 For function-like macro definitions, it should be:
10110 <macro name> "() " <definition>
10112 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
10114 Spaces may appear only where explicitly indicated, and in the
10117 The Dwarf 2 spec says that an object-like macro's name is always
10118 followed by a space, but versions of GCC around March 2002 omit
10119 the space when the macro's definition is the empty string.
10121 The Dwarf 2 spec says that there should be no spaces between the
10122 formal arguments in a function-like macro's formal argument list,
10123 but versions of GCC around March 2002 include spaces after the
10127 /* Find the extent of the macro name. The macro name is terminated
10128 by either a space or null character (for an object-like macro) or
10129 an opening paren (for a function-like macro). */
10130 for (p
= body
; *p
; p
++)
10131 if (*p
== ' ' || *p
== '(')
10134 if (*p
== ' ' || *p
== '\0')
10136 /* It's an object-like macro. */
10137 int name_len
= p
- body
;
10138 char *name
= copy_string (body
, name_len
);
10139 const char *replacement
;
10142 replacement
= body
+ name_len
+ 1;
10145 dwarf2_macro_malformed_definition_complaint (body
);
10146 replacement
= body
+ name_len
;
10149 macro_define_object (file
, line
, name
, replacement
);
10153 else if (*p
== '(')
10155 /* It's a function-like macro. */
10156 char *name
= copy_string (body
, p
- body
);
10159 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
10163 p
= consume_improper_spaces (p
, body
);
10165 /* Parse the formal argument list. */
10166 while (*p
&& *p
!= ')')
10168 /* Find the extent of the current argument name. */
10169 const char *arg_start
= p
;
10171 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
10174 if (! *p
|| p
== arg_start
)
10175 dwarf2_macro_malformed_definition_complaint (body
);
10178 /* Make sure argv has room for the new argument. */
10179 if (argc
>= argv_size
)
10182 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
10185 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
10188 p
= consume_improper_spaces (p
, body
);
10190 /* Consume the comma, if present. */
10195 p
= consume_improper_spaces (p
, body
);
10204 /* Perfectly formed definition, no complaints. */
10205 macro_define_function (file
, line
, name
,
10206 argc
, (const char **) argv
,
10208 else if (*p
== '\0')
10210 /* Complain, but do define it. */
10211 dwarf2_macro_malformed_definition_complaint (body
);
10212 macro_define_function (file
, line
, name
,
10213 argc
, (const char **) argv
,
10217 /* Just complain. */
10218 dwarf2_macro_malformed_definition_complaint (body
);
10221 /* Just complain. */
10222 dwarf2_macro_malformed_definition_complaint (body
);
10228 for (i
= 0; i
< argc
; i
++)
10234 dwarf2_macro_malformed_definition_complaint (body
);
10239 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
10240 char *comp_dir
, bfd
*abfd
,
10241 struct dwarf2_cu
*cu
)
10243 gdb_byte
*mac_ptr
, *mac_end
;
10244 struct macro_source_file
*current_file
= 0;
10245 enum dwarf_macinfo_record_type macinfo_type
;
10246 int at_commandline
;
10248 if (dwarf2_per_objfile
->macinfo
.buffer
== NULL
)
10250 complaint (&symfile_complaints
, _("missing .debug_macinfo section"));
10254 /* First pass: Find the name of the base filename.
10255 This filename is needed in order to process all macros whose definition
10256 (or undefinition) comes from the command line. These macros are defined
10257 before the first DW_MACINFO_start_file entry, and yet still need to be
10258 associated to the base file.
10260 To determine the base file name, we scan the macro definitions until we
10261 reach the first DW_MACINFO_start_file entry. We then initialize
10262 CURRENT_FILE accordingly so that any macro definition found before the
10263 first DW_MACINFO_start_file can still be associated to the base file. */
10265 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
10266 mac_end
= dwarf2_per_objfile
->macinfo
.buffer
10267 + dwarf2_per_objfile
->macinfo
.size
;
10271 /* Do we at least have room for a macinfo type byte? */
10272 if (mac_ptr
>= mac_end
)
10274 /* Complaint is printed during the second pass as GDB will probably
10275 stop the first pass earlier upon finding DW_MACINFO_start_file. */
10279 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10282 switch (macinfo_type
)
10284 /* A zero macinfo type indicates the end of the macro
10289 case DW_MACINFO_define
:
10290 case DW_MACINFO_undef
:
10291 /* Only skip the data by MAC_PTR. */
10293 unsigned int bytes_read
;
10295 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10296 mac_ptr
+= bytes_read
;
10297 read_string (abfd
, mac_ptr
, &bytes_read
);
10298 mac_ptr
+= bytes_read
;
10302 case DW_MACINFO_start_file
:
10304 unsigned int bytes_read
;
10307 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10308 mac_ptr
+= bytes_read
;
10309 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10310 mac_ptr
+= bytes_read
;
10312 current_file
= macro_start_file (file
, line
, current_file
, comp_dir
,
10317 case DW_MACINFO_end_file
:
10318 /* No data to skip by MAC_PTR. */
10321 case DW_MACINFO_vendor_ext
:
10322 /* Only skip the data by MAC_PTR. */
10324 unsigned int bytes_read
;
10326 read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10327 mac_ptr
+= bytes_read
;
10328 read_string (abfd
, mac_ptr
, &bytes_read
);
10329 mac_ptr
+= bytes_read
;
10336 } while (macinfo_type
!= 0 && current_file
== NULL
);
10338 /* Second pass: Process all entries.
10340 Use the AT_COMMAND_LINE flag to determine whether we are still processing
10341 command-line macro definitions/undefinitions. This flag is unset when we
10342 reach the first DW_MACINFO_start_file entry. */
10344 mac_ptr
= dwarf2_per_objfile
->macinfo
.buffer
+ offset
;
10346 /* Determines if GDB is still before first DW_MACINFO_start_file. If true
10347 GDB is still reading the definitions from command line. First
10348 DW_MACINFO_start_file will need to be ignored as it was already executed
10349 to create CURRENT_FILE for the main source holding also the command line
10350 definitions. On first met DW_MACINFO_start_file this flag is reset to
10351 normally execute all the remaining DW_MACINFO_start_file macinfos. */
10353 at_commandline
= 1;
10357 /* Do we at least have room for a macinfo type byte? */
10358 if (mac_ptr
>= mac_end
)
10360 dwarf2_macros_too_long_complaint ();
10364 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
10367 switch (macinfo_type
)
10369 /* A zero macinfo type indicates the end of the macro
10374 case DW_MACINFO_define
:
10375 case DW_MACINFO_undef
:
10377 unsigned int bytes_read
;
10381 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10382 mac_ptr
+= bytes_read
;
10383 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
10384 mac_ptr
+= bytes_read
;
10386 if (! current_file
)
10388 /* DWARF violation as no main source is present. */
10389 complaint (&symfile_complaints
,
10390 _("debug info with no main source gives macro %s "
10393 DW_MACINFO_define
? _("definition") : macinfo_type
==
10394 DW_MACINFO_undef
? _("undefinition") :
10395 "something-or-other", line
, body
);
10398 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10399 complaint (&symfile_complaints
,
10400 _("debug info gives %s macro %s with %s line %d: %s"),
10401 at_commandline
? _("command-line") : _("in-file"),
10403 DW_MACINFO_define
? _("definition") : macinfo_type
==
10404 DW_MACINFO_undef
? _("undefinition") :
10405 "something-or-other",
10406 line
== 0 ? _("zero") : _("non-zero"), line
, body
);
10408 if (macinfo_type
== DW_MACINFO_define
)
10409 parse_macro_definition (current_file
, line
, body
);
10410 else if (macinfo_type
== DW_MACINFO_undef
)
10411 macro_undef (current_file
, line
, body
);
10415 case DW_MACINFO_start_file
:
10417 unsigned int bytes_read
;
10420 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10421 mac_ptr
+= bytes_read
;
10422 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10423 mac_ptr
+= bytes_read
;
10425 if ((line
== 0 && !at_commandline
) || (line
!= 0 && at_commandline
))
10426 complaint (&symfile_complaints
,
10427 _("debug info gives source %d included "
10428 "from %s at %s line %d"),
10429 file
, at_commandline
? _("command-line") : _("file"),
10430 line
== 0 ? _("zero") : _("non-zero"), line
);
10432 if (at_commandline
)
10434 /* This DW_MACINFO_start_file was executed in the pass one. */
10435 at_commandline
= 0;
10438 current_file
= macro_start_file (file
, line
,
10439 current_file
, comp_dir
,
10444 case DW_MACINFO_end_file
:
10445 if (! current_file
)
10446 complaint (&symfile_complaints
,
10447 _("macro debug info has an unmatched `close_file' directive"));
10450 current_file
= current_file
->included_by
;
10451 if (! current_file
)
10453 enum dwarf_macinfo_record_type next_type
;
10455 /* GCC circa March 2002 doesn't produce the zero
10456 type byte marking the end of the compilation
10457 unit. Complain if it's not there, but exit no
10460 /* Do we at least have room for a macinfo type byte? */
10461 if (mac_ptr
>= mac_end
)
10463 dwarf2_macros_too_long_complaint ();
10467 /* We don't increment mac_ptr here, so this is just
10469 next_type
= read_1_byte (abfd
, mac_ptr
);
10470 if (next_type
!= 0)
10471 complaint (&symfile_complaints
,
10472 _("no terminating 0-type entry for macros in `.debug_macinfo' section"));
10479 case DW_MACINFO_vendor_ext
:
10481 unsigned int bytes_read
;
10485 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
10486 mac_ptr
+= bytes_read
;
10487 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
10488 mac_ptr
+= bytes_read
;
10490 /* We don't recognize any vendor extensions. */
10494 } while (macinfo_type
!= 0);
10497 /* Check if the attribute's form is a DW_FORM_block*
10498 if so return true else false. */
10500 attr_form_is_block (struct attribute
*attr
)
10502 return (attr
== NULL
? 0 :
10503 attr
->form
== DW_FORM_block1
10504 || attr
->form
== DW_FORM_block2
10505 || attr
->form
== DW_FORM_block4
10506 || attr
->form
== DW_FORM_block
);
10509 /* Return non-zero if ATTR's value is a section offset --- classes
10510 lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
10511 You may use DW_UNSND (attr) to retrieve such offsets.
10513 Section 7.5.4, "Attribute Encodings", explains that no attribute
10514 may have a value that belongs to more than one of these classes; it
10515 would be ambiguous if we did, because we use the same forms for all
10518 attr_form_is_section_offset (struct attribute
*attr
)
10520 return (attr
->form
== DW_FORM_data4
10521 || attr
->form
== DW_FORM_data8
);
10525 /* Return non-zero if ATTR's value falls in the 'constant' class, or
10526 zero otherwise. When this function returns true, you can apply
10527 dwarf2_get_attr_constant_value to it.
10529 However, note that for some attributes you must check
10530 attr_form_is_section_offset before using this test. DW_FORM_data4
10531 and DW_FORM_data8 are members of both the constant class, and of
10532 the classes that contain offsets into other debug sections
10533 (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says
10534 that, if an attribute's can be either a constant or one of the
10535 section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
10536 taken as section offsets, not constants. */
10538 attr_form_is_constant (struct attribute
*attr
)
10540 switch (attr
->form
)
10542 case DW_FORM_sdata
:
10543 case DW_FORM_udata
:
10544 case DW_FORM_data1
:
10545 case DW_FORM_data2
:
10546 case DW_FORM_data4
:
10547 case DW_FORM_data8
:
10555 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
10556 struct dwarf2_cu
*cu
)
10558 if (attr_form_is_section_offset (attr
)
10559 /* ".debug_loc" may not exist at all, or the offset may be outside
10560 the section. If so, fall through to the complaint in the
10562 && DW_UNSND (attr
) < dwarf2_per_objfile
->loc
.size
)
10564 struct dwarf2_loclist_baton
*baton
;
10566 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10567 sizeof (struct dwarf2_loclist_baton
));
10568 baton
->per_cu
= cu
->per_cu
;
10569 gdb_assert (baton
->per_cu
);
10571 /* We don't know how long the location list is, but make sure we
10572 don't run off the edge of the section. */
10573 baton
->size
= dwarf2_per_objfile
->loc
.size
- DW_UNSND (attr
);
10574 baton
->data
= dwarf2_per_objfile
->loc
.buffer
+ DW_UNSND (attr
);
10575 baton
->base_address
= cu
->base_address
;
10576 if (cu
->base_known
== 0)
10577 complaint (&symfile_complaints
,
10578 _("Location list used without specifying the CU base address."));
10580 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_loclist_funcs
;
10581 SYMBOL_LOCATION_BATON (sym
) = baton
;
10585 struct dwarf2_locexpr_baton
*baton
;
10587 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
10588 sizeof (struct dwarf2_locexpr_baton
));
10589 baton
->per_cu
= cu
->per_cu
;
10590 gdb_assert (baton
->per_cu
);
10592 if (attr_form_is_block (attr
))
10594 /* Note that we're just copying the block's data pointer
10595 here, not the actual data. We're still pointing into the
10596 info_buffer for SYM's objfile; right now we never release
10597 that buffer, but when we do clean up properly this may
10599 baton
->size
= DW_BLOCK (attr
)->size
;
10600 baton
->data
= DW_BLOCK (attr
)->data
;
10604 dwarf2_invalid_attrib_class_complaint ("location description",
10605 SYMBOL_NATURAL_NAME (sym
));
10607 baton
->data
= NULL
;
10610 SYMBOL_COMPUTED_OPS (sym
) = &dwarf2_locexpr_funcs
;
10611 SYMBOL_LOCATION_BATON (sym
) = baton
;
10615 /* Return the OBJFILE associated with the compilation unit CU. */
10618 dwarf2_per_cu_objfile (struct dwarf2_per_cu_data
*per_cu
)
10620 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10622 /* Return the master objfile, so that we can report and look up the
10623 correct file containing this variable. */
10624 if (objfile
->separate_debug_objfile_backlink
)
10625 objfile
= objfile
->separate_debug_objfile_backlink
;
10630 /* Return the address size given in the compilation unit header for CU. */
10633 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data
*per_cu
)
10636 return per_cu
->cu
->header
.addr_size
;
10639 /* If the CU is not currently read in, we re-read its header. */
10640 struct objfile
*objfile
= per_cu
->psymtab
->objfile
;
10641 struct dwarf2_per_objfile
*per_objfile
10642 = objfile_data (objfile
, dwarf2_objfile_data_key
);
10643 gdb_byte
*info_ptr
= per_objfile
->info
.buffer
+ per_cu
->offset
;
10645 struct comp_unit_head cu_header
;
10646 memset (&cu_header
, 0, sizeof cu_header
);
10647 read_comp_unit_head (&cu_header
, info_ptr
, objfile
->obfd
);
10648 return cu_header
.addr_size
;
10652 /* Locate the compilation unit from CU's objfile which contains the
10653 DIE at OFFSET. Raises an error on failure. */
10655 static struct dwarf2_per_cu_data
*
10656 dwarf2_find_containing_comp_unit (unsigned int offset
,
10657 struct objfile
*objfile
)
10659 struct dwarf2_per_cu_data
*this_cu
;
10663 high
= dwarf2_per_objfile
->n_comp_units
- 1;
10666 int mid
= low
+ (high
- low
) / 2;
10667 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
10672 gdb_assert (low
== high
);
10673 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
10676 error (_("Dwarf Error: could not find partial DIE containing "
10677 "offset 0x%lx [in module %s]"),
10678 (long) offset
, bfd_get_filename (objfile
->obfd
));
10680 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
10681 return dwarf2_per_objfile
->all_comp_units
[low
-1];
10685 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
10686 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
10687 && offset
>= this_cu
->offset
+ this_cu
->length
)
10688 error (_("invalid dwarf2 offset %u"), offset
);
10689 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
10694 /* Locate the compilation unit from OBJFILE which is located at exactly
10695 OFFSET. Raises an error on failure. */
10697 static struct dwarf2_per_cu_data
*
10698 dwarf2_find_comp_unit (unsigned int offset
, struct objfile
*objfile
)
10700 struct dwarf2_per_cu_data
*this_cu
;
10701 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
10702 if (this_cu
->offset
!= offset
)
10703 error (_("no compilation unit with offset %u."), offset
);
10707 /* Release one cached compilation unit, CU. We unlink it from the tree
10708 of compilation units, but we don't remove it from the read_in_chain;
10709 the caller is responsible for that. */
10712 free_one_comp_unit (void *data
)
10714 struct dwarf2_cu
*cu
= data
;
10716 if (cu
->per_cu
!= NULL
)
10717 cu
->per_cu
->cu
= NULL
;
10720 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10725 /* This cleanup function is passed the address of a dwarf2_cu on the stack
10726 when we're finished with it. We can't free the pointer itself, but be
10727 sure to unlink it from the cache. Also release any associated storage
10728 and perform cache maintenance.
10730 Only used during partial symbol parsing. */
10733 free_stack_comp_unit (void *data
)
10735 struct dwarf2_cu
*cu
= data
;
10737 obstack_free (&cu
->comp_unit_obstack
, NULL
);
10738 cu
->partial_dies
= NULL
;
10740 if (cu
->per_cu
!= NULL
)
10742 /* This compilation unit is on the stack in our caller, so we
10743 should not xfree it. Just unlink it. */
10744 cu
->per_cu
->cu
= NULL
;
10747 /* If we had a per-cu pointer, then we may have other compilation
10748 units loaded, so age them now. */
10749 age_cached_comp_units ();
10753 /* Free all cached compilation units. */
10756 free_cached_comp_units (void *data
)
10758 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10760 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10761 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10762 while (per_cu
!= NULL
)
10764 struct dwarf2_per_cu_data
*next_cu
;
10766 next_cu
= per_cu
->cu
->read_in_chain
;
10768 free_one_comp_unit (per_cu
->cu
);
10769 *last_chain
= next_cu
;
10775 /* Increase the age counter on each cached compilation unit, and free
10776 any that are too old. */
10779 age_cached_comp_units (void)
10781 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10783 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
10784 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10785 while (per_cu
!= NULL
)
10787 per_cu
->cu
->last_used
++;
10788 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
10789 dwarf2_mark (per_cu
->cu
);
10790 per_cu
= per_cu
->cu
->read_in_chain
;
10793 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10794 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10795 while (per_cu
!= NULL
)
10797 struct dwarf2_per_cu_data
*next_cu
;
10799 next_cu
= per_cu
->cu
->read_in_chain
;
10801 if (!per_cu
->cu
->mark
)
10803 free_one_comp_unit (per_cu
->cu
);
10804 *last_chain
= next_cu
;
10807 last_chain
= &per_cu
->cu
->read_in_chain
;
10813 /* Remove a single compilation unit from the cache. */
10816 free_one_cached_comp_unit (void *target_cu
)
10818 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
10820 per_cu
= dwarf2_per_objfile
->read_in_chain
;
10821 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
10822 while (per_cu
!= NULL
)
10824 struct dwarf2_per_cu_data
*next_cu
;
10826 next_cu
= per_cu
->cu
->read_in_chain
;
10828 if (per_cu
->cu
== target_cu
)
10830 free_one_comp_unit (per_cu
->cu
);
10831 *last_chain
= next_cu
;
10835 last_chain
= &per_cu
->cu
->read_in_chain
;
10841 /* Release all extra memory associated with OBJFILE. */
10844 dwarf2_free_objfile (struct objfile
*objfile
)
10846 dwarf2_per_objfile
= objfile_data (objfile
, dwarf2_objfile_data_key
);
10848 if (dwarf2_per_objfile
== NULL
)
10851 /* Cached DIE trees use xmalloc and the comp_unit_obstack. */
10852 free_cached_comp_units (NULL
);
10854 /* Everything else should be on the objfile obstack. */
10857 /* A pair of DIE offset and GDB type pointer. We store these
10858 in a hash table separate from the DIEs, and preserve them
10859 when the DIEs are flushed out of cache. */
10861 struct dwarf2_offset_and_type
10863 unsigned int offset
;
10867 /* Hash function for a dwarf2_offset_and_type. */
10870 offset_and_type_hash (const void *item
)
10872 const struct dwarf2_offset_and_type
*ofs
= item
;
10873 return ofs
->offset
;
10876 /* Equality function for a dwarf2_offset_and_type. */
10879 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
10881 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
10882 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
10883 return ofs_lhs
->offset
== ofs_rhs
->offset
;
10886 /* Set the type associated with DIE to TYPE. Save it in CU's hash
10887 table if necessary. For convenience, return TYPE. */
10889 static struct type
*
10890 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
10892 struct dwarf2_offset_and_type
**slot
, ofs
;
10894 if (cu
->type_hash
== NULL
)
10896 gdb_assert (cu
->per_cu
!= NULL
);
10897 cu
->per_cu
->type_hash
10898 = htab_create_alloc_ex (cu
->header
.length
/ 24,
10899 offset_and_type_hash
,
10900 offset_and_type_eq
,
10902 &cu
->objfile
->objfile_obstack
,
10903 hashtab_obstack_allocate
,
10904 dummy_obstack_deallocate
);
10905 cu
->type_hash
= cu
->per_cu
->type_hash
;
10908 ofs
.offset
= die
->offset
;
10910 slot
= (struct dwarf2_offset_and_type
**)
10911 htab_find_slot_with_hash (cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
10912 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
10917 /* Find the type for DIE in CU's type_hash, or return NULL if DIE does
10918 not have a saved type. */
10920 static struct type
*
10921 get_die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
10923 struct dwarf2_offset_and_type
*slot
, ofs
;
10924 htab_t type_hash
= cu
->type_hash
;
10926 if (type_hash
== NULL
)
10929 ofs
.offset
= die
->offset
;
10930 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
10937 /* Add a dependence relationship from CU to REF_PER_CU. */
10940 dwarf2_add_dependence (struct dwarf2_cu
*cu
,
10941 struct dwarf2_per_cu_data
*ref_per_cu
)
10945 if (cu
->dependencies
== NULL
)
10947 = htab_create_alloc_ex (5, htab_hash_pointer
, htab_eq_pointer
,
10948 NULL
, &cu
->comp_unit_obstack
,
10949 hashtab_obstack_allocate
,
10950 dummy_obstack_deallocate
);
10952 slot
= htab_find_slot (cu
->dependencies
, ref_per_cu
, INSERT
);
10954 *slot
= ref_per_cu
;
10957 /* Subroutine of dwarf2_mark to pass to htab_traverse.
10958 Set the mark field in every compilation unit in the
10959 cache that we must keep because we are keeping CU. */
10962 dwarf2_mark_helper (void **slot
, void *data
)
10964 struct dwarf2_per_cu_data
*per_cu
;
10966 per_cu
= (struct dwarf2_per_cu_data
*) *slot
;
10967 if (per_cu
->cu
->mark
)
10969 per_cu
->cu
->mark
= 1;
10971 if (per_cu
->cu
->dependencies
!= NULL
)
10972 htab_traverse (per_cu
->cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10977 /* Set the mark field in CU and in every other compilation unit in the
10978 cache that we must keep because we are keeping CU. */
10981 dwarf2_mark (struct dwarf2_cu
*cu
)
10986 if (cu
->dependencies
!= NULL
)
10987 htab_traverse (cu
->dependencies
, dwarf2_mark_helper
, NULL
);
10991 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
10995 per_cu
->cu
->mark
= 0;
10996 per_cu
= per_cu
->cu
->read_in_chain
;
11000 /* Trivial hash function for partial_die_info: the hash value of a DIE
11001 is its offset in .debug_info for this objfile. */
11004 partial_die_hash (const void *item
)
11006 const struct partial_die_info
*part_die
= item
;
11007 return part_die
->offset
;
11010 /* Trivial comparison function for partial_die_info structures: two DIEs
11011 are equal if they have the same offset. */
11014 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
11016 const struct partial_die_info
*part_die_lhs
= item_lhs
;
11017 const struct partial_die_info
*part_die_rhs
= item_rhs
;
11018 return part_die_lhs
->offset
== part_die_rhs
->offset
;
11021 static struct cmd_list_element
*set_dwarf2_cmdlist
;
11022 static struct cmd_list_element
*show_dwarf2_cmdlist
;
11025 set_dwarf2_cmd (char *args
, int from_tty
)
11027 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
11031 show_dwarf2_cmd (char *args
, int from_tty
)
11033 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
11036 /* If section described by INFO was mmapped, munmap it now. */
11039 munmap_section_buffer (struct dwarf2_section_info
*info
)
11041 if (info
->was_mmapped
)
11044 intptr_t begin
= (intptr_t) info
->buffer
;
11045 intptr_t map_begin
= begin
& ~(pagesize
- 1);
11046 size_t map_length
= info
->size
+ begin
- map_begin
;
11047 gdb_assert (munmap ((void *) map_begin
, map_length
) == 0);
11049 /* Without HAVE_MMAP, we should never be here to begin with. */
11055 /* munmap debug sections for OBJFILE, if necessary. */
11058 dwarf2_per_objfile_cleanup (struct objfile
*objfile
, void *d
)
11060 struct dwarf2_per_objfile
*data
= d
;
11061 munmap_section_buffer (&data
->info
);
11062 munmap_section_buffer (&data
->abbrev
);
11063 munmap_section_buffer (&data
->line
);
11064 munmap_section_buffer (&data
->str
);
11065 munmap_section_buffer (&data
->macinfo
);
11066 munmap_section_buffer (&data
->ranges
);
11067 munmap_section_buffer (&data
->loc
);
11068 munmap_section_buffer (&data
->frame
);
11069 munmap_section_buffer (&data
->eh_frame
);
11072 void _initialize_dwarf2_read (void);
11075 _initialize_dwarf2_read (void)
11077 dwarf2_objfile_data_key
11078 = register_objfile_data_with_cleanup (dwarf2_per_objfile_cleanup
);
11080 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
, _("\
11081 Set DWARF 2 specific variables.\n\
11082 Configure DWARF 2 variables such as the cache size"),
11083 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
11084 0/*allow-unknown*/, &maintenance_set_cmdlist
);
11086 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
, _("\
11087 Show DWARF 2 specific variables\n\
11088 Show DWARF 2 variables such as the cache size"),
11089 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
11090 0/*allow-unknown*/, &maintenance_show_cmdlist
);
11092 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
11093 &dwarf2_max_cache_age
, _("\
11094 Set the upper bound on the age of cached dwarf2 compilation units."), _("\
11095 Show the upper bound on the age of cached dwarf2 compilation units."), _("\
11096 A higher limit means that cached compilation units will be stored\n\
11097 in memory longer, and more total memory will be used. Zero disables\n\
11098 caching, which can slow down startup."),
11100 show_dwarf2_max_cache_age
,
11101 &set_dwarf2_cmdlist
,
11102 &show_dwarf2_cmdlist
);
11104 add_setshow_zinteger_cmd ("dwarf2-die", no_class
, &dwarf2_die_debug
, _("\
11105 Set debugging of the dwarf2 DIE reader."), _("\
11106 Show debugging of the dwarf2 DIE reader."), _("\
11107 When enabled (non-zero), DIEs are dumped after they are read in.\n\
11108 The value is the maximum depth to print."),
11111 &setdebuglist
, &showdebuglist
);