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, Boston, MA 02111-1307, USA. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
39 #include "complaints.h"
42 #include "gdb_string.h"
43 #include <sys/types.h>
45 /* .debug_info header for a compilation unit
46 Because of alignment constraints, this structure has padding and cannot
47 be mapped directly onto the beginning of the .debug_info section. */
48 typedef struct comp_unit_header
50 unsigned int length
; /* length of the .debug_info
52 unsigned short version
; /* version number -- 2 for DWARF
54 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
55 unsigned char addr_size
; /* byte size of an address -- 4 */
58 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
60 /* .debug_pubnames header
61 Because of alignment constraints, this structure has padding and cannot
62 be mapped directly onto the beginning of the .debug_info section. */
63 typedef struct pubnames_header
65 unsigned int length
; /* length of the .debug_pubnames
67 unsigned char version
; /* version number -- 2 for DWARF
69 unsigned int info_offset
; /* offset into .debug_info section */
70 unsigned int info_size
; /* byte size of .debug_info section
74 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
76 /* .debug_pubnames header
77 Because of alignment constraints, this structure has padding and cannot
78 be mapped directly onto the beginning of the .debug_info section. */
79 typedef struct aranges_header
81 unsigned int length
; /* byte len of the .debug_aranges
83 unsigned short version
; /* version number -- 2 for DWARF
85 unsigned int info_offset
; /* offset into .debug_info section */
86 unsigned char addr_size
; /* byte size of an address */
87 unsigned char seg_size
; /* byte size of segment descriptor */
90 #define _ACTUAL_ARANGES_HEADER_SIZE 12
92 /* .debug_line statement program prologue
93 Because of alignment constraints, this structure has padding and cannot
94 be mapped directly onto the beginning of the .debug_info section. */
95 typedef struct statement_prologue
97 unsigned int total_length
; /* byte length of the statement
99 unsigned short version
; /* version number -- 2 for DWARF
101 unsigned int prologue_length
; /* # bytes between prologue &
103 unsigned char minimum_instruction_length
; /* byte size of
105 unsigned char default_is_stmt
; /* initial value of is_stmt
108 unsigned char line_range
;
109 unsigned char opcode_base
; /* number assigned to first special
111 unsigned char *standard_opcode_lengths
;
115 /* offsets and sizes of debugging sections */
117 static file_ptr dwarf_info_offset
;
118 static file_ptr dwarf_abbrev_offset
;
119 static file_ptr dwarf_line_offset
;
120 static file_ptr dwarf_pubnames_offset
;
121 static file_ptr dwarf_aranges_offset
;
122 static file_ptr dwarf_loc_offset
;
123 static file_ptr dwarf_macinfo_offset
;
124 static file_ptr dwarf_str_offset
;
126 static unsigned int dwarf_info_size
;
127 static unsigned int dwarf_abbrev_size
;
128 static unsigned int dwarf_line_size
;
129 static unsigned int dwarf_pubnames_size
;
130 static unsigned int dwarf_aranges_size
;
131 static unsigned int dwarf_loc_size
;
132 static unsigned int dwarf_macinfo_size
;
133 static unsigned int dwarf_str_size
;
135 /* names of the debugging sections */
137 #define INFO_SECTION ".debug_info"
138 #define ABBREV_SECTION ".debug_abbrev"
139 #define LINE_SECTION ".debug_line"
140 #define PUBNAMES_SECTION ".debug_pubnames"
141 #define ARANGES_SECTION ".debug_aranges"
142 #define LOC_SECTION ".debug_loc"
143 #define MACINFO_SECTION ".debug_macinfo"
144 #define STR_SECTION ".debug_str"
146 /* local data types */
148 /* The data in a compilation unit header looks like this. */
149 struct comp_unit_head
153 unsigned int abbrev_offset
;
154 unsigned char addr_size
;
157 /* The data in the .debug_line statement prologue looks like this. */
160 unsigned int total_length
;
161 unsigned short version
;
162 unsigned int prologue_length
;
163 unsigned char minimum_instruction_length
;
164 unsigned char default_is_stmt
;
166 unsigned char line_range
;
167 unsigned char opcode_base
;
168 unsigned char *standard_opcode_lengths
;
171 /* When we construct a partial symbol table entry we only
172 need this much information. */
173 struct partial_die_info
176 unsigned char has_children
;
177 unsigned char is_external
;
178 unsigned char is_declaration
;
179 unsigned char has_type
;
185 struct dwarf_block
*locdesc
;
186 unsigned int language
;
190 /* This data structure holds the information of an abbrev. */
193 unsigned int number
; /* number identifying abbrev */
194 enum dwarf_tag tag
; /* dwarf tag */
195 int has_children
; /* boolean */
196 unsigned int num_attrs
; /* number of attributes */
197 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
198 struct abbrev_info
*next
; /* next in chain */
203 enum dwarf_attribute name
;
204 enum dwarf_form form
;
207 /* This data structure holds a complete die structure. */
210 enum dwarf_tag tag
; /* Tag indicating type of die */
211 unsigned short has_children
; /* Does the die have children */
212 unsigned int abbrev
; /* Abbrev number */
213 unsigned int offset
; /* Offset in .debug_info section */
214 unsigned int num_attrs
; /* Number of attributes */
215 struct attribute
*attrs
; /* An array of attributes */
216 struct die_info
*next_ref
; /* Next die in ref hash table */
217 struct die_info
*next
; /* Next die in linked list */
218 struct type
*type
; /* Cached type information */
221 /* Attributes have a name and a value */
224 enum dwarf_attribute name
;
225 enum dwarf_form form
;
229 struct dwarf_block
*blk
;
237 /* Get at parts of an attribute structure */
239 #define DW_STRING(attr) ((attr)->u.str)
240 #define DW_UNSND(attr) ((attr)->u.unsnd)
241 #define DW_BLOCK(attr) ((attr)->u.blk)
242 #define DW_SND(attr) ((attr)->u.snd)
243 #define DW_ADDR(attr) ((attr)->u.addr)
245 /* Blocks are a bunch of untyped bytes. */
252 /* We only hold one compilation unit's abbrevs in
253 memory at any one time. */
254 #ifndef ABBREV_HASH_SIZE
255 #define ABBREV_HASH_SIZE 121
257 #ifndef ATTR_ALLOC_CHUNK
258 #define ATTR_ALLOC_CHUNK 4
261 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
263 /* A hash table of die offsets for following references. */
264 #ifndef REF_HASH_SIZE
265 #define REF_HASH_SIZE 1021
268 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
270 /* Obstack for allocating temporary storage used during symbol reading. */
271 static struct obstack dwarf2_tmp_obstack
;
273 /* Offset to the first byte of the current compilation unit header,
274 for resolving relative reference dies. */
275 static unsigned int cu_header_offset
;
277 /* Allocate fields for structs, unions and enums in this size. */
278 #ifndef DW_FIELD_ALLOC_CHUNK
279 #define DW_FIELD_ALLOC_CHUNK 4
282 /* The language we are debugging. */
283 static enum language cu_language
;
284 static const struct language_defn
*cu_language_defn
;
286 /* Actually data from the sections. */
287 static char *dwarf_info_buffer
;
288 static char *dwarf_abbrev_buffer
;
289 static char *dwarf_line_buffer
;
291 /* A zeroed version of a partial die for initialization purposes. */
292 static struct partial_die_info zeroed_partial_die
;
294 /* The generic symbol table building routines have separate lists for
295 file scope symbols and all all other scopes (local scopes). So
296 we need to select the right one to pass to add_symbol_to_list().
297 We do it by keeping a pointer to the correct list in list_in_scope.
299 FIXME: The original dwarf code just treated the file scope as the first
300 local scope, and all other local scopes as nested local scopes, and worked
301 fine. Check to see if we really need to distinguish these
303 static struct pending
**list_in_scope
= &file_symbols
;
305 /* FIXME: decode_locdesc sets these variables to describe the location
306 to the caller. These ought to be a structure or something. If
307 none of the flags are set, the object lives at the address returned
308 by decode_locdesc. */
310 static int optimized_out
; /* No ops in location in expression,
311 so object was optimized out. */
312 static int isreg
; /* Object lives in register.
313 decode_locdesc's return value is
314 the register number. */
315 static int offreg
; /* Object's address is the sum of the
316 register specified by basereg, plus
317 the offset returned. */
318 static int basereg
; /* See `offreg'. */
319 static int isderef
; /* Value described by flags above is
320 the address of a pointer to the object. */
321 static int islocal
; /* Variable is at the returned offset
322 from the frame start, but there's
323 no identified frame pointer for
324 this function, so we can't say
325 which register it's relative to;
328 /* DW_AT_frame_base values for the current function.
329 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
330 contains the register number for the frame register.
331 frame_base_offset is the offset from the frame register to the
332 virtual stack frame. */
333 static int frame_base_reg
;
334 static CORE_ADDR frame_base_offset
;
336 /* This value is added to each symbol value. FIXME: Generalize to
337 the section_offsets structure used by dbxread (once this is done,
338 pass the appropriate section number to end_symtab). */
339 static CORE_ADDR baseaddr
; /* Add to each symbol value */
341 /* We put a pointer to this structure in the read_symtab_private field
343 The complete dwarf information for an objfile is kept in the
344 psymbol_obstack, so that absolute die references can be handled.
345 Most of the information in this structure is related to an entire
346 object file and could be passed via the sym_private field of the objfile.
347 It is however conceivable that dwarf2 might not be the only type
348 of symbols read from an object file. */
352 /* Pointer to start of dwarf info buffer for the objfile. */
354 char *dwarf_info_buffer
;
356 /* Offset in dwarf_info_buffer for this compilation unit. */
358 unsigned long dwarf_info_offset
;
360 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
362 char *dwarf_abbrev_buffer
;
364 /* Size of dwarf abbreviation section for the objfile. */
366 unsigned int dwarf_abbrev_size
;
368 /* Pointer to start of dwarf line buffer for the objfile. */
370 char *dwarf_line_buffer
;
373 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
374 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
375 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
376 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
377 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
378 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
380 /* Maintain an array of referenced fundamental types for the current
381 compilation unit being read. For DWARF version 1, we have to construct
382 the fundamental types on the fly, since no information about the
383 fundamental types is supplied. Each such fundamental type is created by
384 calling a language dependent routine to create the type, and then a
385 pointer to that type is then placed in the array at the index specified
386 by it's FT_<TYPENAME> value. The array has a fixed size set by the
387 FT_NUM_MEMBERS compile time constant, which is the number of predefined
388 fundamental types gdb knows how to construct. */
389 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
391 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
392 but this would require a corresponding change in unpack_field_as_long
394 static int bits_per_byte
= 8;
396 /* The routines that read and process dies for a C struct or C++ class
397 pass lists of data member fields and lists of member function fields
398 in an instance of a field_info structure, as defined below. */
401 /* List of data member and baseclasses fields. */
404 struct nextfield
*next
;
410 /* Number of fields. */
413 /* Number of baseclasses. */
416 /* Set if the accesibility of one of the fields is not public. */
417 int non_public_fields
;
419 /* Member function fields array, entries are allocated in the order they
420 are encountered in the object file. */
423 struct nextfnfield
*next
;
424 struct fn_field fnfield
;
427 /* Member function fieldlist array, contains name of possibly overloaded
428 member function, number of overloaded member functions and a pointer
429 to the head of the member function field chain. */
434 struct nextfnfield
*head
;
437 /* Number of entries in the fnfieldlists array. */
441 /* FIXME: Kludge to mark a varargs function type for C++ member function
442 argument processing. */
443 #define TYPE_FLAG_VARARGS (1 << 10)
445 /* Dwarf2 has no clean way to discern C++ static and non-static member
446 functions. G++ helps GDB by marking the first parameter for non-static
447 member functions (which is the this pointer) as artificial.
448 We pass this information between dwarf2_add_member_fn and
449 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
450 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
452 /* Various complaints about symbol reading that don't abort the process */
454 static struct complaint dwarf2_const_ignored
=
456 "type qualifier 'const' ignored", 0, 0
458 static struct complaint dwarf2_volatile_ignored
=
460 "type qualifier 'volatile' ignored", 0, 0
462 static struct complaint dwarf2_non_const_array_bound_ignored
=
464 "non-constant array bounds form '%s' ignored", 0, 0
466 static struct complaint dwarf2_missing_line_number_section
=
468 "missing .debug_line section", 0, 0
470 static struct complaint dwarf2_mangled_line_number_section
=
472 "mangled .debug_line section", 0, 0
474 static struct complaint dwarf2_unsupported_die_ref_attr
=
476 "unsupported die ref attribute form: '%s'", 0, 0
478 static struct complaint dwarf2_unsupported_stack_op
=
480 "unsupported stack op: '%s'", 0, 0
482 static struct complaint dwarf2_complex_location_expr
=
484 "location expression too complex", 0, 0
486 static struct complaint dwarf2_unsupported_tag
=
488 "unsupported tag: '%s'", 0, 0
490 static struct complaint dwarf2_unsupported_at_encoding
=
492 "unsupported DW_AT_encoding: '%s'", 0, 0
494 static struct complaint dwarf2_unsupported_at_frame_base
=
496 "unsupported DW_AT_frame_base for function '%s'", 0, 0
498 static struct complaint dwarf2_unexpected_tag
=
500 "unexepected tag in read_type_die: '%s'", 0, 0
502 static struct complaint dwarf2_missing_at_frame_base
=
504 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
506 static struct complaint dwarf2_bad_static_member_name
=
508 "unrecognized static data member name '%s'", 0, 0
510 static struct complaint dwarf2_unsupported_accessibility
=
512 "unsupported accessibility %d", 0, 0
514 static struct complaint dwarf2_bad_member_name_complaint
=
516 "cannot extract member name from '%s'", 0, 0
518 static struct complaint dwarf2_missing_member_fn_type_complaint
=
520 "member function type missing for '%s'", 0, 0
522 static struct complaint dwarf2_vtbl_not_found_complaint
=
524 "virtual function table pointer not found when defining class '%s'", 0, 0
526 static struct complaint dwarf2_absolute_sibling_complaint
=
528 "ignoring absolute DW_AT_sibling", 0, 0
530 static struct complaint dwarf2_const_value_length_mismatch
=
532 "const value length mismatch for '%s', got %d, expected %d", 0, 0
534 static struct complaint dwarf2_unsupported_const_value_attr
=
536 "unsupported const value attribute form: '%s'", 0, 0
539 /* Remember the addr_size read from the dwarf.
540 If a target expects to link compilation units with differing address
541 sizes, gdb needs to be sure that the appropriate size is here for
542 whatever scope is currently getting read. */
543 static int address_size
;
545 /* Some elf32 object file formats while linked for a 32 bit address
546 space contain debug information that has assumed 64 bit
547 addresses. Eg 64 bit MIPS target produced by GCC/GAS/LD where the
548 symbol table contains 32bit address values while its .debug_info
549 section contains 64 bit address values.
550 ADDRESS_SIGNIFICANT_SIZE specifies the number significant bits in
551 the ADDRESS_SIZE bytes read from the file */
552 static int address_significant_size
;
554 /* Externals references. */
555 extern int info_verbose
; /* From main.c; nonzero => verbose */
557 /* local function prototypes */
559 static void dwarf2_locate_sections
PARAMS ((bfd
*, asection
*, PTR
));
562 static void dwarf2_build_psymtabs_easy
PARAMS ((struct objfile
*,
563 struct section_offsets
*,
567 static void dwarf2_build_psymtabs_hard
PARAMS ((struct objfile
*,
568 struct section_offsets
*,
571 static char *scan_partial_symbols
PARAMS ((char *, struct objfile
*,
572 CORE_ADDR
*, CORE_ADDR
*));
574 static void add_partial_symbol
PARAMS ((struct partial_die_info
*,
577 static void dwarf2_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
579 static void psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
581 static char *dwarf2_read_section
PARAMS ((struct objfile
*, file_ptr
,
584 static void dwarf2_read_abbrevs
PARAMS ((bfd
*, unsigned int));
586 static void dwarf2_empty_abbrev_table
PARAMS ((PTR
));
588 static struct abbrev_info
*dwarf2_lookup_abbrev
PARAMS ((unsigned int));
590 static char *read_partial_die
PARAMS ((struct partial_die_info
*,
591 bfd
*, char *, int *));
593 static char *read_full_die
PARAMS ((struct die_info
**, bfd
*, char *));
595 static char *read_attribute
PARAMS ((struct attribute
*, struct attr_abbrev
*,
598 static unsigned int read_1_byte
PARAMS ((bfd
*, char *));
600 static int read_1_signed_byte
PARAMS ((bfd
*, char *));
602 static unsigned int read_2_bytes
PARAMS ((bfd
*, char *));
604 static unsigned int read_4_bytes
PARAMS ((bfd
*, char *));
606 static unsigned int read_8_bytes
PARAMS ((bfd
*, char *));
608 static CORE_ADDR read_address
PARAMS ((bfd
*, char *));
610 static char *read_n_bytes
PARAMS ((bfd
*, char *, unsigned int));
612 static char *read_string
PARAMS ((bfd
*, char *, unsigned int *));
614 static unsigned int read_unsigned_leb128
PARAMS ((bfd
*, char *,
617 static int read_signed_leb128
PARAMS ((bfd
*, char *, unsigned int *));
619 static void set_cu_language
PARAMS ((unsigned int));
621 static struct attribute
*dwarf_attr
PARAMS ((struct die_info
*,
624 static void dwarf_decode_lines
PARAMS ((unsigned int, char *, bfd
*));
626 static void dwarf2_start_subfile
PARAMS ((char *, char *));
628 static struct symbol
*new_symbol
PARAMS ((struct die_info
*, struct type
*,
631 static void dwarf2_const_value
PARAMS ((struct attribute
*, struct symbol
*,
634 static struct type
*die_type
PARAMS ((struct die_info
*, struct objfile
*));
636 static struct type
*die_containing_type
PARAMS ((struct die_info
*,
640 static struct type
*type_at_offset
PARAMS ((unsigned int, struct objfile
*));
643 static struct type
*tag_type_to_type
PARAMS ((struct die_info
*,
646 static void read_type_die
PARAMS ((struct die_info
*, struct objfile
*));
648 static void read_typedef
PARAMS ((struct die_info
*, struct objfile
*));
650 static void read_base_type
PARAMS ((struct die_info
*, struct objfile
*));
652 static void read_file_scope
PARAMS ((struct die_info
*, struct objfile
*));
654 static void read_func_scope
PARAMS ((struct die_info
*, struct objfile
*));
656 static void read_lexical_block_scope
PARAMS ((struct die_info
*,
659 static int dwarf2_get_pc_bounds
PARAMS ((struct die_info
*,
660 CORE_ADDR
*, CORE_ADDR
*,
663 static void dwarf2_add_field
PARAMS ((struct field_info
*, struct die_info
*,
666 static void dwarf2_attach_fields_to_type
PARAMS ((struct field_info
*,
670 static char *skip_member_fn_name
PARAMS ((char *));
672 static void dwarf2_add_member_fn
PARAMS ((struct field_info
*,
673 struct die_info
*, struct type
*,
674 struct objfile
*objfile
));
676 static void dwarf2_attach_fn_fields_to_type
PARAMS ((struct field_info
*,
680 static void read_structure_scope
PARAMS ((struct die_info
*, struct objfile
*));
682 static void read_common_block
PARAMS ((struct die_info
*, struct objfile
*));
684 static void read_enumeration
PARAMS ((struct die_info
*, struct objfile
*));
686 static struct type
*dwarf_base_type
PARAMS ((int, int, struct objfile
*));
688 static CORE_ADDR decode_locdesc
PARAMS ((struct dwarf_block
*,
691 static void read_array_type
PARAMS ((struct die_info
*, struct objfile
*));
693 static void read_tag_pointer_type
PARAMS ((struct die_info
*,
696 static void read_tag_ptr_to_member_type
PARAMS ((struct die_info
*,
699 static void read_tag_reference_type
PARAMS ((struct die_info
*,
702 static void read_tag_const_type
PARAMS ((struct die_info
*, struct objfile
*));
704 static void read_tag_volatile_type
PARAMS ((struct die_info
*,
707 static void read_tag_string_type
PARAMS ((struct die_info
*,
710 static void read_subroutine_type
PARAMS ((struct die_info
*,
713 struct die_info
*read_comp_unit
PARAMS ((char *, bfd
*));
715 static void free_die_list
PARAMS ((struct die_info
*));
717 static void process_die
PARAMS ((struct die_info
*, struct objfile
*));
719 static char *dwarf2_linkage_name
PARAMS ((struct die_info
*));
721 static char *dwarf_tag_name
PARAMS ((unsigned int));
723 static char *dwarf_attr_name
PARAMS ((unsigned int));
725 static char *dwarf_form_name
PARAMS ((unsigned int));
727 static char *dwarf_stack_op_name
PARAMS ((unsigned int));
729 static char *dwarf_bool_name
PARAMS ((unsigned int));
731 static char *dwarf_type_encoding_name
PARAMS ((unsigned int));
734 static char *dwarf_cfi_name
PARAMS ((unsigned int));
736 struct die_info
*copy_die
PARAMS ((struct die_info
*));
739 struct die_info
*sibling_die
PARAMS ((struct die_info
*));
741 void dump_die
PARAMS ((struct die_info
*));
743 void dump_die_list
PARAMS ((struct die_info
*));
745 void store_in_ref_table
PARAMS ((unsigned int, struct die_info
*));
747 static void dwarf2_empty_die_ref_table
PARAMS ((void));
749 static unsigned int dwarf2_get_ref_die_offset
PARAMS ((struct attribute
*));
751 struct die_info
*follow_die_ref
PARAMS ((unsigned int));
753 static struct type
*dwarf2_fundamental_type
PARAMS ((struct objfile
*, int));
755 /* memory allocation interface */
757 static void dwarf2_free_tmp_obstack
PARAMS ((PTR
));
759 static struct dwarf_block
*dwarf_alloc_block
PARAMS ((void));
761 static struct abbrev_info
*dwarf_alloc_abbrev
PARAMS ((void));
763 static struct die_info
*dwarf_alloc_die
PARAMS ((void));
765 /* Try to locate the sections we need for DWARF 2 debugging
766 information and return true if we have enough to do something. */
769 dwarf2_has_info (abfd
)
772 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
773 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
774 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
784 /* This function is mapped across the sections and remembers the
785 offset and size of each of the debugging sections we are interested
789 dwarf2_locate_sections (ignore_abfd
, sectp
, ignore_ptr
)
794 if (STREQ (sectp
->name
, INFO_SECTION
))
796 dwarf_info_offset
= sectp
->filepos
;
797 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
799 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
801 dwarf_abbrev_offset
= sectp
->filepos
;
802 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
804 else if (STREQ (sectp
->name
, LINE_SECTION
))
806 dwarf_line_offset
= sectp
->filepos
;
807 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
809 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
811 dwarf_pubnames_offset
= sectp
->filepos
;
812 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
814 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
816 dwarf_aranges_offset
= sectp
->filepos
;
817 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
819 else if (STREQ (sectp
->name
, LOC_SECTION
))
821 dwarf_loc_offset
= sectp
->filepos
;
822 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
824 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
826 dwarf_macinfo_offset
= sectp
->filepos
;
827 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
829 else if (STREQ (sectp
->name
, STR_SECTION
))
831 dwarf_str_offset
= sectp
->filepos
;
832 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
836 /* Build a partial symbol table. */
839 dwarf2_build_psymtabs (objfile
, section_offsets
, mainline
)
840 struct objfile
*objfile
;
841 struct section_offsets
*section_offsets
;
845 /* We definitely need the .debug_info and .debug_abbrev sections */
847 dwarf_info_buffer
= dwarf2_read_section (objfile
,
850 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
853 dwarf_line_buffer
= dwarf2_read_section (objfile
,
857 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
858 objfile
->static_psymbols
.size
== 0)
860 init_psymbol_list (objfile
, 1024);
864 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
866 /* Things are significanlty easier if we have .debug_aranges and
867 .debug_pubnames sections */
869 dwarf2_build_psymtabs_easy (objfile
, section_offsets
, mainline
);
873 /* only test this case for now */
875 /* In this case we have to work a bit harder */
876 dwarf2_build_psymtabs_hard (objfile
, section_offsets
, mainline
);
881 /* Build the partial symbol table from the information in the
882 .debug_pubnames and .debug_aranges sections. */
885 dwarf2_build_psymtabs_easy (objfile
, section_offsets
, mainline
)
886 struct objfile
*objfile
;
887 struct section_offsets
*section_offsets
;
890 bfd
*abfd
= objfile
->obfd
;
891 char *aranges_buffer
, *pubnames_buffer
;
892 char *aranges_ptr
, *pubnames_ptr
;
893 unsigned int entry_length
, version
, info_offset
, info_size
;
895 pubnames_buffer
= dwarf2_read_section (objfile
,
896 dwarf_pubnames_offset
,
897 dwarf_pubnames_size
);
898 pubnames_ptr
= pubnames_buffer
;
899 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
901 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
903 version
= read_1_byte (abfd
, pubnames_ptr
);
905 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
907 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
911 aranges_buffer
= dwarf2_read_section (objfile
,
912 dwarf_aranges_offset
,
918 /* Build the partial symbol table by doing a quick pass through the
919 .debug_info and .debug_abbrev sections. */
922 dwarf2_build_psymtabs_hard (objfile
, section_offsets
, mainline
)
923 struct objfile
*objfile
;
924 struct section_offsets
*section_offsets
;
927 /* Instead of reading this into a big buffer, we should probably use
928 mmap() on architectures that support it. (FIXME) */
929 bfd
*abfd
= objfile
->obfd
;
930 char *info_ptr
, *abbrev_ptr
;
931 char *beg_of_comp_unit
;
932 struct comp_unit_head cu_header
;
933 struct partial_die_info comp_unit_die
;
934 struct partial_symtab
*pst
;
935 struct cleanup
*back_to
;
936 int comp_unit_has_pc_info
;
937 CORE_ADDR lowpc
, highpc
;
939 /* Number of bytes of any addresses that are signficant */
940 address_significant_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
942 info_ptr
= dwarf_info_buffer
;
943 abbrev_ptr
= dwarf_abbrev_buffer
;
945 obstack_init (&dwarf2_tmp_obstack
);
946 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
948 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
949 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
951 beg_of_comp_unit
= info_ptr
;
952 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
954 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
956 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
958 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
960 address_size
= cu_header
.addr_size
;
962 if (cu_header
.version
!= 2)
964 error ("Dwarf Error: wrong version in compilation unit header.");
967 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
969 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
970 (long) cu_header
.abbrev_offset
,
971 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
974 if (beg_of_comp_unit
+ cu_header
.length
+ 4
975 > dwarf_info_buffer
+ dwarf_info_size
)
977 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
978 (long) cu_header
.length
,
979 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
982 if (address_size
< address_significant_size
)
984 error ("Dwarf Error: bad address size (%ld) in compilation unit header (offset 0x%lx + 11).",
985 (long) cu_header
.addr_size
,
986 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
989 /* Read the abbrevs for this compilation unit into a table */
990 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
991 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
993 /* Read the compilation unit die */
994 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
995 info_ptr
, &comp_unit_has_pc_info
);
997 /* Set the language we're debugging */
998 set_cu_language (comp_unit_die
.language
);
1000 /* Allocate a new partial symbol table structure */
1001 pst
= start_psymtab_common (objfile
, section_offsets
,
1002 comp_unit_die
.name
? comp_unit_die
.name
: "",
1003 comp_unit_die
.lowpc
,
1004 objfile
->global_psymbols
.next
,
1005 objfile
->static_psymbols
.next
);
1007 pst
->read_symtab_private
= (char *)
1008 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1009 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1010 DWARF_INFO_BUFFER(pst
) = dwarf_info_buffer
;
1011 DWARF_INFO_OFFSET(pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1012 DWARF_ABBREV_BUFFER(pst
) = dwarf_abbrev_buffer
;
1013 DWARF_ABBREV_SIZE(pst
) = dwarf_abbrev_size
;
1014 DWARF_LINE_BUFFER(pst
) = dwarf_line_buffer
;
1015 baseaddr
= ANOFFSET (section_offsets
, 0);
1017 /* Store the function that reads in the rest of the symbol table */
1018 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1020 /* Check if comp unit has_children.
1021 If so, read the rest of the partial symbols from this comp unit.
1022 If not, there's no more debug_info for this comp unit. */
1023 if (comp_unit_die
.has_children
)
1025 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
1027 /* If the compilation unit didn't have an explicit address range,
1028 then use the information extracted from its child dies. */
1029 if (!comp_unit_has_pc_info
)
1031 comp_unit_die
.lowpc
= lowpc
;
1032 comp_unit_die
.highpc
= highpc
;
1035 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1036 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1038 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1039 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1040 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1041 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1042 sort_pst_symbols (pst
);
1044 /* If there is already a psymtab or symtab for a file of this
1045 name, remove it. (If there is a symtab, more drastic things
1046 also happen.) This happens in VxWorks. */
1047 free_named_symtabs (pst
->filename
);
1049 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1051 do_cleanups (back_to
);
1054 /* Read in all interesting dies to the end of the compilation unit. */
1057 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1059 struct objfile
*objfile
;
1063 bfd
*abfd
= objfile
->obfd
;
1064 struct partial_die_info pdi
;
1066 /* This function is called after we've read in the comp_unit_die in
1067 order to read its children. We start the nesting level at 1 since
1068 we have pushed 1 level down in order to read the comp unit's children.
1069 The comp unit itself is at level 0, so we stop reading when we pop
1070 back to that level. */
1072 int nesting_level
= 1;
1075 *lowpc
= ((CORE_ADDR
) -1);
1076 *highpc
= ((CORE_ADDR
) 0);
1078 while (nesting_level
)
1080 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1086 case DW_TAG_subprogram
:
1089 if (pdi
.lowpc
< *lowpc
)
1093 if (pdi
.highpc
> *highpc
)
1095 *highpc
= pdi
.highpc
;
1097 if ((pdi
.is_external
|| nesting_level
== 1)
1098 && !pdi
.is_declaration
)
1100 add_partial_symbol (&pdi
, objfile
);
1104 case DW_TAG_variable
:
1105 case DW_TAG_typedef
:
1106 case DW_TAG_class_type
:
1107 case DW_TAG_structure_type
:
1108 case DW_TAG_union_type
:
1109 case DW_TAG_enumeration_type
:
1110 if ((pdi
.is_external
|| nesting_level
== 1)
1111 && !pdi
.is_declaration
)
1113 add_partial_symbol (&pdi
, objfile
);
1116 case DW_TAG_enumerator
:
1117 /* File scope enumerators are added to the partial symbol
1119 if (nesting_level
== 2)
1120 add_partial_symbol (&pdi
, objfile
);
1122 case DW_TAG_base_type
:
1123 /* File scope base type definitions are added to the partial
1125 if (nesting_level
== 1)
1126 add_partial_symbol (&pdi
, objfile
);
1133 /* If the die has a sibling, skip to the sibling.
1134 Do not skip enumeration types, we want to record their
1136 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1138 info_ptr
= pdi
.sibling
;
1140 else if (pdi
.has_children
)
1142 /* Die has children, but the optional DW_AT_sibling attribute
1153 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1154 from `maint check'. */
1155 if (*lowpc
== ((CORE_ADDR
) -1))
1161 add_partial_symbol (pdi
, objfile
)
1162 struct partial_die_info
*pdi
;
1163 struct objfile
*objfile
;
1169 case DW_TAG_subprogram
:
1170 if (pdi
->is_external
)
1172 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1173 mst_text, objfile);*/
1174 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1175 VAR_NAMESPACE
, LOC_BLOCK
,
1176 &objfile
->global_psymbols
,
1177 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1181 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1182 mst_file_text, objfile);*/
1183 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1184 VAR_NAMESPACE
, LOC_BLOCK
,
1185 &objfile
->static_psymbols
,
1186 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1189 case DW_TAG_variable
:
1190 if (pdi
->is_external
)
1193 Don't enter into the minimal symbol tables as there is
1194 a minimal symbol table entry from the ELF symbols already.
1195 Enter into partial symbol table if it has a location
1196 descriptor or a type.
1197 If the location descriptor is missing, new_symbol will create
1198 a LOC_UNRESOLVED symbol, the address of the variable will then
1199 be determined from the minimal symbol table whenever the variable
1201 The address for the partial symbol table entry is not
1202 used by GDB, but it comes in handy for debugging partial symbol
1206 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1207 if (pdi
->locdesc
|| pdi
->has_type
)
1208 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1209 VAR_NAMESPACE
, LOC_STATIC
,
1210 &objfile
->global_psymbols
,
1211 0, addr
+ baseaddr
, cu_language
, objfile
);
1215 /* Static Variable. Skip symbols without location descriptors. */
1216 if (pdi
->locdesc
== NULL
)
1218 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1219 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1220 mst_file_data, objfile);*/
1221 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1222 VAR_NAMESPACE
, LOC_STATIC
,
1223 &objfile
->static_psymbols
,
1224 0, addr
+ baseaddr
, cu_language
, objfile
);
1227 case DW_TAG_typedef
:
1228 case DW_TAG_base_type
:
1229 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1230 VAR_NAMESPACE
, LOC_TYPEDEF
,
1231 &objfile
->static_psymbols
,
1232 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1234 case DW_TAG_class_type
:
1235 case DW_TAG_structure_type
:
1236 case DW_TAG_union_type
:
1237 case DW_TAG_enumeration_type
:
1238 /* Skip aggregate types without children, these are external
1240 if (pdi
->has_children
== 0)
1242 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1243 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1244 &objfile
->static_psymbols
,
1245 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1247 if (cu_language
== language_cplus
)
1249 /* For C++, these implicitly act as typedefs as well. */
1250 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1251 VAR_NAMESPACE
, LOC_TYPEDEF
,
1252 &objfile
->static_psymbols
,
1253 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1256 case DW_TAG_enumerator
:
1257 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1258 VAR_NAMESPACE
, LOC_CONST
,
1259 &objfile
->static_psymbols
,
1260 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1267 /* Expand this partial symbol table into a full symbol table. */
1270 dwarf2_psymtab_to_symtab (pst
)
1271 struct partial_symtab
*pst
;
1273 /* FIXME: This is barely more than a stub. */
1278 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1284 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1285 gdb_flush (gdb_stdout
);
1288 psymtab_to_symtab_1 (pst
);
1290 /* Finish up the debug error message. */
1292 printf_filtered ("done.\n");
1298 psymtab_to_symtab_1 (pst
)
1299 struct partial_symtab
*pst
;
1301 struct objfile
*objfile
= pst
->objfile
;
1302 bfd
*abfd
= objfile
->obfd
;
1303 struct comp_unit_head cu_header
;
1304 struct die_info
*dies
;
1305 unsigned long offset
;
1306 CORE_ADDR lowpc
, highpc
;
1307 struct die_info
*child_die
;
1309 struct symtab
*symtab
;
1310 struct cleanup
*back_to
;
1312 /* Set local variables from the partial symbol table info. */
1313 offset
= DWARF_INFO_OFFSET(pst
);
1314 dwarf_info_buffer
= DWARF_INFO_BUFFER(pst
);
1315 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER(pst
);
1316 dwarf_abbrev_size
= DWARF_ABBREV_SIZE(pst
);
1317 dwarf_line_buffer
= DWARF_LINE_BUFFER(pst
);
1318 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1319 cu_header_offset
= offset
;
1320 info_ptr
= dwarf_info_buffer
+ offset
;
1322 obstack_init (&dwarf2_tmp_obstack
);
1323 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1326 make_cleanup ((make_cleanup_func
) really_free_pendings
, NULL
);
1328 /* read in the comp_unit header */
1329 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1331 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1333 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1335 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1338 /* Read the abbrevs for this compilation unit */
1339 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1340 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1342 dies
= read_comp_unit (info_ptr
, abfd
);
1344 make_cleanup ((make_cleanup_func
) free_die_list
, dies
);
1346 /* Do line number decoding in read_file_scope () */
1347 process_die (dies
, objfile
);
1349 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1351 /* Some compilers don't define a DW_AT_high_pc attribute for
1352 the compilation unit. If the DW_AT_high_pc is missing,
1353 synthesize it, by scanning the DIE's below the compilation unit. */
1355 if (dies
->has_children
)
1357 child_die
= dies
->next
;
1358 while (child_die
&& child_die
->tag
)
1360 if (child_die
->tag
== DW_TAG_subprogram
)
1362 CORE_ADDR low
, high
;
1364 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1366 highpc
= max (highpc
, high
);
1369 child_die
= sibling_die (child_die
);
1373 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1375 /* Set symtab language to language from DW_AT_language.
1376 If the compilation is from a C file generated by language preprocessors,
1377 do not set the language if it was already deduced by start_subfile. */
1379 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1381 symtab
->language
= cu_language
;
1383 pst
->symtab
= symtab
;
1385 sort_symtab_syms (pst
->symtab
);
1387 do_cleanups (back_to
);
1390 /* Process a die and its children. */
1393 process_die (die
, objfile
)
1394 struct die_info
*die
;
1395 struct objfile
*objfile
;
1399 case DW_TAG_padding
:
1401 case DW_TAG_compile_unit
:
1402 read_file_scope (die
, objfile
);
1404 case DW_TAG_subprogram
:
1405 read_subroutine_type (die
, objfile
);
1406 read_func_scope (die
, objfile
);
1408 case DW_TAG_inlined_subroutine
:
1409 /* FIXME: These are ignored for now.
1410 They could be used to set breakpoints on all inlined instances
1411 of a function and make GDB `next' properly over inlined functions. */
1413 case DW_TAG_lexical_block
:
1414 read_lexical_block_scope (die
, objfile
);
1416 case DW_TAG_class_type
:
1417 case DW_TAG_structure_type
:
1418 case DW_TAG_union_type
:
1419 read_structure_scope (die
, objfile
);
1421 case DW_TAG_enumeration_type
:
1422 read_enumeration (die
, objfile
);
1424 case DW_TAG_subroutine_type
:
1425 read_subroutine_type (die
, objfile
);
1427 case DW_TAG_array_type
:
1428 read_array_type (die
, objfile
);
1430 case DW_TAG_pointer_type
:
1431 read_tag_pointer_type (die
, objfile
);
1433 case DW_TAG_ptr_to_member_type
:
1434 read_tag_ptr_to_member_type (die
, objfile
);
1436 case DW_TAG_reference_type
:
1437 read_tag_reference_type (die
, objfile
);
1439 case DW_TAG_string_type
:
1440 read_tag_string_type (die
, objfile
);
1442 case DW_TAG_base_type
:
1443 read_base_type (die
, objfile
);
1444 if (dwarf_attr (die
, DW_AT_name
))
1446 /* Add a typedef symbol for the base type definition. */
1447 new_symbol (die
, die
->type
, objfile
);
1450 case DW_TAG_common_block
:
1451 read_common_block (die
, objfile
);
1453 case DW_TAG_common_inclusion
:
1456 new_symbol (die
, NULL
, objfile
);
1462 read_file_scope (die
, objfile
)
1463 struct die_info
*die
;
1464 struct objfile
*objfile
;
1466 unsigned int line_offset
= 0;
1467 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1468 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1469 struct attribute
*attr
;
1470 char *name
= "<unknown>";
1471 char *comp_dir
= NULL
;
1472 struct die_info
*child_die
;
1473 bfd
*abfd
= objfile
->obfd
;
1475 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1477 if (die
->has_children
)
1479 child_die
= die
->next
;
1480 while (child_die
&& child_die
->tag
)
1482 if (child_die
->tag
== DW_TAG_subprogram
)
1484 CORE_ADDR low
, high
;
1486 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1488 lowpc
= min (lowpc
, low
);
1489 highpc
= max (highpc
, high
);
1492 child_die
= sibling_die (child_die
);
1497 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1498 from finish_block. */
1499 if (lowpc
== ((CORE_ADDR
) -1))
1504 attr
= dwarf_attr (die
, DW_AT_name
);
1507 name
= DW_STRING (attr
);
1509 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1512 comp_dir
= DW_STRING (attr
);
1515 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1516 directory, get rid of it. */
1517 char *cp
= strchr (comp_dir
, ':');
1519 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1524 if (objfile
->ei
.entry_point
>= lowpc
&&
1525 objfile
->ei
.entry_point
< highpc
)
1527 objfile
->ei
.entry_file_lowpc
= lowpc
;
1528 objfile
->ei
.entry_file_highpc
= highpc
;
1531 attr
= dwarf_attr (die
, DW_AT_language
);
1534 set_cu_language (DW_UNSND (attr
));
1537 /* We assume that we're processing GCC output. */
1538 processing_gcc_compilation
= 2;
1540 /* FIXME:Do something here. */
1541 if (dip
->at_producer
!= NULL
)
1543 handle_producer (dip
->at_producer
);
1547 /* The compilation unit may be in a different language or objfile,
1548 zero out all remembered fundamental types. */
1549 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1551 start_symtab (name
, comp_dir
, lowpc
);
1552 record_debugformat ("DWARF 2");
1554 /* Decode line number information if present. */
1555 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1558 line_offset
= DW_UNSND (attr
);
1559 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1562 /* Process all dies in compilation unit. */
1563 if (die
->has_children
)
1565 child_die
= die
->next
;
1566 while (child_die
&& child_die
->tag
)
1568 process_die (child_die
, objfile
);
1569 child_die
= sibling_die (child_die
);
1575 read_func_scope (die
, objfile
)
1576 struct die_info
*die
;
1577 struct objfile
*objfile
;
1579 register struct context_stack
*new;
1582 struct die_info
*child_die
;
1583 struct attribute
*attr
;
1586 name
= dwarf2_linkage_name (die
);
1588 /* Ignore functions with missing or empty names and functions with
1589 missing or invalid low and high pc attributes. */
1590 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1596 if (objfile
->ei
.entry_point
>= lowpc
&&
1597 objfile
->ei
.entry_point
< highpc
)
1599 objfile
->ei
.entry_func_lowpc
= lowpc
;
1600 objfile
->ei
.entry_func_highpc
= highpc
;
1603 if (STREQ (name
, "main")) /* FIXME: hardwired name */
1605 objfile
->ei
.main_func_lowpc
= lowpc
;
1606 objfile
->ei
.main_func_highpc
= highpc
;
1609 /* Decode DW_AT_frame_base location descriptor if present, keep result
1610 for DW_OP_fbreg operands in decode_locdesc. */
1611 frame_base_reg
= -1;
1612 frame_base_offset
= 0;
1613 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1616 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1618 complain (&dwarf2_unsupported_at_frame_base
, name
);
1620 frame_base_reg
= addr
;
1623 frame_base_reg
= basereg
;
1624 frame_base_offset
= addr
;
1627 complain (&dwarf2_unsupported_at_frame_base
, name
);
1630 new = push_context (0, lowpc
);
1631 new->name
= new_symbol (die
, die
->type
, objfile
);
1632 list_in_scope
= &local_symbols
;
1634 if (die
->has_children
)
1636 child_die
= die
->next
;
1637 while (child_die
&& child_die
->tag
)
1639 process_die (child_die
, objfile
);
1640 child_die
= sibling_die (child_die
);
1644 new = pop_context ();
1645 /* Make a block for the local symbols within. */
1646 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1647 lowpc
, highpc
, objfile
);
1648 list_in_scope
= &file_symbols
;
1651 /* Process all the DIES contained within a lexical block scope. Start
1652 a new scope, process the dies, and then close the scope. */
1655 read_lexical_block_scope (die
, objfile
)
1656 struct die_info
*die
;
1657 struct objfile
*objfile
;
1659 register struct context_stack
*new;
1660 CORE_ADDR lowpc
, highpc
;
1661 struct die_info
*child_die
;
1663 /* Ignore blocks with missing or invalid low and high pc attributes. */
1664 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1669 push_context (0, lowpc
);
1670 if (die
->has_children
)
1672 child_die
= die
->next
;
1673 while (child_die
&& child_die
->tag
)
1675 process_die (child_die
, objfile
);
1676 child_die
= sibling_die (child_die
);
1679 new = pop_context ();
1681 if (local_symbols
!= NULL
)
1683 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1686 local_symbols
= new->locals
;
1689 /* Get low and high pc attributes from a die.
1690 Return 1 if the attributes are present and valid, otherwise, return 0. */
1693 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1694 struct die_info
*die
;
1697 struct objfile
*objfile
;
1699 struct attribute
*attr
;
1703 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1705 low
= DW_ADDR (attr
);
1708 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1710 high
= DW_ADDR (attr
);
1717 /* When using the GNU linker, .gnu.linkonce. sections are used to
1718 eliminate duplicate copies of functions and vtables and such.
1719 The linker will arbitrarily choose one and discard the others.
1720 The AT_*_pc values for such functions refer to local labels in
1721 these sections. If the section from that file was discarded, the
1722 labels are not in the output, so the relocs get a value of 0.
1723 If this is a discarded function, mark the pc bounds as invalid,
1724 so that GDB will ignore it. */
1725 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1733 /* Add an aggregate field to the field list. */
1736 dwarf2_add_field (fip
, die
, objfile
)
1737 struct field_info
*fip
;
1738 struct die_info
*die
;
1739 struct objfile
*objfile
;
1741 struct nextfield
*new_field
;
1742 struct attribute
*attr
;
1744 char *fieldname
= "";
1746 /* Allocate a new field list entry and link it in. */
1747 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1748 make_cleanup (free
, new_field
);
1749 memset (new_field
, 0, sizeof (struct nextfield
));
1750 new_field
->next
= fip
->fields
;
1751 fip
->fields
= new_field
;
1754 /* Handle accessibility and virtuality of field.
1755 The default accessibility for members is public, the default
1756 accessibility for inheritance is private. */
1757 if (die
->tag
!= DW_TAG_inheritance
)
1758 new_field
->accessibility
= DW_ACCESS_public
;
1760 new_field
->accessibility
= DW_ACCESS_private
;
1761 new_field
->virtuality
= DW_VIRTUALITY_none
;
1763 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1765 new_field
->accessibility
= DW_UNSND (attr
);
1766 if (new_field
->accessibility
!= DW_ACCESS_public
)
1767 fip
->non_public_fields
= 1;
1768 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1770 new_field
->virtuality
= DW_UNSND (attr
);
1772 fp
= &new_field
->field
;
1773 if (die
->tag
== DW_TAG_member
)
1775 /* Get type of field. */
1776 fp
->type
= die_type (die
, objfile
);
1778 /* Get bit size of field (zero if none). */
1779 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1782 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1786 FIELD_BITSIZE (*fp
) = 0;
1789 /* Get bit offset of field. */
1790 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1793 FIELD_BITPOS (*fp
) =
1794 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1797 FIELD_BITPOS (*fp
) = 0;
1798 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1801 if (BITS_BIG_ENDIAN
)
1803 /* For big endian bits, the DW_AT_bit_offset gives the
1804 additional bit offset from the MSB of the containing
1805 anonymous object to the MSB of the field. We don't
1806 have to do anything special since we don't need to
1807 know the size of the anonymous object. */
1808 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1812 /* For little endian bits, compute the bit offset to the
1813 MSB of the anonymous object, subtract off the number of
1814 bits from the MSB of the field to the MSB of the
1815 object, and then subtract off the number of bits of
1816 the field itself. The result is the bit offset of
1817 the LSB of the field. */
1819 int bit_offset
= DW_UNSND (attr
);
1821 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1824 /* The size of the anonymous object containing
1825 the bit field is explicit, so use the
1826 indicated size (in bytes). */
1827 anonymous_size
= DW_UNSND (attr
);
1831 /* The size of the anonymous object containing
1832 the bit field must be inferred from the type
1833 attribute of the data member containing the
1835 anonymous_size
= TYPE_LENGTH (fp
->type
);
1837 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1838 - bit_offset
- FIELD_BITSIZE (*fp
);
1842 /* Get name of field. */
1843 attr
= dwarf_attr (die
, DW_AT_name
);
1844 if (attr
&& DW_STRING (attr
))
1845 fieldname
= DW_STRING (attr
);
1846 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1847 &objfile
->type_obstack
);
1849 /* Change accessibility for artificial fields (e.g. virtual table
1850 pointer or virtual base class pointer) to private. */
1851 if (dwarf_attr (die
, DW_AT_artificial
))
1853 new_field
->accessibility
= DW_ACCESS_private
;
1854 fip
->non_public_fields
= 1;
1857 else if (die
->tag
== DW_TAG_variable
)
1862 /* C++ static member.
1863 Get physical name, extract field name from physical name. */
1864 physname
= dwarf2_linkage_name (die
);
1865 if (physname
== NULL
)
1869 while (*cp
&& !is_cplus_marker (*cp
))
1873 if (*fieldname
== '\0')
1875 complain (&dwarf2_bad_static_member_name
, physname
);
1878 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1879 &objfile
->type_obstack
));
1880 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1881 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1882 &objfile
->type_obstack
);
1884 else if (die
->tag
== DW_TAG_inheritance
)
1886 /* C++ base class field. */
1887 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1889 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1890 FIELD_BITSIZE (*fp
) = 0;
1891 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1892 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1893 fip
->nbaseclasses
++;
1897 /* Create the vector of fields, and attach it to the type. */
1900 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1901 struct field_info
*fip
;
1903 struct objfile
*objfile
;
1905 int nfields
= fip
->nfields
;
1907 /* Record the field count, allocate space for the array of fields,
1908 and create blank accessibility bitfields if necessary. */
1909 TYPE_NFIELDS (type
) = nfields
;
1910 TYPE_FIELDS (type
) = (struct field
*)
1911 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1912 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1914 if (fip
->non_public_fields
)
1916 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1918 TYPE_FIELD_PRIVATE_BITS (type
) =
1919 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1920 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1922 TYPE_FIELD_PROTECTED_BITS (type
) =
1923 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1924 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1926 TYPE_FIELD_IGNORE_BITS (type
) =
1927 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1928 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1931 /* If the type has baseclasses, allocate and clear a bit vector for
1932 TYPE_FIELD_VIRTUAL_BITS. */
1933 if (fip
->nbaseclasses
)
1935 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1938 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1939 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1940 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1941 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1942 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1945 /* Copy the saved-up fields into the field vector. Start from the head
1946 of the list, adding to the tail of the field array, so that they end
1947 up in the same order in the array in which they were added to the list. */
1948 while (nfields
-- > 0)
1950 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1951 switch (fip
->fields
->accessibility
)
1953 case DW_ACCESS_private
:
1954 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1957 case DW_ACCESS_protected
:
1958 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1961 case DW_ACCESS_public
:
1965 /* Unknown accessibility. Complain and treat it as public. */
1967 complain (&dwarf2_unsupported_accessibility
,
1968 fip
->fields
->accessibility
);
1972 if (nfields
< fip
->nbaseclasses
)
1974 switch (fip
->fields
->virtuality
)
1976 case DW_VIRTUALITY_virtual
:
1977 case DW_VIRTUALITY_pure_virtual
:
1978 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1982 fip
->fields
= fip
->fields
->next
;
1986 /* Skip to the end of a member function name in a mangled name. */
1989 skip_member_fn_name (physname
)
1992 char *endname
= physname
;
1994 /* Skip over leading underscores. */
1995 while (*endname
== '_')
1998 /* Find two succesive underscores. */
2000 endname
= strchr (endname
, '_');
2001 while (endname
!= NULL
&& *++endname
!= '_');
2003 if (endname
== NULL
)
2005 complain (&dwarf2_bad_member_name_complaint
, physname
);
2010 /* Take care of trailing underscores. */
2011 if (endname
[1] != '_')
2017 /* Add a member function to the proper fieldlist. */
2020 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
2021 struct field_info
*fip
;
2022 struct die_info
*die
;
2024 struct objfile
*objfile
;
2026 struct attribute
*attr
;
2027 struct fnfieldlist
*flp
;
2029 struct fn_field
*fnp
;
2032 struct nextfnfield
*new_fnfield
;
2034 /* Extract member function name from mangled name. */
2035 physname
= dwarf2_linkage_name (die
);
2036 if (physname
== NULL
)
2038 if ((physname
[0] == '_' && physname
[1] == '_'
2039 && strchr ("0123456789Qt", physname
[2]))
2040 || DESTRUCTOR_PREFIX_P (physname
))
2042 /* Constructor and destructor field names are set to the name
2043 of the class, but without template parameter lists.
2044 The name might be missing for anonymous aggregates. */
2045 if (TYPE_TAG_NAME (type
))
2047 char *p
= strchr (TYPE_TAG_NAME (type
), '<');
2050 fieldname
= TYPE_TAG_NAME (type
);
2052 fieldname
= obsavestring (TYPE_TAG_NAME (type
),
2053 p
- TYPE_TAG_NAME (type
),
2054 &objfile
->type_obstack
);
2058 char *anon_name
= "";
2059 fieldname
= obsavestring (anon_name
, strlen (anon_name
),
2060 &objfile
->type_obstack
);
2065 char *endname
= skip_member_fn_name (physname
);
2067 /* Ignore member function if we were unable not extract the member
2069 if (endname
== physname
)
2071 fieldname
= obsavestring (physname
, endname
- physname
,
2072 &objfile
->type_obstack
);
2075 /* Look up member function name in fieldlist. */
2076 for (i
= 0; i
< fip
->nfnfields
; i
++)
2078 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2082 /* Create new list element if necessary. */
2083 if (i
< fip
->nfnfields
)
2084 flp
= &fip
->fnfieldlists
[i
];
2087 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2089 fip
->fnfieldlists
= (struct fnfieldlist
*)
2090 xrealloc (fip
->fnfieldlists
,
2091 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2092 * sizeof (struct fnfieldlist
));
2093 if (fip
->nfnfields
== 0)
2094 make_cleanup ((make_cleanup_func
) free_current_contents
,
2095 &fip
->fnfieldlists
);
2097 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2098 flp
->name
= fieldname
;
2104 /* Create a new member function field and chain it to the field list
2106 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2107 make_cleanup (free
, new_fnfield
);
2108 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2109 new_fnfield
->next
= flp
->head
;
2110 flp
->head
= new_fnfield
;
2113 /* Fill in the member function field info. */
2114 fnp
= &new_fnfield
->fnfield
;
2115 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2116 &objfile
->type_obstack
);
2117 fnp
->type
= alloc_type (objfile
);
2118 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2120 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2121 struct type
**arg_types
;
2122 int nparams
= TYPE_NFIELDS (die
->type
);
2125 /* Copy argument types from the subroutine type. */
2126 arg_types
= (struct type
**)
2127 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2128 for (iparams
= 0; iparams
< nparams
; iparams
++)
2129 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2131 /* Set last entry in argument type vector. */
2132 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2133 arg_types
[nparams
] = NULL
;
2135 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2137 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2139 /* Handle static member functions.
2140 Dwarf2 has no clean way to discern C++ static and non-static
2141 member functions. G++ helps GDB by marking the first
2142 parameter for non-static member functions (which is the
2143 this pointer) as artificial. We obtain this information
2144 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2145 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2146 fnp
->voffset
= VOFFSET_STATIC
;
2149 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2151 /* Get fcontext from DW_AT_containing_type if present. */
2152 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2153 fnp
->fcontext
= die_containing_type (die
, objfile
);
2155 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2156 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2158 /* Get accessibility. */
2159 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2162 switch (DW_UNSND (attr
))
2164 case DW_ACCESS_private
:
2165 fnp
->is_private
= 1;
2167 case DW_ACCESS_protected
:
2168 fnp
->is_protected
= 1;
2173 /* Get index in virtual function table if it is a virtual member function. */
2174 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2176 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2179 /* Create the vector of member function fields, and attach it to the type. */
2182 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2183 struct field_info
*fip
;
2185 struct objfile
*objfile
;
2187 struct fnfieldlist
*flp
;
2188 int total_length
= 0;
2191 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2192 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2193 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2195 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2197 struct nextfnfield
*nfp
= flp
->head
;
2198 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2201 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2202 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2203 fn_flp
->fn_fields
= (struct fn_field
*)
2204 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2205 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2206 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2208 total_length
+= flp
->length
;
2211 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2212 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2215 /* Called when we find the DIE that starts a structure or union scope
2216 (definition) to process all dies that define the members of the
2219 NOTE: we need to call struct_type regardless of whether or not the
2220 DIE has an at_name attribute, since it might be an anonymous
2221 structure or union. This gets the type entered into our set of
2224 However, if the structure is incomplete (an opaque struct/union)
2225 then suppress creating a symbol table entry for it since gdb only
2226 wants to find the one with the complete definition. Note that if
2227 it is complete, we just call new_symbol, which does it's own
2228 checking about whether the struct/union is anonymous or not (and
2229 suppresses creating a symbol table entry itself). */
2232 read_structure_scope (die
, objfile
)
2233 struct die_info
*die
;
2234 struct objfile
*objfile
;
2237 struct attribute
*attr
;
2239 type
= alloc_type (objfile
);
2241 INIT_CPLUS_SPECIFIC (type
);
2242 attr
= dwarf_attr (die
, DW_AT_name
);
2243 if (attr
&& DW_STRING (attr
))
2245 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2246 strlen (DW_STRING (attr
)),
2247 &objfile
->type_obstack
);
2250 if (die
->tag
== DW_TAG_structure_type
)
2252 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2254 else if (die
->tag
== DW_TAG_union_type
)
2256 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2260 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2262 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2265 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2268 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2272 TYPE_LENGTH (type
) = 0;
2275 /* We need to add the type field to the die immediately so we don't
2276 infinitely recurse when dealing with pointers to the structure
2277 type within the structure itself. */
2280 if (die
->has_children
)
2282 struct field_info fi
;
2283 struct die_info
*child_die
;
2284 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2286 memset (&fi
, 0, sizeof (struct field_info
));
2288 child_die
= die
->next
;
2290 while (child_die
&& child_die
->tag
)
2292 if (child_die
->tag
== DW_TAG_member
)
2294 dwarf2_add_field (&fi
, child_die
, objfile
);
2296 else if (child_die
->tag
== DW_TAG_variable
)
2298 /* C++ static member. */
2299 dwarf2_add_field (&fi
, child_die
, objfile
);
2301 else if (child_die
->tag
== DW_TAG_subprogram
)
2303 /* C++ member function. */
2304 process_die (child_die
, objfile
);
2305 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2307 else if (child_die
->tag
== DW_TAG_inheritance
)
2309 /* C++ base class field. */
2310 dwarf2_add_field (&fi
, child_die
, objfile
);
2314 process_die (child_die
, objfile
);
2316 child_die
= sibling_die (child_die
);
2319 /* Attach fields and member functions to the type. */
2321 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2324 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2326 /* Get the type which refers to the base class (possibly this
2327 class itself) which contains the vtable pointer for the current
2328 class from the DW_AT_containing_type attribute. */
2330 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2332 struct type
*t
= die_containing_type (die
, objfile
);
2334 TYPE_VPTR_BASETYPE (type
) = t
;
2337 static const char vptr_name
[] = { '_','v','p','t','r','\0' };
2340 /* Our own class provides vtbl ptr. */
2341 for (i
= TYPE_NFIELDS (t
) - 1;
2342 i
>= TYPE_N_BASECLASSES (t
);
2345 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2347 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2348 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2350 TYPE_VPTR_FIELDNO (type
) = i
;
2355 /* Complain if virtual function table field not found. */
2356 if (i
< TYPE_N_BASECLASSES (t
))
2357 complain (&dwarf2_vtbl_not_found_complaint
,
2358 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2362 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2367 new_symbol (die
, type
, objfile
);
2369 do_cleanups (back_to
);
2373 /* No children, must be stub. */
2374 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2380 /* Given a pointer to a die which begins an enumeration, process all
2381 the dies that define the members of the enumeration.
2383 This will be much nicer in draft 6 of the DWARF spec when our
2384 members will be dies instead squished into the DW_AT_element_list
2387 NOTE: We reverse the order of the element list. */
2390 read_enumeration (die
, objfile
)
2391 struct die_info
*die
;
2392 struct objfile
*objfile
;
2394 struct die_info
*child_die
;
2396 struct field
*fields
;
2397 struct attribute
*attr
;
2400 int unsigned_enum
= 1;
2402 type
= alloc_type (objfile
);
2404 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2405 attr
= dwarf_attr (die
, DW_AT_name
);
2406 if (attr
&& DW_STRING (attr
))
2408 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2409 strlen (DW_STRING (attr
)),
2410 &objfile
->type_obstack
);
2413 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2416 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2420 TYPE_LENGTH (type
) = 0;
2425 if (die
->has_children
)
2427 child_die
= die
->next
;
2428 while (child_die
&& child_die
->tag
)
2430 if (child_die
->tag
!= DW_TAG_enumerator
)
2432 process_die (child_die
, objfile
);
2436 attr
= dwarf_attr (child_die
, DW_AT_name
);
2439 sym
= new_symbol (child_die
, type
, objfile
);
2440 if (SYMBOL_VALUE (sym
) < 0)
2443 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2445 fields
= (struct field
*)
2447 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2448 * sizeof (struct field
));
2451 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2452 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2453 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2454 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2460 child_die
= sibling_die (child_die
);
2465 TYPE_NFIELDS (type
) = num_fields
;
2466 TYPE_FIELDS (type
) = (struct field
*)
2467 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2468 memcpy (TYPE_FIELDS (type
), fields
,
2469 sizeof (struct field
) * num_fields
);
2473 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2476 new_symbol (die
, type
, objfile
);
2479 /* Extract all information from a DW_TAG_array_type DIE and put it in
2480 the DIE's type field. For now, this only handles one dimensional
2484 read_array_type (die
, objfile
)
2485 struct die_info
*die
;
2486 struct objfile
*objfile
;
2488 struct die_info
*child_die
;
2489 struct type
*type
= NULL
;
2490 struct type
*element_type
, *range_type
, *index_type
;
2491 struct type
**range_types
= NULL
;
2492 struct attribute
*attr
;
2494 struct cleanup
*back_to
;
2496 /* Return if we've already decoded this type. */
2502 element_type
= die_type (die
, objfile
);
2504 /* Irix 6.2 native cc creates array types without children for
2505 arrays with unspecified length. */
2506 if (die
->has_children
== 0)
2508 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2509 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2510 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2514 back_to
= make_cleanup (null_cleanup
, NULL
);
2515 child_die
= die
->next
;
2516 while (child_die
&& child_die
->tag
)
2518 if (child_die
->tag
== DW_TAG_subrange_type
)
2520 unsigned int low
, high
;
2522 /* Default bounds to an array with unspecified length. */
2525 if (cu_language
== language_fortran
)
2527 /* FORTRAN implies a lower bound of 1, if not given. */
2531 index_type
= die_type (child_die
, objfile
);
2532 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2535 if (attr
->form
== DW_FORM_sdata
)
2537 low
= DW_SND (attr
);
2539 else if (attr
->form
== DW_FORM_udata
2540 || attr
->form
== DW_FORM_data1
2541 || attr
->form
== DW_FORM_data2
2542 || attr
->form
== DW_FORM_data4
)
2544 low
= DW_UNSND (attr
);
2548 complain (&dwarf2_non_const_array_bound_ignored
,
2549 dwarf_form_name (attr
->form
));
2551 die
->type
= lookup_pointer_type (element_type
);
2558 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2561 if (attr
->form
== DW_FORM_sdata
)
2563 high
= DW_SND (attr
);
2565 else if (attr
->form
== DW_FORM_udata
2566 || attr
->form
== DW_FORM_data1
2567 || attr
->form
== DW_FORM_data2
2568 || attr
->form
== DW_FORM_data4
)
2570 high
= DW_UNSND (attr
);
2572 else if (attr
->form
== DW_FORM_block1
)
2574 /* GCC encodes arrays with unspecified or dynamic length
2575 with a DW_FORM_block1 attribute.
2576 FIXME: GDB does not yet know how to handle dynamic
2577 arrays properly, treat them as arrays with unspecified
2583 complain (&dwarf2_non_const_array_bound_ignored
,
2584 dwarf_form_name (attr
->form
));
2586 die
->type
= lookup_pointer_type (element_type
);
2594 /* Create a range type and save it for array type creation. */
2595 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2597 range_types
= (struct type
**)
2598 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2599 * sizeof (struct type
*));
2601 make_cleanup ((make_cleanup_func
) free_current_contents
,
2604 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2606 child_die
= sibling_die (child_die
);
2609 /* Dwarf2 dimensions are output from left to right, create the
2610 necessary array types in backwards order. */
2611 type
= element_type
;
2613 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2615 do_cleanups (back_to
);
2617 /* Install the type in the die. */
2621 /* First cut: install each common block member as a global variable. */
2624 read_common_block (die
, objfile
)
2625 struct die_info
*die
;
2626 struct objfile
*objfile
;
2628 struct die_info
*child_die
;
2629 struct attribute
*attr
;
2631 CORE_ADDR base
= (CORE_ADDR
) 0;
2633 attr
= dwarf_attr (die
, DW_AT_location
);
2636 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2638 if (die
->has_children
)
2640 child_die
= die
->next
;
2641 while (child_die
&& child_die
->tag
)
2643 sym
= new_symbol (child_die
, NULL
, objfile
);
2644 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2647 SYMBOL_VALUE_ADDRESS (sym
) =
2648 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2649 add_symbol_to_list (sym
, &global_symbols
);
2651 child_die
= sibling_die (child_die
);
2656 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2657 the user defined type vector. */
2660 read_tag_pointer_type (die
, objfile
)
2661 struct die_info
*die
;
2662 struct objfile
*objfile
;
2665 struct attribute
*attr
;
2672 type
= lookup_pointer_type (die_type (die
, objfile
));
2673 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2676 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2680 TYPE_LENGTH (type
) = address_size
;
2685 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2686 the user defined type vector. */
2689 read_tag_ptr_to_member_type (die
, objfile
)
2690 struct die_info
*die
;
2691 struct objfile
*objfile
;
2694 struct type
*to_type
;
2695 struct type
*domain
;
2702 type
= alloc_type (objfile
);
2703 to_type
= die_type (die
, objfile
);
2704 domain
= die_containing_type (die
, objfile
);
2705 smash_to_member_type (type
, domain
, to_type
);
2710 /* Extract all information from a DW_TAG_reference_type DIE and add to
2711 the user defined type vector. */
2714 read_tag_reference_type (die
, objfile
)
2715 struct die_info
*die
;
2716 struct objfile
*objfile
;
2719 struct attribute
*attr
;
2726 type
= lookup_reference_type (die_type (die
, objfile
));
2727 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2730 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2734 TYPE_LENGTH (type
) = address_size
;
2740 read_tag_const_type (die
, objfile
)
2741 struct die_info
*die
;
2742 struct objfile
*objfile
;
2749 complain (&dwarf2_const_ignored
);
2750 die
->type
= die_type (die
, objfile
);
2754 read_tag_volatile_type (die
, objfile
)
2755 struct die_info
*die
;
2756 struct objfile
*objfile
;
2763 complain (&dwarf2_volatile_ignored
);
2764 die
->type
= die_type (die
, objfile
);
2767 /* Extract all information from a DW_TAG_string_type DIE and add to
2768 the user defined type vector. It isn't really a user defined type,
2769 but it behaves like one, with other DIE's using an AT_user_def_type
2770 attribute to reference it. */
2773 read_tag_string_type (die
, objfile
)
2774 struct die_info
*die
;
2775 struct objfile
*objfile
;
2777 struct type
*type
, *range_type
, *index_type
, *char_type
;
2778 struct attribute
*attr
;
2779 unsigned int length
;
2786 attr
= dwarf_attr (die
, DW_AT_string_length
);
2789 length
= DW_UNSND (attr
);
2795 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2796 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2797 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2798 type
= create_string_type (char_type
, range_type
);
2802 /* Handle DIES due to C code like:
2806 int (*funcp)(int a, long l);
2810 ('funcp' generates a DW_TAG_subroutine_type DIE)
2814 read_subroutine_type (die
, objfile
)
2815 struct die_info
*die
;
2816 struct objfile
*objfile
;
2818 struct type
*type
; /* Type that this function returns */
2819 struct type
*ftype
; /* Function that returns above type */
2820 struct attribute
*attr
;
2822 /* Decode the type that this subroutine returns */
2827 type
= die_type (die
, objfile
);
2828 ftype
= lookup_function_type (type
);
2830 /* All functions in C++ have prototypes. */
2831 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2832 if ((attr
&& (DW_UNSND (attr
) != 0))
2833 || cu_language
== language_cplus
)
2834 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2836 if (die
->has_children
)
2838 struct die_info
*child_die
;
2842 /* Count the number of parameters.
2843 FIXME: GDB currently ignores vararg functions, but knows about
2844 vararg member functions. */
2845 child_die
= die
->next
;
2846 while (child_die
&& child_die
->tag
)
2848 if (child_die
->tag
== DW_TAG_formal_parameter
)
2850 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2851 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2852 child_die
= sibling_die (child_die
);
2855 /* Allocate storage for parameters and fill them in. */
2856 TYPE_NFIELDS (ftype
) = nparams
;
2857 TYPE_FIELDS (ftype
) = (struct field
*)
2858 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2860 child_die
= die
->next
;
2861 while (child_die
&& child_die
->tag
)
2863 if (child_die
->tag
== DW_TAG_formal_parameter
)
2865 /* Dwarf2 has no clean way to discern C++ static and non-static
2866 member functions. G++ helps GDB by marking the first
2867 parameter for non-static member functions (which is the
2868 this pointer) as artificial. We pass this information
2869 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2870 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2872 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2874 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2875 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2878 child_die
= sibling_die (child_die
);
2886 read_typedef (die
, objfile
)
2887 struct die_info
*die
;
2888 struct objfile
*objfile
;
2894 struct attribute
*attr
;
2897 xtype
= die_type (die
, objfile
);
2899 type
= alloc_type (objfile
);
2900 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2901 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2902 TYPE_TARGET_TYPE (type
) = xtype
;
2903 attr
= dwarf_attr (die
, DW_AT_name
);
2904 if (attr
&& DW_STRING (attr
))
2905 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2906 strlen (DW_STRING (attr
)),
2907 &objfile
->type_obstack
);
2913 /* Find a representation of a given base type and install
2914 it in the TYPE field of the die. */
2917 read_base_type (die
, objfile
)
2918 struct die_info
*die
;
2919 struct objfile
*objfile
;
2922 struct attribute
*attr
;
2923 int encoding
= 0, size
= 0;
2925 /* If we've already decoded this die, this is a no-op. */
2931 attr
= dwarf_attr (die
, DW_AT_encoding
);
2934 encoding
= DW_UNSND (attr
);
2936 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2939 size
= DW_UNSND (attr
);
2941 attr
= dwarf_attr (die
, DW_AT_name
);
2942 if (attr
&& DW_STRING (attr
))
2944 enum type_code code
= TYPE_CODE_INT
;
2945 int is_unsigned
= 0;
2949 case DW_ATE_address
:
2950 /* Turn DW_ATE_address into a void * pointer. */
2951 code
= TYPE_CODE_PTR
;
2954 case DW_ATE_boolean
:
2955 code
= TYPE_CODE_BOOL
;
2958 case DW_ATE_complex_float
:
2959 code
= TYPE_CODE_COMPLEX
;
2962 code
= TYPE_CODE_FLT
;
2965 case DW_ATE_signed_char
:
2967 case DW_ATE_unsigned
:
2968 case DW_ATE_unsigned_char
:
2972 complain (&dwarf2_unsupported_at_encoding
,
2973 dwarf_type_encoding_name (encoding
));
2976 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2977 if (encoding
== DW_ATE_address
)
2978 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2982 type
= dwarf_base_type (encoding
, size
, objfile
);
2987 /* Read a whole compilation unit into a linked list of dies. */
2990 read_comp_unit (info_ptr
, abfd
)
2994 struct die_info
*first_die
, *last_die
, *die
;
2998 /* Reset die reference table, we are building a new one now. */
2999 dwarf2_empty_die_ref_table ();
3003 first_die
= last_die
= NULL
;
3006 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
3007 if (die
->has_children
)
3018 /* Enter die in reference hash table */
3019 store_in_ref_table (die
->offset
, die
);
3023 first_die
= last_die
= die
;
3027 last_die
->next
= die
;
3031 while (nesting_level
> 0);
3035 /* Free a linked list of dies. */
3038 free_die_list (dies
)
3039 struct die_info
*dies
;
3041 struct die_info
*die
, *next
;
3053 /* Read the contents of the section at OFFSET and of size SIZE from the
3054 object file specified by OBJFILE into the psymbol_obstack and return it. */
3057 dwarf2_read_section (objfile
, offset
, size
)
3058 struct objfile
*objfile
;
3062 bfd
*abfd
= objfile
->obfd
;
3068 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3069 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3070 (bfd_read (buf
, size
, 1, abfd
) != size
))
3073 error ("Dwarf Error: Can't read DWARF data from '%s'",
3074 bfd_get_filename (abfd
));
3079 /* In DWARF version 2, the description of the debugging information is
3080 stored in a separate .debug_abbrev section. Before we read any
3081 dies from a section we read in all abbreviations and install them
3085 dwarf2_read_abbrevs (abfd
, offset
)
3087 unsigned int offset
;
3090 struct abbrev_info
*cur_abbrev
;
3091 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3092 unsigned int abbrev_form
, hash_number
;
3094 /* empty the table */
3095 dwarf2_empty_abbrev_table (NULL
);
3097 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3098 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3099 abbrev_ptr
+= bytes_read
;
3101 /* loop until we reach an abbrev number of 0 */
3102 while (abbrev_number
)
3104 cur_abbrev
= dwarf_alloc_abbrev ();
3106 /* read in abbrev header */
3107 cur_abbrev
->number
= abbrev_number
;
3108 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3109 abbrev_ptr
+= bytes_read
;
3110 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3113 /* now read in declarations */
3114 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3115 abbrev_ptr
+= bytes_read
;
3116 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3117 abbrev_ptr
+= bytes_read
;
3120 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3122 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3123 xrealloc (cur_abbrev
->attrs
,
3124 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3125 * sizeof (struct attr_abbrev
));
3127 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3128 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3129 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3130 abbrev_ptr
+= bytes_read
;
3131 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3132 abbrev_ptr
+= bytes_read
;
3135 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3136 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3137 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3139 /* Get next abbreviation.
3140 Under Irix6 the abbreviations for a compilation unit are not
3141 always properly terminated with an abbrev number of 0.
3142 Exit loop if we encounter an abbreviation which we have
3143 already read (which means we are about to read the abbreviations
3144 for the next compile unit) or if the end of the abbreviation
3145 table is reached. */
3146 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3147 >= dwarf_abbrev_size
)
3149 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3150 abbrev_ptr
+= bytes_read
;
3151 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3156 /* Empty the abbrev table for a new compilation unit. */
3160 dwarf2_empty_abbrev_table (ignore
)
3164 struct abbrev_info
*abbrev
, *next
;
3166 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3169 abbrev
= dwarf2_abbrevs
[i
];
3172 next
= abbrev
->next
;
3173 free (abbrev
->attrs
);
3177 dwarf2_abbrevs
[i
] = NULL
;
3181 /* Lookup an abbrev_info structure in the abbrev hash table. */
3183 static struct abbrev_info
*
3184 dwarf2_lookup_abbrev (number
)
3185 unsigned int number
;
3187 unsigned int hash_number
;
3188 struct abbrev_info
*abbrev
;
3190 hash_number
= number
% ABBREV_HASH_SIZE
;
3191 abbrev
= dwarf2_abbrevs
[hash_number
];
3195 if (abbrev
->number
== number
)
3198 abbrev
= abbrev
->next
;
3203 /* Read a minimal amount of information into the minimal die structure. */
3206 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3207 struct partial_die_info
*part_die
;
3212 unsigned int abbrev_number
, bytes_read
, i
;
3213 struct abbrev_info
*abbrev
;
3214 struct attribute attr
;
3215 struct attribute spec_attr
;
3216 int found_spec_attr
= 0;
3217 int has_low_pc_attr
= 0;
3218 int has_high_pc_attr
= 0;
3220 *part_die
= zeroed_partial_die
;
3222 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3223 info_ptr
+= bytes_read
;
3227 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3230 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3232 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3233 part_die
->tag
= abbrev
->tag
;
3234 part_die
->has_children
= abbrev
->has_children
;
3235 part_die
->abbrev
= abbrev_number
;
3237 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3239 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3241 /* Store the data if it is of an attribute we want to keep in a
3242 partial symbol table. */
3247 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3248 if (part_die
->name
== NULL
)
3249 part_die
->name
= DW_STRING (&attr
);
3251 case DW_AT_MIPS_linkage_name
:
3252 part_die
->name
= DW_STRING (&attr
);
3255 has_low_pc_attr
= 1;
3256 part_die
->lowpc
= DW_ADDR (&attr
);
3259 has_high_pc_attr
= 1;
3260 part_die
->highpc
= DW_ADDR (&attr
);
3262 case DW_AT_location
:
3263 part_die
->locdesc
= DW_BLOCK (&attr
);
3265 case DW_AT_language
:
3266 part_die
->language
= DW_UNSND (&attr
);
3268 case DW_AT_external
:
3269 part_die
->is_external
= DW_UNSND (&attr
);
3271 case DW_AT_declaration
:
3272 part_die
->is_declaration
= DW_UNSND (&attr
);
3275 part_die
->has_type
= 1;
3277 case DW_AT_abstract_origin
:
3278 case DW_AT_specification
:
3279 found_spec_attr
= 1;
3283 /* Ignore absolute siblings, they might point outside of
3284 the current compile unit. */
3285 if (attr
.form
== DW_FORM_ref_addr
)
3286 complain(&dwarf2_absolute_sibling_complaint
);
3289 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3296 /* If we found a reference attribute and the die has no name, try
3297 to find a name in the referred to die. */
3299 if (found_spec_attr
&& part_die
->name
== NULL
)
3301 struct partial_die_info spec_die
;
3305 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3306 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3309 part_die
->name
= spec_die
.name
;
3311 /* Copy DW_AT_external attribute if it is set. */
3312 if (spec_die
.is_external
)
3313 part_die
->is_external
= spec_die
.is_external
;
3317 /* When using the GNU linker, .gnu.linkonce. sections are used to
3318 eliminate duplicate copies of functions and vtables and such.
3319 The linker will arbitrarily choose one and discard the others.
3320 The AT_*_pc values for such functions refer to local labels in
3321 these sections. If the section from that file was discarded, the
3322 labels are not in the output, so the relocs get a value of 0.
3323 If this is a discarded function, mark the pc bounds as invalid,
3324 so that GDB will ignore it. */
3325 if (has_low_pc_attr
&& has_high_pc_attr
3326 && part_die
->lowpc
< part_die
->highpc
3327 && (part_die
->lowpc
!= 0
3328 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3333 /* Read the die from the .debug_info section buffer. And set diep to
3334 point to a newly allocated die with its information. */
3337 read_full_die (diep
, abfd
, info_ptr
)
3338 struct die_info
**diep
;
3342 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3343 struct abbrev_info
*abbrev
;
3344 struct die_info
*die
;
3346 offset
= info_ptr
- dwarf_info_buffer
;
3347 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3348 info_ptr
+= bytes_read
;
3351 die
= dwarf_alloc_die ();
3353 die
->abbrev
= abbrev_number
;
3359 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3362 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3364 die
= dwarf_alloc_die ();
3365 die
->offset
= offset
;
3366 die
->tag
= abbrev
->tag
;
3367 die
->has_children
= abbrev
->has_children
;
3368 die
->abbrev
= abbrev_number
;
3371 die
->num_attrs
= abbrev
->num_attrs
;
3372 die
->attrs
= (struct attribute
*)
3373 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3375 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3377 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3385 /* Read an attribute described by an abbreviated attribute. */
3388 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3389 struct attribute
*attr
;
3390 struct attr_abbrev
*abbrev
;
3394 unsigned int bytes_read
;
3395 struct dwarf_block
*blk
;
3397 attr
->name
= abbrev
->name
;
3398 attr
->form
= abbrev
->form
;
3399 switch (abbrev
->form
)
3402 case DW_FORM_ref_addr
:
3403 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3404 info_ptr
+= address_size
;
3406 case DW_FORM_block2
:
3407 blk
= dwarf_alloc_block ();
3408 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3410 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3411 info_ptr
+= blk
->size
;
3412 DW_BLOCK (attr
) = blk
;
3414 case DW_FORM_block4
:
3415 blk
= dwarf_alloc_block ();
3416 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3418 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3419 info_ptr
+= blk
->size
;
3420 DW_BLOCK (attr
) = blk
;
3423 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3427 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3431 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3434 case DW_FORM_string
:
3435 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3436 info_ptr
+= bytes_read
;
3439 blk
= dwarf_alloc_block ();
3440 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3441 info_ptr
+= bytes_read
;
3442 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3443 info_ptr
+= blk
->size
;
3444 DW_BLOCK (attr
) = blk
;
3446 case DW_FORM_block1
:
3447 blk
= dwarf_alloc_block ();
3448 blk
->size
= read_1_byte (abfd
, info_ptr
);
3450 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3451 info_ptr
+= blk
->size
;
3452 DW_BLOCK (attr
) = blk
;
3455 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3459 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3463 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3464 info_ptr
+= bytes_read
;
3467 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3468 info_ptr
+= bytes_read
;
3471 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3475 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3479 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3482 case DW_FORM_ref_udata
:
3483 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3484 info_ptr
+= bytes_read
;
3487 case DW_FORM_indirect
:
3489 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3490 dwarf_form_name (abbrev
->form
));
3495 /* read dwarf information from a buffer */
3498 read_1_byte (abfd
, buf
)
3502 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3506 read_1_signed_byte (abfd
, buf
)
3510 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3514 read_2_bytes (abfd
, buf
)
3518 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3522 read_2_signed_bytes (abfd
, buf
)
3526 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3530 read_4_bytes (abfd
, buf
)
3534 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3538 read_4_signed_bytes (abfd
, buf
)
3542 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3546 read_8_bytes (abfd
, buf
)
3550 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3554 read_address (abfd
, buf
)
3558 CORE_ADDR retval
= 0;
3560 switch (address_size
)
3563 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3566 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3569 /* *THE* alternative is 8, right? */
3572 /* If the address being read is larger than the address that is
3573 applicable for the object file format then mask it down to the
3574 correct size. Take care to avoid unnecessary shift or shift
3576 if (address_size
> address_significant_size
3577 && address_significant_size
< sizeof (CORE_ADDR
))
3579 CORE_ADDR mask
= ((CORE_ADDR
) 0) - 1;
3580 retval
&= ~(mask
<< (address_significant_size
* 8));
3586 read_n_bytes (abfd
, buf
, size
)
3591 /* If the size of a host char is 8 bits, we can return a pointer
3592 to the buffer, otherwise we have to copy the data to a buffer
3593 allocated on the temporary obstack. */
3594 #if HOST_CHAR_BIT == 8
3600 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3601 for (i
= 0; i
< size
; ++i
)
3603 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3611 read_string (abfd
, buf
, bytes_read_ptr
)
3614 unsigned int *bytes_read_ptr
;
3616 /* If the size of a host char is 8 bits, we can return a pointer
3617 to the string, otherwise we have to copy the string to a buffer
3618 allocated on the temporary obstack. */
3619 #if HOST_CHAR_BIT == 8
3622 *bytes_read_ptr
= 1;
3625 *bytes_read_ptr
= strlen (buf
) + 1;
3631 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3633 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3639 *bytes_read_ptr
= 1;
3642 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3643 *bytes_read_ptr
= i
+ 1;
3644 return obstack_finish (&dwarf2_tmp_obstack
);
3649 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3652 unsigned int *bytes_read_ptr
;
3654 unsigned int result
, num_read
;
3664 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3667 result
|= ((byte
& 127) << shift
);
3668 if ((byte
& 128) == 0)
3674 *bytes_read_ptr
= num_read
;
3679 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3682 unsigned int *bytes_read_ptr
;
3685 int i
, shift
, size
, num_read
;
3695 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3698 result
|= ((byte
& 127) << shift
);
3700 if ((byte
& 128) == 0)
3705 if ((shift
< size
) && (byte
& 0x40))
3707 result
|= -(1 << shift
);
3709 *bytes_read_ptr
= num_read
;
3714 set_cu_language (lang
)
3721 cu_language
= language_c
;
3723 case DW_LANG_C_plus_plus
:
3724 cu_language
= language_cplus
;
3726 case DW_LANG_Fortran77
:
3727 case DW_LANG_Fortran90
:
3728 cu_language
= language_fortran
;
3730 case DW_LANG_Mips_Assembler
:
3731 cu_language
= language_asm
;
3734 case DW_LANG_Cobol74
:
3735 case DW_LANG_Cobol85
:
3736 case DW_LANG_Pascal83
:
3737 case DW_LANG_Modula2
:
3739 cu_language
= language_unknown
;
3742 cu_language_defn
= language_def (cu_language
);
3745 /* Return the named attribute or NULL if not there. */
3747 static struct attribute
*
3748 dwarf_attr (die
, name
)
3749 struct die_info
*die
;
3753 struct attribute
*spec
= NULL
;
3755 for (i
= 0; i
< die
->num_attrs
; ++i
)
3757 if (die
->attrs
[i
].name
== name
)
3759 return &die
->attrs
[i
];
3761 if (die
->attrs
[i
].name
== DW_AT_specification
3762 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3763 spec
= &die
->attrs
[i
];
3767 struct die_info
*ref_die
=
3768 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3771 return dwarf_attr (ref_die
, name
);
3777 /* Decode the line number information for the compilation unit whose
3778 line number info is at OFFSET in the .debug_line section.
3779 The compilation directory of the file is passed in COMP_DIR. */
3783 unsigned int num_files
;
3796 unsigned int num_dirs
;
3801 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3802 unsigned int offset
;
3808 struct line_head lh
;
3809 struct cleanup
*back_to
;
3810 unsigned int i
, bytes_read
;
3811 char *cur_file
, *cur_dir
;
3812 unsigned char op_code
, extended_op
, adj_opcode
;
3814 #define FILE_ALLOC_CHUNK 5
3815 #define DIR_ALLOC_CHUNK 5
3817 struct filenames files
;
3818 struct directories dirs
;
3820 if (dwarf_line_buffer
== NULL
)
3822 complain (&dwarf2_missing_line_number_section
);
3826 files
.num_files
= 0;
3832 line_ptr
= dwarf_line_buffer
+ offset
;
3834 /* read in the prologue */
3835 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3837 line_end
= line_ptr
+ lh
.total_length
;
3838 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3840 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3842 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3844 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3846 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3848 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3850 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3852 lh
.standard_opcode_lengths
= (unsigned char *)
3853 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3854 back_to
= make_cleanup ((make_cleanup_func
) free_current_contents
,
3855 &lh
.standard_opcode_lengths
);
3857 lh
.standard_opcode_lengths
[0] = 1;
3858 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3860 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3864 /* Read directory table */
3865 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3867 line_ptr
+= bytes_read
;
3868 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3870 dirs
.dirs
= (char **)
3871 xrealloc (dirs
.dirs
,
3872 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3873 if (dirs
.num_dirs
== 0)
3874 make_cleanup ((make_cleanup_func
) free_current_contents
, &dirs
.dirs
);
3876 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3878 line_ptr
+= bytes_read
;
3880 /* Read file name table */
3881 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3883 line_ptr
+= bytes_read
;
3884 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3886 files
.files
= (struct fileinfo
*)
3887 xrealloc (files
.files
,
3888 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3889 * sizeof (struct fileinfo
));
3890 if (files
.num_files
== 0)
3891 make_cleanup ((make_cleanup_func
) free_current_contents
,
3894 files
.files
[files
.num_files
].name
= cur_file
;
3895 files
.files
[files
.num_files
].dir
=
3896 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3897 line_ptr
+= bytes_read
;
3898 files
.files
[files
.num_files
].time
=
3899 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3900 line_ptr
+= bytes_read
;
3901 files
.files
[files
.num_files
].size
=
3902 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3903 line_ptr
+= bytes_read
;
3906 line_ptr
+= bytes_read
;
3908 /* Read the statement sequences until there's nothing left. */
3909 while (line_ptr
< line_end
)
3911 /* state machine registers */
3912 CORE_ADDR address
= 0;
3913 unsigned int file
= 1;
3914 unsigned int line
= 1;
3915 unsigned int column
= 0;
3916 int is_stmt
= lh
.default_is_stmt
;
3917 int basic_block
= 0;
3918 int end_sequence
= 0;
3920 /* Start a subfile for the current file of the state machine. */
3921 if (files
.num_files
>= file
)
3923 /* The file and directory tables are 0 based, the references
3925 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3926 (files
.files
[file
- 1].dir
3927 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3931 /* Decode the table. */
3932 while (! end_sequence
)
3934 op_code
= read_1_byte (abfd
, line_ptr
);
3938 case DW_LNS_extended_op
:
3939 line_ptr
+= 1; /* ignore length */
3940 extended_op
= read_1_byte (abfd
, line_ptr
);
3942 switch (extended_op
)
3944 case DW_LNE_end_sequence
:
3946 /* Don't call record_line here. The end_sequence
3947 instruction provides the address of the first byte
3948 *after* the last line in the sequence; it's not the
3949 address of any real source line. However, the GDB
3950 linetable structure only records the starts of lines,
3951 not the ends. This is a weakness of GDB. */
3953 case DW_LNE_set_address
:
3954 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3955 line_ptr
+= address_size
;
3957 case DW_LNE_define_file
:
3958 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3959 line_ptr
+= bytes_read
;
3960 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3962 files
.files
= (struct fileinfo
*)
3963 xrealloc (files
.files
,
3964 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3965 * sizeof (struct fileinfo
));
3966 if (files
.num_files
== 0)
3967 make_cleanup ((make_cleanup_func
) free_current_contents
,
3970 files
.files
[files
.num_files
].name
= cur_file
;
3971 files
.files
[files
.num_files
].dir
=
3972 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3973 line_ptr
+= bytes_read
;
3974 files
.files
[files
.num_files
].time
=
3975 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3976 line_ptr
+= bytes_read
;
3977 files
.files
[files
.num_files
].size
=
3978 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3979 line_ptr
+= bytes_read
;
3983 complain (&dwarf2_mangled_line_number_section
);
3988 record_line (current_subfile
, line
, address
);
3991 case DW_LNS_advance_pc
:
3992 address
+= lh
.minimum_instruction_length
3993 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3994 line_ptr
+= bytes_read
;
3996 case DW_LNS_advance_line
:
3997 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3998 line_ptr
+= bytes_read
;
4000 case DW_LNS_set_file
:
4001 /* The file and directory tables are 0 based, the references
4003 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4004 line_ptr
+= bytes_read
;
4005 dwarf2_start_subfile
4006 (files
.files
[file
- 1].name
,
4007 (files
.files
[file
- 1].dir
4008 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4011 case DW_LNS_set_column
:
4012 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4013 line_ptr
+= bytes_read
;
4015 case DW_LNS_negate_stmt
:
4016 is_stmt
= (!is_stmt
);
4018 case DW_LNS_set_basic_block
:
4021 case DW_LNS_const_add_pc
:
4022 address
+= (255 - lh
.opcode_base
) / lh
.line_range
;
4024 case DW_LNS_fixed_advance_pc
:
4025 address
+= read_2_bytes (abfd
, line_ptr
);
4028 default: /* special operand */
4029 adj_opcode
= op_code
- lh
.opcode_base
;
4030 address
+= (adj_opcode
/ lh
.line_range
)
4031 * lh
.minimum_instruction_length
;
4032 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4033 /* append row to matrix using current values */
4034 record_line (current_subfile
, line
, address
);
4040 do_cleanups (back_to
);
4043 /* Start a subfile for DWARF. FILENAME is the name of the file and
4044 DIRNAME the name of the source directory which contains FILENAME
4045 or NULL if not known.
4046 This routine tries to keep line numbers from identical absolute and
4047 relative file names in a common subfile.
4049 Using the `list' example from the GDB testsuite, which resides in
4050 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4051 of /srcdir/list0.c yields the following debugging information for list0.c:
4053 DW_AT_name: /srcdir/list0.c
4054 DW_AT_comp_dir: /compdir
4055 files.files[0].name: list0.h
4056 files.files[0].dir: /srcdir
4057 files.files[1].name: list0.c
4058 files.files[1].dir: /srcdir
4060 The line number information for list0.c has to end up in a single
4061 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4064 dwarf2_start_subfile (filename
, dirname
)
4068 /* If the filename isn't absolute, try to match an existing subfile
4069 with the full pathname. */
4071 if (*filename
!= '/' && dirname
!= NULL
)
4073 struct subfile
*subfile
;
4074 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4076 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4078 if (STREQ (subfile
->name
, fullname
))
4080 current_subfile
= subfile
;
4087 start_subfile (filename
, dirname
);
4090 /* Given a pointer to a DWARF information entry, figure out if we need
4091 to make a symbol table entry for it, and if so, create a new entry
4092 and return a pointer to it.
4093 If TYPE is NULL, determine symbol type from the die, otherwise
4094 used the passed type.
4097 static struct symbol
*
4098 new_symbol (die
, type
, objfile
)
4099 struct die_info
*die
;
4101 struct objfile
*objfile
;
4103 struct symbol
*sym
= NULL
;
4105 struct attribute
*attr
= NULL
;
4106 struct attribute
*attr2
= NULL
;
4109 name
= dwarf2_linkage_name (die
);
4112 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4113 sizeof (struct symbol
));
4114 OBJSTAT (objfile
, n_syms
++);
4115 memset (sym
, 0, sizeof (struct symbol
));
4116 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4117 &objfile
->symbol_obstack
);
4119 /* Default assumptions.
4120 Use the passed type or decode it from the die. */
4121 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4122 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4124 SYMBOL_TYPE (sym
) = type
;
4126 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4127 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4130 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4133 /* If this symbol is from a C++ compilation, then attempt to
4134 cache the demangled form for future reference. This is a
4135 typical time versus space tradeoff, that was decided in favor
4136 of time because it sped up C++ symbol lookups by a factor of
4139 SYMBOL_LANGUAGE (sym
) = cu_language
;
4140 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4144 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4147 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4149 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4151 case DW_TAG_subprogram
:
4152 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4154 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4155 attr2
= dwarf_attr (die
, DW_AT_external
);
4156 if (attr2
&& (DW_UNSND (attr2
) != 0))
4158 add_symbol_to_list (sym
, &global_symbols
);
4162 add_symbol_to_list (sym
, list_in_scope
);
4165 case DW_TAG_variable
:
4166 /* Compilation with minimal debug info may result in variables
4167 with missing type entries. Change the misleading `void' type
4168 to something sensible. */
4169 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4170 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4171 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4172 "<variable, no debug info>",
4174 attr
= dwarf_attr (die
, DW_AT_const_value
);
4177 dwarf2_const_value (attr
, sym
, objfile
);
4178 attr2
= dwarf_attr (die
, DW_AT_external
);
4179 if (attr2
&& (DW_UNSND (attr2
) != 0))
4180 add_symbol_to_list (sym
, &global_symbols
);
4182 add_symbol_to_list (sym
, list_in_scope
);
4185 attr
= dwarf_attr (die
, DW_AT_location
);
4188 attr2
= dwarf_attr (die
, DW_AT_external
);
4189 if (attr2
&& (DW_UNSND (attr2
) != 0))
4191 SYMBOL_VALUE_ADDRESS (sym
) =
4192 decode_locdesc (DW_BLOCK (attr
), objfile
);
4193 add_symbol_to_list (sym
, &global_symbols
);
4195 /* In shared libraries the address of the variable
4196 in the location descriptor might still be relocatable,
4197 so its value could be zero.
4198 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4199 value is zero, the address of the variable will then
4200 be determined from the minimal symbol table whenever
4201 the variable is referenced. */
4202 if (SYMBOL_VALUE_ADDRESS (sym
))
4204 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4205 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4208 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4212 SYMBOL_VALUE (sym
) = addr
=
4213 decode_locdesc (DW_BLOCK (attr
), objfile
);
4214 add_symbol_to_list (sym
, list_in_scope
);
4217 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4221 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4225 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4226 SYMBOL_BASEREG (sym
) = basereg
;
4230 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4234 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4235 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4241 /* We do not know the address of this symbol.
4242 If it is an external symbol and we have type information
4243 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4244 The address of the variable will then be determined from
4245 the minimal symbol table whenever the variable is
4247 attr2
= dwarf_attr (die
, DW_AT_external
);
4248 if (attr2
&& (DW_UNSND (attr2
) != 0)
4249 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4251 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4252 add_symbol_to_list (sym
, &global_symbols
);
4256 case DW_TAG_formal_parameter
:
4257 attr
= dwarf_attr (die
, DW_AT_location
);
4260 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4263 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4269 if (basereg
!= frame_base_reg
)
4270 complain (&dwarf2_complex_location_expr
);
4271 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4275 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4276 SYMBOL_BASEREG (sym
) = basereg
;
4281 SYMBOL_CLASS (sym
) = LOC_ARG
;
4284 attr
= dwarf_attr (die
, DW_AT_const_value
);
4287 dwarf2_const_value (attr
, sym
, objfile
);
4289 add_symbol_to_list (sym
, list_in_scope
);
4291 case DW_TAG_unspecified_parameters
:
4292 /* From varargs functions; gdb doesn't seem to have any
4293 interest in this information, so just ignore it for now.
4296 case DW_TAG_class_type
:
4297 case DW_TAG_structure_type
:
4298 case DW_TAG_union_type
:
4299 case DW_TAG_enumeration_type
:
4300 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4301 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4302 add_symbol_to_list (sym
, list_in_scope
);
4304 /* The semantics of C++ state that "struct foo { ... }" also
4305 defines a typedef for "foo". Synthesize a typedef symbol so
4306 that "ptype foo" works as expected. */
4307 if (cu_language
== language_cplus
)
4309 struct symbol
*typedef_sym
= (struct symbol
*)
4310 obstack_alloc (&objfile
->symbol_obstack
,
4311 sizeof (struct symbol
));
4312 *typedef_sym
= *sym
;
4313 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4314 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4315 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4316 obsavestring (SYMBOL_NAME (sym
),
4317 strlen (SYMBOL_NAME (sym
)),
4318 &objfile
->type_obstack
);
4319 add_symbol_to_list (typedef_sym
, list_in_scope
);
4322 case DW_TAG_typedef
:
4323 case DW_TAG_base_type
:
4324 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4325 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4326 add_symbol_to_list (sym
, list_in_scope
);
4328 case DW_TAG_enumerator
:
4329 attr
= dwarf_attr (die
, DW_AT_const_value
);
4332 dwarf2_const_value (attr
, sym
, objfile
);
4334 add_symbol_to_list (sym
, list_in_scope
);
4337 /* Not a tag we recognize. Hopefully we aren't processing
4338 trash data, but since we must specifically ignore things
4339 we don't recognize, there is nothing else we should do at
4341 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4348 /* Copy constant value from an attribute to a symbol. */
4351 dwarf2_const_value (attr
, sym
, objfile
)
4352 struct attribute
*attr
;
4354 struct objfile
*objfile
;
4356 struct dwarf_block
*blk
;
4361 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4362 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4363 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4364 SYMBOL_VALUE_BYTES (sym
) = (char *)
4365 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4366 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4367 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4369 case DW_FORM_block1
:
4370 case DW_FORM_block2
:
4371 case DW_FORM_block4
:
4373 blk
= DW_BLOCK (attr
);
4374 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4375 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4376 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4377 SYMBOL_VALUE_BYTES (sym
) = (char *)
4378 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4379 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4380 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4388 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4389 SYMBOL_CLASS (sym
) = LOC_CONST
;
4392 complain (&dwarf2_unsupported_const_value_attr
,
4393 dwarf_form_name (attr
->form
));
4394 SYMBOL_VALUE (sym
) = 0;
4395 SYMBOL_CLASS (sym
) = LOC_CONST
;
4400 /* Return the type of the die in question using its DW_AT_type attribute. */
4402 static struct type
*
4403 die_type (die
, objfile
)
4404 struct die_info
*die
;
4405 struct objfile
*objfile
;
4408 struct attribute
*type_attr
;
4409 struct die_info
*type_die
;
4412 type_attr
= dwarf_attr (die
, DW_AT_type
);
4415 /* A missing DW_AT_type represents a void type. */
4416 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4420 ref
= dwarf2_get_ref_die_offset (type_attr
);
4421 type_die
= follow_die_ref (ref
);
4424 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4428 type
= tag_type_to_type (type_die
, objfile
);
4431 dump_die (type_die
);
4432 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4437 /* Return the containing type of the die in question using its
4438 DW_AT_containing_type attribute. */
4440 static struct type
*
4441 die_containing_type (die
, objfile
)
4442 struct die_info
*die
;
4443 struct objfile
*objfile
;
4445 struct type
*type
= NULL
;
4446 struct attribute
*type_attr
;
4447 struct die_info
*type_die
= NULL
;
4450 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4453 ref
= dwarf2_get_ref_die_offset (type_attr
);
4454 type_die
= follow_die_ref (ref
);
4457 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4460 type
= tag_type_to_type (type_die
, objfile
);
4465 dump_die (type_die
);
4466 error ("Dwarf Error: Problem turning containing type into gdb type.");
4472 static struct type
*
4473 type_at_offset (offset
, objfile
)
4474 unsigned int offset
;
4475 struct objfile
*objfile
;
4477 struct die_info
*die
;
4480 die
= follow_die_ref (offset
);
4483 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4486 type
= tag_type_to_type (die
, objfile
);
4491 static struct type
*
4492 tag_type_to_type (die
, objfile
)
4493 struct die_info
*die
;
4494 struct objfile
*objfile
;
4502 read_type_die (die
, objfile
);
4506 error ("Dwarf Error: Cannot find type of die.");
4513 read_type_die (die
, objfile
)
4514 struct die_info
*die
;
4515 struct objfile
*objfile
;
4519 case DW_TAG_class_type
:
4520 case DW_TAG_structure_type
:
4521 case DW_TAG_union_type
:
4522 read_structure_scope (die
, objfile
);
4524 case DW_TAG_enumeration_type
:
4525 read_enumeration (die
, objfile
);
4527 case DW_TAG_subprogram
:
4528 case DW_TAG_subroutine_type
:
4529 read_subroutine_type (die
, objfile
);
4531 case DW_TAG_array_type
:
4532 read_array_type (die
, objfile
);
4534 case DW_TAG_pointer_type
:
4535 read_tag_pointer_type (die
, objfile
);
4537 case DW_TAG_ptr_to_member_type
:
4538 read_tag_ptr_to_member_type (die
, objfile
);
4540 case DW_TAG_reference_type
:
4541 read_tag_reference_type (die
, objfile
);
4543 case DW_TAG_const_type
:
4544 read_tag_const_type (die
, objfile
);
4546 case DW_TAG_volatile_type
:
4547 read_tag_volatile_type (die
, objfile
);
4549 case DW_TAG_string_type
:
4550 read_tag_string_type (die
, objfile
);
4552 case DW_TAG_typedef
:
4553 read_typedef (die
, objfile
);
4555 case DW_TAG_base_type
:
4556 read_base_type (die
, objfile
);
4559 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4564 static struct type
*
4565 dwarf_base_type (encoding
, size
, objfile
)
4568 struct objfile
*objfile
;
4570 /* FIXME - this should not produce a new (struct type *)
4571 every time. It should cache base types. */
4575 case DW_ATE_address
:
4576 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4578 case DW_ATE_boolean
:
4579 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4581 case DW_ATE_complex_float
:
4584 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4588 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4594 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4598 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4605 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4608 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4612 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4616 case DW_ATE_signed_char
:
4617 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4619 case DW_ATE_unsigned
:
4623 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4626 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4630 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4634 case DW_ATE_unsigned_char
:
4635 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4638 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4646 struct die_info
*old_die
;
4648 struct die_info
*new_die
;
4651 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4652 memset (new_die
, 0, sizeof (struct die_info
));
4654 new_die
->tag
= old_die
->tag
;
4655 new_die
->has_children
= old_die
->has_children
;
4656 new_die
->abbrev
= old_die
->abbrev
;
4657 new_die
->offset
= old_die
->offset
;
4658 new_die
->type
= NULL
;
4660 num_attrs
= old_die
->num_attrs
;
4661 new_die
->num_attrs
= num_attrs
;
4662 new_die
->attrs
= (struct attribute
*)
4663 xmalloc (num_attrs
* sizeof (struct attribute
));
4665 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4667 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4668 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4669 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4672 new_die
->next
= NULL
;
4677 /* Return sibling of die, NULL if no sibling. */
4681 struct die_info
*die
;
4683 int nesting_level
= 0;
4685 if (!die
->has_children
)
4687 if (die
->next
&& (die
->next
->tag
== 0))
4700 if (die
->has_children
)
4710 while (nesting_level
);
4711 if (die
&& (die
->tag
== 0))
4722 /* Get linkage name of a die, return NULL if not found. */
4725 dwarf2_linkage_name (die
)
4726 struct die_info
*die
;
4728 struct attribute
*attr
;
4730 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4731 if (attr
&& DW_STRING (attr
))
4732 return DW_STRING (attr
);
4733 attr
= dwarf_attr (die
, DW_AT_name
);
4734 if (attr
&& DW_STRING (attr
))
4735 return DW_STRING (attr
);
4739 /* Convert a DIE tag into its string name. */
4742 dwarf_tag_name (tag
)
4743 register unsigned tag
;
4747 case DW_TAG_padding
:
4748 return "DW_TAG_padding";
4749 case DW_TAG_array_type
:
4750 return "DW_TAG_array_type";
4751 case DW_TAG_class_type
:
4752 return "DW_TAG_class_type";
4753 case DW_TAG_entry_point
:
4754 return "DW_TAG_entry_point";
4755 case DW_TAG_enumeration_type
:
4756 return "DW_TAG_enumeration_type";
4757 case DW_TAG_formal_parameter
:
4758 return "DW_TAG_formal_parameter";
4759 case DW_TAG_imported_declaration
:
4760 return "DW_TAG_imported_declaration";
4762 return "DW_TAG_label";
4763 case DW_TAG_lexical_block
:
4764 return "DW_TAG_lexical_block";
4766 return "DW_TAG_member";
4767 case DW_TAG_pointer_type
:
4768 return "DW_TAG_pointer_type";
4769 case DW_TAG_reference_type
:
4770 return "DW_TAG_reference_type";
4771 case DW_TAG_compile_unit
:
4772 return "DW_TAG_compile_unit";
4773 case DW_TAG_string_type
:
4774 return "DW_TAG_string_type";
4775 case DW_TAG_structure_type
:
4776 return "DW_TAG_structure_type";
4777 case DW_TAG_subroutine_type
:
4778 return "DW_TAG_subroutine_type";
4779 case DW_TAG_typedef
:
4780 return "DW_TAG_typedef";
4781 case DW_TAG_union_type
:
4782 return "DW_TAG_union_type";
4783 case DW_TAG_unspecified_parameters
:
4784 return "DW_TAG_unspecified_parameters";
4785 case DW_TAG_variant
:
4786 return "DW_TAG_variant";
4787 case DW_TAG_common_block
:
4788 return "DW_TAG_common_block";
4789 case DW_TAG_common_inclusion
:
4790 return "DW_TAG_common_inclusion";
4791 case DW_TAG_inheritance
:
4792 return "DW_TAG_inheritance";
4793 case DW_TAG_inlined_subroutine
:
4794 return "DW_TAG_inlined_subroutine";
4796 return "DW_TAG_module";
4797 case DW_TAG_ptr_to_member_type
:
4798 return "DW_TAG_ptr_to_member_type";
4799 case DW_TAG_set_type
:
4800 return "DW_TAG_set_type";
4801 case DW_TAG_subrange_type
:
4802 return "DW_TAG_subrange_type";
4803 case DW_TAG_with_stmt
:
4804 return "DW_TAG_with_stmt";
4805 case DW_TAG_access_declaration
:
4806 return "DW_TAG_access_declaration";
4807 case DW_TAG_base_type
:
4808 return "DW_TAG_base_type";
4809 case DW_TAG_catch_block
:
4810 return "DW_TAG_catch_block";
4811 case DW_TAG_const_type
:
4812 return "DW_TAG_const_type";
4813 case DW_TAG_constant
:
4814 return "DW_TAG_constant";
4815 case DW_TAG_enumerator
:
4816 return "DW_TAG_enumerator";
4817 case DW_TAG_file_type
:
4818 return "DW_TAG_file_type";
4820 return "DW_TAG_friend";
4821 case DW_TAG_namelist
:
4822 return "DW_TAG_namelist";
4823 case DW_TAG_namelist_item
:
4824 return "DW_TAG_namelist_item";
4825 case DW_TAG_packed_type
:
4826 return "DW_TAG_packed_type";
4827 case DW_TAG_subprogram
:
4828 return "DW_TAG_subprogram";
4829 case DW_TAG_template_type_param
:
4830 return "DW_TAG_template_type_param";
4831 case DW_TAG_template_value_param
:
4832 return "DW_TAG_template_value_param";
4833 case DW_TAG_thrown_type
:
4834 return "DW_TAG_thrown_type";
4835 case DW_TAG_try_block
:
4836 return "DW_TAG_try_block";
4837 case DW_TAG_variant_part
:
4838 return "DW_TAG_variant_part";
4839 case DW_TAG_variable
:
4840 return "DW_TAG_variable";
4841 case DW_TAG_volatile_type
:
4842 return "DW_TAG_volatile_type";
4843 case DW_TAG_MIPS_loop
:
4844 return "DW_TAG_MIPS_loop";
4845 case DW_TAG_format_label
:
4846 return "DW_TAG_format_label";
4847 case DW_TAG_function_template
:
4848 return "DW_TAG_function_template";
4849 case DW_TAG_class_template
:
4850 return "DW_TAG_class_template";
4852 return "DW_TAG_<unknown>";
4856 /* Convert a DWARF attribute code into its string name. */
4859 dwarf_attr_name (attr
)
4860 register unsigned attr
;
4865 return "DW_AT_sibling";
4866 case DW_AT_location
:
4867 return "DW_AT_location";
4869 return "DW_AT_name";
4870 case DW_AT_ordering
:
4871 return "DW_AT_ordering";
4872 case DW_AT_subscr_data
:
4873 return "DW_AT_subscr_data";
4874 case DW_AT_byte_size
:
4875 return "DW_AT_byte_size";
4876 case DW_AT_bit_offset
:
4877 return "DW_AT_bit_offset";
4878 case DW_AT_bit_size
:
4879 return "DW_AT_bit_size";
4880 case DW_AT_element_list
:
4881 return "DW_AT_element_list";
4882 case DW_AT_stmt_list
:
4883 return "DW_AT_stmt_list";
4885 return "DW_AT_low_pc";
4887 return "DW_AT_high_pc";
4888 case DW_AT_language
:
4889 return "DW_AT_language";
4891 return "DW_AT_member";
4893 return "DW_AT_discr";
4894 case DW_AT_discr_value
:
4895 return "DW_AT_discr_value";
4896 case DW_AT_visibility
:
4897 return "DW_AT_visibility";
4899 return "DW_AT_import";
4900 case DW_AT_string_length
:
4901 return "DW_AT_string_length";
4902 case DW_AT_common_reference
:
4903 return "DW_AT_common_reference";
4904 case DW_AT_comp_dir
:
4905 return "DW_AT_comp_dir";
4906 case DW_AT_const_value
:
4907 return "DW_AT_const_value";
4908 case DW_AT_containing_type
:
4909 return "DW_AT_containing_type";
4910 case DW_AT_default_value
:
4911 return "DW_AT_default_value";
4913 return "DW_AT_inline";
4914 case DW_AT_is_optional
:
4915 return "DW_AT_is_optional";
4916 case DW_AT_lower_bound
:
4917 return "DW_AT_lower_bound";
4918 case DW_AT_producer
:
4919 return "DW_AT_producer";
4920 case DW_AT_prototyped
:
4921 return "DW_AT_prototyped";
4922 case DW_AT_return_addr
:
4923 return "DW_AT_return_addr";
4924 case DW_AT_start_scope
:
4925 return "DW_AT_start_scope";
4926 case DW_AT_stride_size
:
4927 return "DW_AT_stride_size";
4928 case DW_AT_upper_bound
:
4929 return "DW_AT_upper_bound";
4930 case DW_AT_abstract_origin
:
4931 return "DW_AT_abstract_origin";
4932 case DW_AT_accessibility
:
4933 return "DW_AT_accessibility";
4934 case DW_AT_address_class
:
4935 return "DW_AT_address_class";
4936 case DW_AT_artificial
:
4937 return "DW_AT_artificial";
4938 case DW_AT_base_types
:
4939 return "DW_AT_base_types";
4940 case DW_AT_calling_convention
:
4941 return "DW_AT_calling_convention";
4943 return "DW_AT_count";
4944 case DW_AT_data_member_location
:
4945 return "DW_AT_data_member_location";
4946 case DW_AT_decl_column
:
4947 return "DW_AT_decl_column";
4948 case DW_AT_decl_file
:
4949 return "DW_AT_decl_file";
4950 case DW_AT_decl_line
:
4951 return "DW_AT_decl_line";
4952 case DW_AT_declaration
:
4953 return "DW_AT_declaration";
4954 case DW_AT_discr_list
:
4955 return "DW_AT_discr_list";
4956 case DW_AT_encoding
:
4957 return "DW_AT_encoding";
4958 case DW_AT_external
:
4959 return "DW_AT_external";
4960 case DW_AT_frame_base
:
4961 return "DW_AT_frame_base";
4963 return "DW_AT_friend";
4964 case DW_AT_identifier_case
:
4965 return "DW_AT_identifier_case";
4966 case DW_AT_macro_info
:
4967 return "DW_AT_macro_info";
4968 case DW_AT_namelist_items
:
4969 return "DW_AT_namelist_items";
4970 case DW_AT_priority
:
4971 return "DW_AT_priority";
4973 return "DW_AT_segment";
4974 case DW_AT_specification
:
4975 return "DW_AT_specification";
4976 case DW_AT_static_link
:
4977 return "DW_AT_static_link";
4979 return "DW_AT_type";
4980 case DW_AT_use_location
:
4981 return "DW_AT_use_location";
4982 case DW_AT_variable_parameter
:
4983 return "DW_AT_variable_parameter";
4984 case DW_AT_virtuality
:
4985 return "DW_AT_virtuality";
4986 case DW_AT_vtable_elem_location
:
4987 return "DW_AT_vtable_elem_location";
4990 case DW_AT_MIPS_fde
:
4991 return "DW_AT_MIPS_fde";
4992 case DW_AT_MIPS_loop_begin
:
4993 return "DW_AT_MIPS_loop_begin";
4994 case DW_AT_MIPS_tail_loop_begin
:
4995 return "DW_AT_MIPS_tail_loop_begin";
4996 case DW_AT_MIPS_epilog_begin
:
4997 return "DW_AT_MIPS_epilog_begin";
4998 case DW_AT_MIPS_loop_unroll_factor
:
4999 return "DW_AT_MIPS_loop_unroll_factor";
5000 case DW_AT_MIPS_software_pipeline_depth
:
5001 return "DW_AT_MIPS_software_pipeline_depth";
5002 case DW_AT_MIPS_linkage_name
:
5003 return "DW_AT_MIPS_linkage_name";
5006 case DW_AT_sf_names
:
5007 return "DW_AT_sf_names";
5008 case DW_AT_src_info
:
5009 return "DW_AT_src_info";
5010 case DW_AT_mac_info
:
5011 return "DW_AT_mac_info";
5012 case DW_AT_src_coords
:
5013 return "DW_AT_src_coords";
5014 case DW_AT_body_begin
:
5015 return "DW_AT_body_begin";
5016 case DW_AT_body_end
:
5017 return "DW_AT_body_end";
5019 return "DW_AT_<unknown>";
5023 /* Convert a DWARF value form code into its string name. */
5026 dwarf_form_name (form
)
5027 register unsigned form
;
5032 return "DW_FORM_addr";
5033 case DW_FORM_block2
:
5034 return "DW_FORM_block2";
5035 case DW_FORM_block4
:
5036 return "DW_FORM_block4";
5038 return "DW_FORM_data2";
5040 return "DW_FORM_data4";
5042 return "DW_FORM_data8";
5043 case DW_FORM_string
:
5044 return "DW_FORM_string";
5046 return "DW_FORM_block";
5047 case DW_FORM_block1
:
5048 return "DW_FORM_block1";
5050 return "DW_FORM_data1";
5052 return "DW_FORM_flag";
5054 return "DW_FORM_sdata";
5056 return "DW_FORM_strp";
5058 return "DW_FORM_udata";
5059 case DW_FORM_ref_addr
:
5060 return "DW_FORM_ref_addr";
5062 return "DW_FORM_ref1";
5064 return "DW_FORM_ref2";
5066 return "DW_FORM_ref4";
5068 return "DW_FORM_ref8";
5069 case DW_FORM_ref_udata
:
5070 return "DW_FORM_ref_udata";
5071 case DW_FORM_indirect
:
5072 return "DW_FORM_indirect";
5074 return "DW_FORM_<unknown>";
5078 /* Convert a DWARF stack opcode into its string name. */
5081 dwarf_stack_op_name (op
)
5082 register unsigned op
;
5087 return "DW_OP_addr";
5089 return "DW_OP_deref";
5091 return "DW_OP_const1u";
5093 return "DW_OP_const1s";
5095 return "DW_OP_const2u";
5097 return "DW_OP_const2s";
5099 return "DW_OP_const4u";
5101 return "DW_OP_const4s";
5103 return "DW_OP_const8u";
5105 return "DW_OP_const8s";
5107 return "DW_OP_constu";
5109 return "DW_OP_consts";
5113 return "DW_OP_drop";
5115 return "DW_OP_over";
5117 return "DW_OP_pick";
5119 return "DW_OP_swap";
5123 return "DW_OP_xderef";
5131 return "DW_OP_minus";
5143 return "DW_OP_plus";
5144 case DW_OP_plus_uconst
:
5145 return "DW_OP_plus_uconst";
5151 return "DW_OP_shra";
5169 return "DW_OP_skip";
5171 return "DW_OP_lit0";
5173 return "DW_OP_lit1";
5175 return "DW_OP_lit2";
5177 return "DW_OP_lit3";
5179 return "DW_OP_lit4";
5181 return "DW_OP_lit5";
5183 return "DW_OP_lit6";
5185 return "DW_OP_lit7";
5187 return "DW_OP_lit8";
5189 return "DW_OP_lit9";
5191 return "DW_OP_lit10";
5193 return "DW_OP_lit11";
5195 return "DW_OP_lit12";
5197 return "DW_OP_lit13";
5199 return "DW_OP_lit14";
5201 return "DW_OP_lit15";
5203 return "DW_OP_lit16";
5205 return "DW_OP_lit17";
5207 return "DW_OP_lit18";
5209 return "DW_OP_lit19";
5211 return "DW_OP_lit20";
5213 return "DW_OP_lit21";
5215 return "DW_OP_lit22";
5217 return "DW_OP_lit23";
5219 return "DW_OP_lit24";
5221 return "DW_OP_lit25";
5223 return "DW_OP_lit26";
5225 return "DW_OP_lit27";
5227 return "DW_OP_lit28";
5229 return "DW_OP_lit29";
5231 return "DW_OP_lit30";
5233 return "DW_OP_lit31";
5235 return "DW_OP_reg0";
5237 return "DW_OP_reg1";
5239 return "DW_OP_reg2";
5241 return "DW_OP_reg3";
5243 return "DW_OP_reg4";
5245 return "DW_OP_reg5";
5247 return "DW_OP_reg6";
5249 return "DW_OP_reg7";
5251 return "DW_OP_reg8";
5253 return "DW_OP_reg9";
5255 return "DW_OP_reg10";
5257 return "DW_OP_reg11";
5259 return "DW_OP_reg12";
5261 return "DW_OP_reg13";
5263 return "DW_OP_reg14";
5265 return "DW_OP_reg15";
5267 return "DW_OP_reg16";
5269 return "DW_OP_reg17";
5271 return "DW_OP_reg18";
5273 return "DW_OP_reg19";
5275 return "DW_OP_reg20";
5277 return "DW_OP_reg21";
5279 return "DW_OP_reg22";
5281 return "DW_OP_reg23";
5283 return "DW_OP_reg24";
5285 return "DW_OP_reg25";
5287 return "DW_OP_reg26";
5289 return "DW_OP_reg27";
5291 return "DW_OP_reg28";
5293 return "DW_OP_reg29";
5295 return "DW_OP_reg30";
5297 return "DW_OP_reg31";
5299 return "DW_OP_breg0";
5301 return "DW_OP_breg1";
5303 return "DW_OP_breg2";
5305 return "DW_OP_breg3";
5307 return "DW_OP_breg4";
5309 return "DW_OP_breg5";
5311 return "DW_OP_breg6";
5313 return "DW_OP_breg7";
5315 return "DW_OP_breg8";
5317 return "DW_OP_breg9";
5319 return "DW_OP_breg10";
5321 return "DW_OP_breg11";
5323 return "DW_OP_breg12";
5325 return "DW_OP_breg13";
5327 return "DW_OP_breg14";
5329 return "DW_OP_breg15";
5331 return "DW_OP_breg16";
5333 return "DW_OP_breg17";
5335 return "DW_OP_breg18";
5337 return "DW_OP_breg19";
5339 return "DW_OP_breg20";
5341 return "DW_OP_breg21";
5343 return "DW_OP_breg22";
5345 return "DW_OP_breg23";
5347 return "DW_OP_breg24";
5349 return "DW_OP_breg25";
5351 return "DW_OP_breg26";
5353 return "DW_OP_breg27";
5355 return "DW_OP_breg28";
5357 return "DW_OP_breg29";
5359 return "DW_OP_breg30";
5361 return "DW_OP_breg31";
5363 return "DW_OP_regx";
5365 return "DW_OP_fbreg";
5367 return "DW_OP_bregx";
5369 return "DW_OP_piece";
5370 case DW_OP_deref_size
:
5371 return "DW_OP_deref_size";
5372 case DW_OP_xderef_size
:
5373 return "DW_OP_xderef_size";
5377 return "OP_<unknown>";
5382 dwarf_bool_name (mybool
)
5391 /* Convert a DWARF type code into its string name. */
5394 dwarf_type_encoding_name (enc
)
5395 register unsigned enc
;
5399 case DW_ATE_address
:
5400 return "DW_ATE_address";
5401 case DW_ATE_boolean
:
5402 return "DW_ATE_boolean";
5403 case DW_ATE_complex_float
:
5404 return "DW_ATE_complex_float";
5406 return "DW_ATE_float";
5408 return "DW_ATE_signed";
5409 case DW_ATE_signed_char
:
5410 return "DW_ATE_signed_char";
5411 case DW_ATE_unsigned
:
5412 return "DW_ATE_unsigned";
5413 case DW_ATE_unsigned_char
:
5414 return "DW_ATE_unsigned_char";
5416 return "DW_ATE_<unknown>";
5420 /* Convert a DWARF call frame info operation to its string name. */
5424 dwarf_cfi_name (cfi_opc
)
5425 register unsigned cfi_opc
;
5429 case DW_CFA_advance_loc
:
5430 return "DW_CFA_advance_loc";
5432 return "DW_CFA_offset";
5433 case DW_CFA_restore
:
5434 return "DW_CFA_restore";
5436 return "DW_CFA_nop";
5437 case DW_CFA_set_loc
:
5438 return "DW_CFA_set_loc";
5439 case DW_CFA_advance_loc1
:
5440 return "DW_CFA_advance_loc1";
5441 case DW_CFA_advance_loc2
:
5442 return "DW_CFA_advance_loc2";
5443 case DW_CFA_advance_loc4
:
5444 return "DW_CFA_advance_loc4";
5445 case DW_CFA_offset_extended
:
5446 return "DW_CFA_offset_extended";
5447 case DW_CFA_restore_extended
:
5448 return "DW_CFA_restore_extended";
5449 case DW_CFA_undefined
:
5450 return "DW_CFA_undefined";
5451 case DW_CFA_same_value
:
5452 return "DW_CFA_same_value";
5453 case DW_CFA_register
:
5454 return "DW_CFA_register";
5455 case DW_CFA_remember_state
:
5456 return "DW_CFA_remember_state";
5457 case DW_CFA_restore_state
:
5458 return "DW_CFA_restore_state";
5459 case DW_CFA_def_cfa
:
5460 return "DW_CFA_def_cfa";
5461 case DW_CFA_def_cfa_register
:
5462 return "DW_CFA_def_cfa_register";
5463 case DW_CFA_def_cfa_offset
:
5464 return "DW_CFA_def_cfa_offset";
5465 /* SGI/MIPS specific */
5466 case DW_CFA_MIPS_advance_loc8
:
5467 return "DW_CFA_MIPS_advance_loc8";
5469 return "DW_CFA_<unknown>";
5476 struct die_info
*die
;
5480 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5481 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5482 fprintf (stderr
, "\thas children: %s\n",
5483 dwarf_bool_name (die
->has_children
));
5485 fprintf (stderr
, "\tattributes:\n");
5486 for (i
= 0; i
< die
->num_attrs
; ++i
)
5488 fprintf (stderr
, "\t\t%s (%s) ",
5489 dwarf_attr_name (die
->attrs
[i
].name
),
5490 dwarf_form_name (die
->attrs
[i
].form
));
5491 switch (die
->attrs
[i
].form
)
5493 case DW_FORM_ref_addr
:
5495 fprintf (stderr
, "address: ");
5496 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5498 case DW_FORM_block2
:
5499 case DW_FORM_block4
:
5501 case DW_FORM_block1
:
5502 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5512 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5514 case DW_FORM_string
:
5515 fprintf (stderr
, "string: \"%s\"",
5516 DW_STRING (&die
->attrs
[i
])
5517 ? DW_STRING (&die
->attrs
[i
]) : "");
5520 if (DW_UNSND (&die
->attrs
[i
]))
5521 fprintf (stderr
, "flag: TRUE");
5523 fprintf (stderr
, "flag: FALSE");
5525 case DW_FORM_strp
: /* we do not support separate string
5527 case DW_FORM_indirect
: /* we do not handle indirect yet */
5528 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5530 fprintf (stderr
, "unsupported attribute form: %d.",
5531 die
->attrs
[i
].form
);
5533 fprintf (stderr
, "\n");
5539 struct die_info
*die
;
5549 store_in_ref_table (offset
, die
)
5550 unsigned int offset
;
5551 struct die_info
*die
;
5554 struct die_info
*old
;
5556 h
= (offset
% REF_HASH_SIZE
);
5557 old
= die_ref_table
[h
];
5558 die
->next_ref
= old
;
5559 die_ref_table
[h
] = die
;
5564 dwarf2_empty_die_ref_table ()
5566 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5570 dwarf2_get_ref_die_offset (attr
)
5571 struct attribute
*attr
;
5573 unsigned int result
= 0;
5577 case DW_FORM_ref_addr
:
5578 result
= DW_ADDR (attr
);
5583 case DW_FORM_ref_udata
:
5584 result
= cu_header_offset
+ DW_UNSND (attr
);
5587 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5593 follow_die_ref (offset
)
5594 unsigned int offset
;
5596 struct die_info
*die
;
5599 h
= (offset
% REF_HASH_SIZE
);
5600 die
= die_ref_table
[h
];
5603 if (die
->offset
== offset
)
5607 die
= die
->next_ref
;
5612 static struct type
*
5613 dwarf2_fundamental_type (objfile
, typeid)
5614 struct objfile
*objfile
;
5617 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5619 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5623 /* Look for this particular type in the fundamental type vector. If
5624 one is not found, create and install one appropriate for the
5625 current language and the current target machine. */
5627 if (ftypes
[typeid] == NULL
)
5629 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5632 return (ftypes
[typeid]);
5635 /* Decode simple location descriptions.
5636 Given a pointer to a dwarf block that defines a location, compute
5637 the location and return the value.
5639 FIXME: This is a kludge until we figure out a better
5640 way to handle the location descriptions.
5641 Gdb's design does not mesh well with the DWARF2 notion of a location
5642 computing interpreter, which is a shame because the flexibility goes unused.
5643 FIXME: Implement more operations as necessary.
5645 A location description containing no operations indicates that the
5646 object is optimized out. The global optimized_out flag is set for
5647 those, the return value is meaningless.
5649 When the result is a register number, the global isreg flag is set,
5650 otherwise it is cleared.
5652 When the result is a base register offset, the global offreg flag is set
5653 and the register number is returned in basereg, otherwise it is cleared.
5655 When the DW_OP_fbreg operation is encountered without a corresponding
5656 DW_AT_frame_base attribute, the global islocal flag is set.
5657 Hopefully the machine dependent code knows how to set up a virtual
5658 frame pointer for the local references.
5660 Note that stack[0] is unused except as a default error return.
5661 Note that stack overflow is not yet handled. */
5664 decode_locdesc (blk
, objfile
)
5665 struct dwarf_block
*blk
;
5666 struct objfile
*objfile
;
5669 int size
= blk
->size
;
5670 char *data
= blk
->data
;
5671 CORE_ADDR stack
[64];
5673 unsigned int bytes_read
, unsnd
;
5724 stack
[++stacki
] = op
- DW_OP_reg0
;
5729 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5731 #if defined(HARRIS_TARGET) && defined(_M88K)
5732 /* The Harris 88110 gdb ports have long kept their special reg
5733 numbers between their gp-regs and their x-regs. This is
5734 not how our dwarf is generated. Punt. */
5737 stack
[++stacki
] = unsnd
;
5773 basereg
= op
- DW_OP_breg0
;
5774 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5779 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5781 if (frame_base_reg
>= 0)
5784 basereg
= frame_base_reg
;
5785 stack
[stacki
] += frame_base_offset
;
5789 complain (&dwarf2_missing_at_frame_base
);
5795 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5800 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5805 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5810 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5815 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5820 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5825 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5830 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5836 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5841 stack
[stacki
- 1] += stack
[stacki
];
5845 case DW_OP_plus_uconst
:
5846 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5851 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5857 /* If we're not the last op, then we definitely can't encode
5858 this using GDB's address_class enum. */
5860 complain (&dwarf2_complex_location_expr
);
5864 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name(op
));
5865 return (stack
[stacki
]);
5868 return (stack
[stacki
]);
5871 /* memory allocation interface */
5875 dwarf2_free_tmp_obstack (ignore
)
5878 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5881 static struct dwarf_block
*
5882 dwarf_alloc_block ()
5884 struct dwarf_block
*blk
;
5886 blk
= (struct dwarf_block
*)
5887 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5891 static struct abbrev_info
*
5892 dwarf_alloc_abbrev ()
5894 struct abbrev_info
*abbrev
;
5896 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5897 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5901 static struct die_info
*
5904 struct die_info
*die
;
5906 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5907 memset (die
, 0, sizeof (struct die_info
));