1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
5 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
6 Inc. with support from Florida State University (under contract
7 with the Ada Joint Program Office), and Silicon Graphics, Inc.
8 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
9 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
10 support in dwarfread.c
12 This file is part of GDB.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or (at
17 your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
39 #include "filenames.h" /* for DOSish file names */
43 #include "complaints.h"
46 #include "gdb_string.h"
47 #include "gdb_assert.h"
48 #include <sys/types.h>
50 #ifndef DWARF2_REG_TO_REGNUM
51 #define DWARF2_REG_TO_REGNUM(REG) (REG)
55 /* .debug_info header for a compilation unit
56 Because of alignment constraints, this structure has padding and cannot
57 be mapped directly onto the beginning of the .debug_info section. */
58 typedef struct comp_unit_header
60 unsigned int length
; /* length of the .debug_info
62 unsigned short version
; /* version number -- 2 for DWARF
64 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
65 unsigned char addr_size
; /* byte size of an address -- 4 */
68 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
71 /* .debug_pubnames header
72 Because of alignment constraints, this structure has padding and cannot
73 be mapped directly onto the beginning of the .debug_info section. */
74 typedef struct pubnames_header
76 unsigned int length
; /* length of the .debug_pubnames
78 unsigned char version
; /* version number -- 2 for DWARF
80 unsigned int info_offset
; /* offset into .debug_info section */
81 unsigned int info_size
; /* byte size of .debug_info section
85 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
87 /* .debug_pubnames header
88 Because of alignment constraints, this structure has padding and cannot
89 be mapped directly onto the beginning of the .debug_info section. */
90 typedef struct aranges_header
92 unsigned int length
; /* byte len of the .debug_aranges
94 unsigned short version
; /* version number -- 2 for DWARF
96 unsigned int info_offset
; /* offset into .debug_info section */
97 unsigned char addr_size
; /* byte size of an address */
98 unsigned char seg_size
; /* byte size of segment descriptor */
101 #define _ACTUAL_ARANGES_HEADER_SIZE 12
103 /* .debug_line statement program prologue
104 Because of alignment constraints, this structure has padding and cannot
105 be mapped directly onto the beginning of the .debug_info section. */
106 typedef struct statement_prologue
108 unsigned int total_length
; /* byte length of the statement
110 unsigned short version
; /* version number -- 2 for DWARF
112 unsigned int prologue_length
; /* # bytes between prologue &
114 unsigned char minimum_instruction_length
; /* byte size of
116 unsigned char default_is_stmt
; /* initial value of is_stmt
119 unsigned char line_range
;
120 unsigned char opcode_base
; /* number assigned to first special
122 unsigned char *standard_opcode_lengths
;
126 /* offsets and sizes of debugging sections */
128 static file_ptr dwarf_info_offset
;
129 static file_ptr dwarf_abbrev_offset
;
130 static file_ptr dwarf_line_offset
;
131 static file_ptr dwarf_pubnames_offset
;
132 static file_ptr dwarf_aranges_offset
;
133 static file_ptr dwarf_loc_offset
;
134 static file_ptr dwarf_macinfo_offset
;
135 static file_ptr dwarf_str_offset
;
136 static file_ptr dwarf_ranges_offset
;
137 file_ptr dwarf_frame_offset
;
138 file_ptr dwarf_eh_frame_offset
;
140 static unsigned int dwarf_info_size
;
141 static unsigned int dwarf_abbrev_size
;
142 static unsigned int dwarf_line_size
;
143 static unsigned int dwarf_pubnames_size
;
144 static unsigned int dwarf_aranges_size
;
145 static unsigned int dwarf_loc_size
;
146 static unsigned int dwarf_macinfo_size
;
147 static unsigned int dwarf_str_size
;
148 static unsigned int dwarf_ranges_size
;
149 unsigned int dwarf_frame_size
;
150 unsigned int dwarf_eh_frame_size
;
152 /* names of the debugging sections */
154 #define INFO_SECTION ".debug_info"
155 #define ABBREV_SECTION ".debug_abbrev"
156 #define LINE_SECTION ".debug_line"
157 #define PUBNAMES_SECTION ".debug_pubnames"
158 #define ARANGES_SECTION ".debug_aranges"
159 #define LOC_SECTION ".debug_loc"
160 #define MACINFO_SECTION ".debug_macinfo"
161 #define STR_SECTION ".debug_str"
162 #define RANGES_SECTION ".debug_ranges"
163 #define FRAME_SECTION ".debug_frame"
164 #define EH_FRAME_SECTION ".eh_frame"
166 /* local data types */
168 /* We hold several abbreviation tables in memory at the same time. */
169 #ifndef ABBREV_HASH_SIZE
170 #define ABBREV_HASH_SIZE 121
173 /* The data in a compilation unit header, after target2host
174 translation, looks like this. */
175 struct comp_unit_head
177 unsigned long length
;
179 unsigned int abbrev_offset
;
180 unsigned char addr_size
;
181 unsigned char signed_addr_p
;
182 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
183 unsigned int initial_length_size
; /* size of the length field; either
186 /* Offset to the first byte of this compilation unit header in the
187 * .debug_info section, for resolving relative reference dies. */
191 /* Pointer to this compilation unit header in the .debug_info
196 /* Pointer to the first die of this compilatio unit. This will
197 * be the first byte following the compilation unit header. */
201 /* Pointer to the next compilation unit header in the program. */
203 struct comp_unit_head
*next
;
205 /* DWARF abbreviation table associated with this compilation unit */
207 struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
209 /* Pointer to the DIE associated with the compilation unit. */
211 struct die_info
*die
;
214 /* The line number information for a compilation unit (found in the
215 .debug_line section) begins with a "statement program header",
216 which contains the following information. */
219 unsigned int total_length
;
220 unsigned short version
;
221 unsigned int header_length
;
222 unsigned char minimum_instruction_length
;
223 unsigned char default_is_stmt
;
225 unsigned char line_range
;
226 unsigned char opcode_base
;
228 /* standard_opcode_lengths[i] is the number of operands for the
229 standard opcode whose value is i. This means that
230 standard_opcode_lengths[0] is unused, and the last meaningful
231 element is standard_opcode_lengths[opcode_base - 1]. */
232 unsigned char *standard_opcode_lengths
;
234 /* The include_directories table. NOTE! These strings are not
235 allocated with xmalloc; instead, they are pointers into
236 debug_line_buffer. If you try to free them, `free' will get
238 unsigned int num_include_dirs
, include_dirs_size
;
241 /* The file_names table. NOTE! These strings are not allocated
242 with xmalloc; instead, they are pointers into debug_line_buffer.
243 Don't try to free them directly. */
244 unsigned int num_file_names
, file_names_size
;
248 unsigned int dir_index
;
249 unsigned int mod_time
;
253 /* The start and end of the statement program following this
254 header. These point into dwarf_line_buffer. */
255 char *statement_program_start
, *statement_program_end
;
258 /* When we construct a partial symbol table entry we only
259 need this much information. */
260 struct partial_die_info
263 unsigned char has_children
;
264 unsigned char is_external
;
265 unsigned char is_declaration
;
266 unsigned char has_type
;
273 struct dwarf_block
*locdesc
;
274 unsigned int language
;
278 /* This data structure holds the information of an abbrev. */
281 unsigned int number
; /* number identifying abbrev */
282 enum dwarf_tag tag
; /* dwarf tag */
283 int has_children
; /* boolean */
284 unsigned int num_attrs
; /* number of attributes */
285 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
286 struct abbrev_info
*next
; /* next in chain */
291 enum dwarf_attribute name
;
292 enum dwarf_form form
;
295 /* This data structure holds a complete die structure. */
298 enum dwarf_tag tag
; /* Tag indicating type of die */
299 unsigned short has_children
; /* Does the die have children */
300 unsigned int abbrev
; /* Abbrev number */
301 unsigned int offset
; /* Offset in .debug_info section */
302 unsigned int num_attrs
; /* Number of attributes */
303 struct attribute
*attrs
; /* An array of attributes */
304 struct die_info
*next_ref
; /* Next die in ref hash table */
305 struct die_info
*next
; /* Next die in linked list */
306 struct type
*type
; /* Cached type information */
309 /* Attributes have a name and a value */
312 enum dwarf_attribute name
;
313 enum dwarf_form form
;
317 struct dwarf_block
*blk
;
325 struct function_range
328 CORE_ADDR lowpc
, highpc
;
330 struct function_range
*next
;
333 static struct function_range
*cu_first_fn
, *cu_last_fn
, *cu_cached_fn
;
335 /* Get at parts of an attribute structure */
337 #define DW_STRING(attr) ((attr)->u.str)
338 #define DW_UNSND(attr) ((attr)->u.unsnd)
339 #define DW_BLOCK(attr) ((attr)->u.blk)
340 #define DW_SND(attr) ((attr)->u.snd)
341 #define DW_ADDR(attr) ((attr)->u.addr)
343 /* Blocks are a bunch of untyped bytes. */
350 #ifndef ATTR_ALLOC_CHUNK
351 #define ATTR_ALLOC_CHUNK 4
354 /* A hash table of die offsets for following references. */
355 #ifndef REF_HASH_SIZE
356 #define REF_HASH_SIZE 1021
359 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
361 /* Obstack for allocating temporary storage used during symbol reading. */
362 static struct obstack dwarf2_tmp_obstack
;
364 /* Offset to the first byte of the current compilation unit header,
365 for resolving relative reference dies. */
366 static unsigned int cu_header_offset
;
368 /* Allocate fields for structs, unions and enums in this size. */
369 #ifndef DW_FIELD_ALLOC_CHUNK
370 #define DW_FIELD_ALLOC_CHUNK 4
373 /* The language we are debugging. */
374 static enum language cu_language
;
375 static const struct language_defn
*cu_language_defn
;
377 /* Actually data from the sections. */
378 static char *dwarf_info_buffer
;
379 static char *dwarf_abbrev_buffer
;
380 static char *dwarf_line_buffer
;
381 static char *dwarf_str_buffer
;
382 static char *dwarf_macinfo_buffer
;
383 static char *dwarf_ranges_buffer
;
385 /* A zeroed version of a partial die for initialization purposes. */
386 static struct partial_die_info zeroed_partial_die
;
388 /* The generic symbol table building routines have separate lists for
389 file scope symbols and all all other scopes (local scopes). So
390 we need to select the right one to pass to add_symbol_to_list().
391 We do it by keeping a pointer to the correct list in list_in_scope.
393 FIXME: The original dwarf code just treated the file scope as the first
394 local scope, and all other local scopes as nested local scopes, and worked
395 fine. Check to see if we really need to distinguish these
397 static struct pending
**list_in_scope
= &file_symbols
;
399 /* FIXME: decode_locdesc sets these variables to describe the location
400 to the caller. These ought to be a structure or something. If
401 none of the flags are set, the object lives at the address returned
402 by decode_locdesc. */
404 static int optimized_out
; /* No ops in location in expression,
405 so object was optimized out. */
406 static int isreg
; /* Object lives in register.
407 decode_locdesc's return value is
408 the register number. */
409 static int offreg
; /* Object's address is the sum of the
410 register specified by basereg, plus
411 the offset returned. */
412 static int basereg
; /* See `offreg'. */
413 static int isderef
; /* Value described by flags above is
414 the address of a pointer to the object. */
415 static int islocal
; /* Variable is at the returned offset
416 from the frame start, but there's
417 no identified frame pointer for
418 this function, so we can't say
419 which register it's relative to;
421 static int is_thread_local
; /* Variable is at a constant offset in the
422 thread-local storage block for the
423 current thread and the dynamic linker
424 module containing this expression.
425 decode_locdesc returns the offset from
428 /* DW_AT_frame_base values for the current function.
429 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
430 contains the register number for the frame register.
431 frame_base_offset is the offset from the frame register to the
432 virtual stack frame. */
433 static int frame_base_reg
;
434 static CORE_ADDR frame_base_offset
;
436 /* This value is added to each symbol value. FIXME: Generalize to
437 the section_offsets structure used by dbxread (once this is done,
438 pass the appropriate section number to end_symtab). */
439 static CORE_ADDR baseaddr
; /* Add to each symbol value */
441 /* We put a pointer to this structure in the read_symtab_private field
443 The complete dwarf information for an objfile is kept in the
444 psymbol_obstack, so that absolute die references can be handled.
445 Most of the information in this structure is related to an entire
446 object file and could be passed via the sym_private field of the objfile.
447 It is however conceivable that dwarf2 might not be the only type
448 of symbols read from an object file. */
452 /* Pointer to start of dwarf info buffer for the objfile. */
454 char *dwarf_info_buffer
;
456 /* Offset in dwarf_info_buffer for this compilation unit. */
458 unsigned long dwarf_info_offset
;
460 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
462 char *dwarf_abbrev_buffer
;
464 /* Size of dwarf abbreviation section for the objfile. */
466 unsigned int dwarf_abbrev_size
;
468 /* Pointer to start of dwarf line buffer for the objfile. */
470 char *dwarf_line_buffer
;
472 /* Size of dwarf_line_buffer, in bytes. */
474 unsigned int dwarf_line_size
;
476 /* Pointer to start of dwarf string buffer for the objfile. */
478 char *dwarf_str_buffer
;
480 /* Size of dwarf string section for the objfile. */
482 unsigned int dwarf_str_size
;
484 /* Pointer to start of dwarf macro buffer for the objfile. */
486 char *dwarf_macinfo_buffer
;
488 /* Size of dwarf macinfo section for the objfile. */
490 unsigned int dwarf_macinfo_size
;
492 /* Pointer to start of dwarf ranges buffer for the objfile. */
494 char *dwarf_ranges_buffer
;
496 /* Size of dwarf ranges buffer for the objfile. */
498 unsigned int dwarf_ranges_size
;
502 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
503 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
504 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
505 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
506 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
507 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
508 #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size)
509 #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer)
510 #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size)
511 #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer)
512 #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size)
513 #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer)
514 #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size)
516 /* Maintain an array of referenced fundamental types for the current
517 compilation unit being read. For DWARF version 1, we have to construct
518 the fundamental types on the fly, since no information about the
519 fundamental types is supplied. Each such fundamental type is created by
520 calling a language dependent routine to create the type, and then a
521 pointer to that type is then placed in the array at the index specified
522 by it's FT_<TYPENAME> value. The array has a fixed size set by the
523 FT_NUM_MEMBERS compile time constant, which is the number of predefined
524 fundamental types gdb knows how to construct. */
525 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
527 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
528 but this would require a corresponding change in unpack_field_as_long
530 static int bits_per_byte
= 8;
532 /* The routines that read and process dies for a C struct or C++ class
533 pass lists of data member fields and lists of member function fields
534 in an instance of a field_info structure, as defined below. */
537 /* List of data member and baseclasses fields. */
540 struct nextfield
*next
;
547 /* Number of fields. */
550 /* Number of baseclasses. */
553 /* Set if the accesibility of one of the fields is not public. */
554 int non_public_fields
;
556 /* Member function fields array, entries are allocated in the order they
557 are encountered in the object file. */
560 struct nextfnfield
*next
;
561 struct fn_field fnfield
;
565 /* Member function fieldlist array, contains name of possibly overloaded
566 member function, number of overloaded member functions and a pointer
567 to the head of the member function field chain. */
572 struct nextfnfield
*head
;
576 /* Number of entries in the fnfieldlists array. */
580 /* Various complaints about symbol reading that don't abort the process */
583 dwarf2_non_const_array_bound_ignored_complaint (const char *arg1
)
585 complaint (&symfile_complaints
, "non-constant array bounds form '%s' ignored",
590 dwarf2_statement_list_fits_in_line_number_section_complaint (void)
592 complaint (&symfile_complaints
,
593 "statement list doesn't fit in .debug_line section");
597 dwarf2_complex_location_expr_complaint (void)
599 complaint (&symfile_complaints
, "location expression too complex");
603 dwarf2_unsupported_at_frame_base_complaint (const char *arg1
)
605 complaint (&symfile_complaints
,
606 "unsupported DW_AT_frame_base for function '%s'", arg1
);
610 dwarf2_const_value_length_mismatch_complaint (const char *arg1
, int arg2
,
613 complaint (&symfile_complaints
,
614 "const value length mismatch for '%s', got %d, expected %d", arg1
,
619 dwarf2_macros_too_long_complaint (void)
621 complaint (&symfile_complaints
,
622 "macro info runs off end of `.debug_macinfo' section");
626 dwarf2_macro_malformed_definition_complaint (const char *arg1
)
628 complaint (&symfile_complaints
,
629 "macro debug info contains a malformed macro definition:\n`%s'",
634 dwarf2_invalid_attrib_class_complaint (const char *arg1
, const char *arg2
)
636 complaint (&symfile_complaints
,
637 "invalid attribute class or form for '%s' in '%s'", arg1
, arg2
);
640 /* local function prototypes */
642 static void dwarf2_locate_sections (bfd
*, asection
*, void *);
645 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
648 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
650 static char *scan_partial_symbols (char *, struct objfile
*,
651 CORE_ADDR
*, CORE_ADDR
*,
652 const struct comp_unit_head
*);
654 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
655 const struct comp_unit_head
*);
657 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
659 static void psymtab_to_symtab_1 (struct partial_symtab
*);
661 char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
663 static void dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
);
665 static void dwarf2_empty_abbrev_table (void *);
667 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int,
668 const struct comp_unit_head
*cu_header
);
670 static char *read_partial_die (struct partial_die_info
*,
672 const struct comp_unit_head
*);
674 static char *read_full_die (struct die_info
**, bfd
*, char *,
675 const struct comp_unit_head
*);
677 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
678 bfd
*, char *, const struct comp_unit_head
*);
680 static char *read_attribute_value (struct attribute
*, unsigned,
681 bfd
*, char *, const struct comp_unit_head
*);
683 static unsigned int read_1_byte (bfd
*, char *);
685 static int read_1_signed_byte (bfd
*, char *);
687 static unsigned int read_2_bytes (bfd
*, char *);
689 static unsigned int read_4_bytes (bfd
*, char *);
691 static unsigned long read_8_bytes (bfd
*, char *);
693 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
696 static LONGEST
read_initial_length (bfd
*, char *,
697 struct comp_unit_head
*, int *bytes_read
);
699 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
702 static char *read_n_bytes (bfd
*, char *, unsigned int);
704 static char *read_string (bfd
*, char *, unsigned int *);
706 static char *read_indirect_string (bfd
*, char *, const struct comp_unit_head
*,
709 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
711 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
713 static void set_cu_language (unsigned int);
715 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
717 static int die_is_declaration (struct die_info
*);
719 static void free_line_header (struct line_header
*lh
);
721 static struct line_header
*(dwarf_decode_line_header
722 (unsigned int offset
,
724 const struct comp_unit_head
*cu_header
));
726 static void dwarf_decode_lines (struct line_header
*, char *, bfd
*,
727 const struct comp_unit_head
*);
729 static void dwarf2_start_subfile (char *, char *);
731 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
732 struct objfile
*, const struct comp_unit_head
*);
734 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
735 struct objfile
*, const struct comp_unit_head
*);
737 static void dwarf2_const_value_data (struct attribute
*attr
,
741 static struct type
*die_type (struct die_info
*, struct objfile
*,
742 const struct comp_unit_head
*);
744 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
745 const struct comp_unit_head
*);
748 static struct type
*type_at_offset (unsigned int, struct objfile
*);
751 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
752 const struct comp_unit_head
*);
754 static void read_type_die (struct die_info
*, struct objfile
*,
755 const struct comp_unit_head
*);
757 static void read_typedef (struct die_info
*, struct objfile
*,
758 const struct comp_unit_head
*);
760 static void read_base_type (struct die_info
*, struct objfile
*);
762 static void read_file_scope (struct die_info
*, struct objfile
*,
763 const struct comp_unit_head
*);
765 static void read_func_scope (struct die_info
*, struct objfile
*,
766 const struct comp_unit_head
*);
768 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
769 const struct comp_unit_head
*);
771 static int dwarf2_get_pc_bounds (struct die_info
*,
772 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*,
773 const struct comp_unit_head
*);
775 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
776 struct objfile
*, const struct comp_unit_head
*);
778 static void dwarf2_attach_fields_to_type (struct field_info
*,
779 struct type
*, struct objfile
*);
781 static void dwarf2_add_member_fn (struct field_info
*,
782 struct die_info
*, struct type
*,
783 struct objfile
*objfile
,
784 const struct comp_unit_head
*);
786 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
787 struct type
*, struct objfile
*);
789 static void read_structure_scope (struct die_info
*, struct objfile
*,
790 const struct comp_unit_head
*);
792 static void read_common_block (struct die_info
*, struct objfile
*,
793 const struct comp_unit_head
*);
795 static void read_namespace (struct die_info
*die
, struct objfile
*objfile
,
796 const struct comp_unit_head
*cu_header
);
798 static void read_enumeration (struct die_info
*, struct objfile
*,
799 const struct comp_unit_head
*);
801 static struct type
*dwarf_base_type (int, int, struct objfile
*);
803 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
804 const struct comp_unit_head
*);
806 static void read_array_type (struct die_info
*, struct objfile
*,
807 const struct comp_unit_head
*);
809 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
810 const struct comp_unit_head
*);
812 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
813 const struct comp_unit_head
*);
815 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
816 const struct comp_unit_head
*);
818 static void read_tag_const_type (struct die_info
*, struct objfile
*,
819 const struct comp_unit_head
*);
821 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
822 const struct comp_unit_head
*);
824 static void read_tag_string_type (struct die_info
*, struct objfile
*);
826 static void read_subroutine_type (struct die_info
*, struct objfile
*,
827 const struct comp_unit_head
*);
829 static struct die_info
*read_comp_unit (char *, bfd
*,
830 const struct comp_unit_head
*);
832 static void free_die_list (struct die_info
*);
834 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
836 static void process_die (struct die_info
*, struct objfile
*,
837 const struct comp_unit_head
*);
839 static char *dwarf2_linkage_name (struct die_info
*);
841 static char *dwarf_tag_name (unsigned int);
843 static char *dwarf_attr_name (unsigned int);
845 static char *dwarf_form_name (unsigned int);
847 static char *dwarf_stack_op_name (unsigned int);
849 static char *dwarf_bool_name (unsigned int);
851 static char *dwarf_type_encoding_name (unsigned int);
854 static char *dwarf_cfi_name (unsigned int);
856 struct die_info
*copy_die (struct die_info
*);
859 static struct die_info
*sibling_die (struct die_info
*);
861 static void dump_die (struct die_info
*);
863 static void dump_die_list (struct die_info
*);
865 static void store_in_ref_table (unsigned int, struct die_info
*);
867 static void dwarf2_empty_hash_tables (void);
869 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
871 static struct die_info
*follow_die_ref (unsigned int);
873 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
875 /* memory allocation interface */
877 static void dwarf2_free_tmp_obstack (void *);
879 static struct dwarf_block
*dwarf_alloc_block (void);
881 static struct abbrev_info
*dwarf_alloc_abbrev (void);
883 static struct die_info
*dwarf_alloc_die (void);
885 static void initialize_cu_func_list (void);
887 static void add_to_cu_func_list (const char *, CORE_ADDR
, CORE_ADDR
);
889 static void dwarf_decode_macros (struct line_header
*, unsigned int,
890 char *, bfd
*, const struct comp_unit_head
*,
893 static int attr_form_is_block (struct attribute
*);
895 /* Try to locate the sections we need for DWARF 2 debugging
896 information and return true if we have enough to do something. */
899 dwarf2_has_info (bfd
*abfd
)
901 dwarf_info_offset
= 0;
902 dwarf_abbrev_offset
= 0;
903 dwarf_line_offset
= 0;
904 dwarf_str_offset
= 0;
905 dwarf_macinfo_offset
= 0;
906 dwarf_frame_offset
= 0;
907 dwarf_eh_frame_offset
= 0;
908 dwarf_ranges_offset
= 0;
910 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
911 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
921 /* This function is mapped across the sections and remembers the
922 offset and size of each of the debugging sections we are interested
926 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, void *ignore_ptr
)
928 if (STREQ (sectp
->name
, INFO_SECTION
))
930 dwarf_info_offset
= sectp
->filepos
;
931 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
933 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
935 dwarf_abbrev_offset
= sectp
->filepos
;
936 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
938 else if (STREQ (sectp
->name
, LINE_SECTION
))
940 dwarf_line_offset
= sectp
->filepos
;
941 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
943 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
945 dwarf_pubnames_offset
= sectp
->filepos
;
946 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
948 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
950 dwarf_aranges_offset
= sectp
->filepos
;
951 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
953 else if (STREQ (sectp
->name
, LOC_SECTION
))
955 dwarf_loc_offset
= sectp
->filepos
;
956 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
958 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
960 dwarf_macinfo_offset
= sectp
->filepos
;
961 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
963 else if (STREQ (sectp
->name
, STR_SECTION
))
965 dwarf_str_offset
= sectp
->filepos
;
966 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
968 else if (STREQ (sectp
->name
, FRAME_SECTION
))
970 dwarf_frame_offset
= sectp
->filepos
;
971 dwarf_frame_size
= bfd_get_section_size_before_reloc (sectp
);
973 else if (STREQ (sectp
->name
, EH_FRAME_SECTION
))
975 dwarf_eh_frame_offset
= sectp
->filepos
;
976 dwarf_eh_frame_size
= bfd_get_section_size_before_reloc (sectp
);
978 else if (STREQ (sectp
->name
, RANGES_SECTION
))
980 dwarf_ranges_offset
= sectp
->filepos
;
981 dwarf_ranges_size
= bfd_get_section_size_before_reloc (sectp
);
985 /* Build a partial symbol table. */
988 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
991 /* We definitely need the .debug_info and .debug_abbrev sections */
993 dwarf_info_buffer
= dwarf2_read_section (objfile
,
996 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
1000 if (dwarf_line_offset
)
1001 dwarf_line_buffer
= dwarf2_read_section (objfile
,
1005 dwarf_line_buffer
= NULL
;
1007 if (dwarf_str_offset
)
1008 dwarf_str_buffer
= dwarf2_read_section (objfile
,
1012 dwarf_str_buffer
= NULL
;
1014 if (dwarf_macinfo_offset
)
1015 dwarf_macinfo_buffer
= dwarf2_read_section (objfile
,
1016 dwarf_macinfo_offset
,
1017 dwarf_macinfo_size
);
1019 dwarf_macinfo_buffer
= NULL
;
1021 if (dwarf_ranges_offset
)
1022 dwarf_ranges_buffer
= dwarf2_read_section (objfile
,
1023 dwarf_ranges_offset
,
1026 dwarf_ranges_buffer
= NULL
;
1029 || (objfile
->global_psymbols
.size
== 0
1030 && objfile
->static_psymbols
.size
== 0))
1032 init_psymbol_list (objfile
, 1024);
1036 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
1038 /* Things are significantly easier if we have .debug_aranges and
1039 .debug_pubnames sections */
1041 dwarf2_build_psymtabs_easy (objfile
, mainline
);
1045 /* only test this case for now */
1047 /* In this case we have to work a bit harder */
1048 dwarf2_build_psymtabs_hard (objfile
, mainline
);
1053 /* Build the partial symbol table from the information in the
1054 .debug_pubnames and .debug_aranges sections. */
1057 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
1059 bfd
*abfd
= objfile
->obfd
;
1060 char *aranges_buffer
, *pubnames_buffer
;
1061 char *aranges_ptr
, *pubnames_ptr
;
1062 unsigned int entry_length
, version
, info_offset
, info_size
;
1064 pubnames_buffer
= dwarf2_read_section (objfile
,
1065 dwarf_pubnames_offset
,
1066 dwarf_pubnames_size
);
1067 pubnames_ptr
= pubnames_buffer
;
1068 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
1070 struct comp_unit_head cu_header
;
1073 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
1075 pubnames_ptr
+= bytes_read
;
1076 version
= read_1_byte (abfd
, pubnames_ptr
);
1078 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
1080 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
1084 aranges_buffer
= dwarf2_read_section (objfile
,
1085 dwarf_aranges_offset
,
1086 dwarf_aranges_size
);
1091 /* Read in the comp unit header information from the debug_info at
1095 read_comp_unit_head (struct comp_unit_head
*cu_header
,
1096 char *info_ptr
, bfd
*abfd
)
1100 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
1102 info_ptr
+= bytes_read
;
1103 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
1105 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
1107 info_ptr
+= bytes_read
;
1108 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
1110 signed_addr
= bfd_get_sign_extend_vma (abfd
);
1111 if (signed_addr
< 0)
1112 internal_error (__FILE__
, __LINE__
,
1113 "read_comp_unit_head: dwarf from non elf file");
1114 cu_header
->signed_addr_p
= signed_addr
;
1118 /* Build the partial symbol table by doing a quick pass through the
1119 .debug_info and .debug_abbrev sections. */
1122 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
1124 /* Instead of reading this into a big buffer, we should probably use
1125 mmap() on architectures that support it. (FIXME) */
1126 bfd
*abfd
= objfile
->obfd
;
1127 char *info_ptr
, *abbrev_ptr
;
1128 char *beg_of_comp_unit
;
1129 struct partial_die_info comp_unit_die
;
1130 struct partial_symtab
*pst
;
1131 struct cleanup
*back_to
;
1132 CORE_ADDR lowpc
, highpc
;
1134 info_ptr
= dwarf_info_buffer
;
1135 abbrev_ptr
= dwarf_abbrev_buffer
;
1137 /* We use dwarf2_tmp_obstack for objects that don't need to survive
1138 the partial symbol scan, like attribute values.
1140 We could reduce our peak memory consumption during partial symbol
1141 table construction by freeing stuff from this obstack more often
1142 --- say, after processing each compilation unit, or each die ---
1143 but it turns out that this saves almost nothing. For an
1144 executable with 11Mb of Dwarf 2 data, I found about 64k allocated
1145 on dwarf2_tmp_obstack. Some investigation showed:
1147 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*,
1148 DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are
1149 all fixed-length values not requiring dynamic allocation.
1151 2) 30% of the attributes used the form DW_FORM_string. For
1152 DW_FORM_string, read_attribute simply hands back a pointer to
1153 the null-terminated string in dwarf_info_buffer, so no dynamic
1154 allocation is needed there either.
1156 3) The remaining 1% of the attributes all used DW_FORM_block1.
1157 75% of those were DW_AT_frame_base location lists for
1158 functions; the rest were DW_AT_location attributes, probably
1159 for the global variables.
1161 Anyway, what this all means is that the memory the dwarf2
1162 reader uses as temporary space reading partial symbols is about
1163 0.5% as much as we use for dwarf_*_buffer. That's noise. */
1165 obstack_init (&dwarf2_tmp_obstack
);
1166 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1168 /* Since the objects we're extracting from dwarf_info_buffer vary in
1169 length, only the individual functions to extract them (like
1170 read_comp_unit_head and read_partial_die) can really know whether
1171 the buffer is large enough to hold another complete object.
1173 At the moment, they don't actually check that. If
1174 dwarf_info_buffer holds just one extra byte after the last
1175 compilation unit's dies, then read_comp_unit_head will happily
1176 read off the end of the buffer. read_partial_die is similarly
1177 casual. Those functions should be fixed.
1179 For this loop condition, simply checking whether there's any data
1180 left at all should be sufficient. */
1181 while (info_ptr
< dwarf_info_buffer
+ dwarf_info_size
)
1183 struct comp_unit_head cu_header
;
1184 beg_of_comp_unit
= info_ptr
;
1185 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1187 if (cu_header
.version
!= 2)
1189 error ("Dwarf Error: wrong version in compilation unit header.");
1192 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
1194 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
1195 (long) cu_header
.abbrev_offset
,
1196 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1199 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
1200 > dwarf_info_buffer
+ dwarf_info_size
)
1202 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1203 (long) cu_header
.length
,
1204 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1207 /* Complete the cu_header */
1208 cu_header
.offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1209 cu_header
.first_die_ptr
= info_ptr
;
1210 cu_header
.cu_head_ptr
= beg_of_comp_unit
;
1212 /* Read the abbrevs for this compilation unit into a table */
1213 dwarf2_read_abbrevs (abfd
, &cu_header
);
1214 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1216 /* Read the compilation unit die */
1217 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1220 /* Set the language we're debugging */
1221 set_cu_language (comp_unit_die
.language
);
1223 /* Allocate a new partial symbol table structure */
1224 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1225 comp_unit_die
.name
? comp_unit_die
.name
: "",
1226 comp_unit_die
.lowpc
,
1227 objfile
->global_psymbols
.next
,
1228 objfile
->static_psymbols
.next
);
1230 pst
->read_symtab_private
= (char *)
1231 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1232 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1233 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1234 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1235 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1236 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1237 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1238 DWARF_LINE_SIZE (pst
) = dwarf_line_size
;
1239 DWARF_STR_BUFFER (pst
) = dwarf_str_buffer
;
1240 DWARF_STR_SIZE (pst
) = dwarf_str_size
;
1241 DWARF_MACINFO_BUFFER (pst
) = dwarf_macinfo_buffer
;
1242 DWARF_MACINFO_SIZE (pst
) = dwarf_macinfo_size
;
1243 DWARF_RANGES_BUFFER (pst
) = dwarf_ranges_buffer
;
1244 DWARF_RANGES_SIZE (pst
) = dwarf_ranges_size
;
1245 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1247 /* Store the function that reads in the rest of the symbol table */
1248 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1250 /* Check if comp unit has_children.
1251 If so, read the rest of the partial symbols from this comp unit.
1252 If not, there's no more debug_info for this comp unit. */
1253 if (comp_unit_die
.has_children
)
1255 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1258 /* If the compilation unit didn't have an explicit address range,
1259 then use the information extracted from its child dies. */
1260 if (! comp_unit_die
.has_pc_info
)
1262 comp_unit_die
.lowpc
= lowpc
;
1263 comp_unit_die
.highpc
= highpc
;
1266 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1267 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1269 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1270 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1271 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1272 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1273 sort_pst_symbols (pst
);
1275 /* If there is already a psymtab or symtab for a file of this
1276 name, remove it. (If there is a symtab, more drastic things
1277 also happen.) This happens in VxWorks. */
1278 free_named_symtabs (pst
->filename
);
1280 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1281 + cu_header
.initial_length_size
;
1283 do_cleanups (back_to
);
1286 /* Read in all interesting dies to the end of the compilation unit. */
1289 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1290 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1291 const struct comp_unit_head
*cu_header
)
1293 bfd
*abfd
= objfile
->obfd
;
1294 struct partial_die_info pdi
;
1296 /* This function is called after we've read in the comp_unit_die in
1297 order to read its children. We start the nesting level at 1 since
1298 we have pushed 1 level down in order to read the comp unit's children.
1299 The comp unit itself is at level 0, so we stop reading when we pop
1300 back to that level. */
1302 int nesting_level
= 1;
1304 /* We only want to read in symbols corresponding to variables or
1305 other similar objects that are global or static. Normally, these
1306 are all children of the DW_TAG_compile_unit die, so are all at
1307 level 1. But C++ namespaces give ries to DW_TAG_namespace dies
1308 whose children are global objects. So we keep track of what
1309 level we currently think of as referring to file scope; this
1310 should always equal 1 plus the number of namespaces that we are
1311 currently nested within. */
1313 int file_scope_level
= 1;
1315 *lowpc
= ((CORE_ADDR
) -1);
1316 *highpc
= ((CORE_ADDR
) 0);
1318 while (nesting_level
)
1320 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, cu_header
);
1322 /* Anonymous namespaces have no name but are interesting. */
1324 if (pdi
.name
!= NULL
|| pdi
.tag
== DW_TAG_namespace
)
1328 case DW_TAG_subprogram
:
1329 if (pdi
.has_pc_info
)
1331 if (pdi
.lowpc
< *lowpc
)
1335 if (pdi
.highpc
> *highpc
)
1337 *highpc
= pdi
.highpc
;
1339 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1340 && !pdi
.is_declaration
)
1342 add_partial_symbol (&pdi
, objfile
, cu_header
);
1346 case DW_TAG_variable
:
1347 case DW_TAG_typedef
:
1348 case DW_TAG_class_type
:
1349 case DW_TAG_structure_type
:
1350 case DW_TAG_union_type
:
1351 case DW_TAG_enumeration_type
:
1352 if ((pdi
.is_external
|| nesting_level
== file_scope_level
)
1353 && !pdi
.is_declaration
)
1355 add_partial_symbol (&pdi
, objfile
, cu_header
);
1358 case DW_TAG_enumerator
:
1359 /* File scope enumerators are added to the partial
1360 symbol table. They're children of the enumeration
1361 type die, so they occur at a level one higher than we
1362 normally look for. */
1363 if (nesting_level
== file_scope_level
+ 1)
1364 add_partial_symbol (&pdi
, objfile
, cu_header
);
1366 case DW_TAG_base_type
:
1367 /* File scope base type definitions are added to the partial
1369 if (nesting_level
== file_scope_level
)
1370 add_partial_symbol (&pdi
, objfile
, cu_header
);
1372 case DW_TAG_namespace
:
1373 /* FIXME: carlton/2002-10-16: we're not yet doing
1374 anything useful with this, but for now make sure that
1375 these tags at least don't cause us to miss any
1376 important symbols. */
1377 if (pdi
.has_children
)
1384 /* If the die has a sibling, skip to the sibling. Do not skip
1385 enumeration types, we want to record their enumerators. Do
1386 not skip namespaces, we want to record symbols inside
1389 && pdi
.tag
!= DW_TAG_enumeration_type
1390 && pdi
.tag
!= DW_TAG_namespace
)
1392 info_ptr
= pdi
.sibling
;
1394 else if (pdi
.has_children
)
1396 /* Die has children, but either the optional DW_AT_sibling
1397 attribute is missing or we want to look at them. */
1404 /* If this is the end of a DW_TAG_namespace entry, then
1405 decrease the file_scope_level, too. */
1406 if (nesting_level
< file_scope_level
)
1409 gdb_assert (nesting_level
== file_scope_level
);
1414 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1415 from `maint check'. */
1416 if (*lowpc
== ((CORE_ADDR
) -1))
1422 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1423 const struct comp_unit_head
*cu_header
)
1429 case DW_TAG_subprogram
:
1430 if (pdi
->is_external
)
1432 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1433 mst_text, objfile); */
1434 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1435 VAR_NAMESPACE
, LOC_BLOCK
,
1436 &objfile
->global_psymbols
,
1437 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1441 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1442 mst_file_text, objfile); */
1443 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1444 VAR_NAMESPACE
, LOC_BLOCK
,
1445 &objfile
->static_psymbols
,
1446 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1449 case DW_TAG_variable
:
1450 if (pdi
->is_external
)
1453 Don't enter into the minimal symbol tables as there is
1454 a minimal symbol table entry from the ELF symbols already.
1455 Enter into partial symbol table if it has a location
1456 descriptor or a type.
1457 If the location descriptor is missing, new_symbol will create
1458 a LOC_UNRESOLVED symbol, the address of the variable will then
1459 be determined from the minimal symbol table whenever the variable
1461 The address for the partial symbol table entry is not
1462 used by GDB, but it comes in handy for debugging partial symbol
1466 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1467 if (pdi
->locdesc
|| pdi
->has_type
)
1468 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1469 VAR_NAMESPACE
, LOC_STATIC
,
1470 &objfile
->global_psymbols
,
1471 0, addr
+ baseaddr
, cu_language
, objfile
);
1475 /* Static Variable. Skip symbols without location descriptors. */
1476 if (pdi
->locdesc
== NULL
)
1478 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1479 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1480 mst_file_data, objfile); */
1481 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1482 VAR_NAMESPACE
, LOC_STATIC
,
1483 &objfile
->static_psymbols
,
1484 0, addr
+ baseaddr
, cu_language
, objfile
);
1487 case DW_TAG_typedef
:
1488 case DW_TAG_base_type
:
1489 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1490 VAR_NAMESPACE
, LOC_TYPEDEF
,
1491 &objfile
->static_psymbols
,
1492 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1494 case DW_TAG_class_type
:
1495 case DW_TAG_structure_type
:
1496 case DW_TAG_union_type
:
1497 case DW_TAG_enumeration_type
:
1498 /* Skip aggregate types without children, these are external
1500 if (pdi
->has_children
== 0)
1502 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1503 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1504 &objfile
->static_psymbols
,
1505 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1507 if (cu_language
== language_cplus
)
1509 /* For C++, these implicitly act as typedefs as well. */
1510 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1511 VAR_NAMESPACE
, LOC_TYPEDEF
,
1512 &objfile
->static_psymbols
,
1513 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1516 case DW_TAG_enumerator
:
1517 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1518 VAR_NAMESPACE
, LOC_CONST
,
1519 &objfile
->static_psymbols
,
1520 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1527 /* Expand this partial symbol table into a full symbol table. */
1530 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1532 /* FIXME: This is barely more than a stub. */
1537 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1543 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1544 gdb_flush (gdb_stdout
);
1547 psymtab_to_symtab_1 (pst
);
1549 /* Finish up the debug error message. */
1551 printf_filtered ("done.\n");
1557 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1559 struct objfile
*objfile
= pst
->objfile
;
1560 bfd
*abfd
= objfile
->obfd
;
1561 struct comp_unit_head cu_header
;
1562 struct die_info
*dies
;
1563 unsigned long offset
;
1564 CORE_ADDR lowpc
, highpc
;
1565 struct die_info
*child_die
;
1567 struct symtab
*symtab
;
1568 struct cleanup
*back_to
;
1570 /* Set local variables from the partial symbol table info. */
1571 offset
= DWARF_INFO_OFFSET (pst
);
1572 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1573 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1574 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1575 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1576 dwarf_line_size
= DWARF_LINE_SIZE (pst
);
1577 dwarf_str_buffer
= DWARF_STR_BUFFER (pst
);
1578 dwarf_str_size
= DWARF_STR_SIZE (pst
);
1579 dwarf_macinfo_buffer
= DWARF_MACINFO_BUFFER (pst
);
1580 dwarf_macinfo_size
= DWARF_MACINFO_SIZE (pst
);
1581 dwarf_ranges_buffer
= DWARF_RANGES_BUFFER (pst
);
1582 dwarf_ranges_size
= DWARF_RANGES_SIZE (pst
);
1583 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1584 cu_header_offset
= offset
;
1585 info_ptr
= dwarf_info_buffer
+ offset
;
1587 obstack_init (&dwarf2_tmp_obstack
);
1588 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1591 make_cleanup (really_free_pendings
, NULL
);
1593 /* read in the comp_unit header */
1594 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1596 /* Read the abbrevs for this compilation unit */
1597 dwarf2_read_abbrevs (abfd
, &cu_header
);
1598 make_cleanup (dwarf2_empty_abbrev_table
, cu_header
.dwarf2_abbrevs
);
1600 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1602 make_cleanup_free_die_list (dies
);
1604 /* Do line number decoding in read_file_scope () */
1605 cu_header
.die
= dies
;
1606 process_die (dies
, objfile
, &cu_header
);
1608 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
, &cu_header
))
1610 /* Some compilers don't define a DW_AT_high_pc attribute for
1611 the compilation unit. If the DW_AT_high_pc is missing,
1612 synthesize it, by scanning the DIE's below the compilation unit. */
1614 if (dies
->has_children
)
1616 child_die
= dies
->next
;
1617 while (child_die
&& child_die
->tag
)
1619 if (child_die
->tag
== DW_TAG_subprogram
)
1621 CORE_ADDR low
, high
;
1623 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1624 objfile
, &cu_header
))
1626 highpc
= max (highpc
, high
);
1629 child_die
= sibling_die (child_die
);
1633 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1635 /* Set symtab language to language from DW_AT_language.
1636 If the compilation is from a C file generated by language preprocessors,
1637 do not set the language if it was already deduced by start_subfile. */
1639 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1641 symtab
->language
= cu_language
;
1643 pst
->symtab
= symtab
;
1645 sort_symtab_syms (pst
->symtab
);
1647 do_cleanups (back_to
);
1650 /* Process a die and its children. */
1653 process_die (struct die_info
*die
, struct objfile
*objfile
,
1654 const struct comp_unit_head
*cu_header
)
1658 case DW_TAG_padding
:
1660 case DW_TAG_compile_unit
:
1661 read_file_scope (die
, objfile
, cu_header
);
1663 case DW_TAG_subprogram
:
1664 read_subroutine_type (die
, objfile
, cu_header
);
1665 read_func_scope (die
, objfile
, cu_header
);
1667 case DW_TAG_inlined_subroutine
:
1668 /* FIXME: These are ignored for now.
1669 They could be used to set breakpoints on all inlined instances
1670 of a function and make GDB `next' properly over inlined functions. */
1672 case DW_TAG_lexical_block
:
1673 read_lexical_block_scope (die
, objfile
, cu_header
);
1675 case DW_TAG_class_type
:
1676 case DW_TAG_structure_type
:
1677 case DW_TAG_union_type
:
1678 read_structure_scope (die
, objfile
, cu_header
);
1680 case DW_TAG_enumeration_type
:
1681 read_enumeration (die
, objfile
, cu_header
);
1683 case DW_TAG_subroutine_type
:
1684 read_subroutine_type (die
, objfile
, cu_header
);
1686 case DW_TAG_array_type
:
1687 read_array_type (die
, objfile
, cu_header
);
1689 case DW_TAG_pointer_type
:
1690 read_tag_pointer_type (die
, objfile
, cu_header
);
1692 case DW_TAG_ptr_to_member_type
:
1693 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1695 case DW_TAG_reference_type
:
1696 read_tag_reference_type (die
, objfile
, cu_header
);
1698 case DW_TAG_string_type
:
1699 read_tag_string_type (die
, objfile
);
1701 case DW_TAG_base_type
:
1702 read_base_type (die
, objfile
);
1703 if (dwarf_attr (die
, DW_AT_name
))
1705 /* Add a typedef symbol for the base type definition. */
1706 new_symbol (die
, die
->type
, objfile
, cu_header
);
1709 case DW_TAG_common_block
:
1710 read_common_block (die
, objfile
, cu_header
);
1712 case DW_TAG_common_inclusion
:
1714 case DW_TAG_namespace
:
1715 read_namespace (die
, objfile
, cu_header
);
1717 case DW_TAG_imported_declaration
:
1718 case DW_TAG_imported_module
:
1719 /* FIXME: carlton/2002-10-16: Eventually, we should use the
1720 information contained in these. DW_TAG_imported_declaration
1721 dies shouldn't have children; DW_TAG_imported_module dies
1722 shouldn't in the C++ case, but conceivably could in the
1723 Fortran case, so we'll have to replace this gdb_assert if
1724 Fortran compilers start generating that info. */
1725 gdb_assert (!die
->has_children
);
1728 new_symbol (die
, NULL
, objfile
, cu_header
);
1734 initialize_cu_func_list (void)
1736 cu_first_fn
= cu_last_fn
= cu_cached_fn
= NULL
;
1740 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1741 const struct comp_unit_head
*cu_header
)
1743 struct cleanup
*back_to
= make_cleanup (null_cleanup
, 0);
1744 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1745 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1746 struct attribute
*attr
;
1747 char *name
= "<unknown>";
1748 char *comp_dir
= NULL
;
1749 struct die_info
*child_die
;
1750 bfd
*abfd
= objfile
->obfd
;
1751 struct line_header
*line_header
= 0;
1753 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
1755 if (die
->has_children
)
1757 child_die
= die
->next
;
1758 while (child_die
&& child_die
->tag
)
1760 if (child_die
->tag
== DW_TAG_subprogram
)
1762 CORE_ADDR low
, high
;
1764 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
,
1765 objfile
, cu_header
))
1767 lowpc
= min (lowpc
, low
);
1768 highpc
= max (highpc
, high
);
1771 child_die
= sibling_die (child_die
);
1776 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1777 from finish_block. */
1778 if (lowpc
== ((CORE_ADDR
) -1))
1783 attr
= dwarf_attr (die
, DW_AT_name
);
1786 name
= DW_STRING (attr
);
1788 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1791 comp_dir
= DW_STRING (attr
);
1794 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1795 directory, get rid of it. */
1796 char *cp
= strchr (comp_dir
, ':');
1798 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1803 if (objfile
->ei
.entry_point
>= lowpc
&&
1804 objfile
->ei
.entry_point
< highpc
)
1806 objfile
->ei
.entry_file_lowpc
= lowpc
;
1807 objfile
->ei
.entry_file_highpc
= highpc
;
1810 attr
= dwarf_attr (die
, DW_AT_language
);
1813 set_cu_language (DW_UNSND (attr
));
1816 /* We assume that we're processing GCC output. */
1817 processing_gcc_compilation
= 2;
1819 /* FIXME:Do something here. */
1820 if (dip
->at_producer
!= NULL
)
1822 handle_producer (dip
->at_producer
);
1826 /* The compilation unit may be in a different language or objfile,
1827 zero out all remembered fundamental types. */
1828 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1830 start_symtab (name
, comp_dir
, lowpc
);
1831 record_debugformat ("DWARF 2");
1833 initialize_cu_func_list ();
1835 /* Process all dies in compilation unit. */
1836 if (die
->has_children
)
1838 child_die
= die
->next
;
1839 while (child_die
&& child_die
->tag
)
1841 process_die (child_die
, objfile
, cu_header
);
1842 child_die
= sibling_die (child_die
);
1846 /* Decode line number information if present. */
1847 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1850 unsigned int line_offset
= DW_UNSND (attr
);
1851 line_header
= dwarf_decode_line_header (line_offset
,
1855 make_cleanup ((make_cleanup_ftype
*) free_line_header
,
1856 (void *) line_header
);
1857 dwarf_decode_lines (line_header
, comp_dir
, abfd
, cu_header
);
1861 /* Decode macro information, if present. Dwarf 2 macro information
1862 refers to information in the line number info statement program
1863 header, so we can only read it if we've read the header
1865 attr
= dwarf_attr (die
, DW_AT_macro_info
);
1866 if (attr
&& line_header
)
1868 unsigned int macro_offset
= DW_UNSND (attr
);
1869 dwarf_decode_macros (line_header
, macro_offset
,
1870 comp_dir
, abfd
, cu_header
, objfile
);
1872 do_cleanups (back_to
);
1876 add_to_cu_func_list (const char *name
, CORE_ADDR lowpc
, CORE_ADDR highpc
)
1878 struct function_range
*thisfn
;
1880 thisfn
= (struct function_range
*)
1881 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct function_range
));
1882 thisfn
->name
= name
;
1883 thisfn
->lowpc
= lowpc
;
1884 thisfn
->highpc
= highpc
;
1885 thisfn
->seen_line
= 0;
1886 thisfn
->next
= NULL
;
1888 if (cu_last_fn
== NULL
)
1889 cu_first_fn
= thisfn
;
1891 cu_last_fn
->next
= thisfn
;
1893 cu_last_fn
= thisfn
;
1897 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1898 const struct comp_unit_head
*cu_header
)
1900 register struct context_stack
*new;
1903 struct die_info
*child_die
;
1904 struct attribute
*attr
;
1907 name
= dwarf2_linkage_name (die
);
1909 /* Ignore functions with missing or empty names and functions with
1910 missing or invalid low and high pc attributes. */
1911 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
1917 /* Record the function range for dwarf_decode_lines. */
1918 add_to_cu_func_list (name
, lowpc
, highpc
);
1920 if (objfile
->ei
.entry_point
>= lowpc
&&
1921 objfile
->ei
.entry_point
< highpc
)
1923 objfile
->ei
.entry_func_lowpc
= lowpc
;
1924 objfile
->ei
.entry_func_highpc
= highpc
;
1927 /* Decode DW_AT_frame_base location descriptor if present, keep result
1928 for DW_OP_fbreg operands in decode_locdesc. */
1929 frame_base_reg
= -1;
1930 frame_base_offset
= 0;
1931 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1936 /* Support the .debug_loc offsets */
1937 if (attr_form_is_block (attr
))
1939 addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1941 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
1943 dwarf2_complex_location_expr_complaint ();
1948 dwarf2_invalid_attrib_class_complaint ("DW_AT_frame_base", name
);
1953 dwarf2_unsupported_at_frame_base_complaint (name
);
1955 frame_base_reg
= addr
;
1958 frame_base_reg
= basereg
;
1959 frame_base_offset
= addr
;
1962 dwarf2_unsupported_at_frame_base_complaint (name
);
1965 new = push_context (0, lowpc
);
1966 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1967 list_in_scope
= &local_symbols
;
1969 if (die
->has_children
)
1971 child_die
= die
->next
;
1972 while (child_die
&& child_die
->tag
)
1974 process_die (child_die
, objfile
, cu_header
);
1975 child_die
= sibling_die (child_die
);
1979 new = pop_context ();
1980 /* Make a block for the local symbols within. */
1981 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1982 lowpc
, highpc
, objfile
);
1984 /* In C++, we can have functions nested inside functions (e.g., when
1985 a function declares a class that has methods). This means that
1986 when we finish processing a function scope, we may need to go
1987 back to building a containing block's symbol lists. */
1988 local_symbols
= new->locals
;
1989 param_symbols
= new->params
;
1991 /* If we've finished processing a top-level function, subsequent
1992 symbols go in the file symbol list. */
1993 if (outermost_context_p ())
1994 list_in_scope
= &file_symbols
;
1997 /* Process all the DIES contained within a lexical block scope. Start
1998 a new scope, process the dies, and then close the scope. */
2001 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
2002 const struct comp_unit_head
*cu_header
)
2004 register struct context_stack
*new;
2005 CORE_ADDR lowpc
, highpc
;
2006 struct die_info
*child_die
;
2008 /* Ignore blocks with missing or invalid low and high pc attributes. */
2009 /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges
2010 as multiple lexical blocks? Handling children in a sane way would
2011 be nasty. Might be easier to properly extend generic blocks to
2013 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
, cu_header
))
2018 push_context (0, lowpc
);
2019 if (die
->has_children
)
2021 child_die
= die
->next
;
2022 while (child_die
&& child_die
->tag
)
2024 process_die (child_die
, objfile
, cu_header
);
2025 child_die
= sibling_die (child_die
);
2028 new = pop_context ();
2030 if (local_symbols
!= NULL
)
2032 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
2035 local_symbols
= new->locals
;
2038 /* Get low and high pc attributes from a die. Return 1 if the attributes
2039 are present and valid, otherwise, return 0. Return -1 if the range is
2040 discontinuous, i.e. derived from DW_AT_ranges information. */
2042 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
,
2043 CORE_ADDR
*highpc
, struct objfile
*objfile
,
2044 const struct comp_unit_head
*cu_header
)
2046 struct attribute
*attr
;
2047 bfd
*obfd
= objfile
->obfd
;
2052 attr
= dwarf_attr (die
, DW_AT_high_pc
);
2055 high
= DW_ADDR (attr
);
2056 attr
= dwarf_attr (die
, DW_AT_low_pc
);
2058 low
= DW_ADDR (attr
);
2060 /* Found high w/o low attribute. */
2063 /* Found consecutive range of addresses. */
2068 attr
= dwarf_attr (die
, DW_AT_ranges
);
2071 unsigned int addr_size
= cu_header
->addr_size
;
2072 CORE_ADDR mask
= ~(~(CORE_ADDR
)1 << (addr_size
* 8 - 1));
2073 /* Value of the DW_AT_ranges attribute is the offset in the
2074 .debug_renges section. */
2075 unsigned int offset
= DW_UNSND (attr
);
2076 /* Base address selection entry. */
2085 /* The applicable base address is determined by (1) the closest
2086 preceding base address selection entry in the range list or
2087 (2) the DW_AT_low_pc of the compilation unit. */
2089 /* ??? Was in dwarf3 draft4, and has since been removed.
2090 GCC still uses it though. */
2091 attr
= dwarf_attr (cu_header
->die
, DW_AT_entry_pc
);
2094 base
= DW_ADDR (attr
);
2100 attr
= dwarf_attr (cu_header
->die
, DW_AT_low_pc
);
2103 base
= DW_ADDR (attr
);
2108 buffer
= dwarf_ranges_buffer
+ offset
;
2111 /* Read in the largest possible address. */
2112 marker
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2113 if ((marker
& mask
) == mask
)
2115 /* If we found the largest possible address, then
2116 read the base address. */
2117 base
= read_address (obfd
, buffer
+ addr_size
,
2119 buffer
+= 2 * addr_size
;
2120 offset
+= 2 * addr_size
;
2128 CORE_ADDR range_beginning
, range_end
;
2130 range_beginning
= read_address (obfd
, buffer
,
2132 buffer
+= addr_size
;
2133 range_end
= read_address (obfd
, buffer
, cu_header
, &dummy
);
2134 buffer
+= addr_size
;
2135 offset
+= 2 * addr_size
;
2137 /* An end of list marker is a pair of zero addresses. */
2138 if (range_beginning
== 0 && range_end
== 0)
2139 /* Found the end of list entry. */
2142 /* Each base address selection entry is a pair of 2 values.
2143 The first is the largest possible address, the second is
2144 the base address. Check for a base address here. */
2145 if ((range_beginning
& mask
) == mask
)
2147 /* If we found the largest possible address, then
2148 read the base address. */
2149 base
= read_address (obfd
, buffer
+ addr_size
,
2157 /* We have no valid base address for the ranges
2159 complaint (&symfile_complaints
,
2160 "Invalid .debug_ranges data (no base address)");
2164 /* FIXME: This is recording everything as a low-high
2165 segment of consecutive addresses. We should have a
2166 data structure for discontiguous block ranges
2170 low
= range_beginning
;
2176 if (range_beginning
< low
)
2177 low
= range_beginning
;
2178 if (range_end
> high
)
2184 /* If the first entry is an end-of-list marker, the range
2185 describes an empty scope, i.e. no instructions. */
2195 /* When using the GNU linker, .gnu.linkonce. sections are used to
2196 eliminate duplicate copies of functions and vtables and such.
2197 The linker will arbitrarily choose one and discard the others.
2198 The AT_*_pc values for such functions refer to local labels in
2199 these sections. If the section from that file was discarded, the
2200 labels are not in the output, so the relocs get a value of 0.
2201 If this is a discarded function, mark the pc bounds as invalid,
2202 so that GDB will ignore it. */
2203 if (low
== 0 && (bfd_get_file_flags (obfd
) & HAS_RELOC
) == 0)
2211 /* Add an aggregate field to the field list. */
2214 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
2215 struct objfile
*objfile
,
2216 const struct comp_unit_head
*cu_header
)
2218 struct nextfield
*new_field
;
2219 struct attribute
*attr
;
2221 char *fieldname
= "";
2223 /* Allocate a new field list entry and link it in. */
2224 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2225 make_cleanup (xfree
, new_field
);
2226 memset (new_field
, 0, sizeof (struct nextfield
));
2227 new_field
->next
= fip
->fields
;
2228 fip
->fields
= new_field
;
2231 /* Handle accessibility and virtuality of field.
2232 The default accessibility for members is public, the default
2233 accessibility for inheritance is private. */
2234 if (die
->tag
!= DW_TAG_inheritance
)
2235 new_field
->accessibility
= DW_ACCESS_public
;
2237 new_field
->accessibility
= DW_ACCESS_private
;
2238 new_field
->virtuality
= DW_VIRTUALITY_none
;
2240 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2242 new_field
->accessibility
= DW_UNSND (attr
);
2243 if (new_field
->accessibility
!= DW_ACCESS_public
)
2244 fip
->non_public_fields
= 1;
2245 attr
= dwarf_attr (die
, DW_AT_virtuality
);
2247 new_field
->virtuality
= DW_UNSND (attr
);
2249 fp
= &new_field
->field
;
2251 if (die
->tag
== DW_TAG_member
&& ! die_is_declaration (die
))
2253 /* Data member other than a C++ static data member. */
2255 /* Get type of field. */
2256 fp
->type
= die_type (die
, objfile
, cu_header
);
2258 FIELD_STATIC_KIND (*fp
) = 0;
2260 /* Get bit size of field (zero if none). */
2261 attr
= dwarf_attr (die
, DW_AT_bit_size
);
2264 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
2268 FIELD_BITSIZE (*fp
) = 0;
2271 /* Get bit offset of field. */
2272 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2275 FIELD_BITPOS (*fp
) =
2276 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
2279 FIELD_BITPOS (*fp
) = 0;
2280 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
2283 if (BITS_BIG_ENDIAN
)
2285 /* For big endian bits, the DW_AT_bit_offset gives the
2286 additional bit offset from the MSB of the containing
2287 anonymous object to the MSB of the field. We don't
2288 have to do anything special since we don't need to
2289 know the size of the anonymous object. */
2290 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
2294 /* For little endian bits, compute the bit offset to the
2295 MSB of the anonymous object, subtract off the number of
2296 bits from the MSB of the field to the MSB of the
2297 object, and then subtract off the number of bits of
2298 the field itself. The result is the bit offset of
2299 the LSB of the field. */
2301 int bit_offset
= DW_UNSND (attr
);
2303 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2306 /* The size of the anonymous object containing
2307 the bit field is explicit, so use the
2308 indicated size (in bytes). */
2309 anonymous_size
= DW_UNSND (attr
);
2313 /* The size of the anonymous object containing
2314 the bit field must be inferred from the type
2315 attribute of the data member containing the
2317 anonymous_size
= TYPE_LENGTH (fp
->type
);
2319 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
2320 - bit_offset
- FIELD_BITSIZE (*fp
);
2324 /* Get name of field. */
2325 attr
= dwarf_attr (die
, DW_AT_name
);
2326 if (attr
&& DW_STRING (attr
))
2327 fieldname
= DW_STRING (attr
);
2328 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
2329 &objfile
->type_obstack
);
2331 /* Change accessibility for artificial fields (e.g. virtual table
2332 pointer or virtual base class pointer) to private. */
2333 if (dwarf_attr (die
, DW_AT_artificial
))
2335 new_field
->accessibility
= DW_ACCESS_private
;
2336 fip
->non_public_fields
= 1;
2339 else if (die
->tag
== DW_TAG_member
|| die
->tag
== DW_TAG_variable
)
2341 /* C++ static member. */
2343 /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that
2344 is a declaration, but all versions of G++ as of this writing
2345 (so through at least 3.2.1) incorrectly generate
2346 DW_TAG_variable tags. */
2350 /* Get name of field. */
2351 attr
= dwarf_attr (die
, DW_AT_name
);
2352 if (attr
&& DW_STRING (attr
))
2353 fieldname
= DW_STRING (attr
);
2357 /* Get physical name. */
2358 physname
= dwarf2_linkage_name (die
);
2360 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
2361 &objfile
->type_obstack
));
2362 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2363 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
2364 &objfile
->type_obstack
);
2366 else if (die
->tag
== DW_TAG_inheritance
)
2368 /* C++ base class field. */
2369 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
2371 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
2373 FIELD_BITSIZE (*fp
) = 0;
2374 FIELD_STATIC_KIND (*fp
) = 0;
2375 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
2376 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
2377 fip
->nbaseclasses
++;
2381 /* Create the vector of fields, and attach it to the type. */
2384 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
2385 struct objfile
*objfile
)
2387 int nfields
= fip
->nfields
;
2389 /* Record the field count, allocate space for the array of fields,
2390 and create blank accessibility bitfields if necessary. */
2391 TYPE_NFIELDS (type
) = nfields
;
2392 TYPE_FIELDS (type
) = (struct field
*)
2393 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2394 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2396 if (fip
->non_public_fields
)
2398 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2400 TYPE_FIELD_PRIVATE_BITS (type
) =
2401 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2402 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2404 TYPE_FIELD_PROTECTED_BITS (type
) =
2405 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2406 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2408 TYPE_FIELD_IGNORE_BITS (type
) =
2409 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2410 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2413 /* If the type has baseclasses, allocate and clear a bit vector for
2414 TYPE_FIELD_VIRTUAL_BITS. */
2415 if (fip
->nbaseclasses
)
2417 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
2420 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2421 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2422 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2423 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
2424 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
2427 /* Copy the saved-up fields into the field vector. Start from the head
2428 of the list, adding to the tail of the field array, so that they end
2429 up in the same order in the array in which they were added to the list. */
2430 while (nfields
-- > 0)
2432 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
2433 switch (fip
->fields
->accessibility
)
2435 case DW_ACCESS_private
:
2436 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2439 case DW_ACCESS_protected
:
2440 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2443 case DW_ACCESS_public
:
2447 /* Unknown accessibility. Complain and treat it as public. */
2449 complaint (&symfile_complaints
, "unsupported accessibility %d",
2450 fip
->fields
->accessibility
);
2454 if (nfields
< fip
->nbaseclasses
)
2456 switch (fip
->fields
->virtuality
)
2458 case DW_VIRTUALITY_virtual
:
2459 case DW_VIRTUALITY_pure_virtual
:
2460 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
2464 fip
->fields
= fip
->fields
->next
;
2468 /* Add a member function to the proper fieldlist. */
2471 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
2472 struct type
*type
, struct objfile
*objfile
,
2473 const struct comp_unit_head
*cu_header
)
2475 struct attribute
*attr
;
2476 struct fnfieldlist
*flp
;
2478 struct fn_field
*fnp
;
2481 struct nextfnfield
*new_fnfield
;
2483 /* Get name of member function. */
2484 attr
= dwarf_attr (die
, DW_AT_name
);
2485 if (attr
&& DW_STRING (attr
))
2486 fieldname
= DW_STRING (attr
);
2490 /* Get the mangled name. */
2491 physname
= dwarf2_linkage_name (die
);
2493 /* Look up member function name in fieldlist. */
2494 for (i
= 0; i
< fip
->nfnfields
; i
++)
2496 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2500 /* Create new list element if necessary. */
2501 if (i
< fip
->nfnfields
)
2502 flp
= &fip
->fnfieldlists
[i
];
2505 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2507 fip
->fnfieldlists
= (struct fnfieldlist
*)
2508 xrealloc (fip
->fnfieldlists
,
2509 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2510 * sizeof (struct fnfieldlist
));
2511 if (fip
->nfnfields
== 0)
2512 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2514 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2515 flp
->name
= fieldname
;
2521 /* Create a new member function field and chain it to the field list
2523 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2524 make_cleanup (xfree
, new_fnfield
);
2525 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2526 new_fnfield
->next
= flp
->head
;
2527 flp
->head
= new_fnfield
;
2530 /* Fill in the member function field info. */
2531 fnp
= &new_fnfield
->fnfield
;
2532 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2533 &objfile
->type_obstack
);
2534 fnp
->type
= alloc_type (objfile
);
2535 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2537 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2538 int nparams
= TYPE_NFIELDS (die
->type
);
2540 /* TYPE is the domain of this method, and DIE->TYPE is the type
2541 of the method itself (TYPE_CODE_METHOD). */
2542 smash_to_method_type (fnp
->type
, type
,
2543 TYPE_TARGET_TYPE (die
->type
),
2544 TYPE_FIELDS (die
->type
),
2545 TYPE_NFIELDS (die
->type
),
2546 TYPE_VARARGS (die
->type
));
2548 /* Handle static member functions.
2549 Dwarf2 has no clean way to discern C++ static and non-static
2550 member functions. G++ helps GDB by marking the first
2551 parameter for non-static member functions (which is the
2552 this pointer) as artificial. We obtain this information
2553 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2554 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2555 fnp
->voffset
= VOFFSET_STATIC
;
2558 complaint (&symfile_complaints
, "member function type missing for '%s'",
2561 /* Get fcontext from DW_AT_containing_type if present. */
2562 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2563 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2565 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2566 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2568 /* Get accessibility. */
2569 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2572 switch (DW_UNSND (attr
))
2574 case DW_ACCESS_private
:
2575 fnp
->is_private
= 1;
2577 case DW_ACCESS_protected
:
2578 fnp
->is_protected
= 1;
2583 /* Check for artificial methods. */
2584 attr
= dwarf_attr (die
, DW_AT_artificial
);
2585 if (attr
&& DW_UNSND (attr
) != 0)
2586 fnp
->is_artificial
= 1;
2588 /* Get index in virtual function table if it is a virtual member function. */
2589 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2592 /* Support the .debug_loc offsets */
2593 if (attr_form_is_block (attr
))
2595 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2597 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
2599 dwarf2_complex_location_expr_complaint ();
2603 dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location",
2609 /* Create the vector of member function fields, and attach it to the type. */
2612 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2613 struct objfile
*objfile
)
2615 struct fnfieldlist
*flp
;
2616 int total_length
= 0;
2619 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2620 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2621 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2623 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2625 struct nextfnfield
*nfp
= flp
->head
;
2626 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2629 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2630 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2631 fn_flp
->fn_fields
= (struct fn_field
*)
2632 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2633 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2634 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2636 total_length
+= flp
->length
;
2639 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2640 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2643 /* Called when we find the DIE that starts a structure or union scope
2644 (definition) to process all dies that define the members of the
2647 NOTE: we need to call struct_type regardless of whether or not the
2648 DIE has an at_name attribute, since it might be an anonymous
2649 structure or union. This gets the type entered into our set of
2652 However, if the structure is incomplete (an opaque struct/union)
2653 then suppress creating a symbol table entry for it since gdb only
2654 wants to find the one with the complete definition. Note that if
2655 it is complete, we just call new_symbol, which does it's own
2656 checking about whether the struct/union is anonymous or not (and
2657 suppresses creating a symbol table entry itself). */
2660 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2661 const struct comp_unit_head
*cu_header
)
2664 struct attribute
*attr
;
2666 type
= alloc_type (objfile
);
2668 INIT_CPLUS_SPECIFIC (type
);
2669 attr
= dwarf_attr (die
, DW_AT_name
);
2670 if (attr
&& DW_STRING (attr
))
2672 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2673 strlen (DW_STRING (attr
)),
2674 &objfile
->type_obstack
);
2677 if (die
->tag
== DW_TAG_structure_type
)
2679 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2681 else if (die
->tag
== DW_TAG_union_type
)
2683 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2687 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2689 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2692 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2695 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2699 TYPE_LENGTH (type
) = 0;
2702 /* We need to add the type field to the die immediately so we don't
2703 infinitely recurse when dealing with pointers to the structure
2704 type within the structure itself. */
2707 if (die
->has_children
&& ! die_is_declaration (die
))
2709 struct field_info fi
;
2710 struct die_info
*child_die
;
2711 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2713 memset (&fi
, 0, sizeof (struct field_info
));
2715 child_die
= die
->next
;
2717 while (child_die
&& child_die
->tag
)
2719 if (child_die
->tag
== DW_TAG_member
2720 || child_die
->tag
== DW_TAG_variable
)
2722 /* NOTE: carlton/2002-11-05: A C++ static data member
2723 should be a DW_TAG_member that is a declaration, but
2724 all versions of G++ as of this writing (so through at
2725 least 3.2.1) incorrectly generate DW_TAG_variable
2726 tags for them instead. */
2727 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2729 else if (child_die
->tag
== DW_TAG_subprogram
)
2731 /* C++ member function. */
2732 process_die (child_die
, objfile
, cu_header
);
2733 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2735 else if (child_die
->tag
== DW_TAG_inheritance
)
2737 /* C++ base class field. */
2738 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2742 process_die (child_die
, objfile
, cu_header
);
2744 child_die
= sibling_die (child_die
);
2747 /* Attach fields and member functions to the type. */
2749 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2752 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2754 /* Get the type which refers to the base class (possibly this
2755 class itself) which contains the vtable pointer for the current
2756 class from the DW_AT_containing_type attribute. */
2758 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2760 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2762 TYPE_VPTR_BASETYPE (type
) = t
;
2765 static const char vptr_name
[] =
2766 {'_', 'v', 'p', 't', 'r', '\0'};
2769 /* Our own class provides vtbl ptr. */
2770 for (i
= TYPE_NFIELDS (t
) - 1;
2771 i
>= TYPE_N_BASECLASSES (t
);
2774 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2776 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2777 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2779 TYPE_VPTR_FIELDNO (type
) = i
;
2784 /* Complain if virtual function table field not found. */
2785 if (i
< TYPE_N_BASECLASSES (t
))
2786 complaint (&symfile_complaints
,
2787 "virtual function table pointer not found when defining class '%s'",
2788 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) :
2793 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2798 new_symbol (die
, type
, objfile
, cu_header
);
2800 do_cleanups (back_to
);
2804 /* No children, must be stub. */
2805 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2809 /* Given a pointer to a die which begins an enumeration, process all
2810 the dies that define the members of the enumeration.
2812 This will be much nicer in draft 6 of the DWARF spec when our
2813 members will be dies instead squished into the DW_AT_element_list
2816 NOTE: We reverse the order of the element list. */
2819 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2820 const struct comp_unit_head
*cu_header
)
2822 struct die_info
*child_die
;
2824 struct field
*fields
;
2825 struct attribute
*attr
;
2828 int unsigned_enum
= 1;
2830 type
= alloc_type (objfile
);
2832 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2833 attr
= dwarf_attr (die
, DW_AT_name
);
2834 if (attr
&& DW_STRING (attr
))
2836 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2837 strlen (DW_STRING (attr
)),
2838 &objfile
->type_obstack
);
2841 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2844 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2848 TYPE_LENGTH (type
) = 0;
2853 if (die
->has_children
)
2855 child_die
= die
->next
;
2856 while (child_die
&& child_die
->tag
)
2858 if (child_die
->tag
!= DW_TAG_enumerator
)
2860 process_die (child_die
, objfile
, cu_header
);
2864 attr
= dwarf_attr (child_die
, DW_AT_name
);
2867 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2868 if (SYMBOL_VALUE (sym
) < 0)
2871 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2873 fields
= (struct field
*)
2875 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2876 * sizeof (struct field
));
2879 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2880 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2881 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2882 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2883 FIELD_STATIC_KIND (fields
[num_fields
]) = 0;
2889 child_die
= sibling_die (child_die
);
2894 TYPE_NFIELDS (type
) = num_fields
;
2895 TYPE_FIELDS (type
) = (struct field
*)
2896 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2897 memcpy (TYPE_FIELDS (type
), fields
,
2898 sizeof (struct field
) * num_fields
);
2902 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2905 new_symbol (die
, type
, objfile
, cu_header
);
2908 /* Extract all information from a DW_TAG_array_type DIE and put it in
2909 the DIE's type field. For now, this only handles one dimensional
2913 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2914 const struct comp_unit_head
*cu_header
)
2916 struct die_info
*child_die
;
2917 struct type
*type
= NULL
;
2918 struct type
*element_type
, *range_type
, *index_type
;
2919 struct type
**range_types
= NULL
;
2920 struct attribute
*attr
;
2922 struct cleanup
*back_to
;
2924 /* Return if we've already decoded this type. */
2930 element_type
= die_type (die
, objfile
, cu_header
);
2932 /* Irix 6.2 native cc creates array types without children for
2933 arrays with unspecified length. */
2934 if (die
->has_children
== 0)
2936 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2937 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2938 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2942 back_to
= make_cleanup (null_cleanup
, NULL
);
2943 child_die
= die
->next
;
2944 while (child_die
&& child_die
->tag
)
2946 if (child_die
->tag
== DW_TAG_subrange_type
)
2948 unsigned int low
, high
;
2950 /* Default bounds to an array with unspecified length. */
2953 if (cu_language
== language_fortran
)
2955 /* FORTRAN implies a lower bound of 1, if not given. */
2959 index_type
= die_type (child_die
, objfile
, cu_header
);
2960 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2963 if (attr
->form
== DW_FORM_sdata
)
2965 low
= DW_SND (attr
);
2967 else if (attr
->form
== DW_FORM_udata
2968 || attr
->form
== DW_FORM_data1
2969 || attr
->form
== DW_FORM_data2
2970 || attr
->form
== DW_FORM_data4
2971 || attr
->form
== DW_FORM_data8
)
2973 low
= DW_UNSND (attr
);
2977 dwarf2_non_const_array_bound_ignored_complaint
2978 (dwarf_form_name (attr
->form
));
2980 die
->type
= lookup_pointer_type (element_type
);
2987 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2990 if (attr
->form
== DW_FORM_sdata
)
2992 high
= DW_SND (attr
);
2994 else if (attr
->form
== DW_FORM_udata
2995 || attr
->form
== DW_FORM_data1
2996 || attr
->form
== DW_FORM_data2
2997 || attr
->form
== DW_FORM_data4
2998 || attr
->form
== DW_FORM_data8
)
3000 high
= DW_UNSND (attr
);
3002 else if (attr
->form
== DW_FORM_block1
)
3004 /* GCC encodes arrays with unspecified or dynamic length
3005 with a DW_FORM_block1 attribute.
3006 FIXME: GDB does not yet know how to handle dynamic
3007 arrays properly, treat them as arrays with unspecified
3013 dwarf2_non_const_array_bound_ignored_complaint
3014 (dwarf_form_name (attr
->form
));
3016 die
->type
= lookup_pointer_type (element_type
);
3024 /* Create a range type and save it for array type creation. */
3025 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
3027 range_types
= (struct type
**)
3028 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
3029 * sizeof (struct type
*));
3031 make_cleanup (free_current_contents
, &range_types
);
3033 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
3035 child_die
= sibling_die (child_die
);
3038 /* Dwarf2 dimensions are output from left to right, create the
3039 necessary array types in backwards order. */
3040 type
= element_type
;
3042 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
3044 /* Understand Dwarf2 support for vector types (like they occur on
3045 the PowerPC w/ AltiVec). Gcc just adds another attribute to the
3046 array type. This is not part of the Dwarf2/3 standard yet, but a
3047 custom vendor extension. The main difference between a regular
3048 array and the vector variant is that vectors are passed by value
3050 attr
= dwarf_attr (die
, DW_AT_GNU_vector
);
3052 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
3054 do_cleanups (back_to
);
3056 /* Install the type in the die. */
3060 /* First cut: install each common block member as a global variable. */
3063 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
3064 const struct comp_unit_head
*cu_header
)
3066 struct die_info
*child_die
;
3067 struct attribute
*attr
;
3069 CORE_ADDR base
= (CORE_ADDR
) 0;
3071 attr
= dwarf_attr (die
, DW_AT_location
);
3074 /* Support the .debug_loc offsets */
3075 if (attr_form_is_block (attr
))
3077 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3079 else if (attr
->form
== DW_FORM_data4
|| attr
->form
== DW_FORM_data8
)
3081 dwarf2_complex_location_expr_complaint ();
3085 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3086 "common block member");
3089 if (die
->has_children
)
3091 child_die
= die
->next
;
3092 while (child_die
&& child_die
->tag
)
3094 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
3095 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
3098 SYMBOL_VALUE_ADDRESS (sym
) =
3099 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
3100 add_symbol_to_list (sym
, &global_symbols
);
3102 child_die
= sibling_die (child_die
);
3107 /* Read a C++ namespace. */
3109 /* FIXME: carlton/2002-10-16: For now, we don't actually do anything
3110 useful with the namespace data: we just process its children. */
3113 read_namespace (struct die_info
*die
, struct objfile
*objfile
,
3114 const struct comp_unit_head
*cu_header
)
3116 if (die
->has_children
)
3118 struct die_info
*child_die
= die
->next
;
3120 while (child_die
&& child_die
->tag
)
3122 process_die (child_die
, objfile
, cu_header
);
3123 child_die
= sibling_die (child_die
);
3128 /* Extract all information from a DW_TAG_pointer_type DIE and add to
3129 the user defined type vector. */
3132 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
3133 const struct comp_unit_head
*cu_header
)
3136 struct attribute
*attr_byte_size
;
3137 struct attribute
*attr_address_class
;
3138 int byte_size
, addr_class
;
3145 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
3147 attr_byte_size
= dwarf_attr (die
, DW_AT_byte_size
);
3149 byte_size
= DW_UNSND (attr_byte_size
);
3151 byte_size
= cu_header
->addr_size
;
3153 attr_address_class
= dwarf_attr (die
, DW_AT_address_class
);
3154 if (attr_address_class
)
3155 addr_class
= DW_UNSND (attr_address_class
);
3157 addr_class
= DW_ADDR_none
;
3159 /* If the pointer size or address class is different than the
3160 default, create a type variant marked as such and set the
3161 length accordingly. */
3162 if (TYPE_LENGTH (type
) != byte_size
|| addr_class
!= DW_ADDR_none
)
3164 if (ADDRESS_CLASS_TYPE_FLAGS_P ())
3168 type_flags
= ADDRESS_CLASS_TYPE_FLAGS (byte_size
, addr_class
);
3169 gdb_assert ((type_flags
& ~TYPE_FLAG_ADDRESS_CLASS_ALL
) == 0);
3170 type
= make_type_with_address_space (type
, type_flags
);
3172 else if (TYPE_LENGTH (type
) != byte_size
)
3174 complaint (&symfile_complaints
, "invalid pointer size %d", byte_size
);
3177 /* Should we also complain about unhandled address classes? */
3181 TYPE_LENGTH (type
) = byte_size
;
3185 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
3186 the user defined type vector. */
3189 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
3190 const struct comp_unit_head
*cu_header
)
3193 struct type
*to_type
;
3194 struct type
*domain
;
3201 type
= alloc_type (objfile
);
3202 to_type
= die_type (die
, objfile
, cu_header
);
3203 domain
= die_containing_type (die
, objfile
, cu_header
);
3204 smash_to_member_type (type
, domain
, to_type
);
3209 /* Extract all information from a DW_TAG_reference_type DIE and add to
3210 the user defined type vector. */
3213 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
3214 const struct comp_unit_head
*cu_header
)
3217 struct attribute
*attr
;
3224 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
3225 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3228 TYPE_LENGTH (type
) = DW_UNSND (attr
);
3232 TYPE_LENGTH (type
) = cu_header
->addr_size
;
3238 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
3239 const struct comp_unit_head
*cu_header
)
3241 struct type
*base_type
;
3248 base_type
= die_type (die
, objfile
, cu_header
);
3249 die
->type
= make_cv_type (1, TYPE_VOLATILE (base_type
), base_type
, 0);
3253 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
3254 const struct comp_unit_head
*cu_header
)
3256 struct type
*base_type
;
3263 base_type
= die_type (die
, objfile
, cu_header
);
3264 die
->type
= make_cv_type (TYPE_CONST (base_type
), 1, base_type
, 0);
3267 /* Extract all information from a DW_TAG_string_type DIE and add to
3268 the user defined type vector. It isn't really a user defined type,
3269 but it behaves like one, with other DIE's using an AT_user_def_type
3270 attribute to reference it. */
3273 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
3275 struct type
*type
, *range_type
, *index_type
, *char_type
;
3276 struct attribute
*attr
;
3277 unsigned int length
;
3284 attr
= dwarf_attr (die
, DW_AT_string_length
);
3287 length
= DW_UNSND (attr
);
3291 /* check for the DW_AT_byte_size attribute */
3292 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3295 length
= DW_UNSND (attr
);
3302 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
3303 range_type
= create_range_type (NULL
, index_type
, 1, length
);
3304 if (cu_language
== language_fortran
)
3306 /* Need to create a unique string type for bounds
3308 type
= create_string_type (0, range_type
);
3312 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
3313 type
= create_string_type (char_type
, range_type
);
3318 /* Handle DIES due to C code like:
3322 int (*funcp)(int a, long l);
3326 ('funcp' generates a DW_TAG_subroutine_type DIE)
3330 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
3331 const struct comp_unit_head
*cu_header
)
3333 struct type
*type
; /* Type that this function returns */
3334 struct type
*ftype
; /* Function that returns above type */
3335 struct attribute
*attr
;
3337 /* Decode the type that this subroutine returns */
3342 type
= die_type (die
, objfile
, cu_header
);
3343 ftype
= lookup_function_type (type
);
3345 /* All functions in C++ have prototypes. */
3346 attr
= dwarf_attr (die
, DW_AT_prototyped
);
3347 if ((attr
&& (DW_UNSND (attr
) != 0))
3348 || cu_language
== language_cplus
)
3349 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
3351 if (die
->has_children
)
3353 struct die_info
*child_die
;
3357 /* Count the number of parameters.
3358 FIXME: GDB currently ignores vararg functions, but knows about
3359 vararg member functions. */
3360 child_die
= die
->next
;
3361 while (child_die
&& child_die
->tag
)
3363 if (child_die
->tag
== DW_TAG_formal_parameter
)
3365 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
3366 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
3367 child_die
= sibling_die (child_die
);
3370 /* Allocate storage for parameters and fill them in. */
3371 TYPE_NFIELDS (ftype
) = nparams
;
3372 TYPE_FIELDS (ftype
) = (struct field
*)
3373 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
3375 child_die
= die
->next
;
3376 while (child_die
&& child_die
->tag
)
3378 if (child_die
->tag
== DW_TAG_formal_parameter
)
3380 /* Dwarf2 has no clean way to discern C++ static and non-static
3381 member functions. G++ helps GDB by marking the first
3382 parameter for non-static member functions (which is the
3383 this pointer) as artificial. We pass this information
3384 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
3385 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
3387 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
3389 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
3390 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
3394 child_die
= sibling_die (child_die
);
3402 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
3403 const struct comp_unit_head
*cu_header
)
3405 struct attribute
*attr
;
3410 attr
= dwarf_attr (die
, DW_AT_name
);
3411 if (attr
&& DW_STRING (attr
))
3413 name
= DW_STRING (attr
);
3415 die
->type
= init_type (TYPE_CODE_TYPEDEF
, 0, TYPE_FLAG_TARGET_STUB
, name
, objfile
);
3416 TYPE_TARGET_TYPE (die
->type
) = die_type (die
, objfile
, cu_header
);
3420 /* Find a representation of a given base type and install
3421 it in the TYPE field of the die. */
3424 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
3427 struct attribute
*attr
;
3428 int encoding
= 0, size
= 0;
3430 /* If we've already decoded this die, this is a no-op. */
3436 attr
= dwarf_attr (die
, DW_AT_encoding
);
3439 encoding
= DW_UNSND (attr
);
3441 attr
= dwarf_attr (die
, DW_AT_byte_size
);
3444 size
= DW_UNSND (attr
);
3446 attr
= dwarf_attr (die
, DW_AT_name
);
3447 if (attr
&& DW_STRING (attr
))
3449 enum type_code code
= TYPE_CODE_INT
;
3454 case DW_ATE_address
:
3455 /* Turn DW_ATE_address into a void * pointer. */
3456 code
= TYPE_CODE_PTR
;
3457 type_flags
|= TYPE_FLAG_UNSIGNED
;
3459 case DW_ATE_boolean
:
3460 code
= TYPE_CODE_BOOL
;
3461 type_flags
|= TYPE_FLAG_UNSIGNED
;
3463 case DW_ATE_complex_float
:
3464 code
= TYPE_CODE_COMPLEX
;
3467 code
= TYPE_CODE_FLT
;
3470 case DW_ATE_signed_char
:
3472 case DW_ATE_unsigned
:
3473 case DW_ATE_unsigned_char
:
3474 type_flags
|= TYPE_FLAG_UNSIGNED
;
3477 complaint (&symfile_complaints
, "unsupported DW_AT_encoding: '%s'",
3478 dwarf_type_encoding_name (encoding
));
3481 type
= init_type (code
, size
, type_flags
, DW_STRING (attr
), objfile
);
3482 if (encoding
== DW_ATE_address
)
3483 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
3484 else if (encoding
== DW_ATE_complex_float
)
3487 TYPE_TARGET_TYPE (type
)
3488 = dwarf2_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
3489 else if (size
== 16)
3490 TYPE_TARGET_TYPE (type
)
3491 = dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
3493 TYPE_TARGET_TYPE (type
)
3494 = dwarf2_fundamental_type (objfile
, FT_FLOAT
);
3499 type
= dwarf_base_type (encoding
, size
, objfile
);
3504 /* Read a whole compilation unit into a linked list of dies. */
3506 static struct die_info
*
3507 read_comp_unit (char *info_ptr
, bfd
*abfd
,
3508 const struct comp_unit_head
*cu_header
)
3510 struct die_info
*first_die
, *last_die
, *die
;
3514 /* Reset die reference table; we are
3515 building new ones now. */
3516 dwarf2_empty_hash_tables ();
3520 first_die
= last_die
= NULL
;
3523 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
3524 if (die
->has_children
)
3535 /* Enter die in reference hash table */
3536 store_in_ref_table (die
->offset
, die
);
3540 first_die
= last_die
= die
;
3544 last_die
->next
= die
;
3548 while (nesting_level
> 0);
3552 /* Free a linked list of dies. */
3555 free_die_list (struct die_info
*dies
)
3557 struct die_info
*die
, *next
;
3570 do_free_die_list_cleanup (void *dies
)
3572 free_die_list (dies
);
3575 static struct cleanup
*
3576 make_cleanup_free_die_list (struct die_info
*dies
)
3578 return make_cleanup (do_free_die_list_cleanup
, dies
);
3582 /* Read the contents of the section at OFFSET and of size SIZE from the
3583 object file specified by OBJFILE into the psymbol_obstack and return it. */
3586 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
3589 bfd
*abfd
= objfile
->obfd
;
3595 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3596 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3597 (bfd_bread (buf
, size
, abfd
) != size
))
3600 error ("Dwarf Error: Can't read DWARF data from '%s'",
3601 bfd_get_filename (abfd
));
3606 /* In DWARF version 2, the description of the debugging information is
3607 stored in a separate .debug_abbrev section. Before we read any
3608 dies from a section we read in all abbreviations and install them
3612 dwarf2_read_abbrevs (bfd
*abfd
, struct comp_unit_head
*cu_header
)
3615 struct abbrev_info
*cur_abbrev
;
3616 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3617 unsigned int abbrev_form
, hash_number
;
3619 /* Initialize dwarf2 abbrevs */
3620 memset (cu_header
->dwarf2_abbrevs
, 0,
3621 ABBREV_HASH_SIZE
*sizeof (struct abbrev_info
*));
3623 abbrev_ptr
= dwarf_abbrev_buffer
+ cu_header
->abbrev_offset
;
3624 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3625 abbrev_ptr
+= bytes_read
;
3627 /* loop until we reach an abbrev number of 0 */
3628 while (abbrev_number
)
3630 cur_abbrev
= dwarf_alloc_abbrev ();
3632 /* read in abbrev header */
3633 cur_abbrev
->number
= abbrev_number
;
3634 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3635 abbrev_ptr
+= bytes_read
;
3636 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3639 /* now read in declarations */
3640 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3641 abbrev_ptr
+= bytes_read
;
3642 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3643 abbrev_ptr
+= bytes_read
;
3646 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3648 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3649 xrealloc (cur_abbrev
->attrs
,
3650 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3651 * sizeof (struct attr_abbrev
));
3653 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3654 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3655 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3656 abbrev_ptr
+= bytes_read
;
3657 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3658 abbrev_ptr
+= bytes_read
;
3661 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3662 cur_abbrev
->next
= cu_header
->dwarf2_abbrevs
[hash_number
];
3663 cu_header
->dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3665 /* Get next abbreviation.
3666 Under Irix6 the abbreviations for a compilation unit are not
3667 always properly terminated with an abbrev number of 0.
3668 Exit loop if we encounter an abbreviation which we have
3669 already read (which means we are about to read the abbreviations
3670 for the next compile unit) or if the end of the abbreviation
3671 table is reached. */
3672 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3673 >= dwarf_abbrev_size
)
3675 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3676 abbrev_ptr
+= bytes_read
;
3677 if (dwarf2_lookup_abbrev (abbrev_number
, cu_header
) != NULL
)
3682 /* Empty the abbrev table for a new compilation unit. */
3686 dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table
)
3689 struct abbrev_info
*abbrev
, *next
;
3690 struct abbrev_info
**abbrevs
;
3692 abbrevs
= (struct abbrev_info
**)ptr_to_abbrevs_table
;
3694 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3697 abbrev
= abbrevs
[i
];
3700 next
= abbrev
->next
;
3701 xfree (abbrev
->attrs
);
3709 /* Lookup an abbrev_info structure in the abbrev hash table. */
3711 static struct abbrev_info
*
3712 dwarf2_lookup_abbrev (unsigned int number
, const struct comp_unit_head
*cu_header
)
3714 unsigned int hash_number
;
3715 struct abbrev_info
*abbrev
;
3717 hash_number
= number
% ABBREV_HASH_SIZE
;
3718 abbrev
= cu_header
->dwarf2_abbrevs
[hash_number
];
3722 if (abbrev
->number
== number
)
3725 abbrev
= abbrev
->next
;
3730 /* Read a minimal amount of information into the minimal die structure. */
3733 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3734 char *info_ptr
, const struct comp_unit_head
*cu_header
)
3736 unsigned int abbrev_number
, bytes_read
, i
;
3737 struct abbrev_info
*abbrev
;
3738 struct attribute attr
;
3739 struct attribute spec_attr
;
3740 int found_spec_attr
= 0;
3741 int has_low_pc_attr
= 0;
3742 int has_high_pc_attr
= 0;
3744 *part_die
= zeroed_partial_die
;
3745 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3746 info_ptr
+= bytes_read
;
3750 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3753 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3755 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3756 part_die
->tag
= abbrev
->tag
;
3757 part_die
->has_children
= abbrev
->has_children
;
3758 part_die
->abbrev
= abbrev_number
;
3760 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3762 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3763 info_ptr
, cu_header
);
3765 /* Store the data if it is of an attribute we want to keep in a
3766 partial symbol table. */
3771 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3772 if (part_die
->name
== NULL
)
3773 part_die
->name
= DW_STRING (&attr
);
3775 case DW_AT_MIPS_linkage_name
:
3776 part_die
->name
= DW_STRING (&attr
);
3779 has_low_pc_attr
= 1;
3780 part_die
->lowpc
= DW_ADDR (&attr
);
3783 has_high_pc_attr
= 1;
3784 part_die
->highpc
= DW_ADDR (&attr
);
3786 case DW_AT_location
:
3787 /* Support the .debug_loc offsets */
3788 if (attr_form_is_block (&attr
))
3790 part_die
->locdesc
= DW_BLOCK (&attr
);
3792 else if (attr
.form
== DW_FORM_data4
|| attr
.form
== DW_FORM_data8
)
3794 dwarf2_complex_location_expr_complaint ();
3798 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
3799 "partial symbol information");
3802 case DW_AT_language
:
3803 part_die
->language
= DW_UNSND (&attr
);
3805 case DW_AT_external
:
3806 part_die
->is_external
= DW_UNSND (&attr
);
3808 case DW_AT_declaration
:
3809 part_die
->is_declaration
= DW_UNSND (&attr
);
3812 part_die
->has_type
= 1;
3814 case DW_AT_abstract_origin
:
3815 case DW_AT_specification
:
3816 found_spec_attr
= 1;
3820 /* Ignore absolute siblings, they might point outside of
3821 the current compile unit. */
3822 if (attr
.form
== DW_FORM_ref_addr
)
3823 complaint (&symfile_complaints
, "ignoring absolute DW_AT_sibling");
3826 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3833 /* If we found a reference attribute and the die has no name, try
3834 to find a name in the referred to die. */
3836 if (found_spec_attr
&& part_die
->name
== NULL
)
3838 struct partial_die_info spec_die
;
3842 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3843 read_partial_die (&spec_die
, abfd
, spec_ptr
, cu_header
);
3846 part_die
->name
= spec_die
.name
;
3848 /* Copy DW_AT_external attribute if it is set. */
3849 if (spec_die
.is_external
)
3850 part_die
->is_external
= spec_die
.is_external
;
3854 /* When using the GNU linker, .gnu.linkonce. sections are used to
3855 eliminate duplicate copies of functions and vtables and such.
3856 The linker will arbitrarily choose one and discard the others.
3857 The AT_*_pc values for such functions refer to local labels in
3858 these sections. If the section from that file was discarded, the
3859 labels are not in the output, so the relocs get a value of 0.
3860 If this is a discarded function, mark the pc bounds as invalid,
3861 so that GDB will ignore it. */
3862 if (has_low_pc_attr
&& has_high_pc_attr
3863 && part_die
->lowpc
< part_die
->highpc
3864 && (part_die
->lowpc
!= 0
3865 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3866 part_die
->has_pc_info
= 1;
3870 /* Read the die from the .debug_info section buffer. And set diep to
3871 point to a newly allocated die with its information. */
3874 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3875 const struct comp_unit_head
*cu_header
)
3877 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3878 struct abbrev_info
*abbrev
;
3879 struct die_info
*die
;
3881 offset
= info_ptr
- dwarf_info_buffer
;
3882 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3883 info_ptr
+= bytes_read
;
3886 die
= dwarf_alloc_die ();
3888 die
->abbrev
= abbrev_number
;
3894 abbrev
= dwarf2_lookup_abbrev (abbrev_number
, cu_header
);
3897 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3899 die
= dwarf_alloc_die ();
3900 die
->offset
= offset
;
3901 die
->tag
= abbrev
->tag
;
3902 die
->has_children
= abbrev
->has_children
;
3903 die
->abbrev
= abbrev_number
;
3906 die
->num_attrs
= abbrev
->num_attrs
;
3907 die
->attrs
= (struct attribute
*)
3908 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3910 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3912 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3913 abfd
, info_ptr
, cu_header
);
3920 /* Read an attribute value described by an attribute form. */
3923 read_attribute_value (struct attribute
*attr
, unsigned form
,
3924 bfd
*abfd
, char *info_ptr
,
3925 const struct comp_unit_head
*cu_header
)
3927 unsigned int bytes_read
;
3928 struct dwarf_block
*blk
;
3934 case DW_FORM_ref_addr
:
3935 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3936 info_ptr
+= bytes_read
;
3938 case DW_FORM_block2
:
3939 blk
= dwarf_alloc_block ();
3940 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3942 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3943 info_ptr
+= blk
->size
;
3944 DW_BLOCK (attr
) = blk
;
3946 case DW_FORM_block4
:
3947 blk
= dwarf_alloc_block ();
3948 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3950 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3951 info_ptr
+= blk
->size
;
3952 DW_BLOCK (attr
) = blk
;
3955 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3959 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3963 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3966 case DW_FORM_string
:
3967 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3968 info_ptr
+= bytes_read
;
3971 DW_STRING (attr
) = read_indirect_string (abfd
, info_ptr
, cu_header
,
3973 info_ptr
+= bytes_read
;
3976 blk
= dwarf_alloc_block ();
3977 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3978 info_ptr
+= bytes_read
;
3979 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3980 info_ptr
+= blk
->size
;
3981 DW_BLOCK (attr
) = blk
;
3983 case DW_FORM_block1
:
3984 blk
= dwarf_alloc_block ();
3985 blk
->size
= read_1_byte (abfd
, info_ptr
);
3987 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3988 info_ptr
+= blk
->size
;
3989 DW_BLOCK (attr
) = blk
;
3992 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3996 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4000 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
4001 info_ptr
+= bytes_read
;
4004 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4005 info_ptr
+= bytes_read
;
4008 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
4012 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
4016 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
4020 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
4023 case DW_FORM_ref_udata
:
4024 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4025 info_ptr
+= bytes_read
;
4027 case DW_FORM_indirect
:
4028 form
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
4029 info_ptr
+= bytes_read
;
4030 info_ptr
= read_attribute_value (attr
, form
, abfd
, info_ptr
, cu_header
);
4033 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
4034 dwarf_form_name (form
));
4039 /* Read an attribute described by an abbreviated attribute. */
4042 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
4043 bfd
*abfd
, char *info_ptr
,
4044 const struct comp_unit_head
*cu_header
)
4046 attr
->name
= abbrev
->name
;
4047 return read_attribute_value (attr
, abbrev
->form
, abfd
, info_ptr
, cu_header
);
4050 /* read dwarf information from a buffer */
4053 read_1_byte (bfd
*abfd
, char *buf
)
4055 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4059 read_1_signed_byte (bfd
*abfd
, char *buf
)
4061 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
4065 read_2_bytes (bfd
*abfd
, char *buf
)
4067 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4071 read_2_signed_bytes (bfd
*abfd
, char *buf
)
4073 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4077 read_4_bytes (bfd
*abfd
, char *buf
)
4079 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4083 read_4_signed_bytes (bfd
*abfd
, char *buf
)
4085 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4088 static unsigned long
4089 read_8_bytes (bfd
*abfd
, char *buf
)
4091 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4095 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4098 CORE_ADDR retval
= 0;
4100 if (cu_header
->signed_addr_p
)
4102 switch (cu_header
->addr_size
)
4105 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
4108 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
4111 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
4114 internal_error (__FILE__
, __LINE__
,
4115 "read_address: bad switch, signed");
4120 switch (cu_header
->addr_size
)
4123 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
4126 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4129 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4132 internal_error (__FILE__
, __LINE__
,
4133 "read_address: bad switch, unsigned");
4137 *bytes_read
= cu_header
->addr_size
;
4141 /* Read the initial length from a section. The (draft) DWARF 3
4142 specification allows the initial length to take up either 4 bytes
4143 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
4144 bytes describe the length and all offsets will be 8 bytes in length
4147 An older, non-standard 64-bit format is also handled by this
4148 function. The older format in question stores the initial length
4149 as an 8-byte quantity without an escape value. Lengths greater
4150 than 2^32 aren't very common which means that the initial 4 bytes
4151 is almost always zero. Since a length value of zero doesn't make
4152 sense for the 32-bit format, this initial zero can be considered to
4153 be an escape value which indicates the presence of the older 64-bit
4154 format. As written, the code can't detect (old format) lengths
4155 greater than 4GB. If it becomes necessary to handle lengths somewhat
4156 larger than 4GB, we could allow other small values (such as the
4157 non-sensical values of 1, 2, and 3) to also be used as escape values
4158 indicating the presence of the old format.
4160 The value returned via bytes_read should be used to increment
4161 the relevant pointer after calling read_initial_length().
4163 As a side effect, this function sets the fields initial_length_size
4164 and offset_size in cu_header to the values appropriate for the
4165 length field. (The format of the initial length field determines
4166 the width of file offsets to be fetched later with fetch_offset().)
4168 [ Note: read_initial_length() and read_offset() are based on the
4169 document entitled "DWARF Debugging Information Format", revision
4170 3, draft 8, dated November 19, 2001. This document was obtained
4173 http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
4175 This document is only a draft and is subject to change. (So beware.)
4177 Details regarding the older, non-standard 64-bit format were
4178 determined empirically by examining 64-bit ELF files produced
4179 by the SGI toolchain on an IRIX 6.5 machine.
4181 - Kevin, July 16, 2002
4185 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
4190 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4192 if (retval
== 0xffffffff)
4194 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
4196 if (cu_header
!= NULL
)
4198 cu_header
->initial_length_size
= 12;
4199 cu_header
->offset_size
= 8;
4202 else if (retval
== 0)
4204 /* Handle (non-standard) 64-bit DWARF2 formats such as that used
4206 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4208 if (cu_header
!= NULL
)
4210 cu_header
->initial_length_size
= 8;
4211 cu_header
->offset_size
= 8;
4217 if (cu_header
!= NULL
)
4219 cu_header
->initial_length_size
= 4;
4220 cu_header
->offset_size
= 4;
4227 /* Read an offset from the data stream. The size of the offset is
4228 given by cu_header->offset_size. */
4231 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
4236 switch (cu_header
->offset_size
)
4239 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
4243 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
4247 internal_error (__FILE__
, __LINE__
,
4248 "read_offset: bad switch");
4255 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
4257 /* If the size of a host char is 8 bits, we can return a pointer
4258 to the buffer, otherwise we have to copy the data to a buffer
4259 allocated on the temporary obstack. */
4260 gdb_assert (HOST_CHAR_BIT
== 8);
4265 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4267 /* If the size of a host char is 8 bits, we can return a pointer
4268 to the string, otherwise we have to copy the string to a buffer
4269 allocated on the temporary obstack. */
4270 gdb_assert (HOST_CHAR_BIT
== 8);
4273 *bytes_read_ptr
= 1;
4276 *bytes_read_ptr
= strlen (buf
) + 1;
4281 read_indirect_string (bfd
*abfd
, char *buf
,
4282 const struct comp_unit_head
*cu_header
,
4283 unsigned int *bytes_read_ptr
)
4285 LONGEST str_offset
= read_offset (abfd
, buf
, cu_header
,
4286 (int *) bytes_read_ptr
);
4288 if (dwarf_str_buffer
== NULL
)
4290 error ("DW_FORM_strp used without .debug_str section");
4293 if (str_offset
>= dwarf_str_size
)
4295 error ("DW_FORM_strp pointing outside of .debug_str section");
4298 gdb_assert (HOST_CHAR_BIT
== 8);
4299 if (dwarf_str_buffer
[str_offset
] == '\0')
4301 return dwarf_str_buffer
+ str_offset
;
4304 static unsigned long
4305 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4307 unsigned long result
;
4308 unsigned int num_read
;
4318 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4321 result
|= ((unsigned long)(byte
& 127) << shift
);
4322 if ((byte
& 128) == 0)
4328 *bytes_read_ptr
= num_read
;
4333 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
4336 int i
, shift
, size
, num_read
;
4346 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
4349 result
|= ((long)(byte
& 127) << shift
);
4351 if ((byte
& 128) == 0)
4356 if ((shift
< size
) && (byte
& 0x40))
4358 result
|= -(1 << shift
);
4360 *bytes_read_ptr
= num_read
;
4365 set_cu_language (unsigned int lang
)
4371 cu_language
= language_c
;
4373 case DW_LANG_C_plus_plus
:
4374 cu_language
= language_cplus
;
4376 case DW_LANG_Fortran77
:
4377 case DW_LANG_Fortran90
:
4378 case DW_LANG_Fortran95
:
4379 cu_language
= language_fortran
;
4381 case DW_LANG_Mips_Assembler
:
4382 cu_language
= language_asm
;
4385 cu_language
= language_java
;
4389 case DW_LANG_Cobol74
:
4390 case DW_LANG_Cobol85
:
4391 case DW_LANG_Pascal83
:
4392 case DW_LANG_Modula2
:
4394 cu_language
= language_unknown
;
4397 cu_language_defn
= language_def (cu_language
);
4400 /* Return the named attribute or NULL if not there. */
4402 static struct attribute
*
4403 dwarf_attr (struct die_info
*die
, unsigned int name
)
4406 struct attribute
*spec
= NULL
;
4408 for (i
= 0; i
< die
->num_attrs
; ++i
)
4410 if (die
->attrs
[i
].name
== name
)
4412 return &die
->attrs
[i
];
4414 if (die
->attrs
[i
].name
== DW_AT_specification
4415 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
4416 spec
= &die
->attrs
[i
];
4420 struct die_info
*ref_die
=
4421 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
4424 return dwarf_attr (ref_die
, name
);
4431 die_is_declaration (struct die_info
*die
)
4433 return (dwarf_attr (die
, DW_AT_declaration
)
4434 && ! dwarf_attr (die
, DW_AT_specification
));
4438 /* Free the line_header structure *LH, and any arrays and strings it
4441 free_line_header (struct line_header
*lh
)
4443 if (lh
->standard_opcode_lengths
)
4444 xfree (lh
->standard_opcode_lengths
);
4446 /* Remember that all the lh->file_names[i].name pointers are
4447 pointers into debug_line_buffer, and don't need to be freed. */
4449 xfree (lh
->file_names
);
4451 /* Similarly for the include directory names. */
4452 if (lh
->include_dirs
)
4453 xfree (lh
->include_dirs
);
4459 /* Add an entry to LH's include directory table. */
4461 add_include_dir (struct line_header
*lh
, char *include_dir
)
4463 /* Grow the array if necessary. */
4464 if (lh
->include_dirs_size
== 0)
4466 lh
->include_dirs_size
= 1; /* for testing */
4467 lh
->include_dirs
= xmalloc (lh
->include_dirs_size
4468 * sizeof (*lh
->include_dirs
));
4470 else if (lh
->num_include_dirs
>= lh
->include_dirs_size
)
4472 lh
->include_dirs_size
*= 2;
4473 lh
->include_dirs
= xrealloc (lh
->include_dirs
,
4474 (lh
->include_dirs_size
4475 * sizeof (*lh
->include_dirs
)));
4478 lh
->include_dirs
[lh
->num_include_dirs
++] = include_dir
;
4482 /* Add an entry to LH's file name table. */
4484 add_file_name (struct line_header
*lh
,
4486 unsigned int dir_index
,
4487 unsigned int mod_time
,
4488 unsigned int length
)
4490 struct file_entry
*fe
;
4492 /* Grow the array if necessary. */
4493 if (lh
->file_names_size
== 0)
4495 lh
->file_names_size
= 1; /* for testing */
4496 lh
->file_names
= xmalloc (lh
->file_names_size
4497 * sizeof (*lh
->file_names
));
4499 else if (lh
->num_file_names
>= lh
->file_names_size
)
4501 lh
->file_names_size
*= 2;
4502 lh
->file_names
= xrealloc (lh
->file_names
,
4503 (lh
->file_names_size
4504 * sizeof (*lh
->file_names
)));
4507 fe
= &lh
->file_names
[lh
->num_file_names
++];
4509 fe
->dir_index
= dir_index
;
4510 fe
->mod_time
= mod_time
;
4511 fe
->length
= length
;
4515 /* Read the statement program header starting at OFFSET in
4516 dwarf_line_buffer, according to the endianness of ABFD. Return a
4517 pointer to a struct line_header, allocated using xmalloc.
4519 NOTE: the strings in the include directory and file name tables of
4520 the returned object point into debug_line_buffer, and must not be
4522 static struct line_header
*
4523 dwarf_decode_line_header (unsigned int offset
, bfd
*abfd
,
4524 const struct comp_unit_head
*cu_header
)
4526 struct cleanup
*back_to
;
4527 struct line_header
*lh
;
4531 char *cur_dir
, *cur_file
;
4533 if (dwarf_line_buffer
== NULL
)
4535 complaint (&symfile_complaints
, "missing .debug_line section");
4539 /* Make sure that at least there's room for the total_length field. That
4540 could be 12 bytes long, but we're just going to fudge that. */
4541 if (offset
+ 4 >= dwarf_line_size
)
4543 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4547 lh
= xmalloc (sizeof (*lh
));
4548 memset (lh
, 0, sizeof (*lh
));
4549 back_to
= make_cleanup ((make_cleanup_ftype
*) free_line_header
,
4552 line_ptr
= dwarf_line_buffer
+ offset
;
4554 /* read in the header */
4555 lh
->total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
4556 line_ptr
+= bytes_read
;
4557 if (line_ptr
+ lh
->total_length
> dwarf_line_buffer
+ dwarf_line_size
)
4559 dwarf2_statement_list_fits_in_line_number_section_complaint ();
4562 lh
->statement_program_end
= line_ptr
+ lh
->total_length
;
4563 lh
->version
= read_2_bytes (abfd
, line_ptr
);
4565 lh
->header_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
4566 line_ptr
+= bytes_read
;
4567 lh
->minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
4569 lh
->default_is_stmt
= read_1_byte (abfd
, line_ptr
);
4571 lh
->line_base
= read_1_signed_byte (abfd
, line_ptr
);
4573 lh
->line_range
= read_1_byte (abfd
, line_ptr
);
4575 lh
->opcode_base
= read_1_byte (abfd
, line_ptr
);
4577 lh
->standard_opcode_lengths
4578 = (unsigned char *) xmalloc (lh
->opcode_base
* sizeof (unsigned char));
4580 lh
->standard_opcode_lengths
[0] = 1; /* This should never be used anyway. */
4581 for (i
= 1; i
< lh
->opcode_base
; ++i
)
4583 lh
->standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
4587 /* Read directory table */
4588 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4590 line_ptr
+= bytes_read
;
4591 add_include_dir (lh
, cur_dir
);
4593 line_ptr
+= bytes_read
;
4595 /* Read file name table */
4596 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
4598 unsigned int dir_index
, mod_time
, length
;
4600 line_ptr
+= bytes_read
;
4601 dir_index
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4602 line_ptr
+= bytes_read
;
4603 mod_time
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4604 line_ptr
+= bytes_read
;
4605 length
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4606 line_ptr
+= bytes_read
;
4608 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4610 line_ptr
+= bytes_read
;
4611 lh
->statement_program_start
= line_ptr
;
4613 if (line_ptr
> dwarf_line_buffer
+ dwarf_line_size
)
4614 complaint (&symfile_complaints
,
4615 "line number info header doesn't fit in `.debug_line' section");
4617 discard_cleanups (back_to
);
4621 /* This function exists to work around a bug in certain compilers
4622 (particularly GCC 2.95), in which the first line number marker of a
4623 function does not show up until after the prologue, right before
4624 the second line number marker. This function shifts ADDRESS down
4625 to the beginning of the function if necessary, and is called on
4626 addresses passed to record_line. */
4629 check_cu_functions (CORE_ADDR address
)
4631 struct function_range
*fn
;
4633 /* Find the function_range containing address. */
4638 cu_cached_fn
= cu_first_fn
;
4642 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4648 while (fn
&& fn
!= cu_cached_fn
)
4649 if (fn
->lowpc
<= address
&& fn
->highpc
> address
)
4659 if (address
!= fn
->lowpc
)
4660 complaint (&symfile_complaints
,
4661 "misplaced first line number at 0x%lx for '%s'",
4662 (unsigned long) address
, fn
->name
);
4667 /* Decode the line number information for the compilation unit whose
4668 line number info is at OFFSET in the .debug_line section.
4669 The compilation directory of the file is passed in COMP_DIR. */
4672 dwarf_decode_lines (struct line_header
*lh
, char *comp_dir
, bfd
*abfd
,
4673 const struct comp_unit_head
*cu_header
)
4677 unsigned int i
, bytes_read
;
4679 unsigned char op_code
, extended_op
, adj_opcode
;
4681 line_ptr
= lh
->statement_program_start
;
4682 line_end
= lh
->statement_program_end
;
4684 /* Read the statement sequences until there's nothing left. */
4685 while (line_ptr
< line_end
)
4687 /* state machine registers */
4688 CORE_ADDR address
= 0;
4689 unsigned int file
= 1;
4690 unsigned int line
= 1;
4691 unsigned int column
= 0;
4692 int is_stmt
= lh
->default_is_stmt
;
4693 int basic_block
= 0;
4694 int end_sequence
= 0;
4696 /* Start a subfile for the current file of the state machine. */
4697 if (lh
->num_file_names
>= file
)
4699 /* lh->include_dirs and lh->file_names are 0-based, but the
4700 directory and file name numbers in the statement program
4702 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
4705 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4708 dwarf2_start_subfile (fe
->name
, dir
);
4711 /* Decode the table. */
4712 while (!end_sequence
)
4714 op_code
= read_1_byte (abfd
, line_ptr
);
4717 if (op_code
>= lh
->opcode_base
)
4718 { /* Special operand. */
4719 adj_opcode
= op_code
- lh
->opcode_base
;
4720 address
+= (adj_opcode
/ lh
->line_range
)
4721 * lh
->minimum_instruction_length
;
4722 line
+= lh
->line_base
+ (adj_opcode
% lh
->line_range
);
4723 /* append row to matrix using current values */
4724 address
= check_cu_functions (address
);
4725 record_line (current_subfile
, line
, address
);
4728 else switch (op_code
)
4730 case DW_LNS_extended_op
:
4731 line_ptr
+= 1; /* ignore length */
4732 extended_op
= read_1_byte (abfd
, line_ptr
);
4734 switch (extended_op
)
4736 case DW_LNE_end_sequence
:
4738 record_line (current_subfile
, 0, address
);
4740 case DW_LNE_set_address
:
4741 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
4742 line_ptr
+= bytes_read
;
4743 address
+= baseaddr
;
4745 case DW_LNE_define_file
:
4748 unsigned int dir_index
, mod_time
, length
;
4750 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
4751 line_ptr
+= bytes_read
;
4753 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4754 line_ptr
+= bytes_read
;
4756 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4757 line_ptr
+= bytes_read
;
4759 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4760 line_ptr
+= bytes_read
;
4761 add_file_name (lh
, cur_file
, dir_index
, mod_time
, length
);
4765 complaint (&symfile_complaints
,
4766 "mangled .debug_line section");
4771 address
= check_cu_functions (address
);
4772 record_line (current_subfile
, line
, address
);
4775 case DW_LNS_advance_pc
:
4776 address
+= lh
->minimum_instruction_length
4777 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4778 line_ptr
+= bytes_read
;
4780 case DW_LNS_advance_line
:
4781 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4782 line_ptr
+= bytes_read
;
4784 case DW_LNS_set_file
:
4786 /* lh->include_dirs and lh->file_names are 0-based,
4787 but the directory and file name numbers in the
4788 statement program are 1-based. */
4789 struct file_entry
*fe
;
4791 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4792 line_ptr
+= bytes_read
;
4793 fe
= &lh
->file_names
[file
- 1];
4795 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
4798 dwarf2_start_subfile (fe
->name
, dir
);
4801 case DW_LNS_set_column
:
4802 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4803 line_ptr
+= bytes_read
;
4805 case DW_LNS_negate_stmt
:
4806 is_stmt
= (!is_stmt
);
4808 case DW_LNS_set_basic_block
:
4811 /* Add to the address register of the state machine the
4812 address increment value corresponding to special opcode
4813 255. Ie, this value is scaled by the minimum instruction
4814 length since special opcode 255 would have scaled the
4816 case DW_LNS_const_add_pc
:
4817 address
+= (lh
->minimum_instruction_length
4818 * ((255 - lh
->opcode_base
) / lh
->line_range
));
4820 case DW_LNS_fixed_advance_pc
:
4821 address
+= read_2_bytes (abfd
, line_ptr
);
4825 { /* Unknown standard opcode, ignore it. */
4827 for (i
= 0; i
< lh
->standard_opcode_lengths
[op_code
]; i
++)
4829 (void) read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4830 line_ptr
+= bytes_read
;
4838 /* Start a subfile for DWARF. FILENAME is the name of the file and
4839 DIRNAME the name of the source directory which contains FILENAME
4840 or NULL if not known.
4841 This routine tries to keep line numbers from identical absolute and
4842 relative file names in a common subfile.
4844 Using the `list' example from the GDB testsuite, which resides in
4845 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4846 of /srcdir/list0.c yields the following debugging information for list0.c:
4848 DW_AT_name: /srcdir/list0.c
4849 DW_AT_comp_dir: /compdir
4850 files.files[0].name: list0.h
4851 files.files[0].dir: /srcdir
4852 files.files[1].name: list0.c
4853 files.files[1].dir: /srcdir
4855 The line number information for list0.c has to end up in a single
4856 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4859 dwarf2_start_subfile (char *filename
, char *dirname
)
4861 /* If the filename isn't absolute, try to match an existing subfile
4862 with the full pathname. */
4864 if (!IS_ABSOLUTE_PATH (filename
) && dirname
!= NULL
)
4866 struct subfile
*subfile
;
4867 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4869 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4871 if (FILENAME_CMP (subfile
->name
, fullname
) == 0)
4873 current_subfile
= subfile
;
4880 start_subfile (filename
, dirname
);
4883 /* Given a pointer to a DWARF information entry, figure out if we need
4884 to make a symbol table entry for it, and if so, create a new entry
4885 and return a pointer to it.
4886 If TYPE is NULL, determine symbol type from the die, otherwise
4887 used the passed type. */
4889 static struct symbol
*
4890 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4891 const struct comp_unit_head
*cu_header
)
4893 struct symbol
*sym
= NULL
;
4895 struct attribute
*attr
= NULL
;
4896 struct attribute
*attr2
= NULL
;
4899 name
= dwarf2_linkage_name (die
);
4902 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4903 sizeof (struct symbol
));
4904 OBJSTAT (objfile
, n_syms
++);
4905 memset (sym
, 0, sizeof (struct symbol
));
4906 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4907 &objfile
->symbol_obstack
);
4909 /* Default assumptions.
4910 Use the passed type or decode it from the die. */
4911 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4912 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4914 SYMBOL_TYPE (sym
) = type
;
4916 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4917 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4920 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4923 /* If this symbol is from a C++ compilation, then attempt to
4924 cache the demangled form for future reference. This is a
4925 typical time versus space tradeoff, that was decided in favor
4926 of time because it sped up C++ symbol lookups by a factor of
4929 SYMBOL_LANGUAGE (sym
) = cu_language
;
4930 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4934 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4937 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4939 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4941 case DW_TAG_subprogram
:
4942 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4944 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4945 attr2
= dwarf_attr (die
, DW_AT_external
);
4946 if (attr2
&& (DW_UNSND (attr2
) != 0))
4948 add_symbol_to_list (sym
, &global_symbols
);
4952 add_symbol_to_list (sym
, list_in_scope
);
4955 case DW_TAG_variable
:
4956 /* Compilation with minimal debug info may result in variables
4957 with missing type entries. Change the misleading `void' type
4958 to something sensible. */
4959 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4960 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4961 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4962 "<variable, no debug info>",
4964 attr
= dwarf_attr (die
, DW_AT_const_value
);
4967 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4968 attr2
= dwarf_attr (die
, DW_AT_external
);
4969 if (attr2
&& (DW_UNSND (attr2
) != 0))
4970 add_symbol_to_list (sym
, &global_symbols
);
4972 add_symbol_to_list (sym
, list_in_scope
);
4975 attr
= dwarf_attr (die
, DW_AT_location
);
4978 attr2
= dwarf_attr (die
, DW_AT_external
);
4979 if (attr2
&& (DW_UNSND (attr2
) != 0))
4981 /* Support the .debug_loc offsets */
4982 if (attr_form_is_block (attr
))
4984 SYMBOL_VALUE_ADDRESS (sym
) =
4985 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4987 else if (attr
->form
== DW_FORM_data4
4988 || attr
->form
== DW_FORM_data8
)
4990 dwarf2_complex_location_expr_complaint ();
4994 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
4995 "external variable");
4997 add_symbol_to_list (sym
, &global_symbols
);
4998 if (is_thread_local
)
5000 /* SYMBOL_VALUE_ADDRESS contains at this point the
5001 offset of the variable within the thread local
5003 SYMBOL_CLASS (sym
) = LOC_THREAD_LOCAL_STATIC
;
5004 SYMBOL_OBJFILE (sym
) = objfile
;
5007 /* In shared libraries the address of the variable
5008 in the location descriptor might still be relocatable,
5009 so its value could be zero.
5010 Enter the symbol as a LOC_UNRESOLVED symbol, if its
5011 value is zero, the address of the variable will then
5012 be determined from the minimal symbol table whenever
5013 the variable is referenced. */
5014 else if (SYMBOL_VALUE_ADDRESS (sym
))
5016 fixup_symbol_section (sym
, objfile
);
5017 SYMBOL_VALUE_ADDRESS (sym
) +=
5018 ANOFFSET (objfile
->section_offsets
,
5019 SYMBOL_SECTION (sym
));
5020 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5023 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5027 /* Support the .debug_loc offsets */
5028 if (attr_form_is_block (attr
))
5030 SYMBOL_VALUE (sym
) = addr
=
5031 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
5033 else if (attr
->form
== DW_FORM_data4
5034 || attr
->form
== DW_FORM_data8
)
5036 dwarf2_complex_location_expr_complaint ();
5040 dwarf2_invalid_attrib_class_complaint ("DW_AT_location",
5041 "external variable");
5044 add_symbol_to_list (sym
, list_in_scope
);
5047 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
5051 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
5052 SYMBOL_VALUE (sym
) =
5053 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
5057 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
5058 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
5062 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
5064 else if (is_thread_local
)
5066 SYMBOL_CLASS (sym
) = LOC_THREAD_LOCAL_STATIC
;
5067 SYMBOL_OBJFILE (sym
) = objfile
;
5071 fixup_symbol_section (sym
, objfile
);
5072 SYMBOL_VALUE_ADDRESS (sym
) =
5073 addr
+ ANOFFSET (objfile
->section_offsets
,
5074 SYMBOL_SECTION (sym
));
5075 SYMBOL_CLASS (sym
) = LOC_STATIC
;
5081 /* We do not know the address of this symbol.
5082 If it is an external symbol and we have type information
5083 for it, enter the symbol as a LOC_UNRESOLVED symbol.
5084 The address of the variable will then be determined from
5085 the minimal symbol table whenever the variable is
5087 attr2
= dwarf_attr (die
, DW_AT_external
);
5088 if (attr2
&& (DW_UNSND (attr2
) != 0)
5089 && dwarf_attr (die
, DW_AT_type
) != NULL
)
5091 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
5092 add_symbol_to_list (sym
, &global_symbols
);
5096 case DW_TAG_formal_parameter
:
5097 attr
= dwarf_attr (die
, DW_AT_location
);
5100 SYMBOL_VALUE (sym
) =
5101 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
5104 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
5105 SYMBOL_VALUE (sym
) =
5106 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
5112 if (basereg
!= frame_base_reg
)
5113 dwarf2_complex_location_expr_complaint ();
5114 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
5118 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
5119 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
5124 SYMBOL_CLASS (sym
) = LOC_ARG
;
5127 attr
= dwarf_attr (die
, DW_AT_const_value
);
5130 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5132 add_symbol_to_list (sym
, list_in_scope
);
5134 case DW_TAG_unspecified_parameters
:
5135 /* From varargs functions; gdb doesn't seem to have any
5136 interest in this information, so just ignore it for now.
5139 case DW_TAG_class_type
:
5140 case DW_TAG_structure_type
:
5141 case DW_TAG_union_type
:
5142 case DW_TAG_enumeration_type
:
5143 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5144 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
5145 add_symbol_to_list (sym
, list_in_scope
);
5147 /* The semantics of C++ state that "struct foo { ... }" also
5148 defines a typedef for "foo". Synthesize a typedef symbol so
5149 that "ptype foo" works as expected. */
5150 if (cu_language
== language_cplus
)
5152 struct symbol
*typedef_sym
= (struct symbol
*)
5153 obstack_alloc (&objfile
->symbol_obstack
,
5154 sizeof (struct symbol
));
5155 *typedef_sym
= *sym
;
5156 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
5157 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
5158 TYPE_NAME (SYMBOL_TYPE (sym
)) =
5159 obsavestring (SYMBOL_NAME (sym
),
5160 strlen (SYMBOL_NAME (sym
)),
5161 &objfile
->type_obstack
);
5162 add_symbol_to_list (typedef_sym
, list_in_scope
);
5165 case DW_TAG_typedef
:
5166 case DW_TAG_base_type
:
5167 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
5168 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
5169 add_symbol_to_list (sym
, list_in_scope
);
5171 case DW_TAG_enumerator
:
5172 attr
= dwarf_attr (die
, DW_AT_const_value
);
5175 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
5177 add_symbol_to_list (sym
, list_in_scope
);
5180 /* Not a tag we recognize. Hopefully we aren't processing
5181 trash data, but since we must specifically ignore things
5182 we don't recognize, there is nothing else we should do at
5184 complaint (&symfile_complaints
, "unsupported tag: '%s'",
5185 dwarf_tag_name (die
->tag
));
5192 /* Copy constant value from an attribute to a symbol. */
5195 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
5196 struct objfile
*objfile
,
5197 const struct comp_unit_head
*cu_header
)
5199 struct dwarf_block
*blk
;
5204 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
5205 dwarf2_const_value_length_mismatch_complaint (SYMBOL_NAME (sym
),
5206 cu_header
->addr_size
,
5207 TYPE_LENGTH (SYMBOL_TYPE
5209 SYMBOL_VALUE_BYTES (sym
) = (char *)
5210 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
5211 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
5213 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5215 case DW_FORM_block1
:
5216 case DW_FORM_block2
:
5217 case DW_FORM_block4
:
5219 blk
= DW_BLOCK (attr
);
5220 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
5221 dwarf2_const_value_length_mismatch_complaint (SYMBOL_NAME (sym
),
5223 TYPE_LENGTH (SYMBOL_TYPE
5225 SYMBOL_VALUE_BYTES (sym
) = (char *)
5226 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
5227 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
5228 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
5231 /* The DW_AT_const_value attributes are supposed to carry the
5232 symbol's value "represented as it would be on the target
5233 architecture." By the time we get here, it's already been
5234 converted to host endianness, so we just need to sign- or
5235 zero-extend it as appropriate. */
5237 dwarf2_const_value_data (attr
, sym
, 8);
5240 dwarf2_const_value_data (attr
, sym
, 16);
5243 dwarf2_const_value_data (attr
, sym
, 32);
5246 dwarf2_const_value_data (attr
, sym
, 64);
5250 SYMBOL_VALUE (sym
) = DW_SND (attr
);
5251 SYMBOL_CLASS (sym
) = LOC_CONST
;
5255 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
5256 SYMBOL_CLASS (sym
) = LOC_CONST
;
5260 complaint (&symfile_complaints
,
5261 "unsupported const value attribute form: '%s'",
5262 dwarf_form_name (attr
->form
));
5263 SYMBOL_VALUE (sym
) = 0;
5264 SYMBOL_CLASS (sym
) = LOC_CONST
;
5270 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
5271 or zero-extend it as appropriate for the symbol's type. */
5273 dwarf2_const_value_data (struct attribute
*attr
,
5277 LONGEST l
= DW_UNSND (attr
);
5279 if (bits
< sizeof (l
) * 8)
5281 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
5282 l
&= ((LONGEST
) 1 << bits
) - 1;
5284 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
5287 SYMBOL_VALUE (sym
) = l
;
5288 SYMBOL_CLASS (sym
) = LOC_CONST
;
5292 /* Return the type of the die in question using its DW_AT_type attribute. */
5294 static struct type
*
5295 die_type (struct die_info
*die
, struct objfile
*objfile
,
5296 const struct comp_unit_head
*cu_header
)
5299 struct attribute
*type_attr
;
5300 struct die_info
*type_die
;
5303 type_attr
= dwarf_attr (die
, DW_AT_type
);
5306 /* A missing DW_AT_type represents a void type. */
5307 return dwarf2_fundamental_type (objfile
, FT_VOID
);
5311 ref
= dwarf2_get_ref_die_offset (type_attr
);
5312 type_die
= follow_die_ref (ref
);
5315 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5319 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5322 dump_die (type_die
);
5323 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
5328 /* Return the containing type of the die in question using its
5329 DW_AT_containing_type attribute. */
5331 static struct type
*
5332 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
5333 const struct comp_unit_head
*cu_header
)
5335 struct type
*type
= NULL
;
5336 struct attribute
*type_attr
;
5337 struct die_info
*type_die
= NULL
;
5340 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
5343 ref
= dwarf2_get_ref_die_offset (type_attr
);
5344 type_die
= follow_die_ref (ref
);
5347 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
5350 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
5355 dump_die (type_die
);
5356 error ("Dwarf Error: Problem turning containing type into gdb type.");
5362 static struct type
*
5363 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
5365 struct die_info
*die
;
5368 die
= follow_die_ref (offset
);
5371 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
5374 type
= tag_type_to_type (die
, objfile
);
5379 static struct type
*
5380 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
5381 const struct comp_unit_head
*cu_header
)
5389 read_type_die (die
, objfile
, cu_header
);
5393 error ("Dwarf Error: Cannot find type of die.");
5400 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
5401 const struct comp_unit_head
*cu_header
)
5405 case DW_TAG_class_type
:
5406 case DW_TAG_structure_type
:
5407 case DW_TAG_union_type
:
5408 read_structure_scope (die
, objfile
, cu_header
);
5410 case DW_TAG_enumeration_type
:
5411 read_enumeration (die
, objfile
, cu_header
);
5413 case DW_TAG_subprogram
:
5414 case DW_TAG_subroutine_type
:
5415 read_subroutine_type (die
, objfile
, cu_header
);
5417 case DW_TAG_array_type
:
5418 read_array_type (die
, objfile
, cu_header
);
5420 case DW_TAG_pointer_type
:
5421 read_tag_pointer_type (die
, objfile
, cu_header
);
5423 case DW_TAG_ptr_to_member_type
:
5424 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
5426 case DW_TAG_reference_type
:
5427 read_tag_reference_type (die
, objfile
, cu_header
);
5429 case DW_TAG_const_type
:
5430 read_tag_const_type (die
, objfile
, cu_header
);
5432 case DW_TAG_volatile_type
:
5433 read_tag_volatile_type (die
, objfile
, cu_header
);
5435 case DW_TAG_string_type
:
5436 read_tag_string_type (die
, objfile
);
5438 case DW_TAG_typedef
:
5439 read_typedef (die
, objfile
, cu_header
);
5441 case DW_TAG_base_type
:
5442 read_base_type (die
, objfile
);
5445 complaint (&symfile_complaints
, "unexepected tag in read_type_die: '%s'",
5446 dwarf_tag_name (die
->tag
));
5451 static struct type
*
5452 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
5454 /* FIXME - this should not produce a new (struct type *)
5455 every time. It should cache base types. */
5459 case DW_ATE_address
:
5460 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
5462 case DW_ATE_boolean
:
5463 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
5465 case DW_ATE_complex_float
:
5468 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
5472 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
5478 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
5482 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
5489 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5492 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
5496 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5500 case DW_ATE_signed_char
:
5501 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
5503 case DW_ATE_unsigned
:
5507 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5510 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
5514 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
5518 case DW_ATE_unsigned_char
:
5519 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
5522 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
5529 copy_die (struct die_info
*old_die
)
5531 struct die_info
*new_die
;
5534 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5535 memset (new_die
, 0, sizeof (struct die_info
));
5537 new_die
->tag
= old_die
->tag
;
5538 new_die
->has_children
= old_die
->has_children
;
5539 new_die
->abbrev
= old_die
->abbrev
;
5540 new_die
->offset
= old_die
->offset
;
5541 new_die
->type
= NULL
;
5543 num_attrs
= old_die
->num_attrs
;
5544 new_die
->num_attrs
= num_attrs
;
5545 new_die
->attrs
= (struct attribute
*)
5546 xmalloc (num_attrs
* sizeof (struct attribute
));
5548 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
5550 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
5551 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
5552 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
5555 new_die
->next
= NULL
;
5560 /* Return sibling of die, NULL if no sibling. */
5562 static struct die_info
*
5563 sibling_die (struct die_info
*die
)
5565 int nesting_level
= 0;
5567 if (!die
->has_children
)
5569 if (die
->next
&& (die
->next
->tag
== 0))
5582 if (die
->has_children
)
5592 while (nesting_level
);
5593 if (die
&& (die
->tag
== 0))
5604 /* Get linkage name of a die, return NULL if not found. */
5607 dwarf2_linkage_name (struct die_info
*die
)
5609 struct attribute
*attr
;
5611 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
5612 if (attr
&& DW_STRING (attr
))
5613 return DW_STRING (attr
);
5614 attr
= dwarf_attr (die
, DW_AT_name
);
5615 if (attr
&& DW_STRING (attr
))
5616 return DW_STRING (attr
);
5620 /* Convert a DIE tag into its string name. */
5623 dwarf_tag_name (register unsigned tag
)
5627 case DW_TAG_padding
:
5628 return "DW_TAG_padding";
5629 case DW_TAG_array_type
:
5630 return "DW_TAG_array_type";
5631 case DW_TAG_class_type
:
5632 return "DW_TAG_class_type";
5633 case DW_TAG_entry_point
:
5634 return "DW_TAG_entry_point";
5635 case DW_TAG_enumeration_type
:
5636 return "DW_TAG_enumeration_type";
5637 case DW_TAG_formal_parameter
:
5638 return "DW_TAG_formal_parameter";
5639 case DW_TAG_imported_declaration
:
5640 return "DW_TAG_imported_declaration";
5642 return "DW_TAG_label";
5643 case DW_TAG_lexical_block
:
5644 return "DW_TAG_lexical_block";
5646 return "DW_TAG_member";
5647 case DW_TAG_pointer_type
:
5648 return "DW_TAG_pointer_type";
5649 case DW_TAG_reference_type
:
5650 return "DW_TAG_reference_type";
5651 case DW_TAG_compile_unit
:
5652 return "DW_TAG_compile_unit";
5653 case DW_TAG_string_type
:
5654 return "DW_TAG_string_type";
5655 case DW_TAG_structure_type
:
5656 return "DW_TAG_structure_type";
5657 case DW_TAG_subroutine_type
:
5658 return "DW_TAG_subroutine_type";
5659 case DW_TAG_typedef
:
5660 return "DW_TAG_typedef";
5661 case DW_TAG_union_type
:
5662 return "DW_TAG_union_type";
5663 case DW_TAG_unspecified_parameters
:
5664 return "DW_TAG_unspecified_parameters";
5665 case DW_TAG_variant
:
5666 return "DW_TAG_variant";
5667 case DW_TAG_common_block
:
5668 return "DW_TAG_common_block";
5669 case DW_TAG_common_inclusion
:
5670 return "DW_TAG_common_inclusion";
5671 case DW_TAG_inheritance
:
5672 return "DW_TAG_inheritance";
5673 case DW_TAG_inlined_subroutine
:
5674 return "DW_TAG_inlined_subroutine";
5676 return "DW_TAG_module";
5677 case DW_TAG_ptr_to_member_type
:
5678 return "DW_TAG_ptr_to_member_type";
5679 case DW_TAG_set_type
:
5680 return "DW_TAG_set_type";
5681 case DW_TAG_subrange_type
:
5682 return "DW_TAG_subrange_type";
5683 case DW_TAG_with_stmt
:
5684 return "DW_TAG_with_stmt";
5685 case DW_TAG_access_declaration
:
5686 return "DW_TAG_access_declaration";
5687 case DW_TAG_base_type
:
5688 return "DW_TAG_base_type";
5689 case DW_TAG_catch_block
:
5690 return "DW_TAG_catch_block";
5691 case DW_TAG_const_type
:
5692 return "DW_TAG_const_type";
5693 case DW_TAG_constant
:
5694 return "DW_TAG_constant";
5695 case DW_TAG_enumerator
:
5696 return "DW_TAG_enumerator";
5697 case DW_TAG_file_type
:
5698 return "DW_TAG_file_type";
5700 return "DW_TAG_friend";
5701 case DW_TAG_namelist
:
5702 return "DW_TAG_namelist";
5703 case DW_TAG_namelist_item
:
5704 return "DW_TAG_namelist_item";
5705 case DW_TAG_packed_type
:
5706 return "DW_TAG_packed_type";
5707 case DW_TAG_subprogram
:
5708 return "DW_TAG_subprogram";
5709 case DW_TAG_template_type_param
:
5710 return "DW_TAG_template_type_param";
5711 case DW_TAG_template_value_param
:
5712 return "DW_TAG_template_value_param";
5713 case DW_TAG_thrown_type
:
5714 return "DW_TAG_thrown_type";
5715 case DW_TAG_try_block
:
5716 return "DW_TAG_try_block";
5717 case DW_TAG_variant_part
:
5718 return "DW_TAG_variant_part";
5719 case DW_TAG_variable
:
5720 return "DW_TAG_variable";
5721 case DW_TAG_volatile_type
:
5722 return "DW_TAG_volatile_type";
5723 case DW_TAG_dwarf_procedure
:
5724 return "DW_TAG_dwarf_procedure";
5725 case DW_TAG_restrict_type
:
5726 return "DW_TAG_restrict_type";
5727 case DW_TAG_interface_type
:
5728 return "DW_TAG_interface_type";
5729 case DW_TAG_namespace
:
5730 return "DW_TAG_namespace";
5731 case DW_TAG_imported_module
:
5732 return "DW_TAG_imported_module";
5733 case DW_TAG_unspecified_type
:
5734 return "DW_TAG_unspecified_type";
5735 case DW_TAG_partial_unit
:
5736 return "DW_TAG_partial_unit";
5737 case DW_TAG_imported_unit
:
5738 return "DW_TAG_imported_unit";
5739 case DW_TAG_MIPS_loop
:
5740 return "DW_TAG_MIPS_loop";
5741 case DW_TAG_format_label
:
5742 return "DW_TAG_format_label";
5743 case DW_TAG_function_template
:
5744 return "DW_TAG_function_template";
5745 case DW_TAG_class_template
:
5746 return "DW_TAG_class_template";
5748 return "DW_TAG_<unknown>";
5752 /* Convert a DWARF attribute code into its string name. */
5755 dwarf_attr_name (register unsigned attr
)
5760 return "DW_AT_sibling";
5761 case DW_AT_location
:
5762 return "DW_AT_location";
5764 return "DW_AT_name";
5765 case DW_AT_ordering
:
5766 return "DW_AT_ordering";
5767 case DW_AT_subscr_data
:
5768 return "DW_AT_subscr_data";
5769 case DW_AT_byte_size
:
5770 return "DW_AT_byte_size";
5771 case DW_AT_bit_offset
:
5772 return "DW_AT_bit_offset";
5773 case DW_AT_bit_size
:
5774 return "DW_AT_bit_size";
5775 case DW_AT_element_list
:
5776 return "DW_AT_element_list";
5777 case DW_AT_stmt_list
:
5778 return "DW_AT_stmt_list";
5780 return "DW_AT_low_pc";
5782 return "DW_AT_high_pc";
5783 case DW_AT_language
:
5784 return "DW_AT_language";
5786 return "DW_AT_member";
5788 return "DW_AT_discr";
5789 case DW_AT_discr_value
:
5790 return "DW_AT_discr_value";
5791 case DW_AT_visibility
:
5792 return "DW_AT_visibility";
5794 return "DW_AT_import";
5795 case DW_AT_string_length
:
5796 return "DW_AT_string_length";
5797 case DW_AT_common_reference
:
5798 return "DW_AT_common_reference";
5799 case DW_AT_comp_dir
:
5800 return "DW_AT_comp_dir";
5801 case DW_AT_const_value
:
5802 return "DW_AT_const_value";
5803 case DW_AT_containing_type
:
5804 return "DW_AT_containing_type";
5805 case DW_AT_default_value
:
5806 return "DW_AT_default_value";
5808 return "DW_AT_inline";
5809 case DW_AT_is_optional
:
5810 return "DW_AT_is_optional";
5811 case DW_AT_lower_bound
:
5812 return "DW_AT_lower_bound";
5813 case DW_AT_producer
:
5814 return "DW_AT_producer";
5815 case DW_AT_prototyped
:
5816 return "DW_AT_prototyped";
5817 case DW_AT_return_addr
:
5818 return "DW_AT_return_addr";
5819 case DW_AT_start_scope
:
5820 return "DW_AT_start_scope";
5821 case DW_AT_stride_size
:
5822 return "DW_AT_stride_size";
5823 case DW_AT_upper_bound
:
5824 return "DW_AT_upper_bound";
5825 case DW_AT_abstract_origin
:
5826 return "DW_AT_abstract_origin";
5827 case DW_AT_accessibility
:
5828 return "DW_AT_accessibility";
5829 case DW_AT_address_class
:
5830 return "DW_AT_address_class";
5831 case DW_AT_artificial
:
5832 return "DW_AT_artificial";
5833 case DW_AT_base_types
:
5834 return "DW_AT_base_types";
5835 case DW_AT_calling_convention
:
5836 return "DW_AT_calling_convention";
5838 return "DW_AT_count";
5839 case DW_AT_data_member_location
:
5840 return "DW_AT_data_member_location";
5841 case DW_AT_decl_column
:
5842 return "DW_AT_decl_column";
5843 case DW_AT_decl_file
:
5844 return "DW_AT_decl_file";
5845 case DW_AT_decl_line
:
5846 return "DW_AT_decl_line";
5847 case DW_AT_declaration
:
5848 return "DW_AT_declaration";
5849 case DW_AT_discr_list
:
5850 return "DW_AT_discr_list";
5851 case DW_AT_encoding
:
5852 return "DW_AT_encoding";
5853 case DW_AT_external
:
5854 return "DW_AT_external";
5855 case DW_AT_frame_base
:
5856 return "DW_AT_frame_base";
5858 return "DW_AT_friend";
5859 case DW_AT_identifier_case
:
5860 return "DW_AT_identifier_case";
5861 case DW_AT_macro_info
:
5862 return "DW_AT_macro_info";
5863 case DW_AT_namelist_items
:
5864 return "DW_AT_namelist_items";
5865 case DW_AT_priority
:
5866 return "DW_AT_priority";
5868 return "DW_AT_segment";
5869 case DW_AT_specification
:
5870 return "DW_AT_specification";
5871 case DW_AT_static_link
:
5872 return "DW_AT_static_link";
5874 return "DW_AT_type";
5875 case DW_AT_use_location
:
5876 return "DW_AT_use_location";
5877 case DW_AT_variable_parameter
:
5878 return "DW_AT_variable_parameter";
5879 case DW_AT_virtuality
:
5880 return "DW_AT_virtuality";
5881 case DW_AT_vtable_elem_location
:
5882 return "DW_AT_vtable_elem_location";
5883 case DW_AT_allocated
:
5884 return "DW_AT_allocated";
5885 case DW_AT_associated
:
5886 return "DW_AT_associated";
5887 case DW_AT_data_location
:
5888 return "DW_AT_data_location";
5890 return "DW_AT_stride";
5891 case DW_AT_entry_pc
:
5892 return "DW_AT_entry_pc";
5893 case DW_AT_use_UTF8
:
5894 return "DW_AT_use_UTF8";
5895 case DW_AT_extension
:
5896 return "DW_AT_extension";
5898 return "DW_AT_ranges";
5899 case DW_AT_trampoline
:
5900 return "DW_AT_trampoline";
5901 case DW_AT_call_column
:
5902 return "DW_AT_call_column";
5903 case DW_AT_call_file
:
5904 return "DW_AT_call_file";
5905 case DW_AT_call_line
:
5906 return "DW_AT_call_line";
5908 case DW_AT_MIPS_fde
:
5909 return "DW_AT_MIPS_fde";
5910 case DW_AT_MIPS_loop_begin
:
5911 return "DW_AT_MIPS_loop_begin";
5912 case DW_AT_MIPS_tail_loop_begin
:
5913 return "DW_AT_MIPS_tail_loop_begin";
5914 case DW_AT_MIPS_epilog_begin
:
5915 return "DW_AT_MIPS_epilog_begin";
5916 case DW_AT_MIPS_loop_unroll_factor
:
5917 return "DW_AT_MIPS_loop_unroll_factor";
5918 case DW_AT_MIPS_software_pipeline_depth
:
5919 return "DW_AT_MIPS_software_pipeline_depth";
5920 case DW_AT_MIPS_linkage_name
:
5921 return "DW_AT_MIPS_linkage_name";
5924 case DW_AT_sf_names
:
5925 return "DW_AT_sf_names";
5926 case DW_AT_src_info
:
5927 return "DW_AT_src_info";
5928 case DW_AT_mac_info
:
5929 return "DW_AT_mac_info";
5930 case DW_AT_src_coords
:
5931 return "DW_AT_src_coords";
5932 case DW_AT_body_begin
:
5933 return "DW_AT_body_begin";
5934 case DW_AT_body_end
:
5935 return "DW_AT_body_end";
5936 case DW_AT_GNU_vector
:
5937 return "DW_AT_GNU_vector";
5939 return "DW_AT_<unknown>";
5943 /* Convert a DWARF value form code into its string name. */
5946 dwarf_form_name (register unsigned form
)
5951 return "DW_FORM_addr";
5952 case DW_FORM_block2
:
5953 return "DW_FORM_block2";
5954 case DW_FORM_block4
:
5955 return "DW_FORM_block4";
5957 return "DW_FORM_data2";
5959 return "DW_FORM_data4";
5961 return "DW_FORM_data8";
5962 case DW_FORM_string
:
5963 return "DW_FORM_string";
5965 return "DW_FORM_block";
5966 case DW_FORM_block1
:
5967 return "DW_FORM_block1";
5969 return "DW_FORM_data1";
5971 return "DW_FORM_flag";
5973 return "DW_FORM_sdata";
5975 return "DW_FORM_strp";
5977 return "DW_FORM_udata";
5978 case DW_FORM_ref_addr
:
5979 return "DW_FORM_ref_addr";
5981 return "DW_FORM_ref1";
5983 return "DW_FORM_ref2";
5985 return "DW_FORM_ref4";
5987 return "DW_FORM_ref8";
5988 case DW_FORM_ref_udata
:
5989 return "DW_FORM_ref_udata";
5990 case DW_FORM_indirect
:
5991 return "DW_FORM_indirect";
5993 return "DW_FORM_<unknown>";
5997 /* Convert a DWARF stack opcode into its string name. */
6000 dwarf_stack_op_name (register unsigned op
)
6005 return "DW_OP_addr";
6007 return "DW_OP_deref";
6009 return "DW_OP_const1u";
6011 return "DW_OP_const1s";
6013 return "DW_OP_const2u";
6015 return "DW_OP_const2s";
6017 return "DW_OP_const4u";
6019 return "DW_OP_const4s";
6021 return "DW_OP_const8u";
6023 return "DW_OP_const8s";
6025 return "DW_OP_constu";
6027 return "DW_OP_consts";
6031 return "DW_OP_drop";
6033 return "DW_OP_over";
6035 return "DW_OP_pick";
6037 return "DW_OP_swap";
6041 return "DW_OP_xderef";
6049 return "DW_OP_minus";
6061 return "DW_OP_plus";
6062 case DW_OP_plus_uconst
:
6063 return "DW_OP_plus_uconst";
6069 return "DW_OP_shra";
6087 return "DW_OP_skip";
6089 return "DW_OP_lit0";
6091 return "DW_OP_lit1";
6093 return "DW_OP_lit2";
6095 return "DW_OP_lit3";
6097 return "DW_OP_lit4";
6099 return "DW_OP_lit5";
6101 return "DW_OP_lit6";
6103 return "DW_OP_lit7";
6105 return "DW_OP_lit8";
6107 return "DW_OP_lit9";
6109 return "DW_OP_lit10";
6111 return "DW_OP_lit11";
6113 return "DW_OP_lit12";
6115 return "DW_OP_lit13";
6117 return "DW_OP_lit14";
6119 return "DW_OP_lit15";
6121 return "DW_OP_lit16";
6123 return "DW_OP_lit17";
6125 return "DW_OP_lit18";
6127 return "DW_OP_lit19";
6129 return "DW_OP_lit20";
6131 return "DW_OP_lit21";
6133 return "DW_OP_lit22";
6135 return "DW_OP_lit23";
6137 return "DW_OP_lit24";
6139 return "DW_OP_lit25";
6141 return "DW_OP_lit26";
6143 return "DW_OP_lit27";
6145 return "DW_OP_lit28";
6147 return "DW_OP_lit29";
6149 return "DW_OP_lit30";
6151 return "DW_OP_lit31";
6153 return "DW_OP_reg0";
6155 return "DW_OP_reg1";
6157 return "DW_OP_reg2";
6159 return "DW_OP_reg3";
6161 return "DW_OP_reg4";
6163 return "DW_OP_reg5";
6165 return "DW_OP_reg6";
6167 return "DW_OP_reg7";
6169 return "DW_OP_reg8";
6171 return "DW_OP_reg9";
6173 return "DW_OP_reg10";
6175 return "DW_OP_reg11";
6177 return "DW_OP_reg12";
6179 return "DW_OP_reg13";
6181 return "DW_OP_reg14";
6183 return "DW_OP_reg15";
6185 return "DW_OP_reg16";
6187 return "DW_OP_reg17";
6189 return "DW_OP_reg18";
6191 return "DW_OP_reg19";
6193 return "DW_OP_reg20";
6195 return "DW_OP_reg21";
6197 return "DW_OP_reg22";
6199 return "DW_OP_reg23";
6201 return "DW_OP_reg24";
6203 return "DW_OP_reg25";
6205 return "DW_OP_reg26";
6207 return "DW_OP_reg27";
6209 return "DW_OP_reg28";
6211 return "DW_OP_reg29";
6213 return "DW_OP_reg30";
6215 return "DW_OP_reg31";
6217 return "DW_OP_breg0";
6219 return "DW_OP_breg1";
6221 return "DW_OP_breg2";
6223 return "DW_OP_breg3";
6225 return "DW_OP_breg4";
6227 return "DW_OP_breg5";
6229 return "DW_OP_breg6";
6231 return "DW_OP_breg7";
6233 return "DW_OP_breg8";
6235 return "DW_OP_breg9";
6237 return "DW_OP_breg10";
6239 return "DW_OP_breg11";
6241 return "DW_OP_breg12";
6243 return "DW_OP_breg13";
6245 return "DW_OP_breg14";
6247 return "DW_OP_breg15";
6249 return "DW_OP_breg16";
6251 return "DW_OP_breg17";
6253 return "DW_OP_breg18";
6255 return "DW_OP_breg19";
6257 return "DW_OP_breg20";
6259 return "DW_OP_breg21";
6261 return "DW_OP_breg22";
6263 return "DW_OP_breg23";
6265 return "DW_OP_breg24";
6267 return "DW_OP_breg25";
6269 return "DW_OP_breg26";
6271 return "DW_OP_breg27";
6273 return "DW_OP_breg28";
6275 return "DW_OP_breg29";
6277 return "DW_OP_breg30";
6279 return "DW_OP_breg31";
6281 return "DW_OP_regx";
6283 return "DW_OP_fbreg";
6285 return "DW_OP_bregx";
6287 return "DW_OP_piece";
6288 case DW_OP_deref_size
:
6289 return "DW_OP_deref_size";
6290 case DW_OP_xderef_size
:
6291 return "DW_OP_xderef_size";
6294 /* DWARF 3 extensions. */
6295 case DW_OP_push_object_address
:
6296 return "DW_OP_push_object_address";
6298 return "DW_OP_call2";
6300 return "DW_OP_call4";
6301 case DW_OP_call_ref
:
6302 return "DW_OP_call_ref";
6303 /* GNU extensions. */
6304 case DW_OP_GNU_push_tls_address
:
6305 return "DW_OP_GNU_push_tls_address";
6307 return "OP_<unknown>";
6312 dwarf_bool_name (unsigned mybool
)
6320 /* Convert a DWARF type code into its string name. */
6323 dwarf_type_encoding_name (register unsigned enc
)
6327 case DW_ATE_address
:
6328 return "DW_ATE_address";
6329 case DW_ATE_boolean
:
6330 return "DW_ATE_boolean";
6331 case DW_ATE_complex_float
:
6332 return "DW_ATE_complex_float";
6334 return "DW_ATE_float";
6336 return "DW_ATE_signed";
6337 case DW_ATE_signed_char
:
6338 return "DW_ATE_signed_char";
6339 case DW_ATE_unsigned
:
6340 return "DW_ATE_unsigned";
6341 case DW_ATE_unsigned_char
:
6342 return "DW_ATE_unsigned_char";
6343 case DW_ATE_imaginary_float
:
6344 return "DW_ATE_imaginary_float";
6346 return "DW_ATE_<unknown>";
6350 /* Convert a DWARF call frame info operation to its string name. */
6354 dwarf_cfi_name (register unsigned cfi_opc
)
6358 case DW_CFA_advance_loc
:
6359 return "DW_CFA_advance_loc";
6361 return "DW_CFA_offset";
6362 case DW_CFA_restore
:
6363 return "DW_CFA_restore";
6365 return "DW_CFA_nop";
6366 case DW_CFA_set_loc
:
6367 return "DW_CFA_set_loc";
6368 case DW_CFA_advance_loc1
:
6369 return "DW_CFA_advance_loc1";
6370 case DW_CFA_advance_loc2
:
6371 return "DW_CFA_advance_loc2";
6372 case DW_CFA_advance_loc4
:
6373 return "DW_CFA_advance_loc4";
6374 case DW_CFA_offset_extended
:
6375 return "DW_CFA_offset_extended";
6376 case DW_CFA_restore_extended
:
6377 return "DW_CFA_restore_extended";
6378 case DW_CFA_undefined
:
6379 return "DW_CFA_undefined";
6380 case DW_CFA_same_value
:
6381 return "DW_CFA_same_value";
6382 case DW_CFA_register
:
6383 return "DW_CFA_register";
6384 case DW_CFA_remember_state
:
6385 return "DW_CFA_remember_state";
6386 case DW_CFA_restore_state
:
6387 return "DW_CFA_restore_state";
6388 case DW_CFA_def_cfa
:
6389 return "DW_CFA_def_cfa";
6390 case DW_CFA_def_cfa_register
:
6391 return "DW_CFA_def_cfa_register";
6392 case DW_CFA_def_cfa_offset
:
6393 return "DW_CFA_def_cfa_offset";
6396 case DW_CFA_def_cfa_expression
:
6397 return "DW_CFA_def_cfa_expression";
6398 case DW_CFA_expression
:
6399 return "DW_CFA_expression";
6400 case DW_CFA_offset_extended_sf
:
6401 return "DW_CFA_offset_extended_sf";
6402 case DW_CFA_def_cfa_sf
:
6403 return "DW_CFA_def_cfa_sf";
6404 case DW_CFA_def_cfa_offset_sf
:
6405 return "DW_CFA_def_cfa_offset_sf";
6407 /* SGI/MIPS specific */
6408 case DW_CFA_MIPS_advance_loc8
:
6409 return "DW_CFA_MIPS_advance_loc8";
6411 /* GNU extensions */
6412 case DW_CFA_GNU_window_save
:
6413 return "DW_CFA_GNU_window_save";
6414 case DW_CFA_GNU_args_size
:
6415 return "DW_CFA_GNU_args_size";
6416 case DW_CFA_GNU_negative_offset_extended
:
6417 return "DW_CFA_GNU_negative_offset_extended";
6420 return "DW_CFA_<unknown>";
6426 dump_die (struct die_info
*die
)
6430 fprintf_unfiltered (gdb_stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
6431 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
6432 fprintf_unfiltered (gdb_stderr
, "\thas children: %s\n",
6433 dwarf_bool_name (die
->has_children
));
6435 fprintf_unfiltered (gdb_stderr
, "\tattributes:\n");
6436 for (i
= 0; i
< die
->num_attrs
; ++i
)
6438 fprintf_unfiltered (gdb_stderr
, "\t\t%s (%s) ",
6439 dwarf_attr_name (die
->attrs
[i
].name
),
6440 dwarf_form_name (die
->attrs
[i
].form
));
6441 switch (die
->attrs
[i
].form
)
6443 case DW_FORM_ref_addr
:
6445 fprintf_unfiltered (gdb_stderr
, "address: ");
6446 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
6448 case DW_FORM_block2
:
6449 case DW_FORM_block4
:
6451 case DW_FORM_block1
:
6452 fprintf_unfiltered (gdb_stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
6463 fprintf_unfiltered (gdb_stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
6465 case DW_FORM_string
:
6467 fprintf_unfiltered (gdb_stderr
, "string: \"%s\"",
6468 DW_STRING (&die
->attrs
[i
])
6469 ? DW_STRING (&die
->attrs
[i
]) : "");
6472 if (DW_UNSND (&die
->attrs
[i
]))
6473 fprintf_unfiltered (gdb_stderr
, "flag: TRUE");
6475 fprintf_unfiltered (gdb_stderr
, "flag: FALSE");
6477 case DW_FORM_indirect
:
6478 /* the reader will have reduced the indirect form to
6479 the "base form" so this form should not occur */
6480 fprintf_unfiltered (gdb_stderr
, "unexpected attribute form: DW_FORM_indirect");
6483 fprintf_unfiltered (gdb_stderr
, "unsupported attribute form: %d.",
6484 die
->attrs
[i
].form
);
6486 fprintf_unfiltered (gdb_stderr
, "\n");
6491 dump_die_list (struct die_info
*die
)
6501 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
6504 struct die_info
*old
;
6506 h
= (offset
% REF_HASH_SIZE
);
6507 old
= die_ref_table
[h
];
6508 die
->next_ref
= old
;
6509 die_ref_table
[h
] = die
;
6514 dwarf2_empty_hash_tables (void)
6516 memset (die_ref_table
, 0, sizeof (die_ref_table
));
6520 dwarf2_get_ref_die_offset (struct attribute
*attr
)
6522 unsigned int result
= 0;
6526 case DW_FORM_ref_addr
:
6527 result
= DW_ADDR (attr
);
6533 case DW_FORM_ref_udata
:
6534 result
= cu_header_offset
+ DW_UNSND (attr
);
6537 complaint (&symfile_complaints
,
6538 "unsupported die ref attribute form: '%s'",
6539 dwarf_form_name (attr
->form
));
6544 static struct die_info
*
6545 follow_die_ref (unsigned int offset
)
6547 struct die_info
*die
;
6550 h
= (offset
% REF_HASH_SIZE
);
6551 die
= die_ref_table
[h
];
6554 if (die
->offset
== offset
)
6558 die
= die
->next_ref
;
6563 static struct type
*
6564 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
6566 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
6568 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
6572 /* Look for this particular type in the fundamental type vector. If
6573 one is not found, create and install one appropriate for the
6574 current language and the current target machine. */
6576 if (ftypes
[typeid] == NULL
)
6578 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
6581 return (ftypes
[typeid]);
6584 /* Decode simple location descriptions.
6585 Given a pointer to a dwarf block that defines a location, compute
6586 the location and return the value.
6588 FIXME: This is a kludge until we figure out a better
6589 way to handle the location descriptions.
6590 Gdb's design does not mesh well with the DWARF2 notion of a location
6591 computing interpreter, which is a shame because the flexibility goes unused.
6592 FIXME: Implement more operations as necessary.
6594 A location description containing no operations indicates that the
6595 object is optimized out. The global optimized_out flag is set for
6596 those, the return value is meaningless.
6598 When the result is a register number, the global isreg flag is set,
6599 otherwise it is cleared.
6601 When the result is a base register offset, the global offreg flag is set
6602 and the register number is returned in basereg, otherwise it is cleared.
6604 When the DW_OP_fbreg operation is encountered without a corresponding
6605 DW_AT_frame_base attribute, the global islocal flag is set.
6606 Hopefully the machine dependent code knows how to set up a virtual
6607 frame pointer for the local references.
6609 Note that stack[0] is unused except as a default error return.
6610 Note that stack overflow is not yet handled. */
6613 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
6614 const struct comp_unit_head
*cu_header
)
6617 int size
= blk
->size
;
6618 char *data
= blk
->data
;
6619 CORE_ADDR stack
[64];
6621 unsigned int bytes_read
, unsnd
;
6631 is_thread_local
= 0;
6672 stack
[++stacki
] = op
- DW_OP_lit0
;
6708 stack
[++stacki
] = op
- DW_OP_reg0
;
6713 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6715 stack
[++stacki
] = unsnd
;
6751 basereg
= op
- DW_OP_breg0
;
6752 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6758 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6760 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6765 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6767 if (frame_base_reg
>= 0)
6770 basereg
= frame_base_reg
;
6771 stack
[stacki
] += frame_base_offset
;
6775 complaint (&symfile_complaints
,
6776 "DW_AT_frame_base missing for DW_OP_fbreg");
6782 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
6783 cu_header
, &bytes_read
);
6788 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
6793 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
6798 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
6803 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
6808 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
6813 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
6818 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
6824 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
6829 stack
[stacki
+ 1] = stack
[stacki
];
6834 stack
[stacki
- 1] += stack
[stacki
];
6838 case DW_OP_plus_uconst
:
6839 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
6844 stack
[stacki
- 1] -= stack
[stacki
];
6850 /* If we're not the last op, then we definitely can't encode
6851 this using GDB's address_class enum. */
6853 dwarf2_complex_location_expr_complaint ();
6856 case DW_OP_GNU_push_tls_address
:
6857 is_thread_local
= 1;
6858 /* The top of the stack has the offset from the beginning
6859 of the thread control block at which the variable is located. */
6860 /* Nothing should follow this operator, so the top of stack would
6863 dwarf2_complex_location_expr_complaint ();
6867 complaint (&symfile_complaints
, "unsupported stack op: '%s'",
6868 dwarf_stack_op_name (op
));
6869 return (stack
[stacki
]);
6872 return (stack
[stacki
]);
6875 /* memory allocation interface */
6879 dwarf2_free_tmp_obstack (void *ignore
)
6881 obstack_free (&dwarf2_tmp_obstack
, NULL
);
6884 static struct dwarf_block
*
6885 dwarf_alloc_block (void)
6887 struct dwarf_block
*blk
;
6889 blk
= (struct dwarf_block
*)
6890 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
6894 static struct abbrev_info
*
6895 dwarf_alloc_abbrev (void)
6897 struct abbrev_info
*abbrev
;
6899 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
6900 memset (abbrev
, 0, sizeof (struct abbrev_info
));
6904 static struct die_info
*
6905 dwarf_alloc_die (void)
6907 struct die_info
*die
;
6909 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
6910 memset (die
, 0, sizeof (struct die_info
));
6915 /* Macro support. */
6918 /* Return the full name of file number I in *LH's file name table.
6919 Use COMP_DIR as the name of the current directory of the
6920 compilation. The result is allocated using xmalloc; the caller is
6921 responsible for freeing it. */
6923 file_full_name (int file
, struct line_header
*lh
, const char *comp_dir
)
6925 struct file_entry
*fe
= &lh
->file_names
[file
- 1];
6927 if (IS_ABSOLUTE_PATH (fe
->name
))
6928 return xstrdup (fe
->name
);
6936 dir
= lh
->include_dirs
[fe
->dir_index
- 1];
6942 dir_len
= strlen (dir
);
6943 full_name
= xmalloc (dir_len
+ 1 + strlen (fe
->name
) + 1);
6944 strcpy (full_name
, dir
);
6945 full_name
[dir_len
] = '/';
6946 strcpy (full_name
+ dir_len
+ 1, fe
->name
);
6950 return xstrdup (fe
->name
);
6955 static struct macro_source_file
*
6956 macro_start_file (int file
, int line
,
6957 struct macro_source_file
*current_file
,
6958 const char *comp_dir
,
6959 struct line_header
*lh
, struct objfile
*objfile
)
6961 /* The full name of this source file. */
6962 char *full_name
= file_full_name (file
, lh
, comp_dir
);
6964 /* We don't create a macro table for this compilation unit
6965 at all until we actually get a filename. */
6966 if (! pending_macros
)
6967 pending_macros
= new_macro_table (&objfile
->symbol_obstack
,
6968 objfile
->macro_cache
);
6971 /* If we have no current file, then this must be the start_file
6972 directive for the compilation unit's main source file. */
6973 current_file
= macro_set_main (pending_macros
, full_name
);
6975 current_file
= macro_include (current_file
, line
, full_name
);
6979 return current_file
;
6983 /* Copy the LEN characters at BUF to a xmalloc'ed block of memory,
6984 followed by a null byte. */
6986 copy_string (const char *buf
, int len
)
6988 char *s
= xmalloc (len
+ 1);
6989 memcpy (s
, buf
, len
);
6997 consume_improper_spaces (const char *p
, const char *body
)
7001 complaint (&symfile_complaints
,
7002 "macro definition contains spaces in formal argument list:\n`%s'",
7014 parse_macro_definition (struct macro_source_file
*file
, int line
,
7019 /* The body string takes one of two forms. For object-like macro
7020 definitions, it should be:
7022 <macro name> " " <definition>
7024 For function-like macro definitions, it should be:
7026 <macro name> "() " <definition>
7028 <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition>
7030 Spaces may appear only where explicitly indicated, and in the
7033 The Dwarf 2 spec says that an object-like macro's name is always
7034 followed by a space, but versions of GCC around March 2002 omit
7035 the space when the macro's definition is the empty string.
7037 The Dwarf 2 spec says that there should be no spaces between the
7038 formal arguments in a function-like macro's formal argument list,
7039 but versions of GCC around March 2002 include spaces after the
7043 /* Find the extent of the macro name. The macro name is terminated
7044 by either a space or null character (for an object-like macro) or
7045 an opening paren (for a function-like macro). */
7046 for (p
= body
; *p
; p
++)
7047 if (*p
== ' ' || *p
== '(')
7050 if (*p
== ' ' || *p
== '\0')
7052 /* It's an object-like macro. */
7053 int name_len
= p
- body
;
7054 char *name
= copy_string (body
, name_len
);
7055 const char *replacement
;
7058 replacement
= body
+ name_len
+ 1;
7061 dwarf2_macro_malformed_definition_complaint (body
);
7062 replacement
= body
+ name_len
;
7065 macro_define_object (file
, line
, name
, replacement
);
7071 /* It's a function-like macro. */
7072 char *name
= copy_string (body
, p
- body
);
7075 char **argv
= xmalloc (argv_size
* sizeof (*argv
));
7079 p
= consume_improper_spaces (p
, body
);
7081 /* Parse the formal argument list. */
7082 while (*p
&& *p
!= ')')
7084 /* Find the extent of the current argument name. */
7085 const char *arg_start
= p
;
7087 while (*p
&& *p
!= ',' && *p
!= ')' && *p
!= ' ')
7090 if (! *p
|| p
== arg_start
)
7091 dwarf2_macro_malformed_definition_complaint (body
);
7094 /* Make sure argv has room for the new argument. */
7095 if (argc
>= argv_size
)
7098 argv
= xrealloc (argv
, argv_size
* sizeof (*argv
));
7101 argv
[argc
++] = copy_string (arg_start
, p
- arg_start
);
7104 p
= consume_improper_spaces (p
, body
);
7106 /* Consume the comma, if present. */
7111 p
= consume_improper_spaces (p
, body
);
7120 /* Perfectly formed definition, no complaints. */
7121 macro_define_function (file
, line
, name
,
7122 argc
, (const char **) argv
,
7124 else if (*p
== '\0')
7126 /* Complain, but do define it. */
7127 dwarf2_macro_malformed_definition_complaint (body
);
7128 macro_define_function (file
, line
, name
,
7129 argc
, (const char **) argv
,
7133 /* Just complain. */
7134 dwarf2_macro_malformed_definition_complaint (body
);
7137 /* Just complain. */
7138 dwarf2_macro_malformed_definition_complaint (body
);
7144 for (i
= 0; i
< argc
; i
++)
7150 dwarf2_macro_malformed_definition_complaint (body
);
7155 dwarf_decode_macros (struct line_header
*lh
, unsigned int offset
,
7156 char *comp_dir
, bfd
*abfd
,
7157 const struct comp_unit_head
*cu_header
,
7158 struct objfile
*objfile
)
7160 char *mac_ptr
, *mac_end
;
7161 struct macro_source_file
*current_file
= 0;
7163 if (dwarf_macinfo_buffer
== NULL
)
7165 complaint (&symfile_complaints
, "missing .debug_macinfo section");
7169 mac_ptr
= dwarf_macinfo_buffer
+ offset
;
7170 mac_end
= dwarf_macinfo_buffer
+ dwarf_macinfo_size
;
7174 enum dwarf_macinfo_record_type macinfo_type
;
7176 /* Do we at least have room for a macinfo type byte? */
7177 if (mac_ptr
>= mac_end
)
7179 dwarf2_macros_too_long_complaint ();
7183 macinfo_type
= read_1_byte (abfd
, mac_ptr
);
7186 switch (macinfo_type
)
7188 /* A zero macinfo type indicates the end of the macro
7193 case DW_MACINFO_define
:
7194 case DW_MACINFO_undef
:
7200 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7201 mac_ptr
+= bytes_read
;
7202 body
= read_string (abfd
, mac_ptr
, &bytes_read
);
7203 mac_ptr
+= bytes_read
;
7206 complaint (&symfile_complaints
,
7207 "debug info gives macro %s outside of any file: %s",
7209 DW_MACINFO_define
? "definition" : macinfo_type
==
7210 DW_MACINFO_undef
? "undefinition" :
7211 "something-or-other", body
);
7214 if (macinfo_type
== DW_MACINFO_define
)
7215 parse_macro_definition (current_file
, line
, body
);
7216 else if (macinfo_type
== DW_MACINFO_undef
)
7217 macro_undef (current_file
, line
, body
);
7222 case DW_MACINFO_start_file
:
7227 line
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7228 mac_ptr
+= bytes_read
;
7229 file
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7230 mac_ptr
+= bytes_read
;
7232 current_file
= macro_start_file (file
, line
,
7233 current_file
, comp_dir
,
7238 case DW_MACINFO_end_file
:
7240 complaint (&symfile_complaints
,
7241 "macro debug info has an unmatched `close_file' directive");
7244 current_file
= current_file
->included_by
;
7247 enum dwarf_macinfo_record_type next_type
;
7249 /* GCC circa March 2002 doesn't produce the zero
7250 type byte marking the end of the compilation
7251 unit. Complain if it's not there, but exit no
7254 /* Do we at least have room for a macinfo type byte? */
7255 if (mac_ptr
>= mac_end
)
7257 dwarf2_macros_too_long_complaint ();
7261 /* We don't increment mac_ptr here, so this is just
7263 next_type
= read_1_byte (abfd
, mac_ptr
);
7265 complaint (&symfile_complaints
,
7266 "no terminating 0-type entry for macros in `.debug_macinfo' section");
7273 case DW_MACINFO_vendor_ext
:
7279 constant
= read_unsigned_leb128 (abfd
, mac_ptr
, &bytes_read
);
7280 mac_ptr
+= bytes_read
;
7281 string
= read_string (abfd
, mac_ptr
, &bytes_read
);
7282 mac_ptr
+= bytes_read
;
7284 /* We don't recognize any vendor extensions. */
7291 /* Check if the attribute's form is a DW_FORM_block*
7292 if so return true else false. */
7294 attr_form_is_block (struct attribute
*attr
)
7296 return (attr
== NULL
? 0 :
7297 attr
->form
== DW_FORM_block1
7298 || attr
->form
== DW_FORM_block2
7299 || attr
->form
== DW_FORM_block4
7300 || attr
->form
== DW_FORM_block
);