1 /* DWARF 2 debugging format support for GDB.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
5 Inc. with support from Florida State University (under contract
6 with the Ada Joint Program Office), and Silicon Graphics, Inc.
7 Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
8 based on Fred Fish's (Cygnus Support) implementation of DWARF 1
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or (at
16 your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. */
35 #include "elf/dwarf2.h"
38 #include "expression.h"
40 #include "complaints.h"
43 #include "gdb_string.h"
44 #include <sys/types.h>
46 /* .debug_info header for a compilation unit
47 Because of alignment constraints, this structure has padding and cannot
48 be mapped directly onto the beginning of the .debug_info section. */
49 typedef struct comp_unit_header
51 unsigned int length
; /* length of the .debug_info
53 unsigned short version
; /* version number -- 2 for DWARF
55 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
56 unsigned char addr_size
; /* byte size of an address -- 4 */
59 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
61 /* .debug_pubnames header
62 Because of alignment constraints, this structure has padding and cannot
63 be mapped directly onto the beginning of the .debug_info section. */
64 typedef struct pubnames_header
66 unsigned int length
; /* length of the .debug_pubnames
68 unsigned char version
; /* version number -- 2 for DWARF
70 unsigned int info_offset
; /* offset into .debug_info section */
71 unsigned int info_size
; /* byte size of .debug_info section
75 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
77 /* .debug_pubnames header
78 Because of alignment constraints, this structure has padding and cannot
79 be mapped directly onto the beginning of the .debug_info section. */
80 typedef struct aranges_header
82 unsigned int length
; /* byte len of the .debug_aranges
84 unsigned short version
; /* version number -- 2 for DWARF
86 unsigned int info_offset
; /* offset into .debug_info section */
87 unsigned char addr_size
; /* byte size of an address */
88 unsigned char seg_size
; /* byte size of segment descriptor */
91 #define _ACTUAL_ARANGES_HEADER_SIZE 12
93 /* .debug_line statement program prologue
94 Because of alignment constraints, this structure has padding and cannot
95 be mapped directly onto the beginning of the .debug_info section. */
96 typedef struct statement_prologue
98 unsigned int total_length
; /* byte length of the statement
100 unsigned short version
; /* version number -- 2 for DWARF
102 unsigned int prologue_length
; /* # bytes between prologue &
104 unsigned char minimum_instruction_length
; /* byte size of
106 unsigned char default_is_stmt
; /* initial value of is_stmt
109 unsigned char line_range
;
110 unsigned char opcode_base
; /* number assigned to first special
112 unsigned char *standard_opcode_lengths
;
116 /* offsets and sizes of debugging sections */
118 static file_ptr dwarf_info_offset
;
119 static file_ptr dwarf_abbrev_offset
;
120 static file_ptr dwarf_line_offset
;
121 static file_ptr dwarf_pubnames_offset
;
122 static file_ptr dwarf_aranges_offset
;
123 static file_ptr dwarf_loc_offset
;
124 static file_ptr dwarf_macinfo_offset
;
125 static file_ptr dwarf_str_offset
;
127 static unsigned int dwarf_info_size
;
128 static unsigned int dwarf_abbrev_size
;
129 static unsigned int dwarf_line_size
;
130 static unsigned int dwarf_pubnames_size
;
131 static unsigned int dwarf_aranges_size
;
132 static unsigned int dwarf_loc_size
;
133 static unsigned int dwarf_macinfo_size
;
134 static unsigned int dwarf_str_size
;
136 /* names of the debugging sections */
138 #define INFO_SECTION ".debug_info"
139 #define ABBREV_SECTION ".debug_abbrev"
140 #define LINE_SECTION ".debug_line"
141 #define PUBNAMES_SECTION ".debug_pubnames"
142 #define ARANGES_SECTION ".debug_aranges"
143 #define LOC_SECTION ".debug_loc"
144 #define MACINFO_SECTION ".debug_macinfo"
145 #define STR_SECTION ".debug_str"
147 /* local data types */
149 /* The data in a compilation unit header looks like this. */
150 struct comp_unit_head
154 unsigned int abbrev_offset
;
155 unsigned char addr_size
;
158 /* The data in the .debug_line statement prologue looks like this. */
161 unsigned int total_length
;
162 unsigned short version
;
163 unsigned int prologue_length
;
164 unsigned char minimum_instruction_length
;
165 unsigned char default_is_stmt
;
167 unsigned char line_range
;
168 unsigned char opcode_base
;
169 unsigned char *standard_opcode_lengths
;
172 /* When we construct a partial symbol table entry we only
173 need this much information. */
174 struct partial_die_info
177 unsigned char has_children
;
178 unsigned char is_external
;
179 unsigned char is_declaration
;
180 unsigned char has_type
;
186 struct dwarf_block
*locdesc
;
187 unsigned int language
;
191 /* This data structure holds the information of an abbrev. */
194 unsigned int number
; /* number identifying abbrev */
195 enum dwarf_tag tag
; /* dwarf tag */
196 int has_children
; /* boolean */
197 unsigned int num_attrs
; /* number of attributes */
198 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
199 struct abbrev_info
*next
; /* next in chain */
204 enum dwarf_attribute name
;
205 enum dwarf_form form
;
208 /* This data structure holds a complete die structure. */
211 enum dwarf_tag tag
; /* Tag indicating type of die */
212 unsigned short has_children
; /* Does the die have children */
213 unsigned int abbrev
; /* Abbrev number */
214 unsigned int offset
; /* Offset in .debug_info section */
215 unsigned int num_attrs
; /* Number of attributes */
216 struct attribute
*attrs
; /* An array of attributes */
217 struct die_info
*next_ref
; /* Next die in ref hash table */
218 struct die_info
*next
; /* Next die in linked list */
219 struct type
*type
; /* Cached type information */
222 /* Attributes have a name and a value */
225 enum dwarf_attribute name
;
226 enum dwarf_form form
;
230 struct dwarf_block
*blk
;
238 /* Get at parts of an attribute structure */
240 #define DW_STRING(attr) ((attr)->u.str)
241 #define DW_UNSND(attr) ((attr)->u.unsnd)
242 #define DW_BLOCK(attr) ((attr)->u.blk)
243 #define DW_SND(attr) ((attr)->u.snd)
244 #define DW_ADDR(attr) ((attr)->u.addr)
246 /* Blocks are a bunch of untyped bytes. */
253 /* We only hold one compilation unit's abbrevs in
254 memory at any one time. */
255 #ifndef ABBREV_HASH_SIZE
256 #define ABBREV_HASH_SIZE 121
258 #ifndef ATTR_ALLOC_CHUNK
259 #define ATTR_ALLOC_CHUNK 4
262 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
264 /* A hash table of die offsets for following references. */
265 #ifndef REF_HASH_SIZE
266 #define REF_HASH_SIZE 1021
269 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
271 /* Obstack for allocating temporary storage used during symbol reading. */
272 static struct obstack dwarf2_tmp_obstack
;
274 /* Offset to the first byte of the current compilation unit header,
275 for resolving relative reference dies. */
276 static unsigned int cu_header_offset
;
278 /* Allocate fields for structs, unions and enums in this size. */
279 #ifndef DW_FIELD_ALLOC_CHUNK
280 #define DW_FIELD_ALLOC_CHUNK 4
283 /* The language we are debugging. */
284 static enum language cu_language
;
285 static const struct language_defn
*cu_language_defn
;
287 /* Actually data from the sections. */
288 static char *dwarf_info_buffer
;
289 static char *dwarf_abbrev_buffer
;
290 static char *dwarf_line_buffer
;
292 /* A zeroed version of a partial die for initialization purposes. */
293 static struct partial_die_info zeroed_partial_die
;
295 /* The generic symbol table building routines have separate lists for
296 file scope symbols and all all other scopes (local scopes). So
297 we need to select the right one to pass to add_symbol_to_list().
298 We do it by keeping a pointer to the correct list in list_in_scope.
300 FIXME: The original dwarf code just treated the file scope as the first
301 local scope, and all other local scopes as nested local scopes, and worked
302 fine. Check to see if we really need to distinguish these
304 static struct pending
**list_in_scope
= &file_symbols
;
306 /* FIXME: decode_locdesc sets these variables to describe the location
307 to the caller. These ought to be a structure or something. If
308 none of the flags are set, the object lives at the address returned
309 by decode_locdesc. */
311 static int optimized_out
; /* No ops in location in expression,
312 so object was optimized out. */
313 static int isreg
; /* Object lives in register.
314 decode_locdesc's return value is
315 the register number. */
316 static int offreg
; /* Object's address is the sum of the
317 register specified by basereg, plus
318 the offset returned. */
319 static int basereg
; /* See `offreg'. */
320 static int isderef
; /* Value described by flags above is
321 the address of a pointer to the object. */
322 static int islocal
; /* Variable is at the returned offset
323 from the frame start, but there's
324 no identified frame pointer for
325 this function, so we can't say
326 which register it's relative to;
329 /* DW_AT_frame_base values for the current function.
330 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
331 contains the register number for the frame register.
332 frame_base_offset is the offset from the frame register to the
333 virtual stack frame. */
334 static int frame_base_reg
;
335 static CORE_ADDR frame_base_offset
;
337 /* This value is added to each symbol value. FIXME: Generalize to
338 the section_offsets structure used by dbxread (once this is done,
339 pass the appropriate section number to end_symtab). */
340 static CORE_ADDR baseaddr
; /* Add to each symbol value */
342 /* We put a pointer to this structure in the read_symtab_private field
344 The complete dwarf information for an objfile is kept in the
345 psymbol_obstack, so that absolute die references can be handled.
346 Most of the information in this structure is related to an entire
347 object file and could be passed via the sym_private field of the objfile.
348 It is however conceivable that dwarf2 might not be the only type
349 of symbols read from an object file. */
353 /* Pointer to start of dwarf info buffer for the objfile. */
355 char *dwarf_info_buffer
;
357 /* Offset in dwarf_info_buffer for this compilation unit. */
359 unsigned long dwarf_info_offset
;
361 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
363 char *dwarf_abbrev_buffer
;
365 /* Size of dwarf abbreviation section for the objfile. */
367 unsigned int dwarf_abbrev_size
;
369 /* Pointer to start of dwarf line buffer for the objfile. */
371 char *dwarf_line_buffer
;
374 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
375 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
376 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
377 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
378 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
379 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
381 /* Maintain an array of referenced fundamental types for the current
382 compilation unit being read. For DWARF version 1, we have to construct
383 the fundamental types on the fly, since no information about the
384 fundamental types is supplied. Each such fundamental type is created by
385 calling a language dependent routine to create the type, and then a
386 pointer to that type is then placed in the array at the index specified
387 by it's FT_<TYPENAME> value. The array has a fixed size set by the
388 FT_NUM_MEMBERS compile time constant, which is the number of predefined
389 fundamental types gdb knows how to construct. */
390 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
392 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
393 but this would require a corresponding change in unpack_field_as_long
395 static int bits_per_byte
= 8;
397 /* The routines that read and process dies for a C struct or C++ class
398 pass lists of data member fields and lists of member function fields
399 in an instance of a field_info structure, as defined below. */
402 /* List of data member and baseclasses fields. */
405 struct nextfield
*next
;
412 /* Number of fields. */
415 /* Number of baseclasses. */
418 /* Set if the accesibility of one of the fields is not public. */
419 int non_public_fields
;
421 /* Member function fields array, entries are allocated in the order they
422 are encountered in the object file. */
425 struct nextfnfield
*next
;
426 struct fn_field fnfield
;
430 /* Member function fieldlist array, contains name of possibly overloaded
431 member function, number of overloaded member functions and a pointer
432 to the head of the member function field chain. */
437 struct nextfnfield
*head
;
441 /* Number of entries in the fnfieldlists array. */
445 /* FIXME: Kludge to mark a varargs function type for C++ member function
446 argument processing. */
447 #define TYPE_FLAG_VARARGS (1 << 10)
449 /* Dwarf2 has no clean way to discern C++ static and non-static member
450 functions. G++ helps GDB by marking the first parameter for non-static
451 member functions (which is the this pointer) as artificial.
452 We pass this information between dwarf2_add_member_fn and
453 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
454 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
456 /* Various complaints about symbol reading that don't abort the process */
458 static struct complaint dwarf2_const_ignored
=
460 "type qualifier 'const' ignored", 0, 0
462 static struct complaint dwarf2_volatile_ignored
=
464 "type qualifier 'volatile' ignored", 0, 0
466 static struct complaint dwarf2_non_const_array_bound_ignored
=
468 "non-constant array bounds form '%s' ignored", 0, 0
470 static struct complaint dwarf2_missing_line_number_section
=
472 "missing .debug_line section", 0, 0
474 static struct complaint dwarf2_mangled_line_number_section
=
476 "mangled .debug_line section", 0, 0
478 static struct complaint dwarf2_unsupported_die_ref_attr
=
480 "unsupported die ref attribute form: '%s'", 0, 0
482 static struct complaint dwarf2_unsupported_stack_op
=
484 "unsupported stack op: '%s'", 0, 0
486 static struct complaint dwarf2_complex_location_expr
=
488 "location expression too complex", 0, 0
490 static struct complaint dwarf2_unsupported_tag
=
492 "unsupported tag: '%s'", 0, 0
494 static struct complaint dwarf2_unsupported_at_encoding
=
496 "unsupported DW_AT_encoding: '%s'", 0, 0
498 static struct complaint dwarf2_unsupported_at_frame_base
=
500 "unsupported DW_AT_frame_base for function '%s'", 0, 0
502 static struct complaint dwarf2_unexpected_tag
=
504 "unexepected tag in read_type_die: '%s'", 0, 0
506 static struct complaint dwarf2_missing_at_frame_base
=
508 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
510 static struct complaint dwarf2_bad_static_member_name
=
512 "unrecognized static data member name '%s'", 0, 0
514 static struct complaint dwarf2_unsupported_accessibility
=
516 "unsupported accessibility %d", 0, 0
518 static struct complaint dwarf2_bad_member_name_complaint
=
520 "cannot extract member name from '%s'", 0, 0
522 static struct complaint dwarf2_missing_member_fn_type_complaint
=
524 "member function type missing for '%s'", 0, 0
526 static struct complaint dwarf2_vtbl_not_found_complaint
=
528 "virtual function table pointer not found when defining class '%s'", 0, 0
530 static struct complaint dwarf2_absolute_sibling_complaint
=
532 "ignoring absolute DW_AT_sibling", 0, 0
534 static struct complaint dwarf2_const_value_length_mismatch
=
536 "const value length mismatch for '%s', got %d, expected %d", 0, 0
538 static struct complaint dwarf2_unsupported_const_value_attr
=
540 "unsupported const value attribute form: '%s'", 0, 0
543 /* Remember the addr_size read from the dwarf.
544 If a target expects to link compilation units with differing address
545 sizes, gdb needs to be sure that the appropriate size is here for
546 whatever scope is currently getting read. */
547 static int address_size
;
549 /* Some elf32 object file formats while linked for a 32 bit address
550 space contain debug information that has assumed 64 bit
551 addresses. Eg 64 bit MIPS target produced by GCC/GAS/LD where the
552 symbol table contains 32bit address values while its .debug_info
553 section contains 64 bit address values.
554 ADDRESS_SIGNIFICANT_SIZE specifies the number significant bits in
555 the ADDRESS_SIZE bytes read from the file */
556 static int address_significant_size
;
558 /* Externals references. */
559 extern int info_verbose
; /* From main.c; nonzero => verbose */
561 /* local function prototypes */
563 static void dwarf2_locate_sections
PARAMS ((bfd
*, asection
*, PTR
));
566 static void dwarf2_build_psymtabs_easy
PARAMS ((struct objfile
*, int));
569 static void dwarf2_build_psymtabs_hard
PARAMS ((struct objfile
*, int));
571 static char *scan_partial_symbols
PARAMS ((char *, struct objfile
*,
572 CORE_ADDR
*, CORE_ADDR
*));
574 static void add_partial_symbol
PARAMS ((struct partial_die_info
*,
577 static void dwarf2_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
579 static void psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*));
581 static char *dwarf2_read_section
PARAMS ((struct objfile
*, file_ptr
,
584 static void dwarf2_read_abbrevs
PARAMS ((bfd
*, unsigned int));
586 static void dwarf2_empty_abbrev_table
PARAMS ((PTR
));
588 static struct abbrev_info
*dwarf2_lookup_abbrev
PARAMS ((unsigned int));
590 static char *read_partial_die
PARAMS ((struct partial_die_info
*,
591 bfd
*, char *, int *));
593 static char *read_full_die
PARAMS ((struct die_info
**, bfd
*, char *));
595 static char *read_attribute
PARAMS ((struct attribute
*, struct attr_abbrev
*,
598 static unsigned int read_1_byte
PARAMS ((bfd
*, char *));
600 static int read_1_signed_byte
PARAMS ((bfd
*, char *));
602 static unsigned int read_2_bytes
PARAMS ((bfd
*, char *));
604 static unsigned int read_4_bytes
PARAMS ((bfd
*, char *));
606 static unsigned int read_8_bytes
PARAMS ((bfd
*, char *));
608 static CORE_ADDR read_address
PARAMS ((bfd
*, char *));
610 static char *read_n_bytes
PARAMS ((bfd
*, char *, unsigned int));
612 static char *read_string
PARAMS ((bfd
*, char *, unsigned int *));
614 static unsigned int read_unsigned_leb128
PARAMS ((bfd
*, char *,
617 static int read_signed_leb128
PARAMS ((bfd
*, char *, unsigned int *));
619 static void set_cu_language
PARAMS ((unsigned int));
621 static struct attribute
*dwarf_attr
PARAMS ((struct die_info
*,
624 static 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
, mainline
)
840 struct objfile
*objfile
;
844 /* We definitely need the .debug_info and .debug_abbrev sections */
846 dwarf_info_buffer
= dwarf2_read_section (objfile
,
849 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
852 dwarf_line_buffer
= dwarf2_read_section (objfile
,
856 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
857 objfile
->static_psymbols
.size
== 0)
859 init_psymbol_list (objfile
, 1024);
863 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
865 /* Things are significantly easier if we have .debug_aranges and
866 .debug_pubnames sections */
868 dwarf2_build_psymtabs_easy (objfile
, mainline
);
872 /* only test this case for now */
874 /* In this case we have to work a bit harder */
875 dwarf2_build_psymtabs_hard (objfile
, mainline
);
880 /* Build the partial symbol table from the information in the
881 .debug_pubnames and .debug_aranges sections. */
884 dwarf2_build_psymtabs_easy (objfile
, mainline
)
885 struct objfile
*objfile
;
888 bfd
*abfd
= objfile
->obfd
;
889 char *aranges_buffer
, *pubnames_buffer
;
890 char *aranges_ptr
, *pubnames_ptr
;
891 unsigned int entry_length
, version
, info_offset
, info_size
;
893 pubnames_buffer
= dwarf2_read_section (objfile
,
894 dwarf_pubnames_offset
,
895 dwarf_pubnames_size
);
896 pubnames_ptr
= pubnames_buffer
;
897 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
899 entry_length
= read_4_bytes (abfd
, pubnames_ptr
);
901 version
= read_1_byte (abfd
, pubnames_ptr
);
903 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
905 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
909 aranges_buffer
= dwarf2_read_section (objfile
,
910 dwarf_aranges_offset
,
916 /* Build the partial symbol table by doing a quick pass through the
917 .debug_info and .debug_abbrev sections. */
920 dwarf2_build_psymtabs_hard (objfile
, mainline
)
921 struct objfile
*objfile
;
924 /* Instead of reading this into a big buffer, we should probably use
925 mmap() on architectures that support it. (FIXME) */
926 bfd
*abfd
= objfile
->obfd
;
927 char *info_ptr
, *abbrev_ptr
;
928 char *beg_of_comp_unit
;
929 struct comp_unit_head cu_header
;
930 struct partial_die_info comp_unit_die
;
931 struct partial_symtab
*pst
;
932 struct cleanup
*back_to
;
933 int comp_unit_has_pc_info
;
934 CORE_ADDR lowpc
, highpc
;
936 /* Number of bytes of any addresses that are signficant */
937 address_significant_size
= get_elf_backend_data (abfd
)->s
->arch_size
/ 8;
939 info_ptr
= dwarf_info_buffer
;
940 abbrev_ptr
= dwarf_abbrev_buffer
;
942 obstack_init (&dwarf2_tmp_obstack
);
943 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
945 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
946 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
948 beg_of_comp_unit
= info_ptr
;
949 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
951 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
953 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
955 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
957 address_size
= cu_header
.addr_size
;
959 if (cu_header
.version
!= 2)
961 error ("Dwarf Error: wrong version in compilation unit header.");
964 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
966 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
967 (long) cu_header
.abbrev_offset
,
968 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
971 if (beg_of_comp_unit
+ cu_header
.length
+ 4
972 > dwarf_info_buffer
+ dwarf_info_size
)
974 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
975 (long) cu_header
.length
,
976 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
979 if (address_size
< address_significant_size
)
981 error ("Dwarf Error: bad address size (%ld) in compilation unit header (offset 0x%lx + 11).",
982 (long) cu_header
.addr_size
,
983 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
986 /* Read the abbrevs for this compilation unit into a table */
987 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
988 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
990 /* Read the compilation unit die */
991 info_ptr
= read_partial_die (&comp_unit_die
, abfd
,
992 info_ptr
, &comp_unit_has_pc_info
);
994 /* Set the language we're debugging */
995 set_cu_language (comp_unit_die
.language
);
997 /* Allocate a new partial symbol table structure */
998 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
999 comp_unit_die
.name
? comp_unit_die
.name
: "",
1000 comp_unit_die
.lowpc
,
1001 objfile
->global_psymbols
.next
,
1002 objfile
->static_psymbols
.next
);
1004 pst
->read_symtab_private
= (char *)
1005 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1006 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1007 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1008 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1009 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1010 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1011 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1012 baseaddr
= ANOFFSET (objfile
->section_offsets
, 0);
1014 /* Store the function that reads in the rest of the symbol table */
1015 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1017 /* Check if comp unit has_children.
1018 If so, read the rest of the partial symbols from this comp unit.
1019 If not, there's no more debug_info for this comp unit. */
1020 if (comp_unit_die
.has_children
)
1022 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
);
1024 /* If the compilation unit didn't have an explicit address range,
1025 then use the information extracted from its child dies. */
1026 if (!comp_unit_has_pc_info
)
1028 comp_unit_die
.lowpc
= lowpc
;
1029 comp_unit_die
.highpc
= highpc
;
1032 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1033 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1035 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1036 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1037 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1038 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1039 sort_pst_symbols (pst
);
1041 /* If there is already a psymtab or symtab for a file of this
1042 name, remove it. (If there is a symtab, more drastic things
1043 also happen.) This happens in VxWorks. */
1044 free_named_symtabs (pst
->filename
);
1046 info_ptr
= beg_of_comp_unit
+ cu_header
.length
+ 4;
1048 do_cleanups (back_to
);
1051 /* Read in all interesting dies to the end of the compilation unit. */
1054 scan_partial_symbols (info_ptr
, objfile
, lowpc
, highpc
)
1056 struct objfile
*objfile
;
1060 bfd
*abfd
= objfile
->obfd
;
1061 struct partial_die_info pdi
;
1063 /* This function is called after we've read in the comp_unit_die in
1064 order to read its children. We start the nesting level at 1 since
1065 we have pushed 1 level down in order to read the comp unit's children.
1066 The comp unit itself is at level 0, so we stop reading when we pop
1067 back to that level. */
1069 int nesting_level
= 1;
1072 *lowpc
= ((CORE_ADDR
) - 1);
1073 *highpc
= ((CORE_ADDR
) 0);
1075 while (nesting_level
)
1077 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
, &has_pc_info
);
1083 case DW_TAG_subprogram
:
1086 if (pdi
.lowpc
< *lowpc
)
1090 if (pdi
.highpc
> *highpc
)
1092 *highpc
= pdi
.highpc
;
1094 if ((pdi
.is_external
|| nesting_level
== 1)
1095 && !pdi
.is_declaration
)
1097 add_partial_symbol (&pdi
, objfile
);
1101 case DW_TAG_variable
:
1102 case DW_TAG_typedef
:
1103 case DW_TAG_class_type
:
1104 case DW_TAG_structure_type
:
1105 case DW_TAG_union_type
:
1106 case DW_TAG_enumeration_type
:
1107 if ((pdi
.is_external
|| nesting_level
== 1)
1108 && !pdi
.is_declaration
)
1110 add_partial_symbol (&pdi
, objfile
);
1113 case DW_TAG_enumerator
:
1114 /* File scope enumerators are added to the partial symbol
1116 if (nesting_level
== 2)
1117 add_partial_symbol (&pdi
, objfile
);
1119 case DW_TAG_base_type
:
1120 /* File scope base type definitions are added to the partial
1122 if (nesting_level
== 1)
1123 add_partial_symbol (&pdi
, objfile
);
1130 /* If the die has a sibling, skip to the sibling.
1131 Do not skip enumeration types, we want to record their
1133 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1135 info_ptr
= pdi
.sibling
;
1137 else if (pdi
.has_children
)
1139 /* Die has children, but the optional DW_AT_sibling attribute
1150 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1151 from `maint check'. */
1152 if (*lowpc
== ((CORE_ADDR
) - 1))
1158 add_partial_symbol (pdi
, objfile
)
1159 struct partial_die_info
*pdi
;
1160 struct objfile
*objfile
;
1166 case DW_TAG_subprogram
:
1167 if (pdi
->is_external
)
1169 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1170 mst_text, objfile); */
1171 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1172 VAR_NAMESPACE
, LOC_BLOCK
,
1173 &objfile
->global_psymbols
,
1174 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1178 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1179 mst_file_text, objfile); */
1180 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1181 VAR_NAMESPACE
, LOC_BLOCK
,
1182 &objfile
->static_psymbols
,
1183 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1186 case DW_TAG_variable
:
1187 if (pdi
->is_external
)
1190 Don't enter into the minimal symbol tables as there is
1191 a minimal symbol table entry from the ELF symbols already.
1192 Enter into partial symbol table if it has a location
1193 descriptor or a type.
1194 If the location descriptor is missing, new_symbol will create
1195 a LOC_UNRESOLVED symbol, the address of the variable will then
1196 be determined from the minimal symbol table whenever the variable
1198 The address for the partial symbol table entry is not
1199 used by GDB, but it comes in handy for debugging partial symbol
1203 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1204 if (pdi
->locdesc
|| pdi
->has_type
)
1205 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1206 VAR_NAMESPACE
, LOC_STATIC
,
1207 &objfile
->global_psymbols
,
1208 0, addr
+ baseaddr
, cu_language
, objfile
);
1212 /* Static Variable. Skip symbols without location descriptors. */
1213 if (pdi
->locdesc
== NULL
)
1215 addr
= decode_locdesc (pdi
->locdesc
, objfile
);
1216 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1217 mst_file_data, objfile); */
1218 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1219 VAR_NAMESPACE
, LOC_STATIC
,
1220 &objfile
->static_psymbols
,
1221 0, addr
+ baseaddr
, cu_language
, objfile
);
1224 case DW_TAG_typedef
:
1225 case DW_TAG_base_type
:
1226 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1227 VAR_NAMESPACE
, LOC_TYPEDEF
,
1228 &objfile
->static_psymbols
,
1229 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1231 case DW_TAG_class_type
:
1232 case DW_TAG_structure_type
:
1233 case DW_TAG_union_type
:
1234 case DW_TAG_enumeration_type
:
1235 /* Skip aggregate types without children, these are external
1237 if (pdi
->has_children
== 0)
1239 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1240 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1241 &objfile
->static_psymbols
,
1242 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1244 if (cu_language
== language_cplus
)
1246 /* For C++, these implicitly act as typedefs as well. */
1247 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1248 VAR_NAMESPACE
, LOC_TYPEDEF
,
1249 &objfile
->static_psymbols
,
1250 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1253 case DW_TAG_enumerator
:
1254 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1255 VAR_NAMESPACE
, LOC_CONST
,
1256 &objfile
->static_psymbols
,
1257 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1264 /* Expand this partial symbol table into a full symbol table. */
1267 dwarf2_psymtab_to_symtab (pst
)
1268 struct partial_symtab
*pst
;
1270 /* FIXME: This is barely more than a stub. */
1275 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1281 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1282 gdb_flush (gdb_stdout
);
1285 psymtab_to_symtab_1 (pst
);
1287 /* Finish up the debug error message. */
1289 printf_filtered ("done.\n");
1295 psymtab_to_symtab_1 (pst
)
1296 struct partial_symtab
*pst
;
1298 struct objfile
*objfile
= pst
->objfile
;
1299 bfd
*abfd
= objfile
->obfd
;
1300 struct comp_unit_head cu_header
;
1301 struct die_info
*dies
;
1302 unsigned long offset
;
1303 CORE_ADDR lowpc
, highpc
;
1304 struct die_info
*child_die
;
1306 struct symtab
*symtab
;
1307 struct cleanup
*back_to
;
1309 /* Set local variables from the partial symbol table info. */
1310 offset
= DWARF_INFO_OFFSET (pst
);
1311 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1312 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1313 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1314 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1315 baseaddr
= ANOFFSET (pst
->section_offsets
, 0);
1316 cu_header_offset
= offset
;
1317 info_ptr
= dwarf_info_buffer
+ offset
;
1319 obstack_init (&dwarf2_tmp_obstack
);
1320 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1323 make_cleanup (really_free_pendings
, NULL
);
1325 /* read in the comp_unit header */
1326 cu_header
.length
= read_4_bytes (abfd
, info_ptr
);
1328 cu_header
.version
= read_2_bytes (abfd
, info_ptr
);
1330 cu_header
.abbrev_offset
= read_4_bytes (abfd
, info_ptr
);
1332 cu_header
.addr_size
= read_1_byte (abfd
, info_ptr
);
1335 /* Read the abbrevs for this compilation unit */
1336 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1337 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1339 dies
= read_comp_unit (info_ptr
, abfd
);
1341 make_cleanup ((make_cleanup_func
) free_die_list
, dies
);
1343 /* Do line number decoding in read_file_scope () */
1344 process_die (dies
, objfile
);
1346 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1348 /* Some compilers don't define a DW_AT_high_pc attribute for
1349 the compilation unit. If the DW_AT_high_pc is missing,
1350 synthesize it, by scanning the DIE's below the compilation unit. */
1352 if (dies
->has_children
)
1354 child_die
= dies
->next
;
1355 while (child_die
&& child_die
->tag
)
1357 if (child_die
->tag
== DW_TAG_subprogram
)
1359 CORE_ADDR low
, high
;
1361 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1363 highpc
= max (highpc
, high
);
1366 child_die
= sibling_die (child_die
);
1370 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, 0);
1372 /* Set symtab language to language from DW_AT_language.
1373 If the compilation is from a C file generated by language preprocessors,
1374 do not set the language if it was already deduced by start_subfile. */
1376 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1378 symtab
->language
= cu_language
;
1380 pst
->symtab
= symtab
;
1382 sort_symtab_syms (pst
->symtab
);
1384 do_cleanups (back_to
);
1387 /* Process a die and its children. */
1390 process_die (die
, objfile
)
1391 struct die_info
*die
;
1392 struct objfile
*objfile
;
1396 case DW_TAG_padding
:
1398 case DW_TAG_compile_unit
:
1399 read_file_scope (die
, objfile
);
1401 case DW_TAG_subprogram
:
1402 read_subroutine_type (die
, objfile
);
1403 read_func_scope (die
, objfile
);
1405 case DW_TAG_inlined_subroutine
:
1406 /* FIXME: These are ignored for now.
1407 They could be used to set breakpoints on all inlined instances
1408 of a function and make GDB `next' properly over inlined functions. */
1410 case DW_TAG_lexical_block
:
1411 read_lexical_block_scope (die
, objfile
);
1413 case DW_TAG_class_type
:
1414 case DW_TAG_structure_type
:
1415 case DW_TAG_union_type
:
1416 read_structure_scope (die
, objfile
);
1418 case DW_TAG_enumeration_type
:
1419 read_enumeration (die
, objfile
);
1421 case DW_TAG_subroutine_type
:
1422 read_subroutine_type (die
, objfile
);
1424 case DW_TAG_array_type
:
1425 read_array_type (die
, objfile
);
1427 case DW_TAG_pointer_type
:
1428 read_tag_pointer_type (die
, objfile
);
1430 case DW_TAG_ptr_to_member_type
:
1431 read_tag_ptr_to_member_type (die
, objfile
);
1433 case DW_TAG_reference_type
:
1434 read_tag_reference_type (die
, objfile
);
1436 case DW_TAG_string_type
:
1437 read_tag_string_type (die
, objfile
);
1439 case DW_TAG_base_type
:
1440 read_base_type (die
, objfile
);
1441 if (dwarf_attr (die
, DW_AT_name
))
1443 /* Add a typedef symbol for the base type definition. */
1444 new_symbol (die
, die
->type
, objfile
);
1447 case DW_TAG_common_block
:
1448 read_common_block (die
, objfile
);
1450 case DW_TAG_common_inclusion
:
1453 new_symbol (die
, NULL
, objfile
);
1459 read_file_scope (die
, objfile
)
1460 struct die_info
*die
;
1461 struct objfile
*objfile
;
1463 unsigned int line_offset
= 0;
1464 CORE_ADDR lowpc
= ((CORE_ADDR
) - 1);
1465 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1466 struct attribute
*attr
;
1467 char *name
= "<unknown>";
1468 char *comp_dir
= NULL
;
1469 struct die_info
*child_die
;
1470 bfd
*abfd
= objfile
->obfd
;
1472 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1474 if (die
->has_children
)
1476 child_die
= die
->next
;
1477 while (child_die
&& child_die
->tag
)
1479 if (child_die
->tag
== DW_TAG_subprogram
)
1481 CORE_ADDR low
, high
;
1483 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1485 lowpc
= min (lowpc
, low
);
1486 highpc
= max (highpc
, high
);
1489 child_die
= sibling_die (child_die
);
1494 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1495 from finish_block. */
1496 if (lowpc
== ((CORE_ADDR
) - 1))
1501 attr
= dwarf_attr (die
, DW_AT_name
);
1504 name
= DW_STRING (attr
);
1506 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1509 comp_dir
= DW_STRING (attr
);
1512 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1513 directory, get rid of it. */
1514 char *cp
= strchr (comp_dir
, ':');
1516 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1521 if (objfile
->ei
.entry_point
>= lowpc
&&
1522 objfile
->ei
.entry_point
< highpc
)
1524 objfile
->ei
.entry_file_lowpc
= lowpc
;
1525 objfile
->ei
.entry_file_highpc
= highpc
;
1528 attr
= dwarf_attr (die
, DW_AT_language
);
1531 set_cu_language (DW_UNSND (attr
));
1534 /* We assume that we're processing GCC output. */
1535 processing_gcc_compilation
= 2;
1537 /* FIXME:Do something here. */
1538 if (dip
->at_producer
!= NULL
)
1540 handle_producer (dip
->at_producer
);
1544 /* The compilation unit may be in a different language or objfile,
1545 zero out all remembered fundamental types. */
1546 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1548 start_symtab (name
, comp_dir
, lowpc
);
1549 record_debugformat ("DWARF 2");
1551 /* Decode line number information if present. */
1552 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1555 line_offset
= DW_UNSND (attr
);
1556 dwarf_decode_lines (line_offset
, comp_dir
, abfd
);
1559 /* Process all dies in compilation unit. */
1560 if (die
->has_children
)
1562 child_die
= die
->next
;
1563 while (child_die
&& child_die
->tag
)
1565 process_die (child_die
, objfile
);
1566 child_die
= sibling_die (child_die
);
1572 read_func_scope (die
, objfile
)
1573 struct die_info
*die
;
1574 struct objfile
*objfile
;
1576 register struct context_stack
*new;
1579 struct die_info
*child_die
;
1580 struct attribute
*attr
;
1583 name
= dwarf2_linkage_name (die
);
1585 /* Ignore functions with missing or empty names and functions with
1586 missing or invalid low and high pc attributes. */
1587 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1593 if (objfile
->ei
.entry_point
>= lowpc
&&
1594 objfile
->ei
.entry_point
< highpc
)
1596 objfile
->ei
.entry_func_lowpc
= lowpc
;
1597 objfile
->ei
.entry_func_highpc
= highpc
;
1600 if (STREQ (name
, "main")) /* FIXME: hardwired name */
1602 objfile
->ei
.main_func_lowpc
= lowpc
;
1603 objfile
->ei
.main_func_highpc
= highpc
;
1606 /* Decode DW_AT_frame_base location descriptor if present, keep result
1607 for DW_OP_fbreg operands in decode_locdesc. */
1608 frame_base_reg
= -1;
1609 frame_base_offset
= 0;
1610 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1613 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
);
1615 complain (&dwarf2_unsupported_at_frame_base
, name
);
1617 frame_base_reg
= addr
;
1620 frame_base_reg
= basereg
;
1621 frame_base_offset
= addr
;
1624 complain (&dwarf2_unsupported_at_frame_base
, name
);
1627 new = push_context (0, lowpc
);
1628 new->name
= new_symbol (die
, die
->type
, objfile
);
1629 list_in_scope
= &local_symbols
;
1631 if (die
->has_children
)
1633 child_die
= die
->next
;
1634 while (child_die
&& child_die
->tag
)
1636 process_die (child_die
, objfile
);
1637 child_die
= sibling_die (child_die
);
1641 new = pop_context ();
1642 /* Make a block for the local symbols within. */
1643 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1644 lowpc
, highpc
, objfile
);
1645 list_in_scope
= &file_symbols
;
1648 /* Process all the DIES contained within a lexical block scope. Start
1649 a new scope, process the dies, and then close the scope. */
1652 read_lexical_block_scope (die
, objfile
)
1653 struct die_info
*die
;
1654 struct objfile
*objfile
;
1656 register struct context_stack
*new;
1657 CORE_ADDR lowpc
, highpc
;
1658 struct die_info
*child_die
;
1660 /* Ignore blocks with missing or invalid low and high pc attributes. */
1661 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1666 push_context (0, lowpc
);
1667 if (die
->has_children
)
1669 child_die
= die
->next
;
1670 while (child_die
&& child_die
->tag
)
1672 process_die (child_die
, objfile
);
1673 child_die
= sibling_die (child_die
);
1676 new = pop_context ();
1678 if (local_symbols
!= NULL
)
1680 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1683 local_symbols
= new->locals
;
1686 /* Get low and high pc attributes from a die.
1687 Return 1 if the attributes are present and valid, otherwise, return 0. */
1690 dwarf2_get_pc_bounds (die
, lowpc
, highpc
, objfile
)
1691 struct die_info
*die
;
1694 struct objfile
*objfile
;
1696 struct attribute
*attr
;
1700 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1702 low
= DW_ADDR (attr
);
1705 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1707 high
= DW_ADDR (attr
);
1714 /* When using the GNU linker, .gnu.linkonce. sections are used to
1715 eliminate duplicate copies of functions and vtables and such.
1716 The linker will arbitrarily choose one and discard the others.
1717 The AT_*_pc values for such functions refer to local labels in
1718 these sections. If the section from that file was discarded, the
1719 labels are not in the output, so the relocs get a value of 0.
1720 If this is a discarded function, mark the pc bounds as invalid,
1721 so that GDB will ignore it. */
1722 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1730 /* Add an aggregate field to the field list. */
1733 dwarf2_add_field (fip
, die
, objfile
)
1734 struct field_info
*fip
;
1735 struct die_info
*die
;
1736 struct objfile
*objfile
;
1738 struct nextfield
*new_field
;
1739 struct attribute
*attr
;
1741 char *fieldname
= "";
1743 /* Allocate a new field list entry and link it in. */
1744 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1745 make_cleanup (free
, new_field
);
1746 memset (new_field
, 0, sizeof (struct nextfield
));
1747 new_field
->next
= fip
->fields
;
1748 fip
->fields
= new_field
;
1751 /* Handle accessibility and virtuality of field.
1752 The default accessibility for members is public, the default
1753 accessibility for inheritance is private. */
1754 if (die
->tag
!= DW_TAG_inheritance
)
1755 new_field
->accessibility
= DW_ACCESS_public
;
1757 new_field
->accessibility
= DW_ACCESS_private
;
1758 new_field
->virtuality
= DW_VIRTUALITY_none
;
1760 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1762 new_field
->accessibility
= DW_UNSND (attr
);
1763 if (new_field
->accessibility
!= DW_ACCESS_public
)
1764 fip
->non_public_fields
= 1;
1765 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1767 new_field
->virtuality
= DW_UNSND (attr
);
1769 fp
= &new_field
->field
;
1770 if (die
->tag
== DW_TAG_member
)
1772 /* Get type of field. */
1773 fp
->type
= die_type (die
, objfile
);
1775 /* Get bit size of field (zero if none). */
1776 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1779 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1783 FIELD_BITSIZE (*fp
) = 0;
1786 /* Get bit offset of field. */
1787 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1790 FIELD_BITPOS (*fp
) =
1791 decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1794 FIELD_BITPOS (*fp
) = 0;
1795 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1798 if (BITS_BIG_ENDIAN
)
1800 /* For big endian bits, the DW_AT_bit_offset gives the
1801 additional bit offset from the MSB of the containing
1802 anonymous object to the MSB of the field. We don't
1803 have to do anything special since we don't need to
1804 know the size of the anonymous object. */
1805 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1809 /* For little endian bits, compute the bit offset to the
1810 MSB of the anonymous object, subtract off the number of
1811 bits from the MSB of the field to the MSB of the
1812 object, and then subtract off the number of bits of
1813 the field itself. The result is the bit offset of
1814 the LSB of the field. */
1816 int bit_offset
= DW_UNSND (attr
);
1818 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1821 /* The size of the anonymous object containing
1822 the bit field is explicit, so use the
1823 indicated size (in bytes). */
1824 anonymous_size
= DW_UNSND (attr
);
1828 /* The size of the anonymous object containing
1829 the bit field must be inferred from the type
1830 attribute of the data member containing the
1832 anonymous_size
= TYPE_LENGTH (fp
->type
);
1834 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1835 - bit_offset
- FIELD_BITSIZE (*fp
);
1839 /* Get name of field. */
1840 attr
= dwarf_attr (die
, DW_AT_name
);
1841 if (attr
&& DW_STRING (attr
))
1842 fieldname
= DW_STRING (attr
);
1843 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1844 &objfile
->type_obstack
);
1846 /* Change accessibility for artificial fields (e.g. virtual table
1847 pointer or virtual base class pointer) to private. */
1848 if (dwarf_attr (die
, DW_AT_artificial
))
1850 new_field
->accessibility
= DW_ACCESS_private
;
1851 fip
->non_public_fields
= 1;
1854 else if (die
->tag
== DW_TAG_variable
)
1859 /* C++ static member.
1860 Get physical name, extract field name from physical name. */
1861 physname
= dwarf2_linkage_name (die
);
1862 if (physname
== NULL
)
1866 while (*cp
&& !is_cplus_marker (*cp
))
1870 if (*fieldname
== '\0')
1872 complain (&dwarf2_bad_static_member_name
, physname
);
1875 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1876 &objfile
->type_obstack
));
1877 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1878 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1879 &objfile
->type_obstack
);
1881 else if (die
->tag
== DW_TAG_inheritance
)
1883 /* C++ base class field. */
1884 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1886 FIELD_BITPOS (*fp
) = decode_locdesc (DW_BLOCK (attr
), objfile
) * bits_per_byte
;
1887 FIELD_BITSIZE (*fp
) = 0;
1888 FIELD_TYPE (*fp
) = die_type (die
, objfile
);
1889 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1890 fip
->nbaseclasses
++;
1894 /* Create the vector of fields, and attach it to the type. */
1897 dwarf2_attach_fields_to_type (fip
, type
, objfile
)
1898 struct field_info
*fip
;
1900 struct objfile
*objfile
;
1902 int nfields
= fip
->nfields
;
1904 /* Record the field count, allocate space for the array of fields,
1905 and create blank accessibility bitfields if necessary. */
1906 TYPE_NFIELDS (type
) = nfields
;
1907 TYPE_FIELDS (type
) = (struct field
*)
1908 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1909 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1911 if (fip
->non_public_fields
)
1913 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1915 TYPE_FIELD_PRIVATE_BITS (type
) =
1916 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1917 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1919 TYPE_FIELD_PROTECTED_BITS (type
) =
1920 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1921 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1923 TYPE_FIELD_IGNORE_BITS (type
) =
1924 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1925 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1928 /* If the type has baseclasses, allocate and clear a bit vector for
1929 TYPE_FIELD_VIRTUAL_BITS. */
1930 if (fip
->nbaseclasses
)
1932 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1935 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1936 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1937 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1938 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1939 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1942 /* Copy the saved-up fields into the field vector. Start from the head
1943 of the list, adding to the tail of the field array, so that they end
1944 up in the same order in the array in which they were added to the list. */
1945 while (nfields
-- > 0)
1947 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1948 switch (fip
->fields
->accessibility
)
1950 case DW_ACCESS_private
:
1951 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1954 case DW_ACCESS_protected
:
1955 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1958 case DW_ACCESS_public
:
1962 /* Unknown accessibility. Complain and treat it as public. */
1964 complain (&dwarf2_unsupported_accessibility
,
1965 fip
->fields
->accessibility
);
1969 if (nfields
< fip
->nbaseclasses
)
1971 switch (fip
->fields
->virtuality
)
1973 case DW_VIRTUALITY_virtual
:
1974 case DW_VIRTUALITY_pure_virtual
:
1975 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1979 fip
->fields
= fip
->fields
->next
;
1983 /* Skip to the end of a member function name in a mangled name. */
1986 skip_member_fn_name (physname
)
1989 char *endname
= physname
;
1991 /* Skip over leading underscores. */
1992 while (*endname
== '_')
1995 /* Find two succesive underscores. */
1997 endname
= strchr (endname
, '_');
1998 while (endname
!= NULL
&& *++endname
!= '_');
2000 if (endname
== NULL
)
2002 complain (&dwarf2_bad_member_name_complaint
, physname
);
2007 /* Take care of trailing underscores. */
2008 if (endname
[1] != '_')
2014 /* Add a member function to the proper fieldlist. */
2017 dwarf2_add_member_fn (fip
, die
, type
, objfile
)
2018 struct field_info
*fip
;
2019 struct die_info
*die
;
2021 struct objfile
*objfile
;
2023 struct attribute
*attr
;
2024 struct fnfieldlist
*flp
;
2026 struct fn_field
*fnp
;
2029 struct nextfnfield
*new_fnfield
;
2031 /* Extract member function name from mangled name. */
2032 physname
= dwarf2_linkage_name (die
);
2033 if (physname
== NULL
)
2035 if ((physname
[0] == '_' && physname
[1] == '_'
2036 && strchr ("0123456789Qt", physname
[2]))
2037 || DESTRUCTOR_PREFIX_P (physname
))
2039 /* Constructor and destructor field names are set to the name
2040 of the class, but without template parameter lists.
2041 The name might be missing for anonymous aggregates. */
2042 if (TYPE_TAG_NAME (type
))
2044 char *p
= strchr (TYPE_TAG_NAME (type
), '<');
2047 fieldname
= TYPE_TAG_NAME (type
);
2049 fieldname
= obsavestring (TYPE_TAG_NAME (type
),
2050 p
- TYPE_TAG_NAME (type
),
2051 &objfile
->type_obstack
);
2055 char *anon_name
= "";
2056 fieldname
= obsavestring (anon_name
, strlen (anon_name
),
2057 &objfile
->type_obstack
);
2062 char *endname
= skip_member_fn_name (physname
);
2064 /* Ignore member function if we were unable not extract the member
2066 if (endname
== physname
)
2068 fieldname
= obsavestring (physname
, endname
- physname
,
2069 &objfile
->type_obstack
);
2072 /* Look up member function name in fieldlist. */
2073 for (i
= 0; i
< fip
->nfnfields
; i
++)
2075 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2079 /* Create new list element if necessary. */
2080 if (i
< fip
->nfnfields
)
2081 flp
= &fip
->fnfieldlists
[i
];
2084 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2086 fip
->fnfieldlists
= (struct fnfieldlist
*)
2087 xrealloc (fip
->fnfieldlists
,
2088 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2089 * sizeof (struct fnfieldlist
));
2090 if (fip
->nfnfields
== 0)
2091 make_cleanup ((make_cleanup_func
) free_current_contents
,
2092 &fip
->fnfieldlists
);
2094 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2095 flp
->name
= fieldname
;
2101 /* Create a new member function field and chain it to the field list
2103 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2104 make_cleanup (free
, new_fnfield
);
2105 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2106 new_fnfield
->next
= flp
->head
;
2107 flp
->head
= new_fnfield
;
2110 /* Fill in the member function field info. */
2111 fnp
= &new_fnfield
->fnfield
;
2112 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2113 &objfile
->type_obstack
);
2114 fnp
->type
= alloc_type (objfile
);
2115 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2117 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2118 struct type
**arg_types
;
2119 int nparams
= TYPE_NFIELDS (die
->type
);
2122 /* Copy argument types from the subroutine type. */
2123 arg_types
= (struct type
**)
2124 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2125 for (iparams
= 0; iparams
< nparams
; iparams
++)
2126 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2128 /* Set last entry in argument type vector. */
2129 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2130 arg_types
[nparams
] = NULL
;
2132 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2134 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2136 /* Handle static member functions.
2137 Dwarf2 has no clean way to discern C++ static and non-static
2138 member functions. G++ helps GDB by marking the first
2139 parameter for non-static member functions (which is the
2140 this pointer) as artificial. We obtain this information
2141 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2142 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2143 fnp
->voffset
= VOFFSET_STATIC
;
2146 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2148 /* Get fcontext from DW_AT_containing_type if present. */
2149 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2150 fnp
->fcontext
= die_containing_type (die
, objfile
);
2152 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2153 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2155 /* Get accessibility. */
2156 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2159 switch (DW_UNSND (attr
))
2161 case DW_ACCESS_private
:
2162 fnp
->is_private
= 1;
2164 case DW_ACCESS_protected
:
2165 fnp
->is_protected
= 1;
2170 /* Get index in virtual function table if it is a virtual member function. */
2171 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2173 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
) + 2;
2176 /* Create the vector of member function fields, and attach it to the type. */
2179 dwarf2_attach_fn_fields_to_type (fip
, type
, objfile
)
2180 struct field_info
*fip
;
2182 struct objfile
*objfile
;
2184 struct fnfieldlist
*flp
;
2185 int total_length
= 0;
2188 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2189 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2190 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2192 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2194 struct nextfnfield
*nfp
= flp
->head
;
2195 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2198 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2199 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2200 fn_flp
->fn_fields
= (struct fn_field
*)
2201 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2202 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2203 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2205 total_length
+= flp
->length
;
2208 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2209 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2212 /* Called when we find the DIE that starts a structure or union scope
2213 (definition) to process all dies that define the members of the
2216 NOTE: we need to call struct_type regardless of whether or not the
2217 DIE has an at_name attribute, since it might be an anonymous
2218 structure or union. This gets the type entered into our set of
2221 However, if the structure is incomplete (an opaque struct/union)
2222 then suppress creating a symbol table entry for it since gdb only
2223 wants to find the one with the complete definition. Note that if
2224 it is complete, we just call new_symbol, which does it's own
2225 checking about whether the struct/union is anonymous or not (and
2226 suppresses creating a symbol table entry itself). */
2229 read_structure_scope (die
, objfile
)
2230 struct die_info
*die
;
2231 struct objfile
*objfile
;
2234 struct attribute
*attr
;
2236 type
= alloc_type (objfile
);
2238 INIT_CPLUS_SPECIFIC (type
);
2239 attr
= dwarf_attr (die
, DW_AT_name
);
2240 if (attr
&& DW_STRING (attr
))
2242 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2243 strlen (DW_STRING (attr
)),
2244 &objfile
->type_obstack
);
2247 if (die
->tag
== DW_TAG_structure_type
)
2249 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2251 else if (die
->tag
== DW_TAG_union_type
)
2253 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2257 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2259 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2262 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2265 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2269 TYPE_LENGTH (type
) = 0;
2272 /* We need to add the type field to the die immediately so we don't
2273 infinitely recurse when dealing with pointers to the structure
2274 type within the structure itself. */
2277 if (die
->has_children
)
2279 struct field_info fi
;
2280 struct die_info
*child_die
;
2281 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2283 memset (&fi
, 0, sizeof (struct field_info
));
2285 child_die
= die
->next
;
2287 while (child_die
&& child_die
->tag
)
2289 if (child_die
->tag
== DW_TAG_member
)
2291 dwarf2_add_field (&fi
, child_die
, objfile
);
2293 else if (child_die
->tag
== DW_TAG_variable
)
2295 /* C++ static member. */
2296 dwarf2_add_field (&fi
, child_die
, objfile
);
2298 else if (child_die
->tag
== DW_TAG_subprogram
)
2300 /* C++ member function. */
2301 process_die (child_die
, objfile
);
2302 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
);
2304 else if (child_die
->tag
== DW_TAG_inheritance
)
2306 /* C++ base class field. */
2307 dwarf2_add_field (&fi
, child_die
, objfile
);
2311 process_die (child_die
, objfile
);
2313 child_die
= sibling_die (child_die
);
2316 /* Attach fields and member functions to the type. */
2318 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2321 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2323 /* Get the type which refers to the base class (possibly this
2324 class itself) which contains the vtable pointer for the current
2325 class from the DW_AT_containing_type attribute. */
2327 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2329 struct type
*t
= die_containing_type (die
, objfile
);
2331 TYPE_VPTR_BASETYPE (type
) = t
;
2334 static const char vptr_name
[] =
2335 {'_', 'v', 'p', 't', 'r', '\0'};
2338 /* Our own class provides vtbl ptr. */
2339 for (i
= TYPE_NFIELDS (t
) - 1;
2340 i
>= TYPE_N_BASECLASSES (t
);
2343 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2345 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2346 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2348 TYPE_VPTR_FIELDNO (type
) = i
;
2353 /* Complain if virtual function table field not found. */
2354 if (i
< TYPE_N_BASECLASSES (t
))
2355 complain (&dwarf2_vtbl_not_found_complaint
,
2356 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2360 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2365 new_symbol (die
, type
, objfile
);
2367 do_cleanups (back_to
);
2371 /* No children, must be stub. */
2372 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2378 /* Given a pointer to a die which begins an enumeration, process all
2379 the dies that define the members of the enumeration.
2381 This will be much nicer in draft 6 of the DWARF spec when our
2382 members will be dies instead squished into the DW_AT_element_list
2385 NOTE: We reverse the order of the element list. */
2388 read_enumeration (die
, objfile
)
2389 struct die_info
*die
;
2390 struct objfile
*objfile
;
2392 struct die_info
*child_die
;
2394 struct field
*fields
;
2395 struct attribute
*attr
;
2398 int unsigned_enum
= 1;
2400 type
= alloc_type (objfile
);
2402 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2403 attr
= dwarf_attr (die
, DW_AT_name
);
2404 if (attr
&& DW_STRING (attr
))
2406 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2407 strlen (DW_STRING (attr
)),
2408 &objfile
->type_obstack
);
2411 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2414 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2418 TYPE_LENGTH (type
) = 0;
2423 if (die
->has_children
)
2425 child_die
= die
->next
;
2426 while (child_die
&& child_die
->tag
)
2428 if (child_die
->tag
!= DW_TAG_enumerator
)
2430 process_die (child_die
, objfile
);
2434 attr
= dwarf_attr (child_die
, DW_AT_name
);
2437 sym
= new_symbol (child_die
, type
, objfile
);
2438 if (SYMBOL_VALUE (sym
) < 0)
2441 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2443 fields
= (struct field
*)
2445 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2446 * sizeof (struct field
));
2449 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2450 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2451 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2452 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2458 child_die
= sibling_die (child_die
);
2463 TYPE_NFIELDS (type
) = num_fields
;
2464 TYPE_FIELDS (type
) = (struct field
*)
2465 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2466 memcpy (TYPE_FIELDS (type
), fields
,
2467 sizeof (struct field
) * num_fields
);
2471 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2474 new_symbol (die
, type
, objfile
);
2477 /* Extract all information from a DW_TAG_array_type DIE and put it in
2478 the DIE's type field. For now, this only handles one dimensional
2482 read_array_type (die
, objfile
)
2483 struct die_info
*die
;
2484 struct objfile
*objfile
;
2486 struct die_info
*child_die
;
2487 struct type
*type
= NULL
;
2488 struct type
*element_type
, *range_type
, *index_type
;
2489 struct type
**range_types
= NULL
;
2490 struct attribute
*attr
;
2492 struct cleanup
*back_to
;
2494 /* Return if we've already decoded this type. */
2500 element_type
= die_type (die
, objfile
);
2502 /* Irix 6.2 native cc creates array types without children for
2503 arrays with unspecified length. */
2504 if (die
->has_children
== 0)
2506 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2507 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2508 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2512 back_to
= make_cleanup (null_cleanup
, NULL
);
2513 child_die
= die
->next
;
2514 while (child_die
&& child_die
->tag
)
2516 if (child_die
->tag
== DW_TAG_subrange_type
)
2518 unsigned int low
, high
;
2520 /* Default bounds to an array with unspecified length. */
2523 if (cu_language
== language_fortran
)
2525 /* FORTRAN implies a lower bound of 1, if not given. */
2529 index_type
= die_type (child_die
, objfile
);
2530 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2533 if (attr
->form
== DW_FORM_sdata
)
2535 low
= DW_SND (attr
);
2537 else if (attr
->form
== DW_FORM_udata
2538 || attr
->form
== DW_FORM_data1
2539 || attr
->form
== DW_FORM_data2
2540 || attr
->form
== DW_FORM_data4
)
2542 low
= DW_UNSND (attr
);
2546 complain (&dwarf2_non_const_array_bound_ignored
,
2547 dwarf_form_name (attr
->form
));
2549 die
->type
= lookup_pointer_type (element_type
);
2556 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2559 if (attr
->form
== DW_FORM_sdata
)
2561 high
= DW_SND (attr
);
2563 else if (attr
->form
== DW_FORM_udata
2564 || attr
->form
== DW_FORM_data1
2565 || attr
->form
== DW_FORM_data2
2566 || attr
->form
== DW_FORM_data4
)
2568 high
= DW_UNSND (attr
);
2570 else if (attr
->form
== DW_FORM_block1
)
2572 /* GCC encodes arrays with unspecified or dynamic length
2573 with a DW_FORM_block1 attribute.
2574 FIXME: GDB does not yet know how to handle dynamic
2575 arrays properly, treat them as arrays with unspecified
2581 complain (&dwarf2_non_const_array_bound_ignored
,
2582 dwarf_form_name (attr
->form
));
2584 die
->type
= lookup_pointer_type (element_type
);
2592 /* Create a range type and save it for array type creation. */
2593 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2595 range_types
= (struct type
**)
2596 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2597 * sizeof (struct type
*));
2599 make_cleanup ((make_cleanup_func
) free_current_contents
,
2602 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2604 child_die
= sibling_die (child_die
);
2607 /* Dwarf2 dimensions are output from left to right, create the
2608 necessary array types in backwards order. */
2609 type
= element_type
;
2611 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2613 do_cleanups (back_to
);
2615 /* Install the type in the die. */
2619 /* First cut: install each common block member as a global variable. */
2622 read_common_block (die
, objfile
)
2623 struct die_info
*die
;
2624 struct objfile
*objfile
;
2626 struct die_info
*child_die
;
2627 struct attribute
*attr
;
2629 CORE_ADDR base
= (CORE_ADDR
) 0;
2631 attr
= dwarf_attr (die
, DW_AT_location
);
2634 base
= decode_locdesc (DW_BLOCK (attr
), objfile
);
2636 if (die
->has_children
)
2638 child_die
= die
->next
;
2639 while (child_die
&& child_die
->tag
)
2641 sym
= new_symbol (child_die
, NULL
, objfile
);
2642 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2645 SYMBOL_VALUE_ADDRESS (sym
) =
2646 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
);
2647 add_symbol_to_list (sym
, &global_symbols
);
2649 child_die
= sibling_die (child_die
);
2654 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2655 the user defined type vector. */
2658 read_tag_pointer_type (die
, objfile
)
2659 struct die_info
*die
;
2660 struct objfile
*objfile
;
2663 struct attribute
*attr
;
2670 type
= lookup_pointer_type (die_type (die
, objfile
));
2671 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2674 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2678 TYPE_LENGTH (type
) = address_size
;
2683 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2684 the user defined type vector. */
2687 read_tag_ptr_to_member_type (die
, objfile
)
2688 struct die_info
*die
;
2689 struct objfile
*objfile
;
2692 struct type
*to_type
;
2693 struct type
*domain
;
2700 type
= alloc_type (objfile
);
2701 to_type
= die_type (die
, objfile
);
2702 domain
= die_containing_type (die
, objfile
);
2703 smash_to_member_type (type
, domain
, to_type
);
2708 /* Extract all information from a DW_TAG_reference_type DIE and add to
2709 the user defined type vector. */
2712 read_tag_reference_type (die
, objfile
)
2713 struct die_info
*die
;
2714 struct objfile
*objfile
;
2717 struct attribute
*attr
;
2724 type
= lookup_reference_type (die_type (die
, objfile
));
2725 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2728 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2732 TYPE_LENGTH (type
) = address_size
;
2738 read_tag_const_type (die
, objfile
)
2739 struct die_info
*die
;
2740 struct objfile
*objfile
;
2747 complain (&dwarf2_const_ignored
);
2748 die
->type
= die_type (die
, objfile
);
2752 read_tag_volatile_type (die
, objfile
)
2753 struct die_info
*die
;
2754 struct objfile
*objfile
;
2761 complain (&dwarf2_volatile_ignored
);
2762 die
->type
= die_type (die
, objfile
);
2765 /* Extract all information from a DW_TAG_string_type DIE and add to
2766 the user defined type vector. It isn't really a user defined type,
2767 but it behaves like one, with other DIE's using an AT_user_def_type
2768 attribute to reference it. */
2771 read_tag_string_type (die
, objfile
)
2772 struct die_info
*die
;
2773 struct objfile
*objfile
;
2775 struct type
*type
, *range_type
, *index_type
, *char_type
;
2776 struct attribute
*attr
;
2777 unsigned int length
;
2784 attr
= dwarf_attr (die
, DW_AT_string_length
);
2787 length
= DW_UNSND (attr
);
2793 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2794 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2795 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2796 type
= create_string_type (char_type
, range_type
);
2800 /* Handle DIES due to C code like:
2804 int (*funcp)(int a, long l);
2808 ('funcp' generates a DW_TAG_subroutine_type DIE)
2812 read_subroutine_type (die
, objfile
)
2813 struct die_info
*die
;
2814 struct objfile
*objfile
;
2816 struct type
*type
; /* Type that this function returns */
2817 struct type
*ftype
; /* Function that returns above type */
2818 struct attribute
*attr
;
2820 /* Decode the type that this subroutine returns */
2825 type
= die_type (die
, objfile
);
2826 ftype
= lookup_function_type (type
);
2828 /* All functions in C++ have prototypes. */
2829 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2830 if ((attr
&& (DW_UNSND (attr
) != 0))
2831 || cu_language
== language_cplus
)
2832 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2834 if (die
->has_children
)
2836 struct die_info
*child_die
;
2840 /* Count the number of parameters.
2841 FIXME: GDB currently ignores vararg functions, but knows about
2842 vararg member functions. */
2843 child_die
= die
->next
;
2844 while (child_die
&& child_die
->tag
)
2846 if (child_die
->tag
== DW_TAG_formal_parameter
)
2848 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2849 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2850 child_die
= sibling_die (child_die
);
2853 /* Allocate storage for parameters and fill them in. */
2854 TYPE_NFIELDS (ftype
) = nparams
;
2855 TYPE_FIELDS (ftype
) = (struct field
*)
2856 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2858 child_die
= die
->next
;
2859 while (child_die
&& child_die
->tag
)
2861 if (child_die
->tag
== DW_TAG_formal_parameter
)
2863 /* Dwarf2 has no clean way to discern C++ static and non-static
2864 member functions. G++ helps GDB by marking the first
2865 parameter for non-static member functions (which is the
2866 this pointer) as artificial. We pass this information
2867 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2868 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2870 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2872 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2873 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
);
2876 child_die
= sibling_die (child_die
);
2884 read_typedef (die
, objfile
)
2885 struct die_info
*die
;
2886 struct objfile
*objfile
;
2892 struct attribute
*attr
;
2895 xtype
= die_type (die
, objfile
);
2897 type
= alloc_type (objfile
);
2898 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2899 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2900 TYPE_TARGET_TYPE (type
) = xtype
;
2901 attr
= dwarf_attr (die
, DW_AT_name
);
2902 if (attr
&& DW_STRING (attr
))
2903 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2904 strlen (DW_STRING (attr
)),
2905 &objfile
->type_obstack
);
2911 /* Find a representation of a given base type and install
2912 it in the TYPE field of the die. */
2915 read_base_type (die
, objfile
)
2916 struct die_info
*die
;
2917 struct objfile
*objfile
;
2920 struct attribute
*attr
;
2921 int encoding
= 0, size
= 0;
2923 /* If we've already decoded this die, this is a no-op. */
2929 attr
= dwarf_attr (die
, DW_AT_encoding
);
2932 encoding
= DW_UNSND (attr
);
2934 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2937 size
= DW_UNSND (attr
);
2939 attr
= dwarf_attr (die
, DW_AT_name
);
2940 if (attr
&& DW_STRING (attr
))
2942 enum type_code code
= TYPE_CODE_INT
;
2943 int is_unsigned
= 0;
2947 case DW_ATE_address
:
2948 /* Turn DW_ATE_address into a void * pointer. */
2949 code
= TYPE_CODE_PTR
;
2952 case DW_ATE_boolean
:
2953 code
= TYPE_CODE_BOOL
;
2956 case DW_ATE_complex_float
:
2957 code
= TYPE_CODE_COMPLEX
;
2960 code
= TYPE_CODE_FLT
;
2963 case DW_ATE_signed_char
:
2965 case DW_ATE_unsigned
:
2966 case DW_ATE_unsigned_char
:
2970 complain (&dwarf2_unsupported_at_encoding
,
2971 dwarf_type_encoding_name (encoding
));
2974 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2975 if (encoding
== DW_ATE_address
)
2976 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2980 type
= dwarf_base_type (encoding
, size
, objfile
);
2985 /* Read a whole compilation unit into a linked list of dies. */
2988 read_comp_unit (info_ptr
, abfd
)
2992 struct die_info
*first_die
, *last_die
, *die
;
2996 /* Reset die reference table, we are building a new one now. */
2997 dwarf2_empty_die_ref_table ();
3001 first_die
= last_die
= NULL
;
3004 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
);
3005 if (die
->has_children
)
3016 /* Enter die in reference hash table */
3017 store_in_ref_table (die
->offset
, die
);
3021 first_die
= last_die
= die
;
3025 last_die
->next
= die
;
3029 while (nesting_level
> 0);
3033 /* Free a linked list of dies. */
3036 free_die_list (dies
)
3037 struct die_info
*dies
;
3039 struct die_info
*die
, *next
;
3051 /* Read the contents of the section at OFFSET and of size SIZE from the
3052 object file specified by OBJFILE into the psymbol_obstack and return it. */
3055 dwarf2_read_section (objfile
, offset
, size
)
3056 struct objfile
*objfile
;
3060 bfd
*abfd
= objfile
->obfd
;
3066 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
3067 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
3068 (bfd_read (buf
, size
, 1, abfd
) != size
))
3071 error ("Dwarf Error: Can't read DWARF data from '%s'",
3072 bfd_get_filename (abfd
));
3077 /* In DWARF version 2, the description of the debugging information is
3078 stored in a separate .debug_abbrev section. Before we read any
3079 dies from a section we read in all abbreviations and install them
3083 dwarf2_read_abbrevs (abfd
, offset
)
3085 unsigned int offset
;
3088 struct abbrev_info
*cur_abbrev
;
3089 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3090 unsigned int abbrev_form
, hash_number
;
3092 /* empty the table */
3093 dwarf2_empty_abbrev_table (NULL
);
3095 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3096 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3097 abbrev_ptr
+= bytes_read
;
3099 /* loop until we reach an abbrev number of 0 */
3100 while (abbrev_number
)
3102 cur_abbrev
= dwarf_alloc_abbrev ();
3104 /* read in abbrev header */
3105 cur_abbrev
->number
= abbrev_number
;
3106 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3107 abbrev_ptr
+= bytes_read
;
3108 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3111 /* now read in declarations */
3112 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3113 abbrev_ptr
+= bytes_read
;
3114 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3115 abbrev_ptr
+= bytes_read
;
3118 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3120 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3121 xrealloc (cur_abbrev
->attrs
,
3122 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3123 * sizeof (struct attr_abbrev
));
3125 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3126 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3127 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3128 abbrev_ptr
+= bytes_read
;
3129 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3130 abbrev_ptr
+= bytes_read
;
3133 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3134 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3135 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3137 /* Get next abbreviation.
3138 Under Irix6 the abbreviations for a compilation unit are not
3139 always properly terminated with an abbrev number of 0.
3140 Exit loop if we encounter an abbreviation which we have
3141 already read (which means we are about to read the abbreviations
3142 for the next compile unit) or if the end of the abbreviation
3143 table is reached. */
3144 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3145 >= dwarf_abbrev_size
)
3147 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3148 abbrev_ptr
+= bytes_read
;
3149 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3154 /* Empty the abbrev table for a new compilation unit. */
3158 dwarf2_empty_abbrev_table (ignore
)
3162 struct abbrev_info
*abbrev
, *next
;
3164 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3167 abbrev
= dwarf2_abbrevs
[i
];
3170 next
= abbrev
->next
;
3171 free (abbrev
->attrs
);
3175 dwarf2_abbrevs
[i
] = NULL
;
3179 /* Lookup an abbrev_info structure in the abbrev hash table. */
3181 static struct abbrev_info
*
3182 dwarf2_lookup_abbrev (number
)
3183 unsigned int number
;
3185 unsigned int hash_number
;
3186 struct abbrev_info
*abbrev
;
3188 hash_number
= number
% ABBREV_HASH_SIZE
;
3189 abbrev
= dwarf2_abbrevs
[hash_number
];
3193 if (abbrev
->number
== number
)
3196 abbrev
= abbrev
->next
;
3201 /* Read a minimal amount of information into the minimal die structure. */
3204 read_partial_die (part_die
, abfd
, info_ptr
, has_pc_info
)
3205 struct partial_die_info
*part_die
;
3210 unsigned int abbrev_number
, bytes_read
, i
;
3211 struct abbrev_info
*abbrev
;
3212 struct attribute attr
;
3213 struct attribute spec_attr
;
3214 int found_spec_attr
= 0;
3215 int has_low_pc_attr
= 0;
3216 int has_high_pc_attr
= 0;
3218 *part_die
= zeroed_partial_die
;
3220 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3221 info_ptr
+= bytes_read
;
3225 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3228 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3230 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3231 part_die
->tag
= abbrev
->tag
;
3232 part_die
->has_children
= abbrev
->has_children
;
3233 part_die
->abbrev
= abbrev_number
;
3235 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3237 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
, info_ptr
);
3239 /* Store the data if it is of an attribute we want to keep in a
3240 partial symbol table. */
3245 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3246 if (part_die
->name
== NULL
)
3247 part_die
->name
= DW_STRING (&attr
);
3249 case DW_AT_MIPS_linkage_name
:
3250 part_die
->name
= DW_STRING (&attr
);
3253 has_low_pc_attr
= 1;
3254 part_die
->lowpc
= DW_ADDR (&attr
);
3257 has_high_pc_attr
= 1;
3258 part_die
->highpc
= DW_ADDR (&attr
);
3260 case DW_AT_location
:
3261 part_die
->locdesc
= DW_BLOCK (&attr
);
3263 case DW_AT_language
:
3264 part_die
->language
= DW_UNSND (&attr
);
3266 case DW_AT_external
:
3267 part_die
->is_external
= DW_UNSND (&attr
);
3269 case DW_AT_declaration
:
3270 part_die
->is_declaration
= DW_UNSND (&attr
);
3273 part_die
->has_type
= 1;
3275 case DW_AT_abstract_origin
:
3276 case DW_AT_specification
:
3277 found_spec_attr
= 1;
3281 /* Ignore absolute siblings, they might point outside of
3282 the current compile unit. */
3283 if (attr
.form
== DW_FORM_ref_addr
)
3284 complain (&dwarf2_absolute_sibling_complaint
);
3287 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3294 /* If we found a reference attribute and the die has no name, try
3295 to find a name in the referred to die. */
3297 if (found_spec_attr
&& part_die
->name
== NULL
)
3299 struct partial_die_info spec_die
;
3303 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3304 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
);
3307 part_die
->name
= spec_die
.name
;
3309 /* Copy DW_AT_external attribute if it is set. */
3310 if (spec_die
.is_external
)
3311 part_die
->is_external
= spec_die
.is_external
;
3315 /* When using the GNU linker, .gnu.linkonce. sections are used to
3316 eliminate duplicate copies of functions and vtables and such.
3317 The linker will arbitrarily choose one and discard the others.
3318 The AT_*_pc values for such functions refer to local labels in
3319 these sections. If the section from that file was discarded, the
3320 labels are not in the output, so the relocs get a value of 0.
3321 If this is a discarded function, mark the pc bounds as invalid,
3322 so that GDB will ignore it. */
3323 if (has_low_pc_attr
&& has_high_pc_attr
3324 && part_die
->lowpc
< part_die
->highpc
3325 && (part_die
->lowpc
!= 0
3326 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3331 /* Read the die from the .debug_info section buffer. And set diep to
3332 point to a newly allocated die with its information. */
3335 read_full_die (diep
, abfd
, info_ptr
)
3336 struct die_info
**diep
;
3340 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3341 struct abbrev_info
*abbrev
;
3342 struct die_info
*die
;
3344 offset
= info_ptr
- dwarf_info_buffer
;
3345 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3346 info_ptr
+= bytes_read
;
3349 die
= dwarf_alloc_die ();
3351 die
->abbrev
= abbrev_number
;
3357 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3360 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3362 die
= dwarf_alloc_die ();
3363 die
->offset
= offset
;
3364 die
->tag
= abbrev
->tag
;
3365 die
->has_children
= abbrev
->has_children
;
3366 die
->abbrev
= abbrev_number
;
3369 die
->num_attrs
= abbrev
->num_attrs
;
3370 die
->attrs
= (struct attribute
*)
3371 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3373 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3375 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3383 /* Read an attribute described by an abbreviated attribute. */
3386 read_attribute (attr
, abbrev
, abfd
, info_ptr
)
3387 struct attribute
*attr
;
3388 struct attr_abbrev
*abbrev
;
3392 unsigned int bytes_read
;
3393 struct dwarf_block
*blk
;
3395 attr
->name
= abbrev
->name
;
3396 attr
->form
= abbrev
->form
;
3397 switch (abbrev
->form
)
3400 case DW_FORM_ref_addr
:
3401 DW_ADDR (attr
) = read_address (abfd
, info_ptr
);
3402 info_ptr
+= address_size
;
3404 case DW_FORM_block2
:
3405 blk
= dwarf_alloc_block ();
3406 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3408 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3409 info_ptr
+= blk
->size
;
3410 DW_BLOCK (attr
) = blk
;
3412 case DW_FORM_block4
:
3413 blk
= dwarf_alloc_block ();
3414 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3416 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3417 info_ptr
+= blk
->size
;
3418 DW_BLOCK (attr
) = blk
;
3421 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3425 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3429 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3432 case DW_FORM_string
:
3433 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3434 info_ptr
+= bytes_read
;
3437 blk
= dwarf_alloc_block ();
3438 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3439 info_ptr
+= bytes_read
;
3440 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3441 info_ptr
+= blk
->size
;
3442 DW_BLOCK (attr
) = blk
;
3444 case DW_FORM_block1
:
3445 blk
= dwarf_alloc_block ();
3446 blk
->size
= read_1_byte (abfd
, info_ptr
);
3448 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3449 info_ptr
+= blk
->size
;
3450 DW_BLOCK (attr
) = blk
;
3453 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3457 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3461 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3462 info_ptr
+= bytes_read
;
3465 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3466 info_ptr
+= bytes_read
;
3469 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3473 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3477 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3480 case DW_FORM_ref_udata
:
3481 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3482 info_ptr
+= bytes_read
;
3485 case DW_FORM_indirect
:
3487 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3488 dwarf_form_name (abbrev
->form
));
3493 /* read dwarf information from a buffer */
3496 read_1_byte (abfd
, buf
)
3500 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3504 read_1_signed_byte (abfd
, buf
)
3508 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3512 read_2_bytes (abfd
, buf
)
3516 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3520 read_2_signed_bytes (abfd
, buf
)
3524 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3528 read_4_bytes (abfd
, buf
)
3532 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3536 read_4_signed_bytes (abfd
, buf
)
3540 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3544 read_8_bytes (abfd
, buf
)
3548 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3552 read_address (abfd
, buf
)
3556 CORE_ADDR retval
= 0;
3558 switch (address_size
)
3561 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3564 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3567 /* *THE* alternative is 8, right? */
3570 /* If the address being read is larger than the address that is
3571 applicable for the object file format then mask it down to the
3572 correct size. Take care to avoid unnecessary shift or shift
3574 if (address_size
> address_significant_size
3575 && address_significant_size
< sizeof (CORE_ADDR
))
3577 CORE_ADDR mask
= ((CORE_ADDR
) 0) - 1;
3578 retval
&= ~(mask
<< (address_significant_size
* 8));
3584 read_n_bytes (abfd
, buf
, size
)
3589 /* If the size of a host char is 8 bits, we can return a pointer
3590 to the buffer, otherwise we have to copy the data to a buffer
3591 allocated on the temporary obstack. */
3592 #if HOST_CHAR_BIT == 8
3598 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3599 for (i
= 0; i
< size
; ++i
)
3601 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3609 read_string (abfd
, buf
, bytes_read_ptr
)
3612 unsigned int *bytes_read_ptr
;
3614 /* If the size of a host char is 8 bits, we can return a pointer
3615 to the string, otherwise we have to copy the string to a buffer
3616 allocated on the temporary obstack. */
3617 #if HOST_CHAR_BIT == 8
3620 *bytes_read_ptr
= 1;
3623 *bytes_read_ptr
= strlen (buf
) + 1;
3629 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3631 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3637 *bytes_read_ptr
= 1;
3640 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3641 *bytes_read_ptr
= i
+ 1;
3642 return obstack_finish (&dwarf2_tmp_obstack
);
3647 read_unsigned_leb128 (abfd
, buf
, bytes_read_ptr
)
3650 unsigned int *bytes_read_ptr
;
3652 unsigned int result
, num_read
;
3662 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3665 result
|= ((byte
& 127) << shift
);
3666 if ((byte
& 128) == 0)
3672 *bytes_read_ptr
= num_read
;
3677 read_signed_leb128 (abfd
, buf
, bytes_read_ptr
)
3680 unsigned int *bytes_read_ptr
;
3683 int i
, shift
, size
, num_read
;
3693 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3696 result
|= ((byte
& 127) << shift
);
3698 if ((byte
& 128) == 0)
3703 if ((shift
< size
) && (byte
& 0x40))
3705 result
|= -(1 << shift
);
3707 *bytes_read_ptr
= num_read
;
3712 set_cu_language (lang
)
3719 cu_language
= language_c
;
3721 case DW_LANG_C_plus_plus
:
3722 cu_language
= language_cplus
;
3724 case DW_LANG_Fortran77
:
3725 case DW_LANG_Fortran90
:
3726 cu_language
= language_fortran
;
3728 case DW_LANG_Mips_Assembler
:
3729 cu_language
= language_asm
;
3732 case DW_LANG_Cobol74
:
3733 case DW_LANG_Cobol85
:
3734 case DW_LANG_Pascal83
:
3735 case DW_LANG_Modula2
:
3737 cu_language
= language_unknown
;
3740 cu_language_defn
= language_def (cu_language
);
3743 /* Return the named attribute or NULL if not there. */
3745 static struct attribute
*
3746 dwarf_attr (die
, name
)
3747 struct die_info
*die
;
3751 struct attribute
*spec
= NULL
;
3753 for (i
= 0; i
< die
->num_attrs
; ++i
)
3755 if (die
->attrs
[i
].name
== name
)
3757 return &die
->attrs
[i
];
3759 if (die
->attrs
[i
].name
== DW_AT_specification
3760 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3761 spec
= &die
->attrs
[i
];
3765 struct die_info
*ref_die
=
3766 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3769 return dwarf_attr (ref_die
, name
);
3775 /* Decode the line number information for the compilation unit whose
3776 line number info is at OFFSET in the .debug_line section.
3777 The compilation directory of the file is passed in COMP_DIR. */
3781 unsigned int num_files
;
3794 unsigned int num_dirs
;
3799 dwarf_decode_lines (offset
, comp_dir
, abfd
)
3800 unsigned int offset
;
3806 struct line_head lh
;
3807 struct cleanup
*back_to
;
3808 unsigned int i
, bytes_read
;
3809 char *cur_file
, *cur_dir
;
3810 unsigned char op_code
, extended_op
, adj_opcode
;
3812 #define FILE_ALLOC_CHUNK 5
3813 #define DIR_ALLOC_CHUNK 5
3815 struct filenames files
;
3816 struct directories dirs
;
3818 if (dwarf_line_buffer
== NULL
)
3820 complain (&dwarf2_missing_line_number_section
);
3824 files
.num_files
= 0;
3830 line_ptr
= dwarf_line_buffer
+ offset
;
3832 /* read in the prologue */
3833 lh
.total_length
= read_4_bytes (abfd
, line_ptr
);
3835 line_end
= line_ptr
+ lh
.total_length
;
3836 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3838 lh
.prologue_length
= read_4_bytes (abfd
, line_ptr
);
3840 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3842 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3844 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3846 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3848 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3850 lh
.standard_opcode_lengths
= (unsigned char *)
3851 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3852 back_to
= make_cleanup ((make_cleanup_func
) free_current_contents
,
3853 &lh
.standard_opcode_lengths
);
3855 lh
.standard_opcode_lengths
[0] = 1;
3856 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3858 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3862 /* Read directory table */
3863 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3865 line_ptr
+= bytes_read
;
3866 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3868 dirs
.dirs
= (char **)
3869 xrealloc (dirs
.dirs
,
3870 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3871 if (dirs
.num_dirs
== 0)
3872 make_cleanup ((make_cleanup_func
) free_current_contents
, &dirs
.dirs
);
3874 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3876 line_ptr
+= bytes_read
;
3878 /* Read file name table */
3879 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3881 line_ptr
+= bytes_read
;
3882 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3884 files
.files
= (struct fileinfo
*)
3885 xrealloc (files
.files
,
3886 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3887 * sizeof (struct fileinfo
));
3888 if (files
.num_files
== 0)
3889 make_cleanup ((make_cleanup_func
) free_current_contents
,
3892 files
.files
[files
.num_files
].name
= cur_file
;
3893 files
.files
[files
.num_files
].dir
=
3894 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3895 line_ptr
+= bytes_read
;
3896 files
.files
[files
.num_files
].time
=
3897 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3898 line_ptr
+= bytes_read
;
3899 files
.files
[files
.num_files
].size
=
3900 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3901 line_ptr
+= bytes_read
;
3904 line_ptr
+= bytes_read
;
3906 /* Read the statement sequences until there's nothing left. */
3907 while (line_ptr
< line_end
)
3909 /* state machine registers */
3910 CORE_ADDR address
= 0;
3911 unsigned int file
= 1;
3912 unsigned int line
= 1;
3913 unsigned int column
= 0;
3914 int is_stmt
= lh
.default_is_stmt
;
3915 int basic_block
= 0;
3916 int end_sequence
= 0;
3918 /* Start a subfile for the current file of the state machine. */
3919 if (files
.num_files
>= file
)
3921 /* The file and directory tables are 0 based, the references
3923 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3924 (files
.files
[file
- 1].dir
3925 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3929 /* Decode the table. */
3930 while (!end_sequence
)
3932 op_code
= read_1_byte (abfd
, line_ptr
);
3936 case DW_LNS_extended_op
:
3937 line_ptr
+= 1; /* ignore length */
3938 extended_op
= read_1_byte (abfd
, line_ptr
);
3940 switch (extended_op
)
3942 case DW_LNE_end_sequence
:
3944 /* Don't call record_line here. The end_sequence
3945 instruction provides the address of the first byte
3946 *after* the last line in the sequence; it's not the
3947 address of any real source line. However, the GDB
3948 linetable structure only records the starts of lines,
3949 not the ends. This is a weakness of GDB. */
3951 case DW_LNE_set_address
:
3952 address
= read_address (abfd
, line_ptr
) + baseaddr
;
3953 line_ptr
+= address_size
;
3955 case DW_LNE_define_file
:
3956 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3957 line_ptr
+= bytes_read
;
3958 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3960 files
.files
= (struct fileinfo
*)
3961 xrealloc (files
.files
,
3962 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3963 * sizeof (struct fileinfo
));
3964 if (files
.num_files
== 0)
3965 make_cleanup ((make_cleanup_func
) free_current_contents
,
3968 files
.files
[files
.num_files
].name
= cur_file
;
3969 files
.files
[files
.num_files
].dir
=
3970 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3971 line_ptr
+= bytes_read
;
3972 files
.files
[files
.num_files
].time
=
3973 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3974 line_ptr
+= bytes_read
;
3975 files
.files
[files
.num_files
].size
=
3976 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3977 line_ptr
+= bytes_read
;
3981 complain (&dwarf2_mangled_line_number_section
);
3986 record_line (current_subfile
, line
, address
);
3989 case DW_LNS_advance_pc
:
3990 address
+= lh
.minimum_instruction_length
3991 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3992 line_ptr
+= bytes_read
;
3994 case DW_LNS_advance_line
:
3995 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3996 line_ptr
+= bytes_read
;
3998 case DW_LNS_set_file
:
3999 /* The file and directory tables are 0 based, the references
4001 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4002 line_ptr
+= bytes_read
;
4003 dwarf2_start_subfile
4004 (files
.files
[file
- 1].name
,
4005 (files
.files
[file
- 1].dir
4006 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
4009 case DW_LNS_set_column
:
4010 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
4011 line_ptr
+= bytes_read
;
4013 case DW_LNS_negate_stmt
:
4014 is_stmt
= (!is_stmt
);
4016 case DW_LNS_set_basic_block
:
4019 case DW_LNS_const_add_pc
:
4020 address
+= (255 - lh
.opcode_base
) / lh
.line_range
;
4022 case DW_LNS_fixed_advance_pc
:
4023 address
+= read_2_bytes (abfd
, line_ptr
);
4026 default: /* special operand */
4027 adj_opcode
= op_code
- lh
.opcode_base
;
4028 address
+= (adj_opcode
/ lh
.line_range
)
4029 * lh
.minimum_instruction_length
;
4030 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4031 /* append row to matrix using current values */
4032 record_line (current_subfile
, line
, address
);
4038 do_cleanups (back_to
);
4041 /* Start a subfile for DWARF. FILENAME is the name of the file and
4042 DIRNAME the name of the source directory which contains FILENAME
4043 or NULL if not known.
4044 This routine tries to keep line numbers from identical absolute and
4045 relative file names in a common subfile.
4047 Using the `list' example from the GDB testsuite, which resides in
4048 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4049 of /srcdir/list0.c yields the following debugging information for list0.c:
4051 DW_AT_name: /srcdir/list0.c
4052 DW_AT_comp_dir: /compdir
4053 files.files[0].name: list0.h
4054 files.files[0].dir: /srcdir
4055 files.files[1].name: list0.c
4056 files.files[1].dir: /srcdir
4058 The line number information for list0.c has to end up in a single
4059 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4062 dwarf2_start_subfile (filename
, dirname
)
4066 /* If the filename isn't absolute, try to match an existing subfile
4067 with the full pathname. */
4069 if (*filename
!= '/' && dirname
!= NULL
)
4071 struct subfile
*subfile
;
4072 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4074 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4076 if (STREQ (subfile
->name
, fullname
))
4078 current_subfile
= subfile
;
4085 start_subfile (filename
, dirname
);
4088 /* Given a pointer to a DWARF information entry, figure out if we need
4089 to make a symbol table entry for it, and if so, create a new entry
4090 and return a pointer to it.
4091 If TYPE is NULL, determine symbol type from the die, otherwise
4092 used the passed type.
4095 static struct symbol
*
4096 new_symbol (die
, type
, objfile
)
4097 struct die_info
*die
;
4099 struct objfile
*objfile
;
4101 struct symbol
*sym
= NULL
;
4103 struct attribute
*attr
= NULL
;
4104 struct attribute
*attr2
= NULL
;
4107 name
= dwarf2_linkage_name (die
);
4110 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4111 sizeof (struct symbol
));
4112 OBJSTAT (objfile
, n_syms
++);
4113 memset (sym
, 0, sizeof (struct symbol
));
4114 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4115 &objfile
->symbol_obstack
);
4117 /* Default assumptions.
4118 Use the passed type or decode it from the die. */
4119 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4120 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4122 SYMBOL_TYPE (sym
) = type
;
4124 SYMBOL_TYPE (sym
) = die_type (die
, objfile
);
4125 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4128 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4131 /* If this symbol is from a C++ compilation, then attempt to
4132 cache the demangled form for future reference. This is a
4133 typical time versus space tradeoff, that was decided in favor
4134 of time because it sped up C++ symbol lookups by a factor of
4137 SYMBOL_LANGUAGE (sym
) = cu_language
;
4138 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4142 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4145 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4147 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4149 case DW_TAG_subprogram
:
4150 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4152 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4153 attr2
= dwarf_attr (die
, DW_AT_external
);
4154 if (attr2
&& (DW_UNSND (attr2
) != 0))
4156 add_symbol_to_list (sym
, &global_symbols
);
4160 add_symbol_to_list (sym
, list_in_scope
);
4163 case DW_TAG_variable
:
4164 /* Compilation with minimal debug info may result in variables
4165 with missing type entries. Change the misleading `void' type
4166 to something sensible. */
4167 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4168 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4169 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4170 "<variable, no debug info>",
4172 attr
= dwarf_attr (die
, DW_AT_const_value
);
4175 dwarf2_const_value (attr
, sym
, objfile
);
4176 attr2
= dwarf_attr (die
, DW_AT_external
);
4177 if (attr2
&& (DW_UNSND (attr2
) != 0))
4178 add_symbol_to_list (sym
, &global_symbols
);
4180 add_symbol_to_list (sym
, list_in_scope
);
4183 attr
= dwarf_attr (die
, DW_AT_location
);
4186 attr2
= dwarf_attr (die
, DW_AT_external
);
4187 if (attr2
&& (DW_UNSND (attr2
) != 0))
4189 SYMBOL_VALUE_ADDRESS (sym
) =
4190 decode_locdesc (DW_BLOCK (attr
), objfile
);
4191 add_symbol_to_list (sym
, &global_symbols
);
4193 /* In shared libraries the address of the variable
4194 in the location descriptor might still be relocatable,
4195 so its value could be zero.
4196 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4197 value is zero, the address of the variable will then
4198 be determined from the minimal symbol table whenever
4199 the variable is referenced. */
4200 if (SYMBOL_VALUE_ADDRESS (sym
))
4202 SYMBOL_VALUE_ADDRESS (sym
) += baseaddr
;
4203 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4206 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4210 SYMBOL_VALUE (sym
) = addr
=
4211 decode_locdesc (DW_BLOCK (attr
), objfile
);
4212 add_symbol_to_list (sym
, list_in_scope
);
4215 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4219 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4223 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4224 SYMBOL_BASEREG (sym
) = basereg
;
4228 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4232 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4233 SYMBOL_VALUE_ADDRESS (sym
) = addr
+ baseaddr
;
4239 /* We do not know the address of this symbol.
4240 If it is an external symbol and we have type information
4241 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4242 The address of the variable will then be determined from
4243 the minimal symbol table whenever the variable is
4245 attr2
= dwarf_attr (die
, DW_AT_external
);
4246 if (attr2
&& (DW_UNSND (attr2
) != 0)
4247 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4249 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4250 add_symbol_to_list (sym
, &global_symbols
);
4254 case DW_TAG_formal_parameter
:
4255 attr
= dwarf_attr (die
, DW_AT_location
);
4258 SYMBOL_VALUE (sym
) = decode_locdesc (DW_BLOCK (attr
), objfile
);
4261 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4267 if (basereg
!= frame_base_reg
)
4268 complain (&dwarf2_complex_location_expr
);
4269 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4273 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4274 SYMBOL_BASEREG (sym
) = basereg
;
4279 SYMBOL_CLASS (sym
) = LOC_ARG
;
4282 attr
= dwarf_attr (die
, DW_AT_const_value
);
4285 dwarf2_const_value (attr
, sym
, objfile
);
4287 add_symbol_to_list (sym
, list_in_scope
);
4289 case DW_TAG_unspecified_parameters
:
4290 /* From varargs functions; gdb doesn't seem to have any
4291 interest in this information, so just ignore it for now.
4294 case DW_TAG_class_type
:
4295 case DW_TAG_structure_type
:
4296 case DW_TAG_union_type
:
4297 case DW_TAG_enumeration_type
:
4298 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4299 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4300 add_symbol_to_list (sym
, list_in_scope
);
4302 /* The semantics of C++ state that "struct foo { ... }" also
4303 defines a typedef for "foo". Synthesize a typedef symbol so
4304 that "ptype foo" works as expected. */
4305 if (cu_language
== language_cplus
)
4307 struct symbol
*typedef_sym
= (struct symbol
*)
4308 obstack_alloc (&objfile
->symbol_obstack
,
4309 sizeof (struct symbol
));
4310 *typedef_sym
= *sym
;
4311 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4312 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4313 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4314 obsavestring (SYMBOL_NAME (sym
),
4315 strlen (SYMBOL_NAME (sym
)),
4316 &objfile
->type_obstack
);
4317 add_symbol_to_list (typedef_sym
, list_in_scope
);
4320 case DW_TAG_typedef
:
4321 case DW_TAG_base_type
:
4322 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4323 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4324 add_symbol_to_list (sym
, list_in_scope
);
4326 case DW_TAG_enumerator
:
4327 attr
= dwarf_attr (die
, DW_AT_const_value
);
4330 dwarf2_const_value (attr
, sym
, objfile
);
4332 add_symbol_to_list (sym
, list_in_scope
);
4335 /* Not a tag we recognize. Hopefully we aren't processing
4336 trash data, but since we must specifically ignore things
4337 we don't recognize, there is nothing else we should do at
4339 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4346 /* Copy constant value from an attribute to a symbol. */
4349 dwarf2_const_value (attr
, sym
, objfile
)
4350 struct attribute
*attr
;
4352 struct objfile
*objfile
;
4354 struct dwarf_block
*blk
;
4359 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != (unsigned int) address_size
)
4360 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4361 address_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4362 SYMBOL_VALUE_BYTES (sym
) = (char *)
4363 obstack_alloc (&objfile
->symbol_obstack
, address_size
);
4364 store_address (SYMBOL_VALUE_BYTES (sym
), address_size
, DW_ADDR (attr
));
4365 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4367 case DW_FORM_block1
:
4368 case DW_FORM_block2
:
4369 case DW_FORM_block4
:
4371 blk
= DW_BLOCK (attr
);
4372 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4373 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4374 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4375 SYMBOL_VALUE_BYTES (sym
) = (char *)
4376 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4377 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4378 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4386 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4387 SYMBOL_CLASS (sym
) = LOC_CONST
;
4390 complain (&dwarf2_unsupported_const_value_attr
,
4391 dwarf_form_name (attr
->form
));
4392 SYMBOL_VALUE (sym
) = 0;
4393 SYMBOL_CLASS (sym
) = LOC_CONST
;
4398 /* Return the type of the die in question using its DW_AT_type attribute. */
4400 static struct type
*
4401 die_type (die
, objfile
)
4402 struct die_info
*die
;
4403 struct objfile
*objfile
;
4406 struct attribute
*type_attr
;
4407 struct die_info
*type_die
;
4410 type_attr
= dwarf_attr (die
, DW_AT_type
);
4413 /* A missing DW_AT_type represents a void type. */
4414 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4418 ref
= dwarf2_get_ref_die_offset (type_attr
);
4419 type_die
= follow_die_ref (ref
);
4422 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4426 type
= tag_type_to_type (type_die
, objfile
);
4429 dump_die (type_die
);
4430 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4435 /* Return the containing type of the die in question using its
4436 DW_AT_containing_type attribute. */
4438 static struct type
*
4439 die_containing_type (die
, objfile
)
4440 struct die_info
*die
;
4441 struct objfile
*objfile
;
4443 struct type
*type
= NULL
;
4444 struct attribute
*type_attr
;
4445 struct die_info
*type_die
= NULL
;
4448 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4451 ref
= dwarf2_get_ref_die_offset (type_attr
);
4452 type_die
= follow_die_ref (ref
);
4455 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4458 type
= tag_type_to_type (type_die
, objfile
);
4463 dump_die (type_die
);
4464 error ("Dwarf Error: Problem turning containing type into gdb type.");
4470 static struct type
*
4471 type_at_offset (offset
, objfile
)
4472 unsigned int offset
;
4473 struct objfile
*objfile
;
4475 struct die_info
*die
;
4478 die
= follow_die_ref (offset
);
4481 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4484 type
= tag_type_to_type (die
, objfile
);
4489 static struct type
*
4490 tag_type_to_type (die
, objfile
)
4491 struct die_info
*die
;
4492 struct objfile
*objfile
;
4500 read_type_die (die
, objfile
);
4504 error ("Dwarf Error: Cannot find type of die.");
4511 read_type_die (die
, objfile
)
4512 struct die_info
*die
;
4513 struct objfile
*objfile
;
4517 case DW_TAG_class_type
:
4518 case DW_TAG_structure_type
:
4519 case DW_TAG_union_type
:
4520 read_structure_scope (die
, objfile
);
4522 case DW_TAG_enumeration_type
:
4523 read_enumeration (die
, objfile
);
4525 case DW_TAG_subprogram
:
4526 case DW_TAG_subroutine_type
:
4527 read_subroutine_type (die
, objfile
);
4529 case DW_TAG_array_type
:
4530 read_array_type (die
, objfile
);
4532 case DW_TAG_pointer_type
:
4533 read_tag_pointer_type (die
, objfile
);
4535 case DW_TAG_ptr_to_member_type
:
4536 read_tag_ptr_to_member_type (die
, objfile
);
4538 case DW_TAG_reference_type
:
4539 read_tag_reference_type (die
, objfile
);
4541 case DW_TAG_const_type
:
4542 read_tag_const_type (die
, objfile
);
4544 case DW_TAG_volatile_type
:
4545 read_tag_volatile_type (die
, objfile
);
4547 case DW_TAG_string_type
:
4548 read_tag_string_type (die
, objfile
);
4550 case DW_TAG_typedef
:
4551 read_typedef (die
, objfile
);
4553 case DW_TAG_base_type
:
4554 read_base_type (die
, objfile
);
4557 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4562 static struct type
*
4563 dwarf_base_type (encoding
, size
, objfile
)
4566 struct objfile
*objfile
;
4568 /* FIXME - this should not produce a new (struct type *)
4569 every time. It should cache base types. */
4573 case DW_ATE_address
:
4574 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4576 case DW_ATE_boolean
:
4577 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4579 case DW_ATE_complex_float
:
4582 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4586 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4592 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4596 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4603 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4606 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4610 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4614 case DW_ATE_signed_char
:
4615 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4617 case DW_ATE_unsigned
:
4621 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4624 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4628 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4632 case DW_ATE_unsigned_char
:
4633 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4636 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4644 struct die_info
*old_die
;
4646 struct die_info
*new_die
;
4649 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4650 memset (new_die
, 0, sizeof (struct die_info
));
4652 new_die
->tag
= old_die
->tag
;
4653 new_die
->has_children
= old_die
->has_children
;
4654 new_die
->abbrev
= old_die
->abbrev
;
4655 new_die
->offset
= old_die
->offset
;
4656 new_die
->type
= NULL
;
4658 num_attrs
= old_die
->num_attrs
;
4659 new_die
->num_attrs
= num_attrs
;
4660 new_die
->attrs
= (struct attribute
*)
4661 xmalloc (num_attrs
* sizeof (struct attribute
));
4663 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4665 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4666 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4667 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4670 new_die
->next
= NULL
;
4675 /* Return sibling of die, NULL if no sibling. */
4679 struct die_info
*die
;
4681 int nesting_level
= 0;
4683 if (!die
->has_children
)
4685 if (die
->next
&& (die
->next
->tag
== 0))
4698 if (die
->has_children
)
4708 while (nesting_level
);
4709 if (die
&& (die
->tag
== 0))
4720 /* Get linkage name of a die, return NULL if not found. */
4723 dwarf2_linkage_name (die
)
4724 struct die_info
*die
;
4726 struct attribute
*attr
;
4728 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4729 if (attr
&& DW_STRING (attr
))
4730 return DW_STRING (attr
);
4731 attr
= dwarf_attr (die
, DW_AT_name
);
4732 if (attr
&& DW_STRING (attr
))
4733 return DW_STRING (attr
);
4737 /* Convert a DIE tag into its string name. */
4740 dwarf_tag_name (tag
)
4741 register unsigned tag
;
4745 case DW_TAG_padding
:
4746 return "DW_TAG_padding";
4747 case DW_TAG_array_type
:
4748 return "DW_TAG_array_type";
4749 case DW_TAG_class_type
:
4750 return "DW_TAG_class_type";
4751 case DW_TAG_entry_point
:
4752 return "DW_TAG_entry_point";
4753 case DW_TAG_enumeration_type
:
4754 return "DW_TAG_enumeration_type";
4755 case DW_TAG_formal_parameter
:
4756 return "DW_TAG_formal_parameter";
4757 case DW_TAG_imported_declaration
:
4758 return "DW_TAG_imported_declaration";
4760 return "DW_TAG_label";
4761 case DW_TAG_lexical_block
:
4762 return "DW_TAG_lexical_block";
4764 return "DW_TAG_member";
4765 case DW_TAG_pointer_type
:
4766 return "DW_TAG_pointer_type";
4767 case DW_TAG_reference_type
:
4768 return "DW_TAG_reference_type";
4769 case DW_TAG_compile_unit
:
4770 return "DW_TAG_compile_unit";
4771 case DW_TAG_string_type
:
4772 return "DW_TAG_string_type";
4773 case DW_TAG_structure_type
:
4774 return "DW_TAG_structure_type";
4775 case DW_TAG_subroutine_type
:
4776 return "DW_TAG_subroutine_type";
4777 case DW_TAG_typedef
:
4778 return "DW_TAG_typedef";
4779 case DW_TAG_union_type
:
4780 return "DW_TAG_union_type";
4781 case DW_TAG_unspecified_parameters
:
4782 return "DW_TAG_unspecified_parameters";
4783 case DW_TAG_variant
:
4784 return "DW_TAG_variant";
4785 case DW_TAG_common_block
:
4786 return "DW_TAG_common_block";
4787 case DW_TAG_common_inclusion
:
4788 return "DW_TAG_common_inclusion";
4789 case DW_TAG_inheritance
:
4790 return "DW_TAG_inheritance";
4791 case DW_TAG_inlined_subroutine
:
4792 return "DW_TAG_inlined_subroutine";
4794 return "DW_TAG_module";
4795 case DW_TAG_ptr_to_member_type
:
4796 return "DW_TAG_ptr_to_member_type";
4797 case DW_TAG_set_type
:
4798 return "DW_TAG_set_type";
4799 case DW_TAG_subrange_type
:
4800 return "DW_TAG_subrange_type";
4801 case DW_TAG_with_stmt
:
4802 return "DW_TAG_with_stmt";
4803 case DW_TAG_access_declaration
:
4804 return "DW_TAG_access_declaration";
4805 case DW_TAG_base_type
:
4806 return "DW_TAG_base_type";
4807 case DW_TAG_catch_block
:
4808 return "DW_TAG_catch_block";
4809 case DW_TAG_const_type
:
4810 return "DW_TAG_const_type";
4811 case DW_TAG_constant
:
4812 return "DW_TAG_constant";
4813 case DW_TAG_enumerator
:
4814 return "DW_TAG_enumerator";
4815 case DW_TAG_file_type
:
4816 return "DW_TAG_file_type";
4818 return "DW_TAG_friend";
4819 case DW_TAG_namelist
:
4820 return "DW_TAG_namelist";
4821 case DW_TAG_namelist_item
:
4822 return "DW_TAG_namelist_item";
4823 case DW_TAG_packed_type
:
4824 return "DW_TAG_packed_type";
4825 case DW_TAG_subprogram
:
4826 return "DW_TAG_subprogram";
4827 case DW_TAG_template_type_param
:
4828 return "DW_TAG_template_type_param";
4829 case DW_TAG_template_value_param
:
4830 return "DW_TAG_template_value_param";
4831 case DW_TAG_thrown_type
:
4832 return "DW_TAG_thrown_type";
4833 case DW_TAG_try_block
:
4834 return "DW_TAG_try_block";
4835 case DW_TAG_variant_part
:
4836 return "DW_TAG_variant_part";
4837 case DW_TAG_variable
:
4838 return "DW_TAG_variable";
4839 case DW_TAG_volatile_type
:
4840 return "DW_TAG_volatile_type";
4841 case DW_TAG_MIPS_loop
:
4842 return "DW_TAG_MIPS_loop";
4843 case DW_TAG_format_label
:
4844 return "DW_TAG_format_label";
4845 case DW_TAG_function_template
:
4846 return "DW_TAG_function_template";
4847 case DW_TAG_class_template
:
4848 return "DW_TAG_class_template";
4850 return "DW_TAG_<unknown>";
4854 /* Convert a DWARF attribute code into its string name. */
4857 dwarf_attr_name (attr
)
4858 register unsigned attr
;
4863 return "DW_AT_sibling";
4864 case DW_AT_location
:
4865 return "DW_AT_location";
4867 return "DW_AT_name";
4868 case DW_AT_ordering
:
4869 return "DW_AT_ordering";
4870 case DW_AT_subscr_data
:
4871 return "DW_AT_subscr_data";
4872 case DW_AT_byte_size
:
4873 return "DW_AT_byte_size";
4874 case DW_AT_bit_offset
:
4875 return "DW_AT_bit_offset";
4876 case DW_AT_bit_size
:
4877 return "DW_AT_bit_size";
4878 case DW_AT_element_list
:
4879 return "DW_AT_element_list";
4880 case DW_AT_stmt_list
:
4881 return "DW_AT_stmt_list";
4883 return "DW_AT_low_pc";
4885 return "DW_AT_high_pc";
4886 case DW_AT_language
:
4887 return "DW_AT_language";
4889 return "DW_AT_member";
4891 return "DW_AT_discr";
4892 case DW_AT_discr_value
:
4893 return "DW_AT_discr_value";
4894 case DW_AT_visibility
:
4895 return "DW_AT_visibility";
4897 return "DW_AT_import";
4898 case DW_AT_string_length
:
4899 return "DW_AT_string_length";
4900 case DW_AT_common_reference
:
4901 return "DW_AT_common_reference";
4902 case DW_AT_comp_dir
:
4903 return "DW_AT_comp_dir";
4904 case DW_AT_const_value
:
4905 return "DW_AT_const_value";
4906 case DW_AT_containing_type
:
4907 return "DW_AT_containing_type";
4908 case DW_AT_default_value
:
4909 return "DW_AT_default_value";
4911 return "DW_AT_inline";
4912 case DW_AT_is_optional
:
4913 return "DW_AT_is_optional";
4914 case DW_AT_lower_bound
:
4915 return "DW_AT_lower_bound";
4916 case DW_AT_producer
:
4917 return "DW_AT_producer";
4918 case DW_AT_prototyped
:
4919 return "DW_AT_prototyped";
4920 case DW_AT_return_addr
:
4921 return "DW_AT_return_addr";
4922 case DW_AT_start_scope
:
4923 return "DW_AT_start_scope";
4924 case DW_AT_stride_size
:
4925 return "DW_AT_stride_size";
4926 case DW_AT_upper_bound
:
4927 return "DW_AT_upper_bound";
4928 case DW_AT_abstract_origin
:
4929 return "DW_AT_abstract_origin";
4930 case DW_AT_accessibility
:
4931 return "DW_AT_accessibility";
4932 case DW_AT_address_class
:
4933 return "DW_AT_address_class";
4934 case DW_AT_artificial
:
4935 return "DW_AT_artificial";
4936 case DW_AT_base_types
:
4937 return "DW_AT_base_types";
4938 case DW_AT_calling_convention
:
4939 return "DW_AT_calling_convention";
4941 return "DW_AT_count";
4942 case DW_AT_data_member_location
:
4943 return "DW_AT_data_member_location";
4944 case DW_AT_decl_column
:
4945 return "DW_AT_decl_column";
4946 case DW_AT_decl_file
:
4947 return "DW_AT_decl_file";
4948 case DW_AT_decl_line
:
4949 return "DW_AT_decl_line";
4950 case DW_AT_declaration
:
4951 return "DW_AT_declaration";
4952 case DW_AT_discr_list
:
4953 return "DW_AT_discr_list";
4954 case DW_AT_encoding
:
4955 return "DW_AT_encoding";
4956 case DW_AT_external
:
4957 return "DW_AT_external";
4958 case DW_AT_frame_base
:
4959 return "DW_AT_frame_base";
4961 return "DW_AT_friend";
4962 case DW_AT_identifier_case
:
4963 return "DW_AT_identifier_case";
4964 case DW_AT_macro_info
:
4965 return "DW_AT_macro_info";
4966 case DW_AT_namelist_items
:
4967 return "DW_AT_namelist_items";
4968 case DW_AT_priority
:
4969 return "DW_AT_priority";
4971 return "DW_AT_segment";
4972 case DW_AT_specification
:
4973 return "DW_AT_specification";
4974 case DW_AT_static_link
:
4975 return "DW_AT_static_link";
4977 return "DW_AT_type";
4978 case DW_AT_use_location
:
4979 return "DW_AT_use_location";
4980 case DW_AT_variable_parameter
:
4981 return "DW_AT_variable_parameter";
4982 case DW_AT_virtuality
:
4983 return "DW_AT_virtuality";
4984 case DW_AT_vtable_elem_location
:
4985 return "DW_AT_vtable_elem_location";
4988 case DW_AT_MIPS_fde
:
4989 return "DW_AT_MIPS_fde";
4990 case DW_AT_MIPS_loop_begin
:
4991 return "DW_AT_MIPS_loop_begin";
4992 case DW_AT_MIPS_tail_loop_begin
:
4993 return "DW_AT_MIPS_tail_loop_begin";
4994 case DW_AT_MIPS_epilog_begin
:
4995 return "DW_AT_MIPS_epilog_begin";
4996 case DW_AT_MIPS_loop_unroll_factor
:
4997 return "DW_AT_MIPS_loop_unroll_factor";
4998 case DW_AT_MIPS_software_pipeline_depth
:
4999 return "DW_AT_MIPS_software_pipeline_depth";
5000 case DW_AT_MIPS_linkage_name
:
5001 return "DW_AT_MIPS_linkage_name";
5004 case DW_AT_sf_names
:
5005 return "DW_AT_sf_names";
5006 case DW_AT_src_info
:
5007 return "DW_AT_src_info";
5008 case DW_AT_mac_info
:
5009 return "DW_AT_mac_info";
5010 case DW_AT_src_coords
:
5011 return "DW_AT_src_coords";
5012 case DW_AT_body_begin
:
5013 return "DW_AT_body_begin";
5014 case DW_AT_body_end
:
5015 return "DW_AT_body_end";
5017 return "DW_AT_<unknown>";
5021 /* Convert a DWARF value form code into its string name. */
5024 dwarf_form_name (form
)
5025 register unsigned form
;
5030 return "DW_FORM_addr";
5031 case DW_FORM_block2
:
5032 return "DW_FORM_block2";
5033 case DW_FORM_block4
:
5034 return "DW_FORM_block4";
5036 return "DW_FORM_data2";
5038 return "DW_FORM_data4";
5040 return "DW_FORM_data8";
5041 case DW_FORM_string
:
5042 return "DW_FORM_string";
5044 return "DW_FORM_block";
5045 case DW_FORM_block1
:
5046 return "DW_FORM_block1";
5048 return "DW_FORM_data1";
5050 return "DW_FORM_flag";
5052 return "DW_FORM_sdata";
5054 return "DW_FORM_strp";
5056 return "DW_FORM_udata";
5057 case DW_FORM_ref_addr
:
5058 return "DW_FORM_ref_addr";
5060 return "DW_FORM_ref1";
5062 return "DW_FORM_ref2";
5064 return "DW_FORM_ref4";
5066 return "DW_FORM_ref8";
5067 case DW_FORM_ref_udata
:
5068 return "DW_FORM_ref_udata";
5069 case DW_FORM_indirect
:
5070 return "DW_FORM_indirect";
5072 return "DW_FORM_<unknown>";
5076 /* Convert a DWARF stack opcode into its string name. */
5079 dwarf_stack_op_name (op
)
5080 register unsigned op
;
5085 return "DW_OP_addr";
5087 return "DW_OP_deref";
5089 return "DW_OP_const1u";
5091 return "DW_OP_const1s";
5093 return "DW_OP_const2u";
5095 return "DW_OP_const2s";
5097 return "DW_OP_const4u";
5099 return "DW_OP_const4s";
5101 return "DW_OP_const8u";
5103 return "DW_OP_const8s";
5105 return "DW_OP_constu";
5107 return "DW_OP_consts";
5111 return "DW_OP_drop";
5113 return "DW_OP_over";
5115 return "DW_OP_pick";
5117 return "DW_OP_swap";
5121 return "DW_OP_xderef";
5129 return "DW_OP_minus";
5141 return "DW_OP_plus";
5142 case DW_OP_plus_uconst
:
5143 return "DW_OP_plus_uconst";
5149 return "DW_OP_shra";
5167 return "DW_OP_skip";
5169 return "DW_OP_lit0";
5171 return "DW_OP_lit1";
5173 return "DW_OP_lit2";
5175 return "DW_OP_lit3";
5177 return "DW_OP_lit4";
5179 return "DW_OP_lit5";
5181 return "DW_OP_lit6";
5183 return "DW_OP_lit7";
5185 return "DW_OP_lit8";
5187 return "DW_OP_lit9";
5189 return "DW_OP_lit10";
5191 return "DW_OP_lit11";
5193 return "DW_OP_lit12";
5195 return "DW_OP_lit13";
5197 return "DW_OP_lit14";
5199 return "DW_OP_lit15";
5201 return "DW_OP_lit16";
5203 return "DW_OP_lit17";
5205 return "DW_OP_lit18";
5207 return "DW_OP_lit19";
5209 return "DW_OP_lit20";
5211 return "DW_OP_lit21";
5213 return "DW_OP_lit22";
5215 return "DW_OP_lit23";
5217 return "DW_OP_lit24";
5219 return "DW_OP_lit25";
5221 return "DW_OP_lit26";
5223 return "DW_OP_lit27";
5225 return "DW_OP_lit28";
5227 return "DW_OP_lit29";
5229 return "DW_OP_lit30";
5231 return "DW_OP_lit31";
5233 return "DW_OP_reg0";
5235 return "DW_OP_reg1";
5237 return "DW_OP_reg2";
5239 return "DW_OP_reg3";
5241 return "DW_OP_reg4";
5243 return "DW_OP_reg5";
5245 return "DW_OP_reg6";
5247 return "DW_OP_reg7";
5249 return "DW_OP_reg8";
5251 return "DW_OP_reg9";
5253 return "DW_OP_reg10";
5255 return "DW_OP_reg11";
5257 return "DW_OP_reg12";
5259 return "DW_OP_reg13";
5261 return "DW_OP_reg14";
5263 return "DW_OP_reg15";
5265 return "DW_OP_reg16";
5267 return "DW_OP_reg17";
5269 return "DW_OP_reg18";
5271 return "DW_OP_reg19";
5273 return "DW_OP_reg20";
5275 return "DW_OP_reg21";
5277 return "DW_OP_reg22";
5279 return "DW_OP_reg23";
5281 return "DW_OP_reg24";
5283 return "DW_OP_reg25";
5285 return "DW_OP_reg26";
5287 return "DW_OP_reg27";
5289 return "DW_OP_reg28";
5291 return "DW_OP_reg29";
5293 return "DW_OP_reg30";
5295 return "DW_OP_reg31";
5297 return "DW_OP_breg0";
5299 return "DW_OP_breg1";
5301 return "DW_OP_breg2";
5303 return "DW_OP_breg3";
5305 return "DW_OP_breg4";
5307 return "DW_OP_breg5";
5309 return "DW_OP_breg6";
5311 return "DW_OP_breg7";
5313 return "DW_OP_breg8";
5315 return "DW_OP_breg9";
5317 return "DW_OP_breg10";
5319 return "DW_OP_breg11";
5321 return "DW_OP_breg12";
5323 return "DW_OP_breg13";
5325 return "DW_OP_breg14";
5327 return "DW_OP_breg15";
5329 return "DW_OP_breg16";
5331 return "DW_OP_breg17";
5333 return "DW_OP_breg18";
5335 return "DW_OP_breg19";
5337 return "DW_OP_breg20";
5339 return "DW_OP_breg21";
5341 return "DW_OP_breg22";
5343 return "DW_OP_breg23";
5345 return "DW_OP_breg24";
5347 return "DW_OP_breg25";
5349 return "DW_OP_breg26";
5351 return "DW_OP_breg27";
5353 return "DW_OP_breg28";
5355 return "DW_OP_breg29";
5357 return "DW_OP_breg30";
5359 return "DW_OP_breg31";
5361 return "DW_OP_regx";
5363 return "DW_OP_fbreg";
5365 return "DW_OP_bregx";
5367 return "DW_OP_piece";
5368 case DW_OP_deref_size
:
5369 return "DW_OP_deref_size";
5370 case DW_OP_xderef_size
:
5371 return "DW_OP_xderef_size";
5375 return "OP_<unknown>";
5380 dwarf_bool_name (mybool
)
5389 /* Convert a DWARF type code into its string name. */
5392 dwarf_type_encoding_name (enc
)
5393 register unsigned enc
;
5397 case DW_ATE_address
:
5398 return "DW_ATE_address";
5399 case DW_ATE_boolean
:
5400 return "DW_ATE_boolean";
5401 case DW_ATE_complex_float
:
5402 return "DW_ATE_complex_float";
5404 return "DW_ATE_float";
5406 return "DW_ATE_signed";
5407 case DW_ATE_signed_char
:
5408 return "DW_ATE_signed_char";
5409 case DW_ATE_unsigned
:
5410 return "DW_ATE_unsigned";
5411 case DW_ATE_unsigned_char
:
5412 return "DW_ATE_unsigned_char";
5414 return "DW_ATE_<unknown>";
5418 /* Convert a DWARF call frame info operation to its string name. */
5422 dwarf_cfi_name (cfi_opc
)
5423 register unsigned cfi_opc
;
5427 case DW_CFA_advance_loc
:
5428 return "DW_CFA_advance_loc";
5430 return "DW_CFA_offset";
5431 case DW_CFA_restore
:
5432 return "DW_CFA_restore";
5434 return "DW_CFA_nop";
5435 case DW_CFA_set_loc
:
5436 return "DW_CFA_set_loc";
5437 case DW_CFA_advance_loc1
:
5438 return "DW_CFA_advance_loc1";
5439 case DW_CFA_advance_loc2
:
5440 return "DW_CFA_advance_loc2";
5441 case DW_CFA_advance_loc4
:
5442 return "DW_CFA_advance_loc4";
5443 case DW_CFA_offset_extended
:
5444 return "DW_CFA_offset_extended";
5445 case DW_CFA_restore_extended
:
5446 return "DW_CFA_restore_extended";
5447 case DW_CFA_undefined
:
5448 return "DW_CFA_undefined";
5449 case DW_CFA_same_value
:
5450 return "DW_CFA_same_value";
5451 case DW_CFA_register
:
5452 return "DW_CFA_register";
5453 case DW_CFA_remember_state
:
5454 return "DW_CFA_remember_state";
5455 case DW_CFA_restore_state
:
5456 return "DW_CFA_restore_state";
5457 case DW_CFA_def_cfa
:
5458 return "DW_CFA_def_cfa";
5459 case DW_CFA_def_cfa_register
:
5460 return "DW_CFA_def_cfa_register";
5461 case DW_CFA_def_cfa_offset
:
5462 return "DW_CFA_def_cfa_offset";
5463 /* SGI/MIPS specific */
5464 case DW_CFA_MIPS_advance_loc8
:
5465 return "DW_CFA_MIPS_advance_loc8";
5467 return "DW_CFA_<unknown>";
5474 struct die_info
*die
;
5478 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5479 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5480 fprintf (stderr
, "\thas children: %s\n",
5481 dwarf_bool_name (die
->has_children
));
5483 fprintf (stderr
, "\tattributes:\n");
5484 for (i
= 0; i
< die
->num_attrs
; ++i
)
5486 fprintf (stderr
, "\t\t%s (%s) ",
5487 dwarf_attr_name (die
->attrs
[i
].name
),
5488 dwarf_form_name (die
->attrs
[i
].form
));
5489 switch (die
->attrs
[i
].form
)
5491 case DW_FORM_ref_addr
:
5493 fprintf (stderr
, "address: ");
5494 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5496 case DW_FORM_block2
:
5497 case DW_FORM_block4
:
5499 case DW_FORM_block1
:
5500 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5510 fprintf (stderr
, "constant: %d", DW_UNSND (&die
->attrs
[i
]));
5512 case DW_FORM_string
:
5513 fprintf (stderr
, "string: \"%s\"",
5514 DW_STRING (&die
->attrs
[i
])
5515 ? DW_STRING (&die
->attrs
[i
]) : "");
5518 if (DW_UNSND (&die
->attrs
[i
]))
5519 fprintf (stderr
, "flag: TRUE");
5521 fprintf (stderr
, "flag: FALSE");
5523 case DW_FORM_strp
: /* we do not support separate string
5525 case DW_FORM_indirect
: /* we do not handle indirect yet */
5526 case DW_FORM_data8
: /* we do not have 64 bit quantities */
5528 fprintf (stderr
, "unsupported attribute form: %d.",
5529 die
->attrs
[i
].form
);
5531 fprintf (stderr
, "\n");
5537 struct die_info
*die
;
5547 store_in_ref_table (offset
, die
)
5548 unsigned int offset
;
5549 struct die_info
*die
;
5552 struct die_info
*old
;
5554 h
= (offset
% REF_HASH_SIZE
);
5555 old
= die_ref_table
[h
];
5556 die
->next_ref
= old
;
5557 die_ref_table
[h
] = die
;
5562 dwarf2_empty_die_ref_table ()
5564 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5568 dwarf2_get_ref_die_offset (attr
)
5569 struct attribute
*attr
;
5571 unsigned int result
= 0;
5575 case DW_FORM_ref_addr
:
5576 result
= DW_ADDR (attr
);
5581 case DW_FORM_ref_udata
:
5582 result
= cu_header_offset
+ DW_UNSND (attr
);
5585 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5591 follow_die_ref (offset
)
5592 unsigned int offset
;
5594 struct die_info
*die
;
5597 h
= (offset
% REF_HASH_SIZE
);
5598 die
= die_ref_table
[h
];
5601 if (die
->offset
== offset
)
5605 die
= die
->next_ref
;
5610 static struct type
*
5611 dwarf2_fundamental_type (objfile
, typeid)
5612 struct objfile
*objfile
;
5615 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5617 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5621 /* Look for this particular type in the fundamental type vector. If
5622 one is not found, create and install one appropriate for the
5623 current language and the current target machine. */
5625 if (ftypes
[typeid] == NULL
)
5627 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5630 return (ftypes
[typeid]);
5633 /* Decode simple location descriptions.
5634 Given a pointer to a dwarf block that defines a location, compute
5635 the location and return the value.
5637 FIXME: This is a kludge until we figure out a better
5638 way to handle the location descriptions.
5639 Gdb's design does not mesh well with the DWARF2 notion of a location
5640 computing interpreter, which is a shame because the flexibility goes unused.
5641 FIXME: Implement more operations as necessary.
5643 A location description containing no operations indicates that the
5644 object is optimized out. The global optimized_out flag is set for
5645 those, the return value is meaningless.
5647 When the result is a register number, the global isreg flag is set,
5648 otherwise it is cleared.
5650 When the result is a base register offset, the global offreg flag is set
5651 and the register number is returned in basereg, otherwise it is cleared.
5653 When the DW_OP_fbreg operation is encountered without a corresponding
5654 DW_AT_frame_base attribute, the global islocal flag is set.
5655 Hopefully the machine dependent code knows how to set up a virtual
5656 frame pointer for the local references.
5658 Note that stack[0] is unused except as a default error return.
5659 Note that stack overflow is not yet handled. */
5662 decode_locdesc (blk
, objfile
)
5663 struct dwarf_block
*blk
;
5664 struct objfile
*objfile
;
5667 int size
= blk
->size
;
5668 char *data
= blk
->data
;
5669 CORE_ADDR stack
[64];
5671 unsigned int bytes_read
, unsnd
;
5722 stack
[++stacki
] = op
- DW_OP_reg0
;
5727 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5729 #if defined(HARRIS_TARGET) && defined(_M88K)
5730 /* The Harris 88110 gdb ports have long kept their special reg
5731 numbers between their gp-regs and their x-regs. This is
5732 not how our dwarf is generated. Punt. */
5735 stack
[++stacki
] = unsnd
;
5771 basereg
= op
- DW_OP_breg0
;
5772 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5777 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5779 if (frame_base_reg
>= 0)
5782 basereg
= frame_base_reg
;
5783 stack
[stacki
] += frame_base_offset
;
5787 complain (&dwarf2_missing_at_frame_base
);
5793 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
]);
5798 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5803 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5808 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5813 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5818 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5823 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5828 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5834 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5839 stack
[stacki
- 1] += stack
[stacki
];
5843 case DW_OP_plus_uconst
:
5844 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5849 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5855 /* If we're not the last op, then we definitely can't encode
5856 this using GDB's address_class enum. */
5858 complain (&dwarf2_complex_location_expr
);
5862 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5863 return (stack
[stacki
]);
5866 return (stack
[stacki
]);
5869 /* memory allocation interface */
5873 dwarf2_free_tmp_obstack (ignore
)
5876 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5879 static struct dwarf_block
*
5880 dwarf_alloc_block ()
5882 struct dwarf_block
*blk
;
5884 blk
= (struct dwarf_block
*)
5885 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5889 static struct abbrev_info
*
5890 dwarf_alloc_abbrev ()
5892 struct abbrev_info
*abbrev
;
5894 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5895 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5899 static struct die_info
*
5902 struct die_info
*die
;
5904 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5905 memset (die
, 0, sizeof (struct die_info
));