1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 Free Software Foundation, Inc.
6 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
7 Inc. with support from Florida State University (under contract
8 with the Ada Joint Program Office), and Silicon Graphics, Inc.
9 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
10 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 support in dwarfread.c
13 This file is part of GDB.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or (at
18 your option) any later version.
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
42 #include "complaints.h"
44 #include "dwarf2expr.h"
45 #include "dwarf2loc.h"
46 #include "cp-support.h"
52 #include "gdb_string.h"
53 #include "gdb_assert.h"
54 #include <sys/types.h>
56 /* A note on memory usage for this file.
58 At the present time, this code reads the debug info sections into
59 the objfile's objfile_obstack. A definite improvement for startup
60 time, on platforms which do not emit relocations for debug
61 sections, would be to use mmap instead. The object's complete
62 debug information is loaded into memory, partly to simplify
63 absolute DIE references.
65 Whether using obstacks or mmap, the sections should remain loaded
66 until the objfile is released, and pointers into the section data
67 can be used for any other data associated to the objfile (symbol
68 names, type names, location expressions to name a few). */
70 #ifndef DWARF2_REG_TO_REGNUM
71 #define DWARF2_REG_TO_REGNUM(REG) (REG)
75 /* .debug_info header for a compilation unit
76 Because of alignment constraints, this structure has padding and cannot
77 be mapped directly onto the beginning of the .debug_info section. */
78 typedef struct comp_unit_header
80 unsigned int length
; /* length of the .debug_info
82 unsigned short version
; /* version number -- 2 for DWARF
84 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
85 unsigned char addr_size
; /* byte size of an address -- 4 */
88 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
91 /* .debug_pubnames header
92 Because of alignment constraints, this structure has padding and cannot
93 be mapped directly onto the beginning of the .debug_info section. */
94 typedef struct pubnames_header
96 unsigned int length
; /* length of the .debug_pubnames
98 unsigned char version
; /* version number -- 2 for DWARF
100 unsigned int info_offset
; /* offset into .debug_info section */
101 unsigned int info_size
; /* byte size of .debug_info section
105 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
107 /* .debug_pubnames header
108 Because of alignment constraints, this structure has padding and cannot
109 be mapped directly onto the beginning of the .debug_info section. */
110 typedef struct aranges_header
112 unsigned int length
; /* byte len of the .debug_aranges
114 unsigned short version
; /* version number -- 2 for DWARF
116 unsigned int info_offset
; /* offset into .debug_info section */
117 unsigned char addr_size
; /* byte size of an address */
118 unsigned char seg_size
; /* byte size of segment descriptor */
121 #define _ACTUAL_ARANGES_HEADER_SIZE 12
123 /* .debug_line statement program prologue
124 Because of alignment constraints, this structure has padding and cannot
125 be mapped directly onto the beginning of the .debug_info section. */
126 typedef struct statement_prologue
128 unsigned int total_length
; /* byte length of the statement
130 unsigned short version
; /* version number -- 2 for DWARF
132 unsigned int prologue_length
; /* # bytes between prologue &
134 unsigned char minimum_instruction_length
; /* byte size of
136 unsigned char default_is_stmt
; /* initial value of is_stmt
139 unsigned char line_range
;
140 unsigned char opcode_base
; /* number assigned to first special
142 unsigned char *standard_opcode_lengths
;
146 static const struct objfile_data
*dwarf2_objfile_data_key
;
148 struct dwarf2_per_objfile
150 /* Sizes of debugging sections. */
151 unsigned int info_size
;
152 unsigned int abbrev_size
;
153 unsigned int line_size
;
154 unsigned int pubnames_size
;
155 unsigned int aranges_size
;
156 unsigned int loc_size
;
157 unsigned int macinfo_size
;
158 unsigned int str_size
;
159 unsigned int ranges_size
;
160 unsigned int frame_size
;
161 unsigned int eh_frame_size
;
163 /* Loaded data from the sections. */
168 char *macinfo_buffer
;
172 /* A list of all the compilation units. This will be set if and
173 only if we have encountered a compilation unit with inter-CU
175 struct dwarf2_per_cu_data
**all_comp_units
;
177 /* The number of compilation units in ALL_COMP_UNITS. */
180 /* A chain of compilation units that are currently read in, so that
181 they can be freed later. */
182 struct dwarf2_per_cu_data
*read_in_chain
;
185 static struct dwarf2_per_objfile
*dwarf2_per_objfile
;
187 static asection
*dwarf_info_section
;
188 static asection
*dwarf_abbrev_section
;
189 static asection
*dwarf_line_section
;
190 static asection
*dwarf_pubnames_section
;
191 static asection
*dwarf_aranges_section
;
192 static asection
*dwarf_loc_section
;
193 static asection
*dwarf_macinfo_section
;
194 static asection
*dwarf_str_section
;
195 static asection
*dwarf_ranges_section
;
196 asection
*dwarf_frame_section
;
197 asection
*dwarf_eh_frame_section
;
199 /* names of the debugging sections */
201 #define INFO_SECTION ".debug_info"
202 #define ABBREV_SECTION ".debug_abbrev"
203 #define LINE_SECTION ".debug_line"
204 #define PUBNAMES_SECTION ".debug_pubnames"
205 #define ARANGES_SECTION ".debug_aranges"
206 #define LOC_SECTION ".debug_loc"
207 #define MACINFO_SECTION ".debug_macinfo"
208 #define STR_SECTION ".debug_str"
209 #define RANGES_SECTION ".debug_ranges"
210 #define FRAME_SECTION ".debug_frame"
211 #define EH_FRAME_SECTION ".eh_frame"
213 /* local data types */
215 /* We hold several abbreviation tables in memory at the same time. */
216 #ifndef ABBREV_HASH_SIZE
217 #define ABBREV_HASH_SIZE 121
220 /* The data in a compilation unit header, after target2host
221 translation, looks like this. */
222 struct comp_unit_head
224 unsigned long length
;
226 unsigned int abbrev_offset
;
227 unsigned char addr_size
;
228 unsigned char signed_addr_p
;
229 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
230 unsigned int initial_length_size
; /* size of the length field; either
233 /* Offset to the first byte of this compilation unit header in the
234 * .debug_info section, for resolving relative reference dies. */
238 /* Pointer to this compilation unit header in the .debug_info
243 /* Pointer to the first die of this compilatio unit. This will
244 * be the first byte following the compilation unit header. */
248 /* Pointer to the next compilation unit header in the program. */
250 struct comp_unit_head
*next
;
252 /* Base address of this compilation unit. */
254 CORE_ADDR base_address
;
256 /* Non-zero if base_address has been set. */
261 /* Internal state when decoding a particular compilation unit. */
264 /* The objfile containing this compilation unit. */
265 struct objfile
*objfile
;
267 /* The header of the compilation unit.
269 FIXME drow/2003-11-10: Some of the things from the comp_unit_head
270 should logically be moved to the dwarf2_cu structure. */
271 struct comp_unit_head header
;
273 struct function_range
*first_fn
, *last_fn
, *cached_fn
;
275 /* The language we are debugging. */
276 enum language language
;
277 const struct language_defn
*language_defn
;
279 const char *producer
;
281 /* The generic symbol table building routines have separate lists for
282 file scope symbols and all all other scopes (local scopes). So
283 we need to select the right one to pass to add_symbol_to_list().
284 We do it by keeping a pointer to the correct list in list_in_scope.
286 FIXME: The original dwarf code just treated the file scope as the
287 first local scope, and all other local scopes as nested local
288 scopes, and worked fine. Check to see if we really need to
289 distinguish these in buildsym.c. */
290 struct pending
**list_in_scope
;
292 /* Maintain an array of referenced fundamental types for the current
293 compilation unit being read. For DWARF version 1, we have to construct
294 the fundamental types on the fly, since no information about the
295 fundamental types is supplied. Each such fundamental type is created by
296 calling a language dependent routine to create the type, and then a
297 pointer to that type is then placed in the array at the index specified
298 by it's FT_<TYPENAME> value. The array has a fixed size set by the
299 FT_NUM_MEMBERS compile time constant, which is the number of predefined
300 fundamental types gdb knows how to construct. */
301 struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
303 /* DWARF abbreviation table associated with this compilation unit. */
304 struct abbrev_info
**dwarf2_abbrevs
;
306 /* Storage for the abbrev table. */
307 struct obstack abbrev_obstack
;
309 /* Hash table holding all the loaded partial DIEs. */
312 /* Storage for things with the same lifetime as this read-in compilation
313 unit, including partial DIEs. */
314 struct obstack comp_unit_obstack
;
316 /* When multiple dwarf2_cu structures are living in memory, this field
317 chains them all together, so that they can be released efficiently.
318 We will probably also want a generation counter so that most-recently-used
319 compilation units are cached... */
320 struct dwarf2_per_cu_data
*read_in_chain
;
322 /* Backchain to our per_cu entry if the tree has been built. */
323 struct dwarf2_per_cu_data
*per_cu
;
325 /* How many compilation units ago was this CU last referenced? */
328 /* Mark used when releasing cached dies. */
329 unsigned int mark
: 1;
331 /* This flag will be set if this compilation unit might include
332 inter-compilation-unit references. */
333 unsigned int has_form_ref_addr
: 1;
335 /* This flag will be set if this compilation unit includes any
336 DW_TAG_namespace DIEs. If we know that there are explicit
337 DIEs for namespaces, we don't need to try to infer them
338 from mangled names. */
339 unsigned int has_namespace_info
: 1;
342 struct dwarf2_per_cu_data
344 /* The start offset and length of this compilation unit. 2**31-1
345 bytes should suffice to store the length of any compilation unit
346 - if it doesn't, GDB will fall over anyway. */
347 unsigned long offset
;
348 unsigned long length
: 31;
350 /* Flag indicating this compilation unit will be read in before
351 any of the current compilation units are processed. */
352 unsigned long queued
: 1;
354 /* Set iff currently read in. */
355 struct dwarf2_cu
*cu
;
357 /* If full symbols for this CU have been read in, then this field
358 holds a map of DIE offsets to types. It isn't always possible
359 to reconstruct this information later, so we have to preserve
365 /* The line number information for a compilation unit (found in the
366 .debug_line section) begins with a "statement program header",
367 which contains the following information. */
370 unsigned int total_length
;
371 unsigned short version
;
372 unsigned int header_length
;
373 unsigned char minimum_instruction_length
;
374 unsigned char default_is_stmt
;
376 unsigned char line_range
;
377 unsigned char opcode_base
;
379 /* standard_opcode_lengths[i] is the number of operands for the
380 standard opcode whose value is i. This means that
381 standard_opcode_lengths[0] is unused, and the last meaningful
382 element is standard_opcode_lengths[opcode_base - 1]. */
383 unsigned char *standard_opcode_lengths
;
385 /* The include_directories table. NOTE! These strings are not
386 allocated with xmalloc; instead, they are pointers into
387 debug_line_buffer. If you try to free them, `free' will get
389 unsigned int num_include_dirs
, include_dirs_size
;
392 /* The file_names table. NOTE! These strings are not allocated
393 with xmalloc; instead, they are pointers into debug_line_buffer.
394 Don't try to free them directly. */
395 unsigned int num_file_names
, file_names_size
;
399 unsigned int dir_index
;
400 unsigned int mod_time
;
402 int included_p
; /* Non-zero if referenced by the Line Number Program. */
405 /* The start and end of the statement program following this
406 header. These point into dwarf2_per_objfile->line_buffer. */
407 char *statement_program_start
, *statement_program_end
;
410 /* When we construct a partial symbol table entry we only
411 need this much information. */
412 struct partial_die_info
414 /* Offset of this DIE. */
417 /* DWARF-2 tag for this DIE. */
418 ENUM_BITFIELD(dwarf_tag
) tag
: 16;
420 /* Language code associated with this DIE. This is only used
421 for the compilation unit DIE. */
422 unsigned int language
: 8;
424 /* Assorted flags describing the data found in this DIE. */
425 unsigned int has_children
: 1;
426 unsigned int is_external
: 1;
427 unsigned int is_declaration
: 1;
428 unsigned int has_type
: 1;
429 unsigned int has_specification
: 1;
430 unsigned int has_stmt_list
: 1;
431 unsigned int has_pc_info
: 1;
433 /* Flag set if the SCOPE field of this structure has been
435 unsigned int scope_set
: 1;
437 /* The name of this DIE. Normally the value of DW_AT_name, but
438 sometimes DW_TAG_MIPS_linkage_name or a string computed in some
443 /* The scope to prepend to our children. This is generally
444 allocated on the comp_unit_obstack, so will disappear
445 when this compilation unit leaves the cache. */
448 /* The location description associated with this DIE, if any. */
449 struct dwarf_block
*locdesc
;
451 /* If HAS_PC_INFO, the PC range associated with this DIE. */
455 /* Pointer into the info_buffer pointing at the target of
456 DW_AT_sibling, if any. */
459 /* If HAS_SPECIFICATION, the offset of the DIE referred to by
460 DW_AT_specification (or DW_AT_abstract_origin or
462 unsigned int spec_offset
;
464 /* If HAS_STMT_LIST, the offset of the Line Number Information data. */
465 unsigned int line_offset
;
467 /* Pointers to this DIE's parent, first child, and next sibling,
469 struct partial_die_info
*die_parent
, *die_child
, *die_sibling
;
472 /* This data structure holds the information of an abbrev. */
475 unsigned int number
; /* number identifying abbrev */
476 enum dwarf_tag tag
; /* dwarf tag */
477 unsigned short has_children
; /* boolean */
478 unsigned short num_attrs
; /* number of attributes */
479 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
480 struct abbrev_info
*next
; /* next in chain */
485 enum dwarf_attribute name
;
486 enum dwarf_form form
;
489 /* This data structure holds a complete die structure. */
492 enum dwarf_tag tag
; /* Tag indicating type of die */
493 unsigned int abbrev
; /* Abbrev number */
494 unsigned int offset
; /* Offset in .debug_info section */
495 unsigned int num_attrs
; /* Number of attributes */
496 struct attribute
*attrs
; /* An array of attributes */
497 struct die_info
*next_ref
; /* Next die in ref hash table */
499 /* The dies in a compilation unit form an n-ary tree. PARENT
500 points to this die's parent; CHILD points to the first child of
501 this node; and all the children of a given node are chained
502 together via their SIBLING fields, terminated by a die whose
504 struct die_info
*child
; /* Its first child, if any. */
505 struct die_info
*sibling
; /* Its next sibling, if any. */
506 struct die_info
*parent
; /* Its parent, if any. */
508 struct type
*type
; /* Cached type information */
511 /* Attributes have a name and a value */
514 enum dwarf_attribute name
;
515 enum dwarf_form form
;
519 struct dwarf_block
*blk
;
527 struct function_range
530 CORE_ADDR lowpc
, highpc
;
532 struct function_range
*next
;
535 /* Get at parts of an attribute structure */
537 #define DW_STRING(attr) ((attr)->u.str)
538 #define DW_UNSND(attr) ((attr)->u.unsnd)
539 #define DW_BLOCK(attr) ((attr)->u.blk)
540 #define DW_SND(attr) ((attr)->u.snd)
541 #define DW_ADDR(attr) ((attr)->u.addr)
543 /* Blocks are a bunch of untyped bytes. */
550 #ifndef ATTR_ALLOC_CHUNK
551 #define ATTR_ALLOC_CHUNK 4
554 /* A hash table of die offsets for following references. */
555 #ifndef REF_HASH_SIZE
556 #define REF_HASH_SIZE 1021
559 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
561 /* Allocate fields for structs, unions and enums in this size. */
562 #ifndef DW_FIELD_ALLOC_CHUNK
563 #define DW_FIELD_ALLOC_CHUNK 4
566 /* A zeroed version of a partial die for initialization purposes. */
567 static struct partial_die_info zeroed_partial_die
;
569 /* FIXME: decode_locdesc sets these variables to describe the location
570 to the caller. These ought to be a structure or something. If
571 none of the flags are set, the object lives at the address returned
572 by decode_locdesc. */
574 static int isreg
; /* Object lives in register.
575 decode_locdesc's return value is
576 the register number. */
578 /* We put a pointer to this structure in the read_symtab_private field
583 /* Offset in .debug_info for this compilation unit. */
585 unsigned long dwarf_info_offset
;
588 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
589 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
591 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
592 but this would require a corresponding change in unpack_field_as_long
594 static int bits_per_byte
= 8;
596 /* The routines that read and process dies for a C struct or C++ class
597 pass lists of data member fields and lists of member function fields
598 in an instance of a field_info structure, as defined below. */
601 /* List of data member and baseclasses fields. */
604 struct nextfield
*next
;
611 /* Number of fields. */
614 /* Number of baseclasses. */
617 /* Set if the accesibility of one of the fields is not public. */
618 int non_public_fields
;
620 /* Member function fields array, entries are allocated in the order they
621 are encountered in the object file. */
624 struct nextfnfield
*next
;
625 struct fn_field fnfield
;
629 /* Member function fieldlist array, contains name of possibly overloaded
630 member function, number of overloaded member functions and a pointer
631 to the head of the member function field chain. */
636 struct nextfnfield
*head
;
640 /* Number of entries in the fnfieldlists array. */
644 /* Loaded secondary compilation units are kept in memory until they
645 have not been referenced for the processing of this many
646 compilation units. Set this to zero to disable caching. Cache
647 sizes of up to at least twenty will improve startup time for
648 typical inter-CU-reference binaries, at an obvious memory cost. */
649 static int dwarf2_max_cache_age
= 5;
651 /* Various complaints about symbol reading that don't abort the process */
654 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
656 complaint (&symfile_complaints
,
657 "statement list doesn't fit in .debug_line section");
661 dwarf2_complex_location_expr_complaint (void)
663 complaint (&symfile_complaints
, "location expression too complex");
667 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
670 complaint (&symfile_complaints
,
671 "const value length mismatch for '%s', got %d, expected %d", arg1
,
676 dwarf2_macros_too_long_complaint (void)
678 complaint (&symfile_complaints
,
679 "macro info runs off end of `.debug_macinfo' section");
683 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
685 complaint (&symfile_complaints
,
686 "macro debug info contains a malformed macro definition:\n`%s'",
691 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
693 complaint (&symfile_complaints
,
694 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
697 /* local function prototypes */
699 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
702 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
705 static void dwarf2_create_include_psymtab (char *, struct partial_symtab
*,
708 static void dwarf2_build_include_psymtabs (struct dwarf2_cu
*,
709 struct partial_die_info
*,
710 struct partial_symtab
*);
712 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
714 static void scan_partial_symbols (struct partial_die_info
*,
715 CORE_ADDR
*, CORE_ADDR
*,
718 static void add_partial_symbol (struct partial_die_info
*,
721 static int pdi_needs_namespace (enum dwarf_tag tag
);
723 static void add_partial_namespace (struct partial_die_info
*pdi
,
724 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
725 struct dwarf2_cu
*cu
);
727 static void add_partial_enumeration (struct partial_die_info
*enum_pdi
,
728 struct dwarf2_cu
*cu
);
730 static char *locate_pdi_sibling (struct partial_die_info
*orig_pdi
,
733 struct dwarf2_cu
*cu
);
735 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
737 static void psymtab_to_symtab_1 (struct partial_symtab
*);
739 char *dwarf2_read_section (struct objfile
*, asection
*);
741 static void dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
);
743 static void dwarf2_free_abbrev_table (void *);
745 static struct abbrev_info
*peek_die_abbrev (char *, int *, struct dwarf2_cu
*);
747 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
750 static struct partial_die_info
*load_partial_dies (bfd
*, char *, int,
753 static char *read_partial_die (struct partial_die_info
*,
754 struct abbrev_info
*abbrev
, unsigned int,
755 bfd
*, char *, struct dwarf2_cu
*);
757 static struct partial_die_info
*find_partial_die (unsigned long,
759 struct dwarf2_cu
**);
761 static void fixup_partial_die (struct partial_die_info
*,
764 static char *read_full_die (struct die_info
**, bfd
*, char *,
765 struct dwarf2_cu
*, int *);
767 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
768 bfd
*, char *, struct dwarf2_cu
*);
770 static char *read_attribute_value (struct attribute
*, unsigned,
771 bfd
*, char *, struct dwarf2_cu
*);
773 static unsigned int read_1_byte (bfd
*, char *);
775 static int read_1_signed_byte (bfd
*, char *);
777 static unsigned int read_2_bytes (bfd
*, char *);
779 static unsigned int read_4_bytes (bfd
*, char *);
781 static unsigned long read_8_bytes (bfd
*, char *);
783 static CORE_ADDR
read_address (bfd
*, char *ptr
, struct dwarf2_cu
*,
786 static LONGEST
read_initial_length (bfd
*, char *,
787 struct comp_unit_head
*, int *bytes_read
);
789 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
792 static char *read_n_bytes (bfd
*, char *, unsigned int);
794 static char *read_string (bfd
*, char *, unsigned int *);
796 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
799 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
801 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
803 static char *skip_leb128 (bfd
*, char *);
805 static void set_cu_language (unsigned int, struct dwarf2_cu
*);
807 static struct attribute
*dwarf2_attr (struct die_info
*, unsigned int,
810 static int dwarf2_flag_true_p (struct die_info
*die
, unsigned name
,
811 struct dwarf2_cu
*cu
);
813 static int die_is_declaration (struct die_info
*, struct dwarf2_cu
*cu
);
815 static struct die_info
*die_specification (struct die_info
*die
,
818 static void free_line_header (struct line_header
*lh
);
820 static void add_file_name (struct line_header
*, char *, unsigned int,
821 unsigned int, unsigned int);
823 static struct line_header
*(dwarf_decode_line_header
824 (unsigned int offset
,
825 bfd
*abfd
, struct dwarf2_cu
*cu
));
827 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
828 struct dwarf2_cu
*, struct partial_symtab
*);
830 static void dwarf2_start_subfile (char *, char *);
832 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
835 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
838 static void dwarf2_const_value_data (struct attribute
*attr
,
842 static struct type
*die_type (struct die_info
*, struct dwarf2_cu
*);
844 static struct type
*die_containing_type (struct die_info
*,
848 static struct type
*type_at_offset (unsigned int, struct objfile
*);
851 static struct type
*tag_type_to_type (struct die_info
*, struct dwarf2_cu
*);
853 static void read_type_die (struct die_info
*, struct dwarf2_cu
*);
855 static char *determine_prefix (struct die_info
*die
, struct dwarf2_cu
*);
857 static char *typename_concat (struct obstack
*, const char *prefix
, const char *suffix
,
860 static void read_typedef (struct die_info
*, struct dwarf2_cu
*);
862 static void read_base_type (struct die_info
*, struct dwarf2_cu
*);
864 static void read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
);
866 static void read_file_scope (struct die_info
*, struct dwarf2_cu
*);
868 static void read_func_scope (struct die_info
*, struct dwarf2_cu
*);
870 static void read_lexical_block_scope (struct die_info
*, struct dwarf2_cu
*);
872 static int dwarf2_get_pc_bounds (struct die_info
*,
873 CORE_ADDR
*, CORE_ADDR
*, struct dwarf2_cu
*);
875 static void get_scope_pc_bounds (struct die_info
*,
876 CORE_ADDR
*, CORE_ADDR
*,
879 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
882 static void dwarf2_attach_fields_to_type (struct field_info
*,
883 struct type
*, struct dwarf2_cu
*);
885 static void dwarf2_add_member_fn (struct field_info
*,
886 struct die_info
*, struct type
*,
889 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
890 struct type
*, struct dwarf2_cu
*);
892 static void read_structure_type (struct die_info
*, struct dwarf2_cu
*);
894 static void process_structure_scope (struct die_info
*, struct dwarf2_cu
*);
896 static char *determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
);
898 static void read_common_block (struct die_info
*, struct dwarf2_cu
*);
900 static void read_namespace (struct die_info
*die
, struct dwarf2_cu
*);
902 static const char *namespace_name (struct die_info
*die
,
903 int *is_anonymous
, struct dwarf2_cu
*);
905 static void read_enumeration_type (struct die_info
*, struct dwarf2_cu
*);
907 static void process_enumeration_scope (struct die_info
*, struct dwarf2_cu
*);
909 static struct type
*dwarf_base_type (int, int, struct dwarf2_cu
*);
911 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct dwarf2_cu
*);
913 static void read_array_type (struct die_info
*, struct dwarf2_cu
*);
915 static enum dwarf_array_dim_ordering
read_array_order (struct die_info
*,
918 static void read_tag_pointer_type (struct die_info
*, struct dwarf2_cu
*);
920 static void read_tag_ptr_to_member_type (struct die_info
*,
923 static void read_tag_reference_type (struct die_info
*, struct dwarf2_cu
*);
925 static void read_tag_const_type (struct die_info
*, struct dwarf2_cu
*);
927 static void read_tag_volatile_type (struct die_info
*, struct dwarf2_cu
*);
929 static void read_tag_string_type (struct die_info
*, struct dwarf2_cu
*);
931 static void read_subroutine_type (struct die_info
*, struct dwarf2_cu
*);
933 static struct die_info
*read_comp_unit (char *, bfd
*, struct dwarf2_cu
*);
935 static struct die_info
*read_die_and_children (char *info_ptr
, bfd
*abfd
,
938 struct die_info
*parent
);
940 static struct die_info
*read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
943 struct die_info
*parent
);
945 static void free_die_list (struct die_info
*);
947 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
949 static void process_die (struct die_info
*, struct dwarf2_cu
*);
951 static char *dwarf2_linkage_name (struct die_info
*, struct dwarf2_cu
*);
953 static char *dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*);
955 static struct die_info
*dwarf2_extension (struct die_info
*die
,
958 static char *dwarf_tag_name (unsigned int);
960 static char *dwarf_attr_name (unsigned int);
962 static char *dwarf_form_name (unsigned int);
964 static char *dwarf_stack_op_name (unsigned int);
966 static char *dwarf_bool_name (unsigned int);
968 static char *dwarf_type_encoding_name (unsigned int);
971 static char *dwarf_cfi_name (unsigned int);
973 struct die_info
*copy_die (struct die_info
*);
976 static struct die_info
*sibling_die (struct die_info
*);
978 static void dump_die (struct die_info
*);
980 static void dump_die_list (struct die_info
*);
982 static void store_in_ref_table (unsigned int, struct die_info
*);
984 static void dwarf2_empty_hash_tables (void);
986 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*,
989 static int dwarf2_get_attr_constant_value (struct attribute
*, int);
991 static struct die_info
*follow_die_ref (unsigned int);
993 static struct type
*dwarf2_fundamental_type (struct objfile
*, int,
996 /* memory allocation interface */
998 static struct dwarf_block
*dwarf_alloc_block (struct dwarf2_cu
*);
1000 static struct abbrev_info
*dwarf_alloc_abbrev (struct dwarf2_cu
*);
1002 static struct die_info
*dwarf_alloc_die (void);
1004 static void initialize_cu_func_list (struct dwarf2_cu
*);
1006 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
,
1007 struct dwarf2_cu
*);
1009 static void dwarf_decode_macros (struct line_header
*, unsigned int,
1010 char *, bfd
*, struct dwarf2_cu
*);
1012 static int attr_form_is_block (struct attribute
*);
1015 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
1016 struct dwarf2_cu
*cu
);
1018 static char *skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
1019 struct dwarf2_cu
*cu
);
1021 static void free_stack_comp_unit (void *);
1023 static void *hashtab_obstack_allocate (void *data
, size_t size
, size_t count
);
1025 static void dummy_obstack_deallocate (void *object
, void *data
);
1027 static hashval_t
partial_die_hash (const void *item
);
1029 static int partial_die_eq (const void *item_lhs
, const void *item_rhs
);
1031 static struct dwarf2_per_cu_data
*dwarf2_find_containing_comp_unit
1032 (unsigned long offset
, struct objfile
*objfile
);
1034 static struct dwarf2_per_cu_data
*dwarf2_find_comp_unit
1035 (unsigned long offset
, struct objfile
*objfile
);
1037 static void free_one_comp_unit (void *);
1039 static void free_cached_comp_units (void *);
1041 static void age_cached_comp_units (void);
1043 static void free_one_cached_comp_unit (void *);
1045 static void set_die_type (struct die_info
*, struct type
*,
1046 struct dwarf2_cu
*);
1049 static void reset_die_and_siblings_types (struct die_info
*,
1050 struct dwarf2_cu
*);
1053 static void create_all_comp_units (struct objfile
*);
1055 static void dwarf2_mark (struct dwarf2_cu
*);
1057 static void dwarf2_clear_marks (struct dwarf2_per_cu_data
*);
1059 /* Try to locate the sections we need for DWARF 2 debugging
1060 information and return true if we have enough to do something. */
1063 dwarf2_has_info (struct objfile
*objfile
)
1065 struct dwarf2_per_objfile
*data
;
1067 /* Initialize per-objfile state. */
1068 data
= obstack_alloc (&objfile
->objfile_obstack
, sizeof (*data
));
1069 memset (data
, 0, sizeof (*data
));
1070 set_objfile_data (objfile
, dwarf2_objfile_data_key
, data
);
1071 dwarf2_per_objfile
= data
;
1073 dwarf_info_section
= 0;
1074 dwarf_abbrev_section
= 0;
1075 dwarf_line_section
= 0;
1076 dwarf_str_section
= 0;
1077 dwarf_macinfo_section
= 0;
1078 dwarf_frame_section
= 0;
1079 dwarf_eh_frame_section
= 0;
1080 dwarf_ranges_section
= 0;
1081 dwarf_loc_section
= 0;
1083 bfd_map_over_sections (objfile
->obfd
, dwarf2_locate_sections
, NULL
);
1084 return (dwarf_info_section
!= NULL
&& dwarf_abbrev_section
!= NULL
);
1087 /* This function is mapped across the sections and remembers the
1088 offset and size of each of the debugging sections we are interested
1092 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
1094 if (strcmp (sectp
->name
, INFO_SECTION
) == 0)
1096 dwarf2_per_objfile
->info_size
= bfd_get_section_size (sectp
);
1097 dwarf_info_section
= sectp
;
1099 else if (strcmp (sectp
->name
, ABBREV_SECTION
) == 0)
1101 dwarf2_per_objfile
->abbrev_size
= bfd_get_section_size (sectp
);
1102 dwarf_abbrev_section
= sectp
;
1104 else if (strcmp (sectp
->name
, LINE_SECTION
) == 0)
1106 dwarf2_per_objfile
->line_size
= bfd_get_section_size (sectp
);
1107 dwarf_line_section
= sectp
;
1109 else if (strcmp (sectp
->name
, PUBNAMES_SECTION
) == 0)
1111 dwarf2_per_objfile
->pubnames_size
= bfd_get_section_size (sectp
);
1112 dwarf_pubnames_section
= sectp
;
1114 else if (strcmp (sectp
->name
, ARANGES_SECTION
) == 0)
1116 dwarf2_per_objfile
->aranges_size
= bfd_get_section_size (sectp
);
1117 dwarf_aranges_section
= sectp
;
1119 else if (strcmp (sectp
->name
, LOC_SECTION
) == 0)
1121 dwarf2_per_objfile
->loc_size
= bfd_get_section_size (sectp
);
1122 dwarf_loc_section
= sectp
;
1124 else if (strcmp (sectp
->name
, MACINFO_SECTION
) == 0)
1126 dwarf2_per_objfile
->macinfo_size
= bfd_get_section_size (sectp
);
1127 dwarf_macinfo_section
= sectp
;
1129 else if (strcmp (sectp
->name
, STR_SECTION
) == 0)
1131 dwarf2_per_objfile
->str_size
= bfd_get_section_size (sectp
);
1132 dwarf_str_section
= sectp
;
1134 else if (strcmp (sectp
->name
, FRAME_SECTION
) == 0)
1136 dwarf2_per_objfile
->frame_size
= bfd_get_section_size (sectp
);
1137 dwarf_frame_section
= sectp
;
1139 else if (strcmp (sectp
->name
, EH_FRAME_SECTION
) == 0)
1141 flagword aflag
= bfd_get_section_flags (ignore_abfd
, sectp
);
1142 if (aflag
& SEC_HAS_CONTENTS
)
1144 dwarf2_per_objfile
->eh_frame_size
= bfd_get_section_size (sectp
);
1145 dwarf_eh_frame_section
= sectp
;
1148 else if (strcmp (sectp
->name
, RANGES_SECTION
) == 0)
1150 dwarf2_per_objfile
->ranges_size
= bfd_get_section_size (sectp
);
1151 dwarf_ranges_section
= sectp
;
1155 /* Build a partial symbol table. */
1158 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
1160 /* We definitely need the .debug_info and .debug_abbrev sections */
1162 dwarf2_per_objfile
->info_buffer
= dwarf2_read_section (objfile
, dwarf_info_section
);
1163 dwarf2_per_objfile
->abbrev_buffer
= dwarf2_read_section (objfile
, dwarf_abbrev_section
);
1165 if (dwarf_line_section
)
1166 dwarf2_per_objfile
->line_buffer
= dwarf2_read_section (objfile
, dwarf_line_section
);
1168 dwarf2_per_objfile
->line_buffer
= NULL
;
1170 if (dwarf_str_section
)
1171 dwarf2_per_objfile
->str_buffer
= dwarf2_read_section (objfile
, dwarf_str_section
);
1173 dwarf2_per_objfile
->str_buffer
= NULL
;
1175 if (dwarf_macinfo_section
)
1176 dwarf2_per_objfile
->macinfo_buffer
= dwarf2_read_section (objfile
,
1177 dwarf_macinfo_section
);
1179 dwarf2_per_objfile
->macinfo_buffer
= NULL
;
1181 if (dwarf_ranges_section
)
1182 dwarf2_per_objfile
->ranges_buffer
= dwarf2_read_section (objfile
, dwarf_ranges_section
);
1184 dwarf2_per_objfile
->ranges_buffer
= NULL
;
1186 if (dwarf_loc_section
)
1187 dwarf2_per_objfile
->loc_buffer
= dwarf2_read_section (objfile
, dwarf_loc_section
);
1189 dwarf2_per_objfile
->loc_buffer
= NULL
;
1192 || (objfile
->global_psymbols
.size
== 0
1193 && objfile
->static_psymbols
.size
== 0))
1195 init_psymbol_list (objfile
, 1024);
1199 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1201 /* Things are significantly easier if we have .debug_aranges and
1202 .debug_pubnames sections */
1204 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1208 /* only test this case for now */
1210 /* In this case we have to work a bit harder */
1211 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1216 /* Build the partial symbol table from the information in the
1217 .debug_pubnames and .debug_aranges sections. */
1220 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1222 bfd
*abfd
= objfile
->obfd
;
1223 char *aranges_buffer
, *pubnames_buffer
;
1224 char *aranges_ptr
, *pubnames_ptr
;
1225 unsigned int entry_length
, version
, info_offset
, info_size
;
1227 pubnames_buffer
= dwarf2_read_section (objfile
,
1228 dwarf_pubnames_section
);
1229 pubnames_ptr
= pubnames_buffer
;
1230 while ((pubnames_ptr
- pubnames_buffer
) < dwarf2_per_objfile
->pubnames_size
)
1232 struct comp_unit_head cu_header
;
1235 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1237 pubnames_ptr
+= bytes_read
;
1238 version
= read_1_byte (abfd
, pubnames_ptr
);
1240 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1242 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1246 aranges_buffer
= dwarf2_read_section (objfile
,
1247 dwarf_aranges_section
);
1252 /* Read in the comp unit header information from the debug_info at
1256 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1257 char *info_ptr
, bfd
*abfd
)
1261 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1263 info_ptr
+= bytes_read
;
1264 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1266 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1268 info_ptr
+= bytes_read
;
1269 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1271 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1272 if (signed_addr
< 0)
1273 internal_error (__FILE__
, __LINE__
,
1274 "read_comp_unit_head: dwarf from non elf file");
1275 cu_header
->signed_addr_p
= signed_addr
;
1280 partial_read_comp_unit_head (struct comp_unit_head
*header
, char *info_ptr
,
1283 char *beg_of_comp_unit
= info_ptr
;
1285 info_ptr
= read_comp_unit_head (header
, info_ptr
, abfd
);
1287 if (header
->version
!= 2)
1288 error ("Dwarf Error: wrong version in compilation unit header "
1289 "(is %d, should be %d) [in module %s]", header
->version
,
1290 2, bfd_get_filename (abfd
));
1292 if (header
->abbrev_offset
>= dwarf2_per_objfile
->abbrev_size
)
1293 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header "
1294 "(offset 0x%lx + 6) [in module %s]",
1295 (long) header
->abbrev_offset
,
1296 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1297 bfd_get_filename (abfd
));
1299 if (beg_of_comp_unit
+ header
->length
+ header
->initial_length_size
1300 > dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1301 error ("Dwarf Error: bad length (0x%lx) in compilation unit header "
1302 "(offset 0x%lx + 0) [in module %s]",
1303 (long) header
->length
,
1304 (long) (beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
),
1305 bfd_get_filename (abfd
));
1310 /* Allocate a new partial symtab for file named NAME and mark this new
1311 partial symtab as being an include of PST. */
1314 dwarf2_create_include_psymtab (char *name
, struct partial_symtab
*pst
,
1315 struct objfile
*objfile
)
1317 struct partial_symtab
*subpst
= allocate_psymtab (name
, objfile
);
1319 subpst
->section_offsets
= pst
->section_offsets
;
1320 subpst
->textlow
= 0;
1321 subpst
->texthigh
= 0;
1323 subpst
->dependencies
= (struct partial_symtab
**)
1324 obstack_alloc (&objfile
->objfile_obstack
,
1325 sizeof (struct partial_symtab
*));
1326 subpst
->dependencies
[0] = pst
;
1327 subpst
->number_of_dependencies
= 1;
1329 subpst
->globals_offset
= 0;
1330 subpst
->n_global_syms
= 0;
1331 subpst
->statics_offset
= 0;
1332 subpst
->n_static_syms
= 0;
1333 subpst
->symtab
= NULL
;
1334 subpst
->read_symtab
= pst
->read_symtab
;
1337 /* No private part is necessary for include psymtabs. This property
1338 can be used to differentiate between such include psymtabs and
1339 the regular ones. If it ever happens that a regular psymtab can
1340 legitimally have a NULL private part, then we'll have to add a
1341 dedicated field for that in the dwarf2_pinfo structure. */
1342 subpst
->read_symtab_private
= NULL
;
1345 /* Read the Line Number Program data and extract the list of files
1346 included by the source file represented by PST. Build an include
1347 partial symtab for each of these included files.
1349 This procedure assumes that there *is* a Line Number Program in
1350 the given CU. Callers should check that PDI->HAS_STMT_LIST is set
1351 before calling this procedure. */
1354 dwarf2_build_include_psymtabs (struct dwarf2_cu
*cu
,
1355 struct partial_die_info
*pdi
,
1356 struct partial_symtab
*pst
)
1358 struct objfile
*objfile
= cu
->objfile
;
1359 bfd
*abfd
= objfile
->obfd
;
1360 struct line_header
*lh
;
1362 lh
= dwarf_decode_line_header (pdi
->line_offset
, abfd
, cu
);
1364 return; /* No linetable, so no includes. */
1366 dwarf_decode_lines (lh
, NULL
, abfd
, cu
, pst
);
1368 free_line_header (lh
);
1372 /* Build the partial symbol table by doing a quick pass through the
1373 .debug_info and .debug_abbrev sections. */
1376 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1378 /* Instead of reading this into a big buffer, we should probably use
1379 mmap() on architectures that support it. (FIXME) */
1380 bfd
*abfd
= objfile
->obfd
;
1382 char *beg_of_comp_unit
;
1383 struct partial_die_info comp_unit_die
;
1384 struct partial_symtab
*pst
;
1385 struct cleanup
*back_to
;
1386 CORE_ADDR lowpc
, highpc
, baseaddr
;
1388 info_ptr
= dwarf2_per_objfile
->info_buffer
;
1390 /* Any cached compilation units will be linked by the per-objfile
1391 read_in_chain. Make sure to free them when we're done. */
1392 back_to
= make_cleanup (free_cached_comp_units
, NULL
);
1394 /* Since the objects we're extracting from .debug_info vary in
1395 length, only the individual functions to extract them (like
1396 read_comp_unit_head and load_partial_die) can really know whether
1397 the buffer is large enough to hold another complete object.
1399 At the moment, they don't actually check that. If .debug_info
1400 holds just one extra byte after the last compilation unit's dies,
1401 then read_comp_unit_head will happily read off the end of the
1402 buffer. read_partial_die is similarly casual. Those functions
1405 For this loop condition, simply checking whether there's any data
1406 left at all should be sufficient. */
1407 while (info_ptr
< (dwarf2_per_objfile
->info_buffer
1408 + dwarf2_per_objfile
->info_size
))
1410 struct cleanup
*back_to_inner
;
1411 struct dwarf2_cu cu
;
1412 struct abbrev_info
*abbrev
;
1413 unsigned int bytes_read
;
1414 struct dwarf2_per_cu_data
*this_cu
;
1416 beg_of_comp_unit
= info_ptr
;
1418 memset (&cu
, 0, sizeof (cu
));
1420 obstack_init (&cu
.comp_unit_obstack
);
1422 back_to_inner
= make_cleanup (free_stack_comp_unit
, &cu
);
1424 cu
.objfile
= objfile
;
1425 info_ptr
= partial_read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
1427 /* Complete the cu_header */
1428 cu
.header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1429 cu
.header
.first_die_ptr
= info_ptr
;
1430 cu
.header
.cu_head_ptr
= beg_of_comp_unit
;
1432 cu
.list_in_scope
= &file_symbols
;
1434 /* Read the abbrevs for this compilation unit into a table */
1435 dwarf2_read_abbrevs (abfd
, &cu
);
1436 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
1438 if (cu
.has_form_ref_addr
&& dwarf2_per_objfile
->all_comp_units
== NULL
)
1439 create_all_comp_units (objfile
);
1441 /* Read the compilation unit die */
1442 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, &cu
);
1443 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1444 abfd
, info_ptr
, &cu
);
1446 /* Set the language we're debugging */
1447 set_cu_language (comp_unit_die
.language
, &cu
);
1449 /* Allocate a new partial symbol table structure */
1450 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1451 comp_unit_die
.name
? comp_unit_die
.name
: "",
1452 comp_unit_die
.lowpc
,
1453 objfile
->global_psymbols
.next
,
1454 objfile
->static_psymbols
.next
);
1456 if (comp_unit_die
.dirname
)
1457 pst
->dirname
= xstrdup (comp_unit_die
.dirname
);
1459 pst
->read_symtab_private
= (char *)
1460 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct dwarf2_pinfo
));
1461 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1462 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1464 /* Store the function that reads in the rest of the symbol table */
1465 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1467 if (dwarf2_per_objfile
->all_comp_units
!= NULL
)
1469 struct dwarf2_per_cu_data
*per_cu
;
1471 per_cu
= dwarf2_find_comp_unit (cu
.header
.offset
, objfile
);
1473 /* If this compilation unit was already read in, free the
1474 cached copy in order to read it in again. This is
1475 necessary because we skipped some symbols when we first
1476 read in the compilation unit (see load_partial_dies).
1477 This problem could be avoided, but the benefit is
1479 if (per_cu
->cu
!= NULL
)
1480 free_one_cached_comp_unit (per_cu
->cu
);
1484 /* Note that this is a pointer to our stack frame, being
1485 added to a global data structure. It will be cleaned up
1486 in free_stack_comp_unit when we finish with this
1487 compilation unit. */
1493 /* Check if comp unit has_children.
1494 If so, read the rest of the partial symbols from this comp unit.
1495 If not, there's no more debug_info for this comp unit. */
1496 if (comp_unit_die
.has_children
)
1498 struct partial_die_info
*first_die
;
1500 lowpc
= ((CORE_ADDR
) -1);
1501 highpc
= ((CORE_ADDR
) 0);
1503 first_die
= load_partial_dies (abfd
, info_ptr
, 1, &cu
);
1505 scan_partial_symbols (first_die
, &lowpc
, &highpc
, &cu
);
1507 /* If we didn't find a lowpc, set it to highpc to avoid
1508 complaints from `maint check'. */
1509 if (lowpc
== ((CORE_ADDR
) -1))
1512 /* If the compilation unit didn't have an explicit address range,
1513 then use the information extracted from its child dies. */
1514 if (! comp_unit_die
.has_pc_info
)
1516 comp_unit_die
.lowpc
= lowpc
;
1517 comp_unit_die
.highpc
= highpc
;
1520 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1521 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1523 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1524 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1525 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1526 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1527 sort_pst_symbols (pst
);
1529 /* If there is already a psymtab or symtab for a file of this
1530 name, remove it. (If there is a symtab, more drastic things
1531 also happen.) This happens in VxWorks. */
1532 free_named_symtabs (pst
->filename
);
1534 if (comp_unit_die
.has_stmt_list
)
1536 /* Get the list of files included in the current compilation unit,
1537 and build a psymtab for each of them. */
1538 dwarf2_build_include_psymtabs (&cu
, &comp_unit_die
, pst
);
1541 info_ptr
= beg_of_comp_unit
+ cu
.header
.length
1542 + cu
.header
.initial_length_size
;
1544 do_cleanups (back_to_inner
);
1546 do_cleanups (back_to
);
1549 /* Load the DIEs for a secondary CU into memory. */
1552 load_comp_unit (struct dwarf2_per_cu_data
*this_cu
, struct objfile
*objfile
)
1554 bfd
*abfd
= objfile
->obfd
;
1555 char *info_ptr
, *beg_of_comp_unit
;
1556 struct partial_die_info comp_unit_die
;
1557 struct dwarf2_cu
*cu
;
1558 struct abbrev_info
*abbrev
;
1559 unsigned int bytes_read
;
1560 struct cleanup
*back_to
;
1562 info_ptr
= dwarf2_per_objfile
->info_buffer
+ this_cu
->offset
;
1563 beg_of_comp_unit
= info_ptr
;
1565 cu
= xmalloc (sizeof (struct dwarf2_cu
));
1566 memset (cu
, 0, sizeof (struct dwarf2_cu
));
1568 obstack_init (&cu
->comp_unit_obstack
);
1570 cu
->objfile
= objfile
;
1571 info_ptr
= partial_read_comp_unit_head (&cu
->header
, info_ptr
, abfd
);
1573 /* Complete the cu_header. */
1574 cu
->header
.offset
= beg_of_comp_unit
- dwarf2_per_objfile
->info_buffer
;
1575 cu
->header
.first_die_ptr
= info_ptr
;
1576 cu
->header
.cu_head_ptr
= beg_of_comp_unit
;
1578 /* Read the abbrevs for this compilation unit into a table. */
1579 dwarf2_read_abbrevs (abfd
, cu
);
1580 back_to
= make_cleanup (dwarf2_free_abbrev_table
, cu
);
1582 /* Read the compilation unit die. */
1583 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
1584 info_ptr
= read_partial_die (&comp_unit_die
, abbrev
, bytes_read
,
1585 abfd
, info_ptr
, cu
);
1587 /* Set the language we're debugging. */
1588 set_cu_language (comp_unit_die
.language
, cu
);
1590 /* Link this compilation unit into the compilation unit tree. */
1592 cu
->per_cu
= this_cu
;
1594 /* Check if comp unit has_children.
1595 If so, read the rest of the partial symbols from this comp unit.
1596 If not, there's no more debug_info for this comp unit. */
1597 if (comp_unit_die
.has_children
)
1598 load_partial_dies (abfd
, info_ptr
, 0, cu
);
1600 do_cleanups (back_to
);
1603 /* Create a list of all compilation units in OBJFILE. We do this only
1604 if an inter-comp-unit reference is found; presumably if there is one,
1605 there will be many, and one will occur early in the .debug_info section.
1606 So there's no point in building this list incrementally. */
1609 create_all_comp_units (struct objfile
*objfile
)
1613 struct dwarf2_per_cu_data
**all_comp_units
;
1614 char *info_ptr
= dwarf2_per_objfile
->info_buffer
;
1618 all_comp_units
= xmalloc (n_allocated
1619 * sizeof (struct dwarf2_per_cu_data
*));
1621 while (info_ptr
< dwarf2_per_objfile
->info_buffer
+ dwarf2_per_objfile
->info_size
)
1623 struct comp_unit_head cu_header
;
1624 char *beg_of_comp_unit
;
1625 struct dwarf2_per_cu_data
*this_cu
;
1626 unsigned long offset
;
1629 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
1631 /* Read just enough information to find out where the next
1632 compilation unit is. */
1633 cu_header
.length
= read_initial_length (objfile
->obfd
, info_ptr
,
1634 &cu_header
, &bytes_read
);
1636 /* Save the compilation unit for later lookup. */
1637 this_cu
= obstack_alloc (&objfile
->objfile_obstack
,
1638 sizeof (struct dwarf2_per_cu_data
));
1639 memset (this_cu
, 0, sizeof (*this_cu
));
1640 this_cu
->offset
= offset
;
1641 this_cu
->length
= cu_header
.length
+ cu_header
.initial_length_size
;
1643 if (n_comp_units
== n_allocated
)
1646 all_comp_units
= xrealloc (all_comp_units
,
1648 * sizeof (struct dwarf2_per_cu_data
*));
1650 all_comp_units
[n_comp_units
++] = this_cu
;
1652 info_ptr
= info_ptr
+ this_cu
->length
;
1655 dwarf2_per_objfile
->all_comp_units
1656 = obstack_alloc (&objfile
->objfile_obstack
,
1657 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1658 memcpy (dwarf2_per_objfile
->all_comp_units
, all_comp_units
,
1659 n_comp_units
* sizeof (struct dwarf2_per_cu_data
*));
1660 xfree (all_comp_units
);
1661 dwarf2_per_objfile
->n_comp_units
= n_comp_units
;
1664 /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE.
1665 Also set *LOWPC and *HIGHPC to the lowest and highest PC values found
1669 scan_partial_symbols (struct partial_die_info
*first_die
, CORE_ADDR
*lowpc
,
1670 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
1672 struct objfile
*objfile
= cu
->objfile
;
1673 bfd
*abfd
= objfile
->obfd
;
1674 struct partial_die_info
*pdi
;
1676 /* Now, march along the PDI's, descending into ones which have
1677 interesting children but skipping the children of the other ones,
1678 until we reach the end of the compilation unit. */
1684 fixup_partial_die (pdi
, cu
);
1686 /* Anonymous namespaces have no name but have interesting
1687 children, so we need to look at them. Ditto for anonymous
1690 if (pdi
->name
!= NULL
|| pdi
->tag
== DW_TAG_namespace
1691 || pdi
->tag
== DW_TAG_enumeration_type
)
1695 case DW_TAG_subprogram
:
1696 if (pdi
->has_pc_info
)
1698 if (pdi
->lowpc
< *lowpc
)
1700 *lowpc
= pdi
->lowpc
;
1702 if (pdi
->highpc
> *highpc
)
1704 *highpc
= pdi
->highpc
;
1706 if (!pdi
->is_declaration
)
1708 add_partial_symbol (pdi
, cu
);
1712 case DW_TAG_variable
:
1713 case DW_TAG_typedef
:
1714 case DW_TAG_union_type
:
1715 if (!pdi
->is_declaration
)
1717 add_partial_symbol (pdi
, cu
);
1720 case DW_TAG_class_type
:
1721 case DW_TAG_structure_type
:
1722 if (!pdi
->is_declaration
)
1724 add_partial_symbol (pdi
, cu
);
1727 case DW_TAG_enumeration_type
:
1728 if (!pdi
->is_declaration
)
1729 add_partial_enumeration (pdi
, cu
);
1731 case DW_TAG_base_type
:
1732 case DW_TAG_subrange_type
:
1733 /* File scope base type definitions are added to the partial
1735 add_partial_symbol (pdi
, cu
);
1737 case DW_TAG_namespace
:
1738 add_partial_namespace (pdi
, lowpc
, highpc
, cu
);
1745 /* If the die has a sibling, skip to the sibling. */
1747 pdi
= pdi
->die_sibling
;
1751 /* Functions used to compute the fully scoped name of a partial DIE.
1753 Normally, this is simple. For C++, the parent DIE's fully scoped
1754 name is concatenated with "::" and the partial DIE's name. For
1755 Java, the same thing occurs except that "." is used instead of "::".
1756 Enumerators are an exception; they use the scope of their parent
1757 enumeration type, i.e. the name of the enumeration type is not
1758 prepended to the enumerator.
1760 There are two complexities. One is DW_AT_specification; in this
1761 case "parent" means the parent of the target of the specification,
1762 instead of the direct parent of the DIE. The other is compilers
1763 which do not emit DW_TAG_namespace; in this case we try to guess
1764 the fully qualified name of structure types from their members'
1765 linkage names. This must be done using the DIE's children rather
1766 than the children of any DW_AT_specification target. We only need
1767 to do this for structures at the top level, i.e. if the target of
1768 any DW_AT_specification (if any; otherwise the DIE itself) does not
1771 /* Compute the scope prefix associated with PDI's parent, in
1772 compilation unit CU. The result will be allocated on CU's
1773 comp_unit_obstack, or a copy of the already allocated PDI->NAME
1774 field. NULL is returned if no prefix is necessary. */
1776 partial_die_parent_scope (struct partial_die_info
*pdi
,
1777 struct dwarf2_cu
*cu
)
1779 char *grandparent_scope
;
1780 struct partial_die_info
*parent
, *real_pdi
;
1781 struct dwarf2_cu
*spec_cu
;
1783 /* We need to look at our parent DIE; if we have a DW_AT_specification,
1784 then this means the parent of the specification DIE. */
1788 while (real_pdi
->has_specification
)
1789 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
1791 parent
= real_pdi
->die_parent
;
1795 if (parent
->scope_set
)
1796 return parent
->scope
;
1798 fixup_partial_die (parent
, cu
);
1800 grandparent_scope
= partial_die_parent_scope (parent
, spec_cu
);
1802 if (parent
->tag
== DW_TAG_namespace
1803 || parent
->tag
== DW_TAG_structure_type
1804 || parent
->tag
== DW_TAG_class_type
1805 || parent
->tag
== DW_TAG_union_type
)
1807 if (grandparent_scope
== NULL
)
1808 parent
->scope
= parent
->name
;
1810 parent
->scope
= typename_concat (&cu
->comp_unit_obstack
, grandparent_scope
,
1813 else if (parent
->tag
== DW_TAG_enumeration_type
)
1814 /* Enumerators should not get the name of the enumeration as a prefix. */
1815 parent
->scope
= grandparent_scope
;
1818 /* FIXME drow/2004-04-01: What should we be doing with
1819 function-local names? For partial symbols, we should probably be
1821 complaint (&symfile_complaints
,
1822 "unhandled containing DIE tag %d for DIE at %d",
1823 parent
->tag
, pdi
->offset
);
1824 parent
->scope
= grandparent_scope
;
1827 parent
->scope_set
= 1;
1828 return parent
->scope
;
1831 /* Return the fully scoped name associated with PDI, from compilation unit
1832 CU. The result will be allocated with malloc. */
1834 partial_die_full_name (struct partial_die_info
*pdi
,
1835 struct dwarf2_cu
*cu
)
1839 parent_scope
= partial_die_parent_scope (pdi
, cu
);
1840 if (parent_scope
== NULL
)
1843 return typename_concat (NULL
, parent_scope
, pdi
->name
, cu
);
1847 add_partial_symbol (struct partial_die_info
*pdi
, struct dwarf2_cu
*cu
)
1849 struct objfile
*objfile
= cu
->objfile
;
1852 const char *my_prefix
;
1853 const struct partial_symbol
*psym
= NULL
;
1855 int built_actual_name
= 0;
1857 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1861 if (pdi_needs_namespace (pdi
->tag
))
1863 actual_name
= partial_die_full_name (pdi
, cu
);
1865 built_actual_name
= 1;
1868 if (actual_name
== NULL
)
1869 actual_name
= pdi
->name
;
1873 case DW_TAG_subprogram
:
1874 if (pdi
->is_external
)
1876 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1877 mst_text, objfile); */
1878 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1879 VAR_DOMAIN
, LOC_BLOCK
,
1880 &objfile
->global_psymbols
,
1881 0, pdi
->lowpc
+ baseaddr
,
1882 cu
->language
, objfile
);
1886 /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr,
1887 mst_file_text, objfile); */
1888 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1889 VAR_DOMAIN
, LOC_BLOCK
,
1890 &objfile
->static_psymbols
,
1891 0, pdi
->lowpc
+ baseaddr
,
1892 cu
->language
, objfile
);
1895 case DW_TAG_variable
:
1896 if (pdi
->is_external
)
1899 Don't enter into the minimal symbol tables as there is
1900 a minimal symbol table entry from the ELF symbols already.
1901 Enter into partial symbol table if it has a location
1902 descriptor or a type.
1903 If the location descriptor is missing, new_symbol will create
1904 a LOC_UNRESOLVED symbol, the address of the variable will then
1905 be determined from the minimal symbol table whenever the variable
1907 The address for the partial symbol table entry is not
1908 used by GDB, but it comes in handy for debugging partial symbol
1912 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1913 if (pdi
->locdesc
|| pdi
->has_type
)
1914 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1915 VAR_DOMAIN
, LOC_STATIC
,
1916 &objfile
->global_psymbols
,
1918 cu
->language
, objfile
);
1922 /* Static Variable. Skip symbols without location descriptors. */
1923 if (pdi
->locdesc
== NULL
)
1925 addr
= decode_locdesc (pdi
->locdesc
, cu
);
1926 /*prim_record_minimal_symbol (actual_name, addr + baseaddr,
1927 mst_file_data, objfile); */
1928 psym
= add_psymbol_to_list (actual_name
, strlen (actual_name
),
1929 VAR_DOMAIN
, LOC_STATIC
,
1930 &objfile
->static_psymbols
,
1932 cu
->language
, objfile
);
1935 case DW_TAG_typedef
:
1936 case DW_TAG_base_type
:
1937 case DW_TAG_subrange_type
:
1938 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1939 VAR_DOMAIN
, LOC_TYPEDEF
,
1940 &objfile
->static_psymbols
,
1941 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1943 case DW_TAG_namespace
:
1944 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1945 VAR_DOMAIN
, LOC_TYPEDEF
,
1946 &objfile
->global_psymbols
,
1947 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1949 case DW_TAG_class_type
:
1950 case DW_TAG_structure_type
:
1951 case DW_TAG_union_type
:
1952 case DW_TAG_enumeration_type
:
1953 /* Skip aggregate types without children, these are external
1955 /* NOTE: carlton/2003-10-07: See comment in new_symbol about
1956 static vs. global. */
1957 if (pdi
->has_children
== 0)
1959 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1960 STRUCT_DOMAIN
, LOC_TYPEDEF
,
1961 (cu
->language
== language_cplus
1962 || cu
->language
== language_java
)
1963 ? &objfile
->global_psymbols
1964 : &objfile
->static_psymbols
,
1965 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1967 if (cu
->language
== language_cplus
1968 || cu
->language
== language_java
)
1970 /* For C++ and Java, these implicitly act as typedefs as well. */
1971 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1972 VAR_DOMAIN
, LOC_TYPEDEF
,
1973 &objfile
->global_psymbols
,
1974 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1977 case DW_TAG_enumerator
:
1978 add_psymbol_to_list (actual_name
, strlen (actual_name
),
1979 VAR_DOMAIN
, LOC_CONST
,
1980 (cu
->language
== language_cplus
1981 || cu
->language
== language_java
)
1982 ? &objfile
->global_psymbols
1983 : &objfile
->static_psymbols
,
1984 0, (CORE_ADDR
) 0, cu
->language
, objfile
);
1990 /* Check to see if we should scan the name for possible namespace
1991 info. Only do this if this is C++, if we don't have namespace
1992 debugging info in the file, if the psym is of an appropriate type
1993 (otherwise we'll have psym == NULL), and if we actually had a
1994 mangled name to begin with. */
1996 /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the
1997 cases which do not set PSYM above? */
1999 if (cu
->language
== language_cplus
2000 && cu
->has_namespace_info
== 0
2002 && SYMBOL_CPLUS_DEMANGLED_NAME (psym
) != NULL
)
2003 cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym
),
2006 if (built_actual_name
)
2007 xfree (actual_name
);
2010 /* Determine whether a die of type TAG living in a C++ class or
2011 namespace needs to have the name of the scope prepended to the
2012 name listed in the die. */
2015 pdi_needs_namespace (enum dwarf_tag tag
)
2019 case DW_TAG_namespace
:
2020 case DW_TAG_typedef
:
2021 case DW_TAG_class_type
:
2022 case DW_TAG_structure_type
:
2023 case DW_TAG_union_type
:
2024 case DW_TAG_enumeration_type
:
2025 case DW_TAG_enumerator
:
2032 /* Read a partial die corresponding to a namespace; also, add a symbol
2033 corresponding to that namespace to the symbol table. NAMESPACE is
2034 the name of the enclosing namespace. */
2037 add_partial_namespace (struct partial_die_info
*pdi
,
2038 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
2039 struct dwarf2_cu
*cu
)
2041 struct objfile
*objfile
= cu
->objfile
;
2043 /* Add a symbol for the namespace. */
2045 add_partial_symbol (pdi
, cu
);
2047 /* Now scan partial symbols in that namespace. */
2049 if (pdi
->has_children
)
2050 scan_partial_symbols (pdi
->die_child
, lowpc
, highpc
, cu
);
2053 /* See if we can figure out if the class lives in a namespace. We do
2054 this by looking for a member function; its demangled name will
2055 contain namespace info, if there is any. */
2058 guess_structure_name (struct partial_die_info
*struct_pdi
,
2059 struct dwarf2_cu
*cu
)
2061 if ((cu
->language
== language_cplus
2062 || cu
->language
== language_java
)
2063 && cu
->has_namespace_info
== 0
2064 && struct_pdi
->has_children
)
2066 /* NOTE: carlton/2003-10-07: Getting the info this way changes
2067 what template types look like, because the demangler
2068 frequently doesn't give the same name as the debug info. We
2069 could fix this by only using the demangled name to get the
2070 prefix (but see comment in read_structure_type). */
2072 struct partial_die_info
*child_pdi
= struct_pdi
->die_child
;
2073 struct partial_die_info
*real_pdi
;
2074 struct dwarf2_cu
*spec_cu
;
2076 /* If this DIE (this DIE's specification, if any) has a parent, then
2077 we should not do this. We'll prepend the parent's fully qualified
2078 name when we create the partial symbol. */
2080 real_pdi
= struct_pdi
;
2082 while (real_pdi
->has_specification
)
2083 real_pdi
= find_partial_die (real_pdi
->spec_offset
, spec_cu
, &spec_cu
);
2085 if (real_pdi
->die_parent
!= NULL
)
2088 while (child_pdi
!= NULL
)
2090 if (child_pdi
->tag
== DW_TAG_subprogram
)
2092 char *actual_class_name
2093 = language_class_name_from_physname (cu
->language_defn
,
2095 if (actual_class_name
!= NULL
)
2098 = obsavestring (actual_class_name
,
2099 strlen (actual_class_name
),
2100 &cu
->comp_unit_obstack
);
2101 xfree (actual_class_name
);
2106 child_pdi
= child_pdi
->die_sibling
;
2111 /* Read a partial die corresponding to an enumeration type. */
2114 add_partial_enumeration (struct partial_die_info
*enum_pdi
,
2115 struct dwarf2_cu
*cu
)
2117 struct objfile
*objfile
= cu
->objfile
;
2118 bfd
*abfd
= objfile
->obfd
;
2119 struct partial_die_info
*pdi
;
2121 if (enum_pdi
->name
!= NULL
)
2122 add_partial_symbol (enum_pdi
, cu
);
2124 pdi
= enum_pdi
->die_child
;
2127 if (pdi
->tag
!= DW_TAG_enumerator
|| pdi
->name
== NULL
)
2128 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
2130 add_partial_symbol (pdi
, cu
);
2131 pdi
= pdi
->die_sibling
;
2135 /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU.
2136 Return the corresponding abbrev, or NULL if the number is zero (indicating
2137 an empty DIE). In either case *BYTES_READ will be set to the length of
2138 the initial number. */
2140 static struct abbrev_info
*
2141 peek_die_abbrev (char *info_ptr
, int *bytes_read
, struct dwarf2_cu
*cu
)
2143 bfd
*abfd
= cu
->objfile
->obfd
;
2144 unsigned int abbrev_number
;
2145 struct abbrev_info
*abbrev
;
2147 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, bytes_read
);
2149 if (abbrev_number
== 0)
2152 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
2155 error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number
,
2156 bfd_get_filename (abfd
));
2162 /* Scan the debug information for CU starting at INFO_PTR. Returns a
2163 pointer to the end of a series of DIEs, terminated by an empty
2164 DIE. Any children of the skipped DIEs will also be skipped. */
2167 skip_children (char *info_ptr
, struct dwarf2_cu
*cu
)
2169 struct abbrev_info
*abbrev
;
2170 unsigned int bytes_read
;
2174 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
2176 return info_ptr
+ bytes_read
;
2178 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
2182 /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR
2183 should point just after the initial uleb128 of a DIE, and the
2184 abbrev corresponding to that skipped uleb128 should be passed in
2185 ABBREV. Returns a pointer to this DIE's sibling, skipping any
2189 skip_one_die (char *info_ptr
, struct abbrev_info
*abbrev
,
2190 struct dwarf2_cu
*cu
)
2192 unsigned int bytes_read
;
2193 struct attribute attr
;
2194 bfd
*abfd
= cu
->objfile
->obfd
;
2195 unsigned int form
, i
;
2197 for (i
= 0; i
< abbrev
->num_attrs
; i
++)
2199 /* The only abbrev we care about is DW_AT_sibling. */
2200 if (abbrev
->attrs
[i
].name
== DW_AT_sibling
)
2202 read_attribute (&attr
, &abbrev
->attrs
[i
],
2203 abfd
, info_ptr
, cu
);
2204 if (attr
.form
== DW_FORM_ref_addr
)
2205 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
2207 return dwarf2_per_objfile
->info_buffer
2208 + dwarf2_get_ref_die_offset (&attr
, cu
);
2211 /* If it isn't DW_AT_sibling, skip this attribute. */
2212 form
= abbrev
->attrs
[i
].form
;
2217 case DW_FORM_ref_addr
:
2218 info_ptr
+= cu
->header
.addr_size
;
2237 case DW_FORM_string
:
2238 read_string (abfd
, info_ptr
, &bytes_read
);
2239 info_ptr
+= bytes_read
;
2242 info_ptr
+= cu
->header
.offset_size
;
2245 info_ptr
+= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2246 info_ptr
+= bytes_read
;
2248 case DW_FORM_block1
:
2249 info_ptr
+= 1 + read_1_byte (abfd
, info_ptr
);
2251 case DW_FORM_block2
:
2252 info_ptr
+= 2 + read_2_bytes (abfd
, info_ptr
);
2254 case DW_FORM_block4
:
2255 info_ptr
+= 4 + read_4_bytes (abfd
, info_ptr
);
2259 case DW_FORM_ref_udata
:
2260 info_ptr
= skip_leb128 (abfd
, info_ptr
);
2262 case DW_FORM_indirect
:
2263 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
2264 info_ptr
+= bytes_read
;
2265 /* We need to continue parsing from here, so just go back to
2267 goto skip_attribute
;
2270 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
2271 dwarf_form_name (form
),
2272 bfd_get_filename (abfd
));
2276 if (abbrev
->has_children
)
2277 return skip_children (info_ptr
, cu
);
2282 /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of
2283 the next DIE after ORIG_PDI. */
2286 locate_pdi_sibling (struct partial_die_info
*orig_pdi
, char *info_ptr
,
2287 bfd
*abfd
, struct dwarf2_cu
*cu
)
2289 /* Do we know the sibling already? */
2291 if (orig_pdi
->sibling
)
2292 return orig_pdi
->sibling
;
2294 /* Are there any children to deal with? */
2296 if (!orig_pdi
->has_children
)
2299 /* Skip the children the long way. */
2301 return skip_children (info_ptr
, cu
);
2304 /* Expand this partial symbol table into a full symbol table. */
2307 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
2309 /* FIXME: This is barely more than a stub. */
2314 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
2320 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2321 gdb_flush (gdb_stdout
);
2324 psymtab_to_symtab_1 (pst
);
2326 /* Finish up the debug error message. */
2328 printf_filtered ("done.\n");
2334 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
2336 struct objfile
*objfile
= pst
->objfile
;
2337 bfd
*abfd
= objfile
->obfd
;
2338 struct dwarf2_cu cu
;
2339 struct die_info
*dies
;
2340 unsigned long offset
;
2341 CORE_ADDR lowpc
, highpc
;
2342 struct die_info
*child_die
;
2344 struct symtab
*symtab
;
2345 struct cleanup
*back_to
;
2346 struct attribute
*attr
;
2350 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2351 if (!pst
->dependencies
[i
]->readin
)
2353 /* Inform about additional files that need to be read in. */
2356 fputs_filtered (" ", gdb_stdout
);
2358 fputs_filtered ("and ", gdb_stdout
);
2360 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2361 wrap_here (""); /* Flush output */
2362 gdb_flush (gdb_stdout
);
2364 psymtab_to_symtab_1 (pst
->dependencies
[i
]);
2367 if (pst
->read_symtab_private
== NULL
)
2369 /* It's an include file, no symbols to read for it.
2370 Everything is in the parent symtab. */
2375 dwarf2_per_objfile
= objfile_data (pst
->objfile
, dwarf2_objfile_data_key
);
2377 /* Set local variables from the partial symbol table info. */
2378 offset
= DWARF_INFO_OFFSET (pst
);
2380 info_ptr
= dwarf2_per_objfile
->info_buffer
+ offset
;
2381 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2383 /* We're in the global namespace. */
2384 processing_current_prefix
= "";
2386 memset (&cu
, 0, sizeof (struct dwarf2_cu
));
2387 obstack_init (&cu
.comp_unit_obstack
);
2388 back_to
= make_cleanup (free_stack_comp_unit
, &cu
);
2391 make_cleanup (really_free_pendings
, NULL
);
2393 cu
.objfile
= objfile
;
2395 /* read in the comp_unit header */
2396 info_ptr
= read_comp_unit_head (&cu
.header
, info_ptr
, abfd
);
2398 /* Read the abbrevs for this compilation unit */
2399 dwarf2_read_abbrevs (abfd
, &cu
);
2400 make_cleanup (dwarf2_free_abbrev_table
, &cu
);
2402 cu
.header
.offset
= offset
;
2404 cu
.list_in_scope
= &file_symbols
;
2406 dies
= read_comp_unit (info_ptr
, abfd
, &cu
);
2408 make_cleanup_free_die_list (dies
);
2410 /* Find the base address of the compilation unit for range lists and
2411 location lists. It will normally be specified by DW_AT_low_pc.
2412 In DWARF-3 draft 4, the base address could be overridden by
2413 DW_AT_entry_pc. It's been removed, but GCC still uses this for
2414 compilation units with discontinuous ranges. */
2416 cu
.header
.base_known
= 0;
2417 cu
.header
.base_address
= 0;
2419 attr
= dwarf2_attr (dies
, DW_AT_entry_pc
, &cu
);
2422 cu
.header
.base_address
= DW_ADDR (attr
);
2423 cu
.header
.base_known
= 1;
2427 attr
= dwarf2_attr (dies
, DW_AT_low_pc
, &cu
);
2430 cu
.header
.base_address
= DW_ADDR (attr
);
2431 cu
.header
.base_known
= 1;
2435 /* Do line number decoding in read_file_scope () */
2436 process_die (dies
, &cu
);
2438 /* Some compilers don't define a DW_AT_high_pc attribute for the
2439 compilation unit. If the DW_AT_high_pc is missing, synthesize
2440 it, by scanning the DIE's below the compilation unit. */
2441 get_scope_pc_bounds (dies
, &lowpc
, &highpc
, &cu
);
2443 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
2445 /* Set symtab language to language from DW_AT_language.
2446 If the compilation is from a C file generated by language preprocessors,
2447 do not set the language if it was already deduced by start_subfile. */
2449 && !(cu
.language
== language_c
&& symtab
->language
!= language_c
))
2451 symtab
->language
= cu
.language
;
2453 pst
->symtab
= symtab
;
2456 do_cleanups (back_to
);
2459 /* Process a die and its children. */
2462 process_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
2466 case DW_TAG_padding
:
2468 case DW_TAG_compile_unit
:
2469 read_file_scope (die
, cu
);
2471 case DW_TAG_subprogram
:
2472 read_subroutine_type (die
, cu
);
2473 read_func_scope (die
, cu
);
2475 case DW_TAG_inlined_subroutine
:
2476 /* FIXME: These are ignored for now.
2477 They could be used to set breakpoints on all inlined instances
2478 of a function and make GDB `next' properly over inlined functions. */
2480 case DW_TAG_lexical_block
:
2481 case DW_TAG_try_block
:
2482 case DW_TAG_catch_block
:
2483 read_lexical_block_scope (die
, cu
);
2485 case DW_TAG_class_type
:
2486 case DW_TAG_structure_type
:
2487 case DW_TAG_union_type
:
2488 read_structure_type (die
, cu
);
2489 process_structure_scope (die
, cu
);
2491 case DW_TAG_enumeration_type
:
2492 read_enumeration_type (die
, cu
);
2493 process_enumeration_scope (die
, cu
);
2496 /* FIXME drow/2004-03-14: These initialize die->type, but do not create
2497 a symbol or process any children. Therefore it doesn't do anything
2498 that won't be done on-demand by read_type_die. */
2499 case DW_TAG_subroutine_type
:
2500 read_subroutine_type (die
, cu
);
2502 case DW_TAG_array_type
:
2503 read_array_type (die
, cu
);
2505 case DW_TAG_pointer_type
:
2506 read_tag_pointer_type (die
, cu
);
2508 case DW_TAG_ptr_to_member_type
:
2509 read_tag_ptr_to_member_type (die
, cu
);
2511 case DW_TAG_reference_type
:
2512 read_tag_reference_type (die
, cu
);
2514 case DW_TAG_string_type
:
2515 read_tag_string_type (die
, cu
);
2519 case DW_TAG_base_type
:
2520 read_base_type (die
, cu
);
2521 /* Add a typedef symbol for the type definition, if it has a
2523 new_symbol (die
, die
->type
, cu
);
2525 case DW_TAG_subrange_type
:
2526 read_subrange_type (die
, cu
);
2527 /* Add a typedef symbol for the type definition, if it has a
2529 new_symbol (die
, die
->type
, cu
);
2531 case DW_TAG_common_block
:
2532 read_common_block (die
, cu
);
2534 case DW_TAG_common_inclusion
:
2536 case DW_TAG_namespace
:
2537 processing_has_namespace_info
= 1;
2538 read_namespace (die
, cu
);
2540 case DW_TAG_imported_declaration
:
2541 case DW_TAG_imported_module
:
2542 /* FIXME: carlton/2002-10-16: Eventually, we should use the
2543 information contained in these. DW_TAG_imported_declaration
2544 dies shouldn't have children; DW_TAG_imported_module dies
2545 shouldn't in the C++ case, but conceivably could in the
2546 Fortran case, so we'll have to replace this gdb_assert if
2547 Fortran compilers start generating that info. */
2548 processing_has_namespace_info
= 1;
2549 gdb_assert (die
->child
== NULL
);
2552 new_symbol (die
, NULL
, cu
);
2558 initialize_cu_func_list (struct dwarf2_cu
*cu
)
2560 cu
->first_fn
= cu
->last_fn
= cu
->cached_fn
= NULL
;
2564 read_file_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2566 struct objfile
*objfile
= cu
->objfile
;
2567 struct comp_unit_head
*cu_header
= &cu
->header
;
2568 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
2569 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
2570 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
2571 struct attribute
*attr
;
2572 char *name
= "<unknown>";
2573 char *comp_dir
= NULL
;
2574 struct die_info
*child_die
;
2575 bfd
*abfd
= objfile
->obfd
;
2576 struct line_header
*line_header
= 0;
2579 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2581 get_scope_pc_bounds (die
, &lowpc
, &highpc
, cu
);
2583 /* If we didn't find a lowpc, set it to highpc to avoid complaints
2584 from finish_block. */
2585 if (lowpc
== ((CORE_ADDR
) -1))
2590 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
2593 name
= DW_STRING (attr
);
2595 attr
= dwarf2_attr (die
, DW_AT_comp_dir
, cu
);
2598 comp_dir
= DW_STRING (attr
);
2601 /* Irix 6.2 native cc prepends <machine>.: to the compilation
2602 directory, get rid of it. */
2603 char *cp
= strchr (comp_dir
, ':');
2605 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
2610 attr
= dwarf2_attr (die
, DW_AT_language
, cu
);
2613 set_cu_language (DW_UNSND (attr
), cu
);
2616 attr
= dwarf2_attr (die
, DW_AT_producer
, cu
);
2618 cu
->producer
= DW_STRING (attr
);
2620 /* We assume that we're processing GCC output. */
2621 processing_gcc_compilation
= 2;
2623 /* FIXME:Do something here. */
2624 if (dip
->at_producer
!= NULL
)
2626 handle_producer (dip
->at_producer
);
2630 /* The compilation unit may be in a different language or objfile,
2631 zero out all remembered fundamental types. */
2632 memset (cu
->ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
2634 start_symtab (name
, comp_dir
, lowpc
);
2635 record_debugformat ("DWARF 2");
2637 initialize_cu_func_list (cu
);
2639 /* Process all dies in compilation unit. */
2640 if (die
->child
!= NULL
)
2642 child_die
= die
->child
;
2643 while (child_die
&& child_die
->tag
)
2645 process_die (child_die
, cu
);
2646 child_die
= sibling_die (child_die
);
2650 /* Decode line number information if present. */
2651 attr
= dwarf2_attr (die
, DW_AT_stmt_list
, cu
);
2654 unsigned int line_offset
= DW_UNSND (attr
);
2655 line_header
= dwarf_decode_line_header (line_offset
, abfd
, cu
);
2658 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
2659 (void *) line_header
);
2660 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu
, NULL
);
2664 /* Decode macro information, if present. Dwarf 2 macro information
2665 refers to information in the line number info statement program
2666 header, so we can only read it if we've read the header
2668 attr
= dwarf2_attr (die
, DW_AT_macro_info
, cu
);
2669 if (attr
&& line_header
)
2671 unsigned int macro_offset
= DW_UNSND (attr
);
2672 dwarf_decode_macros (line_header
, macro_offset
,
2673 comp_dir
, abfd
, cu
);
2675 do_cleanups (back_to
);
2679 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
,
2680 struct dwarf2_cu
*cu
)
2682 struct function_range
*thisfn
;
2684 thisfn
= (struct function_range
*)
2685 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct function_range
));
2686 thisfn
->name
= name
;
2687 thisfn
->lowpc
= lowpc
;
2688 thisfn
->highpc
= highpc
;
2689 thisfn
->seen_line
= 0;
2690 thisfn
->next
= NULL
;
2692 if (cu
->last_fn
== NULL
)
2693 cu
->first_fn
= thisfn
;
2695 cu
->last_fn
->next
= thisfn
;
2697 cu
->last_fn
= thisfn
;
2701 read_func_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2703 struct objfile
*objfile
= cu
->objfile
;
2704 struct context_stack
*new;
2707 struct die_info
*child_die
;
2708 struct attribute
*attr
;
2710 const char *previous_prefix
= processing_current_prefix
;
2711 struct cleanup
*back_to
= NULL
;
2714 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2716 name
= dwarf2_linkage_name (die
, cu
);
2718 /* Ignore functions with missing or empty names and functions with
2719 missing or invalid low and high pc attributes. */
2720 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2723 if (cu
->language
== language_cplus
2724 || cu
->language
== language_java
)
2726 struct die_info
*spec_die
= die_specification (die
, cu
);
2728 /* NOTE: carlton/2004-01-23: We have to be careful in the
2729 presence of DW_AT_specification. For example, with GCC 3.4,
2734 // Definition of N::foo.
2738 then we'll have a tree of DIEs like this:
2740 1: DW_TAG_compile_unit
2741 2: DW_TAG_namespace // N
2742 3: DW_TAG_subprogram // declaration of N::foo
2743 4: DW_TAG_subprogram // definition of N::foo
2744 DW_AT_specification // refers to die #3
2746 Thus, when processing die #4, we have to pretend that we're
2747 in the context of its DW_AT_specification, namely the contex
2750 if (spec_die
!= NULL
)
2752 char *specification_prefix
= determine_prefix (spec_die
, cu
);
2753 processing_current_prefix
= specification_prefix
;
2754 back_to
= make_cleanup (xfree
, specification_prefix
);
2761 /* Record the function range for dwarf_decode_lines. */
2762 add_to_cu_func_list (name
, lowpc
, highpc
, cu
);
2764 new = push_context (0, lowpc
);
2765 new->name
= new_symbol (die
, die
->type
, cu
);
2767 /* If there is a location expression for DW_AT_frame_base, record
2769 attr
= dwarf2_attr (die
, DW_AT_frame_base
, cu
);
2771 /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location
2772 expression is being recorded directly in the function's symbol
2773 and not in a separate frame-base object. I guess this hack is
2774 to avoid adding some sort of frame-base adjunct/annex to the
2775 function's symbol :-(. The problem with doing this is that it
2776 results in a function symbol with a location expression that
2777 has nothing to do with the location of the function, ouch! The
2778 relationship should be: a function's symbol has-a frame base; a
2779 frame-base has-a location expression. */
2780 dwarf2_symbol_mark_computed (attr
, new->name
, cu
);
2782 cu
->list_in_scope
= &local_symbols
;
2784 if (die
->child
!= NULL
)
2786 child_die
= die
->child
;
2787 while (child_die
&& child_die
->tag
)
2789 process_die (child_die
, cu
);
2790 child_die
= sibling_die (child_die
);
2794 new = pop_context ();
2795 /* Make a block for the local symbols within. */
2796 finish_block (new->name
, &local_symbols
, new->old_blocks
,
2797 lowpc
, highpc
, objfile
);
2799 /* In C++, we can have functions nested inside functions (e.g., when
2800 a function declares a class that has methods). This means that
2801 when we finish processing a function scope, we may need to go
2802 back to building a containing block's symbol lists. */
2803 local_symbols
= new->locals
;
2804 param_symbols
= new->params
;
2806 /* If we've finished processing a top-level function, subsequent
2807 symbols go in the file symbol list. */
2808 if (outermost_context_p ())
2809 cu
->list_in_scope
= &file_symbols
;
2811 processing_current_prefix
= previous_prefix
;
2812 if (back_to
!= NULL
)
2813 do_cleanups (back_to
);
2816 /* Process all the DIES contained within a lexical block scope. Start
2817 a new scope, process the dies, and then close the scope. */
2820 read_lexical_block_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
2822 struct objfile
*objfile
= cu
->objfile
;
2823 struct context_stack
*new;
2824 CORE_ADDR lowpc
, highpc
;
2825 struct die_info
*child_die
;
2828 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2830 /* Ignore blocks with missing or invalid low and high pc attributes. */
2831 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2832 as multiple lexical blocks? Handling children in a sane way would
2833 be nasty. Might be easier to properly extend generic blocks to
2835 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, cu
))
2840 push_context (0, lowpc
);
2841 if (die
->child
!= NULL
)
2843 child_die
= die
->child
;
2844 while (child_die
&& child_die
->tag
)
2846 process_die (child_die
, cu
);
2847 child_die
= sibling_die (child_die
);
2850 new = pop_context ();
2852 if (local_symbols
!= NULL
)
2854 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2857 local_symbols
= new->locals
;
2860 /* Get low and high pc attributes from a die. Return 1 if the attributes
2861 are present and valid, otherwise, return 0. Return -1 if the range is
2862 discontinuous, i.e. derived from DW_AT_ranges information. */
2864 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2865 CORE_ADDR
*highpc
, struct dwarf2_cu
*cu
)
2867 struct objfile
*objfile
= cu
->objfile
;
2868 struct comp_unit_head
*cu_header
= &cu
->header
;
2869 struct attribute
*attr
;
2870 bfd
*obfd
= objfile
->obfd
;
2875 attr
= dwarf2_attr (die
, DW_AT_high_pc
, cu
);
2878 high
= DW_ADDR (attr
);
2879 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
2881 low
= DW_ADDR (attr
);
2883 /* Found high w/o low attribute. */
2886 /* Found consecutive range of addresses. */
2891 attr
= dwarf2_attr (die
, DW_AT_ranges
, cu
);
2894 unsigned int addr_size
= cu_header
->addr_size
;
2895 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2896 /* Value of the DW_AT_ranges attribute is the offset in the
2897 .debug_ranges section. */
2898 unsigned int offset
= DW_UNSND (attr
);
2899 /* Base address selection entry. */
2907 found_base
= cu_header
->base_known
;
2908 base
= cu_header
->base_address
;
2910 if (offset
>= dwarf2_per_objfile
->ranges_size
)
2912 complaint (&symfile_complaints
,
2913 "Offset %d out of bounds for DW_AT_ranges attribute",
2917 buffer
= dwarf2_per_objfile
->ranges_buffer
+ offset
;
2919 /* Read in the largest possible address. */
2920 marker
= read_address (obfd
, buffer
, cu
, &dummy
);
2921 if ((marker
& mask
) == mask
)
2923 /* If we found the largest possible address, then
2924 read the base address. */
2925 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2926 buffer
+= 2 * addr_size
;
2927 offset
+= 2 * addr_size
;
2935 CORE_ADDR range_beginning
, range_end
;
2937 range_beginning
= read_address (obfd
, buffer
, cu
, &dummy
);
2938 buffer
+= addr_size
;
2939 range_end
= read_address (obfd
, buffer
, cu
, &dummy
);
2940 buffer
+= addr_size
;
2941 offset
+= 2 * addr_size
;
2943 /* An end of list marker is a pair of zero addresses. */
2944 if (range_beginning
== 0 && range_end
== 0)
2945 /* Found the end of list entry. */
2948 /* Each base address selection entry is a pair of 2 values.
2949 The first is the largest possible address, the second is
2950 the base address. Check for a base address here. */
2951 if ((range_beginning
& mask
) == mask
)
2953 /* If we found the largest possible address, then
2954 read the base address. */
2955 base
= read_address (obfd
, buffer
+ addr_size
, cu
, &dummy
);
2962 /* We have no valid base address for the ranges
2964 complaint (&symfile_complaints
,
2965 "Invalid .debug_ranges data (no base address)");
2969 range_beginning
+= base
;
2972 /* FIXME: This is recording everything as a low-high
2973 segment of consecutive addresses. We should have a
2974 data structure for discontiguous block ranges
2978 low
= range_beginning
;
2984 if (range_beginning
< low
)
2985 low
= range_beginning
;
2986 if (range_end
> high
)
2992 /* If the first entry is an end-of-list marker, the range
2993 describes an empty scope, i.e. no instructions. */
3003 /* When using the GNU linker, .gnu.linkonce. sections are used to
3004 eliminate duplicate copies of functions and vtables and such.
3005 The linker will arbitrarily choose one and discard the others.
3006 The AT_*_pc values for such functions refer to local labels in
3007 these sections. If the section from that file was discarded, the
3008 labels are not in the output, so the relocs get a value of 0.
3009 If this is a discarded function, mark the pc bounds as invalid,
3010 so that GDB will ignore it. */
3011 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
3019 /* Get the low and high pc's represented by the scope DIE, and store
3020 them in *LOWPC and *HIGHPC. If the correct values can't be
3021 determined, set *LOWPC to -1 and *HIGHPC to 0. */
3024 get_scope_pc_bounds (struct die_info
*die
,
3025 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
3026 struct dwarf2_cu
*cu
)
3028 CORE_ADDR best_low
= (CORE_ADDR
) -1;
3029 CORE_ADDR best_high
= (CORE_ADDR
) 0;
3030 CORE_ADDR current_low
, current_high
;
3032 if (dwarf2_get_pc_bounds (die
, ¤t_low
, ¤t_high
, cu
))
3034 best_low
= current_low
;
3035 best_high
= current_high
;
3039 struct die_info
*child
= die
->child
;
3041 while (child
&& child
->tag
)
3043 switch (child
->tag
) {
3044 case DW_TAG_subprogram
:
3045 if (dwarf2_get_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
))
3047 best_low
= min (best_low
, current_low
);
3048 best_high
= max (best_high
, current_high
);
3051 case DW_TAG_namespace
:
3052 /* FIXME: carlton/2004-01-16: Should we do this for
3053 DW_TAG_class_type/DW_TAG_structure_type, too? I think
3054 that current GCC's always emit the DIEs corresponding
3055 to definitions of methods of classes as children of a
3056 DW_TAG_compile_unit or DW_TAG_namespace (as opposed to
3057 the DIEs giving the declarations, which could be
3058 anywhere). But I don't see any reason why the
3059 standards says that they have to be there. */
3060 get_scope_pc_bounds (child
, ¤t_low
, ¤t_high
, cu
);
3062 if (current_low
!= ((CORE_ADDR
) -1))
3064 best_low
= min (best_low
, current_low
);
3065 best_high
= max (best_high
, current_high
);
3073 child
= sibling_die (child
);
3078 *highpc
= best_high
;
3081 /* Add an aggregate field to the field list. */
3084 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
3085 struct dwarf2_cu
*cu
)
3087 struct objfile
*objfile
= cu
->objfile
;
3088 struct nextfield
*new_field
;
3089 struct attribute
*attr
;
3091 char *fieldname
= "";
3093 /* Allocate a new field list entry and link it in. */
3094 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3095 make_cleanup (xfree
, new_field
);
3096 memset (new_field
, 0, sizeof (struct nextfield
));
3097 new_field
->next
= fip
->fields
;
3098 fip
->fields
= new_field
;
3101 /* Handle accessibility and virtuality of field.
3102 The default accessibility for members is public, the default
3103 accessibility for inheritance is private. */
3104 if (die
->tag
!= DW_TAG_inheritance
)
3105 new_field
->accessibility
= DW_ACCESS_public
;
3107 new_field
->accessibility
= DW_ACCESS_private
;
3108 new_field
->virtuality
= DW_VIRTUALITY_none
;
3110 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3112 new_field
->accessibility
= DW_UNSND (attr
);
3113 if (new_field
->accessibility
!= DW_ACCESS_public
)
3114 fip
->non_public_fields
= 1;
3115 attr
= dwarf2_attr (die
, DW_AT_virtuality
, cu
);
3117 new_field
->virtuality
= DW_UNSND (attr
);
3119 fp
= &new_field
->field
;
3121 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
, cu
))
3123 /* Data member other than a C++ static data member. */
3125 /* Get type of field. */
3126 fp
->type
= die_type (die
, cu
);
3128 FIELD_STATIC_KIND (*fp
) = 0;
3130 /* Get bit size of field (zero if none). */
3131 attr
= dwarf2_attr (die
, DW_AT_bit_size
, cu
);
3134 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
3138 FIELD_BITSIZE (*fp
) = 0;
3141 /* Get bit offset of field. */
3142 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3145 FIELD_BITPOS (*fp
) =
3146 decode_locdesc (DW_BLOCK (attr
), cu
) * bits_per_byte
;
3149 FIELD_BITPOS (*fp
) = 0;
3150 attr
= dwarf2_attr (die
, DW_AT_bit_offset
, cu
);
3153 if (BITS_BIG_ENDIAN
)
3155 /* For big endian bits, the DW_AT_bit_offset gives the
3156 additional bit offset from the MSB of the containing
3157 anonymous object to the MSB of the field. We don't
3158 have to do anything special since we don't need to
3159 know the size of the anonymous object. */
3160 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
3164 /* For little endian bits, compute the bit offset to the
3165 MSB of the anonymous object, subtract off the number of
3166 bits from the MSB of the field to the MSB of the
3167 object, and then subtract off the number of bits of
3168 the field itself. The result is the bit offset of
3169 the LSB of the field. */
3171 int bit_offset
= DW_UNSND (attr
);
3173 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3176 /* The size of the anonymous object containing
3177 the bit field is explicit, so use the
3178 indicated size (in bytes). */
3179 anonymous_size
= DW_UNSND (attr
);
3183 /* The size of the anonymous object containing
3184 the bit field must be inferred from the type
3185 attribute of the data member containing the
3187 anonymous_size
= TYPE_LENGTH (fp
->type
);
3189 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
3190 - bit_offset
- FIELD_BITSIZE (*fp
);
3194 /* Get name of field. */
3195 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3196 if (attr
&& DW_STRING (attr
))
3197 fieldname
= DW_STRING (attr
);
3199 /* The name is already allocated along with this objfile, so we don't
3200 need to duplicate it for the type. */
3201 fp
->name
= fieldname
;
3203 /* Change accessibility for artificial fields (e.g. virtual table
3204 pointer or virtual base class pointer) to private. */
3205 if (dwarf2_attr (die
, DW_AT_artificial
, cu
))
3207 new_field
->accessibility
= DW_ACCESS_private
;
3208 fip
->non_public_fields
= 1;
3211 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
3213 /* C++ static member. */
3215 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
3216 is a declaration, but all versions of G++ as of this writing
3217 (so through at least 3.2.1) incorrectly generate
3218 DW_TAG_variable tags. */
3222 /* Get name of field. */
3223 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3224 if (attr
&& DW_STRING (attr
))
3225 fieldname
= DW_STRING (attr
);
3229 /* Get physical name. */
3230 physname
= dwarf2_linkage_name (die
, cu
);
3232 /* The name is already allocated along with this objfile, so we don't
3233 need to duplicate it for the type. */
3234 SET_FIELD_PHYSNAME (*fp
, physname
? physname
: "");
3235 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3236 FIELD_NAME (*fp
) = fieldname
;
3238 else if (die
->tag
== DW_TAG_inheritance
)
3240 /* C++ base class field. */
3241 attr
= dwarf2_attr (die
, DW_AT_data_member_location
, cu
);
3243 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), cu
)
3245 FIELD_BITSIZE (*fp
) = 0;
3246 FIELD_STATIC_KIND (*fp
) = 0;
3247 FIELD_TYPE (*fp
) = die_type (die
, cu
);
3248 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
3249 fip
->nbaseclasses
++;
3253 /* Create the vector of fields, and attach it to the type. */
3256 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3257 struct dwarf2_cu
*cu
)
3259 int nfields
= fip
->nfields
;
3261 /* Record the field count, allocate space for the array of fields,
3262 and create blank accessibility bitfields if necessary. */
3263 TYPE_NFIELDS (type
) = nfields
;
3264 TYPE_FIELDS (type
) = (struct field
*)
3265 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3266 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3268 if (fip
->non_public_fields
)
3270 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3272 TYPE_FIELD_PRIVATE_BITS (type
) =
3273 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3274 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3276 TYPE_FIELD_PROTECTED_BITS (type
) =
3277 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3278 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3280 TYPE_FIELD_IGNORE_BITS (type
) =
3281 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3282 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3285 /* If the type has baseclasses, allocate and clear a bit vector for
3286 TYPE_FIELD_VIRTUAL_BITS. */
3287 if (fip
->nbaseclasses
)
3289 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
3292 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3293 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3294 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3295 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
3296 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
3299 /* Copy the saved-up fields into the field vector. Start from the head
3300 of the list, adding to the tail of the field array, so that they end
3301 up in the same order in the array in which they were added to the list. */
3302 while (nfields
-- > 0)
3304 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
3305 switch (fip
->fields
->accessibility
)
3307 case DW_ACCESS_private
:
3308 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3311 case DW_ACCESS_protected
:
3312 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3315 case DW_ACCESS_public
:
3319 /* Unknown accessibility. Complain and treat it as public. */
3321 complaint (&symfile_complaints
, "unsupported accessibility %d",
3322 fip
->fields
->accessibility
);
3326 if (nfields
< fip
->nbaseclasses
)
3328 switch (fip
->fields
->virtuality
)
3330 case DW_VIRTUALITY_virtual
:
3331 case DW_VIRTUALITY_pure_virtual
:
3332 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
3336 fip
->fields
= fip
->fields
->next
;
3340 /* Add a member function to the proper fieldlist. */
3343 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
3344 struct type
*type
, struct dwarf2_cu
*cu
)
3346 struct objfile
*objfile
= cu
->objfile
;
3347 struct attribute
*attr
;
3348 struct fnfieldlist
*flp
;
3350 struct fn_field
*fnp
;
3353 struct nextfnfield
*new_fnfield
;
3355 /* Get name of member function. */
3356 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3357 if (attr
&& DW_STRING (attr
))
3358 fieldname
= DW_STRING (attr
);
3362 /* Get the mangled name. */
3363 physname
= dwarf2_linkage_name (die
, cu
);
3365 /* Look up member function name in fieldlist. */
3366 for (i
= 0; i
< fip
->nfnfields
; i
++)
3368 if (strcmp (fip
->fnfieldlists
[i
].name
, fieldname
) == 0)
3372 /* Create new list element if necessary. */
3373 if (i
< fip
->nfnfields
)
3374 flp
= &fip
->fnfieldlists
[i
];
3377 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3379 fip
->fnfieldlists
= (struct fnfieldlist
*)
3380 xrealloc (fip
->fnfieldlists
,
3381 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
3382 * sizeof (struct fnfieldlist
));
3383 if (fip
->nfnfields
== 0)
3384 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
3386 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
3387 flp
->name
= fieldname
;
3393 /* Create a new member function field and chain it to the field list
3395 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
3396 make_cleanup (xfree
, new_fnfield
);
3397 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
3398 new_fnfield
->next
= flp
->head
;
3399 flp
->head
= new_fnfield
;
3402 /* Fill in the member function field info. */
3403 fnp
= &new_fnfield
->fnfield
;
3404 /* The name is already allocated along with this objfile, so we don't
3405 need to duplicate it for the type. */
3406 fnp
->physname
= physname
? physname
: "";
3407 fnp
->type
= alloc_type (objfile
);
3408 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
3410 int nparams
= TYPE_NFIELDS (die
->type
);
3412 /* TYPE is the domain of this method, and DIE->TYPE is the type
3413 of the method itself (TYPE_CODE_METHOD). */
3414 smash_to_method_type (fnp
->type
, type
,
3415 TYPE_TARGET_TYPE (die
->type
),
3416 TYPE_FIELDS (die
->type
),
3417 TYPE_NFIELDS (die
->type
),
3418 TYPE_VARARGS (die
->type
));
3420 /* Handle static member functions.
3421 Dwarf2 has no clean way to discern C++ static and non-static
3422 member functions. G++ helps GDB by marking the first
3423 parameter for non-static member functions (which is the
3424 this pointer) as artificial. We obtain this information
3425 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
3426 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
3427 fnp
->voffset
= VOFFSET_STATIC
;
3430 complaint (&symfile_complaints
, "member function type missing for '%s'",
3433 /* Get fcontext from DW_AT_containing_type if present. */
3434 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3435 fnp
->fcontext
= die_containing_type (die
, cu
);
3437 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
3438 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
3440 /* Get accessibility. */
3441 attr
= dwarf2_attr (die
, DW_AT_accessibility
, cu
);
3444 switch (DW_UNSND (attr
))
3446 case DW_ACCESS_private
:
3447 fnp
->is_private
= 1;
3449 case DW_ACCESS_protected
:
3450 fnp
->is_protected
= 1;
3455 /* Check for artificial methods. */
3456 attr
= dwarf2_attr (die
, DW_AT_artificial
, cu
);
3457 if (attr
&& DW_UNSND (attr
) != 0)
3458 fnp
->is_artificial
= 1;
3460 /* Get index in virtual function table if it is a virtual member function. */
3461 attr
= dwarf2_attr (die
, DW_AT_vtable_elem_location
, cu
);
3464 /* Support the .debug_loc offsets */
3465 if (attr_form_is_block (attr
))
3467 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), cu
) + 2;
3469 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3471 dwarf2_complex_location_expr_complaint ();
3475 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
3481 /* Create the vector of member function fields, and attach it to the type. */
3484 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
3485 struct dwarf2_cu
*cu
)
3487 struct fnfieldlist
*flp
;
3488 int total_length
= 0;
3491 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3492 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3493 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
3495 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
3497 struct nextfnfield
*nfp
= flp
->head
;
3498 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
3501 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
3502 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
3503 fn_flp
->fn_fields
= (struct fn_field
*)
3504 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
3505 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
3506 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
3508 total_length
+= flp
->length
;
3511 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
3512 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3516 /* Returns non-zero if NAME is the name of a vtable member in CU's
3517 language, zero otherwise. */
3519 is_vtable_name (const char *name
, struct dwarf2_cu
*cu
)
3521 static const char vptr
[] = "_vptr";
3522 static const char vtable
[] = "vtable";
3524 /* Look for the C++ and Java forms of the vtable. */
3525 if ((cu
->language
== language_java
3526 && strncmp (name
, vtable
, sizeof (vtable
) - 1) == 0)
3527 || (strncmp (name
, vptr
, sizeof (vptr
) - 1) == 0
3528 && is_cplus_marker (name
[sizeof (vptr
) - 1])))
3535 /* Called when we find the DIE that starts a structure or union scope
3536 (definition) to process all dies that define the members of the
3539 NOTE: we need to call struct_type regardless of whether or not the
3540 DIE has an at_name attribute, since it might be an anonymous
3541 structure or union. This gets the type entered into our set of
3544 However, if the structure is incomplete (an opaque struct/union)
3545 then suppress creating a symbol table entry for it since gdb only
3546 wants to find the one with the complete definition. Note that if
3547 it is complete, we just call new_symbol, which does it's own
3548 checking about whether the struct/union is anonymous or not (and
3549 suppresses creating a symbol table entry itself). */
3552 read_structure_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3554 struct objfile
*objfile
= cu
->objfile
;
3556 struct attribute
*attr
;
3557 const char *previous_prefix
= processing_current_prefix
;
3558 struct cleanup
*back_to
= NULL
;
3563 type
= alloc_type (objfile
);
3565 INIT_CPLUS_SPECIFIC (type
);
3566 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3567 if (attr
&& DW_STRING (attr
))
3569 if (cu
->language
== language_cplus
3570 || cu
->language
== language_java
)
3572 char *new_prefix
= determine_class_name (die
, cu
);
3573 TYPE_TAG_NAME (type
) = obsavestring (new_prefix
,
3574 strlen (new_prefix
),
3575 &objfile
->objfile_obstack
);
3576 back_to
= make_cleanup (xfree
, new_prefix
);
3577 processing_current_prefix
= new_prefix
;
3581 /* The name is already allocated along with this objfile, so
3582 we don't need to duplicate it for the type. */
3583 TYPE_TAG_NAME (type
) = DW_STRING (attr
);
3587 if (die
->tag
== DW_TAG_structure_type
)
3589 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
3591 else if (die
->tag
== DW_TAG_union_type
)
3593 TYPE_CODE (type
) = TYPE_CODE_UNION
;
3597 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
3599 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
3602 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3605 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3609 TYPE_LENGTH (type
) = 0;
3612 if (die_is_declaration (die
, cu
))
3613 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3615 /* We need to add the type field to the die immediately so we don't
3616 infinitely recurse when dealing with pointers to the structure
3617 type within the structure itself. */
3618 set_die_type (die
, type
, cu
);
3620 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3622 struct field_info fi
;
3623 struct die_info
*child_die
;
3624 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
3626 memset (&fi
, 0, sizeof (struct field_info
));
3628 child_die
= die
->child
;
3630 while (child_die
&& child_die
->tag
)
3632 if (child_die
->tag
== DW_TAG_member
3633 || child_die
->tag
== DW_TAG_variable
)
3635 /* NOTE: carlton/2002-11-05: A C++ static data member
3636 should be a DW_TAG_member that is a declaration, but
3637 all versions of G++ as of this writing (so through at
3638 least 3.2.1) incorrectly generate DW_TAG_variable
3639 tags for them instead. */
3640 dwarf2_add_field (&fi
, child_die
, cu
);
3642 else if (child_die
->tag
== DW_TAG_subprogram
)
3644 /* C++ member function. */
3645 read_type_die (child_die
, cu
);
3646 dwarf2_add_member_fn (&fi
, child_die
, type
, cu
);
3648 else if (child_die
->tag
== DW_TAG_inheritance
)
3650 /* C++ base class field. */
3651 dwarf2_add_field (&fi
, child_die
, cu
);
3653 child_die
= sibling_die (child_die
);
3656 /* Attach fields and member functions to the type. */
3658 dwarf2_attach_fields_to_type (&fi
, type
, cu
);
3661 dwarf2_attach_fn_fields_to_type (&fi
, type
, cu
);
3663 /* Get the type which refers to the base class (possibly this
3664 class itself) which contains the vtable pointer for the current
3665 class from the DW_AT_containing_type attribute. */
3667 if (dwarf2_attr (die
, DW_AT_containing_type
, cu
) != NULL
)
3669 struct type
*t
= die_containing_type (die
, cu
);
3671 TYPE_VPTR_BASETYPE (type
) = t
;
3676 /* Our own class provides vtbl ptr. */
3677 for (i
= TYPE_NFIELDS (t
) - 1;
3678 i
>= TYPE_N_BASECLASSES (t
);
3681 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
3683 if (is_vtable_name (fieldname
, cu
))
3685 TYPE_VPTR_FIELDNO (type
) = i
;
3690 /* Complain if virtual function table field not found. */
3691 if (i
< TYPE_N_BASECLASSES (t
))
3692 complaint (&symfile_complaints
,
3693 "virtual function table pointer not found when defining class '%s'",
3694 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
3699 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3704 do_cleanups (back_to
);
3707 processing_current_prefix
= previous_prefix
;
3708 if (back_to
!= NULL
)
3709 do_cleanups (back_to
);
3713 process_structure_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3715 struct objfile
*objfile
= cu
->objfile
;
3716 const char *previous_prefix
= processing_current_prefix
;
3717 struct die_info
*child_die
= die
->child
;
3719 if (TYPE_TAG_NAME (die
->type
) != NULL
)
3720 processing_current_prefix
= TYPE_TAG_NAME (die
->type
);
3722 /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its
3723 snapshots) has been known to create a die giving a declaration
3724 for a class that has, as a child, a die giving a definition for a
3725 nested class. So we have to process our children even if the
3726 current die is a declaration. Normally, of course, a declaration
3727 won't have any children at all. */
3729 while (child_die
!= NULL
&& child_die
->tag
)
3731 if (child_die
->tag
== DW_TAG_member
3732 || child_die
->tag
== DW_TAG_variable
3733 || child_die
->tag
== DW_TAG_inheritance
)
3738 process_die (child_die
, cu
);
3740 child_die
= sibling_die (child_die
);
3743 if (die
->child
!= NULL
&& ! die_is_declaration (die
, cu
))
3744 new_symbol (die
, die
->type
, cu
);
3746 processing_current_prefix
= previous_prefix
;
3749 /* Given a DW_AT_enumeration_type die, set its type. We do not
3750 complete the type's fields yet, or create any symbols. */
3753 read_enumeration_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3755 struct objfile
*objfile
= cu
->objfile
;
3757 struct attribute
*attr
;
3762 type
= alloc_type (objfile
);
3764 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3765 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
3766 if (attr
&& DW_STRING (attr
))
3768 char *name
= DW_STRING (attr
);
3770 if (processing_has_namespace_info
)
3772 TYPE_TAG_NAME (type
) = typename_concat (&objfile
->objfile_obstack
,
3773 processing_current_prefix
,
3778 /* The name is already allocated along with this objfile, so
3779 we don't need to duplicate it for the type. */
3780 TYPE_TAG_NAME (type
) = name
;
3784 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
3787 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3791 TYPE_LENGTH (type
) = 0;
3794 set_die_type (die
, type
, cu
);
3797 /* Determine the name of the type represented by DIE, which should be
3798 a named C++ or Java compound type. Return the name in question; the caller
3799 is responsible for xfree()'ing it. */
3802 determine_class_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
3804 struct cleanup
*back_to
= NULL
;
3805 struct die_info
*spec_die
= die_specification (die
, cu
);
3806 char *new_prefix
= NULL
;
3808 /* If this is the definition of a class that is declared by another
3809 die, then processing_current_prefix may not be accurate; see
3810 read_func_scope for a similar example. */
3811 if (spec_die
!= NULL
)
3813 char *specification_prefix
= determine_prefix (spec_die
, cu
);
3814 processing_current_prefix
= specification_prefix
;
3815 back_to
= make_cleanup (xfree
, specification_prefix
);
3818 /* If we don't have namespace debug info, guess the name by trying
3819 to demangle the names of members, just like we did in
3820 guess_structure_name. */
3821 if (!processing_has_namespace_info
)
3823 struct die_info
*child
;
3825 for (child
= die
->child
;
3826 child
!= NULL
&& child
->tag
!= 0;
3827 child
= sibling_die (child
))
3829 if (child
->tag
== DW_TAG_subprogram
)
3832 = language_class_name_from_physname (cu
->language_defn
,
3836 if (new_prefix
!= NULL
)
3842 if (new_prefix
== NULL
)
3844 const char *name
= dwarf2_name (die
, cu
);
3845 new_prefix
= typename_concat (NULL
, processing_current_prefix
,
3846 name
? name
: "<<anonymous>>",
3850 if (back_to
!= NULL
)
3851 do_cleanups (back_to
);
3856 /* Given a pointer to a die which begins an enumeration, process all
3857 the dies that define the members of the enumeration, and create the
3858 symbol for the enumeration type.
3860 NOTE: We reverse the order of the element list. */
3863 process_enumeration_scope (struct die_info
*die
, struct dwarf2_cu
*cu
)
3865 struct objfile
*objfile
= cu
->objfile
;
3866 struct die_info
*child_die
;
3867 struct field
*fields
;
3868 struct attribute
*attr
;
3871 int unsigned_enum
= 1;
3875 if (die
->child
!= NULL
)
3877 child_die
= die
->child
;
3878 while (child_die
&& child_die
->tag
)
3880 if (child_die
->tag
!= DW_TAG_enumerator
)
3882 process_die (child_die
, cu
);
3886 attr
= dwarf2_attr (child_die
, DW_AT_name
, cu
);
3889 sym
= new_symbol (child_die
, die
->type
, cu
);
3890 if (SYMBOL_VALUE (sym
) < 0)
3893 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
3895 fields
= (struct field
*)
3897 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
3898 * sizeof (struct field
));
3901 FIELD_NAME (fields
[num_fields
]) = DEPRECATED_SYMBOL_NAME (sym
);
3902 FIELD_TYPE (fields
[num_fields
]) = NULL
;
3903 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
3904 FIELD_BITSIZE (fields
[num_fields
]) = 0;
3905 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
3911 child_die
= sibling_die (child_die
);
3916 TYPE_NFIELDS (die
->type
) = num_fields
;
3917 TYPE_FIELDS (die
->type
) = (struct field
*)
3918 TYPE_ALLOC (die
->type
, sizeof (struct field
) * num_fields
);
3919 memcpy (TYPE_FIELDS (die
->type
), fields
,
3920 sizeof (struct field
) * num_fields
);
3924 TYPE_FLAGS (die
->type
) |= TYPE_FLAG_UNSIGNED
;
3927 new_symbol (die
, die
->type
, cu
);
3930 /* Extract all information from a DW_TAG_array_type DIE and put it in
3931 the DIE's type field. For now, this only handles one dimensional
3935 read_array_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
3937 struct objfile
*objfile
= cu
->objfile
;
3938 struct die_info
*child_die
;
3939 struct type
*type
= NULL
;
3940 struct type
*element_type
, *range_type
, *index_type
;
3941 struct type
**range_types
= NULL
;
3942 struct attribute
*attr
;
3944 struct cleanup
*back_to
;
3946 /* Return if we've already decoded this type. */
3952 element_type
= die_type (die
, cu
);
3954 /* Irix 6.2 native cc creates array types without children for
3955 arrays with unspecified length. */
3956 if (die
->child
== NULL
)
3958 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
3959 range_type
= create_range_type (NULL
, index_type
, 0, -1);
3960 set_die_type (die
, create_array_type (NULL
, element_type
, range_type
),
3965 back_to
= make_cleanup (null_cleanup
, NULL
);
3966 child_die
= die
->child
;
3967 while (child_die
&& child_die
->tag
)
3969 if (child_die
->tag
== DW_TAG_subrange_type
)
3971 read_subrange_type (child_die
, cu
);
3973 if (child_die
->type
!= NULL
)
3975 /* The range type was succesfully read. Save it for
3976 the array type creation. */
3977 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3979 range_types
= (struct type
**)
3980 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3981 * sizeof (struct type
*));
3983 make_cleanup (free_current_contents
, &range_types
);
3985 range_types
[ndim
++] = child_die
->type
;
3988 child_die
= sibling_die (child_die
);
3991 /* Dwarf2 dimensions are output from left to right, create the
3992 necessary array types in backwards order. */
3994 type
= element_type
;
3996 if (read_array_order (die
, cu
) == DW_ORD_col_major
)
4000 type
= create_array_type (NULL
, type
, range_types
[i
++]);
4005 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
4008 /* Understand Dwarf2 support for vector types (like they occur on
4009 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
4010 array type. This is not part of the Dwarf2/3 standard yet, but a
4011 custom vendor extension. The main difference between a regular
4012 array and the vector variant is that vectors are passed by value
4014 attr
= dwarf2_attr (die
, DW_AT_GNU_vector
, cu
);
4016 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
4018 do_cleanups (back_to
);
4020 /* Install the type in the die. */
4021 set_die_type (die
, type
, cu
);
4024 static enum dwarf_array_dim_ordering
4025 read_array_order (struct die_info
*die
, struct dwarf2_cu
*cu
)
4027 struct attribute
*attr
;
4029 attr
= dwarf2_attr (die
, DW_AT_ordering
, cu
);
4031 if (attr
) return DW_SND (attr
);
4034 GNU F77 is a special case, as at 08/2004 array type info is the
4035 opposite order to the dwarf2 specification, but data is still
4036 laid out as per normal fortran.
4038 FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need
4042 if (cu
->language
== language_fortran
&&
4043 cu
->producer
&& strstr (cu
->producer
, "GNU F77"))
4045 return DW_ORD_row_major
;
4048 switch (cu
->language_defn
->la_array_ordering
)
4050 case array_column_major
:
4051 return DW_ORD_col_major
;
4052 case array_row_major
:
4054 return DW_ORD_row_major
;
4059 /* First cut: install each common block member as a global variable. */
4062 read_common_block (struct die_info
*die
, struct dwarf2_cu
*cu
)
4064 struct die_info
*child_die
;
4065 struct attribute
*attr
;
4067 CORE_ADDR base
= (CORE_ADDR
) 0;
4069 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
4072 /* Support the .debug_loc offsets */
4073 if (attr_form_is_block (attr
))
4075 base
= decode_locdesc (DW_BLOCK (attr
), cu
);
4077 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
4079 dwarf2_complex_location_expr_complaint ();
4083 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4084 "common block member");
4087 if (die
->child
!= NULL
)
4089 child_die
= die
->child
;
4090 while (child_die
&& child_die
->tag
)
4092 sym
= new_symbol (child_die
, NULL
, cu
);
4093 attr
= dwarf2_attr (child_die
, DW_AT_data_member_location
, cu
);
4096 SYMBOL_VALUE_ADDRESS (sym
) =
4097 base
+ decode_locdesc (DW_BLOCK (attr
), cu
);
4098 add_symbol_to_list (sym
, &global_symbols
);
4100 child_die
= sibling_die (child_die
);
4105 /* Read a C++ namespace. */
4108 read_namespace (struct die_info
*die
, struct dwarf2_cu
*cu
)
4110 struct objfile
*objfile
= cu
->objfile
;
4111 const char *previous_prefix
= processing_current_prefix
;
4114 struct die_info
*current_die
;
4115 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
4117 name
= namespace_name (die
, &is_anonymous
, cu
);
4119 /* Now build the name of the current namespace. */
4121 if (previous_prefix
[0] == '\0')
4123 processing_current_prefix
= name
;
4127 char *temp_name
= typename_concat (NULL
, previous_prefix
, name
, cu
);
4128 make_cleanup (xfree
, temp_name
);
4129 processing_current_prefix
= temp_name
;
4132 /* Add a symbol associated to this if we haven't seen the namespace
4133 before. Also, add a using directive if it's an anonymous
4136 if (dwarf2_extension (die
, cu
) == NULL
)
4140 /* FIXME: carlton/2003-06-27: Once GDB is more const-correct,
4141 this cast will hopefully become unnecessary. */
4142 type
= init_type (TYPE_CODE_NAMESPACE
, 0, 0,
4143 (char *) processing_current_prefix
,
4145 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
4147 new_symbol (die
, type
, cu
);
4148 set_die_type (die
, type
, cu
);
4151 cp_add_using_directive (processing_current_prefix
,
4152 strlen (previous_prefix
),
4153 strlen (processing_current_prefix
));
4156 if (die
->child
!= NULL
)
4158 struct die_info
*child_die
= die
->child
;
4160 while (child_die
&& child_die
->tag
)
4162 process_die (child_die
, cu
);
4163 child_die
= sibling_die (child_die
);
4167 processing_current_prefix
= previous_prefix
;
4168 do_cleanups (back_to
);
4171 /* Return the name of the namespace represented by DIE. Set
4172 *IS_ANONYMOUS to tell whether or not the namespace is an anonymous
4176 namespace_name (struct die_info
*die
, int *is_anonymous
, struct dwarf2_cu
*cu
)
4178 struct die_info
*current_die
;
4179 const char *name
= NULL
;
4181 /* Loop through the extensions until we find a name. */
4183 for (current_die
= die
;
4184 current_die
!= NULL
;
4185 current_die
= dwarf2_extension (die
, cu
))
4187 name
= dwarf2_name (current_die
, cu
);
4192 /* Is it an anonymous namespace? */
4194 *is_anonymous
= (name
== NULL
);
4196 name
= "(anonymous namespace)";
4201 /* Extract all information from a DW_TAG_pointer_type DIE and add to
4202 the user defined type vector. */
4205 read_tag_pointer_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4207 struct comp_unit_head
*cu_header
= &cu
->header
;
4209 struct attribute
*attr_byte_size
;
4210 struct attribute
*attr_address_class
;
4211 int byte_size
, addr_class
;
4218 type
= lookup_pointer_type (die_type (die
, cu
));
4220 attr_byte_size
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4222 byte_size
= DW_UNSND (attr_byte_size
);
4224 byte_size
= cu_header
->addr_size
;
4226 attr_address_class
= dwarf2_attr (die
, DW_AT_address_class
, cu
);
4227 if (attr_address_class
)
4228 addr_class
= DW_UNSND (attr_address_class
);
4230 addr_class
= DW_ADDR_none
;
4232 /* If the pointer size or address class is different than the
4233 default, create a type variant marked as such and set the
4234 length accordingly. */
4235 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
4237 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
4241 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
4242 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
4243 type
= make_type_with_address_space (type
, type_flags
);
4245 else if (TYPE_LENGTH (type
) != byte_size
)
4247 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
4250 /* Should we also complain about unhandled address classes? */
4254 TYPE_LENGTH (type
) = byte_size
;
4255 set_die_type (die
, type
, cu
);
4258 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
4259 the user defined type vector. */
4262 read_tag_ptr_to_member_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4264 struct objfile
*objfile
= cu
->objfile
;
4266 struct type
*to_type
;
4267 struct type
*domain
;
4274 type
= alloc_type (objfile
);
4275 to_type
= die_type (die
, cu
);
4276 domain
= die_containing_type (die
, cu
);
4277 smash_to_member_type (type
, domain
, to_type
);
4279 set_die_type (die
, type
, cu
);
4282 /* Extract all information from a DW_TAG_reference_type DIE and add to
4283 the user defined type vector. */
4286 read_tag_reference_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4288 struct comp_unit_head
*cu_header
= &cu
->header
;
4290 struct attribute
*attr
;
4297 type
= lookup_reference_type (die_type (die
, cu
));
4298 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4301 TYPE_LENGTH (type
) = DW_UNSND (attr
);
4305 TYPE_LENGTH (type
) = cu_header
->addr_size
;
4307 set_die_type (die
, type
, cu
);
4311 read_tag_const_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4313 struct type
*base_type
;
4320 base_type
= die_type (die
, cu
);
4321 set_die_type (die
, make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0),
4326 read_tag_volatile_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4328 struct type
*base_type
;
4335 base_type
= die_type (die
, cu
);
4336 set_die_type (die
, make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0),
4340 /* Extract all information from a DW_TAG_string_type DIE and add to
4341 the user defined type vector. It isn't really a user defined type,
4342 but it behaves like one, with other DIE's using an AT_user_def_type
4343 attribute to reference it. */
4346 read_tag_string_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4348 struct objfile
*objfile
= cu
->objfile
;
4349 struct type
*type
, *range_type
, *index_type
, *char_type
;
4350 struct attribute
*attr
;
4351 unsigned int length
;
4358 attr
= dwarf2_attr (die
, DW_AT_string_length
, cu
);
4361 length
= DW_UNSND (attr
);
4365 /* check for the DW_AT_byte_size attribute */
4366 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4369 length
= DW_UNSND (attr
);
4376 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
, cu
);
4377 range_type
= create_range_type (NULL
, index_type
, 1, length
);
4378 if (cu
->language
== language_fortran
)
4380 /* Need to create a unique string type for bounds
4382 type
= create_string_type (0, range_type
);
4386 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
, cu
);
4387 type
= create_string_type (char_type
, range_type
);
4389 set_die_type (die
, type
, cu
);
4392 /* Handle DIES due to C code like:
4396 int (*funcp)(int a, long l);
4400 ('funcp' generates a DW_TAG_subroutine_type DIE)
4404 read_subroutine_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4406 struct type
*type
; /* Type that this function returns */
4407 struct type
*ftype
; /* Function that returns above type */
4408 struct attribute
*attr
;
4410 /* Decode the type that this subroutine returns */
4415 type
= die_type (die
, cu
);
4416 ftype
= lookup_function_type (type
);
4418 /* All functions in C++ and Java have prototypes. */
4419 attr
= dwarf2_attr (die
, DW_AT_prototyped
, cu
);
4420 if ((attr
&& (DW_UNSND (attr
) != 0))
4421 || cu
->language
== language_cplus
4422 || cu
->language
== language_java
)
4423 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
4425 if (die
->child
!= NULL
)
4427 struct die_info
*child_die
;
4431 /* Count the number of parameters.
4432 FIXME: GDB currently ignores vararg functions, but knows about
4433 vararg member functions. */
4434 child_die
= die
->child
;
4435 while (child_die
&& child_die
->tag
)
4437 if (child_die
->tag
== DW_TAG_formal_parameter
)
4439 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
4440 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
4441 child_die
= sibling_die (child_die
);
4444 /* Allocate storage for parameters and fill them in. */
4445 TYPE_NFIELDS (ftype
) = nparams
;
4446 TYPE_FIELDS (ftype
) = (struct field
*)
4447 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
4449 child_die
= die
->child
;
4450 while (child_die
&& child_die
->tag
)
4452 if (child_die
->tag
== DW_TAG_formal_parameter
)
4454 /* Dwarf2 has no clean way to discern C++ static and non-static
4455 member functions. G++ helps GDB by marking the first
4456 parameter for non-static member functions (which is the
4457 this pointer) as artificial. We pass this information
4458 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
4459 attr
= dwarf2_attr (child_die
, DW_AT_artificial
, cu
);
4461 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
4463 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
4464 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, cu
);
4467 child_die
= sibling_die (child_die
);
4471 set_die_type (die
, ftype
, cu
);
4475 read_typedef (struct die_info
*die
, struct dwarf2_cu
*cu
)
4477 struct objfile
*objfile
= cu
->objfile
;
4478 struct attribute
*attr
;
4483 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4484 if (attr
&& DW_STRING (attr
))
4486 name
= DW_STRING (attr
);
4488 set_die_type (die
, init_type (TYPE_CODE_TYPEDEF
, 0,
4489 TYPE_FLAG_TARGET_STUB
, name
, objfile
),
4491 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, cu
);
4495 /* Find a representation of a given base type and install
4496 it in the TYPE field of the die. */
4499 read_base_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4501 struct objfile
*objfile
= cu
->objfile
;
4503 struct attribute
*attr
;
4504 int encoding
= 0, size
= 0;
4506 /* If we've already decoded this die, this is a no-op. */
4512 attr
= dwarf2_attr (die
, DW_AT_encoding
, cu
);
4515 encoding
= DW_UNSND (attr
);
4517 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4520 size
= DW_UNSND (attr
);
4522 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4523 if (attr
&& DW_STRING (attr
))
4525 enum type_code code
= TYPE_CODE_INT
;
4530 case DW_ATE_address
:
4531 /* Turn DW_ATE_address into a void * pointer. */
4532 code
= TYPE_CODE_PTR
;
4533 type_flags
|= TYPE_FLAG_UNSIGNED
;
4535 case DW_ATE_boolean
:
4536 code
= TYPE_CODE_BOOL
;
4537 type_flags
|= TYPE_FLAG_UNSIGNED
;
4539 case DW_ATE_complex_float
:
4540 code
= TYPE_CODE_COMPLEX
;
4543 code
= TYPE_CODE_FLT
;
4546 case DW_ATE_signed_char
:
4548 case DW_ATE_unsigned
:
4549 case DW_ATE_unsigned_char
:
4550 type_flags
|= TYPE_FLAG_UNSIGNED
;
4553 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
4554 dwarf_type_encoding_name (encoding
));
4557 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
4558 if (encoding
== DW_ATE_address
)
4559 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
,
4561 else if (encoding
== DW_ATE_complex_float
)
4564 TYPE_TARGET_TYPE (type
)
4565 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
, cu
);
4566 else if (size
== 16)
4567 TYPE_TARGET_TYPE (type
)
4568 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
4570 TYPE_TARGET_TYPE (type
)
4571 = dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
4576 type
= dwarf_base_type (encoding
, size
, cu
);
4578 set_die_type (die
, type
, cu
);
4581 /* Read the given DW_AT_subrange DIE. */
4584 read_subrange_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
4586 struct type
*base_type
;
4587 struct type
*range_type
;
4588 struct attribute
*attr
;
4592 /* If we have already decoded this die, then nothing more to do. */
4596 base_type
= die_type (die
, cu
);
4597 if (base_type
== NULL
)
4599 complaint (&symfile_complaints
,
4600 "DW_AT_type missing from DW_TAG_subrange_type");
4604 if (TYPE_CODE (base_type
) == TYPE_CODE_VOID
)
4605 base_type
= alloc_type (NULL
);
4607 if (cu
->language
== language_fortran
)
4609 /* FORTRAN implies a lower bound of 1, if not given. */
4613 attr
= dwarf2_attr (die
, DW_AT_lower_bound
, cu
);
4615 low
= dwarf2_get_attr_constant_value (attr
, 0);
4617 attr
= dwarf2_attr (die
, DW_AT_upper_bound
, cu
);
4620 if (attr
->form
== DW_FORM_block1
)
4622 /* GCC encodes arrays with unspecified or dynamic length
4623 with a DW_FORM_block1 attribute.
4624 FIXME: GDB does not yet know how to handle dynamic
4625 arrays properly, treat them as arrays with unspecified
4628 FIXME: jimb/2003-09-22: GDB does not really know
4629 how to handle arrays of unspecified length
4630 either; we just represent them as zero-length
4631 arrays. Choose an appropriate upper bound given
4632 the lower bound we've computed above. */
4636 high
= dwarf2_get_attr_constant_value (attr
, 1);
4639 range_type
= create_range_type (NULL
, base_type
, low
, high
);
4641 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
4642 if (attr
&& DW_STRING (attr
))
4643 TYPE_NAME (range_type
) = DW_STRING (attr
);
4645 attr
= dwarf2_attr (die
, DW_AT_byte_size
, cu
);
4647 TYPE_LENGTH (range_type
) = DW_UNSND (attr
);
4649 set_die_type (die
, range_type
, cu
);
4653 /* Read a whole compilation unit into a linked list of dies. */
4655 static struct die_info
*
4656 read_comp_unit (char *info_ptr
, bfd
*abfd
, struct dwarf2_cu
*cu
)
4658 /* Reset die reference table; we are
4659 building new ones now. */
4660 dwarf2_empty_hash_tables ();
4662 return read_die_and_children (info_ptr
, abfd
, cu
, &info_ptr
, NULL
);
4665 /* Read a single die and all its descendents. Set the die's sibling
4666 field to NULL; set other fields in the die correctly, and set all
4667 of the descendents' fields correctly. Set *NEW_INFO_PTR to the
4668 location of the info_ptr after reading all of those dies. PARENT
4669 is the parent of the die in question. */
4671 static struct die_info
*
4672 read_die_and_children (char *info_ptr
, bfd
*abfd
,
4673 struct dwarf2_cu
*cu
,
4674 char **new_info_ptr
,
4675 struct die_info
*parent
)
4677 struct die_info
*die
;
4681 cur_ptr
= read_full_die (&die
, abfd
, info_ptr
, cu
, &has_children
);
4682 store_in_ref_table (die
->offset
, die
);
4686 die
->child
= read_die_and_siblings (cur_ptr
, abfd
, cu
,
4692 *new_info_ptr
= cur_ptr
;
4695 die
->sibling
= NULL
;
4696 die
->parent
= parent
;
4700 /* Read a die, all of its descendents, and all of its siblings; set
4701 all of the fields of all of the dies correctly. Arguments are as
4702 in read_die_and_children. */
4704 static struct die_info
*
4705 read_die_and_siblings (char *info_ptr
, bfd
*abfd
,
4706 struct dwarf2_cu
*cu
,
4707 char **new_info_ptr
,
4708 struct die_info
*parent
)
4710 struct die_info
*first_die
, *last_sibling
;
4714 first_die
= last_sibling
= NULL
;
4718 struct die_info
*die
4719 = read_die_and_children (cur_ptr
, abfd
, cu
, &cur_ptr
, parent
);
4727 last_sibling
->sibling
= die
;
4732 *new_info_ptr
= cur_ptr
;
4742 /* Free a linked list of dies. */
4745 free_die_list (struct die_info
*dies
)
4747 struct die_info
*die
, *next
;
4752 if (die
->child
!= NULL
)
4753 free_die_list (die
->child
);
4754 next
= die
->sibling
;
4762 do_free_die_list_cleanup (void *dies
)
4764 free_die_list (dies
);
4767 static struct cleanup
*
4768 make_cleanup_free_die_list (struct die_info
*dies
)
4770 return make_cleanup (do_free_die_list_cleanup
, dies
);
4774 /* Read the contents of the section at OFFSET and of size SIZE from the
4775 object file specified by OBJFILE into the objfile_obstack and return it. */
4778 dwarf2_read_section (struct objfile
*objfile
, asection
*sectp
)
4780 bfd
*abfd
= objfile
->obfd
;
4782 bfd_size_type size
= bfd_get_section_size (sectp
);
4787 buf
= (char *) obstack_alloc (&objfile
->objfile_obstack
, size
);
4789 = (char *) symfile_relocate_debug_section (abfd
, sectp
, (bfd_byte
*) buf
);
4793 if (bfd_seek (abfd
, sectp
->filepos
, SEEK_SET
) != 0
4794 || bfd_bread (buf
, size
, abfd
) != size
)
4795 error ("Dwarf Error: Can't read DWARF data from '%s'",
4796 bfd_get_filename (abfd
));
4801 /* In DWARF version 2, the description of the debugging information is
4802 stored in a separate .debug_abbrev section. Before we read any
4803 dies from a section we read in all abbreviations and install them
4804 in a hash table. This function also sets flags in CU describing
4805 the data found in the abbrev table. */
4808 dwarf2_read_abbrevs (bfd
*abfd
, struct dwarf2_cu
*cu
)
4810 struct comp_unit_head
*cu_header
= &cu
->header
;
4812 struct abbrev_info
*cur_abbrev
;
4813 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
4814 unsigned int abbrev_form
, hash_number
;
4815 struct attr_abbrev
*cur_attrs
;
4816 unsigned int allocated_attrs
;
4818 /* Initialize dwarf2 abbrevs */
4819 obstack_init (&cu
->abbrev_obstack
);
4820 cu
->dwarf2_abbrevs
= obstack_alloc (&cu
->abbrev_obstack
,
4822 * sizeof (struct abbrev_info
*)));
4823 memset (cu
->dwarf2_abbrevs
, 0,
4824 ABBREV_HASH_SIZE
* sizeof (struct abbrev_info
*));
4826 abbrev_ptr
= dwarf2_per_objfile
->abbrev_buffer
+ cu_header
->abbrev_offset
;
4827 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4828 abbrev_ptr
+= bytes_read
;
4830 allocated_attrs
= ATTR_ALLOC_CHUNK
;
4831 cur_attrs
= xmalloc (allocated_attrs
* sizeof (struct attr_abbrev
));
4833 /* loop until we reach an abbrev number of 0 */
4834 while (abbrev_number
)
4836 cur_abbrev
= dwarf_alloc_abbrev (cu
);
4838 /* read in abbrev header */
4839 cur_abbrev
->number
= abbrev_number
;
4840 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4841 abbrev_ptr
+= bytes_read
;
4842 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
4845 if (cur_abbrev
->tag
== DW_TAG_namespace
)
4846 cu
->has_namespace_info
= 1;
4848 /* now read in declarations */
4849 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4850 abbrev_ptr
+= bytes_read
;
4851 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4852 abbrev_ptr
+= bytes_read
;
4855 if (cur_abbrev
->num_attrs
== allocated_attrs
)
4857 allocated_attrs
+= ATTR_ALLOC_CHUNK
;
4859 = xrealloc (cur_attrs
, (allocated_attrs
4860 * sizeof (struct attr_abbrev
)));
4863 /* Record whether this compilation unit might have
4864 inter-compilation-unit references. If we don't know what form
4865 this attribute will have, then it might potentially be a
4866 DW_FORM_ref_addr, so we conservatively expect inter-CU
4869 if (abbrev_form
== DW_FORM_ref_addr
4870 || abbrev_form
== DW_FORM_indirect
)
4871 cu
->has_form_ref_addr
= 1;
4873 cur_attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
4874 cur_attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
4875 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4876 abbrev_ptr
+= bytes_read
;
4877 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4878 abbrev_ptr
+= bytes_read
;
4881 cur_abbrev
->attrs
= obstack_alloc (&cu
->abbrev_obstack
,
4882 (cur_abbrev
->num_attrs
4883 * sizeof (struct attr_abbrev
)));
4884 memcpy (cur_abbrev
->attrs
, cur_attrs
,
4885 cur_abbrev
->num_attrs
* sizeof (struct attr_abbrev
));
4887 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
4888 cur_abbrev
->next
= cu
->dwarf2_abbrevs
[hash_number
];
4889 cu
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
4891 /* Get next abbreviation.
4892 Under Irix6 the abbreviations for a compilation unit are not
4893 always properly terminated with an abbrev number of 0.
4894 Exit loop if we encounter an abbreviation which we have
4895 already read (which means we are about to read the abbreviations
4896 for the next compile unit) or if the end of the abbreviation
4897 table is reached. */
4898 if ((unsigned int) (abbrev_ptr
- dwarf2_per_objfile
->abbrev_buffer
)
4899 >= dwarf2_per_objfile
->abbrev_size
)
4901 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
4902 abbrev_ptr
+= bytes_read
;
4903 if (dwarf2_lookup_abbrev (abbrev_number
, cu
) != NULL
)
4910 /* Release the memory used by the abbrev table for a compilation unit. */
4913 dwarf2_free_abbrev_table (void *ptr_to_cu
)
4915 struct dwarf2_cu
*cu
= ptr_to_cu
;
4917 obstack_free (&cu
->abbrev_obstack
, NULL
);
4918 cu
->dwarf2_abbrevs
= NULL
;
4921 /* Lookup an abbrev_info structure in the abbrev hash table. */
4923 static struct abbrev_info
*
4924 dwarf2_lookup_abbrev (unsigned int number
, struct dwarf2_cu
*cu
)
4926 unsigned int hash_number
;
4927 struct abbrev_info
*abbrev
;
4929 hash_number
= number
% ABBREV_HASH_SIZE
;
4930 abbrev
= cu
->dwarf2_abbrevs
[hash_number
];
4934 if (abbrev
->number
== number
)
4937 abbrev
= abbrev
->next
;
4942 /* Returns nonzero if TAG represents a type that we might generate a partial
4946 is_type_tag_for_partial (int tag
)
4951 /* Some types that would be reasonable to generate partial symbols for,
4952 that we don't at present. */
4953 case DW_TAG_array_type
:
4954 case DW_TAG_file_type
:
4955 case DW_TAG_ptr_to_member_type
:
4956 case DW_TAG_set_type
:
4957 case DW_TAG_string_type
:
4958 case DW_TAG_subroutine_type
:
4960 case DW_TAG_base_type
:
4961 case DW_TAG_class_type
:
4962 case DW_TAG_enumeration_type
:
4963 case DW_TAG_structure_type
:
4964 case DW_TAG_subrange_type
:
4965 case DW_TAG_typedef
:
4966 case DW_TAG_union_type
:
4973 /* Load all DIEs that are interesting for partial symbols into memory. */
4975 static struct partial_die_info
*
4976 load_partial_dies (bfd
*abfd
, char *info_ptr
, int building_psymtab
,
4977 struct dwarf2_cu
*cu
)
4979 struct partial_die_info
*part_die
;
4980 struct partial_die_info
*parent_die
, *last_die
, *first_die
= NULL
;
4981 struct abbrev_info
*abbrev
;
4982 unsigned int bytes_read
;
4984 int nesting_level
= 1;
4990 = htab_create_alloc_ex (cu
->header
.length
/ 12,
4994 &cu
->comp_unit_obstack
,
4995 hashtab_obstack_allocate
,
4996 dummy_obstack_deallocate
);
4998 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
4999 sizeof (struct partial_die_info
));
5003 abbrev
= peek_die_abbrev (info_ptr
, &bytes_read
, cu
);
5005 /* A NULL abbrev means the end of a series of children. */
5008 if (--nesting_level
== 0)
5010 /* PART_DIE was probably the last thing allocated on the
5011 comp_unit_obstack, so we could call obstack_free
5012 here. We don't do that because the waste is small,
5013 and will be cleaned up when we're done with this
5014 compilation unit. This way, we're also more robust
5015 against other users of the comp_unit_obstack. */
5018 info_ptr
+= bytes_read
;
5019 last_die
= parent_die
;
5020 parent_die
= parent_die
->die_parent
;
5024 /* Check whether this DIE is interesting enough to save. */
5025 if (!is_type_tag_for_partial (abbrev
->tag
)
5026 && abbrev
->tag
!= DW_TAG_enumerator
5027 && abbrev
->tag
!= DW_TAG_subprogram
5028 && abbrev
->tag
!= DW_TAG_variable
5029 && abbrev
->tag
!= DW_TAG_namespace
)
5031 /* Otherwise we skip to the next sibling, if any. */
5032 info_ptr
= skip_one_die (info_ptr
+ bytes_read
, abbrev
, cu
);
5036 info_ptr
= read_partial_die (part_die
, abbrev
, bytes_read
,
5037 abfd
, info_ptr
, cu
);
5039 /* This two-pass algorithm for processing partial symbols has a
5040 high cost in cache pressure. Thus, handle some simple cases
5041 here which cover the majority of C partial symbols. DIEs
5042 which neither have specification tags in them, nor could have
5043 specification tags elsewhere pointing at them, can simply be
5044 processed and discarded.
5046 This segment is also optional; scan_partial_symbols and
5047 add_partial_symbol will handle these DIEs if we chain
5048 them in normally. When compilers which do not emit large
5049 quantities of duplicate debug information are more common,
5050 this code can probably be removed. */
5052 /* Any complete simple types at the top level (pretty much all
5053 of them, for a language without namespaces), can be processed
5055 if (parent_die
== NULL
5056 && part_die
->has_specification
== 0
5057 && part_die
->is_declaration
== 0
5058 && (part_die
->tag
== DW_TAG_typedef
5059 || part_die
->tag
== DW_TAG_base_type
5060 || part_die
->tag
== DW_TAG_subrange_type
))
5062 if (building_psymtab
&& part_die
->name
!= NULL
)
5063 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5064 VAR_DOMAIN
, LOC_TYPEDEF
,
5065 &cu
->objfile
->static_psymbols
,
5066 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5067 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5071 /* If we're at the second level, and we're an enumerator, and
5072 our parent has no specification (meaning possibly lives in a
5073 namespace elsewhere), then we can add the partial symbol now
5074 instead of queueing it. */
5075 if (part_die
->tag
== DW_TAG_enumerator
5076 && parent_die
!= NULL
5077 && parent_die
->die_parent
== NULL
5078 && parent_die
->tag
== DW_TAG_enumeration_type
5079 && parent_die
->has_specification
== 0)
5081 if (part_die
->name
== NULL
)
5082 complaint (&symfile_complaints
, "malformed enumerator DIE ignored");
5083 else if (building_psymtab
)
5084 add_psymbol_to_list (part_die
->name
, strlen (part_die
->name
),
5085 VAR_DOMAIN
, LOC_CONST
,
5086 (cu
->language
== language_cplus
5087 || cu
->language
== language_java
)
5088 ? &cu
->objfile
->global_psymbols
5089 : &cu
->objfile
->static_psymbols
,
5090 0, (CORE_ADDR
) 0, cu
->language
, cu
->objfile
);
5092 info_ptr
= locate_pdi_sibling (part_die
, info_ptr
, abfd
, cu
);
5096 /* We'll save this DIE so link it in. */
5097 part_die
->die_parent
= parent_die
;
5098 part_die
->die_sibling
= NULL
;
5099 part_die
->die_child
= NULL
;
5101 if (last_die
&& last_die
== parent_die
)
5102 last_die
->die_child
= part_die
;
5104 last_die
->die_sibling
= part_die
;
5106 last_die
= part_die
;
5108 if (first_die
== NULL
)
5109 first_die
= part_die
;
5111 /* Maybe add the DIE to the hash table. Not all DIEs that we
5112 find interesting need to be in the hash table, because we
5113 also have the parent/sibling/child chains; only those that we
5114 might refer to by offset later during partial symbol reading.
5116 For now this means things that might have be the target of a
5117 DW_AT_specification, DW_AT_abstract_origin, or
5118 DW_AT_extension. DW_AT_extension will refer only to
5119 namespaces; DW_AT_abstract_origin refers to functions (and
5120 many things under the function DIE, but we do not recurse
5121 into function DIEs during partial symbol reading) and
5122 possibly variables as well; DW_AT_specification refers to
5123 declarations. Declarations ought to have the DW_AT_declaration
5124 flag. It happens that GCC forgets to put it in sometimes, but
5125 only for functions, not for types.
5127 Adding more things than necessary to the hash table is harmless
5128 except for the performance cost. Adding too few will result in
5129 internal errors in find_partial_die. */
5131 if (abbrev
->tag
== DW_TAG_subprogram
5132 || abbrev
->tag
== DW_TAG_variable
5133 || abbrev
->tag
== DW_TAG_namespace
5134 || part_die
->is_declaration
)
5138 slot
= htab_find_slot_with_hash (cu
->partial_dies
, part_die
,
5139 part_die
->offset
, INSERT
);
5143 part_die
= obstack_alloc (&cu
->comp_unit_obstack
,
5144 sizeof (struct partial_die_info
));
5146 /* For some DIEs we want to follow their children (if any). For C
5147 we have no reason to follow the children of structures; for other
5148 languages we have to, both so that we can get at method physnames
5149 to infer fully qualified class names, and for DW_AT_specification. */
5150 if (last_die
->has_children
5151 && (last_die
->tag
== DW_TAG_namespace
5152 || last_die
->tag
== DW_TAG_enumeration_type
5153 || (cu
->language
!= language_c
5154 && (last_die
->tag
== DW_TAG_class_type
5155 || last_die
->tag
== DW_TAG_structure_type
5156 || last_die
->tag
== DW_TAG_union_type
))))
5159 parent_die
= last_die
;
5163 /* Otherwise we skip to the next sibling, if any. */
5164 info_ptr
= locate_pdi_sibling (last_die
, info_ptr
, abfd
, cu
);
5166 /* Back to the top, do it again. */
5170 /* Read a minimal amount of information into the minimal die structure. */
5173 read_partial_die (struct partial_die_info
*part_die
,
5174 struct abbrev_info
*abbrev
,
5175 unsigned int abbrev_len
, bfd
*abfd
,
5176 char *info_ptr
, struct dwarf2_cu
*cu
)
5178 unsigned int bytes_read
, i
;
5179 struct attribute attr
;
5180 int has_low_pc_attr
= 0;
5181 int has_high_pc_attr
= 0;
5183 memset (part_die
, 0, sizeof (struct partial_die_info
));
5185 part_die
->offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5187 info_ptr
+= abbrev_len
;
5192 part_die
->tag
= abbrev
->tag
;
5193 part_die
->has_children
= abbrev
->has_children
;
5195 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5197 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
, cu
);
5199 /* Store the data if it is of an attribute we want to keep in a
5200 partial symbol table. */
5205 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
5206 if (part_die
->name
== NULL
)
5207 part_die
->name
= DW_STRING (&attr
);
5209 case DW_AT_comp_dir
:
5210 if (part_die
->dirname
== NULL
)
5211 part_die
->dirname
= DW_STRING (&attr
);
5213 case DW_AT_MIPS_linkage_name
:
5214 part_die
->name
= DW_STRING (&attr
);
5217 has_low_pc_attr
= 1;
5218 part_die
->lowpc
= DW_ADDR (&attr
);
5221 has_high_pc_attr
= 1;
5222 part_die
->highpc
= DW_ADDR (&attr
);
5224 case DW_AT_location
:
5225 /* Support the .debug_loc offsets */
5226 if (attr_form_is_block (&attr
))
5228 part_die
->locdesc
= DW_BLOCK (&attr
);
5230 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
5232 dwarf2_complex_location_expr_complaint ();
5236 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5237 "partial symbol information");
5240 case DW_AT_language
:
5241 part_die
->language
= DW_UNSND (&attr
);
5243 case DW_AT_external
:
5244 part_die
->is_external
= DW_UNSND (&attr
);
5246 case DW_AT_declaration
:
5247 part_die
->is_declaration
= DW_UNSND (&attr
);
5250 part_die
->has_type
= 1;
5252 case DW_AT_abstract_origin
:
5253 case DW_AT_specification
:
5254 case DW_AT_extension
:
5255 part_die
->has_specification
= 1;
5256 part_die
->spec_offset
= dwarf2_get_ref_die_offset (&attr
, cu
);
5259 /* Ignore absolute siblings, they might point outside of
5260 the current compile unit. */
5261 if (attr
.form
== DW_FORM_ref_addr
)
5262 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
5264 part_die
->sibling
= dwarf2_per_objfile
->info_buffer
5265 + dwarf2_get_ref_die_offset (&attr
, cu
);
5267 case DW_AT_stmt_list
:
5268 part_die
->has_stmt_list
= 1;
5269 part_die
->line_offset
= DW_UNSND (&attr
);
5276 /* When using the GNU linker, .gnu.linkonce. sections are used to
5277 eliminate duplicate copies of functions and vtables and such.
5278 The linker will arbitrarily choose one and discard the others.
5279 The AT_*_pc values for such functions refer to local labels in
5280 these sections. If the section from that file was discarded, the
5281 labels are not in the output, so the relocs get a value of 0.
5282 If this is a discarded function, mark the pc bounds as invalid,
5283 so that GDB will ignore it. */
5284 if (has_low_pc_attr
&& has_high_pc_attr
5285 && part_die
->lowpc
< part_die
->highpc
5286 && (part_die
->lowpc
!= 0
5287 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
5288 part_die
->has_pc_info
= 1;
5292 /* Find a cached partial DIE at OFFSET in CU. */
5294 static struct partial_die_info
*
5295 find_partial_die_in_comp_unit (unsigned long offset
, struct dwarf2_cu
*cu
)
5297 struct partial_die_info
*lookup_die
= NULL
;
5298 struct partial_die_info part_die
;
5300 part_die
.offset
= offset
;
5301 lookup_die
= htab_find_with_hash (cu
->partial_dies
, &part_die
, offset
);
5303 if (lookup_die
== NULL
)
5304 internal_error (__FILE__
, __LINE__
,
5305 "could not find partial DIE in cache\n");
5310 /* Find a partial DIE at OFFSET, which may or may not be in CU. */
5312 static struct partial_die_info
*
5313 find_partial_die (unsigned long offset
, struct dwarf2_cu
*cu
,
5314 struct dwarf2_cu
**target_cu
)
5316 struct dwarf2_per_cu_data
*per_cu
;
5318 if (offset
>= cu
->header
.offset
5319 && offset
< cu
->header
.offset
+ cu
->header
.length
)
5322 return find_partial_die_in_comp_unit (offset
, cu
);
5325 per_cu
= dwarf2_find_containing_comp_unit (offset
, cu
->objfile
);
5327 /* If this offset isn't pointing into a known compilation unit,
5328 the debug information is probably corrupted. */
5330 error ("Dwarf Error: could not find partial DIE containing "
5331 "offset 0x%lx [in module %s]",
5332 (long) offset
, bfd_get_filename (cu
->objfile
->obfd
));
5334 if (per_cu
->cu
== NULL
)
5336 load_comp_unit (per_cu
, cu
->objfile
);
5337 per_cu
->cu
->read_in_chain
= dwarf2_per_objfile
->read_in_chain
;
5338 dwarf2_per_objfile
->read_in_chain
= per_cu
;
5341 per_cu
->cu
->last_used
= 0;
5342 *target_cu
= per_cu
->cu
;
5343 return find_partial_die_in_comp_unit (offset
, per_cu
->cu
);
5346 /* Adjust PART_DIE before generating a symbol for it. This function
5347 may set the is_external flag or change the DIE's name. */
5350 fixup_partial_die (struct partial_die_info
*part_die
,
5351 struct dwarf2_cu
*cu
)
5353 /* If we found a reference attribute and the DIE has no name, try
5354 to find a name in the referred to DIE. */
5356 if (part_die
->name
== NULL
&& part_die
->has_specification
)
5358 struct partial_die_info
*spec_die
;
5359 struct dwarf2_cu
*spec_cu
;
5361 spec_die
= find_partial_die (part_die
->spec_offset
, cu
, &spec_cu
);
5363 fixup_partial_die (spec_die
, spec_cu
);
5367 part_die
->name
= spec_die
->name
;
5369 /* Copy DW_AT_external attribute if it is set. */
5370 if (spec_die
->is_external
)
5371 part_die
->is_external
= spec_die
->is_external
;
5375 /* Set default names for some unnamed DIEs. */
5376 if (part_die
->name
== NULL
&& (part_die
->tag
== DW_TAG_structure_type
5377 || part_die
->tag
== DW_TAG_class_type
))
5378 part_die
->name
= "(anonymous class)";
5380 if (part_die
->name
== NULL
&& part_die
->tag
== DW_TAG_namespace
)
5381 part_die
->name
= "(anonymous namespace)";
5383 if (part_die
->tag
== DW_TAG_structure_type
5384 || part_die
->tag
== DW_TAG_class_type
5385 || part_die
->tag
== DW_TAG_union_type
)
5386 guess_structure_name (part_die
, cu
);
5389 /* Read the die from the .debug_info section buffer. Set DIEP to
5390 point to a newly allocated die with its information, except for its
5391 child, sibling, and parent fields. Set HAS_CHILDREN to tell
5392 whether the die has children or not. */
5395 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
5396 struct dwarf2_cu
*cu
, int *has_children
)
5398 unsigned int abbrev_number
, bytes_read
, i
, offset
;
5399 struct abbrev_info
*abbrev
;
5400 struct die_info
*die
;
5402 offset
= info_ptr
- dwarf2_per_objfile
->info_buffer
;
5403 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5404 info_ptr
+= bytes_read
;
5407 die
= dwarf_alloc_die ();
5409 die
->abbrev
= abbrev_number
;
5416 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu
);
5419 error ("Dwarf Error: could not find abbrev number %d [in module %s]",
5421 bfd_get_filename (abfd
));
5423 die
= dwarf_alloc_die ();
5424 die
->offset
= offset
;
5425 die
->tag
= abbrev
->tag
;
5426 die
->abbrev
= abbrev_number
;
5429 die
->num_attrs
= abbrev
->num_attrs
;
5430 die
->attrs
= (struct attribute
*)
5431 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
5433 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
5435 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
5436 abfd
, info_ptr
, cu
);
5440 *has_children
= abbrev
->has_children
;
5444 /* Read an attribute value described by an attribute form. */
5447 read_attribute_value (struct attribute
*attr
, unsigned form
,
5448 bfd
*abfd
, char *info_ptr
,
5449 struct dwarf2_cu
*cu
)
5451 struct comp_unit_head
*cu_header
= &cu
->header
;
5452 unsigned int bytes_read
;
5453 struct dwarf_block
*blk
;
5459 case DW_FORM_ref_addr
:
5460 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu
, &bytes_read
);
5461 info_ptr
+= bytes_read
;
5463 case DW_FORM_block2
:
5464 blk
= dwarf_alloc_block (cu
);
5465 blk
->size
= read_2_bytes (abfd
, info_ptr
);
5467 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5468 info_ptr
+= blk
->size
;
5469 DW_BLOCK (attr
) = blk
;
5471 case DW_FORM_block4
:
5472 blk
= dwarf_alloc_block (cu
);
5473 blk
->size
= read_4_bytes (abfd
, info_ptr
);
5475 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5476 info_ptr
+= blk
->size
;
5477 DW_BLOCK (attr
) = blk
;
5480 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5484 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5488 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5491 case DW_FORM_string
:
5492 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
5493 info_ptr
+= bytes_read
;
5496 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
5498 info_ptr
+= bytes_read
;
5501 blk
= dwarf_alloc_block (cu
);
5502 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5503 info_ptr
+= bytes_read
;
5504 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5505 info_ptr
+= blk
->size
;
5506 DW_BLOCK (attr
) = blk
;
5508 case DW_FORM_block1
:
5509 blk
= dwarf_alloc_block (cu
);
5510 blk
->size
= read_1_byte (abfd
, info_ptr
);
5512 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
5513 info_ptr
+= blk
->size
;
5514 DW_BLOCK (attr
) = blk
;
5517 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5521 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5525 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
5526 info_ptr
+= bytes_read
;
5529 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5530 info_ptr
+= bytes_read
;
5533 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
5537 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
5541 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
5545 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
5548 case DW_FORM_ref_udata
:
5549 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5550 info_ptr
+= bytes_read
;
5552 case DW_FORM_indirect
:
5553 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
5554 info_ptr
+= bytes_read
;
5555 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu
);
5558 error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]",
5559 dwarf_form_name (form
),
5560 bfd_get_filename (abfd
));
5565 /* Read an attribute described by an abbreviated attribute. */
5568 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
5569 bfd
*abfd
, char *info_ptr
, struct dwarf2_cu
*cu
)
5571 attr
->name
= abbrev
->name
;
5572 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu
);
5575 /* read dwarf information from a buffer */
5578 read_1_byte (bfd
*abfd
, char *buf
)
5580 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5584 read_1_signed_byte (bfd
*abfd
, char *buf
)
5586 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
5590 read_2_bytes (bfd
*abfd
, char *buf
)
5592 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5596 read_2_signed_bytes (bfd
*abfd
, char *buf
)
5598 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5602 read_4_bytes (bfd
*abfd
, char *buf
)
5604 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5608 read_4_signed_bytes (bfd
*abfd
, char *buf
)
5610 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5613 static unsigned long
5614 read_8_bytes (bfd
*abfd
, char *buf
)
5616 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5620 read_address (bfd
*abfd
, char *buf
, struct dwarf2_cu
*cu
, int *bytes_read
)
5622 struct comp_unit_head
*cu_header
= &cu
->header
;
5623 CORE_ADDR retval
= 0;
5625 if (cu_header
->signed_addr_p
)
5627 switch (cu_header
->addr_size
)
5630 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
5633 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
5636 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
5639 internal_error (__FILE__
, __LINE__
,
5640 "read_address: bad switch, signed [in module %s]",
5641 bfd_get_filename (abfd
));
5646 switch (cu_header
->addr_size
)
5649 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
5652 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5655 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5658 internal_error (__FILE__
, __LINE__
,
5659 "read_address: bad switch, unsigned [in module %s]",
5660 bfd_get_filename (abfd
));
5664 *bytes_read
= cu_header
->addr_size
;
5668 /* Read the initial length from a section. The (draft) DWARF 3
5669 specification allows the initial length to take up either 4 bytes
5670 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
5671 bytes describe the length and all offsets will be 8 bytes in length
5674 An older, non-standard 64-bit format is also handled by this
5675 function. The older format in question stores the initial length
5676 as an 8-byte quantity without an escape value. Lengths greater
5677 than 2^32 aren't very common which means that the initial 4 bytes
5678 is almost always zero. Since a length value of zero doesn't make
5679 sense for the 32-bit format, this initial zero can be considered to
5680 be an escape value which indicates the presence of the older 64-bit
5681 format. As written, the code can't detect (old format) lengths
5682 greater than 4GB. If it becomes necessary to handle lengths somewhat
5683 larger than 4GB, we could allow other small values (such as the
5684 non-sensical values of 1, 2, and 3) to also be used as escape values
5685 indicating the presence of the old format.
5687 The value returned via bytes_read should be used to increment
5688 the relevant pointer after calling read_initial_length().
5690 As a side effect, this function sets the fields initial_length_size
5691 and offset_size in cu_header to the values appropriate for the
5692 length field. (The format of the initial length field determines
5693 the width of file offsets to be fetched later with fetch_offset().)
5695 [ Note: read_initial_length() and read_offset() are based on the
5696 document entitled "DWARF Debugging Information Format", revision
5697 3, draft 8, dated November 19, 2001. This document was obtained
5700 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
5702 This document is only a draft and is subject to change. (So beware.)
5704 Details regarding the older, non-standard 64-bit format were
5705 determined empirically by examining 64-bit ELF files produced
5706 by the SGI toolchain on an IRIX 6.5 machine.
5708 - Kevin, July 16, 2002
5712 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
5717 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5719 if (retval
== 0xffffffff)
5721 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
5723 if (cu_header
!= NULL
)
5725 cu_header
->initial_length_size
= 12;
5726 cu_header
->offset_size
= 8;
5729 else if (retval
== 0)
5731 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
5733 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5735 if (cu_header
!= NULL
)
5737 cu_header
->initial_length_size
= 8;
5738 cu_header
->offset_size
= 8;
5744 if (cu_header
!= NULL
)
5746 cu_header
->initial_length_size
= 4;
5747 cu_header
->offset_size
= 4;
5754 /* Read an offset from the data stream. The size of the offset is
5755 given by cu_header->offset_size. */
5758 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
5763 switch (cu_header
->offset_size
)
5766 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
5770 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
5774 internal_error (__FILE__
, __LINE__
,
5775 "read_offset: bad switch [in module %s]",
5776 bfd_get_filename (abfd
));
5783 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
5785 /* If the size of a host char is 8 bits, we can return a pointer
5786 to the buffer, otherwise we have to copy the data to a buffer
5787 allocated on the temporary obstack. */
5788 gdb_assert (HOST_CHAR_BIT
== 8);
5793 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5795 /* If the size of a host char is 8 bits, we can return a pointer
5796 to the string, otherwise we have to copy the string to a buffer
5797 allocated on the temporary obstack. */
5798 gdb_assert (HOST_CHAR_BIT
== 8);
5801 *bytes_read_ptr
= 1;
5804 *bytes_read_ptr
= strlen (buf
) + 1;
5809 read_indirect_string (bfd
*abfd
, char *buf
,
5810 const struct comp_unit_head
*cu_header
,
5811 unsigned int *bytes_read_ptr
)
5813 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
5814 (int *) bytes_read_ptr
);
5816 if (dwarf2_per_objfile
->str_buffer
== NULL
)
5818 error ("DW_FORM_strp used without .debug_str section [in module %s]",
5819 bfd_get_filename (abfd
));
5822 if (str_offset
>= dwarf2_per_objfile
->str_size
)
5824 error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]",
5825 bfd_get_filename (abfd
));
5828 gdb_assert (HOST_CHAR_BIT
== 8);
5829 if (dwarf2_per_objfile
->str_buffer
[str_offset
] == '\0')
5831 return dwarf2_per_objfile
->str_buffer
+ str_offset
;
5834 static unsigned long
5835 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5837 unsigned long result
;
5838 unsigned int num_read
;
5848 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5851 result
|= ((unsigned long)(byte
& 127) << shift
);
5852 if ((byte
& 128) == 0)
5858 *bytes_read_ptr
= num_read
;
5863 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
5866 int i
, shift
, size
, num_read
;
5876 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5879 result
|= ((long)(byte
& 127) << shift
);
5881 if ((byte
& 128) == 0)
5886 if ((shift
< size
) && (byte
& 0x40))
5888 result
|= -(1 << shift
);
5890 *bytes_read_ptr
= num_read
;
5894 /* Return a pointer to just past the end of an LEB128 number in BUF. */
5897 skip_leb128 (bfd
*abfd
, char *buf
)
5903 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
5905 if ((byte
& 128) == 0)
5911 set_cu_language (unsigned int lang
, struct dwarf2_cu
*cu
)
5917 cu
->language
= language_c
;
5919 case DW_LANG_C_plus_plus
:
5920 cu
->language
= language_cplus
;
5922 case DW_LANG_Fortran77
:
5923 case DW_LANG_Fortran90
:
5924 case DW_LANG_Fortran95
:
5925 cu
->language
= language_fortran
;
5927 case DW_LANG_Mips_Assembler
:
5928 cu
->language
= language_asm
;
5931 cu
->language
= language_java
;
5935 case DW_LANG_Cobol74
:
5936 case DW_LANG_Cobol85
:
5937 case DW_LANG_Pascal83
:
5938 case DW_LANG_Modula2
:
5940 cu
->language
= language_minimal
;
5943 cu
->language_defn
= language_def (cu
->language
);
5946 /* Return the named attribute or NULL if not there. */
5948 static struct attribute
*
5949 dwarf2_attr (struct die_info
*die
, unsigned int name
, struct dwarf2_cu
*cu
)
5952 struct attribute
*spec
= NULL
;
5954 for (i
= 0; i
< die
->num_attrs
; ++i
)
5956 if (die
->attrs
[i
].name
== name
)
5958 return &die
->attrs
[i
];
5960 if (die
->attrs
[i
].name
== DW_AT_specification
5961 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
5962 spec
= &die
->attrs
[i
];
5966 struct die_info
*ref_die
=
5967 follow_die_ref (dwarf2_get_ref_die_offset (spec
, cu
));
5970 return dwarf2_attr (ref_die
, name
, cu
);
5976 /* Return non-zero iff the attribute NAME is defined for the given DIE,
5977 and holds a non-zero value. This function should only be used for
5978 DW_FORM_flag attributes. */
5981 dwarf2_flag_true_p (struct die_info
*die
, unsigned name
, struct dwarf2_cu
*cu
)
5983 struct attribute
*attr
= dwarf2_attr (die
, name
, cu
);
5985 return (attr
&& DW_UNSND (attr
));
5989 die_is_declaration (struct die_info
*die
, struct dwarf2_cu
*cu
)
5991 /* A DIE is a declaration if it has a DW_AT_declaration attribute
5992 which value is non-zero. However, we have to be careful with
5993 DIEs having a DW_AT_specification attribute, because dwarf2_attr()
5994 (via dwarf2_flag_true_p) follows this attribute. So we may
5995 end up accidently finding a declaration attribute that belongs
5996 to a different DIE referenced by the specification attribute,
5997 even though the given DIE does not have a declaration attribute. */
5998 return (dwarf2_flag_true_p (die
, DW_AT_declaration
, cu
)
5999 && dwarf2_attr (die
, DW_AT_specification
, cu
) == NULL
);
6002 /* Return the die giving the specification for DIE, if there is
6005 static struct die_info
*
6006 die_specification (struct die_info
*die
, struct dwarf2_cu
*cu
)
6008 struct attribute
*spec_attr
= dwarf2_attr (die
, DW_AT_specification
, cu
);
6010 if (spec_attr
== NULL
)
6013 return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr
, cu
));
6016 /* Free the line_header structure *LH, and any arrays and strings it
6019 free_line_header (struct line_header
*lh
)
6021 if (lh
->standard_opcode_lengths
)
6022 xfree (lh
->standard_opcode_lengths
);
6024 /* Remember that all the lh->file_names[i].name pointers are
6025 pointers into debug_line_buffer, and don't need to be freed. */
6027 xfree (lh
->file_names
);
6029 /* Similarly for the include directory names. */
6030 if (lh
->include_dirs
)
6031 xfree (lh
->include_dirs
);
6037 /* Add an entry to LH's include directory table. */
6039 add_include_dir (struct line_header
*lh
, char *include_dir
)
6041 /* Grow the array if necessary. */
6042 if (lh
->include_dirs_size
== 0)
6044 lh
->include_dirs_size
= 1; /* for testing */
6045 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
6046 * sizeof (*lh
->include_dirs
));
6048 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
6050 lh
->include_dirs_size
*= 2;
6051 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
6052 (lh
->include_dirs_size
6053 * sizeof (*lh
->include_dirs
)));
6056 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
6060 /* Add an entry to LH's file name table. */
6062 add_file_name (struct line_header
*lh
,
6064 unsigned int dir_index
,
6065 unsigned int mod_time
,
6066 unsigned int length
)
6068 struct file_entry
*fe
;
6070 /* Grow the array if necessary. */
6071 if (lh
->file_names_size
== 0)
6073 lh
->file_names_size
= 1; /* for testing */
6074 lh
->file_names
= xmalloc (lh
->file_names_size
6075 * sizeof (*lh
->file_names
));
6077 else if (lh
->num_file_names
>= lh
->file_names_size
)
6079 lh
->file_names_size
*= 2;
6080 lh
->file_names
= xrealloc (lh
->file_names
,
6081 (lh
->file_names_size
6082 * sizeof (*lh
->file_names
)));
6085 fe
= &lh
->file_names
[lh
->num_file_names
++];
6087 fe
->dir_index
= dir_index
;
6088 fe
->mod_time
= mod_time
;
6089 fe
->length
= length
;
6094 /* Read the statement program header starting at OFFSET in
6095 .debug_line, according to the endianness of ABFD. Return a pointer
6096 to a struct line_header, allocated using xmalloc.
6098 NOTE: the strings in the include directory and file name tables of
6099 the returned object point into debug_line_buffer, and must not be
6101 static struct line_header
*
6102 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
6103 struct dwarf2_cu
*cu
)
6105 struct cleanup
*back_to
;
6106 struct line_header
*lh
;
6110 char *cur_dir
, *cur_file
;
6112 if (dwarf2_per_objfile
->line_buffer
== NULL
)
6114 complaint (&symfile_complaints
, "missing .debug_line section");
6118 /* Make sure that at least there's room for the total_length field. That
6119 could be 12 bytes long, but we're just going to fudge that. */
6120 if (offset
+ 4 >= dwarf2_per_objfile
->line_size
)
6122 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6126 lh
= xmalloc (sizeof (*lh
));
6127 memset (lh
, 0, sizeof (*lh
));
6128 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
6131 line_ptr
= dwarf2_per_objfile
->line_buffer
+ offset
;
6133 /* read in the header */
6134 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
6135 line_ptr
+= bytes_read
;
6136 if (line_ptr
+ lh
->total_length
> (dwarf2_per_objfile
->line_buffer
6137 + dwarf2_per_objfile
->line_size
))
6139 dwarf2_statement_list_fits_in_line_number_section_complaint ();
6142 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
6143 lh
->version
= read_2_bytes (abfd
, line_ptr
);
6145 lh
->header_length
= read_offset (abfd
, line_ptr
, &cu
->header
, &bytes_read
);
6146 line_ptr
+= bytes_read
;
6147 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
6149 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
6151 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
6153 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
6155 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
6157 lh
->standard_opcode_lengths
6158 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
6160 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
6161 for (i
= 1; i
< lh
->opcode_base
; ++i
)
6163 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
6167 /* Read directory table */
6168 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6170 line_ptr
+= bytes_read
;
6171 add_include_dir (lh
, cur_dir
);
6173 line_ptr
+= bytes_read
;
6175 /* Read file name table */
6176 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
6178 unsigned int dir_index
, mod_time
, length
;
6180 line_ptr
+= bytes_read
;
6181 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6182 line_ptr
+= bytes_read
;
6183 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6184 line_ptr
+= bytes_read
;
6185 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6186 line_ptr
+= bytes_read
;
6188 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6190 line_ptr
+= bytes_read
;
6191 lh
->statement_program_start
= line_ptr
;
6193 if (line_ptr
> (dwarf2_per_objfile
->line_buffer
6194 + dwarf2_per_objfile
->line_size
))
6195 complaint (&symfile_complaints
,
6196 "line number info header doesn't fit in `.debug_line' section");
6198 discard_cleanups (back_to
);
6202 /* This function exists to work around a bug in certain compilers
6203 (particularly GCC 2.95), in which the first line number marker of a
6204 function does not show up until after the prologue, right before
6205 the second line number marker. This function shifts ADDRESS down
6206 to the beginning of the function if necessary, and is called on
6207 addresses passed to record_line. */
6210 check_cu_functions (CORE_ADDR address
, struct dwarf2_cu
*cu
)
6212 struct function_range
*fn
;
6214 /* Find the function_range containing address. */
6219 cu
->cached_fn
= cu
->first_fn
;
6223 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6229 while (fn
&& fn
!= cu
->cached_fn
)
6230 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
6240 if (address
!= fn
->lowpc
)
6241 complaint (&symfile_complaints
,
6242 "misplaced first line number at 0x%lx for '%s'",
6243 (unsigned long) address
, fn
->name
);
6248 /* Decode the Line Number Program (LNP) for the given line_header
6249 structure and CU. The actual information extracted and the type
6250 of structures created from the LNP depends on the value of PST.
6252 1. If PST is NULL, then this procedure uses the data from the program
6253 to create all necessary symbol tables, and their linetables.
6254 The compilation directory of the file is passed in COMP_DIR,
6255 and must not be NULL.
6257 2. If PST is not NULL, this procedure reads the program to determine
6258 the list of files included by the unit represented by PST, and
6259 builds all the associated partial symbol tables. In this case,
6260 the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR
6261 is not used to compute the full name of the symtab, and therefore
6262 omitting it when building the partial symtab does not introduce
6263 the potential for inconsistency - a partial symtab and its associated
6264 symbtab having a different fullname -). */
6267 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
6268 struct dwarf2_cu
*cu
, struct partial_symtab
*pst
)
6272 unsigned int bytes_read
;
6273 unsigned char op_code
, extended_op
, adj_opcode
;
6275 struct objfile
*objfile
= cu
->objfile
;
6276 const int decode_for_pst_p
= (pst
!= NULL
);
6278 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6280 line_ptr
= lh
->statement_program_start
;
6281 line_end
= lh
->statement_program_end
;
6283 /* Read the statement sequences until there's nothing left. */
6284 while (line_ptr
< line_end
)
6286 /* state machine registers */
6287 CORE_ADDR address
= 0;
6288 unsigned int file
= 1;
6289 unsigned int line
= 1;
6290 unsigned int column
= 0;
6291 int is_stmt
= lh
->default_is_stmt
;
6292 int basic_block
= 0;
6293 int end_sequence
= 0;
6295 if (!decode_for_pst_p
&& lh
->num_file_names
>= file
)
6297 /* Start a subfile for the current file of the state machine. */
6298 /* lh->include_dirs and lh->file_names are 0-based, but the
6299 directory and file name numbers in the statement program
6301 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6304 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6307 dwarf2_start_subfile (fe
->name
, dir
);
6310 /* Decode the table. */
6311 while (!end_sequence
)
6313 op_code
= read_1_byte (abfd
, line_ptr
);
6316 if (op_code
>= lh
->opcode_base
)
6317 { /* Special operand. */
6318 adj_opcode
= op_code
- lh
->opcode_base
;
6319 address
+= (adj_opcode
/ lh
->line_range
)
6320 * lh
->minimum_instruction_length
;
6321 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
6322 lh
->file_names
[file
- 1].included_p
= 1;
6323 if (!decode_for_pst_p
)
6325 /* append row to matrix using current values */
6326 record_line (current_subfile
, line
,
6327 check_cu_functions (address
, cu
));
6331 else switch (op_code
)
6333 case DW_LNS_extended_op
:
6334 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6335 line_ptr
+= bytes_read
;
6336 extended_op
= read_1_byte (abfd
, line_ptr
);
6338 switch (extended_op
)
6340 case DW_LNE_end_sequence
:
6342 lh
->file_names
[file
- 1].included_p
= 1;
6343 if (!decode_for_pst_p
)
6344 record_line (current_subfile
, 0, address
);
6346 case DW_LNE_set_address
:
6347 address
= read_address (abfd
, line_ptr
, cu
, &bytes_read
);
6348 line_ptr
+= bytes_read
;
6349 address
+= baseaddr
;
6351 case DW_LNE_define_file
:
6354 unsigned int dir_index
, mod_time
, length
;
6356 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
6357 line_ptr
+= bytes_read
;
6359 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6360 line_ptr
+= bytes_read
;
6362 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6363 line_ptr
+= bytes_read
;
6365 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6366 line_ptr
+= bytes_read
;
6367 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
6371 complaint (&symfile_complaints
,
6372 "mangled .debug_line section");
6377 lh
->file_names
[file
- 1].included_p
= 1;
6378 if (!decode_for_pst_p
)
6379 record_line (current_subfile
, line
,
6380 check_cu_functions (address
, cu
));
6383 case DW_LNS_advance_pc
:
6384 address
+= lh
->minimum_instruction_length
6385 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6386 line_ptr
+= bytes_read
;
6388 case DW_LNS_advance_line
:
6389 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
6390 line_ptr
+= bytes_read
;
6392 case DW_LNS_set_file
:
6394 /* lh->include_dirs and lh->file_names are 0-based,
6395 but the directory and file name numbers in the
6396 statement program are 1-based. */
6397 struct file_entry
*fe
;
6399 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6400 line_ptr
+= bytes_read
;
6401 fe
= &lh
->file_names
[file
- 1];
6403 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6406 if (!decode_for_pst_p
)
6407 dwarf2_start_subfile (fe
->name
, dir
);
6410 case DW_LNS_set_column
:
6411 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6412 line_ptr
+= bytes_read
;
6414 case DW_LNS_negate_stmt
:
6415 is_stmt
= (!is_stmt
);
6417 case DW_LNS_set_basic_block
:
6420 /* Add to the address register of the state machine the
6421 address increment value corresponding to special opcode
6422 255. Ie, this value is scaled by the minimum instruction
6423 length since special opcode 255 would have scaled the
6425 case DW_LNS_const_add_pc
:
6426 address
+= (lh
->minimum_instruction_length
6427 * ((255 - lh
->opcode_base
) / lh
->line_range
));
6429 case DW_LNS_fixed_advance_pc
:
6430 address
+= read_2_bytes (abfd
, line_ptr
);
6434 { /* Unknown standard opcode, ignore it. */
6436 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
6438 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
6439 line_ptr
+= bytes_read
;
6446 if (decode_for_pst_p
)
6450 /* Now that we're done scanning the Line Header Program, we can
6451 create the psymtab of each included file. */
6452 for (file_index
= 0; file_index
< lh
->num_file_names
; file_index
++)
6453 if (lh
->file_names
[file_index
].included_p
== 1)
6455 char *include_name
= lh
->file_names
[file_index
].name
;
6457 if (strcmp (include_name
, pst
->filename
) != 0)
6458 dwarf2_create_include_psymtab (include_name
, pst
, objfile
);
6463 /* Start a subfile for DWARF. FILENAME is the name of the file and
6464 DIRNAME the name of the source directory which contains FILENAME
6465 or NULL if not known.
6466 This routine tries to keep line numbers from identical absolute and
6467 relative file names in a common subfile.
6469 Using the `list' example from the GDB testsuite, which resides in
6470 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
6471 of /srcdir/list0.c yields the following debugging information for list0.c:
6473 DW_AT_name: /srcdir/list0.c
6474 DW_AT_comp_dir: /compdir
6475 files.files[0].name: list0.h
6476 files.files[0].dir: /srcdir
6477 files.files[1].name: list0.c
6478 files.files[1].dir: /srcdir
6480 The line number information for list0.c has to end up in a single
6481 subfile, so that `break /srcdir/list0.c:1' works as expected. */
6484 dwarf2_start_subfile (char *filename
, char *dirname
)
6486 /* If the filename isn't absolute, try to match an existing subfile
6487 with the full pathname. */
6489 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
6491 struct subfile
*subfile
;
6492 char *fullname
= concat (dirname
, "/", filename
, NULL
);
6494 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
6496 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
6498 current_subfile
= subfile
;
6505 start_subfile (filename
, dirname
);
6509 var_decode_location (struct attribute
*attr
, struct symbol
*sym
,
6510 struct dwarf2_cu
*cu
)
6512 struct objfile
*objfile
= cu
->objfile
;
6513 struct comp_unit_head
*cu_header
= &cu
->header
;
6515 /* NOTE drow/2003-01-30: There used to be a comment and some special
6516 code here to turn a symbol with DW_AT_external and a
6517 SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was
6518 necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux
6519 with some versions of binutils) where shared libraries could have
6520 relocations against symbols in their debug information - the
6521 minimal symbol would have the right address, but the debug info
6522 would not. It's no longer necessary, because we will explicitly
6523 apply relocations when we read in the debug information now. */
6525 /* A DW_AT_location attribute with no contents indicates that a
6526 variable has been optimized away. */
6527 if (attr_form_is_block (attr
) && DW_BLOCK (attr
)->size
== 0)
6529 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
6533 /* Handle one degenerate form of location expression specially, to
6534 preserve GDB's previous behavior when section offsets are
6535 specified. If this is just a DW_OP_addr then mark this symbol
6538 if (attr_form_is_block (attr
)
6539 && DW_BLOCK (attr
)->size
== 1 + cu_header
->addr_size
6540 && DW_BLOCK (attr
)->data
[0] == DW_OP_addr
)
6544 SYMBOL_VALUE_ADDRESS (sym
) =
6545 read_address (objfile
->obfd
, DW_BLOCK (attr
)->data
+ 1, cu
, &dummy
);
6546 fixup_symbol_section (sym
, objfile
);
6547 SYMBOL_VALUE_ADDRESS (sym
) += ANOFFSET (objfile
->section_offsets
,
6548 SYMBOL_SECTION (sym
));
6549 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6553 /* NOTE drow/2002-01-30: It might be worthwhile to have a static
6554 expression evaluator, and use LOC_COMPUTED only when necessary
6555 (i.e. when the value of a register or memory location is
6556 referenced, or a thread-local block, etc.). Then again, it might
6557 not be worthwhile. I'm assuming that it isn't unless performance
6558 or memory numbers show me otherwise. */
6560 dwarf2_symbol_mark_computed (attr
, sym
, cu
);
6561 SYMBOL_CLASS (sym
) = LOC_COMPUTED
;
6564 /* Given a pointer to a DWARF information entry, figure out if we need
6565 to make a symbol table entry for it, and if so, create a new entry
6566 and return a pointer to it.
6567 If TYPE is NULL, determine symbol type from the die, otherwise
6568 used the passed type. */
6570 static struct symbol
*
6571 new_symbol (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
6573 struct objfile
*objfile
= cu
->objfile
;
6574 struct symbol
*sym
= NULL
;
6576 struct attribute
*attr
= NULL
;
6577 struct attribute
*attr2
= NULL
;
6580 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
6582 if (die
->tag
!= DW_TAG_namespace
)
6583 name
= dwarf2_linkage_name (die
, cu
);
6585 name
= TYPE_NAME (type
);
6589 sym
= (struct symbol
*) obstack_alloc (&objfile
->objfile_obstack
,
6590 sizeof (struct symbol
));
6591 OBJSTAT (objfile
, n_syms
++);
6592 memset (sym
, 0, sizeof (struct symbol
));
6594 /* Cache this symbol's name and the name's demangled form (if any). */
6595 SYMBOL_LANGUAGE (sym
) = cu
->language
;
6596 SYMBOL_SET_NAMES (sym
, name
, strlen (name
), objfile
);
6598 /* Default assumptions.
6599 Use the passed type or decode it from the die. */
6600 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6601 SYMBOL_CLASS (sym
) = LOC_STATIC
;
6603 SYMBOL_TYPE (sym
) = type
;
6605 SYMBOL_TYPE (sym
) = die_type (die
, cu
);
6606 attr
= dwarf2_attr (die
, DW_AT_decl_line
, cu
);
6609 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
6614 attr
= dwarf2_attr (die
, DW_AT_low_pc
, cu
);
6617 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
6619 SYMBOL_CLASS (sym
) = LOC_LABEL
;
6621 case DW_TAG_subprogram
:
6622 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
6624 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
6625 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6626 if (attr2
&& (DW_UNSND (attr2
) != 0))
6628 add_symbol_to_list (sym
, &global_symbols
);
6632 add_symbol_to_list (sym
, cu
->list_in_scope
);
6635 case DW_TAG_variable
:
6636 /* Compilation with minimal debug info may result in variables
6637 with missing type entries. Change the misleading `void' type
6638 to something sensible. */
6639 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
6640 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
6641 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
6642 "<variable, no debug info>",
6644 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6647 dwarf2_const_value (attr
, sym
, cu
);
6648 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6649 if (attr2
&& (DW_UNSND (attr2
) != 0))
6650 add_symbol_to_list (sym
, &global_symbols
);
6652 add_symbol_to_list (sym
, cu
->list_in_scope
);
6655 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6658 var_decode_location (attr
, sym
, cu
);
6659 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6660 if (attr2
&& (DW_UNSND (attr2
) != 0))
6661 add_symbol_to_list (sym
, &global_symbols
);
6663 add_symbol_to_list (sym
, cu
->list_in_scope
);
6667 /* We do not know the address of this symbol.
6668 If it is an external symbol and we have type information
6669 for it, enter the symbol as a LOC_UNRESOLVED symbol.
6670 The address of the variable will then be determined from
6671 the minimal symbol table whenever the variable is
6673 attr2
= dwarf2_attr (die
, DW_AT_external
, cu
);
6674 if (attr2
&& (DW_UNSND (attr2
) != 0)
6675 && dwarf2_attr (die
, DW_AT_type
, cu
) != NULL
)
6677 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
6678 add_symbol_to_list (sym
, &global_symbols
);
6682 case DW_TAG_formal_parameter
:
6683 attr
= dwarf2_attr (die
, DW_AT_location
, cu
);
6686 var_decode_location (attr
, sym
, cu
);
6687 /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */
6688 if (SYMBOL_CLASS (sym
) == LOC_COMPUTED
)
6689 SYMBOL_CLASS (sym
) = LOC_COMPUTED_ARG
;
6691 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6694 dwarf2_const_value (attr
, sym
, cu
);
6696 add_symbol_to_list (sym
, cu
->list_in_scope
);
6698 case DW_TAG_unspecified_parameters
:
6699 /* From varargs functions; gdb doesn't seem to have any
6700 interest in this information, so just ignore it for now.
6703 case DW_TAG_class_type
:
6704 case DW_TAG_structure_type
:
6705 case DW_TAG_union_type
:
6706 case DW_TAG_enumeration_type
:
6707 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6708 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
6710 /* Make sure that the symbol includes appropriate enclosing
6711 classes/namespaces in its name. These are calculated in
6712 read_structure_type, and the correct name is saved in
6715 if (cu
->language
== language_cplus
6716 || cu
->language
== language_java
)
6718 struct type
*type
= SYMBOL_TYPE (sym
);
6720 if (TYPE_TAG_NAME (type
) != NULL
)
6722 /* FIXME: carlton/2003-11-10: Should this use
6723 SYMBOL_SET_NAMES instead? (The same problem also
6724 arises further down in this function.) */
6725 /* The type's name is already allocated along with
6726 this objfile, so we don't need to duplicate it
6728 SYMBOL_LINKAGE_NAME (sym
) = TYPE_TAG_NAME (type
);
6733 /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't
6734 really ever be static objects: otherwise, if you try
6735 to, say, break of a class's method and you're in a file
6736 which doesn't mention that class, it won't work unless
6737 the check for all static symbols in lookup_symbol_aux
6738 saves you. See the OtherFileClass tests in
6739 gdb.c++/namespace.exp. */
6741 struct pending
**list_to_add
;
6743 list_to_add
= (cu
->list_in_scope
== &file_symbols
6744 && (cu
->language
== language_cplus
6745 || cu
->language
== language_java
)
6746 ? &global_symbols
: cu
->list_in_scope
);
6748 add_symbol_to_list (sym
, list_to_add
);
6750 /* The semantics of C++ state that "struct foo { ... }" also
6751 defines a typedef for "foo". A Java class declaration also
6752 defines a typedef for the class. Synthesize a typedef symbol
6753 so that "ptype foo" works as expected. */
6754 if (cu
->language
== language_cplus
6755 || cu
->language
== language_java
)
6757 struct symbol
*typedef_sym
= (struct symbol
*)
6758 obstack_alloc (&objfile
->objfile_obstack
,
6759 sizeof (struct symbol
));
6760 *typedef_sym
= *sym
;
6761 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
6762 /* The symbol's name is already allocated along with
6763 this objfile, so we don't need to duplicate it for
6765 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
6766 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NATURAL_NAME (sym
);
6767 add_symbol_to_list (typedef_sym
, list_to_add
);
6771 case DW_TAG_typedef
:
6772 if (processing_has_namespace_info
6773 && processing_current_prefix
[0] != '\0')
6775 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
6776 processing_current_prefix
,
6779 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6780 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6781 add_symbol_to_list (sym
, cu
->list_in_scope
);
6783 case DW_TAG_base_type
:
6784 case DW_TAG_subrange_type
:
6785 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6786 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
6787 add_symbol_to_list (sym
, cu
->list_in_scope
);
6789 case DW_TAG_enumerator
:
6790 if (processing_has_namespace_info
6791 && processing_current_prefix
[0] != '\0')
6793 SYMBOL_LINKAGE_NAME (sym
) = typename_concat (&objfile
->objfile_obstack
,
6794 processing_current_prefix
,
6797 attr
= dwarf2_attr (die
, DW_AT_const_value
, cu
);
6800 dwarf2_const_value (attr
, sym
, cu
);
6803 /* NOTE: carlton/2003-11-10: See comment above in the
6804 DW_TAG_class_type, etc. block. */
6806 struct pending
**list_to_add
;
6808 list_to_add
= (cu
->list_in_scope
== &file_symbols
6809 && (cu
->language
== language_cplus
6810 || cu
->language
== language_java
)
6811 ? &global_symbols
: cu
->list_in_scope
);
6813 add_symbol_to_list (sym
, list_to_add
);
6816 case DW_TAG_namespace
:
6817 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
6818 add_symbol_to_list (sym
, &global_symbols
);
6821 /* Not a tag we recognize. Hopefully we aren't processing
6822 trash data, but since we must specifically ignore things
6823 we don't recognize, there is nothing else we should do at
6825 complaint (&symfile_complaints
, "unsupported tag: '%s'",
6826 dwarf_tag_name (die
->tag
));
6833 /* Copy constant value from an attribute to a symbol. */
6836 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
6837 struct dwarf2_cu
*cu
)
6839 struct objfile
*objfile
= cu
->objfile
;
6840 struct comp_unit_head
*cu_header
= &cu
->header
;
6841 struct dwarf_block
*blk
;
6846 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
6847 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6848 cu_header
->addr_size
,
6849 TYPE_LENGTH (SYMBOL_TYPE
6851 SYMBOL_VALUE_BYTES (sym
) = (char *)
6852 obstack_alloc (&objfile
->objfile_obstack
, cu_header
->addr_size
);
6853 /* NOTE: cagney/2003-05-09: In-lined store_address call with
6854 it's body - store_unsigned_integer. */
6855 store_unsigned_integer (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
6857 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6859 case DW_FORM_block1
:
6860 case DW_FORM_block2
:
6861 case DW_FORM_block4
:
6863 blk
= DW_BLOCK (attr
);
6864 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
6865 dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym
),
6867 TYPE_LENGTH (SYMBOL_TYPE
6869 SYMBOL_VALUE_BYTES (sym
) = (char *)
6870 obstack_alloc (&objfile
->objfile_obstack
, blk
->size
);
6871 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
6872 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
6875 /* The DW_AT_const_value attributes are supposed to carry the
6876 symbol's value "represented as it would be on the target
6877 architecture." By the time we get here, it's already been
6878 converted to host endianness, so we just need to sign- or
6879 zero-extend it as appropriate. */
6881 dwarf2_const_value_data (attr
, sym
, 8);
6884 dwarf2_const_value_data (attr
, sym
, 16);
6887 dwarf2_const_value_data (attr
, sym
, 32);
6890 dwarf2_const_value_data (attr
, sym
, 64);
6894 SYMBOL_VALUE (sym
) = DW_SND (attr
);
6895 SYMBOL_CLASS (sym
) = LOC_CONST
;
6899 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
6900 SYMBOL_CLASS (sym
) = LOC_CONST
;
6904 complaint (&symfile_complaints
,
6905 "unsupported const value attribute form: '%s'",
6906 dwarf_form_name (attr
->form
));
6907 SYMBOL_VALUE (sym
) = 0;
6908 SYMBOL_CLASS (sym
) = LOC_CONST
;
6914 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
6915 or zero-extend it as appropriate for the symbol's type. */
6917 dwarf2_const_value_data (struct attribute
*attr
,
6921 LONGEST l
= DW_UNSND (attr
);
6923 if (bits
< sizeof (l
) * 8)
6925 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
6926 l
&= ((LONGEST
) 1 << bits
) - 1;
6928 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
6931 SYMBOL_VALUE (sym
) = l
;
6932 SYMBOL_CLASS (sym
) = LOC_CONST
;
6936 /* Return the type of the die in question using its DW_AT_type attribute. */
6938 static struct type
*
6939 die_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6942 struct attribute
*type_attr
;
6943 struct die_info
*type_die
;
6946 type_attr
= dwarf2_attr (die
, DW_AT_type
, cu
);
6949 /* A missing DW_AT_type represents a void type. */
6950 return dwarf2_fundamental_type (cu
->objfile
, FT_VOID
, cu
);
6954 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6955 type_die
= follow_die_ref (ref
);
6958 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]",
6959 ref
, cu
->objfile
->name
);
6963 type
= tag_type_to_type (type_die
, cu
);
6966 dump_die (type_die
);
6967 error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]",
6973 /* Return the containing type of the die in question using its
6974 DW_AT_containing_type attribute. */
6976 static struct type
*
6977 die_containing_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
6979 struct type
*type
= NULL
;
6980 struct attribute
*type_attr
;
6981 struct die_info
*type_die
= NULL
;
6984 type_attr
= dwarf2_attr (die
, DW_AT_containing_type
, cu
);
6987 ref
= dwarf2_get_ref_die_offset (type_attr
, cu
);
6988 type_die
= follow_die_ref (ref
);
6991 error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref
,
6995 type
= tag_type_to_type (type_die
, cu
);
7000 dump_die (type_die
);
7001 error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]",
7008 static struct type
*
7009 type_at_offset (unsigned int offset
, struct dwarf2_cu
*cu
)
7011 struct die_info
*die
;
7014 die
= follow_die_ref (offset
);
7017 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
7020 type
= tag_type_to_type (die
, cu
);
7025 static struct type
*
7026 tag_type_to_type (struct die_info
*die
, struct dwarf2_cu
*cu
)
7034 read_type_die (die
, cu
);
7038 error ("Dwarf Error: Cannot find type of die [in module %s]",
7046 read_type_die (struct die_info
*die
, struct dwarf2_cu
*cu
)
7048 char *prefix
= determine_prefix (die
, cu
);
7049 const char *old_prefix
= processing_current_prefix
;
7050 struct cleanup
*back_to
= make_cleanup (xfree
, prefix
);
7051 processing_current_prefix
= prefix
;
7055 case DW_TAG_class_type
:
7056 case DW_TAG_structure_type
:
7057 case DW_TAG_union_type
:
7058 read_structure_type (die
, cu
);
7060 case DW_TAG_enumeration_type
:
7061 read_enumeration_type (die
, cu
);
7063 case DW_TAG_subprogram
:
7064 case DW_TAG_subroutine_type
:
7065 read_subroutine_type (die
, cu
);
7067 case DW_TAG_array_type
:
7068 read_array_type (die
, cu
);
7070 case DW_TAG_pointer_type
:
7071 read_tag_pointer_type (die
, cu
);
7073 case DW_TAG_ptr_to_member_type
:
7074 read_tag_ptr_to_member_type (die
, cu
);
7076 case DW_TAG_reference_type
:
7077 read_tag_reference_type (die
, cu
);
7079 case DW_TAG_const_type
:
7080 read_tag_const_type (die
, cu
);
7082 case DW_TAG_volatile_type
:
7083 read_tag_volatile_type (die
, cu
);
7085 case DW_TAG_string_type
:
7086 read_tag_string_type (die
, cu
);
7088 case DW_TAG_typedef
:
7089 read_typedef (die
, cu
);
7091 case DW_TAG_subrange_type
:
7092 read_subrange_type (die
, cu
);
7094 case DW_TAG_base_type
:
7095 read_base_type (die
, cu
);
7098 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
7099 dwarf_tag_name (die
->tag
));
7103 processing_current_prefix
= old_prefix
;
7104 do_cleanups (back_to
);
7107 /* Return the name of the namespace/class that DIE is defined within,
7108 or "" if we can't tell. The caller should xfree the result. */
7110 /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment
7111 therein) for an example of how to use this function to deal with
7112 DW_AT_specification. */
7115 determine_prefix (struct die_info
*die
, struct dwarf2_cu
*cu
)
7117 struct die_info
*parent
;
7119 if (cu
->language
!= language_cplus
7120 && cu
->language
!= language_java
)
7123 parent
= die
->parent
;
7127 return xstrdup ("");
7131 switch (parent
->tag
) {
7132 case DW_TAG_namespace
:
7134 /* FIXME: carlton/2004-03-05: Should I follow extension dies
7135 before doing this check? */
7136 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
7138 return xstrdup (TYPE_TAG_NAME (parent
->type
));
7143 char *parent_prefix
= determine_prefix (parent
, cu
);
7144 char *retval
= typename_concat (NULL
, parent_prefix
,
7145 namespace_name (parent
, &dummy
,
7148 xfree (parent_prefix
);
7153 case DW_TAG_class_type
:
7154 case DW_TAG_structure_type
:
7156 if (parent
->type
!= NULL
&& TYPE_TAG_NAME (parent
->type
) != NULL
)
7158 return xstrdup (TYPE_TAG_NAME (parent
->type
));
7162 const char *old_prefix
= processing_current_prefix
;
7163 char *new_prefix
= determine_prefix (parent
, cu
);
7166 processing_current_prefix
= new_prefix
;
7167 retval
= determine_class_name (parent
, cu
);
7168 processing_current_prefix
= old_prefix
;
7175 return determine_prefix (parent
, cu
);
7180 /* Return a newly-allocated string formed by concatenating PREFIX and
7181 SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then
7182 simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null,
7183 perform an obconcat, otherwise allocate storage for the result. The CU argument
7184 is used to determine the language and hence, the appropriate separator. */
7186 #define MAX_SEP_LEN 2 /* sizeof ("::") */
7189 typename_concat (struct obstack
*obs
, const char *prefix
, const char *suffix
,
7190 struct dwarf2_cu
*cu
)
7194 if (suffix
== NULL
|| suffix
[0] == '\0' || prefix
== NULL
|| prefix
[0] == '\0')
7196 else if (cu
->language
== language_java
)
7203 char *retval
= xmalloc (strlen (prefix
) + MAX_SEP_LEN
+ strlen (suffix
) + 1);
7208 strcpy (retval
, prefix
);
7209 strcat (retval
, sep
);
7212 strcat (retval
, suffix
);
7218 /* We have an obstack. */
7219 return obconcat (obs
, prefix
, sep
, suffix
);
7223 static struct type
*
7224 dwarf_base_type (int encoding
, int size
, struct dwarf2_cu
*cu
)
7226 struct objfile
*objfile
= cu
->objfile
;
7228 /* FIXME - this should not produce a new (struct type *)
7229 every time. It should cache base types. */
7233 case DW_ATE_address
:
7234 type
= dwarf2_fundamental_type (objfile
, FT_VOID
, cu
);
7236 case DW_ATE_boolean
:
7237 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
, cu
);
7239 case DW_ATE_complex_float
:
7242 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
, cu
);
7246 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
, cu
);
7252 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
, cu
);
7256 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
, cu
);
7263 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
7266 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
, cu
);
7270 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
7274 case DW_ATE_signed_char
:
7275 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
, cu
);
7277 case DW_ATE_unsigned
:
7281 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
7284 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
, cu
);
7288 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
, cu
);
7292 case DW_ATE_unsigned_char
:
7293 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
, cu
);
7296 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
, cu
);
7303 copy_die (struct die_info
*old_die
)
7305 struct die_info
*new_die
;
7308 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
7309 memset (new_die
, 0, sizeof (struct die_info
));
7311 new_die
->tag
= old_die
->tag
;
7312 new_die
->has_children
= old_die
->has_children
;
7313 new_die
->abbrev
= old_die
->abbrev
;
7314 new_die
->offset
= old_die
->offset
;
7315 new_die
->type
= NULL
;
7317 num_attrs
= old_die
->num_attrs
;
7318 new_die
->num_attrs
= num_attrs
;
7319 new_die
->attrs
= (struct attribute
*)
7320 xmalloc (num_attrs
* sizeof (struct attribute
));
7322 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
7324 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
7325 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
7326 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
7329 new_die
->next
= NULL
;
7334 /* Return sibling of die, NULL if no sibling. */
7336 static struct die_info
*
7337 sibling_die (struct die_info
*die
)
7339 return die
->sibling
;
7342 /* Get linkage name of a die, return NULL if not found. */
7345 dwarf2_linkage_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7347 struct attribute
*attr
;
7349 attr
= dwarf2_attr (die
, DW_AT_MIPS_linkage_name
, cu
);
7350 if (attr
&& DW_STRING (attr
))
7351 return DW_STRING (attr
);
7352 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7353 if (attr
&& DW_STRING (attr
))
7354 return DW_STRING (attr
);
7358 /* Get name of a die, return NULL if not found. */
7361 dwarf2_name (struct die_info
*die
, struct dwarf2_cu
*cu
)
7363 struct attribute
*attr
;
7365 attr
= dwarf2_attr (die
, DW_AT_name
, cu
);
7366 if (attr
&& DW_STRING (attr
))
7367 return DW_STRING (attr
);
7371 /* Return the die that this die in an extension of, or NULL if there
7374 static struct die_info
*
7375 dwarf2_extension (struct die_info
*die
, struct dwarf2_cu
*cu
)
7377 struct attribute
*attr
;
7378 struct die_info
*extension_die
;
7381 attr
= dwarf2_attr (die
, DW_AT_extension
, cu
);
7385 ref
= dwarf2_get_ref_die_offset (attr
, cu
);
7386 extension_die
= follow_die_ref (ref
);
7389 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
7392 return extension_die
;
7395 /* Convert a DIE tag into its string name. */
7398 dwarf_tag_name (unsigned tag
)
7402 case DW_TAG_padding
:
7403 return "DW_TAG_padding";
7404 case DW_TAG_array_type
:
7405 return "DW_TAG_array_type";
7406 case DW_TAG_class_type
:
7407 return "DW_TAG_class_type";
7408 case DW_TAG_entry_point
:
7409 return "DW_TAG_entry_point";
7410 case DW_TAG_enumeration_type
:
7411 return "DW_TAG_enumeration_type";
7412 case DW_TAG_formal_parameter
:
7413 return "DW_TAG_formal_parameter";
7414 case DW_TAG_imported_declaration
:
7415 return "DW_TAG_imported_declaration";
7417 return "DW_TAG_label";
7418 case DW_TAG_lexical_block
:
7419 return "DW_TAG_lexical_block";
7421 return "DW_TAG_member";
7422 case DW_TAG_pointer_type
:
7423 return "DW_TAG_pointer_type";
7424 case DW_TAG_reference_type
:
7425 return "DW_TAG_reference_type";
7426 case DW_TAG_compile_unit
:
7427 return "DW_TAG_compile_unit";
7428 case DW_TAG_string_type
:
7429 return "DW_TAG_string_type";
7430 case DW_TAG_structure_type
:
7431 return "DW_TAG_structure_type";
7432 case DW_TAG_subroutine_type
:
7433 return "DW_TAG_subroutine_type";
7434 case DW_TAG_typedef
:
7435 return "DW_TAG_typedef";
7436 case DW_TAG_union_type
:
7437 return "DW_TAG_union_type";
7438 case DW_TAG_unspecified_parameters
:
7439 return "DW_TAG_unspecified_parameters";
7440 case DW_TAG_variant
:
7441 return "DW_TAG_variant";
7442 case DW_TAG_common_block
:
7443 return "DW_TAG_common_block";
7444 case DW_TAG_common_inclusion
:
7445 return "DW_TAG_common_inclusion";
7446 case DW_TAG_inheritance
:
7447 return "DW_TAG_inheritance";
7448 case DW_TAG_inlined_subroutine
:
7449 return "DW_TAG_inlined_subroutine";
7451 return "DW_TAG_module";
7452 case DW_TAG_ptr_to_member_type
:
7453 return "DW_TAG_ptr_to_member_type";
7454 case DW_TAG_set_type
:
7455 return "DW_TAG_set_type";
7456 case DW_TAG_subrange_type
:
7457 return "DW_TAG_subrange_type";
7458 case DW_TAG_with_stmt
:
7459 return "DW_TAG_with_stmt";
7460 case DW_TAG_access_declaration
:
7461 return "DW_TAG_access_declaration";
7462 case DW_TAG_base_type
:
7463 return "DW_TAG_base_type";
7464 case DW_TAG_catch_block
:
7465 return "DW_TAG_catch_block";
7466 case DW_TAG_const_type
:
7467 return "DW_TAG_const_type";
7468 case DW_TAG_constant
:
7469 return "DW_TAG_constant";
7470 case DW_TAG_enumerator
:
7471 return "DW_TAG_enumerator";
7472 case DW_TAG_file_type
:
7473 return "DW_TAG_file_type";
7475 return "DW_TAG_friend";
7476 case DW_TAG_namelist
:
7477 return "DW_TAG_namelist";
7478 case DW_TAG_namelist_item
:
7479 return "DW_TAG_namelist_item";
7480 case DW_TAG_packed_type
:
7481 return "DW_TAG_packed_type";
7482 case DW_TAG_subprogram
:
7483 return "DW_TAG_subprogram";
7484 case DW_TAG_template_type_param
:
7485 return "DW_TAG_template_type_param";
7486 case DW_TAG_template_value_param
:
7487 return "DW_TAG_template_value_param";
7488 case DW_TAG_thrown_type
:
7489 return "DW_TAG_thrown_type";
7490 case DW_TAG_try_block
:
7491 return "DW_TAG_try_block";
7492 case DW_TAG_variant_part
:
7493 return "DW_TAG_variant_part";
7494 case DW_TAG_variable
:
7495 return "DW_TAG_variable";
7496 case DW_TAG_volatile_type
:
7497 return "DW_TAG_volatile_type";
7498 case DW_TAG_dwarf_procedure
:
7499 return "DW_TAG_dwarf_procedure";
7500 case DW_TAG_restrict_type
:
7501 return "DW_TAG_restrict_type";
7502 case DW_TAG_interface_type
:
7503 return "DW_TAG_interface_type";
7504 case DW_TAG_namespace
:
7505 return "DW_TAG_namespace";
7506 case DW_TAG_imported_module
:
7507 return "DW_TAG_imported_module";
7508 case DW_TAG_unspecified_type
:
7509 return "DW_TAG_unspecified_type";
7510 case DW_TAG_partial_unit
:
7511 return "DW_TAG_partial_unit";
7512 case DW_TAG_imported_unit
:
7513 return "DW_TAG_imported_unit";
7514 case DW_TAG_MIPS_loop
:
7515 return "DW_TAG_MIPS_loop";
7516 case DW_TAG_format_label
:
7517 return "DW_TAG_format_label";
7518 case DW_TAG_function_template
:
7519 return "DW_TAG_function_template";
7520 case DW_TAG_class_template
:
7521 return "DW_TAG_class_template";
7523 return "DW_TAG_<unknown>";
7527 /* Convert a DWARF attribute code into its string name. */
7530 dwarf_attr_name (unsigned attr
)
7535 return "DW_AT_sibling";
7536 case DW_AT_location
:
7537 return "DW_AT_location";
7539 return "DW_AT_name";
7540 case DW_AT_ordering
:
7541 return "DW_AT_ordering";
7542 case DW_AT_subscr_data
:
7543 return "DW_AT_subscr_data";
7544 case DW_AT_byte_size
:
7545 return "DW_AT_byte_size";
7546 case DW_AT_bit_offset
:
7547 return "DW_AT_bit_offset";
7548 case DW_AT_bit_size
:
7549 return "DW_AT_bit_size";
7550 case DW_AT_element_list
:
7551 return "DW_AT_element_list";
7552 case DW_AT_stmt_list
:
7553 return "DW_AT_stmt_list";
7555 return "DW_AT_low_pc";
7557 return "DW_AT_high_pc";
7558 case DW_AT_language
:
7559 return "DW_AT_language";
7561 return "DW_AT_member";
7563 return "DW_AT_discr";
7564 case DW_AT_discr_value
:
7565 return "DW_AT_discr_value";
7566 case DW_AT_visibility
:
7567 return "DW_AT_visibility";
7569 return "DW_AT_import";
7570 case DW_AT_string_length
:
7571 return "DW_AT_string_length";
7572 case DW_AT_common_reference
:
7573 return "DW_AT_common_reference";
7574 case DW_AT_comp_dir
:
7575 return "DW_AT_comp_dir";
7576 case DW_AT_const_value
:
7577 return "DW_AT_const_value";
7578 case DW_AT_containing_type
:
7579 return "DW_AT_containing_type";
7580 case DW_AT_default_value
:
7581 return "DW_AT_default_value";
7583 return "DW_AT_inline";
7584 case DW_AT_is_optional
:
7585 return "DW_AT_is_optional";
7586 case DW_AT_lower_bound
:
7587 return "DW_AT_lower_bound";
7588 case DW_AT_producer
:
7589 return "DW_AT_producer";
7590 case DW_AT_prototyped
:
7591 return "DW_AT_prototyped";
7592 case DW_AT_return_addr
:
7593 return "DW_AT_return_addr";
7594 case DW_AT_start_scope
:
7595 return "DW_AT_start_scope";
7596 case DW_AT_stride_size
:
7597 return "DW_AT_stride_size";
7598 case DW_AT_upper_bound
:
7599 return "DW_AT_upper_bound";
7600 case DW_AT_abstract_origin
:
7601 return "DW_AT_abstract_origin";
7602 case DW_AT_accessibility
:
7603 return "DW_AT_accessibility";
7604 case DW_AT_address_class
:
7605 return "DW_AT_address_class";
7606 case DW_AT_artificial
:
7607 return "DW_AT_artificial";
7608 case DW_AT_base_types
:
7609 return "DW_AT_base_types";
7610 case DW_AT_calling_convention
:
7611 return "DW_AT_calling_convention";
7613 return "DW_AT_count";
7614 case DW_AT_data_member_location
:
7615 return "DW_AT_data_member_location";
7616 case DW_AT_decl_column
:
7617 return "DW_AT_decl_column";
7618 case DW_AT_decl_file
:
7619 return "DW_AT_decl_file";
7620 case DW_AT_decl_line
:
7621 return "DW_AT_decl_line";
7622 case DW_AT_declaration
:
7623 return "DW_AT_declaration";
7624 case DW_AT_discr_list
:
7625 return "DW_AT_discr_list";
7626 case DW_AT_encoding
:
7627 return "DW_AT_encoding";
7628 case DW_AT_external
:
7629 return "DW_AT_external";
7630 case DW_AT_frame_base
:
7631 return "DW_AT_frame_base";
7633 return "DW_AT_friend";
7634 case DW_AT_identifier_case
:
7635 return "DW_AT_identifier_case";
7636 case DW_AT_macro_info
:
7637 return "DW_AT_macro_info";
7638 case DW_AT_namelist_items
:
7639 return "DW_AT_namelist_items";
7640 case DW_AT_priority
:
7641 return "DW_AT_priority";
7643 return "DW_AT_segment";
7644 case DW_AT_specification
:
7645 return "DW_AT_specification";
7646 case DW_AT_static_link
:
7647 return "DW_AT_static_link";
7649 return "DW_AT_type";
7650 case DW_AT_use_location
:
7651 return "DW_AT_use_location";
7652 case DW_AT_variable_parameter
:
7653 return "DW_AT_variable_parameter";
7654 case DW_AT_virtuality
:
7655 return "DW_AT_virtuality";
7656 case DW_AT_vtable_elem_location
:
7657 return "DW_AT_vtable_elem_location";
7658 case DW_AT_allocated
:
7659 return "DW_AT_allocated";
7660 case DW_AT_associated
:
7661 return "DW_AT_associated";
7662 case DW_AT_data_location
:
7663 return "DW_AT_data_location";
7665 return "DW_AT_stride";
7666 case DW_AT_entry_pc
:
7667 return "DW_AT_entry_pc";
7668 case DW_AT_use_UTF8
:
7669 return "DW_AT_use_UTF8";
7670 case DW_AT_extension
:
7671 return "DW_AT_extension";
7673 return "DW_AT_ranges";
7674 case DW_AT_trampoline
:
7675 return "DW_AT_trampoline";
7676 case DW_AT_call_column
:
7677 return "DW_AT_call_column";
7678 case DW_AT_call_file
:
7679 return "DW_AT_call_file";
7680 case DW_AT_call_line
:
7681 return "DW_AT_call_line";
7683 case DW_AT_MIPS_fde
:
7684 return "DW_AT_MIPS_fde";
7685 case DW_AT_MIPS_loop_begin
:
7686 return "DW_AT_MIPS_loop_begin";
7687 case DW_AT_MIPS_tail_loop_begin
:
7688 return "DW_AT_MIPS_tail_loop_begin";
7689 case DW_AT_MIPS_epilog_begin
:
7690 return "DW_AT_MIPS_epilog_begin";
7691 case DW_AT_MIPS_loop_unroll_factor
:
7692 return "DW_AT_MIPS_loop_unroll_factor";
7693 case DW_AT_MIPS_software_pipeline_depth
:
7694 return "DW_AT_MIPS_software_pipeline_depth";
7696 case DW_AT_MIPS_linkage_name
:
7697 return "DW_AT_MIPS_linkage_name";
7699 case DW_AT_sf_names
:
7700 return "DW_AT_sf_names";
7701 case DW_AT_src_info
:
7702 return "DW_AT_src_info";
7703 case DW_AT_mac_info
:
7704 return "DW_AT_mac_info";
7705 case DW_AT_src_coords
:
7706 return "DW_AT_src_coords";
7707 case DW_AT_body_begin
:
7708 return "DW_AT_body_begin";
7709 case DW_AT_body_end
:
7710 return "DW_AT_body_end";
7711 case DW_AT_GNU_vector
:
7712 return "DW_AT_GNU_vector";
7714 return "DW_AT_<unknown>";
7718 /* Convert a DWARF value form code into its string name. */
7721 dwarf_form_name (unsigned form
)
7726 return "DW_FORM_addr";
7727 case DW_FORM_block2
:
7728 return "DW_FORM_block2";
7729 case DW_FORM_block4
:
7730 return "DW_FORM_block4";
7732 return "DW_FORM_data2";
7734 return "DW_FORM_data4";
7736 return "DW_FORM_data8";
7737 case DW_FORM_string
:
7738 return "DW_FORM_string";
7740 return "DW_FORM_block";
7741 case DW_FORM_block1
:
7742 return "DW_FORM_block1";
7744 return "DW_FORM_data1";
7746 return "DW_FORM_flag";
7748 return "DW_FORM_sdata";
7750 return "DW_FORM_strp";
7752 return "DW_FORM_udata";
7753 case DW_FORM_ref_addr
:
7754 return "DW_FORM_ref_addr";
7756 return "DW_FORM_ref1";
7758 return "DW_FORM_ref2";
7760 return "DW_FORM_ref4";
7762 return "DW_FORM_ref8";
7763 case DW_FORM_ref_udata
:
7764 return "DW_FORM_ref_udata";
7765 case DW_FORM_indirect
:
7766 return "DW_FORM_indirect";
7768 return "DW_FORM_<unknown>";
7772 /* Convert a DWARF stack opcode into its string name. */
7775 dwarf_stack_op_name (unsigned op
)
7780 return "DW_OP_addr";
7782 return "DW_OP_deref";
7784 return "DW_OP_const1u";
7786 return "DW_OP_const1s";
7788 return "DW_OP_const2u";
7790 return "DW_OP_const2s";
7792 return "DW_OP_const4u";
7794 return "DW_OP_const4s";
7796 return "DW_OP_const8u";
7798 return "DW_OP_const8s";
7800 return "DW_OP_constu";
7802 return "DW_OP_consts";
7806 return "DW_OP_drop";
7808 return "DW_OP_over";
7810 return "DW_OP_pick";
7812 return "DW_OP_swap";
7816 return "DW_OP_xderef";
7824 return "DW_OP_minus";
7836 return "DW_OP_plus";
7837 case DW_OP_plus_uconst
:
7838 return "DW_OP_plus_uconst";
7844 return "DW_OP_shra";
7862 return "DW_OP_skip";
7864 return "DW_OP_lit0";
7866 return "DW_OP_lit1";
7868 return "DW_OP_lit2";
7870 return "DW_OP_lit3";
7872 return "DW_OP_lit4";
7874 return "DW_OP_lit5";
7876 return "DW_OP_lit6";
7878 return "DW_OP_lit7";
7880 return "DW_OP_lit8";
7882 return "DW_OP_lit9";
7884 return "DW_OP_lit10";
7886 return "DW_OP_lit11";
7888 return "DW_OP_lit12";
7890 return "DW_OP_lit13";
7892 return "DW_OP_lit14";
7894 return "DW_OP_lit15";
7896 return "DW_OP_lit16";
7898 return "DW_OP_lit17";
7900 return "DW_OP_lit18";
7902 return "DW_OP_lit19";
7904 return "DW_OP_lit20";
7906 return "DW_OP_lit21";
7908 return "DW_OP_lit22";
7910 return "DW_OP_lit23";
7912 return "DW_OP_lit24";
7914 return "DW_OP_lit25";
7916 return "DW_OP_lit26";
7918 return "DW_OP_lit27";
7920 return "DW_OP_lit28";
7922 return "DW_OP_lit29";
7924 return "DW_OP_lit30";
7926 return "DW_OP_lit31";
7928 return "DW_OP_reg0";
7930 return "DW_OP_reg1";
7932 return "DW_OP_reg2";
7934 return "DW_OP_reg3";
7936 return "DW_OP_reg4";
7938 return "DW_OP_reg5";
7940 return "DW_OP_reg6";
7942 return "DW_OP_reg7";
7944 return "DW_OP_reg8";
7946 return "DW_OP_reg9";
7948 return "DW_OP_reg10";
7950 return "DW_OP_reg11";
7952 return "DW_OP_reg12";
7954 return "DW_OP_reg13";
7956 return "DW_OP_reg14";
7958 return "DW_OP_reg15";
7960 return "DW_OP_reg16";
7962 return "DW_OP_reg17";
7964 return "DW_OP_reg18";
7966 return "DW_OP_reg19";
7968 return "DW_OP_reg20";
7970 return "DW_OP_reg21";
7972 return "DW_OP_reg22";
7974 return "DW_OP_reg23";
7976 return "DW_OP_reg24";
7978 return "DW_OP_reg25";
7980 return "DW_OP_reg26";
7982 return "DW_OP_reg27";
7984 return "DW_OP_reg28";
7986 return "DW_OP_reg29";
7988 return "DW_OP_reg30";
7990 return "DW_OP_reg31";
7992 return "DW_OP_breg0";
7994 return "DW_OP_breg1";
7996 return "DW_OP_breg2";
7998 return "DW_OP_breg3";
8000 return "DW_OP_breg4";
8002 return "DW_OP_breg5";
8004 return "DW_OP_breg6";
8006 return "DW_OP_breg7";
8008 return "DW_OP_breg8";
8010 return "DW_OP_breg9";
8012 return "DW_OP_breg10";
8014 return "DW_OP_breg11";
8016 return "DW_OP_breg12";
8018 return "DW_OP_breg13";
8020 return "DW_OP_breg14";
8022 return "DW_OP_breg15";
8024 return "DW_OP_breg16";
8026 return "DW_OP_breg17";
8028 return "DW_OP_breg18";
8030 return "DW_OP_breg19";
8032 return "DW_OP_breg20";
8034 return "DW_OP_breg21";
8036 return "DW_OP_breg22";
8038 return "DW_OP_breg23";
8040 return "DW_OP_breg24";
8042 return "DW_OP_breg25";
8044 return "DW_OP_breg26";
8046 return "DW_OP_breg27";
8048 return "DW_OP_breg28";
8050 return "DW_OP_breg29";
8052 return "DW_OP_breg30";
8054 return "DW_OP_breg31";
8056 return "DW_OP_regx";
8058 return "DW_OP_fbreg";
8060 return "DW_OP_bregx";
8062 return "DW_OP_piece";
8063 case DW_OP_deref_size
:
8064 return "DW_OP_deref_size";
8065 case DW_OP_xderef_size
:
8066 return "DW_OP_xderef_size";
8069 /* DWARF 3 extensions. */
8070 case DW_OP_push_object_address
:
8071 return "DW_OP_push_object_address";
8073 return "DW_OP_call2";
8075 return "DW_OP_call4";
8076 case DW_OP_call_ref
:
8077 return "DW_OP_call_ref";
8078 /* GNU extensions. */
8079 case DW_OP_GNU_push_tls_address
:
8080 return "DW_OP_GNU_push_tls_address";
8082 return "OP_<unknown>";
8087 dwarf_bool_name (unsigned mybool
)
8095 /* Convert a DWARF type code into its string name. */
8098 dwarf_type_encoding_name (unsigned enc
)
8102 case DW_ATE_address
:
8103 return "DW_ATE_address";
8104 case DW_ATE_boolean
:
8105 return "DW_ATE_boolean";
8106 case DW_ATE_complex_float
:
8107 return "DW_ATE_complex_float";
8109 return "DW_ATE_float";
8111 return "DW_ATE_signed";
8112 case DW_ATE_signed_char
:
8113 return "DW_ATE_signed_char";
8114 case DW_ATE_unsigned
:
8115 return "DW_ATE_unsigned";
8116 case DW_ATE_unsigned_char
:
8117 return "DW_ATE_unsigned_char";
8118 case DW_ATE_imaginary_float
:
8119 return "DW_ATE_imaginary_float";
8121 return "DW_ATE_<unknown>";
8125 /* Convert a DWARF call frame info operation to its string name. */
8129 dwarf_cfi_name (unsigned cfi_opc
)
8133 case DW_CFA_advance_loc
:
8134 return "DW_CFA_advance_loc";
8136 return "DW_CFA_offset";
8137 case DW_CFA_restore
:
8138 return "DW_CFA_restore";
8140 return "DW_CFA_nop";
8141 case DW_CFA_set_loc
:
8142 return "DW_CFA_set_loc";
8143 case DW_CFA_advance_loc1
:
8144 return "DW_CFA_advance_loc1";
8145 case DW_CFA_advance_loc2
:
8146 return "DW_CFA_advance_loc2";
8147 case DW_CFA_advance_loc4
:
8148 return "DW_CFA_advance_loc4";
8149 case DW_CFA_offset_extended
:
8150 return "DW_CFA_offset_extended";
8151 case DW_CFA_restore_extended
:
8152 return "DW_CFA_restore_extended";
8153 case DW_CFA_undefined
:
8154 return "DW_CFA_undefined";
8155 case DW_CFA_same_value
:
8156 return "DW_CFA_same_value";
8157 case DW_CFA_register
:
8158 return "DW_CFA_register";
8159 case DW_CFA_remember_state
:
8160 return "DW_CFA_remember_state";
8161 case DW_CFA_restore_state
:
8162 return "DW_CFA_restore_state";
8163 case DW_CFA_def_cfa
:
8164 return "DW_CFA_def_cfa";
8165 case DW_CFA_def_cfa_register
:
8166 return "DW_CFA_def_cfa_register";
8167 case DW_CFA_def_cfa_offset
:
8168 return "DW_CFA_def_cfa_offset";
8171 case DW_CFA_def_cfa_expression
:
8172 return "DW_CFA_def_cfa_expression";
8173 case DW_CFA_expression
:
8174 return "DW_CFA_expression";
8175 case DW_CFA_offset_extended_sf
:
8176 return "DW_CFA_offset_extended_sf";
8177 case DW_CFA_def_cfa_sf
:
8178 return "DW_CFA_def_cfa_sf";
8179 case DW_CFA_def_cfa_offset_sf
:
8180 return "DW_CFA_def_cfa_offset_sf";
8182 /* SGI/MIPS specific */
8183 case DW_CFA_MIPS_advance_loc8
:
8184 return "DW_CFA_MIPS_advance_loc8";
8186 /* GNU extensions */
8187 case DW_CFA_GNU_window_save
:
8188 return "DW_CFA_GNU_window_save";
8189 case DW_CFA_GNU_args_size
:
8190 return "DW_CFA_GNU_args_size";
8191 case DW_CFA_GNU_negative_offset_extended
:
8192 return "DW_CFA_GNU_negative_offset_extended";
8195 return "DW_CFA_<unknown>";
8201 dump_die (struct die_info
*die
)
8205 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
8206 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
8207 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
8208 dwarf_bool_name (die
->child
!= NULL
));
8210 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
8211 for (i
= 0; i
< die
->num_attrs
; ++i
)
8213 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
8214 dwarf_attr_name (die
->attrs
[i
].name
),
8215 dwarf_form_name (die
->attrs
[i
].form
));
8216 switch (die
->attrs
[i
].form
)
8218 case DW_FORM_ref_addr
:
8220 fprintf_unfiltered (gdb_stderr
, "address: ");
8221 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
8223 case DW_FORM_block2
:
8224 case DW_FORM_block4
:
8226 case DW_FORM_block1
:
8227 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
8238 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
8240 case DW_FORM_string
:
8242 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
8243 DW_STRING (&die
->attrs
[i
])
8244 ? DW_STRING (&die
->attrs
[i
]) : "");
8247 if (DW_UNSND (&die
->attrs
[i
]))
8248 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
8250 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
8252 case DW_FORM_indirect
:
8253 /* the reader will have reduced the indirect form to
8254 the "base form" so this form should not occur */
8255 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
8258 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
8259 die
->attrs
[i
].form
);
8261 fprintf_unfiltered (gdb_stderr
, "\n");
8266 dump_die_list (struct die_info
*die
)
8271 if (die
->child
!= NULL
)
8272 dump_die_list (die
->child
);
8273 if (die
->sibling
!= NULL
)
8274 dump_die_list (die
->sibling
);
8279 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
8282 struct die_info
*old
;
8284 h
= (offset
% REF_HASH_SIZE
);
8285 old
= die_ref_table
[h
];
8286 die
->next_ref
= old
;
8287 die_ref_table
[h
] = die
;
8292 dwarf2_empty_hash_tables (void)
8294 memset (die_ref_table
, 0, sizeof (die_ref_table
));
8298 dwarf2_get_ref_die_offset (struct attribute
*attr
, struct dwarf2_cu
*cu
)
8300 unsigned int result
= 0;
8304 case DW_FORM_ref_addr
:
8305 result
= DW_ADDR (attr
);
8311 case DW_FORM_ref_udata
:
8312 result
= cu
->header
.offset
+ DW_UNSND (attr
);
8315 complaint (&symfile_complaints
,
8316 "unsupported die ref attribute form: '%s'",
8317 dwarf_form_name (attr
->form
));
8322 /* Return the constant value held by the given attribute. Return -1
8323 if the value held by the attribute is not constant. */
8326 dwarf2_get_attr_constant_value (struct attribute
*attr
, int default_value
)
8328 if (attr
->form
== DW_FORM_sdata
)
8329 return DW_SND (attr
);
8330 else if (attr
->form
== DW_FORM_udata
8331 || attr
->form
== DW_FORM_data1
8332 || attr
->form
== DW_FORM_data2
8333 || attr
->form
== DW_FORM_data4
8334 || attr
->form
== DW_FORM_data8
)
8335 return DW_UNSND (attr
);
8338 complaint (&symfile_complaints
, "Attribute value is not a constant (%s)",
8339 dwarf_form_name (attr
->form
));
8340 return default_value
;
8344 static struct die_info
*
8345 follow_die_ref (unsigned int offset
)
8347 struct die_info
*die
;
8350 h
= (offset
% REF_HASH_SIZE
);
8351 die
= die_ref_table
[h
];
8354 if (die
->offset
== offset
)
8358 die
= die
->next_ref
;
8363 static struct type
*
8364 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid,
8365 struct dwarf2_cu
*cu
)
8367 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
8369 error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]",
8370 typeid, objfile
->name
);
8373 /* Look for this particular type in the fundamental type vector. If
8374 one is not found, create and install one appropriate for the
8375 current language and the current target machine. */
8377 if (cu
->ftypes
[typeid] == NULL
)
8379 cu
->ftypes
[typeid] = cu
->language_defn
->la_fund_type (objfile
, typeid);
8382 return (cu
->ftypes
[typeid]);
8385 /* Decode simple location descriptions.
8386 Given a pointer to a dwarf block that defines a location, compute
8387 the location and return the value.
8389 NOTE drow/2003-11-18: This function is called in two situations
8390 now: for the address of static or global variables (partial symbols
8391 only) and for offsets into structures which are expected to be
8392 (more or less) constant. The partial symbol case should go away,
8393 and only the constant case should remain. That will let this
8394 function complain more accurately. A few special modes are allowed
8395 without complaint for global variables (for instance, global
8396 register values and thread-local values).
8398 A location description containing no operations indicates that the
8399 object is optimized out. The return value is 0 for that case.
8400 FIXME drow/2003-11-16: No callers check for this case any more; soon all
8401 callers will only want a very basic result and this can become a
8404 When the result is a register number, the global isreg flag is set,
8405 otherwise it is cleared.
8407 Note that stack[0] is unused except as a default error return.
8408 Note that stack overflow is not yet handled. */
8411 decode_locdesc (struct dwarf_block
*blk
, struct dwarf2_cu
*cu
)
8413 struct objfile
*objfile
= cu
->objfile
;
8414 struct comp_unit_head
*cu_header
= &cu
->header
;
8416 int size
= blk
->size
;
8417 char *data
= blk
->data
;
8418 CORE_ADDR stack
[64];
8420 unsigned int bytes_read
, unsnd
;
8465 stack
[++stacki
] = op
- DW_OP_lit0
;
8501 stack
[++stacki
] = op
- DW_OP_reg0
;
8503 dwarf2_complex_location_expr_complaint ();
8508 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8510 stack
[++stacki
] = unsnd
;
8512 dwarf2_complex_location_expr_complaint ();
8516 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
8522 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
8527 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
8532 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
8537 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
8542 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
8547 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
8552 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
8558 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
8563 stack
[stacki
+ 1] = stack
[stacki
];
8568 stack
[stacki
- 1] += stack
[stacki
];
8572 case DW_OP_plus_uconst
:
8573 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
8578 stack
[stacki
- 1] -= stack
[stacki
];
8583 /* If we're not the last op, then we definitely can't encode
8584 this using GDB's address_class enum. This is valid for partial
8585 global symbols, although the variable's address will be bogus
8588 dwarf2_complex_location_expr_complaint ();
8591 case DW_OP_GNU_push_tls_address
:
8592 /* The top of the stack has the offset from the beginning
8593 of the thread control block at which the variable is located. */
8594 /* Nothing should follow this operator, so the top of stack would
8596 /* This is valid for partial global symbols, but the variable's
8597 address will be bogus in the psymtab. */
8599 dwarf2_complex_location_expr_complaint ();
8603 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
8604 dwarf_stack_op_name (op
));
8605 return (stack
[stacki
]);
8608 return (stack
[stacki
]);
8611 /* memory allocation interface */
8613 static struct dwarf_block
*
8614 dwarf_alloc_block (struct dwarf2_cu
*cu
)
8616 struct dwarf_block
*blk
;
8618 blk
= (struct dwarf_block
*)
8619 obstack_alloc (&cu
->comp_unit_obstack
, sizeof (struct dwarf_block
));
8623 static struct abbrev_info
*
8624 dwarf_alloc_abbrev (struct dwarf2_cu
*cu
)
8626 struct abbrev_info
*abbrev
;
8628 abbrev
= (struct abbrev_info
*)
8629 obstack_alloc (&cu
->abbrev_obstack
, sizeof (struct abbrev_info
));
8630 memset (abbrev
, 0, sizeof (struct abbrev_info
));
8634 static struct die_info
*
8635 dwarf_alloc_die (void)
8637 struct die_info
*die
;
8639 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
8640 memset (die
, 0, sizeof (struct die_info
));
8645 /* Macro support. */
8648 /* Return the full name of file number I in *LH's file name table.
8649 Use COMP_DIR as the name of the current directory of the
8650 compilation. The result is allocated using xmalloc; the caller is
8651 responsible for freeing it. */
8653 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
8655 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
8657 if (IS_ABSOLUTE_PATH (fe
->name
))
8658 return xstrdup (fe
->name
);
8666 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
8672 dir_len
= strlen (dir
);
8673 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
8674 strcpy (full_name
, dir
);
8675 full_name
[dir_len
] = '/';
8676 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
8680 return xstrdup (fe
->name
);
8685 static struct macro_source_file
*
8686 macro_start_file (int file
, int line
,
8687 struct macro_source_file
*current_file
,
8688 const char *comp_dir
,
8689 struct line_header
*lh
, struct objfile
*objfile
)
8691 /* The full name of this source file. */
8692 char *full_name
= file_full_name (file
, lh
, comp_dir
);
8694 /* We don't create a macro table for this compilation unit
8695 at all until we actually get a filename. */
8696 if (! pending_macros
)
8697 pending_macros
= new_macro_table (&objfile
->objfile_obstack
,
8698 objfile
->macro_cache
);
8701 /* If we have no current file, then this must be the start_file
8702 directive for the compilation unit's main source file. */
8703 current_file
= macro_set_main (pending_macros
, full_name
);
8705 current_file
= macro_include (current_file
, line
, full_name
);
8709 return current_file
;
8713 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
8714 followed by a null byte. */
8716 copy_string (const char *buf
, int len
)
8718 char *s
= xmalloc (len
+ 1);
8719 memcpy (s
, buf
, len
);
8727 consume_improper_spaces (const char *p
, const char *body
)
8731 complaint (&symfile_complaints
,
8732 "macro definition contains spaces in formal argument list:\n`%s'",
8744 parse_macro_definition (struct macro_source_file
*file
, int line
,
8749 /* The body string takes one of two forms. For object-like macro
8750 definitions, it should be:
8752 <macro name> " " <definition>
8754 For function-like macro definitions, it should be:
8756 <macro name> "() " <definition>
8758 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
8760 Spaces may appear only where explicitly indicated, and in the
8763 The Dwarf 2 spec says that an object-like macro's name is always
8764 followed by a space, but versions of GCC around March 2002 omit
8765 the space when the macro's definition is the empty string.
8767 The Dwarf 2 spec says that there should be no spaces between the
8768 formal arguments in a function-like macro's formal argument list,
8769 but versions of GCC around March 2002 include spaces after the
8773 /* Find the extent of the macro name. The macro name is terminated
8774 by either a space or null character (for an object-like macro) or
8775 an opening paren (for a function-like macro). */
8776 for (p
= body
; *p
; p
++)
8777 if (*p
== ' ' || *p
== '(')
8780 if (*p
== ' ' || *p
== '\0')
8782 /* It's an object-like macro. */
8783 int name_len
= p
- body
;
8784 char *name
= copy_string (body
, name_len
);
8785 const char *replacement
;
8788 replacement
= body
+ name_len
+ 1;
8791 dwarf2_macro_malformed_definition_complaint (body
);
8792 replacement
= body
+ name_len
;
8795 macro_define_object (file
, line
, name
, replacement
);
8801 /* It's a function-like macro. */
8802 char *name
= copy_string (body
, p
- body
);
8805 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
8809 p
= consume_improper_spaces (p
, body
);
8811 /* Parse the formal argument list. */
8812 while (*p
&& *p
!= ')')
8814 /* Find the extent of the current argument name. */
8815 const char *arg_start
= p
;
8817 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
8820 if (! *p
|| p
== arg_start
)
8821 dwarf2_macro_malformed_definition_complaint (body
);
8824 /* Make sure argv has room for the new argument. */
8825 if (argc
>= argv_size
)
8828 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
8831 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
8834 p
= consume_improper_spaces (p
, body
);
8836 /* Consume the comma, if present. */
8841 p
= consume_improper_spaces (p
, body
);
8850 /* Perfectly formed definition, no complaints. */
8851 macro_define_function (file
, line
, name
,
8852 argc
, (const char **) argv
,
8854 else if (*p
== '\0')
8856 /* Complain, but do define it. */
8857 dwarf2_macro_malformed_definition_complaint (body
);
8858 macro_define_function (file
, line
, name
,
8859 argc
, (const char **) argv
,
8863 /* Just complain. */
8864 dwarf2_macro_malformed_definition_complaint (body
);
8867 /* Just complain. */
8868 dwarf2_macro_malformed_definition_complaint (body
);
8874 for (i
= 0; i
< argc
; i
++)
8880 dwarf2_macro_malformed_definition_complaint (body
);
8885 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
8886 char *comp_dir
, bfd
*abfd
,
8887 struct dwarf2_cu
*cu
)
8889 char *mac_ptr
, *mac_end
;
8890 struct macro_source_file
*current_file
= 0;
8892 if (dwarf2_per_objfile
->macinfo_buffer
== NULL
)
8894 complaint (&symfile_complaints
, "missing .debug_macinfo section");
8898 mac_ptr
= dwarf2_per_objfile
->macinfo_buffer
+ offset
;
8899 mac_end
= dwarf2_per_objfile
->macinfo_buffer
8900 + dwarf2_per_objfile
->macinfo_size
;
8904 enum dwarf_macinfo_record_type macinfo_type
;
8906 /* Do we at least have room for a macinfo type byte? */
8907 if (mac_ptr
>= mac_end
)
8909 dwarf2_macros_too_long_complaint ();
8913 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
8916 switch (macinfo_type
)
8918 /* A zero macinfo type indicates the end of the macro
8923 case DW_MACINFO_define
:
8924 case DW_MACINFO_undef
:
8930 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8931 mac_ptr
+= bytes_read
;
8932 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
8933 mac_ptr
+= bytes_read
;
8936 complaint (&symfile_complaints
,
8937 "debug info gives macro %s outside of any file: %s",
8939 DW_MACINFO_define
? "definition" : macinfo_type
==
8940 DW_MACINFO_undef
? "undefinition" :
8941 "something-or-other", body
);
8944 if (macinfo_type
== DW_MACINFO_define
)
8945 parse_macro_definition (current_file
, line
, body
);
8946 else if (macinfo_type
== DW_MACINFO_undef
)
8947 macro_undef (current_file
, line
, body
);
8952 case DW_MACINFO_start_file
:
8957 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8958 mac_ptr
+= bytes_read
;
8959 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
8960 mac_ptr
+= bytes_read
;
8962 current_file
= macro_start_file (file
, line
,
8963 current_file
, comp_dir
,
8968 case DW_MACINFO_end_file
:
8970 complaint (&symfile_complaints
,
8971 "macro debug info has an unmatched `close_file' directive");
8974 current_file
= current_file
->included_by
;
8977 enum dwarf_macinfo_record_type next_type
;
8979 /* GCC circa March 2002 doesn't produce the zero
8980 type byte marking the end of the compilation
8981 unit. Complain if it's not there, but exit no
8984 /* Do we at least have room for a macinfo type byte? */
8985 if (mac_ptr
>= mac_end
)
8987 dwarf2_macros_too_long_complaint ();
8991 /* We don't increment mac_ptr here, so this is just
8993 next_type
= read_1_byte (abfd
, mac_ptr
);
8995 complaint (&symfile_complaints
,
8996 "no terminating 0-type entry for macros in `.debug_macinfo' section");
9003 case DW_MACINFO_vendor_ext
:
9009 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
9010 mac_ptr
+= bytes_read
;
9011 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
9012 mac_ptr
+= bytes_read
;
9014 /* We don't recognize any vendor extensions. */
9021 /* Check if the attribute's form is a DW_FORM_block*
9022 if so return true else false. */
9024 attr_form_is_block (struct attribute
*attr
)
9026 return (attr
== NULL
? 0 :
9027 attr
->form
== DW_FORM_block1
9028 || attr
->form
== DW_FORM_block2
9029 || attr
->form
== DW_FORM_block4
9030 || attr
->form
== DW_FORM_block
);
9034 dwarf2_symbol_mark_computed (struct attribute
*attr
, struct symbol
*sym
,
9035 struct dwarf2_cu
*cu
)
9037 if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
9039 struct dwarf2_loclist_baton
*baton
;
9041 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9042 sizeof (struct dwarf2_loclist_baton
));
9043 baton
->objfile
= cu
->objfile
;
9045 /* We don't know how long the location list is, but make sure we
9046 don't run off the edge of the section. */
9047 baton
->size
= dwarf2_per_objfile
->loc_size
- DW_UNSND (attr
);
9048 baton
->data
= dwarf2_per_objfile
->loc_buffer
+ DW_UNSND (attr
);
9049 baton
->base_address
= cu
->header
.base_address
;
9050 if (cu
->header
.base_known
== 0)
9051 complaint (&symfile_complaints
,
9052 "Location list used without specifying the CU base address.");
9054 SYMBOL_OPS (sym
) = &dwarf2_loclist_funcs
;
9055 SYMBOL_LOCATION_BATON (sym
) = baton
;
9059 struct dwarf2_locexpr_baton
*baton
;
9061 baton
= obstack_alloc (&cu
->objfile
->objfile_obstack
,
9062 sizeof (struct dwarf2_locexpr_baton
));
9063 baton
->objfile
= cu
->objfile
;
9065 if (attr_form_is_block (attr
))
9067 /* Note that we're just copying the block's data pointer
9068 here, not the actual data. We're still pointing into the
9069 info_buffer for SYM's objfile; right now we never release
9070 that buffer, but when we do clean up properly this may
9072 baton
->size
= DW_BLOCK (attr
)->size
;
9073 baton
->data
= DW_BLOCK (attr
)->data
;
9077 dwarf2_invalid_attrib_class_complaint ("location description",
9078 SYMBOL_NATURAL_NAME (sym
));
9083 SYMBOL_OPS (sym
) = &dwarf2_locexpr_funcs
;
9084 SYMBOL_LOCATION_BATON (sym
) = baton
;
9088 /* Locate the compilation unit from CU's objfile which contains the
9089 DIE at OFFSET. Returns NULL on failure. */
9091 static struct dwarf2_per_cu_data
*
9092 dwarf2_find_containing_comp_unit (unsigned long offset
,
9093 struct objfile
*objfile
)
9095 struct dwarf2_per_cu_data
*this_cu
;
9098 if (dwarf2_per_objfile
->all_comp_units
== NULL
)
9099 error ("Dwarf Error: offset 0x%lx points outside this "
9100 "compilation unit [in module %s]",
9101 offset
, bfd_get_filename (objfile
->obfd
));
9104 high
= dwarf2_per_objfile
->n_comp_units
- 1;
9107 int mid
= low
+ (high
- low
) / 2;
9108 if (dwarf2_per_objfile
->all_comp_units
[mid
]->offset
>= offset
)
9113 gdb_assert (low
== high
);
9114 if (dwarf2_per_objfile
->all_comp_units
[low
]->offset
> offset
)
9116 gdb_assert (low
> 0);
9117 gdb_assert (dwarf2_per_objfile
->all_comp_units
[low
-1]->offset
<= offset
);
9118 return dwarf2_per_objfile
->all_comp_units
[low
-1];
9122 this_cu
= dwarf2_per_objfile
->all_comp_units
[low
];
9123 if (low
== dwarf2_per_objfile
->n_comp_units
- 1
9124 && offset
>= this_cu
->offset
+ this_cu
->length
)
9125 error ("invalid dwarf2 offset %ld", offset
);
9126 gdb_assert (offset
< this_cu
->offset
+ this_cu
->length
);
9131 static struct dwarf2_per_cu_data
*
9132 dwarf2_find_comp_unit (unsigned long offset
, struct objfile
*objfile
)
9134 struct dwarf2_per_cu_data
*this_cu
;
9135 this_cu
= dwarf2_find_containing_comp_unit (offset
, objfile
);
9136 if (this_cu
->offset
!= offset
)
9137 error ("no compilation unit with offset %ld\n", offset
);
9141 /* Release one cached compilation unit, CU. We unlink it from the tree
9142 of compilation units, but we don't remove it from the read_in_chain;
9143 the caller is responsible for that. */
9146 free_one_comp_unit (void *data
)
9148 struct dwarf2_cu
*cu
= data
;
9150 if (cu
->per_cu
!= NULL
)
9151 cu
->per_cu
->cu
= NULL
;
9154 obstack_free (&cu
->comp_unit_obstack
, NULL
);
9159 /* This cleanup function is passed the address of a dwarf2_cu on the stack
9160 when we're finished with it. We can't free the pointer itself, but be
9161 sure to unlink it from the cache. Also release any associated storage
9162 and perform cache maintenance.
9164 Only used during partial symbol parsing. */
9167 free_stack_comp_unit (void *data
)
9169 struct dwarf2_cu
*cu
= data
;
9171 obstack_free (&cu
->comp_unit_obstack
, NULL
);
9172 cu
->partial_dies
= NULL
;
9174 if (cu
->per_cu
!= NULL
)
9176 /* This compilation unit is on the stack in our caller, so we
9177 should not xfree it. Just unlink it. */
9178 cu
->per_cu
->cu
= NULL
;
9181 /* If we had a per-cu pointer, then we may have other compilation
9182 units loaded, so age them now. */
9183 age_cached_comp_units ();
9187 /* Free all cached compilation units. */
9190 free_cached_comp_units (void *data
)
9192 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9194 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9195 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9196 while (per_cu
!= NULL
)
9198 struct dwarf2_per_cu_data
*next_cu
;
9200 next_cu
= per_cu
->cu
->read_in_chain
;
9202 free_one_comp_unit (per_cu
->cu
);
9203 *last_chain
= next_cu
;
9209 /* Increase the age counter on each cached compilation unit, and free
9210 any that are too old. */
9213 age_cached_comp_units (void)
9215 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9217 dwarf2_clear_marks (dwarf2_per_objfile
->read_in_chain
);
9218 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9219 while (per_cu
!= NULL
)
9221 per_cu
->cu
->last_used
++;
9222 if (per_cu
->cu
->last_used
<= dwarf2_max_cache_age
)
9223 dwarf2_mark (per_cu
->cu
);
9224 per_cu
= per_cu
->cu
->read_in_chain
;
9227 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9228 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9229 while (per_cu
!= NULL
)
9231 struct dwarf2_per_cu_data
*next_cu
;
9233 next_cu
= per_cu
->cu
->read_in_chain
;
9235 if (!per_cu
->cu
->mark
)
9237 free_one_comp_unit (per_cu
->cu
);
9238 *last_chain
= next_cu
;
9241 last_chain
= &per_cu
->cu
->read_in_chain
;
9247 /* Remove a single compilation unit from the cache. */
9250 free_one_cached_comp_unit (void *target_cu
)
9252 struct dwarf2_per_cu_data
*per_cu
, **last_chain
;
9254 per_cu
= dwarf2_per_objfile
->read_in_chain
;
9255 last_chain
= &dwarf2_per_objfile
->read_in_chain
;
9256 while (per_cu
!= NULL
)
9258 struct dwarf2_per_cu_data
*next_cu
;
9260 next_cu
= per_cu
->cu
->read_in_chain
;
9262 if (per_cu
->cu
== target_cu
)
9264 free_one_comp_unit (per_cu
->cu
);
9265 *last_chain
= next_cu
;
9269 last_chain
= &per_cu
->cu
->read_in_chain
;
9275 /* A pair of DIE offset and GDB type pointer. We store these
9276 in a hash table separate from the DIEs, and preserve them
9277 when the DIEs are flushed out of cache. */
9279 struct dwarf2_offset_and_type
9281 unsigned int offset
;
9285 /* Hash function for a dwarf2_offset_and_type. */
9288 offset_and_type_hash (const void *item
)
9290 const struct dwarf2_offset_and_type
*ofs
= item
;
9294 /* Equality function for a dwarf2_offset_and_type. */
9297 offset_and_type_eq (const void *item_lhs
, const void *item_rhs
)
9299 const struct dwarf2_offset_and_type
*ofs_lhs
= item_lhs
;
9300 const struct dwarf2_offset_and_type
*ofs_rhs
= item_rhs
;
9301 return ofs_lhs
->offset
== ofs_rhs
->offset
;
9304 /* Set the type associated with DIE to TYPE. Save it in CU's hash
9305 table if necessary. */
9308 set_die_type (struct die_info
*die
, struct type
*type
, struct dwarf2_cu
*cu
)
9310 struct dwarf2_offset_and_type
**slot
, ofs
;
9314 if (cu
->per_cu
== NULL
)
9317 if (cu
->per_cu
->type_hash
== NULL
)
9318 cu
->per_cu
->type_hash
9319 = htab_create_alloc_ex (cu
->header
.length
/ 24,
9320 offset_and_type_hash
,
9323 &cu
->objfile
->objfile_obstack
,
9324 hashtab_obstack_allocate
,
9325 dummy_obstack_deallocate
);
9327 ofs
.offset
= die
->offset
;
9329 slot
= (struct dwarf2_offset_and_type
**)
9330 htab_find_slot_with_hash (cu
->per_cu
->type_hash
, &ofs
, ofs
.offset
, INSERT
);
9331 *slot
= obstack_alloc (&cu
->objfile
->objfile_obstack
, sizeof (**slot
));
9337 /* Find the type for DIE in TYPE_HASH, or return NULL if DIE does not
9338 have a saved type. */
9340 static struct type
*
9341 get_die_type (struct die_info
*die
, htab_t type_hash
)
9343 struct dwarf2_offset_and_type
*slot
, ofs
;
9345 ofs
.offset
= die
->offset
;
9346 slot
= htab_find_with_hash (type_hash
, &ofs
, ofs
.offset
);
9353 /* Restore the types of the DIE tree starting at START_DIE from the hash
9354 table saved in CU. */
9357 reset_die_and_siblings_types (struct die_info
*start_die
, struct dwarf2_cu
*cu
)
9359 struct die_info
*die
;
9361 if (cu
->per_cu
->type_hash
== NULL
)
9364 for (die
= start_die
; die
!= NULL
; die
= die
->sibling
)
9366 die
->type
= get_die_type (die
, cu
->per_cu
->type_hash
);
9367 if (die
->child
!= NULL
)
9368 reset_die_and_siblings_types (die
->child
, cu
);
9374 /* Set the mark field in CU and in every other compilation unit in the
9375 cache that we must keep because we are keeping CU. */
9378 dwarf2_mark (struct dwarf2_cu
*cu
)
9386 dwarf2_clear_marks (struct dwarf2_per_cu_data
*per_cu
)
9390 per_cu
->cu
->mark
= 0;
9391 per_cu
= per_cu
->cu
->read_in_chain
;
9395 /* Allocation function for the libiberty hash table which uses an
9399 hashtab_obstack_allocate (void *data
, size_t size
, size_t count
)
9401 unsigned int total
= size
* count
;
9402 void *ptr
= obstack_alloc ((struct obstack
*) data
, total
);
9403 memset (ptr
, 0, total
);
9407 /* Trivial deallocation function for the libiberty splay tree and hash
9408 table - don't deallocate anything. Rely on later deletion of the
9412 dummy_obstack_deallocate (void *object
, void *data
)
9417 /* Trivial hash function for partial_die_info: the hash value of a DIE
9418 is its offset in .debug_info for this objfile. */
9421 partial_die_hash (const void *item
)
9423 const struct partial_die_info
*part_die
= item
;
9424 return part_die
->offset
;
9427 /* Trivial comparison function for partial_die_info structures: two DIEs
9428 are equal if they have the same offset. */
9431 partial_die_eq (const void *item_lhs
, const void *item_rhs
)
9433 const struct partial_die_info
*part_die_lhs
= item_lhs
;
9434 const struct partial_die_info
*part_die_rhs
= item_rhs
;
9435 return part_die_lhs
->offset
== part_die_rhs
->offset
;
9438 static struct cmd_list_element
*set_dwarf2_cmdlist
;
9439 static struct cmd_list_element
*show_dwarf2_cmdlist
;
9442 set_dwarf2_cmd (char *args
, int from_tty
)
9444 help_list (set_dwarf2_cmdlist
, "maintenance set dwarf2 ", -1, gdb_stdout
);
9448 show_dwarf2_cmd (char *args
, int from_tty
)
9450 cmd_show_list (show_dwarf2_cmdlist
, from_tty
, "");
9453 void _initialize_dwarf2_read (void);
9456 _initialize_dwarf2_read (void)
9458 dwarf2_objfile_data_key
= register_objfile_data ();
9460 add_prefix_cmd ("dwarf2", class_maintenance
, set_dwarf2_cmd
,
9461 "Set DWARF 2 specific variables.\n"
9462 "Configure DWARF 2 variables such as the cache size",
9463 &set_dwarf2_cmdlist
, "maintenance set dwarf2 ",
9464 0/*allow-unknown*/, &maintenance_set_cmdlist
);
9466 add_prefix_cmd ("dwarf2", class_maintenance
, show_dwarf2_cmd
,
9467 "Show DWARF 2 specific variables\n"
9468 "Show DWARF 2 variables such as the cache size",
9469 &show_dwarf2_cmdlist
, "maintenance show dwarf2 ",
9470 0/*allow-unknown*/, &maintenance_show_cmdlist
);
9472 add_setshow_zinteger_cmd ("max-cache-age", class_obscure
,
9473 &dwarf2_max_cache_age
,
9474 "Set the upper bound on the age of cached "
9475 "dwarf2 compilation units.",
9476 "Show the upper bound on the age of cached "
9477 "dwarf2 compilation units.",
9478 "A higher limit means that cached "
9479 "compilation units will be stored\n"
9480 "in memory longer, and more total memory will "
9481 "be used. Zero disables\n"
9482 "caching, which can slow down startup.",
9483 "The upper bound on the age of cached "
9484 "dwarf2 compilation units is %d.",
9485 NULL
, NULL
, &set_dwarf2_cmdlist
,
9486 &show_dwarf2_cmdlist
);