1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
5 Inc. with support from Florida State University (under contract
6 with the Ada Joint Program Office), and Silicon Graphics, Inc.
7 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or (at
16 your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
40 #include "complaints.h"
43 #include "gdb_string.h"
44 #include <sys/types.h>
46 /* .debug_info header for a compilation unit
47 Because of alignment constraints, this structure has padding and cannot
48 be mapped directly onto the beginning of the .debug_info section. */
49 typedef struct comp_unit_header
51 unsigned int length
; /* length of the .debug_info
53 unsigned short version
; /* version number -- 2 for DWARF
55 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
56 unsigned char addr_size
; /* byte size of an address -- 4 */
59 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
61 /* .debug_pubnames header
62 Because of alignment constraints, this structure has padding and cannot
63 be mapped directly onto the beginning of the .debug_info section. */
64 typedef struct pubnames_header
66 unsigned int length
; /* length of the .debug_pubnames
68 unsigned char version
; /* version number -- 2 for DWARF
70 unsigned int info_offset
; /* offset into .debug_info section */
71 unsigned int info_size
; /* byte size of .debug_info section
75 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
77 /* .debug_pubnames header
78 Because of alignment constraints, this structure has padding and cannot
79 be mapped directly onto the beginning of the .debug_info section. */
80 typedef struct aranges_header
82 unsigned int length
; /* byte len of the .debug_aranges
84 unsigned short version
; /* version number -- 2 for DWARF
86 unsigned int info_offset
; /* offset into .debug_info section */
87 unsigned char addr_size
; /* byte size of an address */
88 unsigned char seg_size
; /* byte size of segment descriptor */
91 #define _ACTUAL_ARANGES_HEADER_SIZE 12
93 /* .debug_line statement program prologue
94 Because of alignment constraints, this structure has padding and cannot
95 be mapped directly onto the beginning of the .debug_info section. */
96 typedef struct statement_prologue
98 unsigned int total_length
; /* byte length of the statement
100 unsigned short version
; /* version number -- 2 for DWARF
102 unsigned int prologue_length
; /* # bytes between prologue &
104 unsigned char minimum_instruction_length
; /* byte size of
106 unsigned char default_is_stmt
; /* initial value of is_stmt
109 unsigned char line_range
;
110 unsigned char opcode_base
; /* number assigned to first special
112 unsigned char *standard_opcode_lengths
;
116 /* offsets and sizes of debugging sections */
118 static file_ptr dwarf_info_offset
;
119 static file_ptr dwarf_abbrev_offset
;
120 static file_ptr dwarf_line_offset
;
121 static file_ptr dwarf_pubnames_offset
;
122 static file_ptr dwarf_aranges_offset
;
123 static file_ptr dwarf_loc_offset
;
124 static file_ptr dwarf_macinfo_offset
;
125 static file_ptr dwarf_str_offset
;
127 static unsigned int dwarf_info_size
;
128 static unsigned int dwarf_abbrev_size
;
129 static unsigned int dwarf_line_size
;
130 static unsigned int dwarf_pubnames_size
;
131 static unsigned int dwarf_aranges_size
;
132 static unsigned int dwarf_loc_size
;
133 static unsigned int dwarf_macinfo_size
;
134 static unsigned int dwarf_str_size
;
136 /* names of the debugging sections */
138 #define INFO_SECTION ".debug_info"
139 #define ABBREV_SECTION ".debug_abbrev"
140 #define LINE_SECTION ".debug_line"
141 #define PUBNAMES_SECTION ".debug_pubnames"
142 #define ARANGES_SECTION ".debug_aranges"
143 #define LOC_SECTION ".debug_loc"
144 #define MACINFO_SECTION ".debug_macinfo"
145 #define STR_SECTION ".debug_str"
147 /* local data types */
149 /* The data in a compilation unit header looks like this. */
150 struct comp_unit_head
154 unsigned int abbrev_offset
;
155 unsigned char addr_size
;
158 /* The data in the .debug_line statement prologue looks like this. */
161 unsigned int total_length
;
162 unsigned short version
;
163 unsigned int prologue_length
;
164 unsigned char minimum_instruction_length
;
165 unsigned char default_is_stmt
;
167 unsigned char line_range
;
168 unsigned char opcode_base
;
169 unsigned char *standard_opcode_lengths
;
172 /* When we construct a partial symbol table entry we only
173 need this much information. */
174 struct partial_die_info
177 unsigned char has_children
;
178 unsigned char is_external
;
179 unsigned char is_declaration
;
180 unsigned char has_type
;
186 struct dwarf_block
*locdesc
;
187 unsigned int language
;
191 /* This data structure holds the information of an abbrev. */
194 unsigned int number
; /* number identifying abbrev */
195 enum dwarf_tag tag
; /* dwarf tag */
196 int has_children
; /* boolean */
197 unsigned int num_attrs
; /* number of attributes */
198 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
199 struct abbrev_info
*next
; /* next in chain */
204 enum dwarf_attribute name
;
205 enum dwarf_form form
;
208 /* This data structure holds a complete die structure. */
211 enum dwarf_tag tag
; /* Tag indicating type of die */
212 unsigned short has_children
; /* Does the die have children */
213 unsigned int abbrev
; /* Abbrev number */
214 unsigned int offset
; /* Offset in .debug_info section */
215 unsigned int num_attrs
; /* Number of attributes */
216 struct attribute
*attrs
; /* An array of attributes */
217 struct die_info
*next_ref
; /* Next die in ref hash table */
218 struct die_info
*next
; /* Next die in linked list */
219 struct type
*type
; /* Cached type information */
222 /* Attributes have a name and a value */
225 enum dwarf_attribute name
;
226 enum dwarf_form form
;
230 struct dwarf_block
*blk
;
238 /* Get at parts of an attribute structure */
240 #define DW_STRING(attr) ((attr)->u.str)
241 #define DW_UNSND(attr) ((attr)->u.unsnd)
242 #define DW_BLOCK(attr) ((attr)->u.blk)
243 #define DW_SND(attr) ((attr)->u.snd)
244 #define DW_ADDR(attr) ((attr)->u.addr)
246 /* Blocks are a bunch of untyped bytes. */
253 /* We only hold one compilation unit's abbrevs in
254 memory at any one time. */
255 #ifndef ABBREV_HASH_SIZE
256 #define ABBREV_HASH_SIZE 121
258 #ifndef ATTR_ALLOC_CHUNK
259 #define ATTR_ALLOC_CHUNK 4
262 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
264 /* A hash table of die offsets for following references. */
265 #ifndef REF_HASH_SIZE
266 #define REF_HASH_SIZE 1021
269 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
271 /* Obstack for allocating temporary storage used during symbol reading. */
272 static struct obstack dwarf2_tmp_obstack
;
274 /* Offset to the first byte of the current compilation unit header,
275 for resolving relative reference dies. */
276 static unsigned int cu_header_offset
;
278 /* Allocate fields for structs, unions and enums in this size. */
279 #ifndef DW_FIELD_ALLOC_CHUNK
280 #define DW_FIELD_ALLOC_CHUNK 4
283 /* The language we are debugging. */
284 static enum language cu_language
;
285 static const struct language_defn
*cu_language_defn
;
287 /* Actually data from the sections. */
288 static char *dwarf_info_buffer
;
289 static char *dwarf_abbrev_buffer
;
290 static char *dwarf_line_buffer
;
292 /* A zeroed version of a partial die for initialization purposes. */
293 static struct partial_die_info zeroed_partial_die
;
295 /* The generic symbol table building routines have separate lists for
296 file scope symbols and all all other scopes (local scopes). So
297 we need to select the right one to pass to add_symbol_to_list().
298 We do it by keeping a pointer to the correct list in list_in_scope.
300 FIXME: The original dwarf code just treated the file scope as the first
301 local scope, and all other local scopes as nested local scopes, and worked
302 fine. Check to see if we really need to distinguish these
304 static struct pending
**list_in_scope
= &file_symbols
;
306 /* FIXME: decode_locdesc sets these variables to describe the location
307 to the caller. These ought to be a structure or something. If
308 none of the flags are set, the object lives at the address returned
309 by decode_locdesc. */
311 static int optimized_out
; /* No ops in location in expression,
312 so object was optimized out. */
313 static int isreg
; /* Object lives in register.
314 decode_locdesc's return value is
315 the register number. */
316 static int offreg
; /* Object's address is the sum of the
317 register specified by basereg, plus
318 the offset returned. */
319 static int basereg
; /* See `offreg'. */
320 static int isderef
; /* Value described by flags above is
321 the address of a pointer to the object. */
322 static int islocal
; /* Variable is at the returned offset
323 from the frame start, but there's
324 no identified frame pointer for
325 this function, so we can't say
326 which register it's relative to;
329 /* DW_AT_frame_base values for the current function.
330 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
331 contains the register number for the frame register.
332 frame_base_offset is the offset from the frame register to the
333 virtual stack frame. */
334 static int frame_base_reg
;
335 static CORE_ADDR frame_base_offset
;
337 /* This value is added to each symbol value. FIXME: Generalize to
338 the section_offsets structure used by dbxread (once this is done,
339 pass the appropriate section number to end_symtab). */
340 static CORE_ADDR baseaddr
; /* Add to each symbol value */
342 /* We put a pointer to this structure in the read_symtab_private field
344 The complete dwarf information for an objfile is kept in the
345 psymbol_obstack, so that absolute die references can be handled.
346 Most of the information in this structure is related to an entire
347 object file and could be passed via the sym_private field of the objfile.
348 It is however conceivable that dwarf2 might not be the only type
349 of symbols read from an object file. */
353 /* Pointer to start of dwarf info buffer for the objfile. */
355 char *dwarf_info_buffer
;
357 /* Offset in dwarf_info_buffer for this compilation unit. */
359 unsigned long dwarf_info_offset
;
361 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
363 char *dwarf_abbrev_buffer
;
365 /* Size of dwarf abbreviation section for the objfile. */
367 unsigned int dwarf_abbrev_size
;
369 /* Pointer to start of dwarf line buffer for the objfile. */
371 char *dwarf_line_buffer
;
374 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
375 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
376 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
377 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
378 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
379 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
381 /* Maintain an array of referenced fundamental types for the current
382 compilation unit being read. For DWARF version 1, we have to construct
383 the fundamental types on the fly, since no information about the
384 fundamental types is supplied. Each such fundamental type is created by
385 calling a language dependent routine to create the type, and then a
386 pointer to that type is then placed in the array at the index specified
387 by it's FT_<TYPENAME> value. The array has a fixed size set by the
388 FT_NUM_MEMBERS compile time constant, which is the number of predefined
389 fundamental types gdb knows how to construct. */
390 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
392 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
393 but this would require a corresponding change in unpack_field_as_long
395 static int bits_per_byte
= 8;
397 /* The routines that read and process dies for a C struct or C++ class
398 pass lists of data member fields and lists of member function fields
399 in an instance of a field_info structure, as defined below. */
402 /* List of data member and baseclasses fields. */
405 struct nextfield
*next
;
412 /* Number of fields. */
415 /* Number of baseclasses. */
418 /* Set if the accesibility of one of the fields is not public. */
419 int non_public_fields
;
421 /* Member function fields array, entries are allocated in the order they
422 are encountered in the object file. */
425 struct nextfnfield
*next
;
426 struct fn_field fnfield
;
430 /* Member function fieldlist array, contains name of possibly overloaded
431 member function, number of overloaded member functions and a pointer
432 to the head of the member function field chain. */
437 struct nextfnfield
*head
;
441 /* Number of entries in the fnfieldlists array. */
445 /* FIXME: Kludge to mark a varargs function type for C++ member function
446 argument processing. */
447 #define TYPE_FLAG_VARARGS (1 << 10)
449 /* Dwarf2 has no clean way to discern C++ static and non-static member
450 functions. G++ helps GDB by marking the first parameter for non-static
451 member functions (which is the this pointer) as artificial.
452 We pass this information between dwarf2_add_member_fn and
453 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
454 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
456 /* Various complaints about symbol reading that don't abort the process */
458 static struct complaint dwarf2_const_ignored
=
460 "type qualifier 'const' ignored", 0, 0
462 static struct complaint dwarf2_volatile_ignored
=
464 "type qualifier 'volatile' ignored", 0, 0
466 static struct complaint dwarf2_non_const_array_bound_ignored
=
468 "non-constant array bounds form '%s' ignored", 0, 0
470 static struct complaint dwarf2_missing_line_number_section
=
472 "missing .debug_line section", 0, 0
474 static struct complaint dwarf2_mangled_line_number_section
=
476 "mangled .debug_line section", 0, 0
478 static struct complaint dwarf2_unsupported_die_ref_attr
=
480 "unsupported die ref attribute form: '%s'", 0, 0
482 static struct complaint dwarf2_unsupported_stack_op
=
484 "unsupported stack op: '%s'", 0, 0
486 static struct complaint dwarf2_complex_location_expr
=
488 "location expression too complex", 0, 0
490 static struct complaint dwarf2_unsupported_tag
=
492 "unsupported tag: '%s'", 0, 0
494 static struct complaint dwarf2_unsupported_at_encoding
=
496 "unsupported DW_AT_encoding: '%s'", 0, 0
498 static struct complaint dwarf2_unsupported_at_frame_base
=
500 "unsupported DW_AT_frame_base for function '%s'", 0, 0
502 static struct complaint dwarf2_unexpected_tag
=
504 "unexepected tag in read_type_die: '%s'", 0, 0
506 static struct complaint dwarf2_missing_at_frame_base
=
508 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
510 static struct complaint dwarf2_bad_static_member_name
=
512 "unrecognized static data member name '%s'", 0, 0
514 static struct complaint dwarf2_unsupported_accessibility
=
516 "unsupported accessibility %d", 0, 0
518 static struct complaint dwarf2_bad_member_name_complaint
=
520 "cannot extract member name from '%s'", 0, 0
522 static struct complaint dwarf2_missing_member_fn_type_complaint
=
524 "member function type missing for '%s'", 0, 0
526 static struct complaint dwarf2_vtbl_not_found_complaint
=
528 "virtual function table pointer not found when defining class '%s'", 0, 0
530 static struct complaint dwarf2_absolute_sibling_complaint
=
532 "ignoring absolute DW_AT_sibling", 0, 0
534 static struct complaint dwarf2_const_value_length_mismatch
=
536 "const value length mismatch for '%s', got %d, expected %d", 0, 0
538 static struct complaint dwarf2_unsupported_const_value_attr
=
540 "unsupported const value attribute form: '%s'", 0, 0
543 /* Remember the addr_size read from the dwarf.
544 If a target expects to link compilation units with differing address
545 sizes, gdb needs to be sure that the appropriate size is here for
546 whatever scope is currently getting read. */
547 static int address_size
;
549 /* Some elf32 object file formats while linked for a 32 bit address
550 space contain debug information that has assumed 64 bit
551 addresses. Eg 64 bit MIPS target produced by GCC/GAS/LD where the
552 symbol table contains 32bit address values while its .debug_info
553 section contains 64 bit address values.
554 ADDRESS_SIGNIFICANT_SIZE specifies the number significant bits in
555 the ADDRESS_SIZE bytes read from the file */
556 static int address_significant_size
;
558 /* Externals references. */
559 extern int info_verbose
; /* From main.c; nonzero => verbose */
561 /* local function prototypes */
563 static void dwarf2_locate_sections
PARAMS ((bfd
*, asection
*, PTR
));
566 static void dwarf2_build_psymtabs_easy
PARAMS ((struct objfile
*, int));
569 static void dwarf2_build_psymtabs_hard
PARAMS ((struct objfile
*, int));
571 static char *scan_partial_symbols
PARAMS ((char *, struct objfile
*,
572 CORE_ADDR
*, CORE_ADDR
*));
574 static void add_partial_symbol
PARAMS ((struct partial_die_info
*,
577 static void dwarf2_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
579 static void psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
581 static char *dwarf2_read_section
PARAMS ((struct objfile
*, file_ptr
,
584 static void dwarf2_read_abbrevs
PARAMS ((bfd
*, unsigned int));
586 static void dwarf2_empty_abbrev_table
PARAMS ((PTR
));
588 static struct abbrev_info
*dwarf2_lookup_abbrev
PARAMS ((unsigned int));
590 static char *read_partial_die
PARAMS ((struct partial_die_info
*,
591 bfd
*, char *, int *));
593 static char *read_full_die
PARAMS ((struct die_info
**, bfd
*, char *));
595 static char *read_attribute
PARAMS ((struct attribute
*, struct attr_abbrev
*,
598 static unsigned int read_1_byte
PARAMS ((bfd
*, char *));
600 static int read_1_signed_byte
PARAMS ((bfd
*, char *));
602 static unsigned int read_2_bytes
PARAMS ((bfd
*, char *));
604 static unsigned int read_4_bytes
PARAMS ((bfd
*, char *));
606 static unsigned int read_8_bytes
PARAMS ((bfd
*, char *));
608 static CORE_ADDR read_address
PARAMS ((bfd
*, char *));
610 static char *read_n_bytes
PARAMS ((bfd
*, char *, unsigned int));
612 static char *read_string
PARAMS ((bfd
*, char *, unsigned int *));
614 static unsigned int read_unsigned_leb128
PARAMS ((bfd
*, char *,
617 static int read_signed_leb128
PARAMS ((bfd
*, char *, unsigned int *));
619 static void set_cu_language
PARAMS ((unsigned int));
621 static struct attribute
*dwarf_attr
PARAMS ((struct die_info
*,
624 static int die_is_declaration (struct die_info
*);
626 static void dwarf_decode_lines
PARAMS ((unsigned int, char *, bfd
*));
628 static void dwarf2_start_subfile
PARAMS ((char *, char *));
630 static struct symbol
*new_symbol
PARAMS ((struct die_info
*, struct type
*,
633 static void dwarf2_const_value
PARAMS ((struct attribute
*, struct symbol
*,
636 static void dwarf2_const_value_data (struct attribute
*attr
,
640 static struct type
*die_type
PARAMS ((struct die_info
*, struct objfile
*));
642 static struct type
*die_containing_type
PARAMS ((struct die_info
*,
646 static struct type
*type_at_offset
PARAMS ((unsigned int, struct objfile
*));
649 static struct type
*tag_type_to_type
PARAMS ((struct die_info
*,
652 static void read_type_die
PARAMS ((struct die_info
*, struct objfile
*));
654 static void read_typedef
PARAMS ((struct die_info
*, struct objfile
*));
656 static void read_base_type
PARAMS ((struct die_info
*, struct objfile
*));
658 static void read_file_scope
PARAMS ((struct die_info
*, struct objfile
*));
660 static void read_func_scope
PARAMS ((struct die_info
*, struct objfile
*));
662 static void read_lexical_block_scope
PARAMS ((struct die_info
*,
665 static int dwarf2_get_pc_bounds
PARAMS ((struct die_info
*,
666 CORE_ADDR
*, CORE_ADDR
*,
669 static void dwarf2_add_field
PARAMS ((struct field_info
*, struct die_info
*,
672 static void dwarf2_attach_fields_to_type
PARAMS ((struct field_info
*,
676 static void dwarf2_add_member_fn
PARAMS ((struct field_info
*,
677 struct die_info
*, struct type
*,
678 struct objfile
* objfile
));
680 static void dwarf2_attach_fn_fields_to_type
PARAMS ((struct field_info
*,
684 static void read_structure_scope
PARAMS ((struct die_info
*, struct objfile
*));
686 static void read_common_block
PARAMS ((struct die_info
*, struct objfile
*));
688 static void read_enumeration
PARAMS ((struct die_info
*, struct objfile
*));
690 static struct type
*dwarf_base_type
PARAMS ((int, int, struct objfile
*));
692 static CORE_ADDR decode_locdesc
PARAMS ((struct dwarf_block
*,
695 static void read_array_type
PARAMS ((struct die_info
*, struct objfile
*));
697 static void read_tag_pointer_type
PARAMS ((struct die_info
*,
700 static void read_tag_ptr_to_member_type
PARAMS ((struct die_info
*,
703 static void read_tag_reference_type
PARAMS ((struct die_info
*,
706 static void read_tag_const_type
PARAMS ((struct die_info
*, struct objfile
*));
708 static void read_tag_volatile_type
PARAMS ((struct die_info
*,
711 static void read_tag_string_type
PARAMS ((struct die_info
*,
714 static void read_subroutine_type
PARAMS ((struct die_info
*,
717 struct die_info
*read_comp_unit
PARAMS ((char *, bfd
*));
719 static void free_die_list
PARAMS ((struct die_info
*));
721 static void process_die
PARAMS ((struct die_info
*, struct objfile
*));
723 static char *dwarf2_linkage_name
PARAMS ((struct die_info
*));
725 static char *dwarf_tag_name
PARAMS ((unsigned int));
727 static char *dwarf_attr_name
PARAMS ((unsigned int));
729 static char *dwarf_form_name
PARAMS ((unsigned int));
731 static char *dwarf_stack_op_name
PARAMS ((unsigned int));
733 static char *dwarf_bool_name
PARAMS ((unsigned int));
735 static char *dwarf_type_encoding_name
PARAMS ((unsigned int));
738 static char *dwarf_cfi_name
PARAMS ((unsigned int));
740 struct die_info
*copy_die
PARAMS ((struct die_info
*));
743 struct die_info
*sibling_die
PARAMS ((struct die_info
*));
745 void dump_die
PARAMS ((struct die_info
*));
747 void dump_die_list
PARAMS ((struct die_info
*));
749 void store_in_ref_table
PARAMS ((unsigned int, struct die_info
*));
751 static void dwarf2_empty_die_ref_table
PARAMS ((void));
753 static unsigned int dwarf2_get_ref_die_offset
PARAMS ((struct attribute
*));
755 struct die_info
*follow_die_ref
PARAMS ((unsigned int));
757 static struct type
*dwarf2_fundamental_type
PARAMS ((struct objfile
*, int));
759 /* memory allocation interface */
761 static void dwarf2_free_tmp_obstack
PARAMS ((PTR
));
763 static struct dwarf_block
*dwarf_alloc_block
PARAMS ((void));
765 static struct abbrev_info
*dwarf_alloc_abbrev
PARAMS ((void));
767 static struct die_info
*dwarf_alloc_die
PARAMS ((void));
769 /* Try to locate the sections we need for DWARF 2 debugging
770 information and return true if we have enough to do something. */
773 dwarf2_has_info (abfd
)
776 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
777 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
778 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
788 /* This function is mapped across the sections and remembers the
789 offset and size of each of the debugging sections we are interested
793 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
798 if (STREQ (sectp
->name
, INFO_SECTION
))
800 dwarf_info_offset
= sectp
->filepos
;
801 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
803 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
805 dwarf_abbrev_offset
= sectp
->filepos
;
806 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
808 else if (STREQ (sectp
->name
, LINE_SECTION
))
810 dwarf_line_offset
= sectp
->filepos
;
811 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
813 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
815 dwarf_pubnames_offset
= sectp
->filepos
;
816 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
818 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
820 dwarf_aranges_offset
= sectp
->filepos
;
821 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
823 else if (STREQ (sectp
->name
, LOC_SECTION
))
825 dwarf_loc_offset
= sectp
->filepos
;
826 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
828 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
830 dwarf_macinfo_offset
= sectp
->filepos
;
831 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
833 else if (STREQ (sectp
->name
, STR_SECTION
))
835 dwarf_str_offset
= sectp
->filepos
;
836 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
840 /* Build a partial symbol table. */
843 dwarf2_build_psymtabs (objfile
, mainline
)
844 struct objfile
*objfile
;
848 /* We definitely need the .debug_info and .debug_abbrev sections */
850 dwarf_info_buffer
= dwarf2_read_section (objfile
,
853 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
856 dwarf_line_buffer
= dwarf2_read_section (objfile
,
860 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
861 objfile
->static_psymbols
.size
== 0)
863 init_psymbol_list (objfile
, 1024);
867 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
869 /* Things are significantly easier if we have .debug_aranges and
870 .debug_pubnames sections */
872 dwarf2_build_psymtabs_easy (objfile
, mainline
);
876 /* only test this case for now */
878 /* In this case we have to work a bit harder */
879 dwarf2_build_psymtabs_hard (objfile
, mainline
);
884 /* Build the partial symbol table from the information in the
885 .debug_pubnames and .debug_aranges sections. */
888 dwarf2_build_psymtabs_easy (objfile
, mainline
)
889 struct objfile
*objfile
;
892 bfd
*abfd
= objfile
->obfd
;
893 char *aranges_buffer
, *pubnames_buffer
;
894 char *aranges_ptr
, *pubnames_ptr
;
895 unsigned int entry_length
, version
, info_offset
, info_size
;
897 pubnames_buffer
= dwarf2_read_section (objfile
,
898 dwarf_pubnames_offset
,
899 dwarf_pubnames_size
);
900 pubnames_ptr
= pubnames_buffer
;
901 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
903 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
905 version
= read_1_byte (abfd
, pubnames_ptr
);
907 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
909 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
913 aranges_buffer
= dwarf2_read_section (objfile
,
914 dwarf_aranges_offset
,
920 /* Build the partial symbol table by doing a quick pass through the
921 .debug_info and .debug_abbrev sections. */
924 dwarf2_build_psymtabs_hard (objfile
, mainline
)
925 struct objfile
*objfile
;
928 /* Instead of reading this into a big buffer, we should probably use
929 mmap() on architectures that support it. (FIXME) */
930 bfd
*abfd
= objfile
->obfd
;
931 char *info_ptr
, *abbrev_ptr
;
932 char *beg_of_comp_unit
;
933 struct comp_unit_head cu_header
;
934 struct partial_die_info comp_unit_die
;
935 struct partial_symtab
*pst
;
936 struct cleanup
*back_to
;
937 int comp_unit_has_pc_info
;
938 CORE_ADDR lowpc
, highpc
;
940 /* Number of bytes of any addresses that are signficant */
941 address_significant_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
943 info_ptr
= dwarf_info_buffer
;
944 abbrev_ptr
= dwarf_abbrev_buffer
;
946 obstack_init (&dwarf2_tmp_obstack
);
947 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
949 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
950 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
952 beg_of_comp_unit
= info_ptr
;
953 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
955 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
957 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
959 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
961 address_size
= cu_header
.addr_size
;
963 if (cu_header
.version
!= 2)
965 error ("Dwarf Error: wrong version in compilation unit header.");
968 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
970 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
971 (long) cu_header
.abbrev_offset
,
972 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
975 if (beg_of_comp_unit
+ cu_header
.length
+ 4
976 > dwarf_info_buffer
+ dwarf_info_size
)
978 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
979 (long) cu_header
.length
,
980 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
983 if (address_size
< address_significant_size
)
985 error ("Dwarf Error: bad address size (%ld) in compilation unit header (offset 0x%lx + 11).",
986 (long) cu_header
.addr_size
,
987 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
990 /* Read the abbrevs for this compilation unit into a table */
991 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
992 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
994 /* Read the compilation unit die */
995 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
996 info_ptr
, &comp_unit_has_pc_info
);
998 /* Set the language we're debugging */
999 set_cu_language (comp_unit_die
.language
);
1001 /* Allocate a new partial symbol table structure */
1002 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1003 comp_unit_die
.name
? comp_unit_die
.name
: "",
1004 comp_unit_die
.lowpc
,
1005 objfile
->global_psymbols
.next
,
1006 objfile
->static_psymbols
.next
);
1008 pst
->read_symtab_private
= (char *)
1009 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1010 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1011 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1012 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1013 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1014 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1015 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1016 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
1018 /* Store the function that reads in the rest of the symbol table */
1019 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1021 /* Check if comp unit has_children.
1022 If so, read the rest of the partial symbols from this comp unit.
1023 If not, there's no more debug_info for this comp unit. */
1024 if (comp_unit_die
.has_children
)
1026 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
1028 /* If the compilation unit didn't have an explicit address range,
1029 then use the information extracted from its child dies. */
1030 if (!comp_unit_has_pc_info
)
1032 comp_unit_die
.lowpc
= lowpc
;
1033 comp_unit_die
.highpc
= highpc
;
1036 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1037 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1039 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1040 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1041 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1042 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1043 sort_pst_symbols (pst
);
1045 /* If there is already a psymtab or symtab for a file of this
1046 name, remove it. (If there is a symtab, more drastic things
1047 also happen.) This happens in VxWorks. */
1048 free_named_symtabs (pst
->filename
);
1050 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1052 do_cleanups (back_to
);
1055 /* Read in all interesting dies to the end of the compilation unit. */
1058 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1060 struct objfile
*objfile
;
1064 bfd
*abfd
= objfile
->obfd
;
1065 struct partial_die_info pdi
;
1067 /* This function is called after we've read in the comp_unit_die in
1068 order to read its children. We start the nesting level at 1 since
1069 we have pushed 1 level down in order to read the comp unit's children.
1070 The comp unit itself is at level 0, so we stop reading when we pop
1071 back to that level. */
1073 int nesting_level
= 1;
1076 *lowpc
= ((CORE_ADDR
) -1);
1077 *highpc
= ((CORE_ADDR
) 0);
1079 while (nesting_level
)
1081 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1087 case DW_TAG_subprogram
:
1090 if (pdi
.lowpc
< *lowpc
)
1094 if (pdi
.highpc
> *highpc
)
1096 *highpc
= pdi
.highpc
;
1098 if ((pdi
.is_external
|| nesting_level
== 1)
1099 && !pdi
.is_declaration
)
1101 add_partial_symbol (&pdi
, objfile
);
1105 case DW_TAG_variable
:
1106 case DW_TAG_typedef
:
1107 case DW_TAG_class_type
:
1108 case DW_TAG_structure_type
:
1109 case DW_TAG_union_type
:
1110 case DW_TAG_enumeration_type
:
1111 if ((pdi
.is_external
|| nesting_level
== 1)
1112 && !pdi
.is_declaration
)
1114 add_partial_symbol (&pdi
, objfile
);
1117 case DW_TAG_enumerator
:
1118 /* File scope enumerators are added to the partial symbol
1120 if (nesting_level
== 2)
1121 add_partial_symbol (&pdi
, objfile
);
1123 case DW_TAG_base_type
:
1124 /* File scope base type definitions are added to the partial
1126 if (nesting_level
== 1)
1127 add_partial_symbol (&pdi
, objfile
);
1134 /* If the die has a sibling, skip to the sibling.
1135 Do not skip enumeration types, we want to record their
1137 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1139 info_ptr
= pdi
.sibling
;
1141 else if (pdi
.has_children
)
1143 /* Die has children, but the optional DW_AT_sibling attribute
1154 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1155 from `maint check'. */
1156 if (*lowpc
== ((CORE_ADDR
) -1))
1162 add_partial_symbol (pdi
, objfile
)
1163 struct partial_die_info
*pdi
;
1164 struct objfile
*objfile
;
1170 case DW_TAG_subprogram
:
1171 if (pdi
->is_external
)
1173 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1174 mst_text, objfile); */
1175 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1176 VAR_NAMESPACE
, LOC_BLOCK
,
1177 &objfile
->global_psymbols
,
1178 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1182 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1183 mst_file_text, objfile); */
1184 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1185 VAR_NAMESPACE
, LOC_BLOCK
,
1186 &objfile
->static_psymbols
,
1187 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1190 case DW_TAG_variable
:
1191 if (pdi
->is_external
)
1194 Don't enter into the minimal symbol tables as there is
1195 a minimal symbol table entry from the ELF symbols already.
1196 Enter into partial symbol table if it has a location
1197 descriptor or a type.
1198 If the location descriptor is missing, new_symbol will create
1199 a LOC_UNRESOLVED symbol, the address of the variable will then
1200 be determined from the minimal symbol table whenever the variable
1202 The address for the partial symbol table entry is not
1203 used by GDB, but it comes in handy for debugging partial symbol
1207 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1208 if (pdi
->locdesc
|| pdi
->has_type
)
1209 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1210 VAR_NAMESPACE
, LOC_STATIC
,
1211 &objfile
->global_psymbols
,
1212 0, addr
+ baseaddr
, cu_language
, objfile
);
1216 /* Static Variable. Skip symbols without location descriptors. */
1217 if (pdi
->locdesc
== NULL
)
1219 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1220 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1221 mst_file_data, objfile); */
1222 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1223 VAR_NAMESPACE
, LOC_STATIC
,
1224 &objfile
->static_psymbols
,
1225 0, addr
+ baseaddr
, cu_language
, objfile
);
1228 case DW_TAG_typedef
:
1229 case DW_TAG_base_type
:
1230 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1231 VAR_NAMESPACE
, LOC_TYPEDEF
,
1232 &objfile
->static_psymbols
,
1233 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1235 case DW_TAG_class_type
:
1236 case DW_TAG_structure_type
:
1237 case DW_TAG_union_type
:
1238 case DW_TAG_enumeration_type
:
1239 /* Skip aggregate types without children, these are external
1241 if (pdi
->has_children
== 0)
1243 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1244 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1245 &objfile
->static_psymbols
,
1246 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1248 if (cu_language
== language_cplus
)
1250 /* For C++, these implicitly act as typedefs as well. */
1251 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1252 VAR_NAMESPACE
, LOC_TYPEDEF
,
1253 &objfile
->static_psymbols
,
1254 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1257 case DW_TAG_enumerator
:
1258 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1259 VAR_NAMESPACE
, LOC_CONST
,
1260 &objfile
->static_psymbols
,
1261 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1268 /* Expand this partial symbol table into a full symbol table. */
1271 dwarf2_psymtab_to_symtab (pst
)
1272 struct partial_symtab
*pst
;
1274 /* FIXME: This is barely more than a stub. */
1279 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1285 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1286 gdb_flush (gdb_stdout
);
1289 psymtab_to_symtab_1 (pst
);
1291 /* Finish up the debug error message. */
1293 printf_filtered ("done.\n");
1299 psymtab_to_symtab_1 (pst
)
1300 struct partial_symtab
*pst
;
1302 struct objfile
*objfile
= pst
->objfile
;
1303 bfd
*abfd
= objfile
->obfd
;
1304 struct comp_unit_head cu_header
;
1305 struct die_info
*dies
;
1306 unsigned long offset
;
1307 CORE_ADDR lowpc
, highpc
;
1308 struct die_info
*child_die
;
1310 struct symtab
*symtab
;
1311 struct cleanup
*back_to
;
1313 /* Set local variables from the partial symbol table info. */
1314 offset
= DWARF_INFO_OFFSET (pst
);
1315 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1316 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1317 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1318 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1319 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1320 cu_header_offset
= offset
;
1321 info_ptr
= dwarf_info_buffer
+ offset
;
1323 obstack_init (&dwarf2_tmp_obstack
);
1324 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1327 make_cleanup (really_free_pendings
, NULL
);
1329 /* read in the comp_unit header */
1330 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1332 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1334 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1336 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1339 /* Read the abbrevs for this compilation unit */
1340 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1341 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1343 dies
= read_comp_unit (info_ptr
, abfd
);
1345 make_cleanup ((make_cleanup_func
) free_die_list
, dies
);
1347 /* Do line number decoding in read_file_scope () */
1348 process_die (dies
, objfile
);
1350 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1352 /* Some compilers don't define a DW_AT_high_pc attribute for
1353 the compilation unit. If the DW_AT_high_pc is missing,
1354 synthesize it, by scanning the DIE's below the compilation unit. */
1356 if (dies
->has_children
)
1358 child_die
= dies
->next
;
1359 while (child_die
&& child_die
->tag
)
1361 if (child_die
->tag
== DW_TAG_subprogram
)
1363 CORE_ADDR low
, high
;
1365 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1367 highpc
= max (highpc
, high
);
1370 child_die
= sibling_die (child_die
);
1374 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1376 /* Set symtab language to language from DW_AT_language.
1377 If the compilation is from a C file generated by language preprocessors,
1378 do not set the language if it was already deduced by start_subfile. */
1380 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1382 symtab
->language
= cu_language
;
1384 pst
->symtab
= symtab
;
1386 sort_symtab_syms (pst
->symtab
);
1388 do_cleanups (back_to
);
1391 /* Process a die and its children. */
1394 process_die (die
, objfile
)
1395 struct die_info
*die
;
1396 struct objfile
*objfile
;
1400 case DW_TAG_padding
:
1402 case DW_TAG_compile_unit
:
1403 read_file_scope (die
, objfile
);
1405 case DW_TAG_subprogram
:
1406 read_subroutine_type (die
, objfile
);
1407 read_func_scope (die
, objfile
);
1409 case DW_TAG_inlined_subroutine
:
1410 /* FIXME: These are ignored for now.
1411 They could be used to set breakpoints on all inlined instances
1412 of a function and make GDB `next' properly over inlined functions. */
1414 case DW_TAG_lexical_block
:
1415 read_lexical_block_scope (die
, objfile
);
1417 case DW_TAG_class_type
:
1418 case DW_TAG_structure_type
:
1419 case DW_TAG_union_type
:
1420 read_structure_scope (die
, objfile
);
1422 case DW_TAG_enumeration_type
:
1423 read_enumeration (die
, objfile
);
1425 case DW_TAG_subroutine_type
:
1426 read_subroutine_type (die
, objfile
);
1428 case DW_TAG_array_type
:
1429 read_array_type (die
, objfile
);
1431 case DW_TAG_pointer_type
:
1432 read_tag_pointer_type (die
, objfile
);
1434 case DW_TAG_ptr_to_member_type
:
1435 read_tag_ptr_to_member_type (die
, objfile
);
1437 case DW_TAG_reference_type
:
1438 read_tag_reference_type (die
, objfile
);
1440 case DW_TAG_string_type
:
1441 read_tag_string_type (die
, objfile
);
1443 case DW_TAG_base_type
:
1444 read_base_type (die
, objfile
);
1445 if (dwarf_attr (die
, DW_AT_name
))
1447 /* Add a typedef symbol for the base type definition. */
1448 new_symbol (die
, die
->type
, objfile
);
1451 case DW_TAG_common_block
:
1452 read_common_block (die
, objfile
);
1454 case DW_TAG_common_inclusion
:
1457 new_symbol (die
, NULL
, objfile
);
1463 read_file_scope (die
, objfile
)
1464 struct die_info
*die
;
1465 struct objfile
*objfile
;
1467 unsigned int line_offset
= 0;
1468 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1469 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1470 struct attribute
*attr
;
1471 char *name
= "<unknown>";
1472 char *comp_dir
= NULL
;
1473 struct die_info
*child_die
;
1474 bfd
*abfd
= objfile
->obfd
;
1476 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1478 if (die
->has_children
)
1480 child_die
= die
->next
;
1481 while (child_die
&& child_die
->tag
)
1483 if (child_die
->tag
== DW_TAG_subprogram
)
1485 CORE_ADDR low
, high
;
1487 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1489 lowpc
= min (lowpc
, low
);
1490 highpc
= max (highpc
, high
);
1493 child_die
= sibling_die (child_die
);
1498 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1499 from finish_block. */
1500 if (lowpc
== ((CORE_ADDR
) -1))
1505 attr
= dwarf_attr (die
, DW_AT_name
);
1508 name
= DW_STRING (attr
);
1510 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1513 comp_dir
= DW_STRING (attr
);
1516 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1517 directory, get rid of it. */
1518 char *cp
= strchr (comp_dir
, ':');
1520 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1525 if (objfile
->ei
.entry_point
>= lowpc
&&
1526 objfile
->ei
.entry_point
< highpc
)
1528 objfile
->ei
.entry_file_lowpc
= lowpc
;
1529 objfile
->ei
.entry_file_highpc
= highpc
;
1532 attr
= dwarf_attr (die
, DW_AT_language
);
1535 set_cu_language (DW_UNSND (attr
));
1538 /* We assume that we're processing GCC output. */
1539 processing_gcc_compilation
= 2;
1541 /* FIXME:Do something here. */
1542 if (dip
->at_producer
!= NULL
)
1544 handle_producer (dip
->at_producer
);
1548 /* The compilation unit may be in a different language or objfile,
1549 zero out all remembered fundamental types. */
1550 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1552 start_symtab (name
, comp_dir
, lowpc
);
1553 record_debugformat ("DWARF 2");
1555 /* Decode line number information if present. */
1556 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1559 line_offset
= DW_UNSND (attr
);
1560 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1563 /* Process all dies in compilation unit. */
1564 if (die
->has_children
)
1566 child_die
= die
->next
;
1567 while (child_die
&& child_die
->tag
)
1569 process_die (child_die
, objfile
);
1570 child_die
= sibling_die (child_die
);
1576 read_func_scope (die
, objfile
)
1577 struct die_info
*die
;
1578 struct objfile
*objfile
;
1580 register struct context_stack
*new;
1583 struct die_info
*child_die
;
1584 struct attribute
*attr
;
1587 name
= dwarf2_linkage_name (die
);
1589 /* Ignore functions with missing or empty names and functions with
1590 missing or invalid low and high pc attributes. */
1591 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1597 if (objfile
->ei
.entry_point
>= lowpc
&&
1598 objfile
->ei
.entry_point
< highpc
)
1600 objfile
->ei
.entry_func_lowpc
= lowpc
;
1601 objfile
->ei
.entry_func_highpc
= highpc
;
1604 /* Decode DW_AT_frame_base location descriptor if present, keep result
1605 for DW_OP_fbreg operands in decode_locdesc. */
1606 frame_base_reg
= -1;
1607 frame_base_offset
= 0;
1608 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1611 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1613 complain (&dwarf2_unsupported_at_frame_base
, name
);
1615 frame_base_reg
= addr
;
1618 frame_base_reg
= basereg
;
1619 frame_base_offset
= addr
;
1622 complain (&dwarf2_unsupported_at_frame_base
, name
);
1625 new = push_context (0, lowpc
);
1626 new->name
= new_symbol (die
, die
->type
, objfile
);
1627 list_in_scope
= &local_symbols
;
1629 if (die
->has_children
)
1631 child_die
= die
->next
;
1632 while (child_die
&& child_die
->tag
)
1634 process_die (child_die
, objfile
);
1635 child_die
= sibling_die (child_die
);
1639 new = pop_context ();
1640 /* Make a block for the local symbols within. */
1641 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1642 lowpc
, highpc
, objfile
);
1643 list_in_scope
= &file_symbols
;
1646 /* Process all the DIES contained within a lexical block scope. Start
1647 a new scope, process the dies, and then close the scope. */
1650 read_lexical_block_scope (die
, objfile
)
1651 struct die_info
*die
;
1652 struct objfile
*objfile
;
1654 register struct context_stack
*new;
1655 CORE_ADDR lowpc
, highpc
;
1656 struct die_info
*child_die
;
1658 /* Ignore blocks with missing or invalid low and high pc attributes. */
1659 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1664 push_context (0, lowpc
);
1665 if (die
->has_children
)
1667 child_die
= die
->next
;
1668 while (child_die
&& child_die
->tag
)
1670 process_die (child_die
, objfile
);
1671 child_die
= sibling_die (child_die
);
1674 new = pop_context ();
1676 if (local_symbols
!= NULL
)
1678 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1681 local_symbols
= new->locals
;
1684 /* Get low and high pc attributes from a die.
1685 Return 1 if the attributes are present and valid, otherwise, return 0. */
1688 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1689 struct die_info
*die
;
1692 struct objfile
*objfile
;
1694 struct attribute
*attr
;
1698 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1700 low
= DW_ADDR (attr
);
1703 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1705 high
= DW_ADDR (attr
);
1712 /* When using the GNU linker, .gnu.linkonce. sections are used to
1713 eliminate duplicate copies of functions and vtables and such.
1714 The linker will arbitrarily choose one and discard the others.
1715 The AT_*_pc values for such functions refer to local labels in
1716 these sections. If the section from that file was discarded, the
1717 labels are not in the output, so the relocs get a value of 0.
1718 If this is a discarded function, mark the pc bounds as invalid,
1719 so that GDB will ignore it. */
1720 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1728 /* Add an aggregate field to the field list. */
1731 dwarf2_add_field (fip
, die
, objfile
)
1732 struct field_info
*fip
;
1733 struct die_info
*die
;
1734 struct objfile
*objfile
;
1736 struct nextfield
*new_field
;
1737 struct attribute
*attr
;
1739 char *fieldname
= "";
1741 /* Allocate a new field list entry and link it in. */
1742 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1743 make_cleanup (free
, new_field
);
1744 memset (new_field
, 0, sizeof (struct nextfield
));
1745 new_field
->next
= fip
->fields
;
1746 fip
->fields
= new_field
;
1749 /* Handle accessibility and virtuality of field.
1750 The default accessibility for members is public, the default
1751 accessibility for inheritance is private. */
1752 if (die
->tag
!= DW_TAG_inheritance
)
1753 new_field
->accessibility
= DW_ACCESS_public
;
1755 new_field
->accessibility
= DW_ACCESS_private
;
1756 new_field
->virtuality
= DW_VIRTUALITY_none
;
1758 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1760 new_field
->accessibility
= DW_UNSND (attr
);
1761 if (new_field
->accessibility
!= DW_ACCESS_public
)
1762 fip
->non_public_fields
= 1;
1763 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1765 new_field
->virtuality
= DW_UNSND (attr
);
1767 fp
= &new_field
->field
;
1768 if (die
->tag
== DW_TAG_member
)
1770 /* Get type of field. */
1771 fp
->type
= die_type (die
, objfile
);
1773 /* Get bit size of field (zero if none). */
1774 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1777 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1781 FIELD_BITSIZE (*fp
) = 0;
1784 /* Get bit offset of field. */
1785 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1788 FIELD_BITPOS (*fp
) =
1789 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1792 FIELD_BITPOS (*fp
) = 0;
1793 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1796 if (BITS_BIG_ENDIAN
)
1798 /* For big endian bits, the DW_AT_bit_offset gives the
1799 additional bit offset from the MSB of the containing
1800 anonymous object to the MSB of the field. We don't
1801 have to do anything special since we don't need to
1802 know the size of the anonymous object. */
1803 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1807 /* For little endian bits, compute the bit offset to the
1808 MSB of the anonymous object, subtract off the number of
1809 bits from the MSB of the field to the MSB of the
1810 object, and then subtract off the number of bits of
1811 the field itself. The result is the bit offset of
1812 the LSB of the field. */
1814 int bit_offset
= DW_UNSND (attr
);
1816 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1819 /* The size of the anonymous object containing
1820 the bit field is explicit, so use the
1821 indicated size (in bytes). */
1822 anonymous_size
= DW_UNSND (attr
);
1826 /* The size of the anonymous object containing
1827 the bit field must be inferred from the type
1828 attribute of the data member containing the
1830 anonymous_size
= TYPE_LENGTH (fp
->type
);
1832 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1833 - bit_offset
- FIELD_BITSIZE (*fp
);
1837 /* Get name of field. */
1838 attr
= dwarf_attr (die
, DW_AT_name
);
1839 if (attr
&& DW_STRING (attr
))
1840 fieldname
= DW_STRING (attr
);
1841 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1842 &objfile
->type_obstack
);
1844 /* Change accessibility for artificial fields (e.g. virtual table
1845 pointer or virtual base class pointer) to private. */
1846 if (dwarf_attr (die
, DW_AT_artificial
))
1848 new_field
->accessibility
= DW_ACCESS_private
;
1849 fip
->non_public_fields
= 1;
1852 else if (die
->tag
== DW_TAG_variable
)
1856 /* C++ static member.
1857 Get name of field. */
1858 attr
= dwarf_attr (die
, DW_AT_name
);
1859 if (attr
&& DW_STRING (attr
))
1860 fieldname
= DW_STRING (attr
);
1864 /* Get physical name. */
1865 physname
= dwarf2_linkage_name (die
);
1867 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1868 &objfile
->type_obstack
));
1869 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1870 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1871 &objfile
->type_obstack
);
1873 else if (die
->tag
== DW_TAG_inheritance
)
1875 /* C++ base class field. */
1876 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1878 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1879 FIELD_BITSIZE (*fp
) = 0;
1880 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1881 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1882 fip
->nbaseclasses
++;
1886 /* Create the vector of fields, and attach it to the type. */
1889 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1890 struct field_info
*fip
;
1892 struct objfile
*objfile
;
1894 int nfields
= fip
->nfields
;
1896 /* Record the field count, allocate space for the array of fields,
1897 and create blank accessibility bitfields if necessary. */
1898 TYPE_NFIELDS (type
) = nfields
;
1899 TYPE_FIELDS (type
) = (struct field
*)
1900 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1901 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1903 if (fip
->non_public_fields
)
1905 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1907 TYPE_FIELD_PRIVATE_BITS (type
) =
1908 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1909 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1911 TYPE_FIELD_PROTECTED_BITS (type
) =
1912 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1913 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1915 TYPE_FIELD_IGNORE_BITS (type
) =
1916 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1917 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1920 /* If the type has baseclasses, allocate and clear a bit vector for
1921 TYPE_FIELD_VIRTUAL_BITS. */
1922 if (fip
->nbaseclasses
)
1924 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1927 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1928 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1929 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1930 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1931 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1934 /* Copy the saved-up fields into the field vector. Start from the head
1935 of the list, adding to the tail of the field array, so that they end
1936 up in the same order in the array in which they were added to the list. */
1937 while (nfields
-- > 0)
1939 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1940 switch (fip
->fields
->accessibility
)
1942 case DW_ACCESS_private
:
1943 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1946 case DW_ACCESS_protected
:
1947 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1950 case DW_ACCESS_public
:
1954 /* Unknown accessibility. Complain and treat it as public. */
1956 complain (&dwarf2_unsupported_accessibility
,
1957 fip
->fields
->accessibility
);
1961 if (nfields
< fip
->nbaseclasses
)
1963 switch (fip
->fields
->virtuality
)
1965 case DW_VIRTUALITY_virtual
:
1966 case DW_VIRTUALITY_pure_virtual
:
1967 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1971 fip
->fields
= fip
->fields
->next
;
1975 /* Add a member function to the proper fieldlist. */
1978 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
1979 struct field_info
*fip
;
1980 struct die_info
*die
;
1982 struct objfile
*objfile
;
1984 struct attribute
*attr
;
1985 struct fnfieldlist
*flp
;
1987 struct fn_field
*fnp
;
1990 struct nextfnfield
*new_fnfield
;
1992 /* Get name of member function. */
1993 attr
= dwarf_attr (die
, DW_AT_name
);
1994 if (attr
&& DW_STRING (attr
))
1995 fieldname
= DW_STRING (attr
);
1999 /* Get the mangled name. */
2000 physname
= dwarf2_linkage_name (die
);
2002 /* Look up member function name in fieldlist. */
2003 for (i
= 0; i
< fip
->nfnfields
; i
++)
2005 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2009 /* Create new list element if necessary. */
2010 if (i
< fip
->nfnfields
)
2011 flp
= &fip
->fnfieldlists
[i
];
2014 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2016 fip
->fnfieldlists
= (struct fnfieldlist
*)
2017 xrealloc (fip
->fnfieldlists
,
2018 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2019 * sizeof (struct fnfieldlist
));
2020 if (fip
->nfnfields
== 0)
2021 make_cleanup ((make_cleanup_func
) free_current_contents
,
2022 &fip
->fnfieldlists
);
2024 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2025 flp
->name
= fieldname
;
2031 /* Create a new member function field and chain it to the field list
2033 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2034 make_cleanup (free
, new_fnfield
);
2035 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2036 new_fnfield
->next
= flp
->head
;
2037 flp
->head
= new_fnfield
;
2040 /* Fill in the member function field info. */
2041 fnp
= &new_fnfield
->fnfield
;
2042 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2043 &objfile
->type_obstack
);
2044 fnp
->type
= alloc_type (objfile
);
2045 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2047 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2048 struct type
**arg_types
;
2049 int nparams
= TYPE_NFIELDS (die
->type
);
2052 /* Copy argument types from the subroutine type. */
2053 arg_types
= (struct type
**)
2054 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2055 for (iparams
= 0; iparams
< nparams
; iparams
++)
2056 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2058 /* Set last entry in argument type vector. */
2059 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2060 arg_types
[nparams
] = NULL
;
2062 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2064 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2066 /* Handle static member functions.
2067 Dwarf2 has no clean way to discern C++ static and non-static
2068 member functions. G++ helps GDB by marking the first
2069 parameter for non-static member functions (which is the
2070 this pointer) as artificial. We obtain this information
2071 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2072 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2073 fnp
->voffset
= VOFFSET_STATIC
;
2076 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2078 /* Get fcontext from DW_AT_containing_type if present. */
2079 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2080 fnp
->fcontext
= die_containing_type (die
, objfile
);
2082 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2083 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2085 /* Get accessibility. */
2086 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2089 switch (DW_UNSND (attr
))
2091 case DW_ACCESS_private
:
2092 fnp
->is_private
= 1;
2094 case DW_ACCESS_protected
:
2095 fnp
->is_protected
= 1;
2100 /* Get index in virtual function table if it is a virtual member function. */
2101 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2103 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2106 /* Create the vector of member function fields, and attach it to the type. */
2109 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2110 struct field_info
*fip
;
2112 struct objfile
*objfile
;
2114 struct fnfieldlist
*flp
;
2115 int total_length
= 0;
2118 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2119 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2120 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2122 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2124 struct nextfnfield
*nfp
= flp
->head
;
2125 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2128 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2129 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2130 fn_flp
->fn_fields
= (struct fn_field
*)
2131 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2132 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2133 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2135 total_length
+= flp
->length
;
2138 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2139 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2142 /* Called when we find the DIE that starts a structure or union scope
2143 (definition) to process all dies that define the members of the
2146 NOTE: we need to call struct_type regardless of whether or not the
2147 DIE has an at_name attribute, since it might be an anonymous
2148 structure or union. This gets the type entered into our set of
2151 However, if the structure is incomplete (an opaque struct/union)
2152 then suppress creating a symbol table entry for it since gdb only
2153 wants to find the one with the complete definition. Note that if
2154 it is complete, we just call new_symbol, which does it's own
2155 checking about whether the struct/union is anonymous or not (and
2156 suppresses creating a symbol table entry itself). */
2159 read_structure_scope (die
, objfile
)
2160 struct die_info
*die
;
2161 struct objfile
*objfile
;
2164 struct attribute
*attr
;
2166 type
= alloc_type (objfile
);
2168 INIT_CPLUS_SPECIFIC (type
);
2169 attr
= dwarf_attr (die
, DW_AT_name
);
2170 if (attr
&& DW_STRING (attr
))
2172 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2173 strlen (DW_STRING (attr
)),
2174 &objfile
->type_obstack
);
2177 if (die
->tag
== DW_TAG_structure_type
)
2179 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2181 else if (die
->tag
== DW_TAG_union_type
)
2183 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2187 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2189 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2192 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2195 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2199 TYPE_LENGTH (type
) = 0;
2202 /* We need to add the type field to the die immediately so we don't
2203 infinitely recurse when dealing with pointers to the structure
2204 type within the structure itself. */
2207 if (die
->has_children
&& ! die_is_declaration (die
))
2209 struct field_info fi
;
2210 struct die_info
*child_die
;
2211 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2213 memset (&fi
, 0, sizeof (struct field_info
));
2215 child_die
= die
->next
;
2217 while (child_die
&& child_die
->tag
)
2219 if (child_die
->tag
== DW_TAG_member
)
2221 dwarf2_add_field (&fi
, child_die
, objfile
);
2223 else if (child_die
->tag
== DW_TAG_variable
)
2225 /* C++ static member. */
2226 dwarf2_add_field (&fi
, child_die
, objfile
);
2228 else if (child_die
->tag
== DW_TAG_subprogram
)
2230 /* C++ member function. */
2231 process_die (child_die
, objfile
);
2232 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2234 else if (child_die
->tag
== DW_TAG_inheritance
)
2236 /* C++ base class field. */
2237 dwarf2_add_field (&fi
, child_die
, objfile
);
2241 process_die (child_die
, objfile
);
2243 child_die
= sibling_die (child_die
);
2246 /* Attach fields and member functions to the type. */
2248 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2251 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2253 /* Get the type which refers to the base class (possibly this
2254 class itself) which contains the vtable pointer for the current
2255 class from the DW_AT_containing_type attribute. */
2257 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2259 struct type
*t
= die_containing_type (die
, objfile
);
2261 TYPE_VPTR_BASETYPE (type
) = t
;
2264 static const char vptr_name
[] =
2265 {'_', 'v', 'p', 't', 'r', '\0'};
2268 /* Our own class provides vtbl ptr. */
2269 for (i
= TYPE_NFIELDS (t
) - 1;
2270 i
>= TYPE_N_BASECLASSES (t
);
2273 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2275 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2276 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2278 TYPE_VPTR_FIELDNO (type
) = i
;
2283 /* Complain if virtual function table field not found. */
2284 if (i
< TYPE_N_BASECLASSES (t
))
2285 complain (&dwarf2_vtbl_not_found_complaint
,
2286 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2290 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2295 new_symbol (die
, type
, objfile
);
2297 do_cleanups (back_to
);
2301 /* No children, must be stub. */
2302 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2308 /* Given a pointer to a die which begins an enumeration, process all
2309 the dies that define the members of the enumeration.
2311 This will be much nicer in draft 6 of the DWARF spec when our
2312 members will be dies instead squished into the DW_AT_element_list
2315 NOTE: We reverse the order of the element list. */
2318 read_enumeration (die
, objfile
)
2319 struct die_info
*die
;
2320 struct objfile
*objfile
;
2322 struct die_info
*child_die
;
2324 struct field
*fields
;
2325 struct attribute
*attr
;
2328 int unsigned_enum
= 1;
2330 type
= alloc_type (objfile
);
2332 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2333 attr
= dwarf_attr (die
, DW_AT_name
);
2334 if (attr
&& DW_STRING (attr
))
2336 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2337 strlen (DW_STRING (attr
)),
2338 &objfile
->type_obstack
);
2341 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2344 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2348 TYPE_LENGTH (type
) = 0;
2353 if (die
->has_children
)
2355 child_die
= die
->next
;
2356 while (child_die
&& child_die
->tag
)
2358 if (child_die
->tag
!= DW_TAG_enumerator
)
2360 process_die (child_die
, objfile
);
2364 attr
= dwarf_attr (child_die
, DW_AT_name
);
2367 sym
= new_symbol (child_die
, type
, objfile
);
2368 if (SYMBOL_VALUE (sym
) < 0)
2371 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2373 fields
= (struct field
*)
2375 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2376 * sizeof (struct field
));
2379 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2380 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2381 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2382 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2388 child_die
= sibling_die (child_die
);
2393 TYPE_NFIELDS (type
) = num_fields
;
2394 TYPE_FIELDS (type
) = (struct field
*)
2395 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2396 memcpy (TYPE_FIELDS (type
), fields
,
2397 sizeof (struct field
) * num_fields
);
2401 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2404 new_symbol (die
, type
, objfile
);
2407 /* Extract all information from a DW_TAG_array_type DIE and put it in
2408 the DIE's type field. For now, this only handles one dimensional
2412 read_array_type (die
, objfile
)
2413 struct die_info
*die
;
2414 struct objfile
*objfile
;
2416 struct die_info
*child_die
;
2417 struct type
*type
= NULL
;
2418 struct type
*element_type
, *range_type
, *index_type
;
2419 struct type
**range_types
= NULL
;
2420 struct attribute
*attr
;
2422 struct cleanup
*back_to
;
2424 /* Return if we've already decoded this type. */
2430 element_type
= die_type (die
, objfile
);
2432 /* Irix 6.2 native cc creates array types without children for
2433 arrays with unspecified length. */
2434 if (die
->has_children
== 0)
2436 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2437 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2438 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2442 back_to
= make_cleanup (null_cleanup
, NULL
);
2443 child_die
= die
->next
;
2444 while (child_die
&& child_die
->tag
)
2446 if (child_die
->tag
== DW_TAG_subrange_type
)
2448 unsigned int low
, high
;
2450 /* Default bounds to an array with unspecified length. */
2453 if (cu_language
== language_fortran
)
2455 /* FORTRAN implies a lower bound of 1, if not given. */
2459 index_type
= die_type (child_die
, objfile
);
2460 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2463 if (attr
->form
== DW_FORM_sdata
)
2465 low
= DW_SND (attr
);
2467 else if (attr
->form
== DW_FORM_udata
2468 || attr
->form
== DW_FORM_data1
2469 || attr
->form
== DW_FORM_data2
2470 || attr
->form
== DW_FORM_data4
)
2472 low
= DW_UNSND (attr
);
2476 complain (&dwarf2_non_const_array_bound_ignored
,
2477 dwarf_form_name (attr
->form
));
2479 die
->type
= lookup_pointer_type (element_type
);
2486 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2489 if (attr
->form
== DW_FORM_sdata
)
2491 high
= DW_SND (attr
);
2493 else if (attr
->form
== DW_FORM_udata
2494 || attr
->form
== DW_FORM_data1
2495 || attr
->form
== DW_FORM_data2
2496 || attr
->form
== DW_FORM_data4
)
2498 high
= DW_UNSND (attr
);
2500 else if (attr
->form
== DW_FORM_block1
)
2502 /* GCC encodes arrays with unspecified or dynamic length
2503 with a DW_FORM_block1 attribute.
2504 FIXME: GDB does not yet know how to handle dynamic
2505 arrays properly, treat them as arrays with unspecified
2511 complain (&dwarf2_non_const_array_bound_ignored
,
2512 dwarf_form_name (attr
->form
));
2514 die
->type
= lookup_pointer_type (element_type
);
2522 /* Create a range type and save it for array type creation. */
2523 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2525 range_types
= (struct type
**)
2526 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2527 * sizeof (struct type
*));
2529 make_cleanup ((make_cleanup_func
) free_current_contents
,
2532 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2534 child_die
= sibling_die (child_die
);
2537 /* Dwarf2 dimensions are output from left to right, create the
2538 necessary array types in backwards order. */
2539 type
= element_type
;
2541 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2543 do_cleanups (back_to
);
2545 /* Install the type in the die. */
2549 /* First cut: install each common block member as a global variable. */
2552 read_common_block (die
, objfile
)
2553 struct die_info
*die
;
2554 struct objfile
*objfile
;
2556 struct die_info
*child_die
;
2557 struct attribute
*attr
;
2559 CORE_ADDR base
= (CORE_ADDR
) 0;
2561 attr
= dwarf_attr (die
, DW_AT_location
);
2564 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2566 if (die
->has_children
)
2568 child_die
= die
->next
;
2569 while (child_die
&& child_die
->tag
)
2571 sym
= new_symbol (child_die
, NULL
, objfile
);
2572 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2575 SYMBOL_VALUE_ADDRESS (sym
) =
2576 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2577 add_symbol_to_list (sym
, &global_symbols
);
2579 child_die
= sibling_die (child_die
);
2584 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2585 the user defined type vector. */
2588 read_tag_pointer_type (die
, objfile
)
2589 struct die_info
*die
;
2590 struct objfile
*objfile
;
2593 struct attribute
*attr
;
2600 type
= lookup_pointer_type (die_type (die
, objfile
));
2601 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2604 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2608 TYPE_LENGTH (type
) = address_size
;
2613 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2614 the user defined type vector. */
2617 read_tag_ptr_to_member_type (die
, objfile
)
2618 struct die_info
*die
;
2619 struct objfile
*objfile
;
2622 struct type
*to_type
;
2623 struct type
*domain
;
2630 type
= alloc_type (objfile
);
2631 to_type
= die_type (die
, objfile
);
2632 domain
= die_containing_type (die
, objfile
);
2633 smash_to_member_type (type
, domain
, to_type
);
2638 /* Extract all information from a DW_TAG_reference_type DIE and add to
2639 the user defined type vector. */
2642 read_tag_reference_type (die
, objfile
)
2643 struct die_info
*die
;
2644 struct objfile
*objfile
;
2647 struct attribute
*attr
;
2654 type
= lookup_reference_type (die_type (die
, objfile
));
2655 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2658 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2662 TYPE_LENGTH (type
) = address_size
;
2668 read_tag_const_type (die
, objfile
)
2669 struct die_info
*die
;
2670 struct objfile
*objfile
;
2677 complain (&dwarf2_const_ignored
);
2678 die
->type
= die_type (die
, objfile
);
2682 read_tag_volatile_type (die
, objfile
)
2683 struct die_info
*die
;
2684 struct objfile
*objfile
;
2691 complain (&dwarf2_volatile_ignored
);
2692 die
->type
= die_type (die
, objfile
);
2695 /* Extract all information from a DW_TAG_string_type DIE and add to
2696 the user defined type vector. It isn't really a user defined type,
2697 but it behaves like one, with other DIE's using an AT_user_def_type
2698 attribute to reference it. */
2701 read_tag_string_type (die
, objfile
)
2702 struct die_info
*die
;
2703 struct objfile
*objfile
;
2705 struct type
*type
, *range_type
, *index_type
, *char_type
;
2706 struct attribute
*attr
;
2707 unsigned int length
;
2714 attr
= dwarf_attr (die
, DW_AT_string_length
);
2717 length
= DW_UNSND (attr
);
2723 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2724 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2725 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2726 type
= create_string_type (char_type
, range_type
);
2730 /* Handle DIES due to C code like:
2734 int (*funcp)(int a, long l);
2738 ('funcp' generates a DW_TAG_subroutine_type DIE)
2742 read_subroutine_type (die
, objfile
)
2743 struct die_info
*die
;
2744 struct objfile
*objfile
;
2746 struct type
*type
; /* Type that this function returns */
2747 struct type
*ftype
; /* Function that returns above type */
2748 struct attribute
*attr
;
2750 /* Decode the type that this subroutine returns */
2755 type
= die_type (die
, objfile
);
2756 ftype
= lookup_function_type (type
);
2758 /* All functions in C++ have prototypes. */
2759 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2760 if ((attr
&& (DW_UNSND (attr
) != 0))
2761 || cu_language
== language_cplus
)
2762 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2764 if (die
->has_children
)
2766 struct die_info
*child_die
;
2770 /* Count the number of parameters.
2771 FIXME: GDB currently ignores vararg functions, but knows about
2772 vararg member functions. */
2773 child_die
= die
->next
;
2774 while (child_die
&& child_die
->tag
)
2776 if (child_die
->tag
== DW_TAG_formal_parameter
)
2778 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2779 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2780 child_die
= sibling_die (child_die
);
2783 /* Allocate storage for parameters and fill them in. */
2784 TYPE_NFIELDS (ftype
) = nparams
;
2785 TYPE_FIELDS (ftype
) = (struct field
*)
2786 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2788 child_die
= die
->next
;
2789 while (child_die
&& child_die
->tag
)
2791 if (child_die
->tag
== DW_TAG_formal_parameter
)
2793 /* Dwarf2 has no clean way to discern C++ static and non-static
2794 member functions. G++ helps GDB by marking the first
2795 parameter for non-static member functions (which is the
2796 this pointer) as artificial. We pass this information
2797 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2798 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2800 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2802 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2803 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2806 child_die
= sibling_die (child_die
);
2814 read_typedef (die
, objfile
)
2815 struct die_info
*die
;
2816 struct objfile
*objfile
;
2822 struct attribute
*attr
;
2825 xtype
= die_type (die
, objfile
);
2827 type
= alloc_type (objfile
);
2828 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2829 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2830 TYPE_TARGET_TYPE (type
) = xtype
;
2831 attr
= dwarf_attr (die
, DW_AT_name
);
2832 if (attr
&& DW_STRING (attr
))
2833 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2834 strlen (DW_STRING (attr
)),
2835 &objfile
->type_obstack
);
2841 /* Find a representation of a given base type and install
2842 it in the TYPE field of the die. */
2845 read_base_type (die
, objfile
)
2846 struct die_info
*die
;
2847 struct objfile
*objfile
;
2850 struct attribute
*attr
;
2851 int encoding
= 0, size
= 0;
2853 /* If we've already decoded this die, this is a no-op. */
2859 attr
= dwarf_attr (die
, DW_AT_encoding
);
2862 encoding
= DW_UNSND (attr
);
2864 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2867 size
= DW_UNSND (attr
);
2869 attr
= dwarf_attr (die
, DW_AT_name
);
2870 if (attr
&& DW_STRING (attr
))
2872 enum type_code code
= TYPE_CODE_INT
;
2873 int is_unsigned
= 0;
2877 case DW_ATE_address
:
2878 /* Turn DW_ATE_address into a void * pointer. */
2879 code
= TYPE_CODE_PTR
;
2882 case DW_ATE_boolean
:
2883 code
= TYPE_CODE_BOOL
;
2886 case DW_ATE_complex_float
:
2887 code
= TYPE_CODE_COMPLEX
;
2890 code
= TYPE_CODE_FLT
;
2893 case DW_ATE_signed_char
:
2895 case DW_ATE_unsigned
:
2896 case DW_ATE_unsigned_char
:
2900 complain (&dwarf2_unsupported_at_encoding
,
2901 dwarf_type_encoding_name (encoding
));
2904 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2905 if (encoding
== DW_ATE_address
)
2906 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2910 type
= dwarf_base_type (encoding
, size
, objfile
);
2915 /* Read a whole compilation unit into a linked list of dies. */
2918 read_comp_unit (info_ptr
, abfd
)
2922 struct die_info
*first_die
, *last_die
, *die
;
2926 /* Reset die reference table, we are building a new one now. */
2927 dwarf2_empty_die_ref_table ();
2931 first_die
= last_die
= NULL
;
2934 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
2935 if (die
->has_children
)
2946 /* Enter die in reference hash table */
2947 store_in_ref_table (die
->offset
, die
);
2951 first_die
= last_die
= die
;
2955 last_die
->next
= die
;
2959 while (nesting_level
> 0);
2963 /* Free a linked list of dies. */
2966 free_die_list (dies
)
2967 struct die_info
*dies
;
2969 struct die_info
*die
, *next
;
2981 /* Read the contents of the section at OFFSET and of size SIZE from the
2982 object file specified by OBJFILE into the psymbol_obstack and return it. */
2985 dwarf2_read_section (objfile
, offset
, size
)
2986 struct objfile
*objfile
;
2990 bfd
*abfd
= objfile
->obfd
;
2996 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2997 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2998 (bfd_read (buf
, size
, 1, abfd
) != size
))
3001 error ("Dwarf Error: Can't read DWARF data from '%s'",
3002 bfd_get_filename (abfd
));
3007 /* In DWARF version 2, the description of the debugging information is
3008 stored in a separate .debug_abbrev section. Before we read any
3009 dies from a section we read in all abbreviations and install them
3013 dwarf2_read_abbrevs (abfd
, offset
)
3015 unsigned int offset
;
3018 struct abbrev_info
*cur_abbrev
;
3019 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3020 unsigned int abbrev_form
, hash_number
;
3022 /* empty the table */
3023 dwarf2_empty_abbrev_table (NULL
);
3025 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3026 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3027 abbrev_ptr
+= bytes_read
;
3029 /* loop until we reach an abbrev number of 0 */
3030 while (abbrev_number
)
3032 cur_abbrev
= dwarf_alloc_abbrev ();
3034 /* read in abbrev header */
3035 cur_abbrev
->number
= abbrev_number
;
3036 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3037 abbrev_ptr
+= bytes_read
;
3038 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3041 /* now read in declarations */
3042 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3043 abbrev_ptr
+= bytes_read
;
3044 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3045 abbrev_ptr
+= bytes_read
;
3048 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3050 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3051 xrealloc (cur_abbrev
->attrs
,
3052 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3053 * sizeof (struct attr_abbrev
));
3055 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3056 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3057 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3058 abbrev_ptr
+= bytes_read
;
3059 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3060 abbrev_ptr
+= bytes_read
;
3063 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3064 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3065 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3067 /* Get next abbreviation.
3068 Under Irix6 the abbreviations for a compilation unit are not
3069 always properly terminated with an abbrev number of 0.
3070 Exit loop if we encounter an abbreviation which we have
3071 already read (which means we are about to read the abbreviations
3072 for the next compile unit) or if the end of the abbreviation
3073 table is reached. */
3074 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3075 >= dwarf_abbrev_size
)
3077 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3078 abbrev_ptr
+= bytes_read
;
3079 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3084 /* Empty the abbrev table for a new compilation unit. */
3088 dwarf2_empty_abbrev_table (ignore
)
3092 struct abbrev_info
*abbrev
, *next
;
3094 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3097 abbrev
= dwarf2_abbrevs
[i
];
3100 next
= abbrev
->next
;
3101 free (abbrev
->attrs
);
3105 dwarf2_abbrevs
[i
] = NULL
;
3109 /* Lookup an abbrev_info structure in the abbrev hash table. */
3111 static struct abbrev_info
*
3112 dwarf2_lookup_abbrev (number
)
3113 unsigned int number
;
3115 unsigned int hash_number
;
3116 struct abbrev_info
*abbrev
;
3118 hash_number
= number
% ABBREV_HASH_SIZE
;
3119 abbrev
= dwarf2_abbrevs
[hash_number
];
3123 if (abbrev
->number
== number
)
3126 abbrev
= abbrev
->next
;
3131 /* Read a minimal amount of information into the minimal die structure. */
3134 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3135 struct partial_die_info
*part_die
;
3140 unsigned int abbrev_number
, bytes_read
, i
;
3141 struct abbrev_info
*abbrev
;
3142 struct attribute attr
;
3143 struct attribute spec_attr
;
3144 int found_spec_attr
= 0;
3145 int has_low_pc_attr
= 0;
3146 int has_high_pc_attr
= 0;
3148 *part_die
= zeroed_partial_die
;
3150 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3151 info_ptr
+= bytes_read
;
3155 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3158 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3160 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3161 part_die
->tag
= abbrev
->tag
;
3162 part_die
->has_children
= abbrev
->has_children
;
3163 part_die
->abbrev
= abbrev_number
;
3165 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3167 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3169 /* Store the data if it is of an attribute we want to keep in a
3170 partial symbol table. */
3175 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3176 if (part_die
->name
== NULL
)
3177 part_die
->name
= DW_STRING (&attr
);
3179 case DW_AT_MIPS_linkage_name
:
3180 part_die
->name
= DW_STRING (&attr
);
3183 has_low_pc_attr
= 1;
3184 part_die
->lowpc
= DW_ADDR (&attr
);
3187 has_high_pc_attr
= 1;
3188 part_die
->highpc
= DW_ADDR (&attr
);
3190 case DW_AT_location
:
3191 part_die
->locdesc
= DW_BLOCK (&attr
);
3193 case DW_AT_language
:
3194 part_die
->language
= DW_UNSND (&attr
);
3196 case DW_AT_external
:
3197 part_die
->is_external
= DW_UNSND (&attr
);
3199 case DW_AT_declaration
:
3200 part_die
->is_declaration
= DW_UNSND (&attr
);
3203 part_die
->has_type
= 1;
3205 case DW_AT_abstract_origin
:
3206 case DW_AT_specification
:
3207 found_spec_attr
= 1;
3211 /* Ignore absolute siblings, they might point outside of
3212 the current compile unit. */
3213 if (attr
.form
== DW_FORM_ref_addr
)
3214 complain (&dwarf2_absolute_sibling_complaint
);
3217 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3224 /* If we found a reference attribute and the die has no name, try
3225 to find a name in the referred to die. */
3227 if (found_spec_attr
&& part_die
->name
== NULL
)
3229 struct partial_die_info spec_die
;
3233 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3234 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3237 part_die
->name
= spec_die
.name
;
3239 /* Copy DW_AT_external attribute if it is set. */
3240 if (spec_die
.is_external
)
3241 part_die
->is_external
= spec_die
.is_external
;
3245 /* When using the GNU linker, .gnu.linkonce. sections are used to
3246 eliminate duplicate copies of functions and vtables and such.
3247 The linker will arbitrarily choose one and discard the others.
3248 The AT_*_pc values for such functions refer to local labels in
3249 these sections. If the section from that file was discarded, the
3250 labels are not in the output, so the relocs get a value of 0.
3251 If this is a discarded function, mark the pc bounds as invalid,
3252 so that GDB will ignore it. */
3253 if (has_low_pc_attr
&& has_high_pc_attr
3254 && part_die
->lowpc
< part_die
->highpc
3255 && (part_die
->lowpc
!= 0
3256 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3261 /* Read the die from the .debug_info section buffer. And set diep to
3262 point to a newly allocated die with its information. */
3265 read_full_die (diep
, abfd
, info_ptr
)
3266 struct die_info
**diep
;
3270 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3271 struct abbrev_info
*abbrev
;
3272 struct die_info
*die
;
3274 offset
= info_ptr
- dwarf_info_buffer
;
3275 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3276 info_ptr
+= bytes_read
;
3279 die
= dwarf_alloc_die ();
3281 die
->abbrev
= abbrev_number
;
3287 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3290 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3292 die
= dwarf_alloc_die ();
3293 die
->offset
= offset
;
3294 die
->tag
= abbrev
->tag
;
3295 die
->has_children
= abbrev
->has_children
;
3296 die
->abbrev
= abbrev_number
;
3299 die
->num_attrs
= abbrev
->num_attrs
;
3300 die
->attrs
= (struct attribute
*)
3301 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3303 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3305 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3313 /* Read an attribute described by an abbreviated attribute. */
3316 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3317 struct attribute
*attr
;
3318 struct attr_abbrev
*abbrev
;
3322 unsigned int bytes_read
;
3323 struct dwarf_block
*blk
;
3325 attr
->name
= abbrev
->name
;
3326 attr
->form
= abbrev
->form
;
3327 switch (abbrev
->form
)
3330 case DW_FORM_ref_addr
:
3331 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3332 info_ptr
+= address_size
;
3334 case DW_FORM_block2
:
3335 blk
= dwarf_alloc_block ();
3336 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3338 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3339 info_ptr
+= blk
->size
;
3340 DW_BLOCK (attr
) = blk
;
3342 case DW_FORM_block4
:
3343 blk
= dwarf_alloc_block ();
3344 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3346 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3347 info_ptr
+= blk
->size
;
3348 DW_BLOCK (attr
) = blk
;
3351 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3355 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3359 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3362 case DW_FORM_string
:
3363 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3364 info_ptr
+= bytes_read
;
3367 blk
= dwarf_alloc_block ();
3368 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3369 info_ptr
+= bytes_read
;
3370 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3371 info_ptr
+= blk
->size
;
3372 DW_BLOCK (attr
) = blk
;
3374 case DW_FORM_block1
:
3375 blk
= dwarf_alloc_block ();
3376 blk
->size
= read_1_byte (abfd
, info_ptr
);
3378 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3379 info_ptr
+= blk
->size
;
3380 DW_BLOCK (attr
) = blk
;
3383 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3387 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3391 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3392 info_ptr
+= bytes_read
;
3395 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3396 info_ptr
+= bytes_read
;
3399 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3403 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3407 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3410 case DW_FORM_ref_udata
:
3411 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3412 info_ptr
+= bytes_read
;
3415 case DW_FORM_indirect
:
3417 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3418 dwarf_form_name (abbrev
->form
));
3423 /* read dwarf information from a buffer */
3426 read_1_byte (abfd
, buf
)
3430 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3434 read_1_signed_byte (abfd
, buf
)
3438 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3442 read_2_bytes (abfd
, buf
)
3446 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3450 read_2_signed_bytes (abfd
, buf
)
3454 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3458 read_4_bytes (abfd
, buf
)
3462 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3466 read_4_signed_bytes (abfd
, buf
)
3470 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3474 read_8_bytes (abfd
, buf
)
3478 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3482 read_address (abfd
, buf
)
3486 CORE_ADDR retval
= 0;
3488 switch (address_size
)
3491 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3494 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3497 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3500 /* *THE* alternative is 8, right? */
3503 /* If the address being read is larger than the address that is
3504 applicable for the object file format then mask it down to the
3505 correct size. Take care to avoid unnecessary shift or shift
3507 if (address_size
> address_significant_size
3508 && address_significant_size
< sizeof (CORE_ADDR
))
3510 CORE_ADDR mask
= ((CORE_ADDR
) 0) - 1;
3511 retval
&= ~(mask
<< (address_significant_size
* 8));
3517 read_n_bytes (abfd
, buf
, size
)
3522 /* If the size of a host char is 8 bits, we can return a pointer
3523 to the buffer, otherwise we have to copy the data to a buffer
3524 allocated on the temporary obstack. */
3525 #if HOST_CHAR_BIT == 8
3531 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3532 for (i
= 0; i
< size
; ++i
)
3534 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3542 read_string (abfd
, buf
, bytes_read_ptr
)
3545 unsigned int *bytes_read_ptr
;
3547 /* If the size of a host char is 8 bits, we can return a pointer
3548 to the string, otherwise we have to copy the string to a buffer
3549 allocated on the temporary obstack. */
3550 #if HOST_CHAR_BIT == 8
3553 *bytes_read_ptr
= 1;
3556 *bytes_read_ptr
= strlen (buf
) + 1;
3562 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3564 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3570 *bytes_read_ptr
= 1;
3573 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3574 *bytes_read_ptr
= i
+ 1;
3575 return obstack_finish (&dwarf2_tmp_obstack
);
3580 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3583 unsigned int *bytes_read_ptr
;
3585 unsigned int result
, num_read
;
3595 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3598 result
|= ((byte
& 127) << shift
);
3599 if ((byte
& 128) == 0)
3605 *bytes_read_ptr
= num_read
;
3610 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3613 unsigned int *bytes_read_ptr
;
3616 int i
, shift
, size
, num_read
;
3626 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3629 result
|= ((byte
& 127) << shift
);
3631 if ((byte
& 128) == 0)
3636 if ((shift
< size
) && (byte
& 0x40))
3638 result
|= -(1 << shift
);
3640 *bytes_read_ptr
= num_read
;
3645 set_cu_language (lang
)
3652 cu_language
= language_c
;
3654 case DW_LANG_C_plus_plus
:
3655 cu_language
= language_cplus
;
3657 case DW_LANG_Fortran77
:
3658 case DW_LANG_Fortran90
:
3659 cu_language
= language_fortran
;
3661 case DW_LANG_Mips_Assembler
:
3662 cu_language
= language_asm
;
3665 case DW_LANG_Cobol74
:
3666 case DW_LANG_Cobol85
:
3667 case DW_LANG_Pascal83
:
3668 case DW_LANG_Modula2
:
3670 cu_language
= language_unknown
;
3673 cu_language_defn
= language_def (cu_language
);
3676 /* Return the named attribute or NULL if not there. */
3678 static struct attribute
*
3679 dwarf_attr (die
, name
)
3680 struct die_info
*die
;
3684 struct attribute
*spec
= NULL
;
3686 for (i
= 0; i
< die
->num_attrs
; ++i
)
3688 if (die
->attrs
[i
].name
== name
)
3690 return &die
->attrs
[i
];
3692 if (die
->attrs
[i
].name
== DW_AT_specification
3693 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3694 spec
= &die
->attrs
[i
];
3698 struct die_info
*ref_die
=
3699 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3702 return dwarf_attr (ref_die
, name
);
3709 die_is_declaration (struct die_info
*die
)
3711 return (dwarf_attr (die
, DW_AT_declaration
)
3712 && ! dwarf_attr (die
, DW_AT_specification
));
3715 /* Decode the line number information for the compilation unit whose
3716 line number info is at OFFSET in the .debug_line section.
3717 The compilation directory of the file is passed in COMP_DIR. */
3721 unsigned int num_files
;
3734 unsigned int num_dirs
;
3739 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3740 unsigned int offset
;
3746 struct line_head lh
;
3747 struct cleanup
*back_to
;
3748 unsigned int i
, bytes_read
;
3749 char *cur_file
, *cur_dir
;
3750 unsigned char op_code
, extended_op
, adj_opcode
;
3752 #define FILE_ALLOC_CHUNK 5
3753 #define DIR_ALLOC_CHUNK 5
3755 struct filenames files
;
3756 struct directories dirs
;
3758 if (dwarf_line_buffer
== NULL
)
3760 complain (&dwarf2_missing_line_number_section
);
3764 files
.num_files
= 0;
3770 line_ptr
= dwarf_line_buffer
+ offset
;
3772 /* read in the prologue */
3773 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3775 line_end
= line_ptr
+ lh
.total_length
;
3776 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3778 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3780 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3782 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3784 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3786 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3788 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3790 lh
.standard_opcode_lengths
= (unsigned char *)
3791 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3792 back_to
= make_cleanup ((make_cleanup_func
) free_current_contents
,
3793 &lh
.standard_opcode_lengths
);
3795 lh
.standard_opcode_lengths
[0] = 1;
3796 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3798 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3802 /* Read directory table */
3803 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3805 line_ptr
+= bytes_read
;
3806 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3808 dirs
.dirs
= (char **)
3809 xrealloc (dirs
.dirs
,
3810 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3811 if (dirs
.num_dirs
== 0)
3812 make_cleanup ((make_cleanup_func
) free_current_contents
, &dirs
.dirs
);
3814 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3816 line_ptr
+= bytes_read
;
3818 /* Read file name table */
3819 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3821 line_ptr
+= bytes_read
;
3822 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3824 files
.files
= (struct fileinfo
*)
3825 xrealloc (files
.files
,
3826 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3827 * sizeof (struct fileinfo
));
3828 if (files
.num_files
== 0)
3829 make_cleanup ((make_cleanup_func
) free_current_contents
,
3832 files
.files
[files
.num_files
].name
= cur_file
;
3833 files
.files
[files
.num_files
].dir
=
3834 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3835 line_ptr
+= bytes_read
;
3836 files
.files
[files
.num_files
].time
=
3837 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3838 line_ptr
+= bytes_read
;
3839 files
.files
[files
.num_files
].size
=
3840 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3841 line_ptr
+= bytes_read
;
3844 line_ptr
+= bytes_read
;
3846 /* Read the statement sequences until there's nothing left. */
3847 while (line_ptr
< line_end
)
3849 /* state machine registers */
3850 CORE_ADDR address
= 0;
3851 unsigned int file
= 1;
3852 unsigned int line
= 1;
3853 unsigned int column
= 0;
3854 int is_stmt
= lh
.default_is_stmt
;
3855 int basic_block
= 0;
3856 int end_sequence
= 0;
3858 /* Start a subfile for the current file of the state machine. */
3859 if (files
.num_files
>= file
)
3861 /* The file and directory tables are 0 based, the references
3863 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3864 (files
.files
[file
- 1].dir
3865 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3869 /* Decode the table. */
3870 while (!end_sequence
)
3872 op_code
= read_1_byte (abfd
, line_ptr
);
3876 case DW_LNS_extended_op
:
3877 line_ptr
+= 1; /* ignore length */
3878 extended_op
= read_1_byte (abfd
, line_ptr
);
3880 switch (extended_op
)
3882 case DW_LNE_end_sequence
:
3884 /* Don't call record_line here. The end_sequence
3885 instruction provides the address of the first byte
3886 *after* the last line in the sequence; it's not the
3887 address of any real source line. However, the GDB
3888 linetable structure only records the starts of lines,
3889 not the ends. This is a weakness of GDB. */
3891 case DW_LNE_set_address
:
3892 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3893 line_ptr
+= address_size
;
3895 case DW_LNE_define_file
:
3896 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3897 line_ptr
+= bytes_read
;
3898 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3900 files
.files
= (struct fileinfo
*)
3901 xrealloc (files
.files
,
3902 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3903 * sizeof (struct fileinfo
));
3904 if (files
.num_files
== 0)
3905 make_cleanup ((make_cleanup_func
) free_current_contents
,
3908 files
.files
[files
.num_files
].name
= cur_file
;
3909 files
.files
[files
.num_files
].dir
=
3910 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3911 line_ptr
+= bytes_read
;
3912 files
.files
[files
.num_files
].time
=
3913 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3914 line_ptr
+= bytes_read
;
3915 files
.files
[files
.num_files
].size
=
3916 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3917 line_ptr
+= bytes_read
;
3921 complain (&dwarf2_mangled_line_number_section
);
3926 record_line (current_subfile
, line
, address
);
3929 case DW_LNS_advance_pc
:
3930 address
+= lh
.minimum_instruction_length
3931 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3932 line_ptr
+= bytes_read
;
3934 case DW_LNS_advance_line
:
3935 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3936 line_ptr
+= bytes_read
;
3938 case DW_LNS_set_file
:
3939 /* The file and directory tables are 0 based, the references
3941 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3942 line_ptr
+= bytes_read
;
3943 dwarf2_start_subfile
3944 (files
.files
[file
- 1].name
,
3945 (files
.files
[file
- 1].dir
3946 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3949 case DW_LNS_set_column
:
3950 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3951 line_ptr
+= bytes_read
;
3953 case DW_LNS_negate_stmt
:
3954 is_stmt
= (!is_stmt
);
3956 case DW_LNS_set_basic_block
:
3959 /* Add to the address register of the state machine the
3960 address increment value corresponding to special opcode
3961 255. Ie, this value is scaled by the minimum instruction
3962 length since special opcode 255 would have scaled the
3964 case DW_LNS_const_add_pc
:
3965 address
+= (lh
.minimum_instruction_length
3966 * ((255 - lh
.opcode_base
) / lh
.line_range
));
3968 case DW_LNS_fixed_advance_pc
:
3969 address
+= read_2_bytes (abfd
, line_ptr
);
3972 default: /* special operand */
3973 adj_opcode
= op_code
- lh
.opcode_base
;
3974 address
+= (adj_opcode
/ lh
.line_range
)
3975 * lh
.minimum_instruction_length
;
3976 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
3977 /* append row to matrix using current values */
3978 record_line (current_subfile
, line
, address
);
3984 do_cleanups (back_to
);
3987 /* Start a subfile for DWARF. FILENAME is the name of the file and
3988 DIRNAME the name of the source directory which contains FILENAME
3989 or NULL if not known.
3990 This routine tries to keep line numbers from identical absolute and
3991 relative file names in a common subfile.
3993 Using the `list' example from the GDB testsuite, which resides in
3994 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
3995 of /srcdir/list0.c yields the following debugging information for list0.c:
3997 DW_AT_name: /srcdir/list0.c
3998 DW_AT_comp_dir: /compdir
3999 files.files[0].name: list0.h
4000 files.files[0].dir: /srcdir
4001 files.files[1].name: list0.c
4002 files.files[1].dir: /srcdir
4004 The line number information for list0.c has to end up in a single
4005 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4008 dwarf2_start_subfile (filename
, dirname
)
4012 /* If the filename isn't absolute, try to match an existing subfile
4013 with the full pathname. */
4015 if (*filename
!= '/' && dirname
!= NULL
)
4017 struct subfile
*subfile
;
4018 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4020 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4022 if (STREQ (subfile
->name
, fullname
))
4024 current_subfile
= subfile
;
4031 start_subfile (filename
, dirname
);
4034 /* Given a pointer to a DWARF information entry, figure out if we need
4035 to make a symbol table entry for it, and if so, create a new entry
4036 and return a pointer to it.
4037 If TYPE is NULL, determine symbol type from the die, otherwise
4038 used the passed type. */
4040 static struct symbol
*
4041 new_symbol (die
, type
, objfile
)
4042 struct die_info
*die
;
4044 struct objfile
*objfile
;
4046 struct symbol
*sym
= NULL
;
4048 struct attribute
*attr
= NULL
;
4049 struct attribute
*attr2
= NULL
;
4052 name
= dwarf2_linkage_name (die
);
4055 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4056 sizeof (struct symbol
));
4057 OBJSTAT (objfile
, n_syms
++);
4058 memset (sym
, 0, sizeof (struct symbol
));
4059 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4060 &objfile
->symbol_obstack
);
4062 /* Default assumptions.
4063 Use the passed type or decode it from the die. */
4064 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4065 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4067 SYMBOL_TYPE (sym
) = type
;
4069 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4070 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4073 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4076 /* If this symbol is from a C++ compilation, then attempt to
4077 cache the demangled form for future reference. This is a
4078 typical time versus space tradeoff, that was decided in favor
4079 of time because it sped up C++ symbol lookups by a factor of
4082 SYMBOL_LANGUAGE (sym
) = cu_language
;
4083 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4087 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4090 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4092 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4094 case DW_TAG_subprogram
:
4095 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4097 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4098 attr2
= dwarf_attr (die
, DW_AT_external
);
4099 if (attr2
&& (DW_UNSND (attr2
) != 0))
4101 add_symbol_to_list (sym
, &global_symbols
);
4105 add_symbol_to_list (sym
, list_in_scope
);
4108 case DW_TAG_variable
:
4109 /* Compilation with minimal debug info may result in variables
4110 with missing type entries. Change the misleading `void' type
4111 to something sensible. */
4112 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4113 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4114 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4115 "<variable, no debug info>",
4117 attr
= dwarf_attr (die
, DW_AT_const_value
);
4120 dwarf2_const_value (attr
, sym
, objfile
);
4121 attr2
= dwarf_attr (die
, DW_AT_external
);
4122 if (attr2
&& (DW_UNSND (attr2
) != 0))
4123 add_symbol_to_list (sym
, &global_symbols
);
4125 add_symbol_to_list (sym
, list_in_scope
);
4128 attr
= dwarf_attr (die
, DW_AT_location
);
4131 attr2
= dwarf_attr (die
, DW_AT_external
);
4132 if (attr2
&& (DW_UNSND (attr2
) != 0))
4134 SYMBOL_VALUE_ADDRESS (sym
) =
4135 decode_locdesc (DW_BLOCK (attr
), objfile
);
4136 add_symbol_to_list (sym
, &global_symbols
);
4138 /* In shared libraries the address of the variable
4139 in the location descriptor might still be relocatable,
4140 so its value could be zero.
4141 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4142 value is zero, the address of the variable will then
4143 be determined from the minimal symbol table whenever
4144 the variable is referenced. */
4145 if (SYMBOL_VALUE_ADDRESS (sym
))
4147 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4148 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4151 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4155 SYMBOL_VALUE (sym
) = addr
=
4156 decode_locdesc (DW_BLOCK (attr
), objfile
);
4157 add_symbol_to_list (sym
, list_in_scope
);
4160 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4164 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4168 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4169 SYMBOL_BASEREG (sym
) = basereg
;
4173 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4177 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4178 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4184 /* We do not know the address of this symbol.
4185 If it is an external symbol and we have type information
4186 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4187 The address of the variable will then be determined from
4188 the minimal symbol table whenever the variable is
4190 attr2
= dwarf_attr (die
, DW_AT_external
);
4191 if (attr2
&& (DW_UNSND (attr2
) != 0)
4192 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4194 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4195 add_symbol_to_list (sym
, &global_symbols
);
4199 case DW_TAG_formal_parameter
:
4200 attr
= dwarf_attr (die
, DW_AT_location
);
4203 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4206 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4212 if (basereg
!= frame_base_reg
)
4213 complain (&dwarf2_complex_location_expr
);
4214 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4218 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4219 SYMBOL_BASEREG (sym
) = basereg
;
4224 SYMBOL_CLASS (sym
) = LOC_ARG
;
4227 attr
= dwarf_attr (die
, DW_AT_const_value
);
4230 dwarf2_const_value (attr
, sym
, objfile
);
4232 add_symbol_to_list (sym
, list_in_scope
);
4234 case DW_TAG_unspecified_parameters
:
4235 /* From varargs functions; gdb doesn't seem to have any
4236 interest in this information, so just ignore it for now.
4239 case DW_TAG_class_type
:
4240 case DW_TAG_structure_type
:
4241 case DW_TAG_union_type
:
4242 case DW_TAG_enumeration_type
:
4243 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4244 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4245 add_symbol_to_list (sym
, list_in_scope
);
4247 /* The semantics of C++ state that "struct foo { ... }" also
4248 defines a typedef for "foo". Synthesize a typedef symbol so
4249 that "ptype foo" works as expected. */
4250 if (cu_language
== language_cplus
)
4252 struct symbol
*typedef_sym
= (struct symbol
*)
4253 obstack_alloc (&objfile
->symbol_obstack
,
4254 sizeof (struct symbol
));
4255 *typedef_sym
= *sym
;
4256 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4257 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4258 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4259 obsavestring (SYMBOL_NAME (sym
),
4260 strlen (SYMBOL_NAME (sym
)),
4261 &objfile
->type_obstack
);
4262 add_symbol_to_list (typedef_sym
, list_in_scope
);
4265 case DW_TAG_typedef
:
4266 case DW_TAG_base_type
:
4267 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4268 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4269 add_symbol_to_list (sym
, list_in_scope
);
4271 case DW_TAG_enumerator
:
4272 attr
= dwarf_attr (die
, DW_AT_const_value
);
4275 dwarf2_const_value (attr
, sym
, objfile
);
4277 add_symbol_to_list (sym
, list_in_scope
);
4280 /* Not a tag we recognize. Hopefully we aren't processing
4281 trash data, but since we must specifically ignore things
4282 we don't recognize, there is nothing else we should do at
4284 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4291 /* Copy constant value from an attribute to a symbol. */
4294 dwarf2_const_value (attr
, sym
, objfile
)
4295 struct attribute
*attr
;
4297 struct objfile
*objfile
;
4299 struct dwarf_block
*blk
;
4304 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4305 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4306 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4307 SYMBOL_VALUE_BYTES (sym
) = (char *)
4308 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4309 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4310 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4312 case DW_FORM_block1
:
4313 case DW_FORM_block2
:
4314 case DW_FORM_block4
:
4316 blk
= DW_BLOCK (attr
);
4317 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4318 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4319 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4320 SYMBOL_VALUE_BYTES (sym
) = (char *)
4321 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4322 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4323 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4326 /* The DW_AT_const_value attributes are supposed to carry the
4327 symbol's value "represented as it would be on the target
4328 architecture." By the time we get here, it's already been
4329 converted to host endianness, so we just need to sign- or
4330 zero-extend it as appropriate. */
4332 dwarf2_const_value_data (attr
, sym
, 8);
4335 dwarf2_const_value_data (attr
, sym
, 16);
4338 dwarf2_const_value_data (attr
, sym
, 32);
4341 dwarf2_const_value_data (attr
, sym
, 64);
4345 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4346 SYMBOL_CLASS (sym
) = LOC_CONST
;
4350 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4351 SYMBOL_CLASS (sym
) = LOC_CONST
;
4355 complain (&dwarf2_unsupported_const_value_attr
,
4356 dwarf_form_name (attr
->form
));
4357 SYMBOL_VALUE (sym
) = 0;
4358 SYMBOL_CLASS (sym
) = LOC_CONST
;
4364 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4365 or zero-extend it as appropriate for the symbol's type. */
4367 dwarf2_const_value_data (struct attribute
*attr
,
4371 LONGEST l
= DW_UNSND (attr
);
4373 if (bits
< sizeof (l
) * 8)
4375 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4376 l
&= ((LONGEST
) 1 << bits
) - 1;
4378 l
= (l
<< (sizeof (l
) - bits
)) >> (sizeof (l
) - bits
);
4381 SYMBOL_VALUE (sym
) = l
;
4382 SYMBOL_CLASS (sym
) = LOC_CONST
;
4386 /* Return the type of the die in question using its DW_AT_type attribute. */
4388 static struct type
*
4389 die_type (die
, objfile
)
4390 struct die_info
*die
;
4391 struct objfile
*objfile
;
4394 struct attribute
*type_attr
;
4395 struct die_info
*type_die
;
4398 type_attr
= dwarf_attr (die
, DW_AT_type
);
4401 /* A missing DW_AT_type represents a void type. */
4402 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4406 ref
= dwarf2_get_ref_die_offset (type_attr
);
4407 type_die
= follow_die_ref (ref
);
4410 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4414 type
= tag_type_to_type (type_die
, objfile
);
4417 dump_die (type_die
);
4418 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4423 /* Return the containing type of the die in question using its
4424 DW_AT_containing_type attribute. */
4426 static struct type
*
4427 die_containing_type (die
, objfile
)
4428 struct die_info
*die
;
4429 struct objfile
*objfile
;
4431 struct type
*type
= NULL
;
4432 struct attribute
*type_attr
;
4433 struct die_info
*type_die
= NULL
;
4436 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4439 ref
= dwarf2_get_ref_die_offset (type_attr
);
4440 type_die
= follow_die_ref (ref
);
4443 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4446 type
= tag_type_to_type (type_die
, objfile
);
4451 dump_die (type_die
);
4452 error ("Dwarf Error: Problem turning containing type into gdb type.");
4458 static struct type
*
4459 type_at_offset (offset
, objfile
)
4460 unsigned int offset
;
4461 struct objfile
*objfile
;
4463 struct die_info
*die
;
4466 die
= follow_die_ref (offset
);
4469 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4472 type
= tag_type_to_type (die
, objfile
);
4477 static struct type
*
4478 tag_type_to_type (die
, objfile
)
4479 struct die_info
*die
;
4480 struct objfile
*objfile
;
4488 read_type_die (die
, objfile
);
4492 error ("Dwarf Error: Cannot find type of die.");
4499 read_type_die (die
, objfile
)
4500 struct die_info
*die
;
4501 struct objfile
*objfile
;
4505 case DW_TAG_class_type
:
4506 case DW_TAG_structure_type
:
4507 case DW_TAG_union_type
:
4508 read_structure_scope (die
, objfile
);
4510 case DW_TAG_enumeration_type
:
4511 read_enumeration (die
, objfile
);
4513 case DW_TAG_subprogram
:
4514 case DW_TAG_subroutine_type
:
4515 read_subroutine_type (die
, objfile
);
4517 case DW_TAG_array_type
:
4518 read_array_type (die
, objfile
);
4520 case DW_TAG_pointer_type
:
4521 read_tag_pointer_type (die
, objfile
);
4523 case DW_TAG_ptr_to_member_type
:
4524 read_tag_ptr_to_member_type (die
, objfile
);
4526 case DW_TAG_reference_type
:
4527 read_tag_reference_type (die
, objfile
);
4529 case DW_TAG_const_type
:
4530 read_tag_const_type (die
, objfile
);
4532 case DW_TAG_volatile_type
:
4533 read_tag_volatile_type (die
, objfile
);
4535 case DW_TAG_string_type
:
4536 read_tag_string_type (die
, objfile
);
4538 case DW_TAG_typedef
:
4539 read_typedef (die
, objfile
);
4541 case DW_TAG_base_type
:
4542 read_base_type (die
, objfile
);
4545 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4550 static struct type
*
4551 dwarf_base_type (encoding
, size
, objfile
)
4554 struct objfile
*objfile
;
4556 /* FIXME - this should not produce a new (struct type *)
4557 every time. It should cache base types. */
4561 case DW_ATE_address
:
4562 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4564 case DW_ATE_boolean
:
4565 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4567 case DW_ATE_complex_float
:
4570 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4574 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4580 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4584 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4591 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4594 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4598 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4602 case DW_ATE_signed_char
:
4603 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4605 case DW_ATE_unsigned
:
4609 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4612 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4616 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4620 case DW_ATE_unsigned_char
:
4621 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4624 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4632 struct die_info
*old_die
;
4634 struct die_info
*new_die
;
4637 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4638 memset (new_die
, 0, sizeof (struct die_info
));
4640 new_die
->tag
= old_die
->tag
;
4641 new_die
->has_children
= old_die
->has_children
;
4642 new_die
->abbrev
= old_die
->abbrev
;
4643 new_die
->offset
= old_die
->offset
;
4644 new_die
->type
= NULL
;
4646 num_attrs
= old_die
->num_attrs
;
4647 new_die
->num_attrs
= num_attrs
;
4648 new_die
->attrs
= (struct attribute
*)
4649 xmalloc (num_attrs
* sizeof (struct attribute
));
4651 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4653 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4654 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4655 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4658 new_die
->next
= NULL
;
4663 /* Return sibling of die, NULL if no sibling. */
4667 struct die_info
*die
;
4669 int nesting_level
= 0;
4671 if (!die
->has_children
)
4673 if (die
->next
&& (die
->next
->tag
== 0))
4686 if (die
->has_children
)
4696 while (nesting_level
);
4697 if (die
&& (die
->tag
== 0))
4708 /* Get linkage name of a die, return NULL if not found. */
4711 dwarf2_linkage_name (die
)
4712 struct die_info
*die
;
4714 struct attribute
*attr
;
4716 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4717 if (attr
&& DW_STRING (attr
))
4718 return DW_STRING (attr
);
4719 attr
= dwarf_attr (die
, DW_AT_name
);
4720 if (attr
&& DW_STRING (attr
))
4721 return DW_STRING (attr
);
4725 /* Convert a DIE tag into its string name. */
4728 dwarf_tag_name (tag
)
4729 register unsigned tag
;
4733 case DW_TAG_padding
:
4734 return "DW_TAG_padding";
4735 case DW_TAG_array_type
:
4736 return "DW_TAG_array_type";
4737 case DW_TAG_class_type
:
4738 return "DW_TAG_class_type";
4739 case DW_TAG_entry_point
:
4740 return "DW_TAG_entry_point";
4741 case DW_TAG_enumeration_type
:
4742 return "DW_TAG_enumeration_type";
4743 case DW_TAG_formal_parameter
:
4744 return "DW_TAG_formal_parameter";
4745 case DW_TAG_imported_declaration
:
4746 return "DW_TAG_imported_declaration";
4748 return "DW_TAG_label";
4749 case DW_TAG_lexical_block
:
4750 return "DW_TAG_lexical_block";
4752 return "DW_TAG_member";
4753 case DW_TAG_pointer_type
:
4754 return "DW_TAG_pointer_type";
4755 case DW_TAG_reference_type
:
4756 return "DW_TAG_reference_type";
4757 case DW_TAG_compile_unit
:
4758 return "DW_TAG_compile_unit";
4759 case DW_TAG_string_type
:
4760 return "DW_TAG_string_type";
4761 case DW_TAG_structure_type
:
4762 return "DW_TAG_structure_type";
4763 case DW_TAG_subroutine_type
:
4764 return "DW_TAG_subroutine_type";
4765 case DW_TAG_typedef
:
4766 return "DW_TAG_typedef";
4767 case DW_TAG_union_type
:
4768 return "DW_TAG_union_type";
4769 case DW_TAG_unspecified_parameters
:
4770 return "DW_TAG_unspecified_parameters";
4771 case DW_TAG_variant
:
4772 return "DW_TAG_variant";
4773 case DW_TAG_common_block
:
4774 return "DW_TAG_common_block";
4775 case DW_TAG_common_inclusion
:
4776 return "DW_TAG_common_inclusion";
4777 case DW_TAG_inheritance
:
4778 return "DW_TAG_inheritance";
4779 case DW_TAG_inlined_subroutine
:
4780 return "DW_TAG_inlined_subroutine";
4782 return "DW_TAG_module";
4783 case DW_TAG_ptr_to_member_type
:
4784 return "DW_TAG_ptr_to_member_type";
4785 case DW_TAG_set_type
:
4786 return "DW_TAG_set_type";
4787 case DW_TAG_subrange_type
:
4788 return "DW_TAG_subrange_type";
4789 case DW_TAG_with_stmt
:
4790 return "DW_TAG_with_stmt";
4791 case DW_TAG_access_declaration
:
4792 return "DW_TAG_access_declaration";
4793 case DW_TAG_base_type
:
4794 return "DW_TAG_base_type";
4795 case DW_TAG_catch_block
:
4796 return "DW_TAG_catch_block";
4797 case DW_TAG_const_type
:
4798 return "DW_TAG_const_type";
4799 case DW_TAG_constant
:
4800 return "DW_TAG_constant";
4801 case DW_TAG_enumerator
:
4802 return "DW_TAG_enumerator";
4803 case DW_TAG_file_type
:
4804 return "DW_TAG_file_type";
4806 return "DW_TAG_friend";
4807 case DW_TAG_namelist
:
4808 return "DW_TAG_namelist";
4809 case DW_TAG_namelist_item
:
4810 return "DW_TAG_namelist_item";
4811 case DW_TAG_packed_type
:
4812 return "DW_TAG_packed_type";
4813 case DW_TAG_subprogram
:
4814 return "DW_TAG_subprogram";
4815 case DW_TAG_template_type_param
:
4816 return "DW_TAG_template_type_param";
4817 case DW_TAG_template_value_param
:
4818 return "DW_TAG_template_value_param";
4819 case DW_TAG_thrown_type
:
4820 return "DW_TAG_thrown_type";
4821 case DW_TAG_try_block
:
4822 return "DW_TAG_try_block";
4823 case DW_TAG_variant_part
:
4824 return "DW_TAG_variant_part";
4825 case DW_TAG_variable
:
4826 return "DW_TAG_variable";
4827 case DW_TAG_volatile_type
:
4828 return "DW_TAG_volatile_type";
4829 case DW_TAG_MIPS_loop
:
4830 return "DW_TAG_MIPS_loop";
4831 case DW_TAG_format_label
:
4832 return "DW_TAG_format_label";
4833 case DW_TAG_function_template
:
4834 return "DW_TAG_function_template";
4835 case DW_TAG_class_template
:
4836 return "DW_TAG_class_template";
4838 return "DW_TAG_<unknown>";
4842 /* Convert a DWARF attribute code into its string name. */
4845 dwarf_attr_name (attr
)
4846 register unsigned attr
;
4851 return "DW_AT_sibling";
4852 case DW_AT_location
:
4853 return "DW_AT_location";
4855 return "DW_AT_name";
4856 case DW_AT_ordering
:
4857 return "DW_AT_ordering";
4858 case DW_AT_subscr_data
:
4859 return "DW_AT_subscr_data";
4860 case DW_AT_byte_size
:
4861 return "DW_AT_byte_size";
4862 case DW_AT_bit_offset
:
4863 return "DW_AT_bit_offset";
4864 case DW_AT_bit_size
:
4865 return "DW_AT_bit_size";
4866 case DW_AT_element_list
:
4867 return "DW_AT_element_list";
4868 case DW_AT_stmt_list
:
4869 return "DW_AT_stmt_list";
4871 return "DW_AT_low_pc";
4873 return "DW_AT_high_pc";
4874 case DW_AT_language
:
4875 return "DW_AT_language";
4877 return "DW_AT_member";
4879 return "DW_AT_discr";
4880 case DW_AT_discr_value
:
4881 return "DW_AT_discr_value";
4882 case DW_AT_visibility
:
4883 return "DW_AT_visibility";
4885 return "DW_AT_import";
4886 case DW_AT_string_length
:
4887 return "DW_AT_string_length";
4888 case DW_AT_common_reference
:
4889 return "DW_AT_common_reference";
4890 case DW_AT_comp_dir
:
4891 return "DW_AT_comp_dir";
4892 case DW_AT_const_value
:
4893 return "DW_AT_const_value";
4894 case DW_AT_containing_type
:
4895 return "DW_AT_containing_type";
4896 case DW_AT_default_value
:
4897 return "DW_AT_default_value";
4899 return "DW_AT_inline";
4900 case DW_AT_is_optional
:
4901 return "DW_AT_is_optional";
4902 case DW_AT_lower_bound
:
4903 return "DW_AT_lower_bound";
4904 case DW_AT_producer
:
4905 return "DW_AT_producer";
4906 case DW_AT_prototyped
:
4907 return "DW_AT_prototyped";
4908 case DW_AT_return_addr
:
4909 return "DW_AT_return_addr";
4910 case DW_AT_start_scope
:
4911 return "DW_AT_start_scope";
4912 case DW_AT_stride_size
:
4913 return "DW_AT_stride_size";
4914 case DW_AT_upper_bound
:
4915 return "DW_AT_upper_bound";
4916 case DW_AT_abstract_origin
:
4917 return "DW_AT_abstract_origin";
4918 case DW_AT_accessibility
:
4919 return "DW_AT_accessibility";
4920 case DW_AT_address_class
:
4921 return "DW_AT_address_class";
4922 case DW_AT_artificial
:
4923 return "DW_AT_artificial";
4924 case DW_AT_base_types
:
4925 return "DW_AT_base_types";
4926 case DW_AT_calling_convention
:
4927 return "DW_AT_calling_convention";
4929 return "DW_AT_count";
4930 case DW_AT_data_member_location
:
4931 return "DW_AT_data_member_location";
4932 case DW_AT_decl_column
:
4933 return "DW_AT_decl_column";
4934 case DW_AT_decl_file
:
4935 return "DW_AT_decl_file";
4936 case DW_AT_decl_line
:
4937 return "DW_AT_decl_line";
4938 case DW_AT_declaration
:
4939 return "DW_AT_declaration";
4940 case DW_AT_discr_list
:
4941 return "DW_AT_discr_list";
4942 case DW_AT_encoding
:
4943 return "DW_AT_encoding";
4944 case DW_AT_external
:
4945 return "DW_AT_external";
4946 case DW_AT_frame_base
:
4947 return "DW_AT_frame_base";
4949 return "DW_AT_friend";
4950 case DW_AT_identifier_case
:
4951 return "DW_AT_identifier_case";
4952 case DW_AT_macro_info
:
4953 return "DW_AT_macro_info";
4954 case DW_AT_namelist_items
:
4955 return "DW_AT_namelist_items";
4956 case DW_AT_priority
:
4957 return "DW_AT_priority";
4959 return "DW_AT_segment";
4960 case DW_AT_specification
:
4961 return "DW_AT_specification";
4962 case DW_AT_static_link
:
4963 return "DW_AT_static_link";
4965 return "DW_AT_type";
4966 case DW_AT_use_location
:
4967 return "DW_AT_use_location";
4968 case DW_AT_variable_parameter
:
4969 return "DW_AT_variable_parameter";
4970 case DW_AT_virtuality
:
4971 return "DW_AT_virtuality";
4972 case DW_AT_vtable_elem_location
:
4973 return "DW_AT_vtable_elem_location";
4976 case DW_AT_MIPS_fde
:
4977 return "DW_AT_MIPS_fde";
4978 case DW_AT_MIPS_loop_begin
:
4979 return "DW_AT_MIPS_loop_begin";
4980 case DW_AT_MIPS_tail_loop_begin
:
4981 return "DW_AT_MIPS_tail_loop_begin";
4982 case DW_AT_MIPS_epilog_begin
:
4983 return "DW_AT_MIPS_epilog_begin";
4984 case DW_AT_MIPS_loop_unroll_factor
:
4985 return "DW_AT_MIPS_loop_unroll_factor";
4986 case DW_AT_MIPS_software_pipeline_depth
:
4987 return "DW_AT_MIPS_software_pipeline_depth";
4988 case DW_AT_MIPS_linkage_name
:
4989 return "DW_AT_MIPS_linkage_name";
4992 case DW_AT_sf_names
:
4993 return "DW_AT_sf_names";
4994 case DW_AT_src_info
:
4995 return "DW_AT_src_info";
4996 case DW_AT_mac_info
:
4997 return "DW_AT_mac_info";
4998 case DW_AT_src_coords
:
4999 return "DW_AT_src_coords";
5000 case DW_AT_body_begin
:
5001 return "DW_AT_body_begin";
5002 case DW_AT_body_end
:
5003 return "DW_AT_body_end";
5005 return "DW_AT_<unknown>";
5009 /* Convert a DWARF value form code into its string name. */
5012 dwarf_form_name (form
)
5013 register unsigned form
;
5018 return "DW_FORM_addr";
5019 case DW_FORM_block2
:
5020 return "DW_FORM_block2";
5021 case DW_FORM_block4
:
5022 return "DW_FORM_block4";
5024 return "DW_FORM_data2";
5026 return "DW_FORM_data4";
5028 return "DW_FORM_data8";
5029 case DW_FORM_string
:
5030 return "DW_FORM_string";
5032 return "DW_FORM_block";
5033 case DW_FORM_block1
:
5034 return "DW_FORM_block1";
5036 return "DW_FORM_data1";
5038 return "DW_FORM_flag";
5040 return "DW_FORM_sdata";
5042 return "DW_FORM_strp";
5044 return "DW_FORM_udata";
5045 case DW_FORM_ref_addr
:
5046 return "DW_FORM_ref_addr";
5048 return "DW_FORM_ref1";
5050 return "DW_FORM_ref2";
5052 return "DW_FORM_ref4";
5054 return "DW_FORM_ref8";
5055 case DW_FORM_ref_udata
:
5056 return "DW_FORM_ref_udata";
5057 case DW_FORM_indirect
:
5058 return "DW_FORM_indirect";
5060 return "DW_FORM_<unknown>";
5064 /* Convert a DWARF stack opcode into its string name. */
5067 dwarf_stack_op_name (op
)
5068 register unsigned op
;
5073 return "DW_OP_addr";
5075 return "DW_OP_deref";
5077 return "DW_OP_const1u";
5079 return "DW_OP_const1s";
5081 return "DW_OP_const2u";
5083 return "DW_OP_const2s";
5085 return "DW_OP_const4u";
5087 return "DW_OP_const4s";
5089 return "DW_OP_const8u";
5091 return "DW_OP_const8s";
5093 return "DW_OP_constu";
5095 return "DW_OP_consts";
5099 return "DW_OP_drop";
5101 return "DW_OP_over";
5103 return "DW_OP_pick";
5105 return "DW_OP_swap";
5109 return "DW_OP_xderef";
5117 return "DW_OP_minus";
5129 return "DW_OP_plus";
5130 case DW_OP_plus_uconst
:
5131 return "DW_OP_plus_uconst";
5137 return "DW_OP_shra";
5155 return "DW_OP_skip";
5157 return "DW_OP_lit0";
5159 return "DW_OP_lit1";
5161 return "DW_OP_lit2";
5163 return "DW_OP_lit3";
5165 return "DW_OP_lit4";
5167 return "DW_OP_lit5";
5169 return "DW_OP_lit6";
5171 return "DW_OP_lit7";
5173 return "DW_OP_lit8";
5175 return "DW_OP_lit9";
5177 return "DW_OP_lit10";
5179 return "DW_OP_lit11";
5181 return "DW_OP_lit12";
5183 return "DW_OP_lit13";
5185 return "DW_OP_lit14";
5187 return "DW_OP_lit15";
5189 return "DW_OP_lit16";
5191 return "DW_OP_lit17";
5193 return "DW_OP_lit18";
5195 return "DW_OP_lit19";
5197 return "DW_OP_lit20";
5199 return "DW_OP_lit21";
5201 return "DW_OP_lit22";
5203 return "DW_OP_lit23";
5205 return "DW_OP_lit24";
5207 return "DW_OP_lit25";
5209 return "DW_OP_lit26";
5211 return "DW_OP_lit27";
5213 return "DW_OP_lit28";
5215 return "DW_OP_lit29";
5217 return "DW_OP_lit30";
5219 return "DW_OP_lit31";
5221 return "DW_OP_reg0";
5223 return "DW_OP_reg1";
5225 return "DW_OP_reg2";
5227 return "DW_OP_reg3";
5229 return "DW_OP_reg4";
5231 return "DW_OP_reg5";
5233 return "DW_OP_reg6";
5235 return "DW_OP_reg7";
5237 return "DW_OP_reg8";
5239 return "DW_OP_reg9";
5241 return "DW_OP_reg10";
5243 return "DW_OP_reg11";
5245 return "DW_OP_reg12";
5247 return "DW_OP_reg13";
5249 return "DW_OP_reg14";
5251 return "DW_OP_reg15";
5253 return "DW_OP_reg16";
5255 return "DW_OP_reg17";
5257 return "DW_OP_reg18";
5259 return "DW_OP_reg19";
5261 return "DW_OP_reg20";
5263 return "DW_OP_reg21";
5265 return "DW_OP_reg22";
5267 return "DW_OP_reg23";
5269 return "DW_OP_reg24";
5271 return "DW_OP_reg25";
5273 return "DW_OP_reg26";
5275 return "DW_OP_reg27";
5277 return "DW_OP_reg28";
5279 return "DW_OP_reg29";
5281 return "DW_OP_reg30";
5283 return "DW_OP_reg31";
5285 return "DW_OP_breg0";
5287 return "DW_OP_breg1";
5289 return "DW_OP_breg2";
5291 return "DW_OP_breg3";
5293 return "DW_OP_breg4";
5295 return "DW_OP_breg5";
5297 return "DW_OP_breg6";
5299 return "DW_OP_breg7";
5301 return "DW_OP_breg8";
5303 return "DW_OP_breg9";
5305 return "DW_OP_breg10";
5307 return "DW_OP_breg11";
5309 return "DW_OP_breg12";
5311 return "DW_OP_breg13";
5313 return "DW_OP_breg14";
5315 return "DW_OP_breg15";
5317 return "DW_OP_breg16";
5319 return "DW_OP_breg17";
5321 return "DW_OP_breg18";
5323 return "DW_OP_breg19";
5325 return "DW_OP_breg20";
5327 return "DW_OP_breg21";
5329 return "DW_OP_breg22";
5331 return "DW_OP_breg23";
5333 return "DW_OP_breg24";
5335 return "DW_OP_breg25";
5337 return "DW_OP_breg26";
5339 return "DW_OP_breg27";
5341 return "DW_OP_breg28";
5343 return "DW_OP_breg29";
5345 return "DW_OP_breg30";
5347 return "DW_OP_breg31";
5349 return "DW_OP_regx";
5351 return "DW_OP_fbreg";
5353 return "DW_OP_bregx";
5355 return "DW_OP_piece";
5356 case DW_OP_deref_size
:
5357 return "DW_OP_deref_size";
5358 case DW_OP_xderef_size
:
5359 return "DW_OP_xderef_size";
5363 return "OP_<unknown>";
5368 dwarf_bool_name (mybool
)
5377 /* Convert a DWARF type code into its string name. */
5380 dwarf_type_encoding_name (enc
)
5381 register unsigned enc
;
5385 case DW_ATE_address
:
5386 return "DW_ATE_address";
5387 case DW_ATE_boolean
:
5388 return "DW_ATE_boolean";
5389 case DW_ATE_complex_float
:
5390 return "DW_ATE_complex_float";
5392 return "DW_ATE_float";
5394 return "DW_ATE_signed";
5395 case DW_ATE_signed_char
:
5396 return "DW_ATE_signed_char";
5397 case DW_ATE_unsigned
:
5398 return "DW_ATE_unsigned";
5399 case DW_ATE_unsigned_char
:
5400 return "DW_ATE_unsigned_char";
5402 return "DW_ATE_<unknown>";
5406 /* Convert a DWARF call frame info operation to its string name. */
5410 dwarf_cfi_name (cfi_opc
)
5411 register unsigned cfi_opc
;
5415 case DW_CFA_advance_loc
:
5416 return "DW_CFA_advance_loc";
5418 return "DW_CFA_offset";
5419 case DW_CFA_restore
:
5420 return "DW_CFA_restore";
5422 return "DW_CFA_nop";
5423 case DW_CFA_set_loc
:
5424 return "DW_CFA_set_loc";
5425 case DW_CFA_advance_loc1
:
5426 return "DW_CFA_advance_loc1";
5427 case DW_CFA_advance_loc2
:
5428 return "DW_CFA_advance_loc2";
5429 case DW_CFA_advance_loc4
:
5430 return "DW_CFA_advance_loc4";
5431 case DW_CFA_offset_extended
:
5432 return "DW_CFA_offset_extended";
5433 case DW_CFA_restore_extended
:
5434 return "DW_CFA_restore_extended";
5435 case DW_CFA_undefined
:
5436 return "DW_CFA_undefined";
5437 case DW_CFA_same_value
:
5438 return "DW_CFA_same_value";
5439 case DW_CFA_register
:
5440 return "DW_CFA_register";
5441 case DW_CFA_remember_state
:
5442 return "DW_CFA_remember_state";
5443 case DW_CFA_restore_state
:
5444 return "DW_CFA_restore_state";
5445 case DW_CFA_def_cfa
:
5446 return "DW_CFA_def_cfa";
5447 case DW_CFA_def_cfa_register
:
5448 return "DW_CFA_def_cfa_register";
5449 case DW_CFA_def_cfa_offset
:
5450 return "DW_CFA_def_cfa_offset";
5451 /* SGI/MIPS specific */
5452 case DW_CFA_MIPS_advance_loc8
:
5453 return "DW_CFA_MIPS_advance_loc8";
5455 return "DW_CFA_<unknown>";
5462 struct die_info
*die
;
5466 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5467 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5468 fprintf (stderr
, "\thas children: %s\n",
5469 dwarf_bool_name (die
->has_children
));
5471 fprintf (stderr
, "\tattributes:\n");
5472 for (i
= 0; i
< die
->num_attrs
; ++i
)
5474 fprintf (stderr
, "\t\t%s (%s) ",
5475 dwarf_attr_name (die
->attrs
[i
].name
),
5476 dwarf_form_name (die
->attrs
[i
].form
));
5477 switch (die
->attrs
[i
].form
)
5479 case DW_FORM_ref_addr
:
5481 fprintf (stderr
, "address: ");
5482 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5484 case DW_FORM_block2
:
5485 case DW_FORM_block4
:
5487 case DW_FORM_block1
:
5488 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5498 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5500 case DW_FORM_string
:
5501 fprintf (stderr
, "string: \"%s\"",
5502 DW_STRING (&die
->attrs
[i
])
5503 ? DW_STRING (&die
->attrs
[i
]) : "");
5506 if (DW_UNSND (&die
->attrs
[i
]))
5507 fprintf (stderr
, "flag: TRUE");
5509 fprintf (stderr
, "flag: FALSE");
5511 case DW_FORM_strp
: /* we do not support separate string
5513 case DW_FORM_indirect
: /* we do not handle indirect yet */
5514 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5516 fprintf (stderr
, "unsupported attribute form: %d.",
5517 die
->attrs
[i
].form
);
5519 fprintf (stderr
, "\n");
5525 struct die_info
*die
;
5535 store_in_ref_table (offset
, die
)
5536 unsigned int offset
;
5537 struct die_info
*die
;
5540 struct die_info
*old
;
5542 h
= (offset
% REF_HASH_SIZE
);
5543 old
= die_ref_table
[h
];
5544 die
->next_ref
= old
;
5545 die_ref_table
[h
] = die
;
5550 dwarf2_empty_die_ref_table ()
5552 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5556 dwarf2_get_ref_die_offset (attr
)
5557 struct attribute
*attr
;
5559 unsigned int result
= 0;
5563 case DW_FORM_ref_addr
:
5564 result
= DW_ADDR (attr
);
5569 case DW_FORM_ref_udata
:
5570 result
= cu_header_offset
+ DW_UNSND (attr
);
5573 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5579 follow_die_ref (offset
)
5580 unsigned int offset
;
5582 struct die_info
*die
;
5585 h
= (offset
% REF_HASH_SIZE
);
5586 die
= die_ref_table
[h
];
5589 if (die
->offset
== offset
)
5593 die
= die
->next_ref
;
5598 static struct type
*
5599 dwarf2_fundamental_type (objfile
, typeid)
5600 struct objfile
*objfile
;
5603 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5605 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5609 /* Look for this particular type in the fundamental type vector. If
5610 one is not found, create and install one appropriate for the
5611 current language and the current target machine. */
5613 if (ftypes
[typeid] == NULL
)
5615 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5618 return (ftypes
[typeid]);
5621 /* Decode simple location descriptions.
5622 Given a pointer to a dwarf block that defines a location, compute
5623 the location and return the value.
5625 FIXME: This is a kludge until we figure out a better
5626 way to handle the location descriptions.
5627 Gdb's design does not mesh well with the DWARF2 notion of a location
5628 computing interpreter, which is a shame because the flexibility goes unused.
5629 FIXME: Implement more operations as necessary.
5631 A location description containing no operations indicates that the
5632 object is optimized out. The global optimized_out flag is set for
5633 those, the return value is meaningless.
5635 When the result is a register number, the global isreg flag is set,
5636 otherwise it is cleared.
5638 When the result is a base register offset, the global offreg flag is set
5639 and the register number is returned in basereg, otherwise it is cleared.
5641 When the DW_OP_fbreg operation is encountered without a corresponding
5642 DW_AT_frame_base attribute, the global islocal flag is set.
5643 Hopefully the machine dependent code knows how to set up a virtual
5644 frame pointer for the local references.
5646 Note that stack[0] is unused except as a default error return.
5647 Note that stack overflow is not yet handled. */
5650 decode_locdesc (blk
, objfile
)
5651 struct dwarf_block
*blk
;
5652 struct objfile
*objfile
;
5655 int size
= blk
->size
;
5656 char *data
= blk
->data
;
5657 CORE_ADDR stack
[64];
5659 unsigned int bytes_read
, unsnd
;
5710 stack
[++stacki
] = op
- DW_OP_reg0
;
5715 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5717 #if defined(HARRIS_TARGET) && defined(_M88K)
5718 /* The Harris 88110 gdb ports have long kept their special reg
5719 numbers between their gp-regs and their x-regs. This is
5720 not how our dwarf is generated. Punt. */
5723 stack
[++stacki
] = unsnd
;
5759 basereg
= op
- DW_OP_breg0
;
5760 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5766 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5768 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5773 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5775 if (frame_base_reg
>= 0)
5778 basereg
= frame_base_reg
;
5779 stack
[stacki
] += frame_base_offset
;
5783 complain (&dwarf2_missing_at_frame_base
);
5789 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5794 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5799 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5804 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5809 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5814 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5819 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5824 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5830 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5835 stack
[stacki
- 1] += stack
[stacki
];
5839 case DW_OP_plus_uconst
:
5840 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5845 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5851 /* If we're not the last op, then we definitely can't encode
5852 this using GDB's address_class enum. */
5854 complain (&dwarf2_complex_location_expr
);
5858 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5859 return (stack
[stacki
]);
5862 return (stack
[stacki
]);
5865 /* memory allocation interface */
5869 dwarf2_free_tmp_obstack (ignore
)
5872 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5875 static struct dwarf_block
*
5876 dwarf_alloc_block ()
5878 struct dwarf_block
*blk
;
5880 blk
= (struct dwarf_block
*)
5881 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5885 static struct abbrev_info
*
5886 dwarf_alloc_abbrev ()
5888 struct abbrev_info
*abbrev
;
5890 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5891 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5895 static struct die_info
*
5898 struct die_info
*die
;
5900 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5901 memset (die
, 0, sizeof (struct die_info
));