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
*,
567 struct section_offsets
*,
571 static void dwarf2_build_psymtabs_hard
PARAMS ((struct objfile
*,
572 struct section_offsets
*,
575 static char *scan_partial_symbols
PARAMS ((char *, struct objfile
*,
576 CORE_ADDR
*, CORE_ADDR
*));
578 static void add_partial_symbol
PARAMS ((struct partial_die_info
*,
581 static void dwarf2_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
583 static void psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
585 static char *dwarf2_read_section
PARAMS ((struct objfile
*, file_ptr
,
588 static void dwarf2_read_abbrevs
PARAMS ((bfd
*, unsigned int));
590 static void dwarf2_empty_abbrev_table
PARAMS ((PTR
));
592 static struct abbrev_info
*dwarf2_lookup_abbrev
PARAMS ((unsigned int));
594 static char *read_partial_die
PARAMS ((struct partial_die_info
*,
595 bfd
*, char *, int *));
597 static char *read_full_die
PARAMS ((struct die_info
**, bfd
*, char *));
599 static char *read_attribute
PARAMS ((struct attribute
*, struct attr_abbrev
*,
602 static unsigned int read_1_byte
PARAMS ((bfd
*, char *));
604 static int read_1_signed_byte
PARAMS ((bfd
*, char *));
606 static unsigned int read_2_bytes
PARAMS ((bfd
*, char *));
608 static unsigned int read_4_bytes
PARAMS ((bfd
*, char *));
610 static unsigned int read_8_bytes
PARAMS ((bfd
*, char *));
612 static CORE_ADDR read_address
PARAMS ((bfd
*, char *));
614 static char *read_n_bytes
PARAMS ((bfd
*, char *, unsigned int));
616 static char *read_string
PARAMS ((bfd
*, char *, unsigned int *));
618 static unsigned int read_unsigned_leb128
PARAMS ((bfd
*, char *,
621 static int read_signed_leb128
PARAMS ((bfd
*, char *, unsigned int *));
623 static void set_cu_language
PARAMS ((unsigned int));
625 static struct attribute
*dwarf_attr
PARAMS ((struct die_info
*,
628 static void dwarf_decode_lines
PARAMS ((unsigned int, char *, bfd
*));
630 static void dwarf2_start_subfile
PARAMS ((char *, char *));
632 static struct symbol
*new_symbol
PARAMS ((struct die_info
*, struct type
*,
635 static void dwarf2_const_value
PARAMS ((struct attribute
*, struct symbol
*,
638 static struct type
*die_type
PARAMS ((struct die_info
*, struct objfile
*));
640 static struct type
*die_containing_type
PARAMS ((struct die_info
*,
644 static struct type
*type_at_offset
PARAMS ((unsigned int, struct objfile
*));
647 static struct type
*tag_type_to_type
PARAMS ((struct die_info
*,
650 static void read_type_die
PARAMS ((struct die_info
*, struct objfile
*));
652 static void read_typedef
PARAMS ((struct die_info
*, struct objfile
*));
654 static void read_base_type
PARAMS ((struct die_info
*, struct objfile
*));
656 static void read_file_scope
PARAMS ((struct die_info
*, struct objfile
*));
658 static void read_func_scope
PARAMS ((struct die_info
*, struct objfile
*));
660 static void read_lexical_block_scope
PARAMS ((struct die_info
*,
663 static int dwarf2_get_pc_bounds
PARAMS ((struct die_info
*,
664 CORE_ADDR
*, CORE_ADDR
*,
667 static void dwarf2_add_field
PARAMS ((struct field_info
*, struct die_info
*,
670 static void dwarf2_attach_fields_to_type
PARAMS ((struct field_info
*,
674 static char *skip_member_fn_name
PARAMS ((char *));
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
, section_offsets
, mainline
)
844 struct objfile
*objfile
;
845 struct section_offsets
*section_offsets
;
849 /* We definitely need the .debug_info and .debug_abbrev sections */
851 dwarf_info_buffer
= dwarf2_read_section (objfile
,
854 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
857 dwarf_line_buffer
= dwarf2_read_section (objfile
,
861 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
862 objfile
->static_psymbols
.size
== 0)
864 init_psymbol_list (objfile
, 1024);
868 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
870 /* Things are significanlty easier if we have .debug_aranges and
871 .debug_pubnames sections */
873 dwarf2_build_psymtabs_easy (objfile
, section_offsets
, mainline
);
877 /* only test this case for now */
879 /* In this case we have to work a bit harder */
880 dwarf2_build_psymtabs_hard (objfile
, section_offsets
, mainline
);
885 /* Build the partial symbol table from the information in the
886 .debug_pubnames and .debug_aranges sections. */
889 dwarf2_build_psymtabs_easy (objfile
, section_offsets
, mainline
)
890 struct objfile
*objfile
;
891 struct section_offsets
*section_offsets
;
894 bfd
*abfd
= objfile
->obfd
;
895 char *aranges_buffer
, *pubnames_buffer
;
896 char *aranges_ptr
, *pubnames_ptr
;
897 unsigned int entry_length
, version
, info_offset
, info_size
;
899 pubnames_buffer
= dwarf2_read_section (objfile
,
900 dwarf_pubnames_offset
,
901 dwarf_pubnames_size
);
902 pubnames_ptr
= pubnames_buffer
;
903 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
905 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
907 version
= read_1_byte (abfd
, pubnames_ptr
);
909 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
911 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
915 aranges_buffer
= dwarf2_read_section (objfile
,
916 dwarf_aranges_offset
,
922 /* Build the partial symbol table by doing a quick pass through the
923 .debug_info and .debug_abbrev sections. */
926 dwarf2_build_psymtabs_hard (objfile
, section_offsets
, mainline
)
927 struct objfile
*objfile
;
928 struct section_offsets
*section_offsets
;
931 /* Instead of reading this into a big buffer, we should probably use
932 mmap() on architectures that support it. (FIXME) */
933 bfd
*abfd
= objfile
->obfd
;
934 char *info_ptr
, *abbrev_ptr
;
935 char *beg_of_comp_unit
;
936 struct comp_unit_head cu_header
;
937 struct partial_die_info comp_unit_die
;
938 struct partial_symtab
*pst
;
939 struct cleanup
*back_to
;
940 int comp_unit_has_pc_info
;
941 CORE_ADDR lowpc
, highpc
;
943 /* Number of bytes of any addresses that are signficant */
944 address_significant_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
946 info_ptr
= dwarf_info_buffer
;
947 abbrev_ptr
= dwarf_abbrev_buffer
;
949 obstack_init (&dwarf2_tmp_obstack
);
950 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
952 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
953 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
955 beg_of_comp_unit
= info_ptr
;
956 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
958 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
960 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
962 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
964 address_size
= cu_header
.addr_size
;
966 if (cu_header
.version
!= 2)
968 error ("Dwarf Error: wrong version in compilation unit header.");
971 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
973 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
974 (long) cu_header
.abbrev_offset
,
975 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
978 if (beg_of_comp_unit
+ cu_header
.length
+ 4
979 > dwarf_info_buffer
+ dwarf_info_size
)
981 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
982 (long) cu_header
.length
,
983 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
986 if (address_size
< address_significant_size
)
988 error ("Dwarf Error: bad address size (%ld) in compilation unit header (offset 0x%lx + 11).",
989 (long) cu_header
.addr_size
,
990 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
993 /* Read the abbrevs for this compilation unit into a table */
994 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
995 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
997 /* Read the compilation unit die */
998 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
999 info_ptr
, &comp_unit_has_pc_info
);
1001 /* Set the language we're debugging */
1002 set_cu_language (comp_unit_die
.language
);
1004 /* Allocate a new partial symbol table structure */
1005 pst
= start_psymtab_common (objfile
, section_offsets
,
1006 comp_unit_die
.name
? comp_unit_die
.name
: "",
1007 comp_unit_die
.lowpc
,
1008 objfile
->global_psymbols
.next
,
1009 objfile
->static_psymbols
.next
);
1011 pst
->read_symtab_private
= (char *)
1012 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1013 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1014 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1015 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1016 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1017 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1018 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1019 baseaddr
= ANOFFSET (section_offsets
, 0);
1021 /* Store the function that reads in the rest of the symbol table */
1022 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1024 /* Check if comp unit has_children.
1025 If so, read the rest of the partial symbols from this comp unit.
1026 If not, there's no more debug_info for this comp unit. */
1027 if (comp_unit_die
.has_children
)
1029 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
1031 /* If the compilation unit didn't have an explicit address range,
1032 then use the information extracted from its child dies. */
1033 if (!comp_unit_has_pc_info
)
1035 comp_unit_die
.lowpc
= lowpc
;
1036 comp_unit_die
.highpc
= highpc
;
1039 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1040 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1042 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1043 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1044 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1045 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1046 sort_pst_symbols (pst
);
1048 /* If there is already a psymtab or symtab for a file of this
1049 name, remove it. (If there is a symtab, more drastic things
1050 also happen.) This happens in VxWorks. */
1051 free_named_symtabs (pst
->filename
);
1053 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1055 do_cleanups (back_to
);
1058 /* Read in all interesting dies to the end of the compilation unit. */
1061 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1063 struct objfile
*objfile
;
1067 bfd
*abfd
= objfile
->obfd
;
1068 struct partial_die_info pdi
;
1070 /* This function is called after we've read in the comp_unit_die in
1071 order to read its children. We start the nesting level at 1 since
1072 we have pushed 1 level down in order to read the comp unit's children.
1073 The comp unit itself is at level 0, so we stop reading when we pop
1074 back to that level. */
1076 int nesting_level
= 1;
1079 *lowpc
= ((CORE_ADDR
) - 1);
1080 *highpc
= ((CORE_ADDR
) 0);
1082 while (nesting_level
)
1084 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1090 case DW_TAG_subprogram
:
1093 if (pdi
.lowpc
< *lowpc
)
1097 if (pdi
.highpc
> *highpc
)
1099 *highpc
= pdi
.highpc
;
1101 if ((pdi
.is_external
|| nesting_level
== 1)
1102 && !pdi
.is_declaration
)
1104 add_partial_symbol (&pdi
, objfile
);
1108 case DW_TAG_variable
:
1109 case DW_TAG_typedef
:
1110 case DW_TAG_class_type
:
1111 case DW_TAG_structure_type
:
1112 case DW_TAG_union_type
:
1113 case DW_TAG_enumeration_type
:
1114 if ((pdi
.is_external
|| nesting_level
== 1)
1115 && !pdi
.is_declaration
)
1117 add_partial_symbol (&pdi
, objfile
);
1120 case DW_TAG_enumerator
:
1121 /* File scope enumerators are added to the partial symbol
1123 if (nesting_level
== 2)
1124 add_partial_symbol (&pdi
, objfile
);
1126 case DW_TAG_base_type
:
1127 /* File scope base type definitions are added to the partial
1129 if (nesting_level
== 1)
1130 add_partial_symbol (&pdi
, objfile
);
1137 /* If the die has a sibling, skip to the sibling.
1138 Do not skip enumeration types, we want to record their
1140 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1142 info_ptr
= pdi
.sibling
;
1144 else if (pdi
.has_children
)
1146 /* Die has children, but the optional DW_AT_sibling attribute
1157 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1158 from `maint check'. */
1159 if (*lowpc
== ((CORE_ADDR
) - 1))
1165 add_partial_symbol (pdi
, objfile
)
1166 struct partial_die_info
*pdi
;
1167 struct objfile
*objfile
;
1173 case DW_TAG_subprogram
:
1174 if (pdi
->is_external
)
1176 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1177 mst_text, objfile); */
1178 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1179 VAR_NAMESPACE
, LOC_BLOCK
,
1180 &objfile
->global_psymbols
,
1181 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1185 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1186 mst_file_text, objfile); */
1187 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1188 VAR_NAMESPACE
, LOC_BLOCK
,
1189 &objfile
->static_psymbols
,
1190 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1193 case DW_TAG_variable
:
1194 if (pdi
->is_external
)
1197 Don't enter into the minimal symbol tables as there is
1198 a minimal symbol table entry from the ELF symbols already.
1199 Enter into partial symbol table if it has a location
1200 descriptor or a type.
1201 If the location descriptor is missing, new_symbol will create
1202 a LOC_UNRESOLVED symbol, the address of the variable will then
1203 be determined from the minimal symbol table whenever the variable
1205 The address for the partial symbol table entry is not
1206 used by GDB, but it comes in handy for debugging partial symbol
1210 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1211 if (pdi
->locdesc
|| pdi
->has_type
)
1212 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1213 VAR_NAMESPACE
, LOC_STATIC
,
1214 &objfile
->global_psymbols
,
1215 0, addr
+ baseaddr
, cu_language
, objfile
);
1219 /* Static Variable. Skip symbols without location descriptors. */
1220 if (pdi
->locdesc
== NULL
)
1222 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1223 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1224 mst_file_data, objfile); */
1225 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1226 VAR_NAMESPACE
, LOC_STATIC
,
1227 &objfile
->static_psymbols
,
1228 0, addr
+ baseaddr
, cu_language
, objfile
);
1231 case DW_TAG_typedef
:
1232 case DW_TAG_base_type
:
1233 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1234 VAR_NAMESPACE
, LOC_TYPEDEF
,
1235 &objfile
->static_psymbols
,
1236 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1238 case DW_TAG_class_type
:
1239 case DW_TAG_structure_type
:
1240 case DW_TAG_union_type
:
1241 case DW_TAG_enumeration_type
:
1242 /* Skip aggregate types without children, these are external
1244 if (pdi
->has_children
== 0)
1246 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1247 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1248 &objfile
->static_psymbols
,
1249 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1251 if (cu_language
== language_cplus
)
1253 /* For C++, these implicitly act as typedefs as well. */
1254 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1255 VAR_NAMESPACE
, LOC_TYPEDEF
,
1256 &objfile
->static_psymbols
,
1257 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1260 case DW_TAG_enumerator
:
1261 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1262 VAR_NAMESPACE
, LOC_CONST
,
1263 &objfile
->static_psymbols
,
1264 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1271 /* Expand this partial symbol table into a full symbol table. */
1274 dwarf2_psymtab_to_symtab (pst
)
1275 struct partial_symtab
*pst
;
1277 /* FIXME: This is barely more than a stub. */
1282 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1288 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1289 gdb_flush (gdb_stdout
);
1292 psymtab_to_symtab_1 (pst
);
1294 /* Finish up the debug error message. */
1296 printf_filtered ("done.\n");
1302 psymtab_to_symtab_1 (pst
)
1303 struct partial_symtab
*pst
;
1305 struct objfile
*objfile
= pst
->objfile
;
1306 bfd
*abfd
= objfile
->obfd
;
1307 struct comp_unit_head cu_header
;
1308 struct die_info
*dies
;
1309 unsigned long offset
;
1310 CORE_ADDR lowpc
, highpc
;
1311 struct die_info
*child_die
;
1313 struct symtab
*symtab
;
1314 struct cleanup
*back_to
;
1316 /* Set local variables from the partial symbol table info. */
1317 offset
= DWARF_INFO_OFFSET (pst
);
1318 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1319 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1320 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1321 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1322 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1323 cu_header_offset
= offset
;
1324 info_ptr
= dwarf_info_buffer
+ offset
;
1326 obstack_init (&dwarf2_tmp_obstack
);
1327 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1330 make_cleanup (really_free_pendings
, NULL
);
1332 /* read in the comp_unit header */
1333 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1335 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1337 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1339 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1342 /* Read the abbrevs for this compilation unit */
1343 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1344 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1346 dies
= read_comp_unit (info_ptr
, abfd
);
1348 make_cleanup ((make_cleanup_func
) free_die_list
, dies
);
1350 /* Do line number decoding in read_file_scope () */
1351 process_die (dies
, objfile
);
1353 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1355 /* Some compilers don't define a DW_AT_high_pc attribute for
1356 the compilation unit. If the DW_AT_high_pc is missing,
1357 synthesize it, by scanning the DIE's below the compilation unit. */
1359 if (dies
->has_children
)
1361 child_die
= dies
->next
;
1362 while (child_die
&& child_die
->tag
)
1364 if (child_die
->tag
== DW_TAG_subprogram
)
1366 CORE_ADDR low
, high
;
1368 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1370 highpc
= max (highpc
, high
);
1373 child_die
= sibling_die (child_die
);
1377 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1379 /* Set symtab language to language from DW_AT_language.
1380 If the compilation is from a C file generated by language preprocessors,
1381 do not set the language if it was already deduced by start_subfile. */
1383 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1385 symtab
->language
= cu_language
;
1387 pst
->symtab
= symtab
;
1389 sort_symtab_syms (pst
->symtab
);
1391 do_cleanups (back_to
);
1394 /* Process a die and its children. */
1397 process_die (die
, objfile
)
1398 struct die_info
*die
;
1399 struct objfile
*objfile
;
1403 case DW_TAG_padding
:
1405 case DW_TAG_compile_unit
:
1406 read_file_scope (die
, objfile
);
1408 case DW_TAG_subprogram
:
1409 read_subroutine_type (die
, objfile
);
1410 read_func_scope (die
, objfile
);
1412 case DW_TAG_inlined_subroutine
:
1413 /* FIXME: These are ignored for now.
1414 They could be used to set breakpoints on all inlined instances
1415 of a function and make GDB `next' properly over inlined functions. */
1417 case DW_TAG_lexical_block
:
1418 read_lexical_block_scope (die
, objfile
);
1420 case DW_TAG_class_type
:
1421 case DW_TAG_structure_type
:
1422 case DW_TAG_union_type
:
1423 read_structure_scope (die
, objfile
);
1425 case DW_TAG_enumeration_type
:
1426 read_enumeration (die
, objfile
);
1428 case DW_TAG_subroutine_type
:
1429 read_subroutine_type (die
, objfile
);
1431 case DW_TAG_array_type
:
1432 read_array_type (die
, objfile
);
1434 case DW_TAG_pointer_type
:
1435 read_tag_pointer_type (die
, objfile
);
1437 case DW_TAG_ptr_to_member_type
:
1438 read_tag_ptr_to_member_type (die
, objfile
);
1440 case DW_TAG_reference_type
:
1441 read_tag_reference_type (die
, objfile
);
1443 case DW_TAG_string_type
:
1444 read_tag_string_type (die
, objfile
);
1446 case DW_TAG_base_type
:
1447 read_base_type (die
, objfile
);
1448 if (dwarf_attr (die
, DW_AT_name
))
1450 /* Add a typedef symbol for the base type definition. */
1451 new_symbol (die
, die
->type
, objfile
);
1454 case DW_TAG_common_block
:
1455 read_common_block (die
, objfile
);
1457 case DW_TAG_common_inclusion
:
1460 new_symbol (die
, NULL
, objfile
);
1466 read_file_scope (die
, objfile
)
1467 struct die_info
*die
;
1468 struct objfile
*objfile
;
1470 unsigned int line_offset
= 0;
1471 CORE_ADDR lowpc
= ((CORE_ADDR
) - 1);
1472 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1473 struct attribute
*attr
;
1474 char *name
= "<unknown>";
1475 char *comp_dir
= NULL
;
1476 struct die_info
*child_die
;
1477 bfd
*abfd
= objfile
->obfd
;
1479 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1481 if (die
->has_children
)
1483 child_die
= die
->next
;
1484 while (child_die
&& child_die
->tag
)
1486 if (child_die
->tag
== DW_TAG_subprogram
)
1488 CORE_ADDR low
, high
;
1490 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1492 lowpc
= min (lowpc
, low
);
1493 highpc
= max (highpc
, high
);
1496 child_die
= sibling_die (child_die
);
1501 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1502 from finish_block. */
1503 if (lowpc
== ((CORE_ADDR
) - 1))
1508 attr
= dwarf_attr (die
, DW_AT_name
);
1511 name
= DW_STRING (attr
);
1513 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1516 comp_dir
= DW_STRING (attr
);
1519 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1520 directory, get rid of it. */
1521 char *cp
= strchr (comp_dir
, ':');
1523 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1528 if (objfile
->ei
.entry_point
>= lowpc
&&
1529 objfile
->ei
.entry_point
< highpc
)
1531 objfile
->ei
.entry_file_lowpc
= lowpc
;
1532 objfile
->ei
.entry_file_highpc
= highpc
;
1535 attr
= dwarf_attr (die
, DW_AT_language
);
1538 set_cu_language (DW_UNSND (attr
));
1541 /* We assume that we're processing GCC output. */
1542 processing_gcc_compilation
= 2;
1544 /* FIXME:Do something here. */
1545 if (dip
->at_producer
!= NULL
)
1547 handle_producer (dip
->at_producer
);
1551 /* The compilation unit may be in a different language or objfile,
1552 zero out all remembered fundamental types. */
1553 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1555 start_symtab (name
, comp_dir
, lowpc
);
1556 record_debugformat ("DWARF 2");
1558 /* Decode line number information if present. */
1559 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1562 line_offset
= DW_UNSND (attr
);
1563 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1566 /* Process all dies in compilation unit. */
1567 if (die
->has_children
)
1569 child_die
= die
->next
;
1570 while (child_die
&& child_die
->tag
)
1572 process_die (child_die
, objfile
);
1573 child_die
= sibling_die (child_die
);
1579 read_func_scope (die
, objfile
)
1580 struct die_info
*die
;
1581 struct objfile
*objfile
;
1583 register struct context_stack
*new;
1586 struct die_info
*child_die
;
1587 struct attribute
*attr
;
1590 name
= dwarf2_linkage_name (die
);
1592 /* Ignore functions with missing or empty names and functions with
1593 missing or invalid low and high pc attributes. */
1594 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1600 if (objfile
->ei
.entry_point
>= lowpc
&&
1601 objfile
->ei
.entry_point
< highpc
)
1603 objfile
->ei
.entry_func_lowpc
= lowpc
;
1604 objfile
->ei
.entry_func_highpc
= highpc
;
1607 if (STREQ (name
, "main")) /* FIXME: hardwired name */
1609 objfile
->ei
.main_func_lowpc
= lowpc
;
1610 objfile
->ei
.main_func_highpc
= highpc
;
1613 /* Decode DW_AT_frame_base location descriptor if present, keep result
1614 for DW_OP_fbreg operands in decode_locdesc. */
1615 frame_base_reg
= -1;
1616 frame_base_offset
= 0;
1617 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1620 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1622 complain (&dwarf2_unsupported_at_frame_base
, name
);
1624 frame_base_reg
= addr
;
1627 frame_base_reg
= basereg
;
1628 frame_base_offset
= addr
;
1631 complain (&dwarf2_unsupported_at_frame_base
, name
);
1634 new = push_context (0, lowpc
);
1635 new->name
= new_symbol (die
, die
->type
, objfile
);
1636 list_in_scope
= &local_symbols
;
1638 if (die
->has_children
)
1640 child_die
= die
->next
;
1641 while (child_die
&& child_die
->tag
)
1643 process_die (child_die
, objfile
);
1644 child_die
= sibling_die (child_die
);
1648 new = pop_context ();
1649 /* Make a block for the local symbols within. */
1650 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1651 lowpc
, highpc
, objfile
);
1652 list_in_scope
= &file_symbols
;
1655 /* Process all the DIES contained within a lexical block scope. Start
1656 a new scope, process the dies, and then close the scope. */
1659 read_lexical_block_scope (die
, objfile
)
1660 struct die_info
*die
;
1661 struct objfile
*objfile
;
1663 register struct context_stack
*new;
1664 CORE_ADDR lowpc
, highpc
;
1665 struct die_info
*child_die
;
1667 /* Ignore blocks with missing or invalid low and high pc attributes. */
1668 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1673 push_context (0, lowpc
);
1674 if (die
->has_children
)
1676 child_die
= die
->next
;
1677 while (child_die
&& child_die
->tag
)
1679 process_die (child_die
, objfile
);
1680 child_die
= sibling_die (child_die
);
1683 new = pop_context ();
1685 if (local_symbols
!= NULL
)
1687 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1690 local_symbols
= new->locals
;
1693 /* Get low and high pc attributes from a die.
1694 Return 1 if the attributes are present and valid, otherwise, return 0. */
1697 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1698 struct die_info
*die
;
1701 struct objfile
*objfile
;
1703 struct attribute
*attr
;
1707 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1709 low
= DW_ADDR (attr
);
1712 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1714 high
= DW_ADDR (attr
);
1721 /* When using the GNU linker, .gnu.linkonce. sections are used to
1722 eliminate duplicate copies of functions and vtables and such.
1723 The linker will arbitrarily choose one and discard the others.
1724 The AT_*_pc values for such functions refer to local labels in
1725 these sections. If the section from that file was discarded, the
1726 labels are not in the output, so the relocs get a value of 0.
1727 If this is a discarded function, mark the pc bounds as invalid,
1728 so that GDB will ignore it. */
1729 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1737 /* Add an aggregate field to the field list. */
1740 dwarf2_add_field (fip
, die
, objfile
)
1741 struct field_info
*fip
;
1742 struct die_info
*die
;
1743 struct objfile
*objfile
;
1745 struct nextfield
*new_field
;
1746 struct attribute
*attr
;
1748 char *fieldname
= "";
1750 /* Allocate a new field list entry and link it in. */
1751 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1752 make_cleanup (free
, new_field
);
1753 memset (new_field
, 0, sizeof (struct nextfield
));
1754 new_field
->next
= fip
->fields
;
1755 fip
->fields
= new_field
;
1758 /* Handle accessibility and virtuality of field.
1759 The default accessibility for members is public, the default
1760 accessibility for inheritance is private. */
1761 if (die
->tag
!= DW_TAG_inheritance
)
1762 new_field
->accessibility
= DW_ACCESS_public
;
1764 new_field
->accessibility
= DW_ACCESS_private
;
1765 new_field
->virtuality
= DW_VIRTUALITY_none
;
1767 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1769 new_field
->accessibility
= DW_UNSND (attr
);
1770 if (new_field
->accessibility
!= DW_ACCESS_public
)
1771 fip
->non_public_fields
= 1;
1772 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1774 new_field
->virtuality
= DW_UNSND (attr
);
1776 fp
= &new_field
->field
;
1777 if (die
->tag
== DW_TAG_member
)
1779 /* Get type of field. */
1780 fp
->type
= die_type (die
, objfile
);
1782 /* Get bit size of field (zero if none). */
1783 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1786 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1790 FIELD_BITSIZE (*fp
) = 0;
1793 /* Get bit offset of field. */
1794 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1797 FIELD_BITPOS (*fp
) =
1798 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1801 FIELD_BITPOS (*fp
) = 0;
1802 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1805 if (BITS_BIG_ENDIAN
)
1807 /* For big endian bits, the DW_AT_bit_offset gives the
1808 additional bit offset from the MSB of the containing
1809 anonymous object to the MSB of the field. We don't
1810 have to do anything special since we don't need to
1811 know the size of the anonymous object. */
1812 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1816 /* For little endian bits, compute the bit offset to the
1817 MSB of the anonymous object, subtract off the number of
1818 bits from the MSB of the field to the MSB of the
1819 object, and then subtract off the number of bits of
1820 the field itself. The result is the bit offset of
1821 the LSB of the field. */
1823 int bit_offset
= DW_UNSND (attr
);
1825 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1828 /* The size of the anonymous object containing
1829 the bit field is explicit, so use the
1830 indicated size (in bytes). */
1831 anonymous_size
= DW_UNSND (attr
);
1835 /* The size of the anonymous object containing
1836 the bit field must be inferred from the type
1837 attribute of the data member containing the
1839 anonymous_size
= TYPE_LENGTH (fp
->type
);
1841 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1842 - bit_offset
- FIELD_BITSIZE (*fp
);
1846 /* Get name of field. */
1847 attr
= dwarf_attr (die
, DW_AT_name
);
1848 if (attr
&& DW_STRING (attr
))
1849 fieldname
= DW_STRING (attr
);
1850 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1851 &objfile
->type_obstack
);
1853 /* Change accessibility for artificial fields (e.g. virtual table
1854 pointer or virtual base class pointer) to private. */
1855 if (dwarf_attr (die
, DW_AT_artificial
))
1857 new_field
->accessibility
= DW_ACCESS_private
;
1858 fip
->non_public_fields
= 1;
1861 else if (die
->tag
== DW_TAG_variable
)
1866 /* C++ static member.
1867 Get physical name, extract field name from physical name. */
1868 physname
= dwarf2_linkage_name (die
);
1869 if (physname
== NULL
)
1873 while (*cp
&& !is_cplus_marker (*cp
))
1877 if (*fieldname
== '\0')
1879 complain (&dwarf2_bad_static_member_name
, physname
);
1882 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1883 &objfile
->type_obstack
));
1884 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1885 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1886 &objfile
->type_obstack
);
1888 else if (die
->tag
== DW_TAG_inheritance
)
1890 /* C++ base class field. */
1891 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1893 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1894 FIELD_BITSIZE (*fp
) = 0;
1895 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1896 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1897 fip
->nbaseclasses
++;
1901 /* Create the vector of fields, and attach it to the type. */
1904 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1905 struct field_info
*fip
;
1907 struct objfile
*objfile
;
1909 int nfields
= fip
->nfields
;
1911 /* Record the field count, allocate space for the array of fields,
1912 and create blank accessibility bitfields if necessary. */
1913 TYPE_NFIELDS (type
) = nfields
;
1914 TYPE_FIELDS (type
) = (struct field
*)
1915 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1916 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1918 if (fip
->non_public_fields
)
1920 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1922 TYPE_FIELD_PRIVATE_BITS (type
) =
1923 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1924 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1926 TYPE_FIELD_PROTECTED_BITS (type
) =
1927 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1928 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1930 TYPE_FIELD_IGNORE_BITS (type
) =
1931 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1932 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1935 /* If the type has baseclasses, allocate and clear a bit vector for
1936 TYPE_FIELD_VIRTUAL_BITS. */
1937 if (fip
->nbaseclasses
)
1939 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1942 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1943 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1944 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1945 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1946 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1949 /* Copy the saved-up fields into the field vector. Start from the head
1950 of the list, adding to the tail of the field array, so that they end
1951 up in the same order in the array in which they were added to the list. */
1952 while (nfields
-- > 0)
1954 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1955 switch (fip
->fields
->accessibility
)
1957 case DW_ACCESS_private
:
1958 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1961 case DW_ACCESS_protected
:
1962 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1965 case DW_ACCESS_public
:
1969 /* Unknown accessibility. Complain and treat it as public. */
1971 complain (&dwarf2_unsupported_accessibility
,
1972 fip
->fields
->accessibility
);
1976 if (nfields
< fip
->nbaseclasses
)
1978 switch (fip
->fields
->virtuality
)
1980 case DW_VIRTUALITY_virtual
:
1981 case DW_VIRTUALITY_pure_virtual
:
1982 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1986 fip
->fields
= fip
->fields
->next
;
1990 /* Skip to the end of a member function name in a mangled name. */
1993 skip_member_fn_name (physname
)
1996 char *endname
= physname
;
1998 /* Skip over leading underscores. */
1999 while (*endname
== '_')
2002 /* Find two succesive underscores. */
2004 endname
= strchr (endname
, '_');
2005 while (endname
!= NULL
&& *++endname
!= '_');
2007 if (endname
== NULL
)
2009 complain (&dwarf2_bad_member_name_complaint
, physname
);
2014 /* Take care of trailing underscores. */
2015 if (endname
[1] != '_')
2021 /* Add a member function to the proper fieldlist. */
2024 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
2025 struct field_info
*fip
;
2026 struct die_info
*die
;
2028 struct objfile
*objfile
;
2030 struct attribute
*attr
;
2031 struct fnfieldlist
*flp
;
2033 struct fn_field
*fnp
;
2036 struct nextfnfield
*new_fnfield
;
2038 /* Extract member function name from mangled name. */
2039 physname
= dwarf2_linkage_name (die
);
2040 if (physname
== NULL
)
2042 if ((physname
[0] == '_' && physname
[1] == '_'
2043 && strchr ("0123456789Qt", physname
[2]))
2044 || DESTRUCTOR_PREFIX_P (physname
))
2046 /* Constructor and destructor field names are set to the name
2047 of the class, but without template parameter lists.
2048 The name might be missing for anonymous aggregates. */
2049 if (TYPE_TAG_NAME (type
))
2051 char *p
= strchr (TYPE_TAG_NAME (type
), '<');
2054 fieldname
= TYPE_TAG_NAME (type
);
2056 fieldname
= obsavestring (TYPE_TAG_NAME (type
),
2057 p
- TYPE_TAG_NAME (type
),
2058 &objfile
->type_obstack
);
2062 char *anon_name
= "";
2063 fieldname
= obsavestring (anon_name
, strlen (anon_name
),
2064 &objfile
->type_obstack
);
2069 char *endname
= skip_member_fn_name (physname
);
2071 /* Ignore member function if we were unable not extract the member
2073 if (endname
== physname
)
2075 fieldname
= obsavestring (physname
, endname
- physname
,
2076 &objfile
->type_obstack
);
2079 /* Look up member function name in fieldlist. */
2080 for (i
= 0; i
< fip
->nfnfields
; i
++)
2082 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2086 /* Create new list element if necessary. */
2087 if (i
< fip
->nfnfields
)
2088 flp
= &fip
->fnfieldlists
[i
];
2091 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2093 fip
->fnfieldlists
= (struct fnfieldlist
*)
2094 xrealloc (fip
->fnfieldlists
,
2095 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2096 * sizeof (struct fnfieldlist
));
2097 if (fip
->nfnfields
== 0)
2098 make_cleanup ((make_cleanup_func
) free_current_contents
,
2099 &fip
->fnfieldlists
);
2101 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2102 flp
->name
= fieldname
;
2108 /* Create a new member function field and chain it to the field list
2110 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2111 make_cleanup (free
, new_fnfield
);
2112 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2113 new_fnfield
->next
= flp
->head
;
2114 flp
->head
= new_fnfield
;
2117 /* Fill in the member function field info. */
2118 fnp
= &new_fnfield
->fnfield
;
2119 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2120 &objfile
->type_obstack
);
2121 fnp
->type
= alloc_type (objfile
);
2122 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2124 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2125 struct type
**arg_types
;
2126 int nparams
= TYPE_NFIELDS (die
->type
);
2129 /* Copy argument types from the subroutine type. */
2130 arg_types
= (struct type
**)
2131 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2132 for (iparams
= 0; iparams
< nparams
; iparams
++)
2133 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2135 /* Set last entry in argument type vector. */
2136 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2137 arg_types
[nparams
] = NULL
;
2139 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2141 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2143 /* Handle static member functions.
2144 Dwarf2 has no clean way to discern C++ static and non-static
2145 member functions. G++ helps GDB by marking the first
2146 parameter for non-static member functions (which is the
2147 this pointer) as artificial. We obtain this information
2148 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2149 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2150 fnp
->voffset
= VOFFSET_STATIC
;
2153 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2155 /* Get fcontext from DW_AT_containing_type if present. */
2156 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2157 fnp
->fcontext
= die_containing_type (die
, objfile
);
2159 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2160 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2162 /* Get accessibility. */
2163 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2166 switch (DW_UNSND (attr
))
2168 case DW_ACCESS_private
:
2169 fnp
->is_private
= 1;
2171 case DW_ACCESS_protected
:
2172 fnp
->is_protected
= 1;
2177 /* Get index in virtual function table if it is a virtual member function. */
2178 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2180 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2183 /* Create the vector of member function fields, and attach it to the type. */
2186 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2187 struct field_info
*fip
;
2189 struct objfile
*objfile
;
2191 struct fnfieldlist
*flp
;
2192 int total_length
= 0;
2195 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2196 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2197 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2199 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2201 struct nextfnfield
*nfp
= flp
->head
;
2202 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2205 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2206 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2207 fn_flp
->fn_fields
= (struct fn_field
*)
2208 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2209 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2210 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2212 total_length
+= flp
->length
;
2215 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2216 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2219 /* Called when we find the DIE that starts a structure or union scope
2220 (definition) to process all dies that define the members of the
2223 NOTE: we need to call struct_type regardless of whether or not the
2224 DIE has an at_name attribute, since it might be an anonymous
2225 structure or union. This gets the type entered into our set of
2228 However, if the structure is incomplete (an opaque struct/union)
2229 then suppress creating a symbol table entry for it since gdb only
2230 wants to find the one with the complete definition. Note that if
2231 it is complete, we just call new_symbol, which does it's own
2232 checking about whether the struct/union is anonymous or not (and
2233 suppresses creating a symbol table entry itself). */
2236 read_structure_scope (die
, objfile
)
2237 struct die_info
*die
;
2238 struct objfile
*objfile
;
2241 struct attribute
*attr
;
2243 type
= alloc_type (objfile
);
2245 INIT_CPLUS_SPECIFIC (type
);
2246 attr
= dwarf_attr (die
, DW_AT_name
);
2247 if (attr
&& DW_STRING (attr
))
2249 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2250 strlen (DW_STRING (attr
)),
2251 &objfile
->type_obstack
);
2254 if (die
->tag
== DW_TAG_structure_type
)
2256 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2258 else if (die
->tag
== DW_TAG_union_type
)
2260 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2264 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2266 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2269 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2272 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2276 TYPE_LENGTH (type
) = 0;
2279 /* We need to add the type field to the die immediately so we don't
2280 infinitely recurse when dealing with pointers to the structure
2281 type within the structure itself. */
2284 if (die
->has_children
)
2286 struct field_info fi
;
2287 struct die_info
*child_die
;
2288 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2290 memset (&fi
, 0, sizeof (struct field_info
));
2292 child_die
= die
->next
;
2294 while (child_die
&& child_die
->tag
)
2296 if (child_die
->tag
== DW_TAG_member
)
2298 dwarf2_add_field (&fi
, child_die
, objfile
);
2300 else if (child_die
->tag
== DW_TAG_variable
)
2302 /* C++ static member. */
2303 dwarf2_add_field (&fi
, child_die
, objfile
);
2305 else if (child_die
->tag
== DW_TAG_subprogram
)
2307 /* C++ member function. */
2308 process_die (child_die
, objfile
);
2309 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2311 else if (child_die
->tag
== DW_TAG_inheritance
)
2313 /* C++ base class field. */
2314 dwarf2_add_field (&fi
, child_die
, objfile
);
2318 process_die (child_die
, objfile
);
2320 child_die
= sibling_die (child_die
);
2323 /* Attach fields and member functions to the type. */
2325 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2328 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2330 /* Get the type which refers to the base class (possibly this
2331 class itself) which contains the vtable pointer for the current
2332 class from the DW_AT_containing_type attribute. */
2334 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2336 struct type
*t
= die_containing_type (die
, objfile
);
2338 TYPE_VPTR_BASETYPE (type
) = t
;
2341 static const char vptr_name
[] =
2342 {'_', 'v', 'p', 't', 'r', '\0'};
2345 /* Our own class provides vtbl ptr. */
2346 for (i
= TYPE_NFIELDS (t
) - 1;
2347 i
>= TYPE_N_BASECLASSES (t
);
2350 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2352 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2353 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2355 TYPE_VPTR_FIELDNO (type
) = i
;
2360 /* Complain if virtual function table field not found. */
2361 if (i
< TYPE_N_BASECLASSES (t
))
2362 complain (&dwarf2_vtbl_not_found_complaint
,
2363 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2367 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2372 new_symbol (die
, type
, objfile
);
2374 do_cleanups (back_to
);
2378 /* No children, must be stub. */
2379 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2385 /* Given a pointer to a die which begins an enumeration, process all
2386 the dies that define the members of the enumeration.
2388 This will be much nicer in draft 6 of the DWARF spec when our
2389 members will be dies instead squished into the DW_AT_element_list
2392 NOTE: We reverse the order of the element list. */
2395 read_enumeration (die
, objfile
)
2396 struct die_info
*die
;
2397 struct objfile
*objfile
;
2399 struct die_info
*child_die
;
2401 struct field
*fields
;
2402 struct attribute
*attr
;
2405 int unsigned_enum
= 1;
2407 type
= alloc_type (objfile
);
2409 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2410 attr
= dwarf_attr (die
, DW_AT_name
);
2411 if (attr
&& DW_STRING (attr
))
2413 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2414 strlen (DW_STRING (attr
)),
2415 &objfile
->type_obstack
);
2418 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2421 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2425 TYPE_LENGTH (type
) = 0;
2430 if (die
->has_children
)
2432 child_die
= die
->next
;
2433 while (child_die
&& child_die
->tag
)
2435 if (child_die
->tag
!= DW_TAG_enumerator
)
2437 process_die (child_die
, objfile
);
2441 attr
= dwarf_attr (child_die
, DW_AT_name
);
2444 sym
= new_symbol (child_die
, type
, objfile
);
2445 if (SYMBOL_VALUE (sym
) < 0)
2448 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2450 fields
= (struct field
*)
2452 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2453 * sizeof (struct field
));
2456 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2457 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2458 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2459 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2465 child_die
= sibling_die (child_die
);
2470 TYPE_NFIELDS (type
) = num_fields
;
2471 TYPE_FIELDS (type
) = (struct field
*)
2472 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2473 memcpy (TYPE_FIELDS (type
), fields
,
2474 sizeof (struct field
) * num_fields
);
2478 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2481 new_symbol (die
, type
, objfile
);
2484 /* Extract all information from a DW_TAG_array_type DIE and put it in
2485 the DIE's type field. For now, this only handles one dimensional
2489 read_array_type (die
, objfile
)
2490 struct die_info
*die
;
2491 struct objfile
*objfile
;
2493 struct die_info
*child_die
;
2494 struct type
*type
= NULL
;
2495 struct type
*element_type
, *range_type
, *index_type
;
2496 struct type
**range_types
= NULL
;
2497 struct attribute
*attr
;
2499 struct cleanup
*back_to
;
2501 /* Return if we've already decoded this type. */
2507 element_type
= die_type (die
, objfile
);
2509 /* Irix 6.2 native cc creates array types without children for
2510 arrays with unspecified length. */
2511 if (die
->has_children
== 0)
2513 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2514 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2515 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2519 back_to
= make_cleanup (null_cleanup
, NULL
);
2520 child_die
= die
->next
;
2521 while (child_die
&& child_die
->tag
)
2523 if (child_die
->tag
== DW_TAG_subrange_type
)
2525 unsigned int low
, high
;
2527 /* Default bounds to an array with unspecified length. */
2530 if (cu_language
== language_fortran
)
2532 /* FORTRAN implies a lower bound of 1, if not given. */
2536 index_type
= die_type (child_die
, objfile
);
2537 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2540 if (attr
->form
== DW_FORM_sdata
)
2542 low
= DW_SND (attr
);
2544 else if (attr
->form
== DW_FORM_udata
2545 || attr
->form
== DW_FORM_data1
2546 || attr
->form
== DW_FORM_data2
2547 || attr
->form
== DW_FORM_data4
)
2549 low
= DW_UNSND (attr
);
2553 complain (&dwarf2_non_const_array_bound_ignored
,
2554 dwarf_form_name (attr
->form
));
2556 die
->type
= lookup_pointer_type (element_type
);
2563 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2566 if (attr
->form
== DW_FORM_sdata
)
2568 high
= DW_SND (attr
);
2570 else if (attr
->form
== DW_FORM_udata
2571 || attr
->form
== DW_FORM_data1
2572 || attr
->form
== DW_FORM_data2
2573 || attr
->form
== DW_FORM_data4
)
2575 high
= DW_UNSND (attr
);
2577 else if (attr
->form
== DW_FORM_block1
)
2579 /* GCC encodes arrays with unspecified or dynamic length
2580 with a DW_FORM_block1 attribute.
2581 FIXME: GDB does not yet know how to handle dynamic
2582 arrays properly, treat them as arrays with unspecified
2588 complain (&dwarf2_non_const_array_bound_ignored
,
2589 dwarf_form_name (attr
->form
));
2591 die
->type
= lookup_pointer_type (element_type
);
2599 /* Create a range type and save it for array type creation. */
2600 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2602 range_types
= (struct type
**)
2603 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2604 * sizeof (struct type
*));
2606 make_cleanup ((make_cleanup_func
) free_current_contents
,
2609 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2611 child_die
= sibling_die (child_die
);
2614 /* Dwarf2 dimensions are output from left to right, create the
2615 necessary array types in backwards order. */
2616 type
= element_type
;
2618 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2620 do_cleanups (back_to
);
2622 /* Install the type in the die. */
2626 /* First cut: install each common block member as a global variable. */
2629 read_common_block (die
, objfile
)
2630 struct die_info
*die
;
2631 struct objfile
*objfile
;
2633 struct die_info
*child_die
;
2634 struct attribute
*attr
;
2636 CORE_ADDR base
= (CORE_ADDR
) 0;
2638 attr
= dwarf_attr (die
, DW_AT_location
);
2641 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2643 if (die
->has_children
)
2645 child_die
= die
->next
;
2646 while (child_die
&& child_die
->tag
)
2648 sym
= new_symbol (child_die
, NULL
, objfile
);
2649 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2652 SYMBOL_VALUE_ADDRESS (sym
) =
2653 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2654 add_symbol_to_list (sym
, &global_symbols
);
2656 child_die
= sibling_die (child_die
);
2661 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2662 the user defined type vector. */
2665 read_tag_pointer_type (die
, objfile
)
2666 struct die_info
*die
;
2667 struct objfile
*objfile
;
2670 struct attribute
*attr
;
2677 type
= lookup_pointer_type (die_type (die
, objfile
));
2678 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2681 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2685 TYPE_LENGTH (type
) = address_size
;
2690 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2691 the user defined type vector. */
2694 read_tag_ptr_to_member_type (die
, objfile
)
2695 struct die_info
*die
;
2696 struct objfile
*objfile
;
2699 struct type
*to_type
;
2700 struct type
*domain
;
2707 type
= alloc_type (objfile
);
2708 to_type
= die_type (die
, objfile
);
2709 domain
= die_containing_type (die
, objfile
);
2710 smash_to_member_type (type
, domain
, to_type
);
2715 /* Extract all information from a DW_TAG_reference_type DIE and add to
2716 the user defined type vector. */
2719 read_tag_reference_type (die
, objfile
)
2720 struct die_info
*die
;
2721 struct objfile
*objfile
;
2724 struct attribute
*attr
;
2731 type
= lookup_reference_type (die_type (die
, objfile
));
2732 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2735 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2739 TYPE_LENGTH (type
) = address_size
;
2745 read_tag_const_type (die
, objfile
)
2746 struct die_info
*die
;
2747 struct objfile
*objfile
;
2754 complain (&dwarf2_const_ignored
);
2755 die
->type
= die_type (die
, objfile
);
2759 read_tag_volatile_type (die
, objfile
)
2760 struct die_info
*die
;
2761 struct objfile
*objfile
;
2768 complain (&dwarf2_volatile_ignored
);
2769 die
->type
= die_type (die
, objfile
);
2772 /* Extract all information from a DW_TAG_string_type DIE and add to
2773 the user defined type vector. It isn't really a user defined type,
2774 but it behaves like one, with other DIE's using an AT_user_def_type
2775 attribute to reference it. */
2778 read_tag_string_type (die
, objfile
)
2779 struct die_info
*die
;
2780 struct objfile
*objfile
;
2782 struct type
*type
, *range_type
, *index_type
, *char_type
;
2783 struct attribute
*attr
;
2784 unsigned int length
;
2791 attr
= dwarf_attr (die
, DW_AT_string_length
);
2794 length
= DW_UNSND (attr
);
2800 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2801 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2802 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2803 type
= create_string_type (char_type
, range_type
);
2807 /* Handle DIES due to C code like:
2811 int (*funcp)(int a, long l);
2815 ('funcp' generates a DW_TAG_subroutine_type DIE)
2819 read_subroutine_type (die
, objfile
)
2820 struct die_info
*die
;
2821 struct objfile
*objfile
;
2823 struct type
*type
; /* Type that this function returns */
2824 struct type
*ftype
; /* Function that returns above type */
2825 struct attribute
*attr
;
2827 /* Decode the type that this subroutine returns */
2832 type
= die_type (die
, objfile
);
2833 ftype
= lookup_function_type (type
);
2835 /* All functions in C++ have prototypes. */
2836 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2837 if ((attr
&& (DW_UNSND (attr
) != 0))
2838 || cu_language
== language_cplus
)
2839 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2841 if (die
->has_children
)
2843 struct die_info
*child_die
;
2847 /* Count the number of parameters.
2848 FIXME: GDB currently ignores vararg functions, but knows about
2849 vararg member functions. */
2850 child_die
= die
->next
;
2851 while (child_die
&& child_die
->tag
)
2853 if (child_die
->tag
== DW_TAG_formal_parameter
)
2855 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2856 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2857 child_die
= sibling_die (child_die
);
2860 /* Allocate storage for parameters and fill them in. */
2861 TYPE_NFIELDS (ftype
) = nparams
;
2862 TYPE_FIELDS (ftype
) = (struct field
*)
2863 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2865 child_die
= die
->next
;
2866 while (child_die
&& child_die
->tag
)
2868 if (child_die
->tag
== DW_TAG_formal_parameter
)
2870 /* Dwarf2 has no clean way to discern C++ static and non-static
2871 member functions. G++ helps GDB by marking the first
2872 parameter for non-static member functions (which is the
2873 this pointer) as artificial. We pass this information
2874 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2875 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2877 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2879 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2880 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2883 child_die
= sibling_die (child_die
);
2891 read_typedef (die
, objfile
)
2892 struct die_info
*die
;
2893 struct objfile
*objfile
;
2899 struct attribute
*attr
;
2902 xtype
= die_type (die
, objfile
);
2904 type
= alloc_type (objfile
);
2905 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2906 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2907 TYPE_TARGET_TYPE (type
) = xtype
;
2908 attr
= dwarf_attr (die
, DW_AT_name
);
2909 if (attr
&& DW_STRING (attr
))
2910 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2911 strlen (DW_STRING (attr
)),
2912 &objfile
->type_obstack
);
2918 /* Find a representation of a given base type and install
2919 it in the TYPE field of the die. */
2922 read_base_type (die
, objfile
)
2923 struct die_info
*die
;
2924 struct objfile
*objfile
;
2927 struct attribute
*attr
;
2928 int encoding
= 0, size
= 0;
2930 /* If we've already decoded this die, this is a no-op. */
2936 attr
= dwarf_attr (die
, DW_AT_encoding
);
2939 encoding
= DW_UNSND (attr
);
2941 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2944 size
= DW_UNSND (attr
);
2946 attr
= dwarf_attr (die
, DW_AT_name
);
2947 if (attr
&& DW_STRING (attr
))
2949 enum type_code code
= TYPE_CODE_INT
;
2950 int is_unsigned
= 0;
2954 case DW_ATE_address
:
2955 /* Turn DW_ATE_address into a void * pointer. */
2956 code
= TYPE_CODE_PTR
;
2959 case DW_ATE_boolean
:
2960 code
= TYPE_CODE_BOOL
;
2963 case DW_ATE_complex_float
:
2964 code
= TYPE_CODE_COMPLEX
;
2967 code
= TYPE_CODE_FLT
;
2970 case DW_ATE_signed_char
:
2972 case DW_ATE_unsigned
:
2973 case DW_ATE_unsigned_char
:
2977 complain (&dwarf2_unsupported_at_encoding
,
2978 dwarf_type_encoding_name (encoding
));
2981 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2982 if (encoding
== DW_ATE_address
)
2983 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2987 type
= dwarf_base_type (encoding
, size
, objfile
);
2992 /* Read a whole compilation unit into a linked list of dies. */
2995 read_comp_unit (info_ptr
, abfd
)
2999 struct die_info
*first_die
, *last_die
, *die
;
3003 /* Reset die reference table, we are building a new one now. */
3004 dwarf2_empty_die_ref_table ();
3008 first_die
= last_die
= NULL
;
3011 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
3012 if (die
->has_children
)
3023 /* Enter die in reference hash table */
3024 store_in_ref_table (die
->offset
, die
);
3028 first_die
= last_die
= die
;
3032 last_die
->next
= die
;
3036 while (nesting_level
> 0);
3040 /* Free a linked list of dies. */
3043 free_die_list (dies
)
3044 struct die_info
*dies
;
3046 struct die_info
*die
, *next
;
3058 /* Read the contents of the section at OFFSET and of size SIZE from the
3059 object file specified by OBJFILE into the psymbol_obstack and return it. */
3062 dwarf2_read_section (objfile
, offset
, size
)
3063 struct objfile
*objfile
;
3067 bfd
*abfd
= objfile
->obfd
;
3073 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3074 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3075 (bfd_read (buf
, size
, 1, abfd
) != size
))
3078 error ("Dwarf Error: Can't read DWARF data from '%s'",
3079 bfd_get_filename (abfd
));
3084 /* In DWARF version 2, the description of the debugging information is
3085 stored in a separate .debug_abbrev section. Before we read any
3086 dies from a section we read in all abbreviations and install them
3090 dwarf2_read_abbrevs (abfd
, offset
)
3092 unsigned int offset
;
3095 struct abbrev_info
*cur_abbrev
;
3096 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3097 unsigned int abbrev_form
, hash_number
;
3099 /* empty the table */
3100 dwarf2_empty_abbrev_table (NULL
);
3102 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3103 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3104 abbrev_ptr
+= bytes_read
;
3106 /* loop until we reach an abbrev number of 0 */
3107 while (abbrev_number
)
3109 cur_abbrev
= dwarf_alloc_abbrev ();
3111 /* read in abbrev header */
3112 cur_abbrev
->number
= abbrev_number
;
3113 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3114 abbrev_ptr
+= bytes_read
;
3115 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3118 /* now read in declarations */
3119 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3120 abbrev_ptr
+= bytes_read
;
3121 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3122 abbrev_ptr
+= bytes_read
;
3125 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3127 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3128 xrealloc (cur_abbrev
->attrs
,
3129 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3130 * sizeof (struct attr_abbrev
));
3132 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3133 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3134 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3135 abbrev_ptr
+= bytes_read
;
3136 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3137 abbrev_ptr
+= bytes_read
;
3140 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3141 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3142 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3144 /* Get next abbreviation.
3145 Under Irix6 the abbreviations for a compilation unit are not
3146 always properly terminated with an abbrev number of 0.
3147 Exit loop if we encounter an abbreviation which we have
3148 already read (which means we are about to read the abbreviations
3149 for the next compile unit) or if the end of the abbreviation
3150 table is reached. */
3151 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3152 >= dwarf_abbrev_size
)
3154 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3155 abbrev_ptr
+= bytes_read
;
3156 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3161 /* Empty the abbrev table for a new compilation unit. */
3165 dwarf2_empty_abbrev_table (ignore
)
3169 struct abbrev_info
*abbrev
, *next
;
3171 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3174 abbrev
= dwarf2_abbrevs
[i
];
3177 next
= abbrev
->next
;
3178 free (abbrev
->attrs
);
3182 dwarf2_abbrevs
[i
] = NULL
;
3186 /* Lookup an abbrev_info structure in the abbrev hash table. */
3188 static struct abbrev_info
*
3189 dwarf2_lookup_abbrev (number
)
3190 unsigned int number
;
3192 unsigned int hash_number
;
3193 struct abbrev_info
*abbrev
;
3195 hash_number
= number
% ABBREV_HASH_SIZE
;
3196 abbrev
= dwarf2_abbrevs
[hash_number
];
3200 if (abbrev
->number
== number
)
3203 abbrev
= abbrev
->next
;
3208 /* Read a minimal amount of information into the minimal die structure. */
3211 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3212 struct partial_die_info
*part_die
;
3217 unsigned int abbrev_number
, bytes_read
, i
;
3218 struct abbrev_info
*abbrev
;
3219 struct attribute attr
;
3220 struct attribute spec_attr
;
3221 int found_spec_attr
= 0;
3222 int has_low_pc_attr
= 0;
3223 int has_high_pc_attr
= 0;
3225 *part_die
= zeroed_partial_die
;
3227 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3228 info_ptr
+= bytes_read
;
3232 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3235 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3237 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3238 part_die
->tag
= abbrev
->tag
;
3239 part_die
->has_children
= abbrev
->has_children
;
3240 part_die
->abbrev
= abbrev_number
;
3242 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3244 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3246 /* Store the data if it is of an attribute we want to keep in a
3247 partial symbol table. */
3252 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3253 if (part_die
->name
== NULL
)
3254 part_die
->name
= DW_STRING (&attr
);
3256 case DW_AT_MIPS_linkage_name
:
3257 part_die
->name
= DW_STRING (&attr
);
3260 has_low_pc_attr
= 1;
3261 part_die
->lowpc
= DW_ADDR (&attr
);
3264 has_high_pc_attr
= 1;
3265 part_die
->highpc
= DW_ADDR (&attr
);
3267 case DW_AT_location
:
3268 part_die
->locdesc
= DW_BLOCK (&attr
);
3270 case DW_AT_language
:
3271 part_die
->language
= DW_UNSND (&attr
);
3273 case DW_AT_external
:
3274 part_die
->is_external
= DW_UNSND (&attr
);
3276 case DW_AT_declaration
:
3277 part_die
->is_declaration
= DW_UNSND (&attr
);
3280 part_die
->has_type
= 1;
3282 case DW_AT_abstract_origin
:
3283 case DW_AT_specification
:
3284 found_spec_attr
= 1;
3288 /* Ignore absolute siblings, they might point outside of
3289 the current compile unit. */
3290 if (attr
.form
== DW_FORM_ref_addr
)
3291 complain (&dwarf2_absolute_sibling_complaint
);
3294 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3301 /* If we found a reference attribute and the die has no name, try
3302 to find a name in the referred to die. */
3304 if (found_spec_attr
&& part_die
->name
== NULL
)
3306 struct partial_die_info spec_die
;
3310 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3311 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3314 part_die
->name
= spec_die
.name
;
3316 /* Copy DW_AT_external attribute if it is set. */
3317 if (spec_die
.is_external
)
3318 part_die
->is_external
= spec_die
.is_external
;
3322 /* When using the GNU linker, .gnu.linkonce. sections are used to
3323 eliminate duplicate copies of functions and vtables and such.
3324 The linker will arbitrarily choose one and discard the others.
3325 The AT_*_pc values for such functions refer to local labels in
3326 these sections. If the section from that file was discarded, the
3327 labels are not in the output, so the relocs get a value of 0.
3328 If this is a discarded function, mark the pc bounds as invalid,
3329 so that GDB will ignore it. */
3330 if (has_low_pc_attr
&& has_high_pc_attr
3331 && part_die
->lowpc
< part_die
->highpc
3332 && (part_die
->lowpc
!= 0
3333 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3338 /* Read the die from the .debug_info section buffer. And set diep to
3339 point to a newly allocated die with its information. */
3342 read_full_die (diep
, abfd
, info_ptr
)
3343 struct die_info
**diep
;
3347 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3348 struct abbrev_info
*abbrev
;
3349 struct die_info
*die
;
3351 offset
= info_ptr
- dwarf_info_buffer
;
3352 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3353 info_ptr
+= bytes_read
;
3356 die
= dwarf_alloc_die ();
3358 die
->abbrev
= abbrev_number
;
3364 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3367 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3369 die
= dwarf_alloc_die ();
3370 die
->offset
= offset
;
3371 die
->tag
= abbrev
->tag
;
3372 die
->has_children
= abbrev
->has_children
;
3373 die
->abbrev
= abbrev_number
;
3376 die
->num_attrs
= abbrev
->num_attrs
;
3377 die
->attrs
= (struct attribute
*)
3378 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3380 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3382 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3390 /* Read an attribute described by an abbreviated attribute. */
3393 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3394 struct attribute
*attr
;
3395 struct attr_abbrev
*abbrev
;
3399 unsigned int bytes_read
;
3400 struct dwarf_block
*blk
;
3402 attr
->name
= abbrev
->name
;
3403 attr
->form
= abbrev
->form
;
3404 switch (abbrev
->form
)
3407 case DW_FORM_ref_addr
:
3408 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3409 info_ptr
+= address_size
;
3411 case DW_FORM_block2
:
3412 blk
= dwarf_alloc_block ();
3413 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3415 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3416 info_ptr
+= blk
->size
;
3417 DW_BLOCK (attr
) = blk
;
3419 case DW_FORM_block4
:
3420 blk
= dwarf_alloc_block ();
3421 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3423 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3424 info_ptr
+= blk
->size
;
3425 DW_BLOCK (attr
) = blk
;
3428 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3432 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3436 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3439 case DW_FORM_string
:
3440 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3441 info_ptr
+= bytes_read
;
3444 blk
= dwarf_alloc_block ();
3445 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3446 info_ptr
+= bytes_read
;
3447 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3448 info_ptr
+= blk
->size
;
3449 DW_BLOCK (attr
) = blk
;
3451 case DW_FORM_block1
:
3452 blk
= dwarf_alloc_block ();
3453 blk
->size
= read_1_byte (abfd
, info_ptr
);
3455 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3456 info_ptr
+= blk
->size
;
3457 DW_BLOCK (attr
) = blk
;
3460 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3464 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3468 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3469 info_ptr
+= bytes_read
;
3472 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3473 info_ptr
+= bytes_read
;
3476 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3480 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3484 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3487 case DW_FORM_ref_udata
:
3488 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3489 info_ptr
+= bytes_read
;
3492 case DW_FORM_indirect
:
3494 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3495 dwarf_form_name (abbrev
->form
));
3500 /* read dwarf information from a buffer */
3503 read_1_byte (abfd
, buf
)
3507 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3511 read_1_signed_byte (abfd
, buf
)
3515 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3519 read_2_bytes (abfd
, buf
)
3523 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3527 read_2_signed_bytes (abfd
, buf
)
3531 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3535 read_4_bytes (abfd
, buf
)
3539 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3543 read_4_signed_bytes (abfd
, buf
)
3547 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3551 read_8_bytes (abfd
, buf
)
3555 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3559 read_address (abfd
, buf
)
3563 CORE_ADDR retval
= 0;
3565 switch (address_size
)
3568 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3571 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3574 /* *THE* alternative is 8, right? */
3577 /* If the address being read is larger than the address that is
3578 applicable for the object file format then mask it down to the
3579 correct size. Take care to avoid unnecessary shift or shift
3581 if (address_size
> address_significant_size
3582 && address_significant_size
< sizeof (CORE_ADDR
))
3584 CORE_ADDR mask
= ((CORE_ADDR
) 0) - 1;
3585 retval
&= ~(mask
<< (address_significant_size
* 8));
3591 read_n_bytes (abfd
, buf
, size
)
3596 /* If the size of a host char is 8 bits, we can return a pointer
3597 to the buffer, otherwise we have to copy the data to a buffer
3598 allocated on the temporary obstack. */
3599 #if HOST_CHAR_BIT == 8
3605 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3606 for (i
= 0; i
< size
; ++i
)
3608 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3616 read_string (abfd
, buf
, bytes_read_ptr
)
3619 unsigned int *bytes_read_ptr
;
3621 /* If the size of a host char is 8 bits, we can return a pointer
3622 to the string, otherwise we have to copy the string to a buffer
3623 allocated on the temporary obstack. */
3624 #if HOST_CHAR_BIT == 8
3627 *bytes_read_ptr
= 1;
3630 *bytes_read_ptr
= strlen (buf
) + 1;
3636 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3638 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3644 *bytes_read_ptr
= 1;
3647 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3648 *bytes_read_ptr
= i
+ 1;
3649 return obstack_finish (&dwarf2_tmp_obstack
);
3654 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3657 unsigned int *bytes_read_ptr
;
3659 unsigned int result
, num_read
;
3669 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3672 result
|= ((byte
& 127) << shift
);
3673 if ((byte
& 128) == 0)
3679 *bytes_read_ptr
= num_read
;
3684 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3687 unsigned int *bytes_read_ptr
;
3690 int i
, shift
, size
, num_read
;
3700 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3703 result
|= ((byte
& 127) << shift
);
3705 if ((byte
& 128) == 0)
3710 if ((shift
< size
) && (byte
& 0x40))
3712 result
|= -(1 << shift
);
3714 *bytes_read_ptr
= num_read
;
3719 set_cu_language (lang
)
3726 cu_language
= language_c
;
3728 case DW_LANG_C_plus_plus
:
3729 cu_language
= language_cplus
;
3731 case DW_LANG_Fortran77
:
3732 case DW_LANG_Fortran90
:
3733 cu_language
= language_fortran
;
3735 case DW_LANG_Mips_Assembler
:
3736 cu_language
= language_asm
;
3739 case DW_LANG_Cobol74
:
3740 case DW_LANG_Cobol85
:
3741 case DW_LANG_Pascal83
:
3742 case DW_LANG_Modula2
:
3744 cu_language
= language_unknown
;
3747 cu_language_defn
= language_def (cu_language
);
3750 /* Return the named attribute or NULL if not there. */
3752 static struct attribute
*
3753 dwarf_attr (die
, name
)
3754 struct die_info
*die
;
3758 struct attribute
*spec
= NULL
;
3760 for (i
= 0; i
< die
->num_attrs
; ++i
)
3762 if (die
->attrs
[i
].name
== name
)
3764 return &die
->attrs
[i
];
3766 if (die
->attrs
[i
].name
== DW_AT_specification
3767 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3768 spec
= &die
->attrs
[i
];
3772 struct die_info
*ref_die
=
3773 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3776 return dwarf_attr (ref_die
, name
);
3782 /* Decode the line number information for the compilation unit whose
3783 line number info is at OFFSET in the .debug_line section.
3784 The compilation directory of the file is passed in COMP_DIR. */
3788 unsigned int num_files
;
3801 unsigned int num_dirs
;
3806 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3807 unsigned int offset
;
3813 struct line_head lh
;
3814 struct cleanup
*back_to
;
3815 unsigned int i
, bytes_read
;
3816 char *cur_file
, *cur_dir
;
3817 unsigned char op_code
, extended_op
, adj_opcode
;
3819 #define FILE_ALLOC_CHUNK 5
3820 #define DIR_ALLOC_CHUNK 5
3822 struct filenames files
;
3823 struct directories dirs
;
3825 if (dwarf_line_buffer
== NULL
)
3827 complain (&dwarf2_missing_line_number_section
);
3831 files
.num_files
= 0;
3837 line_ptr
= dwarf_line_buffer
+ offset
;
3839 /* read in the prologue */
3840 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3842 line_end
= line_ptr
+ lh
.total_length
;
3843 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3845 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3847 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3849 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3851 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3853 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3855 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3857 lh
.standard_opcode_lengths
= (unsigned char *)
3858 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3859 back_to
= make_cleanup ((make_cleanup_func
) free_current_contents
,
3860 &lh
.standard_opcode_lengths
);
3862 lh
.standard_opcode_lengths
[0] = 1;
3863 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3865 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3869 /* Read directory table */
3870 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3872 line_ptr
+= bytes_read
;
3873 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3875 dirs
.dirs
= (char **)
3876 xrealloc (dirs
.dirs
,
3877 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3878 if (dirs
.num_dirs
== 0)
3879 make_cleanup ((make_cleanup_func
) free_current_contents
, &dirs
.dirs
);
3881 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3883 line_ptr
+= bytes_read
;
3885 /* Read file name table */
3886 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3888 line_ptr
+= bytes_read
;
3889 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3891 files
.files
= (struct fileinfo
*)
3892 xrealloc (files
.files
,
3893 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3894 * sizeof (struct fileinfo
));
3895 if (files
.num_files
== 0)
3896 make_cleanup ((make_cleanup_func
) free_current_contents
,
3899 files
.files
[files
.num_files
].name
= cur_file
;
3900 files
.files
[files
.num_files
].dir
=
3901 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3902 line_ptr
+= bytes_read
;
3903 files
.files
[files
.num_files
].time
=
3904 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3905 line_ptr
+= bytes_read
;
3906 files
.files
[files
.num_files
].size
=
3907 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3908 line_ptr
+= bytes_read
;
3911 line_ptr
+= bytes_read
;
3913 /* Read the statement sequences until there's nothing left. */
3914 while (line_ptr
< line_end
)
3916 /* state machine registers */
3917 CORE_ADDR address
= 0;
3918 unsigned int file
= 1;
3919 unsigned int line
= 1;
3920 unsigned int column
= 0;
3921 int is_stmt
= lh
.default_is_stmt
;
3922 int basic_block
= 0;
3923 int end_sequence
= 0;
3925 /* Start a subfile for the current file of the state machine. */
3926 if (files
.num_files
>= file
)
3928 /* The file and directory tables are 0 based, the references
3930 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3931 (files
.files
[file
- 1].dir
3932 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3936 /* Decode the table. */
3937 while (!end_sequence
)
3939 op_code
= read_1_byte (abfd
, line_ptr
);
3943 case DW_LNS_extended_op
:
3944 line_ptr
+= 1; /* ignore length */
3945 extended_op
= read_1_byte (abfd
, line_ptr
);
3947 switch (extended_op
)
3949 case DW_LNE_end_sequence
:
3951 /* Don't call record_line here. The end_sequence
3952 instruction provides the address of the first byte
3953 *after* the last line in the sequence; it's not the
3954 address of any real source line. However, the GDB
3955 linetable structure only records the starts of lines,
3956 not the ends. This is a weakness of GDB. */
3958 case DW_LNE_set_address
:
3959 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3960 line_ptr
+= address_size
;
3962 case DW_LNE_define_file
:
3963 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3964 line_ptr
+= bytes_read
;
3965 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3967 files
.files
= (struct fileinfo
*)
3968 xrealloc (files
.files
,
3969 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3970 * sizeof (struct fileinfo
));
3971 if (files
.num_files
== 0)
3972 make_cleanup ((make_cleanup_func
) free_current_contents
,
3975 files
.files
[files
.num_files
].name
= cur_file
;
3976 files
.files
[files
.num_files
].dir
=
3977 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3978 line_ptr
+= bytes_read
;
3979 files
.files
[files
.num_files
].time
=
3980 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3981 line_ptr
+= bytes_read
;
3982 files
.files
[files
.num_files
].size
=
3983 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3984 line_ptr
+= bytes_read
;
3988 complain (&dwarf2_mangled_line_number_section
);
3993 record_line (current_subfile
, line
, address
);
3996 case DW_LNS_advance_pc
:
3997 address
+= lh
.minimum_instruction_length
3998 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3999 line_ptr
+= bytes_read
;
4001 case DW_LNS_advance_line
:
4002 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
4003 line_ptr
+= bytes_read
;
4005 case DW_LNS_set_file
:
4006 /* The file and directory tables are 0 based, the references
4008 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4009 line_ptr
+= bytes_read
;
4010 dwarf2_start_subfile
4011 (files
.files
[file
- 1].name
,
4012 (files
.files
[file
- 1].dir
4013 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4016 case DW_LNS_set_column
:
4017 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4018 line_ptr
+= bytes_read
;
4020 case DW_LNS_negate_stmt
:
4021 is_stmt
= (!is_stmt
);
4023 case DW_LNS_set_basic_block
:
4026 case DW_LNS_const_add_pc
:
4027 address
+= (255 - lh
.opcode_base
) / lh
.line_range
;
4029 case DW_LNS_fixed_advance_pc
:
4030 address
+= read_2_bytes (abfd
, line_ptr
);
4033 default: /* special operand */
4034 adj_opcode
= op_code
- lh
.opcode_base
;
4035 address
+= (adj_opcode
/ lh
.line_range
)
4036 * lh
.minimum_instruction_length
;
4037 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4038 /* append row to matrix using current values */
4039 record_line (current_subfile
, line
, address
);
4045 do_cleanups (back_to
);
4048 /* Start a subfile for DWARF. FILENAME is the name of the file and
4049 DIRNAME the name of the source directory which contains FILENAME
4050 or NULL if not known.
4051 This routine tries to keep line numbers from identical absolute and
4052 relative file names in a common subfile.
4054 Using the `list' example from the GDB testsuite, which resides in
4055 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4056 of /srcdir/list0.c yields the following debugging information for list0.c:
4058 DW_AT_name: /srcdir/list0.c
4059 DW_AT_comp_dir: /compdir
4060 files.files[0].name: list0.h
4061 files.files[0].dir: /srcdir
4062 files.files[1].name: list0.c
4063 files.files[1].dir: /srcdir
4065 The line number information for list0.c has to end up in a single
4066 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4069 dwarf2_start_subfile (filename
, dirname
)
4073 /* If the filename isn't absolute, try to match an existing subfile
4074 with the full pathname. */
4076 if (*filename
!= '/' && dirname
!= NULL
)
4078 struct subfile
*subfile
;
4079 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4081 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4083 if (STREQ (subfile
->name
, fullname
))
4085 current_subfile
= subfile
;
4092 start_subfile (filename
, dirname
);
4095 /* Given a pointer to a DWARF information entry, figure out if we need
4096 to make a symbol table entry for it, and if so, create a new entry
4097 and return a pointer to it.
4098 If TYPE is NULL, determine symbol type from the die, otherwise
4099 used the passed type.
4102 static struct symbol
*
4103 new_symbol (die
, type
, objfile
)
4104 struct die_info
*die
;
4106 struct objfile
*objfile
;
4108 struct symbol
*sym
= NULL
;
4110 struct attribute
*attr
= NULL
;
4111 struct attribute
*attr2
= NULL
;
4114 name
= dwarf2_linkage_name (die
);
4117 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4118 sizeof (struct symbol
));
4119 OBJSTAT (objfile
, n_syms
++);
4120 memset (sym
, 0, sizeof (struct symbol
));
4121 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4122 &objfile
->symbol_obstack
);
4124 /* Default assumptions.
4125 Use the passed type or decode it from the die. */
4126 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4127 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4129 SYMBOL_TYPE (sym
) = type
;
4131 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4132 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4135 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4138 /* If this symbol is from a C++ compilation, then attempt to
4139 cache the demangled form for future reference. This is a
4140 typical time versus space tradeoff, that was decided in favor
4141 of time because it sped up C++ symbol lookups by a factor of
4144 SYMBOL_LANGUAGE (sym
) = cu_language
;
4145 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4149 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4152 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4154 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4156 case DW_TAG_subprogram
:
4157 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4159 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4160 attr2
= dwarf_attr (die
, DW_AT_external
);
4161 if (attr2
&& (DW_UNSND (attr2
) != 0))
4163 add_symbol_to_list (sym
, &global_symbols
);
4167 add_symbol_to_list (sym
, list_in_scope
);
4170 case DW_TAG_variable
:
4171 /* Compilation with minimal debug info may result in variables
4172 with missing type entries. Change the misleading `void' type
4173 to something sensible. */
4174 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4175 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4176 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4177 "<variable, no debug info>",
4179 attr
= dwarf_attr (die
, DW_AT_const_value
);
4182 dwarf2_const_value (attr
, sym
, objfile
);
4183 attr2
= dwarf_attr (die
, DW_AT_external
);
4184 if (attr2
&& (DW_UNSND (attr2
) != 0))
4185 add_symbol_to_list (sym
, &global_symbols
);
4187 add_symbol_to_list (sym
, list_in_scope
);
4190 attr
= dwarf_attr (die
, DW_AT_location
);
4193 attr2
= dwarf_attr (die
, DW_AT_external
);
4194 if (attr2
&& (DW_UNSND (attr2
) != 0))
4196 SYMBOL_VALUE_ADDRESS (sym
) =
4197 decode_locdesc (DW_BLOCK (attr
), objfile
);
4198 add_symbol_to_list (sym
, &global_symbols
);
4200 /* In shared libraries the address of the variable
4201 in the location descriptor might still be relocatable,
4202 so its value could be zero.
4203 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4204 value is zero, the address of the variable will then
4205 be determined from the minimal symbol table whenever
4206 the variable is referenced. */
4207 if (SYMBOL_VALUE_ADDRESS (sym
))
4209 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4210 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4213 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4217 SYMBOL_VALUE (sym
) = addr
=
4218 decode_locdesc (DW_BLOCK (attr
), objfile
);
4219 add_symbol_to_list (sym
, list_in_scope
);
4222 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4226 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4230 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4231 SYMBOL_BASEREG (sym
) = basereg
;
4235 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4239 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4240 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4246 /* We do not know the address of this symbol.
4247 If it is an external symbol and we have type information
4248 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4249 The address of the variable will then be determined from
4250 the minimal symbol table whenever the variable is
4252 attr2
= dwarf_attr (die
, DW_AT_external
);
4253 if (attr2
&& (DW_UNSND (attr2
) != 0)
4254 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4256 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4257 add_symbol_to_list (sym
, &global_symbols
);
4261 case DW_TAG_formal_parameter
:
4262 attr
= dwarf_attr (die
, DW_AT_location
);
4265 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4268 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4274 if (basereg
!= frame_base_reg
)
4275 complain (&dwarf2_complex_location_expr
);
4276 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4280 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4281 SYMBOL_BASEREG (sym
) = basereg
;
4286 SYMBOL_CLASS (sym
) = LOC_ARG
;
4289 attr
= dwarf_attr (die
, DW_AT_const_value
);
4292 dwarf2_const_value (attr
, sym
, objfile
);
4294 add_symbol_to_list (sym
, list_in_scope
);
4296 case DW_TAG_unspecified_parameters
:
4297 /* From varargs functions; gdb doesn't seem to have any
4298 interest in this information, so just ignore it for now.
4301 case DW_TAG_class_type
:
4302 case DW_TAG_structure_type
:
4303 case DW_TAG_union_type
:
4304 case DW_TAG_enumeration_type
:
4305 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4306 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4307 add_symbol_to_list (sym
, list_in_scope
);
4309 /* The semantics of C++ state that "struct foo { ... }" also
4310 defines a typedef for "foo". Synthesize a typedef symbol so
4311 that "ptype foo" works as expected. */
4312 if (cu_language
== language_cplus
)
4314 struct symbol
*typedef_sym
= (struct symbol
*)
4315 obstack_alloc (&objfile
->symbol_obstack
,
4316 sizeof (struct symbol
));
4317 *typedef_sym
= *sym
;
4318 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4319 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4320 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4321 obsavestring (SYMBOL_NAME (sym
),
4322 strlen (SYMBOL_NAME (sym
)),
4323 &objfile
->type_obstack
);
4324 add_symbol_to_list (typedef_sym
, list_in_scope
);
4327 case DW_TAG_typedef
:
4328 case DW_TAG_base_type
:
4329 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4330 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4331 add_symbol_to_list (sym
, list_in_scope
);
4333 case DW_TAG_enumerator
:
4334 attr
= dwarf_attr (die
, DW_AT_const_value
);
4337 dwarf2_const_value (attr
, sym
, objfile
);
4339 add_symbol_to_list (sym
, list_in_scope
);
4342 /* Not a tag we recognize. Hopefully we aren't processing
4343 trash data, but since we must specifically ignore things
4344 we don't recognize, there is nothing else we should do at
4346 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4353 /* Copy constant value from an attribute to a symbol. */
4356 dwarf2_const_value (attr
, sym
, objfile
)
4357 struct attribute
*attr
;
4359 struct objfile
*objfile
;
4361 struct dwarf_block
*blk
;
4366 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4367 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4368 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4369 SYMBOL_VALUE_BYTES (sym
) = (char *)
4370 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4371 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4372 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4374 case DW_FORM_block1
:
4375 case DW_FORM_block2
:
4376 case DW_FORM_block4
:
4378 blk
= DW_BLOCK (attr
);
4379 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4380 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4381 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4382 SYMBOL_VALUE_BYTES (sym
) = (char *)
4383 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4384 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4385 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4393 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4394 SYMBOL_CLASS (sym
) = LOC_CONST
;
4397 complain (&dwarf2_unsupported_const_value_attr
,
4398 dwarf_form_name (attr
->form
));
4399 SYMBOL_VALUE (sym
) = 0;
4400 SYMBOL_CLASS (sym
) = LOC_CONST
;
4405 /* Return the type of the die in question using its DW_AT_type attribute. */
4407 static struct type
*
4408 die_type (die
, objfile
)
4409 struct die_info
*die
;
4410 struct objfile
*objfile
;
4413 struct attribute
*type_attr
;
4414 struct die_info
*type_die
;
4417 type_attr
= dwarf_attr (die
, DW_AT_type
);
4420 /* A missing DW_AT_type represents a void type. */
4421 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4425 ref
= dwarf2_get_ref_die_offset (type_attr
);
4426 type_die
= follow_die_ref (ref
);
4429 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4433 type
= tag_type_to_type (type_die
, objfile
);
4436 dump_die (type_die
);
4437 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4442 /* Return the containing type of the die in question using its
4443 DW_AT_containing_type attribute. */
4445 static struct type
*
4446 die_containing_type (die
, objfile
)
4447 struct die_info
*die
;
4448 struct objfile
*objfile
;
4450 struct type
*type
= NULL
;
4451 struct attribute
*type_attr
;
4452 struct die_info
*type_die
= NULL
;
4455 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4458 ref
= dwarf2_get_ref_die_offset (type_attr
);
4459 type_die
= follow_die_ref (ref
);
4462 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4465 type
= tag_type_to_type (type_die
, objfile
);
4470 dump_die (type_die
);
4471 error ("Dwarf Error: Problem turning containing type into gdb type.");
4477 static struct type
*
4478 type_at_offset (offset
, objfile
)
4479 unsigned int offset
;
4480 struct objfile
*objfile
;
4482 struct die_info
*die
;
4485 die
= follow_die_ref (offset
);
4488 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4491 type
= tag_type_to_type (die
, objfile
);
4496 static struct type
*
4497 tag_type_to_type (die
, objfile
)
4498 struct die_info
*die
;
4499 struct objfile
*objfile
;
4507 read_type_die (die
, objfile
);
4511 error ("Dwarf Error: Cannot find type of die.");
4518 read_type_die (die
, objfile
)
4519 struct die_info
*die
;
4520 struct objfile
*objfile
;
4524 case DW_TAG_class_type
:
4525 case DW_TAG_structure_type
:
4526 case DW_TAG_union_type
:
4527 read_structure_scope (die
, objfile
);
4529 case DW_TAG_enumeration_type
:
4530 read_enumeration (die
, objfile
);
4532 case DW_TAG_subprogram
:
4533 case DW_TAG_subroutine_type
:
4534 read_subroutine_type (die
, objfile
);
4536 case DW_TAG_array_type
:
4537 read_array_type (die
, objfile
);
4539 case DW_TAG_pointer_type
:
4540 read_tag_pointer_type (die
, objfile
);
4542 case DW_TAG_ptr_to_member_type
:
4543 read_tag_ptr_to_member_type (die
, objfile
);
4545 case DW_TAG_reference_type
:
4546 read_tag_reference_type (die
, objfile
);
4548 case DW_TAG_const_type
:
4549 read_tag_const_type (die
, objfile
);
4551 case DW_TAG_volatile_type
:
4552 read_tag_volatile_type (die
, objfile
);
4554 case DW_TAG_string_type
:
4555 read_tag_string_type (die
, objfile
);
4557 case DW_TAG_typedef
:
4558 read_typedef (die
, objfile
);
4560 case DW_TAG_base_type
:
4561 read_base_type (die
, objfile
);
4564 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4569 static struct type
*
4570 dwarf_base_type (encoding
, size
, objfile
)
4573 struct objfile
*objfile
;
4575 /* FIXME - this should not produce a new (struct type *)
4576 every time. It should cache base types. */
4580 case DW_ATE_address
:
4581 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4583 case DW_ATE_boolean
:
4584 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4586 case DW_ATE_complex_float
:
4589 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4593 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4599 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4603 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4610 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4613 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4617 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4621 case DW_ATE_signed_char
:
4622 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4624 case DW_ATE_unsigned
:
4628 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4631 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4635 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4639 case DW_ATE_unsigned_char
:
4640 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4643 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4651 struct die_info
*old_die
;
4653 struct die_info
*new_die
;
4656 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4657 memset (new_die
, 0, sizeof (struct die_info
));
4659 new_die
->tag
= old_die
->tag
;
4660 new_die
->has_children
= old_die
->has_children
;
4661 new_die
->abbrev
= old_die
->abbrev
;
4662 new_die
->offset
= old_die
->offset
;
4663 new_die
->type
= NULL
;
4665 num_attrs
= old_die
->num_attrs
;
4666 new_die
->num_attrs
= num_attrs
;
4667 new_die
->attrs
= (struct attribute
*)
4668 xmalloc (num_attrs
* sizeof (struct attribute
));
4670 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4672 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4673 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4674 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4677 new_die
->next
= NULL
;
4682 /* Return sibling of die, NULL if no sibling. */
4686 struct die_info
*die
;
4688 int nesting_level
= 0;
4690 if (!die
->has_children
)
4692 if (die
->next
&& (die
->next
->tag
== 0))
4705 if (die
->has_children
)
4715 while (nesting_level
);
4716 if (die
&& (die
->tag
== 0))
4727 /* Get linkage name of a die, return NULL if not found. */
4730 dwarf2_linkage_name (die
)
4731 struct die_info
*die
;
4733 struct attribute
*attr
;
4735 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4736 if (attr
&& DW_STRING (attr
))
4737 return DW_STRING (attr
);
4738 attr
= dwarf_attr (die
, DW_AT_name
);
4739 if (attr
&& DW_STRING (attr
))
4740 return DW_STRING (attr
);
4744 /* Convert a DIE tag into its string name. */
4747 dwarf_tag_name (tag
)
4748 register unsigned tag
;
4752 case DW_TAG_padding
:
4753 return "DW_TAG_padding";
4754 case DW_TAG_array_type
:
4755 return "DW_TAG_array_type";
4756 case DW_TAG_class_type
:
4757 return "DW_TAG_class_type";
4758 case DW_TAG_entry_point
:
4759 return "DW_TAG_entry_point";
4760 case DW_TAG_enumeration_type
:
4761 return "DW_TAG_enumeration_type";
4762 case DW_TAG_formal_parameter
:
4763 return "DW_TAG_formal_parameter";
4764 case DW_TAG_imported_declaration
:
4765 return "DW_TAG_imported_declaration";
4767 return "DW_TAG_label";
4768 case DW_TAG_lexical_block
:
4769 return "DW_TAG_lexical_block";
4771 return "DW_TAG_member";
4772 case DW_TAG_pointer_type
:
4773 return "DW_TAG_pointer_type";
4774 case DW_TAG_reference_type
:
4775 return "DW_TAG_reference_type";
4776 case DW_TAG_compile_unit
:
4777 return "DW_TAG_compile_unit";
4778 case DW_TAG_string_type
:
4779 return "DW_TAG_string_type";
4780 case DW_TAG_structure_type
:
4781 return "DW_TAG_structure_type";
4782 case DW_TAG_subroutine_type
:
4783 return "DW_TAG_subroutine_type";
4784 case DW_TAG_typedef
:
4785 return "DW_TAG_typedef";
4786 case DW_TAG_union_type
:
4787 return "DW_TAG_union_type";
4788 case DW_TAG_unspecified_parameters
:
4789 return "DW_TAG_unspecified_parameters";
4790 case DW_TAG_variant
:
4791 return "DW_TAG_variant";
4792 case DW_TAG_common_block
:
4793 return "DW_TAG_common_block";
4794 case DW_TAG_common_inclusion
:
4795 return "DW_TAG_common_inclusion";
4796 case DW_TAG_inheritance
:
4797 return "DW_TAG_inheritance";
4798 case DW_TAG_inlined_subroutine
:
4799 return "DW_TAG_inlined_subroutine";
4801 return "DW_TAG_module";
4802 case DW_TAG_ptr_to_member_type
:
4803 return "DW_TAG_ptr_to_member_type";
4804 case DW_TAG_set_type
:
4805 return "DW_TAG_set_type";
4806 case DW_TAG_subrange_type
:
4807 return "DW_TAG_subrange_type";
4808 case DW_TAG_with_stmt
:
4809 return "DW_TAG_with_stmt";
4810 case DW_TAG_access_declaration
:
4811 return "DW_TAG_access_declaration";
4812 case DW_TAG_base_type
:
4813 return "DW_TAG_base_type";
4814 case DW_TAG_catch_block
:
4815 return "DW_TAG_catch_block";
4816 case DW_TAG_const_type
:
4817 return "DW_TAG_const_type";
4818 case DW_TAG_constant
:
4819 return "DW_TAG_constant";
4820 case DW_TAG_enumerator
:
4821 return "DW_TAG_enumerator";
4822 case DW_TAG_file_type
:
4823 return "DW_TAG_file_type";
4825 return "DW_TAG_friend";
4826 case DW_TAG_namelist
:
4827 return "DW_TAG_namelist";
4828 case DW_TAG_namelist_item
:
4829 return "DW_TAG_namelist_item";
4830 case DW_TAG_packed_type
:
4831 return "DW_TAG_packed_type";
4832 case DW_TAG_subprogram
:
4833 return "DW_TAG_subprogram";
4834 case DW_TAG_template_type_param
:
4835 return "DW_TAG_template_type_param";
4836 case DW_TAG_template_value_param
:
4837 return "DW_TAG_template_value_param";
4838 case DW_TAG_thrown_type
:
4839 return "DW_TAG_thrown_type";
4840 case DW_TAG_try_block
:
4841 return "DW_TAG_try_block";
4842 case DW_TAG_variant_part
:
4843 return "DW_TAG_variant_part";
4844 case DW_TAG_variable
:
4845 return "DW_TAG_variable";
4846 case DW_TAG_volatile_type
:
4847 return "DW_TAG_volatile_type";
4848 case DW_TAG_MIPS_loop
:
4849 return "DW_TAG_MIPS_loop";
4850 case DW_TAG_format_label
:
4851 return "DW_TAG_format_label";
4852 case DW_TAG_function_template
:
4853 return "DW_TAG_function_template";
4854 case DW_TAG_class_template
:
4855 return "DW_TAG_class_template";
4857 return "DW_TAG_<unknown>";
4861 /* Convert a DWARF attribute code into its string name. */
4864 dwarf_attr_name (attr
)
4865 register unsigned attr
;
4870 return "DW_AT_sibling";
4871 case DW_AT_location
:
4872 return "DW_AT_location";
4874 return "DW_AT_name";
4875 case DW_AT_ordering
:
4876 return "DW_AT_ordering";
4877 case DW_AT_subscr_data
:
4878 return "DW_AT_subscr_data";
4879 case DW_AT_byte_size
:
4880 return "DW_AT_byte_size";
4881 case DW_AT_bit_offset
:
4882 return "DW_AT_bit_offset";
4883 case DW_AT_bit_size
:
4884 return "DW_AT_bit_size";
4885 case DW_AT_element_list
:
4886 return "DW_AT_element_list";
4887 case DW_AT_stmt_list
:
4888 return "DW_AT_stmt_list";
4890 return "DW_AT_low_pc";
4892 return "DW_AT_high_pc";
4893 case DW_AT_language
:
4894 return "DW_AT_language";
4896 return "DW_AT_member";
4898 return "DW_AT_discr";
4899 case DW_AT_discr_value
:
4900 return "DW_AT_discr_value";
4901 case DW_AT_visibility
:
4902 return "DW_AT_visibility";
4904 return "DW_AT_import";
4905 case DW_AT_string_length
:
4906 return "DW_AT_string_length";
4907 case DW_AT_common_reference
:
4908 return "DW_AT_common_reference";
4909 case DW_AT_comp_dir
:
4910 return "DW_AT_comp_dir";
4911 case DW_AT_const_value
:
4912 return "DW_AT_const_value";
4913 case DW_AT_containing_type
:
4914 return "DW_AT_containing_type";
4915 case DW_AT_default_value
:
4916 return "DW_AT_default_value";
4918 return "DW_AT_inline";
4919 case DW_AT_is_optional
:
4920 return "DW_AT_is_optional";
4921 case DW_AT_lower_bound
:
4922 return "DW_AT_lower_bound";
4923 case DW_AT_producer
:
4924 return "DW_AT_producer";
4925 case DW_AT_prototyped
:
4926 return "DW_AT_prototyped";
4927 case DW_AT_return_addr
:
4928 return "DW_AT_return_addr";
4929 case DW_AT_start_scope
:
4930 return "DW_AT_start_scope";
4931 case DW_AT_stride_size
:
4932 return "DW_AT_stride_size";
4933 case DW_AT_upper_bound
:
4934 return "DW_AT_upper_bound";
4935 case DW_AT_abstract_origin
:
4936 return "DW_AT_abstract_origin";
4937 case DW_AT_accessibility
:
4938 return "DW_AT_accessibility";
4939 case DW_AT_address_class
:
4940 return "DW_AT_address_class";
4941 case DW_AT_artificial
:
4942 return "DW_AT_artificial";
4943 case DW_AT_base_types
:
4944 return "DW_AT_base_types";
4945 case DW_AT_calling_convention
:
4946 return "DW_AT_calling_convention";
4948 return "DW_AT_count";
4949 case DW_AT_data_member_location
:
4950 return "DW_AT_data_member_location";
4951 case DW_AT_decl_column
:
4952 return "DW_AT_decl_column";
4953 case DW_AT_decl_file
:
4954 return "DW_AT_decl_file";
4955 case DW_AT_decl_line
:
4956 return "DW_AT_decl_line";
4957 case DW_AT_declaration
:
4958 return "DW_AT_declaration";
4959 case DW_AT_discr_list
:
4960 return "DW_AT_discr_list";
4961 case DW_AT_encoding
:
4962 return "DW_AT_encoding";
4963 case DW_AT_external
:
4964 return "DW_AT_external";
4965 case DW_AT_frame_base
:
4966 return "DW_AT_frame_base";
4968 return "DW_AT_friend";
4969 case DW_AT_identifier_case
:
4970 return "DW_AT_identifier_case";
4971 case DW_AT_macro_info
:
4972 return "DW_AT_macro_info";
4973 case DW_AT_namelist_items
:
4974 return "DW_AT_namelist_items";
4975 case DW_AT_priority
:
4976 return "DW_AT_priority";
4978 return "DW_AT_segment";
4979 case DW_AT_specification
:
4980 return "DW_AT_specification";
4981 case DW_AT_static_link
:
4982 return "DW_AT_static_link";
4984 return "DW_AT_type";
4985 case DW_AT_use_location
:
4986 return "DW_AT_use_location";
4987 case DW_AT_variable_parameter
:
4988 return "DW_AT_variable_parameter";
4989 case DW_AT_virtuality
:
4990 return "DW_AT_virtuality";
4991 case DW_AT_vtable_elem_location
:
4992 return "DW_AT_vtable_elem_location";
4995 case DW_AT_MIPS_fde
:
4996 return "DW_AT_MIPS_fde";
4997 case DW_AT_MIPS_loop_begin
:
4998 return "DW_AT_MIPS_loop_begin";
4999 case DW_AT_MIPS_tail_loop_begin
:
5000 return "DW_AT_MIPS_tail_loop_begin";
5001 case DW_AT_MIPS_epilog_begin
:
5002 return "DW_AT_MIPS_epilog_begin";
5003 case DW_AT_MIPS_loop_unroll_factor
:
5004 return "DW_AT_MIPS_loop_unroll_factor";
5005 case DW_AT_MIPS_software_pipeline_depth
:
5006 return "DW_AT_MIPS_software_pipeline_depth";
5007 case DW_AT_MIPS_linkage_name
:
5008 return "DW_AT_MIPS_linkage_name";
5011 case DW_AT_sf_names
:
5012 return "DW_AT_sf_names";
5013 case DW_AT_src_info
:
5014 return "DW_AT_src_info";
5015 case DW_AT_mac_info
:
5016 return "DW_AT_mac_info";
5017 case DW_AT_src_coords
:
5018 return "DW_AT_src_coords";
5019 case DW_AT_body_begin
:
5020 return "DW_AT_body_begin";
5021 case DW_AT_body_end
:
5022 return "DW_AT_body_end";
5024 return "DW_AT_<unknown>";
5028 /* Convert a DWARF value form code into its string name. */
5031 dwarf_form_name (form
)
5032 register unsigned form
;
5037 return "DW_FORM_addr";
5038 case DW_FORM_block2
:
5039 return "DW_FORM_block2";
5040 case DW_FORM_block4
:
5041 return "DW_FORM_block4";
5043 return "DW_FORM_data2";
5045 return "DW_FORM_data4";
5047 return "DW_FORM_data8";
5048 case DW_FORM_string
:
5049 return "DW_FORM_string";
5051 return "DW_FORM_block";
5052 case DW_FORM_block1
:
5053 return "DW_FORM_block1";
5055 return "DW_FORM_data1";
5057 return "DW_FORM_flag";
5059 return "DW_FORM_sdata";
5061 return "DW_FORM_strp";
5063 return "DW_FORM_udata";
5064 case DW_FORM_ref_addr
:
5065 return "DW_FORM_ref_addr";
5067 return "DW_FORM_ref1";
5069 return "DW_FORM_ref2";
5071 return "DW_FORM_ref4";
5073 return "DW_FORM_ref8";
5074 case DW_FORM_ref_udata
:
5075 return "DW_FORM_ref_udata";
5076 case DW_FORM_indirect
:
5077 return "DW_FORM_indirect";
5079 return "DW_FORM_<unknown>";
5083 /* Convert a DWARF stack opcode into its string name. */
5086 dwarf_stack_op_name (op
)
5087 register unsigned op
;
5092 return "DW_OP_addr";
5094 return "DW_OP_deref";
5096 return "DW_OP_const1u";
5098 return "DW_OP_const1s";
5100 return "DW_OP_const2u";
5102 return "DW_OP_const2s";
5104 return "DW_OP_const4u";
5106 return "DW_OP_const4s";
5108 return "DW_OP_const8u";
5110 return "DW_OP_const8s";
5112 return "DW_OP_constu";
5114 return "DW_OP_consts";
5118 return "DW_OP_drop";
5120 return "DW_OP_over";
5122 return "DW_OP_pick";
5124 return "DW_OP_swap";
5128 return "DW_OP_xderef";
5136 return "DW_OP_minus";
5148 return "DW_OP_plus";
5149 case DW_OP_plus_uconst
:
5150 return "DW_OP_plus_uconst";
5156 return "DW_OP_shra";
5174 return "DW_OP_skip";
5176 return "DW_OP_lit0";
5178 return "DW_OP_lit1";
5180 return "DW_OP_lit2";
5182 return "DW_OP_lit3";
5184 return "DW_OP_lit4";
5186 return "DW_OP_lit5";
5188 return "DW_OP_lit6";
5190 return "DW_OP_lit7";
5192 return "DW_OP_lit8";
5194 return "DW_OP_lit9";
5196 return "DW_OP_lit10";
5198 return "DW_OP_lit11";
5200 return "DW_OP_lit12";
5202 return "DW_OP_lit13";
5204 return "DW_OP_lit14";
5206 return "DW_OP_lit15";
5208 return "DW_OP_lit16";
5210 return "DW_OP_lit17";
5212 return "DW_OP_lit18";
5214 return "DW_OP_lit19";
5216 return "DW_OP_lit20";
5218 return "DW_OP_lit21";
5220 return "DW_OP_lit22";
5222 return "DW_OP_lit23";
5224 return "DW_OP_lit24";
5226 return "DW_OP_lit25";
5228 return "DW_OP_lit26";
5230 return "DW_OP_lit27";
5232 return "DW_OP_lit28";
5234 return "DW_OP_lit29";
5236 return "DW_OP_lit30";
5238 return "DW_OP_lit31";
5240 return "DW_OP_reg0";
5242 return "DW_OP_reg1";
5244 return "DW_OP_reg2";
5246 return "DW_OP_reg3";
5248 return "DW_OP_reg4";
5250 return "DW_OP_reg5";
5252 return "DW_OP_reg6";
5254 return "DW_OP_reg7";
5256 return "DW_OP_reg8";
5258 return "DW_OP_reg9";
5260 return "DW_OP_reg10";
5262 return "DW_OP_reg11";
5264 return "DW_OP_reg12";
5266 return "DW_OP_reg13";
5268 return "DW_OP_reg14";
5270 return "DW_OP_reg15";
5272 return "DW_OP_reg16";
5274 return "DW_OP_reg17";
5276 return "DW_OP_reg18";
5278 return "DW_OP_reg19";
5280 return "DW_OP_reg20";
5282 return "DW_OP_reg21";
5284 return "DW_OP_reg22";
5286 return "DW_OP_reg23";
5288 return "DW_OP_reg24";
5290 return "DW_OP_reg25";
5292 return "DW_OP_reg26";
5294 return "DW_OP_reg27";
5296 return "DW_OP_reg28";
5298 return "DW_OP_reg29";
5300 return "DW_OP_reg30";
5302 return "DW_OP_reg31";
5304 return "DW_OP_breg0";
5306 return "DW_OP_breg1";
5308 return "DW_OP_breg2";
5310 return "DW_OP_breg3";
5312 return "DW_OP_breg4";
5314 return "DW_OP_breg5";
5316 return "DW_OP_breg6";
5318 return "DW_OP_breg7";
5320 return "DW_OP_breg8";
5322 return "DW_OP_breg9";
5324 return "DW_OP_breg10";
5326 return "DW_OP_breg11";
5328 return "DW_OP_breg12";
5330 return "DW_OP_breg13";
5332 return "DW_OP_breg14";
5334 return "DW_OP_breg15";
5336 return "DW_OP_breg16";
5338 return "DW_OP_breg17";
5340 return "DW_OP_breg18";
5342 return "DW_OP_breg19";
5344 return "DW_OP_breg20";
5346 return "DW_OP_breg21";
5348 return "DW_OP_breg22";
5350 return "DW_OP_breg23";
5352 return "DW_OP_breg24";
5354 return "DW_OP_breg25";
5356 return "DW_OP_breg26";
5358 return "DW_OP_breg27";
5360 return "DW_OP_breg28";
5362 return "DW_OP_breg29";
5364 return "DW_OP_breg30";
5366 return "DW_OP_breg31";
5368 return "DW_OP_regx";
5370 return "DW_OP_fbreg";
5372 return "DW_OP_bregx";
5374 return "DW_OP_piece";
5375 case DW_OP_deref_size
:
5376 return "DW_OP_deref_size";
5377 case DW_OP_xderef_size
:
5378 return "DW_OP_xderef_size";
5382 return "OP_<unknown>";
5387 dwarf_bool_name (mybool
)
5396 /* Convert a DWARF type code into its string name. */
5399 dwarf_type_encoding_name (enc
)
5400 register unsigned enc
;
5404 case DW_ATE_address
:
5405 return "DW_ATE_address";
5406 case DW_ATE_boolean
:
5407 return "DW_ATE_boolean";
5408 case DW_ATE_complex_float
:
5409 return "DW_ATE_complex_float";
5411 return "DW_ATE_float";
5413 return "DW_ATE_signed";
5414 case DW_ATE_signed_char
:
5415 return "DW_ATE_signed_char";
5416 case DW_ATE_unsigned
:
5417 return "DW_ATE_unsigned";
5418 case DW_ATE_unsigned_char
:
5419 return "DW_ATE_unsigned_char";
5421 return "DW_ATE_<unknown>";
5425 /* Convert a DWARF call frame info operation to its string name. */
5429 dwarf_cfi_name (cfi_opc
)
5430 register unsigned cfi_opc
;
5434 case DW_CFA_advance_loc
:
5435 return "DW_CFA_advance_loc";
5437 return "DW_CFA_offset";
5438 case DW_CFA_restore
:
5439 return "DW_CFA_restore";
5441 return "DW_CFA_nop";
5442 case DW_CFA_set_loc
:
5443 return "DW_CFA_set_loc";
5444 case DW_CFA_advance_loc1
:
5445 return "DW_CFA_advance_loc1";
5446 case DW_CFA_advance_loc2
:
5447 return "DW_CFA_advance_loc2";
5448 case DW_CFA_advance_loc4
:
5449 return "DW_CFA_advance_loc4";
5450 case DW_CFA_offset_extended
:
5451 return "DW_CFA_offset_extended";
5452 case DW_CFA_restore_extended
:
5453 return "DW_CFA_restore_extended";
5454 case DW_CFA_undefined
:
5455 return "DW_CFA_undefined";
5456 case DW_CFA_same_value
:
5457 return "DW_CFA_same_value";
5458 case DW_CFA_register
:
5459 return "DW_CFA_register";
5460 case DW_CFA_remember_state
:
5461 return "DW_CFA_remember_state";
5462 case DW_CFA_restore_state
:
5463 return "DW_CFA_restore_state";
5464 case DW_CFA_def_cfa
:
5465 return "DW_CFA_def_cfa";
5466 case DW_CFA_def_cfa_register
:
5467 return "DW_CFA_def_cfa_register";
5468 case DW_CFA_def_cfa_offset
:
5469 return "DW_CFA_def_cfa_offset";
5470 /* SGI/MIPS specific */
5471 case DW_CFA_MIPS_advance_loc8
:
5472 return "DW_CFA_MIPS_advance_loc8";
5474 return "DW_CFA_<unknown>";
5481 struct die_info
*die
;
5485 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5486 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5487 fprintf (stderr
, "\thas children: %s\n",
5488 dwarf_bool_name (die
->has_children
));
5490 fprintf (stderr
, "\tattributes:\n");
5491 for (i
= 0; i
< die
->num_attrs
; ++i
)
5493 fprintf (stderr
, "\t\t%s (%s) ",
5494 dwarf_attr_name (die
->attrs
[i
].name
),
5495 dwarf_form_name (die
->attrs
[i
].form
));
5496 switch (die
->attrs
[i
].form
)
5498 case DW_FORM_ref_addr
:
5500 fprintf (stderr
, "address: ");
5501 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5503 case DW_FORM_block2
:
5504 case DW_FORM_block4
:
5506 case DW_FORM_block1
:
5507 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5517 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5519 case DW_FORM_string
:
5520 fprintf (stderr
, "string: \"%s\"",
5521 DW_STRING (&die
->attrs
[i
])
5522 ? DW_STRING (&die
->attrs
[i
]) : "");
5525 if (DW_UNSND (&die
->attrs
[i
]))
5526 fprintf (stderr
, "flag: TRUE");
5528 fprintf (stderr
, "flag: FALSE");
5530 case DW_FORM_strp
: /* we do not support separate string
5532 case DW_FORM_indirect
: /* we do not handle indirect yet */
5533 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5535 fprintf (stderr
, "unsupported attribute form: %d.",
5536 die
->attrs
[i
].form
);
5538 fprintf (stderr
, "\n");
5544 struct die_info
*die
;
5554 store_in_ref_table (offset
, die
)
5555 unsigned int offset
;
5556 struct die_info
*die
;
5559 struct die_info
*old
;
5561 h
= (offset
% REF_HASH_SIZE
);
5562 old
= die_ref_table
[h
];
5563 die
->next_ref
= old
;
5564 die_ref_table
[h
] = die
;
5569 dwarf2_empty_die_ref_table ()
5571 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5575 dwarf2_get_ref_die_offset (attr
)
5576 struct attribute
*attr
;
5578 unsigned int result
= 0;
5582 case DW_FORM_ref_addr
:
5583 result
= DW_ADDR (attr
);
5588 case DW_FORM_ref_udata
:
5589 result
= cu_header_offset
+ DW_UNSND (attr
);
5592 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5598 follow_die_ref (offset
)
5599 unsigned int offset
;
5601 struct die_info
*die
;
5604 h
= (offset
% REF_HASH_SIZE
);
5605 die
= die_ref_table
[h
];
5608 if (die
->offset
== offset
)
5612 die
= die
->next_ref
;
5617 static struct type
*
5618 dwarf2_fundamental_type (objfile
, typeid)
5619 struct objfile
*objfile
;
5622 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5624 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5628 /* Look for this particular type in the fundamental type vector. If
5629 one is not found, create and install one appropriate for the
5630 current language and the current target machine. */
5632 if (ftypes
[typeid] == NULL
)
5634 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5637 return (ftypes
[typeid]);
5640 /* Decode simple location descriptions.
5641 Given a pointer to a dwarf block that defines a location, compute
5642 the location and return the value.
5644 FIXME: This is a kludge until we figure out a better
5645 way to handle the location descriptions.
5646 Gdb's design does not mesh well with the DWARF2 notion of a location
5647 computing interpreter, which is a shame because the flexibility goes unused.
5648 FIXME: Implement more operations as necessary.
5650 A location description containing no operations indicates that the
5651 object is optimized out. The global optimized_out flag is set for
5652 those, the return value is meaningless.
5654 When the result is a register number, the global isreg flag is set,
5655 otherwise it is cleared.
5657 When the result is a base register offset, the global offreg flag is set
5658 and the register number is returned in basereg, otherwise it is cleared.
5660 When the DW_OP_fbreg operation is encountered without a corresponding
5661 DW_AT_frame_base attribute, the global islocal flag is set.
5662 Hopefully the machine dependent code knows how to set up a virtual
5663 frame pointer for the local references.
5665 Note that stack[0] is unused except as a default error return.
5666 Note that stack overflow is not yet handled. */
5669 decode_locdesc (blk
, objfile
)
5670 struct dwarf_block
*blk
;
5671 struct objfile
*objfile
;
5674 int size
= blk
->size
;
5675 char *data
= blk
->data
;
5676 CORE_ADDR stack
[64];
5678 unsigned int bytes_read
, unsnd
;
5729 stack
[++stacki
] = op
- DW_OP_reg0
;
5734 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5736 #if defined(HARRIS_TARGET) && defined(_M88K)
5737 /* The Harris 88110 gdb ports have long kept their special reg
5738 numbers between their gp-regs and their x-regs. This is
5739 not how our dwarf is generated. Punt. */
5742 stack
[++stacki
] = unsnd
;
5778 basereg
= op
- DW_OP_breg0
;
5779 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5784 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5786 if (frame_base_reg
>= 0)
5789 basereg
= frame_base_reg
;
5790 stack
[stacki
] += frame_base_offset
;
5794 complain (&dwarf2_missing_at_frame_base
);
5800 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5805 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5810 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5815 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5820 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5825 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5830 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5835 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5841 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5846 stack
[stacki
- 1] += stack
[stacki
];
5850 case DW_OP_plus_uconst
:
5851 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5856 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5862 /* If we're not the last op, then we definitely can't encode
5863 this using GDB's address_class enum. */
5865 complain (&dwarf2_complex_location_expr
);
5869 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5870 return (stack
[stacki
]);
5873 return (stack
[stacki
]);
5876 /* memory allocation interface */
5880 dwarf2_free_tmp_obstack (ignore
)
5883 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5886 static struct dwarf_block
*
5887 dwarf_alloc_block ()
5889 struct dwarf_block
*blk
;
5891 blk
= (struct dwarf_block
*)
5892 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5896 static struct abbrev_info
*
5897 dwarf_alloc_abbrev ()
5899 struct abbrev_info
*abbrev
;
5901 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5902 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5906 static struct die_info
*
5909 struct die_info
*die
;
5911 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5912 memset (die
, 0, sizeof (struct die_info
));