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. */
34 #include "elf/dwarf2.h"
37 #include "expression.h"
40 #include "complaints.h"
43 #include "gdb_string.h"
44 #include <sys/types.h>
46 #ifndef DWARF2_REG_TO_REGNUM
47 #define DWARF2_REG_TO_REGNUM(REG) (REG)
51 /* .debug_info header for a compilation unit
52 Because of alignment constraints, this structure has padding and cannot
53 be mapped directly onto the beginning of the .debug_info section. */
54 typedef struct comp_unit_header
56 unsigned int length
; /* length of the .debug_info
58 unsigned short version
; /* version number -- 2 for DWARF
60 unsigned int abbrev_offset
; /* offset into .debug_abbrev section */
61 unsigned char addr_size
; /* byte size of an address -- 4 */
64 #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11
67 /* .debug_pubnames header
68 Because of alignment constraints, this structure has padding and cannot
69 be mapped directly onto the beginning of the .debug_info section. */
70 typedef struct pubnames_header
72 unsigned int length
; /* length of the .debug_pubnames
74 unsigned char version
; /* version number -- 2 for DWARF
76 unsigned int info_offset
; /* offset into .debug_info section */
77 unsigned int info_size
; /* byte size of .debug_info section
81 #define _ACTUAL_PUBNAMES_HEADER_SIZE 13
83 /* .debug_pubnames header
84 Because of alignment constraints, this structure has padding and cannot
85 be mapped directly onto the beginning of the .debug_info section. */
86 typedef struct aranges_header
88 unsigned int length
; /* byte len of the .debug_aranges
90 unsigned short version
; /* version number -- 2 for DWARF
92 unsigned int info_offset
; /* offset into .debug_info section */
93 unsigned char addr_size
; /* byte size of an address */
94 unsigned char seg_size
; /* byte size of segment descriptor */
97 #define _ACTUAL_ARANGES_HEADER_SIZE 12
99 /* .debug_line statement program prologue
100 Because of alignment constraints, this structure has padding and cannot
101 be mapped directly onto the beginning of the .debug_info section. */
102 typedef struct statement_prologue
104 unsigned int total_length
; /* byte length of the statement
106 unsigned short version
; /* version number -- 2 for DWARF
108 unsigned int prologue_length
; /* # bytes between prologue &
110 unsigned char minimum_instruction_length
; /* byte size of
112 unsigned char default_is_stmt
; /* initial value of is_stmt
115 unsigned char line_range
;
116 unsigned char opcode_base
; /* number assigned to first special
118 unsigned char *standard_opcode_lengths
;
122 /* offsets and sizes of debugging sections */
124 static file_ptr dwarf_info_offset
;
125 static file_ptr dwarf_abbrev_offset
;
126 static file_ptr dwarf_line_offset
;
127 static file_ptr dwarf_pubnames_offset
;
128 static file_ptr dwarf_aranges_offset
;
129 static file_ptr dwarf_loc_offset
;
130 static file_ptr dwarf_macinfo_offset
;
131 static file_ptr dwarf_str_offset
;
133 static unsigned int dwarf_info_size
;
134 static unsigned int dwarf_abbrev_size
;
135 static unsigned int dwarf_line_size
;
136 static unsigned int dwarf_pubnames_size
;
137 static unsigned int dwarf_aranges_size
;
138 static unsigned int dwarf_loc_size
;
139 static unsigned int dwarf_macinfo_size
;
140 static unsigned int dwarf_str_size
;
142 /* names of the debugging sections */
144 #define INFO_SECTION ".debug_info"
145 #define ABBREV_SECTION ".debug_abbrev"
146 #define LINE_SECTION ".debug_line"
147 #define PUBNAMES_SECTION ".debug_pubnames"
148 #define ARANGES_SECTION ".debug_aranges"
149 #define LOC_SECTION ".debug_loc"
150 #define MACINFO_SECTION ".debug_macinfo"
151 #define STR_SECTION ".debug_str"
153 /* local data types */
155 /* The data in a compilation unit header, after target2host
156 translation, looks like this. */
157 struct comp_unit_head
159 unsigned long length
;
161 unsigned int abbrev_offset
;
162 unsigned char addr_size
;
163 unsigned char signed_addr_p
;
164 unsigned int offset_size
; /* size of file offsets; either 4 or 8 */
165 unsigned int initial_length_size
; /* size of the length field; either
169 /* The data in the .debug_line statement prologue looks like this. */
172 unsigned int total_length
;
173 unsigned short version
;
174 unsigned int prologue_length
;
175 unsigned char minimum_instruction_length
;
176 unsigned char default_is_stmt
;
178 unsigned char line_range
;
179 unsigned char opcode_base
;
180 unsigned char *standard_opcode_lengths
;
183 /* When we construct a partial symbol table entry we only
184 need this much information. */
185 struct partial_die_info
188 unsigned char has_children
;
189 unsigned char is_external
;
190 unsigned char is_declaration
;
191 unsigned char has_type
;
197 struct dwarf_block
*locdesc
;
198 unsigned int language
;
202 /* This data structure holds the information of an abbrev. */
205 unsigned int number
; /* number identifying abbrev */
206 enum dwarf_tag tag
; /* dwarf tag */
207 int has_children
; /* boolean */
208 unsigned int num_attrs
; /* number of attributes */
209 struct attr_abbrev
*attrs
; /* an array of attribute descriptions */
210 struct abbrev_info
*next
; /* next in chain */
215 enum dwarf_attribute name
;
216 enum dwarf_form form
;
219 /* This data structure holds a complete die structure. */
222 enum dwarf_tag tag
; /* Tag indicating type of die */
223 unsigned short has_children
; /* Does the die have children */
224 unsigned int abbrev
; /* Abbrev number */
225 unsigned int offset
; /* Offset in .debug_info section */
226 unsigned int num_attrs
; /* Number of attributes */
227 struct attribute
*attrs
; /* An array of attributes */
228 struct die_info
*next_ref
; /* Next die in ref hash table */
229 struct die_info
*next
; /* Next die in linked list */
230 struct type
*type
; /* Cached type information */
233 /* Attributes have a name and a value */
236 enum dwarf_attribute name
;
237 enum dwarf_form form
;
241 struct dwarf_block
*blk
;
249 /* Get at parts of an attribute structure */
251 #define DW_STRING(attr) ((attr)->u.str)
252 #define DW_UNSND(attr) ((attr)->u.unsnd)
253 #define DW_BLOCK(attr) ((attr)->u.blk)
254 #define DW_SND(attr) ((attr)->u.snd)
255 #define DW_ADDR(attr) ((attr)->u.addr)
257 /* Blocks are a bunch of untyped bytes. */
264 /* We only hold one compilation unit's abbrevs in
265 memory at any one time. */
266 #ifndef ABBREV_HASH_SIZE
267 #define ABBREV_HASH_SIZE 121
269 #ifndef ATTR_ALLOC_CHUNK
270 #define ATTR_ALLOC_CHUNK 4
273 static struct abbrev_info
*dwarf2_abbrevs
[ABBREV_HASH_SIZE
];
275 /* A hash table of die offsets for following references. */
276 #ifndef REF_HASH_SIZE
277 #define REF_HASH_SIZE 1021
280 static struct die_info
*die_ref_table
[REF_HASH_SIZE
];
282 /* Obstack for allocating temporary storage used during symbol reading. */
283 static struct obstack dwarf2_tmp_obstack
;
285 /* Offset to the first byte of the current compilation unit header,
286 for resolving relative reference dies. */
287 static unsigned int cu_header_offset
;
289 /* Allocate fields for structs, unions and enums in this size. */
290 #ifndef DW_FIELD_ALLOC_CHUNK
291 #define DW_FIELD_ALLOC_CHUNK 4
294 /* The language we are debugging. */
295 static enum language cu_language
;
296 static const struct language_defn
*cu_language_defn
;
298 /* Actually data from the sections. */
299 static char *dwarf_info_buffer
;
300 static char *dwarf_abbrev_buffer
;
301 static char *dwarf_line_buffer
;
303 /* A zeroed version of a partial die for initialization purposes. */
304 static struct partial_die_info zeroed_partial_die
;
306 /* The generic symbol table building routines have separate lists for
307 file scope symbols and all all other scopes (local scopes). So
308 we need to select the right one to pass to add_symbol_to_list().
309 We do it by keeping a pointer to the correct list in list_in_scope.
311 FIXME: The original dwarf code just treated the file scope as the first
312 local scope, and all other local scopes as nested local scopes, and worked
313 fine. Check to see if we really need to distinguish these
315 static struct pending
**list_in_scope
= &file_symbols
;
317 /* FIXME: decode_locdesc sets these variables to describe the location
318 to the caller. These ought to be a structure or something. If
319 none of the flags are set, the object lives at the address returned
320 by decode_locdesc. */
322 static int optimized_out
; /* No ops in location in expression,
323 so object was optimized out. */
324 static int isreg
; /* Object lives in register.
325 decode_locdesc's return value is
326 the register number. */
327 static int offreg
; /* Object's address is the sum of the
328 register specified by basereg, plus
329 the offset returned. */
330 static int basereg
; /* See `offreg'. */
331 static int isderef
; /* Value described by flags above is
332 the address of a pointer to the object. */
333 static int islocal
; /* Variable is at the returned offset
334 from the frame start, but there's
335 no identified frame pointer for
336 this function, so we can't say
337 which register it's relative to;
340 /* DW_AT_frame_base values for the current function.
341 frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it
342 contains the register number for the frame register.
343 frame_base_offset is the offset from the frame register to the
344 virtual stack frame. */
345 static int frame_base_reg
;
346 static CORE_ADDR frame_base_offset
;
348 /* This value is added to each symbol value. FIXME: Generalize to
349 the section_offsets structure used by dbxread (once this is done,
350 pass the appropriate section number to end_symtab). */
351 static CORE_ADDR baseaddr
; /* Add to each symbol value */
353 /* We put a pointer to this structure in the read_symtab_private field
355 The complete dwarf information for an objfile is kept in the
356 psymbol_obstack, so that absolute die references can be handled.
357 Most of the information in this structure is related to an entire
358 object file and could be passed via the sym_private field of the objfile.
359 It is however conceivable that dwarf2 might not be the only type
360 of symbols read from an object file. */
364 /* Pointer to start of dwarf info buffer for the objfile. */
366 char *dwarf_info_buffer
;
368 /* Offset in dwarf_info_buffer for this compilation unit. */
370 unsigned long dwarf_info_offset
;
372 /* Pointer to start of dwarf abbreviation buffer for the objfile. */
374 char *dwarf_abbrev_buffer
;
376 /* Size of dwarf abbreviation section for the objfile. */
378 unsigned int dwarf_abbrev_size
;
380 /* Pointer to start of dwarf line buffer for the objfile. */
382 char *dwarf_line_buffer
;
385 #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private)
386 #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer)
387 #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset)
388 #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer)
389 #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size)
390 #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer)
392 /* Maintain an array of referenced fundamental types for the current
393 compilation unit being read. For DWARF version 1, we have to construct
394 the fundamental types on the fly, since no information about the
395 fundamental types is supplied. Each such fundamental type is created by
396 calling a language dependent routine to create the type, and then a
397 pointer to that type is then placed in the array at the index specified
398 by it's FT_<TYPENAME> value. The array has a fixed size set by the
399 FT_NUM_MEMBERS compile time constant, which is the number of predefined
400 fundamental types gdb knows how to construct. */
401 static struct type
*ftypes
[FT_NUM_MEMBERS
]; /* Fundamental types */
403 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
404 but this would require a corresponding change in unpack_field_as_long
406 static int bits_per_byte
= 8;
408 /* The routines that read and process dies for a C struct or C++ class
409 pass lists of data member fields and lists of member function fields
410 in an instance of a field_info structure, as defined below. */
413 /* List of data member and baseclasses fields. */
416 struct nextfield
*next
;
423 /* Number of fields. */
426 /* Number of baseclasses. */
429 /* Set if the accesibility of one of the fields is not public. */
430 int non_public_fields
;
432 /* Member function fields array, entries are allocated in the order they
433 are encountered in the object file. */
436 struct nextfnfield
*next
;
437 struct fn_field fnfield
;
441 /* Member function fieldlist array, contains name of possibly overloaded
442 member function, number of overloaded member functions and a pointer
443 to the head of the member function field chain. */
448 struct nextfnfield
*head
;
452 /* Number of entries in the fnfieldlists array. */
456 /* FIXME: Kludge to mark a varargs function type for C++ member function
457 argument processing. */
458 #define TYPE_FLAG_VARARGS (1 << 10)
460 /* Dwarf2 has no clean way to discern C++ static and non-static member
461 functions. G++ helps GDB by marking the first parameter for non-static
462 member functions (which is the this pointer) as artificial.
463 We pass this information between dwarf2_add_member_fn and
464 read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
465 #define TYPE_FIELD_ARTIFICIAL TYPE_FIELD_BITPOS
467 /* Various complaints about symbol reading that don't abort the process */
469 static struct complaint dwarf2_const_ignored
=
471 "type qualifier 'const' ignored", 0, 0
473 static struct complaint dwarf2_volatile_ignored
=
475 "type qualifier 'volatile' ignored", 0, 0
477 static struct complaint dwarf2_non_const_array_bound_ignored
=
479 "non-constant array bounds form '%s' ignored", 0, 0
481 static struct complaint dwarf2_missing_line_number_section
=
483 "missing .debug_line section", 0, 0
485 static struct complaint dwarf2_mangled_line_number_section
=
487 "mangled .debug_line section", 0, 0
489 static struct complaint dwarf2_unsupported_die_ref_attr
=
491 "unsupported die ref attribute form: '%s'", 0, 0
493 static struct complaint dwarf2_unsupported_stack_op
=
495 "unsupported stack op: '%s'", 0, 0
497 static struct complaint dwarf2_complex_location_expr
=
499 "location expression too complex", 0, 0
501 static struct complaint dwarf2_unsupported_tag
=
503 "unsupported tag: '%s'", 0, 0
505 static struct complaint dwarf2_unsupported_at_encoding
=
507 "unsupported DW_AT_encoding: '%s'", 0, 0
509 static struct complaint dwarf2_unsupported_at_frame_base
=
511 "unsupported DW_AT_frame_base for function '%s'", 0, 0
513 static struct complaint dwarf2_unexpected_tag
=
515 "unexepected tag in read_type_die: '%s'", 0, 0
517 static struct complaint dwarf2_missing_at_frame_base
=
519 "DW_AT_frame_base missing for DW_OP_fbreg", 0, 0
521 static struct complaint dwarf2_bad_static_member_name
=
523 "unrecognized static data member name '%s'", 0, 0
525 static struct complaint dwarf2_unsupported_accessibility
=
527 "unsupported accessibility %d", 0, 0
529 static struct complaint dwarf2_bad_member_name_complaint
=
531 "cannot extract member name from '%s'", 0, 0
533 static struct complaint dwarf2_missing_member_fn_type_complaint
=
535 "member function type missing for '%s'", 0, 0
537 static struct complaint dwarf2_vtbl_not_found_complaint
=
539 "virtual function table pointer not found when defining class '%s'", 0, 0
541 static struct complaint dwarf2_absolute_sibling_complaint
=
543 "ignoring absolute DW_AT_sibling", 0, 0
545 static struct complaint dwarf2_const_value_length_mismatch
=
547 "const value length mismatch for '%s', got %d, expected %d", 0, 0
549 static struct complaint dwarf2_unsupported_const_value_attr
=
551 "unsupported const value attribute form: '%s'", 0, 0
554 /* Externals references. */
555 extern int info_verbose
; /* From main.c; nonzero => verbose */
557 /* local function prototypes */
559 static void dwarf2_locate_sections (bfd
*, asection
*, PTR
);
562 static void dwarf2_build_psymtabs_easy (struct objfile
*, int);
565 static void dwarf2_build_psymtabs_hard (struct objfile
*, int);
567 static char *scan_partial_symbols (char *, struct objfile
*,
568 CORE_ADDR
*, CORE_ADDR
*,
569 const struct comp_unit_head
*);
571 static void add_partial_symbol (struct partial_die_info
*, struct objfile
*,
572 const struct comp_unit_head
*);
574 static void dwarf2_psymtab_to_symtab (struct partial_symtab
*);
576 static void psymtab_to_symtab_1 (struct partial_symtab
*);
578 static char *dwarf2_read_section (struct objfile
*, file_ptr
, unsigned int);
580 static void dwarf2_read_abbrevs (bfd
*, unsigned int);
582 static void dwarf2_empty_abbrev_table (PTR
);
584 static struct abbrev_info
*dwarf2_lookup_abbrev (unsigned int);
586 static char *read_partial_die (struct partial_die_info
*,
587 bfd
*, char *, int *,
588 const struct comp_unit_head
*);
590 static char *read_full_die (struct die_info
**, bfd
*, char *,
591 const struct comp_unit_head
*);
593 static char *read_attribute (struct attribute
*, struct attr_abbrev
*,
594 bfd
*, char *, const struct comp_unit_head
*);
596 static unsigned int read_1_byte (bfd
*, char *);
598 static int read_1_signed_byte (bfd
*, char *);
600 static unsigned int read_2_bytes (bfd
*, char *);
602 static unsigned int read_4_bytes (bfd
*, char *);
604 static unsigned long read_8_bytes (bfd
*, char *);
606 static CORE_ADDR
read_address (bfd
*, char *ptr
, const struct comp_unit_head
*,
609 static LONGEST
read_initial_length (bfd
*, char *,
610 struct comp_unit_head
*, int *bytes_read
);
612 static LONGEST
read_offset (bfd
*, char *, const struct comp_unit_head
*,
615 static char *read_n_bytes (bfd
*, char *, unsigned int);
617 static char *read_string (bfd
*, char *, unsigned int *);
619 static unsigned long read_unsigned_leb128 (bfd
*, char *, unsigned int *);
621 static long read_signed_leb128 (bfd
*, char *, unsigned int *);
623 static void set_cu_language (unsigned int);
625 static struct attribute
*dwarf_attr (struct die_info
*, unsigned int);
627 static int die_is_declaration (struct die_info
*);
629 static void dwarf_decode_lines (unsigned int, char *, bfd
*,
630 const struct comp_unit_head
*);
632 static void dwarf2_start_subfile (char *, char *);
634 static struct symbol
*new_symbol (struct die_info
*, struct type
*,
635 struct objfile
*, const struct comp_unit_head
*);
637 static void dwarf2_const_value (struct attribute
*, struct symbol
*,
638 struct objfile
*, const struct comp_unit_head
*);
640 static void dwarf2_const_value_data (struct attribute
*attr
,
644 static struct type
*die_type (struct die_info
*, struct objfile
*,
645 const struct comp_unit_head
*);
647 static struct type
*die_containing_type (struct die_info
*, struct objfile
*,
648 const struct comp_unit_head
*);
651 static struct type
*type_at_offset (unsigned int, struct objfile
*);
654 static struct type
*tag_type_to_type (struct die_info
*, struct objfile
*,
655 const struct comp_unit_head
*);
657 static void read_type_die (struct die_info
*, struct objfile
*,
658 const struct comp_unit_head
*);
660 static void read_typedef (struct die_info
*, struct objfile
*,
661 const struct comp_unit_head
*);
663 static void read_base_type (struct die_info
*, struct objfile
*);
665 static void read_file_scope (struct die_info
*, struct objfile
*,
666 const struct comp_unit_head
*);
668 static void read_func_scope (struct die_info
*, struct objfile
*,
669 const struct comp_unit_head
*);
671 static void read_lexical_block_scope (struct die_info
*, struct objfile
*,
672 const struct comp_unit_head
*);
674 static int dwarf2_get_pc_bounds (struct die_info
*,
675 CORE_ADDR
*, CORE_ADDR
*, struct objfile
*);
677 static void dwarf2_add_field (struct field_info
*, struct die_info
*,
678 struct objfile
*, const struct comp_unit_head
*);
680 static void dwarf2_attach_fields_to_type (struct field_info
*,
681 struct type
*, struct objfile
*);
683 static void dwarf2_add_member_fn (struct field_info
*,
684 struct die_info
*, struct type
*,
685 struct objfile
*objfile
,
686 const struct comp_unit_head
*);
688 static void dwarf2_attach_fn_fields_to_type (struct field_info
*,
689 struct type
*, struct objfile
*);
691 static void read_structure_scope (struct die_info
*, struct objfile
*,
692 const struct comp_unit_head
*);
694 static void read_common_block (struct die_info
*, struct objfile
*,
695 const struct comp_unit_head
*);
697 static void read_enumeration (struct die_info
*, struct objfile
*,
698 const struct comp_unit_head
*);
700 static struct type
*dwarf_base_type (int, int, struct objfile
*);
702 static CORE_ADDR
decode_locdesc (struct dwarf_block
*, struct objfile
*,
703 const struct comp_unit_head
*);
705 static void read_array_type (struct die_info
*, struct objfile
*,
706 const struct comp_unit_head
*);
708 static void read_tag_pointer_type (struct die_info
*, struct objfile
*,
709 const struct comp_unit_head
*);
711 static void read_tag_ptr_to_member_type (struct die_info
*, struct objfile
*,
712 const struct comp_unit_head
*);
714 static void read_tag_reference_type (struct die_info
*, struct objfile
*,
715 const struct comp_unit_head
*);
717 static void read_tag_const_type (struct die_info
*, struct objfile
*,
718 const struct comp_unit_head
*);
720 static void read_tag_volatile_type (struct die_info
*, struct objfile
*,
721 const struct comp_unit_head
*);
723 static void read_tag_string_type (struct die_info
*, struct objfile
*);
725 static void read_subroutine_type (struct die_info
*, struct objfile
*,
726 const struct comp_unit_head
*);
728 struct die_info
*read_comp_unit (char *, bfd
*, const struct comp_unit_head
*);
730 static void free_die_list (struct die_info
*);
732 static struct cleanup
*make_cleanup_free_die_list (struct die_info
*);
734 static void process_die (struct die_info
*, struct objfile
*,
735 const struct comp_unit_head
*);
737 static char *dwarf2_linkage_name (struct die_info
*);
739 static char *dwarf_tag_name (unsigned int);
741 static char *dwarf_attr_name (unsigned int);
743 static char *dwarf_form_name (unsigned int);
745 static char *dwarf_stack_op_name (unsigned int);
747 static char *dwarf_bool_name (unsigned int);
749 static char *dwarf_type_encoding_name (unsigned int);
752 static char *dwarf_cfi_name (unsigned int);
754 struct die_info
*copy_die (struct die_info
*);
757 struct die_info
*sibling_die (struct die_info
*);
759 void dump_die (struct die_info
*);
761 void dump_die_list (struct die_info
*);
763 void store_in_ref_table (unsigned int, struct die_info
*);
765 static void dwarf2_empty_hash_tables (void);
767 static unsigned int dwarf2_get_ref_die_offset (struct attribute
*);
769 struct die_info
*follow_die_ref (unsigned int);
771 static struct type
*dwarf2_fundamental_type (struct objfile
*, int);
773 /* memory allocation interface */
775 static void dwarf2_free_tmp_obstack (PTR
);
777 static struct dwarf_block
*dwarf_alloc_block (void);
779 static struct abbrev_info
*dwarf_alloc_abbrev (void);
781 static struct die_info
*dwarf_alloc_die (void);
783 /* Try to locate the sections we need for DWARF 2 debugging
784 information and return true if we have enough to do something. */
787 dwarf2_has_info (bfd
*abfd
)
789 dwarf_info_offset
= dwarf_abbrev_offset
= dwarf_line_offset
= 0;
790 bfd_map_over_sections (abfd
, dwarf2_locate_sections
, NULL
);
791 if (dwarf_info_offset
&& dwarf_abbrev_offset
)
801 /* This function is mapped across the sections and remembers the
802 offset and size of each of the debugging sections we are interested
806 dwarf2_locate_sections (bfd
*ignore_abfd
, asection
*sectp
, PTR ignore_ptr
)
808 if (STREQ (sectp
->name
, INFO_SECTION
))
810 dwarf_info_offset
= sectp
->filepos
;
811 dwarf_info_size
= bfd_get_section_size_before_reloc (sectp
);
813 else if (STREQ (sectp
->name
, ABBREV_SECTION
))
815 dwarf_abbrev_offset
= sectp
->filepos
;
816 dwarf_abbrev_size
= bfd_get_section_size_before_reloc (sectp
);
818 else if (STREQ (sectp
->name
, LINE_SECTION
))
820 dwarf_line_offset
= sectp
->filepos
;
821 dwarf_line_size
= bfd_get_section_size_before_reloc (sectp
);
823 else if (STREQ (sectp
->name
, PUBNAMES_SECTION
))
825 dwarf_pubnames_offset
= sectp
->filepos
;
826 dwarf_pubnames_size
= bfd_get_section_size_before_reloc (sectp
);
828 else if (STREQ (sectp
->name
, ARANGES_SECTION
))
830 dwarf_aranges_offset
= sectp
->filepos
;
831 dwarf_aranges_size
= bfd_get_section_size_before_reloc (sectp
);
833 else if (STREQ (sectp
->name
, LOC_SECTION
))
835 dwarf_loc_offset
= sectp
->filepos
;
836 dwarf_loc_size
= bfd_get_section_size_before_reloc (sectp
);
838 else if (STREQ (sectp
->name
, MACINFO_SECTION
))
840 dwarf_macinfo_offset
= sectp
->filepos
;
841 dwarf_macinfo_size
= bfd_get_section_size_before_reloc (sectp
);
843 else if (STREQ (sectp
->name
, STR_SECTION
))
845 dwarf_str_offset
= sectp
->filepos
;
846 dwarf_str_size
= bfd_get_section_size_before_reloc (sectp
);
850 /* Build a partial symbol table. */
853 dwarf2_build_psymtabs (struct objfile
*objfile
, int mainline
)
856 /* We definitely need the .debug_info and .debug_abbrev sections */
858 dwarf_info_buffer
= dwarf2_read_section (objfile
,
861 dwarf_abbrev_buffer
= dwarf2_read_section (objfile
,
864 dwarf_line_buffer
= dwarf2_read_section (objfile
,
868 if (mainline
|| objfile
->global_psymbols
.size
== 0 ||
869 objfile
->static_psymbols
.size
== 0)
871 init_psymbol_list (objfile
, 1024);
875 if (dwarf_aranges_offset
&& dwarf_pubnames_offset
)
877 /* Things are significantly easier if we have .debug_aranges and
878 .debug_pubnames sections */
880 dwarf2_build_psymtabs_easy (objfile
, mainline
);
884 /* only test this case for now */
886 /* In this case we have to work a bit harder */
887 dwarf2_build_psymtabs_hard (objfile
, mainline
);
892 /* Build the partial symbol table from the information in the
893 .debug_pubnames and .debug_aranges sections. */
896 dwarf2_build_psymtabs_easy (struct objfile
*objfile
, int mainline
)
898 bfd
*abfd
= objfile
->obfd
;
899 char *aranges_buffer
, *pubnames_buffer
;
900 char *aranges_ptr
, *pubnames_ptr
;
901 unsigned int entry_length
, version
, info_offset
, info_size
;
903 pubnames_buffer
= dwarf2_read_section (objfile
,
904 dwarf_pubnames_offset
,
905 dwarf_pubnames_size
);
906 pubnames_ptr
= pubnames_buffer
;
907 while ((pubnames_ptr
- pubnames_buffer
) < dwarf_pubnames_size
)
909 struct comp_unit_head cu_header
;
912 entry_length
= read_initial_length (abfd
, pubnames_ptr
, &cu_header
,
914 pubnames_ptr
+= bytes_read
;
915 version
= read_1_byte (abfd
, pubnames_ptr
);
917 info_offset
= read_4_bytes (abfd
, pubnames_ptr
);
919 info_size
= read_4_bytes (abfd
, pubnames_ptr
);
923 aranges_buffer
= dwarf2_read_section (objfile
,
924 dwarf_aranges_offset
,
930 /* Read in the comp unit header information from the debug_info at
934 read_comp_unit_head (struct comp_unit_head
*cu_header
,
935 char *info_ptr
, bfd
*abfd
)
939 cu_header
->length
= read_initial_length (abfd
, info_ptr
, cu_header
,
941 info_ptr
+= bytes_read
;
942 cu_header
->version
= read_2_bytes (abfd
, info_ptr
);
944 cu_header
->abbrev_offset
= read_offset (abfd
, info_ptr
, cu_header
,
946 info_ptr
+= bytes_read
;
947 cu_header
->addr_size
= read_1_byte (abfd
, info_ptr
);
949 signed_addr
= bfd_get_sign_extend_vma (abfd
);
951 internal_error ("read_comp_unit_head: dwarf from non elf file");
952 cu_header
->signed_addr_p
= signed_addr
;
956 /* Build the partial symbol table by doing a quick pass through the
957 .debug_info and .debug_abbrev sections. */
960 dwarf2_build_psymtabs_hard (struct objfile
*objfile
, int mainline
)
962 /* Instead of reading this into a big buffer, we should probably use
963 mmap() on architectures that support it. (FIXME) */
964 bfd
*abfd
= objfile
->obfd
;
965 char *info_ptr
, *abbrev_ptr
;
966 char *beg_of_comp_unit
;
967 struct partial_die_info comp_unit_die
;
968 struct partial_symtab
*pst
;
969 struct cleanup
*back_to
;
970 int comp_unit_has_pc_info
;
971 CORE_ADDR lowpc
, highpc
;
973 info_ptr
= dwarf_info_buffer
;
974 abbrev_ptr
= dwarf_abbrev_buffer
;
976 obstack_init (&dwarf2_tmp_obstack
);
977 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
979 while ((unsigned int) (info_ptr
- dwarf_info_buffer
)
980 + ((info_ptr
- dwarf_info_buffer
) % 4) < dwarf_info_size
)
982 struct comp_unit_head cu_header
;
983 beg_of_comp_unit
= info_ptr
;
984 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
986 if (cu_header
.version
!= 2)
988 error ("Dwarf Error: wrong version in compilation unit header.");
991 if (cu_header
.abbrev_offset
>= dwarf_abbrev_size
)
993 error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6).",
994 (long) cu_header
.abbrev_offset
,
995 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
998 if (beg_of_comp_unit
+ cu_header
.length
+ cu_header
.initial_length_size
999 > dwarf_info_buffer
+ dwarf_info_size
)
1001 error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0).",
1002 (long) cu_header
.length
,
1003 (long) (beg_of_comp_unit
- dwarf_info_buffer
));
1006 /* Read the abbrevs for this compilation unit into a table */
1007 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1008 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1010 /* Read the compilation unit die */
1011 info_ptr
= read_partial_die (&comp_unit_die
, abfd
, info_ptr
,
1012 &comp_unit_has_pc_info
, &cu_header
);
1014 /* Set the language we're debugging */
1015 set_cu_language (comp_unit_die
.language
);
1017 /* Allocate a new partial symbol table structure */
1018 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
1019 comp_unit_die
.name
? comp_unit_die
.name
: "",
1020 comp_unit_die
.lowpc
,
1021 objfile
->global_psymbols
.next
,
1022 objfile
->static_psymbols
.next
);
1024 pst
->read_symtab_private
= (char *)
1025 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct dwarf2_pinfo
));
1026 cu_header_offset
= beg_of_comp_unit
- dwarf_info_buffer
;
1027 DWARF_INFO_BUFFER (pst
) = dwarf_info_buffer
;
1028 DWARF_INFO_OFFSET (pst
) = beg_of_comp_unit
- dwarf_info_buffer
;
1029 DWARF_ABBREV_BUFFER (pst
) = dwarf_abbrev_buffer
;
1030 DWARF_ABBREV_SIZE (pst
) = dwarf_abbrev_size
;
1031 DWARF_LINE_BUFFER (pst
) = dwarf_line_buffer
;
1032 baseaddr
= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
1034 /* Store the function that reads in the rest of the symbol table */
1035 pst
->read_symtab
= dwarf2_psymtab_to_symtab
;
1037 /* Check if comp unit has_children.
1038 If so, read the rest of the partial symbols from this comp unit.
1039 If not, there's no more debug_info for this comp unit. */
1040 if (comp_unit_die
.has_children
)
1042 info_ptr
= scan_partial_symbols (info_ptr
, objfile
, &lowpc
, &highpc
,
1045 /* If the compilation unit didn't have an explicit address range,
1046 then use the information extracted from its child dies. */
1047 if (!comp_unit_has_pc_info
)
1049 comp_unit_die
.lowpc
= lowpc
;
1050 comp_unit_die
.highpc
= highpc
;
1053 pst
->textlow
= comp_unit_die
.lowpc
+ baseaddr
;
1054 pst
->texthigh
= comp_unit_die
.highpc
+ baseaddr
;
1056 pst
->n_global_syms
= objfile
->global_psymbols
.next
-
1057 (objfile
->global_psymbols
.list
+ pst
->globals_offset
);
1058 pst
->n_static_syms
= objfile
->static_psymbols
.next
-
1059 (objfile
->static_psymbols
.list
+ pst
->statics_offset
);
1060 sort_pst_symbols (pst
);
1062 /* If there is already a psymtab or symtab for a file of this
1063 name, remove it. (If there is a symtab, more drastic things
1064 also happen.) This happens in VxWorks. */
1065 free_named_symtabs (pst
->filename
);
1067 info_ptr
= beg_of_comp_unit
+ cu_header
.length
1068 + cu_header
.initial_length_size
;
1070 do_cleanups (back_to
);
1073 /* Read in all interesting dies to the end of the compilation unit. */
1076 scan_partial_symbols (char *info_ptr
, struct objfile
*objfile
,
1077 CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1078 const struct comp_unit_head
*cu_header
)
1080 bfd
*abfd
= objfile
->obfd
;
1081 struct partial_die_info pdi
;
1083 /* This function is called after we've read in the comp_unit_die in
1084 order to read its children. We start the nesting level at 1 since
1085 we have pushed 1 level down in order to read the comp unit's children.
1086 The comp unit itself is at level 0, so we stop reading when we pop
1087 back to that level. */
1089 int nesting_level
= 1;
1092 *lowpc
= ((CORE_ADDR
) -1);
1093 *highpc
= ((CORE_ADDR
) 0);
1095 while (nesting_level
)
1097 info_ptr
= read_partial_die (&pdi
, abfd
, info_ptr
,
1098 &has_pc_info
, cu_header
);
1104 case DW_TAG_subprogram
:
1107 if (pdi
.lowpc
< *lowpc
)
1111 if (pdi
.highpc
> *highpc
)
1113 *highpc
= pdi
.highpc
;
1115 if ((pdi
.is_external
|| nesting_level
== 1)
1116 && !pdi
.is_declaration
)
1118 add_partial_symbol (&pdi
, objfile
, cu_header
);
1122 case DW_TAG_variable
:
1123 case DW_TAG_typedef
:
1124 case DW_TAG_class_type
:
1125 case DW_TAG_structure_type
:
1126 case DW_TAG_union_type
:
1127 case DW_TAG_enumeration_type
:
1128 if ((pdi
.is_external
|| nesting_level
== 1)
1129 && !pdi
.is_declaration
)
1131 add_partial_symbol (&pdi
, objfile
, cu_header
);
1134 case DW_TAG_enumerator
:
1135 /* File scope enumerators are added to the partial symbol
1137 if (nesting_level
== 2)
1138 add_partial_symbol (&pdi
, objfile
, cu_header
);
1140 case DW_TAG_base_type
:
1141 /* File scope base type definitions are added to the partial
1143 if (nesting_level
== 1)
1144 add_partial_symbol (&pdi
, objfile
, cu_header
);
1151 /* If the die has a sibling, skip to the sibling.
1152 Do not skip enumeration types, we want to record their
1154 if (pdi
.sibling
&& pdi
.tag
!= DW_TAG_enumeration_type
)
1156 info_ptr
= pdi
.sibling
;
1158 else if (pdi
.has_children
)
1160 /* Die has children, but the optional DW_AT_sibling attribute
1171 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1172 from `maint check'. */
1173 if (*lowpc
== ((CORE_ADDR
) -1))
1179 add_partial_symbol (struct partial_die_info
*pdi
, struct objfile
*objfile
,
1180 const struct comp_unit_head
*cu_header
)
1186 case DW_TAG_subprogram
:
1187 if (pdi
->is_external
)
1189 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1190 mst_text, objfile); */
1191 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1192 VAR_NAMESPACE
, LOC_BLOCK
,
1193 &objfile
->global_psymbols
,
1194 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1198 /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr,
1199 mst_file_text, objfile); */
1200 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1201 VAR_NAMESPACE
, LOC_BLOCK
,
1202 &objfile
->static_psymbols
,
1203 0, pdi
->lowpc
+ baseaddr
, cu_language
, objfile
);
1206 case DW_TAG_variable
:
1207 if (pdi
->is_external
)
1210 Don't enter into the minimal symbol tables as there is
1211 a minimal symbol table entry from the ELF symbols already.
1212 Enter into partial symbol table if it has a location
1213 descriptor or a type.
1214 If the location descriptor is missing, new_symbol will create
1215 a LOC_UNRESOLVED symbol, the address of the variable will then
1216 be determined from the minimal symbol table whenever the variable
1218 The address for the partial symbol table entry is not
1219 used by GDB, but it comes in handy for debugging partial symbol
1223 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1224 if (pdi
->locdesc
|| pdi
->has_type
)
1225 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1226 VAR_NAMESPACE
, LOC_STATIC
,
1227 &objfile
->global_psymbols
,
1228 0, addr
+ baseaddr
, cu_language
, objfile
);
1232 /* Static Variable. Skip symbols without location descriptors. */
1233 if (pdi
->locdesc
== NULL
)
1235 addr
= decode_locdesc (pdi
->locdesc
, objfile
, cu_header
);
1236 /*prim_record_minimal_symbol (pdi->name, addr + baseaddr,
1237 mst_file_data, objfile); */
1238 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1239 VAR_NAMESPACE
, LOC_STATIC
,
1240 &objfile
->static_psymbols
,
1241 0, addr
+ baseaddr
, cu_language
, objfile
);
1244 case DW_TAG_typedef
:
1245 case DW_TAG_base_type
:
1246 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1247 VAR_NAMESPACE
, LOC_TYPEDEF
,
1248 &objfile
->static_psymbols
,
1249 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1251 case DW_TAG_class_type
:
1252 case DW_TAG_structure_type
:
1253 case DW_TAG_union_type
:
1254 case DW_TAG_enumeration_type
:
1255 /* Skip aggregate types without children, these are external
1257 if (pdi
->has_children
== 0)
1259 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1260 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1261 &objfile
->static_psymbols
,
1262 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1264 if (cu_language
== language_cplus
)
1266 /* For C++, these implicitly act as typedefs as well. */
1267 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1268 VAR_NAMESPACE
, LOC_TYPEDEF
,
1269 &objfile
->static_psymbols
,
1270 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1273 case DW_TAG_enumerator
:
1274 add_psymbol_to_list (pdi
->name
, strlen (pdi
->name
),
1275 VAR_NAMESPACE
, LOC_CONST
,
1276 &objfile
->static_psymbols
,
1277 0, (CORE_ADDR
) 0, cu_language
, objfile
);
1284 /* Expand this partial symbol table into a full symbol table. */
1287 dwarf2_psymtab_to_symtab (struct partial_symtab
*pst
)
1289 /* FIXME: This is barely more than a stub. */
1294 warning ("bug: psymtab for %s is already read in.", pst
->filename
);
1300 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
1301 gdb_flush (gdb_stdout
);
1304 psymtab_to_symtab_1 (pst
);
1306 /* Finish up the debug error message. */
1308 printf_filtered ("done.\n");
1314 psymtab_to_symtab_1 (struct partial_symtab
*pst
)
1316 struct objfile
*objfile
= pst
->objfile
;
1317 bfd
*abfd
= objfile
->obfd
;
1318 struct comp_unit_head cu_header
;
1319 struct die_info
*dies
;
1320 unsigned long offset
;
1321 CORE_ADDR lowpc
, highpc
;
1322 struct die_info
*child_die
;
1324 struct symtab
*symtab
;
1325 struct cleanup
*back_to
;
1327 /* Set local variables from the partial symbol table info. */
1328 offset
= DWARF_INFO_OFFSET (pst
);
1329 dwarf_info_buffer
= DWARF_INFO_BUFFER (pst
);
1330 dwarf_abbrev_buffer
= DWARF_ABBREV_BUFFER (pst
);
1331 dwarf_abbrev_size
= DWARF_ABBREV_SIZE (pst
);
1332 dwarf_line_buffer
= DWARF_LINE_BUFFER (pst
);
1333 baseaddr
= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (objfile
));
1334 cu_header_offset
= offset
;
1335 info_ptr
= dwarf_info_buffer
+ offset
;
1337 obstack_init (&dwarf2_tmp_obstack
);
1338 back_to
= make_cleanup (dwarf2_free_tmp_obstack
, NULL
);
1341 make_cleanup (really_free_pendings
, NULL
);
1343 /* read in the comp_unit header */
1344 info_ptr
= read_comp_unit_head (&cu_header
, info_ptr
, abfd
);
1346 /* Read the abbrevs for this compilation unit */
1347 dwarf2_read_abbrevs (abfd
, cu_header
.abbrev_offset
);
1348 make_cleanup (dwarf2_empty_abbrev_table
, NULL
);
1350 dies
= read_comp_unit (info_ptr
, abfd
, &cu_header
);
1352 make_cleanup_free_die_list (dies
);
1354 /* Do line number decoding in read_file_scope () */
1355 process_die (dies
, objfile
, &cu_header
);
1357 if (!dwarf2_get_pc_bounds (dies
, &lowpc
, &highpc
, objfile
))
1359 /* Some compilers don't define a DW_AT_high_pc attribute for
1360 the compilation unit. If the DW_AT_high_pc is missing,
1361 synthesize it, by scanning the DIE's below the compilation unit. */
1363 if (dies
->has_children
)
1365 child_die
= dies
->next
;
1366 while (child_die
&& child_die
->tag
)
1368 if (child_die
->tag
== DW_TAG_subprogram
)
1370 CORE_ADDR low
, high
;
1372 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1374 highpc
= max (highpc
, high
);
1377 child_die
= sibling_die (child_die
);
1381 symtab
= end_symtab (highpc
+ baseaddr
, objfile
, SECT_OFF_TEXT (objfile
));
1383 /* Set symtab language to language from DW_AT_language.
1384 If the compilation is from a C file generated by language preprocessors,
1385 do not set the language if it was already deduced by start_subfile. */
1387 && !(cu_language
== language_c
&& symtab
->language
!= language_c
))
1389 symtab
->language
= cu_language
;
1391 pst
->symtab
= symtab
;
1393 sort_symtab_syms (pst
->symtab
);
1395 do_cleanups (back_to
);
1398 /* Process a die and its children. */
1401 process_die (struct die_info
*die
, struct objfile
*objfile
,
1402 const struct comp_unit_head
*cu_header
)
1406 case DW_TAG_padding
:
1408 case DW_TAG_compile_unit
:
1409 read_file_scope (die
, objfile
, cu_header
);
1411 case DW_TAG_subprogram
:
1412 read_subroutine_type (die
, objfile
, cu_header
);
1413 read_func_scope (die
, objfile
, cu_header
);
1415 case DW_TAG_inlined_subroutine
:
1416 /* FIXME: These are ignored for now.
1417 They could be used to set breakpoints on all inlined instances
1418 of a function and make GDB `next' properly over inlined functions. */
1420 case DW_TAG_lexical_block
:
1421 read_lexical_block_scope (die
, objfile
, cu_header
);
1423 case DW_TAG_class_type
:
1424 case DW_TAG_structure_type
:
1425 case DW_TAG_union_type
:
1426 read_structure_scope (die
, objfile
, cu_header
);
1428 case DW_TAG_enumeration_type
:
1429 read_enumeration (die
, objfile
, cu_header
);
1431 case DW_TAG_subroutine_type
:
1432 read_subroutine_type (die
, objfile
, cu_header
);
1434 case DW_TAG_array_type
:
1435 read_array_type (die
, objfile
, cu_header
);
1437 case DW_TAG_pointer_type
:
1438 read_tag_pointer_type (die
, objfile
, cu_header
);
1440 case DW_TAG_ptr_to_member_type
:
1441 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
1443 case DW_TAG_reference_type
:
1444 read_tag_reference_type (die
, objfile
, cu_header
);
1446 case DW_TAG_string_type
:
1447 read_tag_string_type (die
, objfile
);
1449 case DW_TAG_base_type
:
1450 read_base_type (die
, objfile
);
1451 if (dwarf_attr (die
, DW_AT_name
))
1453 /* Add a typedef symbol for the base type definition. */
1454 new_symbol (die
, die
->type
, objfile
, cu_header
);
1457 case DW_TAG_common_block
:
1458 read_common_block (die
, objfile
, cu_header
);
1460 case DW_TAG_common_inclusion
:
1463 new_symbol (die
, NULL
, objfile
, cu_header
);
1469 read_file_scope (struct die_info
*die
, struct objfile
*objfile
,
1470 const struct comp_unit_head
*cu_header
)
1472 unsigned int line_offset
= 0;
1473 CORE_ADDR lowpc
= ((CORE_ADDR
) -1);
1474 CORE_ADDR highpc
= ((CORE_ADDR
) 0);
1475 struct attribute
*attr
;
1476 char *name
= "<unknown>";
1477 char *comp_dir
= NULL
;
1478 struct die_info
*child_die
;
1479 bfd
*abfd
= objfile
->obfd
;
1481 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1483 if (die
->has_children
)
1485 child_die
= die
->next
;
1486 while (child_die
&& child_die
->tag
)
1488 if (child_die
->tag
== DW_TAG_subprogram
)
1490 CORE_ADDR low
, high
;
1492 if (dwarf2_get_pc_bounds (child_die
, &low
, &high
, objfile
))
1494 lowpc
= min (lowpc
, low
);
1495 highpc
= max (highpc
, high
);
1498 child_die
= sibling_die (child_die
);
1503 /* If we didn't find a lowpc, set it to highpc to avoid complaints
1504 from finish_block. */
1505 if (lowpc
== ((CORE_ADDR
) -1))
1510 attr
= dwarf_attr (die
, DW_AT_name
);
1513 name
= DW_STRING (attr
);
1515 attr
= dwarf_attr (die
, DW_AT_comp_dir
);
1518 comp_dir
= DW_STRING (attr
);
1521 /* Irix 6.2 native cc prepends <machine>.: to the compilation
1522 directory, get rid of it. */
1523 char *cp
= strchr (comp_dir
, ':');
1525 if (cp
&& cp
!= comp_dir
&& cp
[-1] == '.' && cp
[1] == '/')
1530 if (objfile
->ei
.entry_point
>= lowpc
&&
1531 objfile
->ei
.entry_point
< highpc
)
1533 objfile
->ei
.entry_file_lowpc
= lowpc
;
1534 objfile
->ei
.entry_file_highpc
= highpc
;
1537 attr
= dwarf_attr (die
, DW_AT_language
);
1540 set_cu_language (DW_UNSND (attr
));
1543 /* We assume that we're processing GCC output. */
1544 processing_gcc_compilation
= 2;
1546 /* FIXME:Do something here. */
1547 if (dip
->at_producer
!= NULL
)
1549 handle_producer (dip
->at_producer
);
1553 /* The compilation unit may be in a different language or objfile,
1554 zero out all remembered fundamental types. */
1555 memset (ftypes
, 0, FT_NUM_MEMBERS
* sizeof (struct type
*));
1557 start_symtab (name
, comp_dir
, lowpc
);
1558 record_debugformat ("DWARF 2");
1560 /* Decode line number information if present. */
1561 attr
= dwarf_attr (die
, DW_AT_stmt_list
);
1564 line_offset
= DW_UNSND (attr
);
1565 dwarf_decode_lines (line_offset
, comp_dir
, abfd
, cu_header
);
1568 /* Process all dies in compilation unit. */
1569 if (die
->has_children
)
1571 child_die
= die
->next
;
1572 while (child_die
&& child_die
->tag
)
1574 process_die (child_die
, objfile
, cu_header
);
1575 child_die
= sibling_die (child_die
);
1581 read_func_scope (struct die_info
*die
, struct objfile
*objfile
,
1582 const struct comp_unit_head
*cu_header
)
1584 register struct context_stack
*new;
1587 struct die_info
*child_die
;
1588 struct attribute
*attr
;
1591 name
= dwarf2_linkage_name (die
);
1593 /* Ignore functions with missing or empty names and functions with
1594 missing or invalid low and high pc attributes. */
1595 if (name
== NULL
|| !dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1601 if (objfile
->ei
.entry_point
>= lowpc
&&
1602 objfile
->ei
.entry_point
< highpc
)
1604 objfile
->ei
.entry_func_lowpc
= lowpc
;
1605 objfile
->ei
.entry_func_highpc
= highpc
;
1608 /* Decode DW_AT_frame_base location descriptor if present, keep result
1609 for DW_OP_fbreg operands in decode_locdesc. */
1610 frame_base_reg
= -1;
1611 frame_base_offset
= 0;
1612 attr
= dwarf_attr (die
, DW_AT_frame_base
);
1615 CORE_ADDR addr
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
1617 complain (&dwarf2_unsupported_at_frame_base
, name
);
1619 frame_base_reg
= addr
;
1622 frame_base_reg
= basereg
;
1623 frame_base_offset
= addr
;
1626 complain (&dwarf2_unsupported_at_frame_base
, name
);
1629 new = push_context (0, lowpc
);
1630 new->name
= new_symbol (die
, die
->type
, objfile
, cu_header
);
1631 list_in_scope
= &local_symbols
;
1633 if (die
->has_children
)
1635 child_die
= die
->next
;
1636 while (child_die
&& child_die
->tag
)
1638 process_die (child_die
, objfile
, cu_header
);
1639 child_die
= sibling_die (child_die
);
1643 new = pop_context ();
1644 /* Make a block for the local symbols within. */
1645 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1646 lowpc
, highpc
, objfile
);
1647 list_in_scope
= &file_symbols
;
1650 /* Process all the DIES contained within a lexical block scope. Start
1651 a new scope, process the dies, and then close the scope. */
1654 read_lexical_block_scope (struct die_info
*die
, struct objfile
*objfile
,
1655 const struct comp_unit_head
*cu_header
)
1657 register struct context_stack
*new;
1658 CORE_ADDR lowpc
, highpc
;
1659 struct die_info
*child_die
;
1661 /* Ignore blocks with missing or invalid low and high pc attributes. */
1662 if (!dwarf2_get_pc_bounds (die
, &lowpc
, &highpc
, objfile
))
1667 push_context (0, lowpc
);
1668 if (die
->has_children
)
1670 child_die
= die
->next
;
1671 while (child_die
&& child_die
->tag
)
1673 process_die (child_die
, objfile
, cu_header
);
1674 child_die
= sibling_die (child_die
);
1677 new = pop_context ();
1679 if (local_symbols
!= NULL
)
1681 finish_block (0, &local_symbols
, new->old_blocks
, new->start_addr
,
1684 local_symbols
= new->locals
;
1687 /* Get low and high pc attributes from a die.
1688 Return 1 if the attributes are present and valid, otherwise, return 0. */
1691 dwarf2_get_pc_bounds (struct die_info
*die
, CORE_ADDR
*lowpc
, CORE_ADDR
*highpc
,
1692 struct objfile
*objfile
)
1694 struct attribute
*attr
;
1698 attr
= dwarf_attr (die
, DW_AT_low_pc
);
1700 low
= DW_ADDR (attr
);
1703 attr
= dwarf_attr (die
, DW_AT_high_pc
);
1705 high
= DW_ADDR (attr
);
1712 /* When using the GNU linker, .gnu.linkonce. sections are used to
1713 eliminate duplicate copies of functions and vtables and such.
1714 The linker will arbitrarily choose one and discard the others.
1715 The AT_*_pc values for such functions refer to local labels in
1716 these sections. If the section from that file was discarded, the
1717 labels are not in the output, so the relocs get a value of 0.
1718 If this is a discarded function, mark the pc bounds as invalid,
1719 so that GDB will ignore it. */
1720 if (low
== 0 && (bfd_get_file_flags (objfile
->obfd
) & HAS_RELOC
) == 0)
1728 /* Add an aggregate field to the field list. */
1731 dwarf2_add_field (struct field_info
*fip
, struct die_info
*die
,
1732 struct objfile
*objfile
,
1733 const struct comp_unit_head
*cu_header
)
1735 struct nextfield
*new_field
;
1736 struct attribute
*attr
;
1738 char *fieldname
= "";
1740 /* Allocate a new field list entry and link it in. */
1741 new_field
= (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1742 make_cleanup (xfree
, new_field
);
1743 memset (new_field
, 0, sizeof (struct nextfield
));
1744 new_field
->next
= fip
->fields
;
1745 fip
->fields
= new_field
;
1748 /* Handle accessibility and virtuality of field.
1749 The default accessibility for members is public, the default
1750 accessibility for inheritance is private. */
1751 if (die
->tag
!= DW_TAG_inheritance
)
1752 new_field
->accessibility
= DW_ACCESS_public
;
1754 new_field
->accessibility
= DW_ACCESS_private
;
1755 new_field
->virtuality
= DW_VIRTUALITY_none
;
1757 attr
= dwarf_attr (die
, DW_AT_accessibility
);
1759 new_field
->accessibility
= DW_UNSND (attr
);
1760 if (new_field
->accessibility
!= DW_ACCESS_public
)
1761 fip
->non_public_fields
= 1;
1762 attr
= dwarf_attr (die
, DW_AT_virtuality
);
1764 new_field
->virtuality
= DW_UNSND (attr
);
1766 fp
= &new_field
->field
;
1767 if (die
->tag
== DW_TAG_member
)
1769 /* Get type of field. */
1770 fp
->type
= die_type (die
, objfile
, cu_header
);
1772 /* Get bit size of field (zero if none). */
1773 attr
= dwarf_attr (die
, DW_AT_bit_size
);
1776 FIELD_BITSIZE (*fp
) = DW_UNSND (attr
);
1780 FIELD_BITSIZE (*fp
) = 0;
1783 /* Get bit offset of field. */
1784 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1787 FIELD_BITPOS (*fp
) =
1788 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) * bits_per_byte
;
1791 FIELD_BITPOS (*fp
) = 0;
1792 attr
= dwarf_attr (die
, DW_AT_bit_offset
);
1795 if (BITS_BIG_ENDIAN
)
1797 /* For big endian bits, the DW_AT_bit_offset gives the
1798 additional bit offset from the MSB of the containing
1799 anonymous object to the MSB of the field. We don't
1800 have to do anything special since we don't need to
1801 know the size of the anonymous object. */
1802 FIELD_BITPOS (*fp
) += DW_UNSND (attr
);
1806 /* For little endian bits, compute the bit offset to the
1807 MSB of the anonymous object, subtract off the number of
1808 bits from the MSB of the field to the MSB of the
1809 object, and then subtract off the number of bits of
1810 the field itself. The result is the bit offset of
1811 the LSB of the field. */
1813 int bit_offset
= DW_UNSND (attr
);
1815 attr
= dwarf_attr (die
, DW_AT_byte_size
);
1818 /* The size of the anonymous object containing
1819 the bit field is explicit, so use the
1820 indicated size (in bytes). */
1821 anonymous_size
= DW_UNSND (attr
);
1825 /* The size of the anonymous object containing
1826 the bit field must be inferred from the type
1827 attribute of the data member containing the
1829 anonymous_size
= TYPE_LENGTH (fp
->type
);
1831 FIELD_BITPOS (*fp
) += anonymous_size
* bits_per_byte
1832 - bit_offset
- FIELD_BITSIZE (*fp
);
1836 /* Get name of field. */
1837 attr
= dwarf_attr (die
, DW_AT_name
);
1838 if (attr
&& DW_STRING (attr
))
1839 fieldname
= DW_STRING (attr
);
1840 fp
->name
= obsavestring (fieldname
, strlen (fieldname
),
1841 &objfile
->type_obstack
);
1843 /* Change accessibility for artificial fields (e.g. virtual table
1844 pointer or virtual base class pointer) to private. */
1845 if (dwarf_attr (die
, DW_AT_artificial
))
1847 new_field
->accessibility
= DW_ACCESS_private
;
1848 fip
->non_public_fields
= 1;
1851 else if (die
->tag
== DW_TAG_variable
)
1855 /* C++ static member.
1856 Get name of field. */
1857 attr
= dwarf_attr (die
, DW_AT_name
);
1858 if (attr
&& DW_STRING (attr
))
1859 fieldname
= DW_STRING (attr
);
1863 /* Get physical name. */
1864 physname
= dwarf2_linkage_name (die
);
1866 SET_FIELD_PHYSNAME (*fp
, obsavestring (physname
, strlen (physname
),
1867 &objfile
->type_obstack
));
1868 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1869 FIELD_NAME (*fp
) = obsavestring (fieldname
, strlen (fieldname
),
1870 &objfile
->type_obstack
);
1872 else if (die
->tag
== DW_TAG_inheritance
)
1874 /* C++ base class field. */
1875 attr
= dwarf_attr (die
, DW_AT_data_member_location
);
1877 FIELD_BITPOS (*fp
) = (decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
)
1879 FIELD_BITSIZE (*fp
) = 0;
1880 FIELD_TYPE (*fp
) = die_type (die
, objfile
, cu_header
);
1881 FIELD_NAME (*fp
) = type_name_no_tag (fp
->type
);
1882 fip
->nbaseclasses
++;
1886 /* Create the vector of fields, and attach it to the type. */
1889 dwarf2_attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
1890 struct objfile
*objfile
)
1892 int nfields
= fip
->nfields
;
1894 /* Record the field count, allocate space for the array of fields,
1895 and create blank accessibility bitfields if necessary. */
1896 TYPE_NFIELDS (type
) = nfields
;
1897 TYPE_FIELDS (type
) = (struct field
*)
1898 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1899 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1901 if (fip
->non_public_fields
)
1903 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1905 TYPE_FIELD_PRIVATE_BITS (type
) =
1906 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1907 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1909 TYPE_FIELD_PROTECTED_BITS (type
) =
1910 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1911 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1913 TYPE_FIELD_IGNORE_BITS (type
) =
1914 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
1915 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
1918 /* If the type has baseclasses, allocate and clear a bit vector for
1919 TYPE_FIELD_VIRTUAL_BITS. */
1920 if (fip
->nbaseclasses
)
1922 int num_bytes
= B_BYTES (fip
->nbaseclasses
);
1925 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1926 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1927 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1928 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), fip
->nbaseclasses
);
1929 TYPE_N_BASECLASSES (type
) = fip
->nbaseclasses
;
1932 /* Copy the saved-up fields into the field vector. Start from the head
1933 of the list, adding to the tail of the field array, so that they end
1934 up in the same order in the array in which they were added to the list. */
1935 while (nfields
-- > 0)
1937 TYPE_FIELD (type
, nfields
) = fip
->fields
->field
;
1938 switch (fip
->fields
->accessibility
)
1940 case DW_ACCESS_private
:
1941 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
1944 case DW_ACCESS_protected
:
1945 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
1948 case DW_ACCESS_public
:
1952 /* Unknown accessibility. Complain and treat it as public. */
1954 complain (&dwarf2_unsupported_accessibility
,
1955 fip
->fields
->accessibility
);
1959 if (nfields
< fip
->nbaseclasses
)
1961 switch (fip
->fields
->virtuality
)
1963 case DW_VIRTUALITY_virtual
:
1964 case DW_VIRTUALITY_pure_virtual
:
1965 SET_TYPE_FIELD_VIRTUAL (type
, nfields
);
1969 fip
->fields
= fip
->fields
->next
;
1973 /* Add a member function to the proper fieldlist. */
1976 dwarf2_add_member_fn (struct field_info
*fip
, struct die_info
*die
,
1977 struct type
*type
, struct objfile
*objfile
,
1978 const struct comp_unit_head
*cu_header
)
1980 struct attribute
*attr
;
1981 struct fnfieldlist
*flp
;
1983 struct fn_field
*fnp
;
1986 struct nextfnfield
*new_fnfield
;
1988 /* Get name of member function. */
1989 attr
= dwarf_attr (die
, DW_AT_name
);
1990 if (attr
&& DW_STRING (attr
))
1991 fieldname
= DW_STRING (attr
);
1995 /* Get the mangled name. */
1996 physname
= dwarf2_linkage_name (die
);
1998 /* Look up member function name in fieldlist. */
1999 for (i
= 0; i
< fip
->nfnfields
; i
++)
2001 if (STREQ (fip
->fnfieldlists
[i
].name
, fieldname
))
2005 /* Create new list element if necessary. */
2006 if (i
< fip
->nfnfields
)
2007 flp
= &fip
->fnfieldlists
[i
];
2010 if ((fip
->nfnfields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2012 fip
->fnfieldlists
= (struct fnfieldlist
*)
2013 xrealloc (fip
->fnfieldlists
,
2014 (fip
->nfnfields
+ DW_FIELD_ALLOC_CHUNK
)
2015 * sizeof (struct fnfieldlist
));
2016 if (fip
->nfnfields
== 0)
2017 make_cleanup (free_current_contents
, &fip
->fnfieldlists
);
2019 flp
= &fip
->fnfieldlists
[fip
->nfnfields
];
2020 flp
->name
= fieldname
;
2026 /* Create a new member function field and chain it to the field list
2028 new_fnfield
= (struct nextfnfield
*) xmalloc (sizeof (struct nextfnfield
));
2029 make_cleanup (xfree
, new_fnfield
);
2030 memset (new_fnfield
, 0, sizeof (struct nextfnfield
));
2031 new_fnfield
->next
= flp
->head
;
2032 flp
->head
= new_fnfield
;
2035 /* Fill in the member function field info. */
2036 fnp
= &new_fnfield
->fnfield
;
2037 fnp
->physname
= obsavestring (physname
, strlen (physname
),
2038 &objfile
->type_obstack
);
2039 fnp
->type
= alloc_type (objfile
);
2040 if (die
->type
&& TYPE_CODE (die
->type
) == TYPE_CODE_FUNC
)
2042 struct type
*return_type
= TYPE_TARGET_TYPE (die
->type
);
2043 struct type
**arg_types
;
2044 int nparams
= TYPE_NFIELDS (die
->type
);
2047 /* Copy argument types from the subroutine type. */
2048 arg_types
= (struct type
**)
2049 TYPE_ALLOC (fnp
->type
, (nparams
+ 1) * sizeof (struct type
*));
2050 for (iparams
= 0; iparams
< nparams
; iparams
++)
2051 arg_types
[iparams
] = TYPE_FIELD_TYPE (die
->type
, iparams
);
2053 /* Set last entry in argument type vector. */
2054 if (TYPE_FLAGS (die
->type
) & TYPE_FLAG_VARARGS
)
2055 arg_types
[nparams
] = NULL
;
2057 arg_types
[nparams
] = dwarf2_fundamental_type (objfile
, FT_VOID
);
2059 smash_to_method_type (fnp
->type
, type
, return_type
, arg_types
);
2061 /* Handle static member functions.
2062 Dwarf2 has no clean way to discern C++ static and non-static
2063 member functions. G++ helps GDB by marking the first
2064 parameter for non-static member functions (which is the
2065 this pointer) as artificial. We obtain this information
2066 from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */
2067 if (nparams
== 0 || TYPE_FIELD_ARTIFICIAL (die
->type
, 0) == 0)
2068 fnp
->voffset
= VOFFSET_STATIC
;
2071 complain (&dwarf2_missing_member_fn_type_complaint
, physname
);
2073 /* Get fcontext from DW_AT_containing_type if present. */
2074 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2075 fnp
->fcontext
= die_containing_type (die
, objfile
, cu_header
);
2077 /* dwarf2 doesn't have stubbed physical names, so the setting of is_const
2078 and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */
2080 /* Get accessibility. */
2081 attr
= dwarf_attr (die
, DW_AT_accessibility
);
2084 switch (DW_UNSND (attr
))
2086 case DW_ACCESS_private
:
2087 fnp
->is_private
= 1;
2089 case DW_ACCESS_protected
:
2090 fnp
->is_protected
= 1;
2095 /* Get index in virtual function table if it is a virtual member function. */
2096 attr
= dwarf_attr (die
, DW_AT_vtable_elem_location
);
2098 fnp
->voffset
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
) + 2;
2101 /* Create the vector of member function fields, and attach it to the type. */
2104 dwarf2_attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
,
2105 struct objfile
*objfile
)
2107 struct fnfieldlist
*flp
;
2108 int total_length
= 0;
2111 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2112 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2113 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * fip
->nfnfields
);
2115 for (i
= 0, flp
= fip
->fnfieldlists
; i
< fip
->nfnfields
; i
++, flp
++)
2117 struct nextfnfield
*nfp
= flp
->head
;
2118 struct fn_fieldlist
*fn_flp
= &TYPE_FN_FIELDLIST (type
, i
);
2121 TYPE_FN_FIELDLIST_NAME (type
, i
) = flp
->name
;
2122 TYPE_FN_FIELDLIST_LENGTH (type
, i
) = flp
->length
;
2123 fn_flp
->fn_fields
= (struct fn_field
*)
2124 TYPE_ALLOC (type
, sizeof (struct fn_field
) * flp
->length
);
2125 for (k
= flp
->length
; (k
--, nfp
); nfp
= nfp
->next
)
2126 fn_flp
->fn_fields
[k
] = nfp
->fnfield
;
2128 total_length
+= flp
->length
;
2131 TYPE_NFN_FIELDS (type
) = fip
->nfnfields
;
2132 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2135 /* Called when we find the DIE that starts a structure or union scope
2136 (definition) to process all dies that define the members of the
2139 NOTE: we need to call struct_type regardless of whether or not the
2140 DIE has an at_name attribute, since it might be an anonymous
2141 structure or union. This gets the type entered into our set of
2144 However, if the structure is incomplete (an opaque struct/union)
2145 then suppress creating a symbol table entry for it since gdb only
2146 wants to find the one with the complete definition. Note that if
2147 it is complete, we just call new_symbol, which does it's own
2148 checking about whether the struct/union is anonymous or not (and
2149 suppresses creating a symbol table entry itself). */
2152 read_structure_scope (struct die_info
*die
, struct objfile
*objfile
,
2153 const struct comp_unit_head
*cu_header
)
2156 struct attribute
*attr
;
2158 type
= alloc_type (objfile
);
2160 INIT_CPLUS_SPECIFIC (type
);
2161 attr
= dwarf_attr (die
, DW_AT_name
);
2162 if (attr
&& DW_STRING (attr
))
2164 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2165 strlen (DW_STRING (attr
)),
2166 &objfile
->type_obstack
);
2169 if (die
->tag
== DW_TAG_structure_type
)
2171 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2173 else if (die
->tag
== DW_TAG_union_type
)
2175 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2179 /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT
2181 TYPE_CODE (type
) = TYPE_CODE_CLASS
;
2184 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2187 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2191 TYPE_LENGTH (type
) = 0;
2194 /* We need to add the type field to the die immediately so we don't
2195 infinitely recurse when dealing with pointers to the structure
2196 type within the structure itself. */
2199 if (die
->has_children
&& ! die_is_declaration (die
))
2201 struct field_info fi
;
2202 struct die_info
*child_die
;
2203 struct cleanup
*back_to
= make_cleanup (null_cleanup
, NULL
);
2205 memset (&fi
, 0, sizeof (struct field_info
));
2207 child_die
= die
->next
;
2209 while (child_die
&& child_die
->tag
)
2211 if (child_die
->tag
== DW_TAG_member
)
2213 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2215 else if (child_die
->tag
== DW_TAG_variable
)
2217 /* C++ static member. */
2218 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2220 else if (child_die
->tag
== DW_TAG_subprogram
)
2222 /* C++ member function. */
2223 process_die (child_die
, objfile
, cu_header
);
2224 dwarf2_add_member_fn (&fi
, child_die
, type
, objfile
, cu_header
);
2226 else if (child_die
->tag
== DW_TAG_inheritance
)
2228 /* C++ base class field. */
2229 dwarf2_add_field (&fi
, child_die
, objfile
, cu_header
);
2233 process_die (child_die
, objfile
, cu_header
);
2235 child_die
= sibling_die (child_die
);
2238 /* Attach fields and member functions to the type. */
2240 dwarf2_attach_fields_to_type (&fi
, type
, objfile
);
2243 dwarf2_attach_fn_fields_to_type (&fi
, type
, objfile
);
2245 /* Get the type which refers to the base class (possibly this
2246 class itself) which contains the vtable pointer for the current
2247 class from the DW_AT_containing_type attribute. */
2249 if (dwarf_attr (die
, DW_AT_containing_type
) != NULL
)
2251 struct type
*t
= die_containing_type (die
, objfile
, cu_header
);
2253 TYPE_VPTR_BASETYPE (type
) = t
;
2256 static const char vptr_name
[] =
2257 {'_', 'v', 'p', 't', 'r', '\0'};
2260 /* Our own class provides vtbl ptr. */
2261 for (i
= TYPE_NFIELDS (t
) - 1;
2262 i
>= TYPE_N_BASECLASSES (t
);
2265 char *fieldname
= TYPE_FIELD_NAME (t
, i
);
2267 if (STREQN (fieldname
, vptr_name
, strlen (vptr_name
) - 1)
2268 && is_cplus_marker (fieldname
[strlen (vptr_name
)]))
2270 TYPE_VPTR_FIELDNO (type
) = i
;
2275 /* Complain if virtual function table field not found. */
2276 if (i
< TYPE_N_BASECLASSES (t
))
2277 complain (&dwarf2_vtbl_not_found_complaint
,
2278 TYPE_TAG_NAME (type
) ? TYPE_TAG_NAME (type
) : "");
2282 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2287 new_symbol (die
, type
, objfile
, cu_header
);
2289 do_cleanups (back_to
);
2293 /* No children, must be stub. */
2294 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2300 /* Given a pointer to a die which begins an enumeration, process all
2301 the dies that define the members of the enumeration.
2303 This will be much nicer in draft 6 of the DWARF spec when our
2304 members will be dies instead squished into the DW_AT_element_list
2307 NOTE: We reverse the order of the element list. */
2310 read_enumeration (struct die_info
*die
, struct objfile
*objfile
,
2311 const struct comp_unit_head
*cu_header
)
2313 struct die_info
*child_die
;
2315 struct field
*fields
;
2316 struct attribute
*attr
;
2319 int unsigned_enum
= 1;
2321 type
= alloc_type (objfile
);
2323 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2324 attr
= dwarf_attr (die
, DW_AT_name
);
2325 if (attr
&& DW_STRING (attr
))
2327 TYPE_TAG_NAME (type
) = obsavestring (DW_STRING (attr
),
2328 strlen (DW_STRING (attr
)),
2329 &objfile
->type_obstack
);
2332 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2335 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2339 TYPE_LENGTH (type
) = 0;
2344 if (die
->has_children
)
2346 child_die
= die
->next
;
2347 while (child_die
&& child_die
->tag
)
2349 if (child_die
->tag
!= DW_TAG_enumerator
)
2351 process_die (child_die
, objfile
, cu_header
);
2355 attr
= dwarf_attr (child_die
, DW_AT_name
);
2358 sym
= new_symbol (child_die
, type
, objfile
, cu_header
);
2359 if (SYMBOL_VALUE (sym
) < 0)
2362 if ((num_fields
% DW_FIELD_ALLOC_CHUNK
) == 0)
2364 fields
= (struct field
*)
2366 (num_fields
+ DW_FIELD_ALLOC_CHUNK
)
2367 * sizeof (struct field
));
2370 FIELD_NAME (fields
[num_fields
]) = SYMBOL_NAME (sym
);
2371 FIELD_TYPE (fields
[num_fields
]) = NULL
;
2372 FIELD_BITPOS (fields
[num_fields
]) = SYMBOL_VALUE (sym
);
2373 FIELD_BITSIZE (fields
[num_fields
]) = 0;
2379 child_die
= sibling_die (child_die
);
2384 TYPE_NFIELDS (type
) = num_fields
;
2385 TYPE_FIELDS (type
) = (struct field
*)
2386 TYPE_ALLOC (type
, sizeof (struct field
) * num_fields
);
2387 memcpy (TYPE_FIELDS (type
), fields
,
2388 sizeof (struct field
) * num_fields
);
2392 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
2395 new_symbol (die
, type
, objfile
, cu_header
);
2398 /* Extract all information from a DW_TAG_array_type DIE and put it in
2399 the DIE's type field. For now, this only handles one dimensional
2403 read_array_type (struct die_info
*die
, struct objfile
*objfile
,
2404 const struct comp_unit_head
*cu_header
)
2406 struct die_info
*child_die
;
2407 struct type
*type
= NULL
;
2408 struct type
*element_type
, *range_type
, *index_type
;
2409 struct type
**range_types
= NULL
;
2410 struct attribute
*attr
;
2412 struct cleanup
*back_to
;
2414 /* Return if we've already decoded this type. */
2420 element_type
= die_type (die
, objfile
, cu_header
);
2422 /* Irix 6.2 native cc creates array types without children for
2423 arrays with unspecified length. */
2424 if (die
->has_children
== 0)
2426 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2427 range_type
= create_range_type (NULL
, index_type
, 0, -1);
2428 die
->type
= create_array_type (NULL
, element_type
, range_type
);
2432 back_to
= make_cleanup (null_cleanup
, NULL
);
2433 child_die
= die
->next
;
2434 while (child_die
&& child_die
->tag
)
2436 if (child_die
->tag
== DW_TAG_subrange_type
)
2438 unsigned int low
, high
;
2440 /* Default bounds to an array with unspecified length. */
2443 if (cu_language
== language_fortran
)
2445 /* FORTRAN implies a lower bound of 1, if not given. */
2449 index_type
= die_type (child_die
, objfile
, cu_header
);
2450 attr
= dwarf_attr (child_die
, DW_AT_lower_bound
);
2453 if (attr
->form
== DW_FORM_sdata
)
2455 low
= DW_SND (attr
);
2457 else if (attr
->form
== DW_FORM_udata
2458 || attr
->form
== DW_FORM_data1
2459 || attr
->form
== DW_FORM_data2
2460 || attr
->form
== DW_FORM_data4
)
2462 low
= DW_UNSND (attr
);
2466 complain (&dwarf2_non_const_array_bound_ignored
,
2467 dwarf_form_name (attr
->form
));
2469 die
->type
= lookup_pointer_type (element_type
);
2476 attr
= dwarf_attr (child_die
, DW_AT_upper_bound
);
2479 if (attr
->form
== DW_FORM_sdata
)
2481 high
= DW_SND (attr
);
2483 else if (attr
->form
== DW_FORM_udata
2484 || attr
->form
== DW_FORM_data1
2485 || attr
->form
== DW_FORM_data2
2486 || attr
->form
== DW_FORM_data4
)
2488 high
= DW_UNSND (attr
);
2490 else if (attr
->form
== DW_FORM_block1
)
2492 /* GCC encodes arrays with unspecified or dynamic length
2493 with a DW_FORM_block1 attribute.
2494 FIXME: GDB does not yet know how to handle dynamic
2495 arrays properly, treat them as arrays with unspecified
2501 complain (&dwarf2_non_const_array_bound_ignored
,
2502 dwarf_form_name (attr
->form
));
2504 die
->type
= lookup_pointer_type (element_type
);
2512 /* Create a range type and save it for array type creation. */
2513 if ((ndim
% DW_FIELD_ALLOC_CHUNK
) == 0)
2515 range_types
= (struct type
**)
2516 xrealloc (range_types
, (ndim
+ DW_FIELD_ALLOC_CHUNK
)
2517 * sizeof (struct type
*));
2519 make_cleanup (free_current_contents
, &range_types
);
2521 range_types
[ndim
++] = create_range_type (NULL
, index_type
, low
, high
);
2523 child_die
= sibling_die (child_die
);
2526 /* Dwarf2 dimensions are output from left to right, create the
2527 necessary array types in backwards order. */
2528 type
= element_type
;
2530 type
= create_array_type (NULL
, type
, range_types
[ndim
]);
2532 do_cleanups (back_to
);
2534 /* Install the type in the die. */
2538 /* First cut: install each common block member as a global variable. */
2541 read_common_block (struct die_info
*die
, struct objfile
*objfile
,
2542 const struct comp_unit_head
*cu_header
)
2544 struct die_info
*child_die
;
2545 struct attribute
*attr
;
2547 CORE_ADDR base
= (CORE_ADDR
) 0;
2549 attr
= dwarf_attr (die
, DW_AT_location
);
2552 base
= decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2554 if (die
->has_children
)
2556 child_die
= die
->next
;
2557 while (child_die
&& child_die
->tag
)
2559 sym
= new_symbol (child_die
, NULL
, objfile
, cu_header
);
2560 attr
= dwarf_attr (child_die
, DW_AT_data_member_location
);
2563 SYMBOL_VALUE_ADDRESS (sym
) =
2564 base
+ decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
2565 add_symbol_to_list (sym
, &global_symbols
);
2567 child_die
= sibling_die (child_die
);
2572 /* Extract all information from a DW_TAG_pointer_type DIE and add to
2573 the user defined type vector. */
2576 read_tag_pointer_type (struct die_info
*die
, struct objfile
*objfile
,
2577 const struct comp_unit_head
*cu_header
)
2580 struct attribute
*attr
;
2587 type
= lookup_pointer_type (die_type (die
, objfile
, cu_header
));
2588 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2591 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2595 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2600 /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to
2601 the user defined type vector. */
2604 read_tag_ptr_to_member_type (struct die_info
*die
, struct objfile
*objfile
,
2605 const struct comp_unit_head
*cu_header
)
2608 struct type
*to_type
;
2609 struct type
*domain
;
2616 type
= alloc_type (objfile
);
2617 to_type
= die_type (die
, objfile
, cu_header
);
2618 domain
= die_containing_type (die
, objfile
, cu_header
);
2619 smash_to_member_type (type
, domain
, to_type
);
2624 /* Extract all information from a DW_TAG_reference_type DIE and add to
2625 the user defined type vector. */
2628 read_tag_reference_type (struct die_info
*die
, struct objfile
*objfile
,
2629 const struct comp_unit_head
*cu_header
)
2632 struct attribute
*attr
;
2639 type
= lookup_reference_type (die_type (die
, objfile
, cu_header
));
2640 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2643 TYPE_LENGTH (type
) = DW_UNSND (attr
);
2647 TYPE_LENGTH (type
) = cu_header
->addr_size
;
2653 read_tag_const_type (struct die_info
*die
, struct objfile
*objfile
,
2654 const struct comp_unit_head
*cu_header
)
2661 complain (&dwarf2_const_ignored
);
2662 die
->type
= die_type (die
, objfile
, cu_header
);
2666 read_tag_volatile_type (struct die_info
*die
, struct objfile
*objfile
,
2667 const struct comp_unit_head
*cu_header
)
2674 complain (&dwarf2_volatile_ignored
);
2675 die
->type
= die_type (die
, objfile
, cu_header
);
2678 /* Extract all information from a DW_TAG_string_type DIE and add to
2679 the user defined type vector. It isn't really a user defined type,
2680 but it behaves like one, with other DIE's using an AT_user_def_type
2681 attribute to reference it. */
2684 read_tag_string_type (struct die_info
*die
, struct objfile
*objfile
)
2686 struct type
*type
, *range_type
, *index_type
, *char_type
;
2687 struct attribute
*attr
;
2688 unsigned int length
;
2695 attr
= dwarf_attr (die
, DW_AT_string_length
);
2698 length
= DW_UNSND (attr
);
2704 index_type
= dwarf2_fundamental_type (objfile
, FT_INTEGER
);
2705 range_type
= create_range_type (NULL
, index_type
, 1, length
);
2706 char_type
= dwarf2_fundamental_type (objfile
, FT_CHAR
);
2707 type
= create_string_type (char_type
, range_type
);
2711 /* Handle DIES due to C code like:
2715 int (*funcp)(int a, long l);
2719 ('funcp' generates a DW_TAG_subroutine_type DIE)
2723 read_subroutine_type (struct die_info
*die
, struct objfile
*objfile
,
2724 const struct comp_unit_head
*cu_header
)
2726 struct type
*type
; /* Type that this function returns */
2727 struct type
*ftype
; /* Function that returns above type */
2728 struct attribute
*attr
;
2730 /* Decode the type that this subroutine returns */
2735 type
= die_type (die
, objfile
, cu_header
);
2736 ftype
= lookup_function_type (type
);
2738 /* All functions in C++ have prototypes. */
2739 attr
= dwarf_attr (die
, DW_AT_prototyped
);
2740 if ((attr
&& (DW_UNSND (attr
) != 0))
2741 || cu_language
== language_cplus
)
2742 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
2744 if (die
->has_children
)
2746 struct die_info
*child_die
;
2750 /* Count the number of parameters.
2751 FIXME: GDB currently ignores vararg functions, but knows about
2752 vararg member functions. */
2753 child_die
= die
->next
;
2754 while (child_die
&& child_die
->tag
)
2756 if (child_die
->tag
== DW_TAG_formal_parameter
)
2758 else if (child_die
->tag
== DW_TAG_unspecified_parameters
)
2759 TYPE_FLAGS (ftype
) |= TYPE_FLAG_VARARGS
;
2760 child_die
= sibling_die (child_die
);
2763 /* Allocate storage for parameters and fill them in. */
2764 TYPE_NFIELDS (ftype
) = nparams
;
2765 TYPE_FIELDS (ftype
) = (struct field
*)
2766 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
2768 child_die
= die
->next
;
2769 while (child_die
&& child_die
->tag
)
2771 if (child_die
->tag
== DW_TAG_formal_parameter
)
2773 /* Dwarf2 has no clean way to discern C++ static and non-static
2774 member functions. G++ helps GDB by marking the first
2775 parameter for non-static member functions (which is the
2776 this pointer) as artificial. We pass this information
2777 to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */
2778 attr
= dwarf_attr (child_die
, DW_AT_artificial
);
2780 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = DW_UNSND (attr
);
2782 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
2783 TYPE_FIELD_TYPE (ftype
, iparams
) = die_type (child_die
, objfile
,
2787 child_die
= sibling_die (child_die
);
2795 read_typedef (struct die_info
*die
, struct objfile
*objfile
,
2796 const struct comp_unit_head
*cu_header
)
2802 struct attribute
*attr
;
2805 xtype
= die_type (die
, objfile
, cu_header
);
2807 type
= alloc_type (objfile
);
2808 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2809 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2810 TYPE_TARGET_TYPE (type
) = xtype
;
2811 attr
= dwarf_attr (die
, DW_AT_name
);
2812 if (attr
&& DW_STRING (attr
))
2813 TYPE_NAME (type
) = obsavestring (DW_STRING (attr
),
2814 strlen (DW_STRING (attr
)),
2815 &objfile
->type_obstack
);
2821 /* Find a representation of a given base type and install
2822 it in the TYPE field of the die. */
2825 read_base_type (struct die_info
*die
, struct objfile
*objfile
)
2828 struct attribute
*attr
;
2829 int encoding
= 0, size
= 0;
2831 /* If we've already decoded this die, this is a no-op. */
2837 attr
= dwarf_attr (die
, DW_AT_encoding
);
2840 encoding
= DW_UNSND (attr
);
2842 attr
= dwarf_attr (die
, DW_AT_byte_size
);
2845 size
= DW_UNSND (attr
);
2847 attr
= dwarf_attr (die
, DW_AT_name
);
2848 if (attr
&& DW_STRING (attr
))
2850 enum type_code code
= TYPE_CODE_INT
;
2851 int is_unsigned
= 0;
2855 case DW_ATE_address
:
2856 /* Turn DW_ATE_address into a void * pointer. */
2857 code
= TYPE_CODE_PTR
;
2860 case DW_ATE_boolean
:
2861 code
= TYPE_CODE_BOOL
;
2864 case DW_ATE_complex_float
:
2865 code
= TYPE_CODE_COMPLEX
;
2868 code
= TYPE_CODE_FLT
;
2871 case DW_ATE_signed_char
:
2873 case DW_ATE_unsigned
:
2874 case DW_ATE_unsigned_char
:
2878 complain (&dwarf2_unsupported_at_encoding
,
2879 dwarf_type_encoding_name (encoding
));
2882 type
= init_type (code
, size
, is_unsigned
, DW_STRING (attr
), objfile
);
2883 if (encoding
== DW_ATE_address
)
2884 TYPE_TARGET_TYPE (type
) = dwarf2_fundamental_type (objfile
, FT_VOID
);
2888 type
= dwarf_base_type (encoding
, size
, objfile
);
2893 /* Read a whole compilation unit into a linked list of dies. */
2896 read_comp_unit (char *info_ptr
, bfd
*abfd
,
2897 const struct comp_unit_head
*cu_header
)
2899 struct die_info
*first_die
, *last_die
, *die
;
2903 /* Reset die reference table; we are
2904 building new ones now. */
2905 dwarf2_empty_hash_tables ();
2909 first_die
= last_die
= NULL
;
2912 cur_ptr
= read_full_die (&die
, abfd
, cur_ptr
, cu_header
);
2913 if (die
->has_children
)
2924 /* Enter die in reference hash table */
2925 store_in_ref_table (die
->offset
, die
);
2929 first_die
= last_die
= die
;
2933 last_die
->next
= die
;
2937 while (nesting_level
> 0);
2941 /* Free a linked list of dies. */
2944 free_die_list (struct die_info
*dies
)
2946 struct die_info
*die
, *next
;
2959 do_free_die_list_cleanup (void *dies
)
2961 free_die_list (dies
);
2964 static struct cleanup
*
2965 make_cleanup_free_die_list (struct die_info
*dies
)
2967 return make_cleanup (do_free_die_list_cleanup
, dies
);
2971 /* Read the contents of the section at OFFSET and of size SIZE from the
2972 object file specified by OBJFILE into the psymbol_obstack and return it. */
2975 dwarf2_read_section (struct objfile
*objfile
, file_ptr offset
,
2978 bfd
*abfd
= objfile
->obfd
;
2984 buf
= (char *) obstack_alloc (&objfile
->psymbol_obstack
, size
);
2985 if ((bfd_seek (abfd
, offset
, SEEK_SET
) != 0) ||
2986 (bfd_read (buf
, size
, 1, abfd
) != size
))
2989 error ("Dwarf Error: Can't read DWARF data from '%s'",
2990 bfd_get_filename (abfd
));
2995 /* In DWARF version 2, the description of the debugging information is
2996 stored in a separate .debug_abbrev section. Before we read any
2997 dies from a section we read in all abbreviations and install them
3001 dwarf2_read_abbrevs (bfd
*abfd
, unsigned int offset
)
3004 struct abbrev_info
*cur_abbrev
;
3005 unsigned int abbrev_number
, bytes_read
, abbrev_name
;
3006 unsigned int abbrev_form
, hash_number
;
3008 /* empty the table */
3009 dwarf2_empty_abbrev_table (NULL
);
3011 abbrev_ptr
= dwarf_abbrev_buffer
+ offset
;
3012 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3013 abbrev_ptr
+= bytes_read
;
3015 /* loop until we reach an abbrev number of 0 */
3016 while (abbrev_number
)
3018 cur_abbrev
= dwarf_alloc_abbrev ();
3020 /* read in abbrev header */
3021 cur_abbrev
->number
= abbrev_number
;
3022 cur_abbrev
->tag
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3023 abbrev_ptr
+= bytes_read
;
3024 cur_abbrev
->has_children
= read_1_byte (abfd
, abbrev_ptr
);
3027 /* now read in declarations */
3028 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3029 abbrev_ptr
+= bytes_read
;
3030 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3031 abbrev_ptr
+= bytes_read
;
3034 if ((cur_abbrev
->num_attrs
% ATTR_ALLOC_CHUNK
) == 0)
3036 cur_abbrev
->attrs
= (struct attr_abbrev
*)
3037 xrealloc (cur_abbrev
->attrs
,
3038 (cur_abbrev
->num_attrs
+ ATTR_ALLOC_CHUNK
)
3039 * sizeof (struct attr_abbrev
));
3041 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
].name
= abbrev_name
;
3042 cur_abbrev
->attrs
[cur_abbrev
->num_attrs
++].form
= abbrev_form
;
3043 abbrev_name
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3044 abbrev_ptr
+= bytes_read
;
3045 abbrev_form
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3046 abbrev_ptr
+= bytes_read
;
3049 hash_number
= abbrev_number
% ABBREV_HASH_SIZE
;
3050 cur_abbrev
->next
= dwarf2_abbrevs
[hash_number
];
3051 dwarf2_abbrevs
[hash_number
] = cur_abbrev
;
3053 /* Get next abbreviation.
3054 Under Irix6 the abbreviations for a compilation unit are not
3055 always properly terminated with an abbrev number of 0.
3056 Exit loop if we encounter an abbreviation which we have
3057 already read (which means we are about to read the abbreviations
3058 for the next compile unit) or if the end of the abbreviation
3059 table is reached. */
3060 if ((unsigned int) (abbrev_ptr
- dwarf_abbrev_buffer
)
3061 >= dwarf_abbrev_size
)
3063 abbrev_number
= read_unsigned_leb128 (abfd
, abbrev_ptr
, &bytes_read
);
3064 abbrev_ptr
+= bytes_read
;
3065 if (dwarf2_lookup_abbrev (abbrev_number
) != NULL
)
3070 /* Empty the abbrev table for a new compilation unit. */
3074 dwarf2_empty_abbrev_table (PTR ignore
)
3077 struct abbrev_info
*abbrev
, *next
;
3079 for (i
= 0; i
< ABBREV_HASH_SIZE
; ++i
)
3082 abbrev
= dwarf2_abbrevs
[i
];
3085 next
= abbrev
->next
;
3086 xfree (abbrev
->attrs
);
3090 dwarf2_abbrevs
[i
] = NULL
;
3094 /* Lookup an abbrev_info structure in the abbrev hash table. */
3096 static struct abbrev_info
*
3097 dwarf2_lookup_abbrev (unsigned int number
)
3099 unsigned int hash_number
;
3100 struct abbrev_info
*abbrev
;
3102 hash_number
= number
% ABBREV_HASH_SIZE
;
3103 abbrev
= dwarf2_abbrevs
[hash_number
];
3107 if (abbrev
->number
== number
)
3110 abbrev
= abbrev
->next
;
3115 /* Read a minimal amount of information into the minimal die structure. */
3118 read_partial_die (struct partial_die_info
*part_die
, bfd
*abfd
,
3119 char *info_ptr
, int *has_pc_info
,
3120 const struct comp_unit_head
*cu_header
)
3122 unsigned int abbrev_number
, bytes_read
, i
;
3123 struct abbrev_info
*abbrev
;
3124 struct attribute attr
;
3125 struct attribute spec_attr
;
3126 int found_spec_attr
= 0;
3127 int has_low_pc_attr
= 0;
3128 int has_high_pc_attr
= 0;
3130 *part_die
= zeroed_partial_die
;
3132 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3133 info_ptr
+= bytes_read
;
3137 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3140 error ("Dwarf Error: Could not find abbrev number %d.", abbrev_number
);
3142 part_die
->offset
= info_ptr
- dwarf_info_buffer
;
3143 part_die
->tag
= abbrev
->tag
;
3144 part_die
->has_children
= abbrev
->has_children
;
3145 part_die
->abbrev
= abbrev_number
;
3147 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3149 info_ptr
= read_attribute (&attr
, &abbrev
->attrs
[i
], abfd
,
3150 info_ptr
, cu_header
);
3152 /* Store the data if it is of an attribute we want to keep in a
3153 partial symbol table. */
3158 /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */
3159 if (part_die
->name
== NULL
)
3160 part_die
->name
= DW_STRING (&attr
);
3162 case DW_AT_MIPS_linkage_name
:
3163 part_die
->name
= DW_STRING (&attr
);
3166 has_low_pc_attr
= 1;
3167 part_die
->lowpc
= DW_ADDR (&attr
);
3170 has_high_pc_attr
= 1;
3171 part_die
->highpc
= DW_ADDR (&attr
);
3173 case DW_AT_location
:
3174 part_die
->locdesc
= DW_BLOCK (&attr
);
3176 case DW_AT_language
:
3177 part_die
->language
= DW_UNSND (&attr
);
3179 case DW_AT_external
:
3180 part_die
->is_external
= DW_UNSND (&attr
);
3182 case DW_AT_declaration
:
3183 part_die
->is_declaration
= DW_UNSND (&attr
);
3186 part_die
->has_type
= 1;
3188 case DW_AT_abstract_origin
:
3189 case DW_AT_specification
:
3190 found_spec_attr
= 1;
3194 /* Ignore absolute siblings, they might point outside of
3195 the current compile unit. */
3196 if (attr
.form
== DW_FORM_ref_addr
)
3197 complain (&dwarf2_absolute_sibling_complaint
);
3200 dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&attr
);
3207 /* If we found a reference attribute and the die has no name, try
3208 to find a name in the referred to die. */
3210 if (found_spec_attr
&& part_die
->name
== NULL
)
3212 struct partial_die_info spec_die
;
3216 spec_ptr
= dwarf_info_buffer
+ dwarf2_get_ref_die_offset (&spec_attr
);
3217 read_partial_die (&spec_die
, abfd
, spec_ptr
, &dummy
, cu_header
);
3220 part_die
->name
= spec_die
.name
;
3222 /* Copy DW_AT_external attribute if it is set. */
3223 if (spec_die
.is_external
)
3224 part_die
->is_external
= spec_die
.is_external
;
3228 /* When using the GNU linker, .gnu.linkonce. sections are used to
3229 eliminate duplicate copies of functions and vtables and such.
3230 The linker will arbitrarily choose one and discard the others.
3231 The AT_*_pc values for such functions refer to local labels in
3232 these sections. If the section from that file was discarded, the
3233 labels are not in the output, so the relocs get a value of 0.
3234 If this is a discarded function, mark the pc bounds as invalid,
3235 so that GDB will ignore it. */
3236 if (has_low_pc_attr
&& has_high_pc_attr
3237 && part_die
->lowpc
< part_die
->highpc
3238 && (part_die
->lowpc
!= 0
3239 || (bfd_get_file_flags (abfd
) & HAS_RELOC
)))
3244 /* Read the die from the .debug_info section buffer. And set diep to
3245 point to a newly allocated die with its information. */
3248 read_full_die (struct die_info
**diep
, bfd
*abfd
, char *info_ptr
,
3249 const struct comp_unit_head
*cu_header
)
3251 unsigned int abbrev_number
, bytes_read
, i
, offset
;
3252 struct abbrev_info
*abbrev
;
3253 struct die_info
*die
;
3255 offset
= info_ptr
- dwarf_info_buffer
;
3256 abbrev_number
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3257 info_ptr
+= bytes_read
;
3260 die
= dwarf_alloc_die ();
3262 die
->abbrev
= abbrev_number
;
3268 abbrev
= dwarf2_lookup_abbrev (abbrev_number
);
3271 error ("Dwarf Error: could not find abbrev number %d.", abbrev_number
);
3273 die
= dwarf_alloc_die ();
3274 die
->offset
= offset
;
3275 die
->tag
= abbrev
->tag
;
3276 die
->has_children
= abbrev
->has_children
;
3277 die
->abbrev
= abbrev_number
;
3280 die
->num_attrs
= abbrev
->num_attrs
;
3281 die
->attrs
= (struct attribute
*)
3282 xmalloc (die
->num_attrs
* sizeof (struct attribute
));
3284 for (i
= 0; i
< abbrev
->num_attrs
; ++i
)
3286 info_ptr
= read_attribute (&die
->attrs
[i
], &abbrev
->attrs
[i
],
3287 abfd
, info_ptr
, cu_header
);
3294 /* Read an attribute described by an abbreviated attribute. */
3297 read_attribute (struct attribute
*attr
, struct attr_abbrev
*abbrev
,
3298 bfd
*abfd
, char *info_ptr
,
3299 const struct comp_unit_head
*cu_header
)
3301 unsigned int bytes_read
;
3302 struct dwarf_block
*blk
;
3304 attr
->name
= abbrev
->name
;
3305 attr
->form
= abbrev
->form
;
3306 switch (abbrev
->form
)
3309 case DW_FORM_ref_addr
:
3310 DW_ADDR (attr
) = read_address (abfd
, info_ptr
, cu_header
, &bytes_read
);
3311 info_ptr
+= bytes_read
;
3313 case DW_FORM_block2
:
3314 blk
= dwarf_alloc_block ();
3315 blk
->size
= read_2_bytes (abfd
, info_ptr
);
3317 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3318 info_ptr
+= blk
->size
;
3319 DW_BLOCK (attr
) = blk
;
3321 case DW_FORM_block4
:
3322 blk
= dwarf_alloc_block ();
3323 blk
->size
= read_4_bytes (abfd
, info_ptr
);
3325 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3326 info_ptr
+= blk
->size
;
3327 DW_BLOCK (attr
) = blk
;
3330 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3334 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3338 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3341 case DW_FORM_string
:
3342 DW_STRING (attr
) = read_string (abfd
, info_ptr
, &bytes_read
);
3343 info_ptr
+= bytes_read
;
3346 blk
= dwarf_alloc_block ();
3347 blk
->size
= read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3348 info_ptr
+= bytes_read
;
3349 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3350 info_ptr
+= blk
->size
;
3351 DW_BLOCK (attr
) = blk
;
3353 case DW_FORM_block1
:
3354 blk
= dwarf_alloc_block ();
3355 blk
->size
= read_1_byte (abfd
, info_ptr
);
3357 blk
->data
= read_n_bytes (abfd
, info_ptr
, blk
->size
);
3358 info_ptr
+= blk
->size
;
3359 DW_BLOCK (attr
) = blk
;
3362 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3366 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3370 DW_SND (attr
) = read_signed_leb128 (abfd
, info_ptr
, &bytes_read
);
3371 info_ptr
+= bytes_read
;
3374 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3375 info_ptr
+= bytes_read
;
3378 DW_UNSND (attr
) = read_1_byte (abfd
, info_ptr
);
3382 DW_UNSND (attr
) = read_2_bytes (abfd
, info_ptr
);
3386 DW_UNSND (attr
) = read_4_bytes (abfd
, info_ptr
);
3390 DW_UNSND (attr
) = read_8_bytes (abfd
, info_ptr
);
3393 case DW_FORM_ref_udata
:
3394 DW_UNSND (attr
) = read_unsigned_leb128 (abfd
, info_ptr
, &bytes_read
);
3395 info_ptr
+= bytes_read
;
3398 case DW_FORM_indirect
:
3400 error ("Dwarf Error: Cannot handle %s in DWARF reader.",
3401 dwarf_form_name (abbrev
->form
));
3406 /* read dwarf information from a buffer */
3409 read_1_byte (bfd
*abfd
, char *buf
)
3411 return bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3415 read_1_signed_byte (bfd
*abfd
, char *buf
)
3417 return bfd_get_signed_8 (abfd
, (bfd_byte
*) buf
);
3421 read_2_bytes (bfd
*abfd
, char *buf
)
3423 return bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3427 read_2_signed_bytes (bfd
*abfd
, char *buf
)
3429 return bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3433 read_4_bytes (bfd
*abfd
, char *buf
)
3435 return bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3439 read_4_signed_bytes (bfd
*abfd
, char *buf
)
3441 return bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3444 static unsigned long
3445 read_8_bytes (bfd
*abfd
, char *buf
)
3447 return bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3451 read_address (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3454 CORE_ADDR retval
= 0;
3456 if (cu_header
->signed_addr_p
)
3458 switch (cu_header
->addr_size
)
3461 retval
= bfd_get_signed_16 (abfd
, (bfd_byte
*) buf
);
3464 retval
= bfd_get_signed_32 (abfd
, (bfd_byte
*) buf
);
3467 retval
= bfd_get_signed_64 (abfd
, (bfd_byte
*) buf
);
3470 internal_error ("read_address: bad switch, signed");
3475 switch (cu_header
->addr_size
)
3478 retval
= bfd_get_16 (abfd
, (bfd_byte
*) buf
);
3481 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3484 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3487 internal_error ("read_address: bad switch, unsigned");
3491 *bytes_read
= cu_header
->addr_size
;
3495 /* Reads the initial length from a section. The (draft) DWARF 2.1
3496 specification allows the initial length to take up either 4 bytes
3497 or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8
3498 bytes describe the length and all offsets will be 8 bytes in length
3501 The value returned via bytes_read should be used to increment
3502 the relevant pointer after calling read_initial_length().
3504 As a side effect, this function sets the fields initial_length_size
3505 and offset_size in cu_header to the values appropriate for the
3506 length field. (The format of the initial length field determines
3507 the width of file offsets to be fetched later with fetch_offset().)
3509 [ Note: read_initial_length() and read_offset() are based on the
3510 document entitled "DWARF Debugging Information Format", revision
3511 2.1, draft 4, dated July 20, 2000. This document was obtained
3514 http://reality.sgi.com/dehnert_engr/dwarf/dwarf2p1-draft4-000720.pdf
3516 This document is only a draft and is subject to change. (So beware.)
3518 - Kevin, Aug 4, 2000
3522 read_initial_length (bfd
*abfd
, char *buf
, struct comp_unit_head
*cu_header
,
3527 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3529 if (retval
== 0xffffffff)
3531 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
+ 4);
3533 if (cu_header
!= NULL
)
3535 cu_header
->initial_length_size
= 12;
3536 cu_header
->offset_size
= 8;
3542 if (cu_header
!= NULL
)
3544 cu_header
->initial_length_size
= 4;
3545 cu_header
->offset_size
= 4;
3552 /* Read an offset from the data stream. The size of the offset is
3553 given by cu_header->offset_size. */
3556 read_offset (bfd
*abfd
, char *buf
, const struct comp_unit_head
*cu_header
,
3561 switch (cu_header
->offset_size
)
3564 retval
= bfd_get_32 (abfd
, (bfd_byte
*) buf
);
3568 retval
= bfd_get_64 (abfd
, (bfd_byte
*) buf
);
3572 internal_error ("read_offset: bad switch");
3579 read_n_bytes (bfd
*abfd
, char *buf
, unsigned int size
)
3581 /* If the size of a host char is 8 bits, we can return a pointer
3582 to the buffer, otherwise we have to copy the data to a buffer
3583 allocated on the temporary obstack. */
3584 #if HOST_CHAR_BIT == 8
3590 ret
= obstack_alloc (&dwarf2_tmp_obstack
, size
);
3591 for (i
= 0; i
< size
; ++i
)
3593 ret
[i
] = bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3601 read_string (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3603 /* If the size of a host char is 8 bits, we can return a pointer
3604 to the string, otherwise we have to copy the string to a buffer
3605 allocated on the temporary obstack. */
3606 #if HOST_CHAR_BIT == 8
3609 *bytes_read_ptr
= 1;
3612 *bytes_read_ptr
= strlen (buf
) + 1;
3618 while ((byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
)) != 0)
3620 obstack_1grow (&dwarf2_tmp_obstack
, byte
);
3626 *bytes_read_ptr
= 1;
3629 obstack_1grow (&dwarf2_tmp_obstack
, '\0');
3630 *bytes_read_ptr
= i
+ 1;
3631 return obstack_finish (&dwarf2_tmp_obstack
);
3635 static unsigned long
3636 read_unsigned_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3638 unsigned long result
;
3639 unsigned int num_read
;
3649 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3652 result
|= ((unsigned long)(byte
& 127) << shift
);
3653 if ((byte
& 128) == 0)
3659 *bytes_read_ptr
= num_read
;
3664 read_signed_leb128 (bfd
*abfd
, char *buf
, unsigned int *bytes_read_ptr
)
3667 int i
, shift
, size
, num_read
;
3677 byte
= bfd_get_8 (abfd
, (bfd_byte
*) buf
);
3680 result
|= ((long)(byte
& 127) << shift
);
3682 if ((byte
& 128) == 0)
3687 if ((shift
< size
) && (byte
& 0x40))
3689 result
|= -(1 << shift
);
3691 *bytes_read_ptr
= num_read
;
3696 set_cu_language (unsigned int lang
)
3702 cu_language
= language_c
;
3704 case DW_LANG_C_plus_plus
:
3705 cu_language
= language_cplus
;
3707 case DW_LANG_Fortran77
:
3708 case DW_LANG_Fortran90
:
3709 cu_language
= language_fortran
;
3711 case DW_LANG_Mips_Assembler
:
3712 cu_language
= language_asm
;
3715 case DW_LANG_Cobol74
:
3716 case DW_LANG_Cobol85
:
3717 case DW_LANG_Pascal83
:
3718 case DW_LANG_Modula2
:
3720 cu_language
= language_unknown
;
3723 cu_language_defn
= language_def (cu_language
);
3726 /* Return the named attribute or NULL if not there. */
3728 static struct attribute
*
3729 dwarf_attr (struct die_info
*die
, unsigned int name
)
3732 struct attribute
*spec
= NULL
;
3734 for (i
= 0; i
< die
->num_attrs
; ++i
)
3736 if (die
->attrs
[i
].name
== name
)
3738 return &die
->attrs
[i
];
3740 if (die
->attrs
[i
].name
== DW_AT_specification
3741 || die
->attrs
[i
].name
== DW_AT_abstract_origin
)
3742 spec
= &die
->attrs
[i
];
3746 struct die_info
*ref_die
=
3747 follow_die_ref (dwarf2_get_ref_die_offset (spec
));
3750 return dwarf_attr (ref_die
, name
);
3757 die_is_declaration (struct die_info
*die
)
3759 return (dwarf_attr (die
, DW_AT_declaration
)
3760 && ! dwarf_attr (die
, DW_AT_specification
));
3763 /* Decode the line number information for the compilation unit whose
3764 line number info is at OFFSET in the .debug_line section.
3765 The compilation directory of the file is passed in COMP_DIR. */
3769 unsigned int num_files
;
3782 unsigned int num_dirs
;
3787 dwarf_decode_lines (unsigned int offset
, char *comp_dir
, bfd
*abfd
,
3788 const struct comp_unit_head
*cu_header
)
3792 struct line_head lh
;
3793 struct cleanup
*back_to
;
3794 unsigned int i
, bytes_read
;
3795 char *cur_file
, *cur_dir
;
3796 unsigned char op_code
, extended_op
, adj_opcode
;
3798 #define FILE_ALLOC_CHUNK 5
3799 #define DIR_ALLOC_CHUNK 5
3801 struct filenames files
;
3802 struct directories dirs
;
3804 if (dwarf_line_buffer
== NULL
)
3806 complain (&dwarf2_missing_line_number_section
);
3810 files
.num_files
= 0;
3816 line_ptr
= dwarf_line_buffer
+ offset
;
3818 /* read in the prologue */
3819 lh
.total_length
= read_initial_length (abfd
, line_ptr
, NULL
, &bytes_read
);
3820 line_ptr
+= bytes_read
;
3821 line_end
= line_ptr
+ lh
.total_length
;
3822 lh
.version
= read_2_bytes (abfd
, line_ptr
);
3824 lh
.prologue_length
= read_offset (abfd
, line_ptr
, cu_header
, &bytes_read
);
3825 line_ptr
+= bytes_read
;
3826 lh
.minimum_instruction_length
= read_1_byte (abfd
, line_ptr
);
3828 lh
.default_is_stmt
= read_1_byte (abfd
, line_ptr
);
3830 lh
.line_base
= read_1_signed_byte (abfd
, line_ptr
);
3832 lh
.line_range
= read_1_byte (abfd
, line_ptr
);
3834 lh
.opcode_base
= read_1_byte (abfd
, line_ptr
);
3836 lh
.standard_opcode_lengths
= (unsigned char *)
3837 xmalloc (lh
.opcode_base
* sizeof (unsigned char));
3838 back_to
= make_cleanup (free_current_contents
, &lh
.standard_opcode_lengths
);
3840 lh
.standard_opcode_lengths
[0] = 1;
3841 for (i
= 1; i
< lh
.opcode_base
; ++i
)
3843 lh
.standard_opcode_lengths
[i
] = read_1_byte (abfd
, line_ptr
);
3847 /* Read directory table */
3848 while ((cur_dir
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3850 line_ptr
+= bytes_read
;
3851 if ((dirs
.num_dirs
% DIR_ALLOC_CHUNK
) == 0)
3853 dirs
.dirs
= (char **)
3854 xrealloc (dirs
.dirs
,
3855 (dirs
.num_dirs
+ DIR_ALLOC_CHUNK
) * sizeof (char *));
3856 if (dirs
.num_dirs
== 0)
3857 make_cleanup (free_current_contents
, &dirs
.dirs
);
3859 dirs
.dirs
[dirs
.num_dirs
++] = cur_dir
;
3861 line_ptr
+= bytes_read
;
3863 /* Read file name table */
3864 while ((cur_file
= read_string (abfd
, line_ptr
, &bytes_read
)) != NULL
)
3866 line_ptr
+= bytes_read
;
3867 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3869 files
.files
= (struct fileinfo
*)
3870 xrealloc (files
.files
,
3871 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3872 * sizeof (struct fileinfo
));
3873 if (files
.num_files
== 0)
3874 make_cleanup (free_current_contents
, &files
.files
);
3876 files
.files
[files
.num_files
].name
= cur_file
;
3877 files
.files
[files
.num_files
].dir
=
3878 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3879 line_ptr
+= bytes_read
;
3880 files
.files
[files
.num_files
].time
=
3881 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3882 line_ptr
+= bytes_read
;
3883 files
.files
[files
.num_files
].size
=
3884 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3885 line_ptr
+= bytes_read
;
3888 line_ptr
+= bytes_read
;
3890 /* Read the statement sequences until there's nothing left. */
3891 while (line_ptr
< line_end
)
3893 /* state machine registers */
3894 CORE_ADDR address
= 0;
3895 unsigned int file
= 1;
3896 unsigned int line
= 1;
3897 unsigned int column
= 0;
3898 int is_stmt
= lh
.default_is_stmt
;
3899 int basic_block
= 0;
3900 int end_sequence
= 0;
3902 /* Start a subfile for the current file of the state machine. */
3903 if (files
.num_files
>= file
)
3905 /* The file and directory tables are 0 based, the references
3907 dwarf2_start_subfile (files
.files
[file
- 1].name
,
3908 (files
.files
[file
- 1].dir
3909 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3913 /* Decode the table. */
3914 while (!end_sequence
)
3916 op_code
= read_1_byte (abfd
, line_ptr
);
3920 case DW_LNS_extended_op
:
3921 line_ptr
+= 1; /* ignore length */
3922 extended_op
= read_1_byte (abfd
, line_ptr
);
3924 switch (extended_op
)
3926 case DW_LNE_end_sequence
:
3928 /* Don't call record_line here. The end_sequence
3929 instruction provides the address of the first byte
3930 *after* the last line in the sequence; it's not the
3931 address of any real source line. However, the GDB
3932 linetable structure only records the starts of lines,
3933 not the ends. This is a weakness of GDB. */
3935 case DW_LNE_set_address
:
3936 address
= read_address (abfd
, line_ptr
, cu_header
, &bytes_read
);
3937 line_ptr
+= bytes_read
;
3938 address
+= baseaddr
;
3940 case DW_LNE_define_file
:
3941 cur_file
= read_string (abfd
, line_ptr
, &bytes_read
);
3942 line_ptr
+= bytes_read
;
3943 if ((files
.num_files
% FILE_ALLOC_CHUNK
) == 0)
3945 files
.files
= (struct fileinfo
*)
3946 xrealloc (files
.files
,
3947 (files
.num_files
+ FILE_ALLOC_CHUNK
)
3948 * sizeof (struct fileinfo
));
3949 if (files
.num_files
== 0)
3950 make_cleanup (free_current_contents
, &files
.files
);
3952 files
.files
[files
.num_files
].name
= cur_file
;
3953 files
.files
[files
.num_files
].dir
=
3954 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3955 line_ptr
+= bytes_read
;
3956 files
.files
[files
.num_files
].time
=
3957 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3958 line_ptr
+= bytes_read
;
3959 files
.files
[files
.num_files
].size
=
3960 read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3961 line_ptr
+= bytes_read
;
3965 complain (&dwarf2_mangled_line_number_section
);
3970 record_line (current_subfile
, line
, address
);
3973 case DW_LNS_advance_pc
:
3974 address
+= lh
.minimum_instruction_length
3975 * read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3976 line_ptr
+= bytes_read
;
3978 case DW_LNS_advance_line
:
3979 line
+= read_signed_leb128 (abfd
, line_ptr
, &bytes_read
);
3980 line_ptr
+= bytes_read
;
3982 case DW_LNS_set_file
:
3983 /* The file and directory tables are 0 based, the references
3985 file
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3986 line_ptr
+= bytes_read
;
3987 dwarf2_start_subfile
3988 (files
.files
[file
- 1].name
,
3989 (files
.files
[file
- 1].dir
3990 ? dirs
.dirs
[files
.files
[file
- 1].dir
- 1]
3993 case DW_LNS_set_column
:
3994 column
= read_unsigned_leb128 (abfd
, line_ptr
, &bytes_read
);
3995 line_ptr
+= bytes_read
;
3997 case DW_LNS_negate_stmt
:
3998 is_stmt
= (!is_stmt
);
4000 case DW_LNS_set_basic_block
:
4003 /* Add to the address register of the state machine the
4004 address increment value corresponding to special opcode
4005 255. Ie, this value is scaled by the minimum instruction
4006 length since special opcode 255 would have scaled the
4008 case DW_LNS_const_add_pc
:
4009 address
+= (lh
.minimum_instruction_length
4010 * ((255 - lh
.opcode_base
) / lh
.line_range
));
4012 case DW_LNS_fixed_advance_pc
:
4013 address
+= read_2_bytes (abfd
, line_ptr
);
4016 default: /* special operand */
4017 adj_opcode
= op_code
- lh
.opcode_base
;
4018 address
+= (adj_opcode
/ lh
.line_range
)
4019 * lh
.minimum_instruction_length
;
4020 line
+= lh
.line_base
+ (adj_opcode
% lh
.line_range
);
4021 /* append row to matrix using current values */
4022 record_line (current_subfile
, line
, address
);
4028 do_cleanups (back_to
);
4031 /* Start a subfile for DWARF. FILENAME is the name of the file and
4032 DIRNAME the name of the source directory which contains FILENAME
4033 or NULL if not known.
4034 This routine tries to keep line numbers from identical absolute and
4035 relative file names in a common subfile.
4037 Using the `list' example from the GDB testsuite, which resides in
4038 /srcdir and compiling it with Irix6.2 cc in /compdir using a filename
4039 of /srcdir/list0.c yields the following debugging information for list0.c:
4041 DW_AT_name: /srcdir/list0.c
4042 DW_AT_comp_dir: /compdir
4043 files.files[0].name: list0.h
4044 files.files[0].dir: /srcdir
4045 files.files[1].name: list0.c
4046 files.files[1].dir: /srcdir
4048 The line number information for list0.c has to end up in a single
4049 subfile, so that `break /srcdir/list0.c:1' works as expected. */
4052 dwarf2_start_subfile (char *filename
, char *dirname
)
4054 /* If the filename isn't absolute, try to match an existing subfile
4055 with the full pathname. */
4057 if (*filename
!= '/' && dirname
!= NULL
)
4059 struct subfile
*subfile
;
4060 char *fullname
= concat (dirname
, "/", filename
, NULL
);
4062 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
4064 if (STREQ (subfile
->name
, fullname
))
4066 current_subfile
= subfile
;
4073 start_subfile (filename
, dirname
);
4076 /* Given a pointer to a DWARF information entry, figure out if we need
4077 to make a symbol table entry for it, and if so, create a new entry
4078 and return a pointer to it.
4079 If TYPE is NULL, determine symbol type from the die, otherwise
4080 used the passed type. */
4082 static struct symbol
*
4083 new_symbol (struct die_info
*die
, struct type
*type
, struct objfile
*objfile
,
4084 const struct comp_unit_head
*cu_header
)
4086 struct symbol
*sym
= NULL
;
4088 struct attribute
*attr
= NULL
;
4089 struct attribute
*attr2
= NULL
;
4092 name
= dwarf2_linkage_name (die
);
4095 sym
= (struct symbol
*) obstack_alloc (&objfile
->symbol_obstack
,
4096 sizeof (struct symbol
));
4097 OBJSTAT (objfile
, n_syms
++);
4098 memset (sym
, 0, sizeof (struct symbol
));
4099 SYMBOL_NAME (sym
) = obsavestring (name
, strlen (name
),
4100 &objfile
->symbol_obstack
);
4102 /* Default assumptions.
4103 Use the passed type or decode it from the die. */
4104 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4105 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4107 SYMBOL_TYPE (sym
) = type
;
4109 SYMBOL_TYPE (sym
) = die_type (die
, objfile
, cu_header
);
4110 attr
= dwarf_attr (die
, DW_AT_decl_line
);
4113 SYMBOL_LINE (sym
) = DW_UNSND (attr
);
4116 /* If this symbol is from a C++ compilation, then attempt to
4117 cache the demangled form for future reference. This is a
4118 typical time versus space tradeoff, that was decided in favor
4119 of time because it sped up C++ symbol lookups by a factor of
4122 SYMBOL_LANGUAGE (sym
) = cu_language
;
4123 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
4127 attr
= dwarf_attr (die
, DW_AT_low_pc
);
4130 SYMBOL_VALUE_ADDRESS (sym
) = DW_ADDR (attr
) + baseaddr
;
4132 SYMBOL_CLASS (sym
) = LOC_LABEL
;
4134 case DW_TAG_subprogram
:
4135 /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by
4137 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4138 attr2
= dwarf_attr (die
, DW_AT_external
);
4139 if (attr2
&& (DW_UNSND (attr2
) != 0))
4141 add_symbol_to_list (sym
, &global_symbols
);
4145 add_symbol_to_list (sym
, list_in_scope
);
4148 case DW_TAG_variable
:
4149 /* Compilation with minimal debug info may result in variables
4150 with missing type entries. Change the misleading `void' type
4151 to something sensible. */
4152 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_VOID
)
4153 SYMBOL_TYPE (sym
) = init_type (TYPE_CODE_INT
,
4154 TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4155 "<variable, no debug info>",
4157 attr
= dwarf_attr (die
, DW_AT_const_value
);
4160 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4161 attr2
= dwarf_attr (die
, DW_AT_external
);
4162 if (attr2
&& (DW_UNSND (attr2
) != 0))
4163 add_symbol_to_list (sym
, &global_symbols
);
4165 add_symbol_to_list (sym
, list_in_scope
);
4168 attr
= dwarf_attr (die
, DW_AT_location
);
4171 attr2
= dwarf_attr (die
, DW_AT_external
);
4172 if (attr2
&& (DW_UNSND (attr2
) != 0))
4174 SYMBOL_VALUE_ADDRESS (sym
) =
4175 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4176 add_symbol_to_list (sym
, &global_symbols
);
4178 /* In shared libraries the address of the variable
4179 in the location descriptor might still be relocatable,
4180 so its value could be zero.
4181 Enter the symbol as a LOC_UNRESOLVED symbol, if its
4182 value is zero, the address of the variable will then
4183 be determined from the minimal symbol table whenever
4184 the variable is referenced. */
4185 if (SYMBOL_VALUE_ADDRESS (sym
))
4187 fixup_symbol_section (sym
, objfile
);
4188 SYMBOL_VALUE_ADDRESS (sym
) +=
4189 ANOFFSET (objfile
->section_offsets
,
4190 SYMBOL_SECTION (sym
));
4191 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4194 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4198 SYMBOL_VALUE (sym
) = addr
=
4199 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4200 add_symbol_to_list (sym
, list_in_scope
);
4203 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
4207 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
4208 SYMBOL_VALUE (sym
) =
4209 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4213 SYMBOL_CLASS (sym
) = LOC_BASEREG
;
4214 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4218 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
4222 fixup_symbol_section (sym
, objfile
);
4223 SYMBOL_VALUE_ADDRESS (sym
) =
4224 addr
+ ANOFFSET (objfile
->section_offsets
,
4225 SYMBOL_SECTION (sym
));
4226 SYMBOL_CLASS (sym
) = LOC_STATIC
;
4232 /* We do not know the address of this symbol.
4233 If it is an external symbol and we have type information
4234 for it, enter the symbol as a LOC_UNRESOLVED symbol.
4235 The address of the variable will then be determined from
4236 the minimal symbol table whenever the variable is
4238 attr2
= dwarf_attr (die
, DW_AT_external
);
4239 if (attr2
&& (DW_UNSND (attr2
) != 0)
4240 && dwarf_attr (die
, DW_AT_type
) != NULL
)
4242 SYMBOL_CLASS (sym
) = LOC_UNRESOLVED
;
4243 add_symbol_to_list (sym
, &global_symbols
);
4247 case DW_TAG_formal_parameter
:
4248 attr
= dwarf_attr (die
, DW_AT_location
);
4251 SYMBOL_VALUE (sym
) =
4252 decode_locdesc (DW_BLOCK (attr
), objfile
, cu_header
);
4255 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
4256 SYMBOL_VALUE (sym
) =
4257 DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym
));
4263 if (basereg
!= frame_base_reg
)
4264 complain (&dwarf2_complex_location_expr
);
4265 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
4269 SYMBOL_CLASS (sym
) = LOC_BASEREG_ARG
;
4270 SYMBOL_BASEREG (sym
) = DWARF2_REG_TO_REGNUM (basereg
);
4275 SYMBOL_CLASS (sym
) = LOC_ARG
;
4278 attr
= dwarf_attr (die
, DW_AT_const_value
);
4281 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4283 add_symbol_to_list (sym
, list_in_scope
);
4285 case DW_TAG_unspecified_parameters
:
4286 /* From varargs functions; gdb doesn't seem to have any
4287 interest in this information, so just ignore it for now.
4290 case DW_TAG_class_type
:
4291 case DW_TAG_structure_type
:
4292 case DW_TAG_union_type
:
4293 case DW_TAG_enumeration_type
:
4294 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4295 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
4296 add_symbol_to_list (sym
, list_in_scope
);
4298 /* The semantics of C++ state that "struct foo { ... }" also
4299 defines a typedef for "foo". Synthesize a typedef symbol so
4300 that "ptype foo" works as expected. */
4301 if (cu_language
== language_cplus
)
4303 struct symbol
*typedef_sym
= (struct symbol
*)
4304 obstack_alloc (&objfile
->symbol_obstack
,
4305 sizeof (struct symbol
));
4306 *typedef_sym
= *sym
;
4307 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
4308 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
4309 TYPE_NAME (SYMBOL_TYPE (sym
)) =
4310 obsavestring (SYMBOL_NAME (sym
),
4311 strlen (SYMBOL_NAME (sym
)),
4312 &objfile
->type_obstack
);
4313 add_symbol_to_list (typedef_sym
, list_in_scope
);
4316 case DW_TAG_typedef
:
4317 case DW_TAG_base_type
:
4318 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
4319 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4320 add_symbol_to_list (sym
, list_in_scope
);
4322 case DW_TAG_enumerator
:
4323 attr
= dwarf_attr (die
, DW_AT_const_value
);
4326 dwarf2_const_value (attr
, sym
, objfile
, cu_header
);
4328 add_symbol_to_list (sym
, list_in_scope
);
4331 /* Not a tag we recognize. Hopefully we aren't processing
4332 trash data, but since we must specifically ignore things
4333 we don't recognize, there is nothing else we should do at
4335 complain (&dwarf2_unsupported_tag
, dwarf_tag_name (die
->tag
));
4342 /* Copy constant value from an attribute to a symbol. */
4345 dwarf2_const_value (struct attribute
*attr
, struct symbol
*sym
,
4346 struct objfile
*objfile
,
4347 const struct comp_unit_head
*cu_header
)
4349 struct dwarf_block
*blk
;
4354 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != cu_header
->addr_size
)
4355 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4356 cu_header
->addr_size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4357 SYMBOL_VALUE_BYTES (sym
) = (char *)
4358 obstack_alloc (&objfile
->symbol_obstack
, cu_header
->addr_size
);
4359 store_address (SYMBOL_VALUE_BYTES (sym
), cu_header
->addr_size
,
4361 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4363 case DW_FORM_block1
:
4364 case DW_FORM_block2
:
4365 case DW_FORM_block4
:
4367 blk
= DW_BLOCK (attr
);
4368 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) != blk
->size
)
4369 complain (&dwarf2_const_value_length_mismatch
, SYMBOL_NAME (sym
),
4370 blk
->size
, TYPE_LENGTH (SYMBOL_TYPE (sym
)));
4371 SYMBOL_VALUE_BYTES (sym
) = (char *)
4372 obstack_alloc (&objfile
->symbol_obstack
, blk
->size
);
4373 memcpy (SYMBOL_VALUE_BYTES (sym
), blk
->data
, blk
->size
);
4374 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
4377 /* The DW_AT_const_value attributes are supposed to carry the
4378 symbol's value "represented as it would be on the target
4379 architecture." By the time we get here, it's already been
4380 converted to host endianness, so we just need to sign- or
4381 zero-extend it as appropriate. */
4383 dwarf2_const_value_data (attr
, sym
, 8);
4386 dwarf2_const_value_data (attr
, sym
, 16);
4389 dwarf2_const_value_data (attr
, sym
, 32);
4392 dwarf2_const_value_data (attr
, sym
, 64);
4396 SYMBOL_VALUE (sym
) = DW_SND (attr
);
4397 SYMBOL_CLASS (sym
) = LOC_CONST
;
4401 SYMBOL_VALUE (sym
) = DW_UNSND (attr
);
4402 SYMBOL_CLASS (sym
) = LOC_CONST
;
4406 complain (&dwarf2_unsupported_const_value_attr
,
4407 dwarf_form_name (attr
->form
));
4408 SYMBOL_VALUE (sym
) = 0;
4409 SYMBOL_CLASS (sym
) = LOC_CONST
;
4415 /* Given an attr with a DW_FORM_dataN value in host byte order, sign-
4416 or zero-extend it as appropriate for the symbol's type. */
4418 dwarf2_const_value_data (struct attribute
*attr
,
4422 LONGEST l
= DW_UNSND (attr
);
4424 if (bits
< sizeof (l
) * 8)
4426 if (TYPE_UNSIGNED (SYMBOL_TYPE (sym
)))
4427 l
&= ((LONGEST
) 1 << bits
) - 1;
4429 l
= (l
<< (sizeof (l
) * 8 - bits
)) >> (sizeof (l
) * 8 - bits
);
4432 SYMBOL_VALUE (sym
) = l
;
4433 SYMBOL_CLASS (sym
) = LOC_CONST
;
4437 /* Return the type of the die in question using its DW_AT_type attribute. */
4439 static struct type
*
4440 die_type (struct die_info
*die
, struct objfile
*objfile
,
4441 const struct comp_unit_head
*cu_header
)
4444 struct attribute
*type_attr
;
4445 struct die_info
*type_die
;
4448 type_attr
= dwarf_attr (die
, DW_AT_type
);
4451 /* A missing DW_AT_type represents a void type. */
4452 return dwarf2_fundamental_type (objfile
, FT_VOID
);
4456 ref
= dwarf2_get_ref_die_offset (type_attr
);
4457 type_die
= follow_die_ref (ref
);
4460 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4464 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4467 dump_die (type_die
);
4468 error ("Dwarf Error: Problem turning type die at offset into gdb type.");
4473 /* Return the containing type of the die in question using its
4474 DW_AT_containing_type attribute. */
4476 static struct type
*
4477 die_containing_type (struct die_info
*die
, struct objfile
*objfile
,
4478 const struct comp_unit_head
*cu_header
)
4480 struct type
*type
= NULL
;
4481 struct attribute
*type_attr
;
4482 struct die_info
*type_die
= NULL
;
4485 type_attr
= dwarf_attr (die
, DW_AT_containing_type
);
4488 ref
= dwarf2_get_ref_die_offset (type_attr
);
4489 type_die
= follow_die_ref (ref
);
4492 error ("Dwarf Error: Cannot find referent at offset %d.", ref
);
4495 type
= tag_type_to_type (type_die
, objfile
, cu_header
);
4500 dump_die (type_die
);
4501 error ("Dwarf Error: Problem turning containing type into gdb type.");
4507 static struct type
*
4508 type_at_offset (unsigned int offset
, struct objfile
*objfile
)
4510 struct die_info
*die
;
4513 die
= follow_die_ref (offset
);
4516 error ("Dwarf Error: Cannot find type referent at offset %d.", offset
);
4519 type
= tag_type_to_type (die
, objfile
);
4524 static struct type
*
4525 tag_type_to_type (struct die_info
*die
, struct objfile
*objfile
,
4526 const struct comp_unit_head
*cu_header
)
4534 read_type_die (die
, objfile
, cu_header
);
4538 error ("Dwarf Error: Cannot find type of die.");
4545 read_type_die (struct die_info
*die
, struct objfile
*objfile
,
4546 const struct comp_unit_head
*cu_header
)
4550 case DW_TAG_class_type
:
4551 case DW_TAG_structure_type
:
4552 case DW_TAG_union_type
:
4553 read_structure_scope (die
, objfile
, cu_header
);
4555 case DW_TAG_enumeration_type
:
4556 read_enumeration (die
, objfile
, cu_header
);
4558 case DW_TAG_subprogram
:
4559 case DW_TAG_subroutine_type
:
4560 read_subroutine_type (die
, objfile
, cu_header
);
4562 case DW_TAG_array_type
:
4563 read_array_type (die
, objfile
, cu_header
);
4565 case DW_TAG_pointer_type
:
4566 read_tag_pointer_type (die
, objfile
, cu_header
);
4568 case DW_TAG_ptr_to_member_type
:
4569 read_tag_ptr_to_member_type (die
, objfile
, cu_header
);
4571 case DW_TAG_reference_type
:
4572 read_tag_reference_type (die
, objfile
, cu_header
);
4574 case DW_TAG_const_type
:
4575 read_tag_const_type (die
, objfile
, cu_header
);
4577 case DW_TAG_volatile_type
:
4578 read_tag_volatile_type (die
, objfile
, cu_header
);
4580 case DW_TAG_string_type
:
4581 read_tag_string_type (die
, objfile
);
4583 case DW_TAG_typedef
:
4584 read_typedef (die
, objfile
, cu_header
);
4586 case DW_TAG_base_type
:
4587 read_base_type (die
, objfile
);
4590 complain (&dwarf2_unexpected_tag
, dwarf_tag_name (die
->tag
));
4595 static struct type
*
4596 dwarf_base_type (int encoding
, int size
, struct objfile
*objfile
)
4598 /* FIXME - this should not produce a new (struct type *)
4599 every time. It should cache base types. */
4603 case DW_ATE_address
:
4604 type
= dwarf2_fundamental_type (objfile
, FT_VOID
);
4606 case DW_ATE_boolean
:
4607 type
= dwarf2_fundamental_type (objfile
, FT_BOOLEAN
);
4609 case DW_ATE_complex_float
:
4612 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_COMPLEX
);
4616 type
= dwarf2_fundamental_type (objfile
, FT_COMPLEX
);
4622 type
= dwarf2_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
4626 type
= dwarf2_fundamental_type (objfile
, FT_FLOAT
);
4633 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4636 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_SHORT
);
4640 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4644 case DW_ATE_signed_char
:
4645 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_CHAR
);
4647 case DW_ATE_unsigned
:
4651 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4654 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_SHORT
);
4658 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
4662 case DW_ATE_unsigned_char
:
4663 type
= dwarf2_fundamental_type (objfile
, FT_UNSIGNED_CHAR
);
4666 type
= dwarf2_fundamental_type (objfile
, FT_SIGNED_INTEGER
);
4673 copy_die (struct die_info
*old_die
)
4675 struct die_info
*new_die
;
4678 new_die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
4679 memset (new_die
, 0, sizeof (struct die_info
));
4681 new_die
->tag
= old_die
->tag
;
4682 new_die
->has_children
= old_die
->has_children
;
4683 new_die
->abbrev
= old_die
->abbrev
;
4684 new_die
->offset
= old_die
->offset
;
4685 new_die
->type
= NULL
;
4687 num_attrs
= old_die
->num_attrs
;
4688 new_die
->num_attrs
= num_attrs
;
4689 new_die
->attrs
= (struct attribute
*)
4690 xmalloc (num_attrs
* sizeof (struct attribute
));
4692 for (i
= 0; i
< old_die
->num_attrs
; ++i
)
4694 new_die
->attrs
[i
].name
= old_die
->attrs
[i
].name
;
4695 new_die
->attrs
[i
].form
= old_die
->attrs
[i
].form
;
4696 new_die
->attrs
[i
].u
.addr
= old_die
->attrs
[i
].u
.addr
;
4699 new_die
->next
= NULL
;
4704 /* Return sibling of die, NULL if no sibling. */
4707 sibling_die (struct die_info
*die
)
4709 int nesting_level
= 0;
4711 if (!die
->has_children
)
4713 if (die
->next
&& (die
->next
->tag
== 0))
4726 if (die
->has_children
)
4736 while (nesting_level
);
4737 if (die
&& (die
->tag
== 0))
4748 /* Get linkage name of a die, return NULL if not found. */
4751 dwarf2_linkage_name (struct die_info
*die
)
4753 struct attribute
*attr
;
4755 attr
= dwarf_attr (die
, DW_AT_MIPS_linkage_name
);
4756 if (attr
&& DW_STRING (attr
))
4757 return DW_STRING (attr
);
4758 attr
= dwarf_attr (die
, DW_AT_name
);
4759 if (attr
&& DW_STRING (attr
))
4760 return DW_STRING (attr
);
4764 /* Convert a DIE tag into its string name. */
4767 dwarf_tag_name (register unsigned tag
)
4771 case DW_TAG_padding
:
4772 return "DW_TAG_padding";
4773 case DW_TAG_array_type
:
4774 return "DW_TAG_array_type";
4775 case DW_TAG_class_type
:
4776 return "DW_TAG_class_type";
4777 case DW_TAG_entry_point
:
4778 return "DW_TAG_entry_point";
4779 case DW_TAG_enumeration_type
:
4780 return "DW_TAG_enumeration_type";
4781 case DW_TAG_formal_parameter
:
4782 return "DW_TAG_formal_parameter";
4783 case DW_TAG_imported_declaration
:
4784 return "DW_TAG_imported_declaration";
4786 return "DW_TAG_label";
4787 case DW_TAG_lexical_block
:
4788 return "DW_TAG_lexical_block";
4790 return "DW_TAG_member";
4791 case DW_TAG_pointer_type
:
4792 return "DW_TAG_pointer_type";
4793 case DW_TAG_reference_type
:
4794 return "DW_TAG_reference_type";
4795 case DW_TAG_compile_unit
:
4796 return "DW_TAG_compile_unit";
4797 case DW_TAG_string_type
:
4798 return "DW_TAG_string_type";
4799 case DW_TAG_structure_type
:
4800 return "DW_TAG_structure_type";
4801 case DW_TAG_subroutine_type
:
4802 return "DW_TAG_subroutine_type";
4803 case DW_TAG_typedef
:
4804 return "DW_TAG_typedef";
4805 case DW_TAG_union_type
:
4806 return "DW_TAG_union_type";
4807 case DW_TAG_unspecified_parameters
:
4808 return "DW_TAG_unspecified_parameters";
4809 case DW_TAG_variant
:
4810 return "DW_TAG_variant";
4811 case DW_TAG_common_block
:
4812 return "DW_TAG_common_block";
4813 case DW_TAG_common_inclusion
:
4814 return "DW_TAG_common_inclusion";
4815 case DW_TAG_inheritance
:
4816 return "DW_TAG_inheritance";
4817 case DW_TAG_inlined_subroutine
:
4818 return "DW_TAG_inlined_subroutine";
4820 return "DW_TAG_module";
4821 case DW_TAG_ptr_to_member_type
:
4822 return "DW_TAG_ptr_to_member_type";
4823 case DW_TAG_set_type
:
4824 return "DW_TAG_set_type";
4825 case DW_TAG_subrange_type
:
4826 return "DW_TAG_subrange_type";
4827 case DW_TAG_with_stmt
:
4828 return "DW_TAG_with_stmt";
4829 case DW_TAG_access_declaration
:
4830 return "DW_TAG_access_declaration";
4831 case DW_TAG_base_type
:
4832 return "DW_TAG_base_type";
4833 case DW_TAG_catch_block
:
4834 return "DW_TAG_catch_block";
4835 case DW_TAG_const_type
:
4836 return "DW_TAG_const_type";
4837 case DW_TAG_constant
:
4838 return "DW_TAG_constant";
4839 case DW_TAG_enumerator
:
4840 return "DW_TAG_enumerator";
4841 case DW_TAG_file_type
:
4842 return "DW_TAG_file_type";
4844 return "DW_TAG_friend";
4845 case DW_TAG_namelist
:
4846 return "DW_TAG_namelist";
4847 case DW_TAG_namelist_item
:
4848 return "DW_TAG_namelist_item";
4849 case DW_TAG_packed_type
:
4850 return "DW_TAG_packed_type";
4851 case DW_TAG_subprogram
:
4852 return "DW_TAG_subprogram";
4853 case DW_TAG_template_type_param
:
4854 return "DW_TAG_template_type_param";
4855 case DW_TAG_template_value_param
:
4856 return "DW_TAG_template_value_param";
4857 case DW_TAG_thrown_type
:
4858 return "DW_TAG_thrown_type";
4859 case DW_TAG_try_block
:
4860 return "DW_TAG_try_block";
4861 case DW_TAG_variant_part
:
4862 return "DW_TAG_variant_part";
4863 case DW_TAG_variable
:
4864 return "DW_TAG_variable";
4865 case DW_TAG_volatile_type
:
4866 return "DW_TAG_volatile_type";
4867 case DW_TAG_MIPS_loop
:
4868 return "DW_TAG_MIPS_loop";
4869 case DW_TAG_format_label
:
4870 return "DW_TAG_format_label";
4871 case DW_TAG_function_template
:
4872 return "DW_TAG_function_template";
4873 case DW_TAG_class_template
:
4874 return "DW_TAG_class_template";
4876 return "DW_TAG_<unknown>";
4880 /* Convert a DWARF attribute code into its string name. */
4883 dwarf_attr_name (register unsigned attr
)
4888 return "DW_AT_sibling";
4889 case DW_AT_location
:
4890 return "DW_AT_location";
4892 return "DW_AT_name";
4893 case DW_AT_ordering
:
4894 return "DW_AT_ordering";
4895 case DW_AT_subscr_data
:
4896 return "DW_AT_subscr_data";
4897 case DW_AT_byte_size
:
4898 return "DW_AT_byte_size";
4899 case DW_AT_bit_offset
:
4900 return "DW_AT_bit_offset";
4901 case DW_AT_bit_size
:
4902 return "DW_AT_bit_size";
4903 case DW_AT_element_list
:
4904 return "DW_AT_element_list";
4905 case DW_AT_stmt_list
:
4906 return "DW_AT_stmt_list";
4908 return "DW_AT_low_pc";
4910 return "DW_AT_high_pc";
4911 case DW_AT_language
:
4912 return "DW_AT_language";
4914 return "DW_AT_member";
4916 return "DW_AT_discr";
4917 case DW_AT_discr_value
:
4918 return "DW_AT_discr_value";
4919 case DW_AT_visibility
:
4920 return "DW_AT_visibility";
4922 return "DW_AT_import";
4923 case DW_AT_string_length
:
4924 return "DW_AT_string_length";
4925 case DW_AT_common_reference
:
4926 return "DW_AT_common_reference";
4927 case DW_AT_comp_dir
:
4928 return "DW_AT_comp_dir";
4929 case DW_AT_const_value
:
4930 return "DW_AT_const_value";
4931 case DW_AT_containing_type
:
4932 return "DW_AT_containing_type";
4933 case DW_AT_default_value
:
4934 return "DW_AT_default_value";
4936 return "DW_AT_inline";
4937 case DW_AT_is_optional
:
4938 return "DW_AT_is_optional";
4939 case DW_AT_lower_bound
:
4940 return "DW_AT_lower_bound";
4941 case DW_AT_producer
:
4942 return "DW_AT_producer";
4943 case DW_AT_prototyped
:
4944 return "DW_AT_prototyped";
4945 case DW_AT_return_addr
:
4946 return "DW_AT_return_addr";
4947 case DW_AT_start_scope
:
4948 return "DW_AT_start_scope";
4949 case DW_AT_stride_size
:
4950 return "DW_AT_stride_size";
4951 case DW_AT_upper_bound
:
4952 return "DW_AT_upper_bound";
4953 case DW_AT_abstract_origin
:
4954 return "DW_AT_abstract_origin";
4955 case DW_AT_accessibility
:
4956 return "DW_AT_accessibility";
4957 case DW_AT_address_class
:
4958 return "DW_AT_address_class";
4959 case DW_AT_artificial
:
4960 return "DW_AT_artificial";
4961 case DW_AT_base_types
:
4962 return "DW_AT_base_types";
4963 case DW_AT_calling_convention
:
4964 return "DW_AT_calling_convention";
4966 return "DW_AT_count";
4967 case DW_AT_data_member_location
:
4968 return "DW_AT_data_member_location";
4969 case DW_AT_decl_column
:
4970 return "DW_AT_decl_column";
4971 case DW_AT_decl_file
:
4972 return "DW_AT_decl_file";
4973 case DW_AT_decl_line
:
4974 return "DW_AT_decl_line";
4975 case DW_AT_declaration
:
4976 return "DW_AT_declaration";
4977 case DW_AT_discr_list
:
4978 return "DW_AT_discr_list";
4979 case DW_AT_encoding
:
4980 return "DW_AT_encoding";
4981 case DW_AT_external
:
4982 return "DW_AT_external";
4983 case DW_AT_frame_base
:
4984 return "DW_AT_frame_base";
4986 return "DW_AT_friend";
4987 case DW_AT_identifier_case
:
4988 return "DW_AT_identifier_case";
4989 case DW_AT_macro_info
:
4990 return "DW_AT_macro_info";
4991 case DW_AT_namelist_items
:
4992 return "DW_AT_namelist_items";
4993 case DW_AT_priority
:
4994 return "DW_AT_priority";
4996 return "DW_AT_segment";
4997 case DW_AT_specification
:
4998 return "DW_AT_specification";
4999 case DW_AT_static_link
:
5000 return "DW_AT_static_link";
5002 return "DW_AT_type";
5003 case DW_AT_use_location
:
5004 return "DW_AT_use_location";
5005 case DW_AT_variable_parameter
:
5006 return "DW_AT_variable_parameter";
5007 case DW_AT_virtuality
:
5008 return "DW_AT_virtuality";
5009 case DW_AT_vtable_elem_location
:
5010 return "DW_AT_vtable_elem_location";
5013 case DW_AT_MIPS_fde
:
5014 return "DW_AT_MIPS_fde";
5015 case DW_AT_MIPS_loop_begin
:
5016 return "DW_AT_MIPS_loop_begin";
5017 case DW_AT_MIPS_tail_loop_begin
:
5018 return "DW_AT_MIPS_tail_loop_begin";
5019 case DW_AT_MIPS_epilog_begin
:
5020 return "DW_AT_MIPS_epilog_begin";
5021 case DW_AT_MIPS_loop_unroll_factor
:
5022 return "DW_AT_MIPS_loop_unroll_factor";
5023 case DW_AT_MIPS_software_pipeline_depth
:
5024 return "DW_AT_MIPS_software_pipeline_depth";
5025 case DW_AT_MIPS_linkage_name
:
5026 return "DW_AT_MIPS_linkage_name";
5029 case DW_AT_sf_names
:
5030 return "DW_AT_sf_names";
5031 case DW_AT_src_info
:
5032 return "DW_AT_src_info";
5033 case DW_AT_mac_info
:
5034 return "DW_AT_mac_info";
5035 case DW_AT_src_coords
:
5036 return "DW_AT_src_coords";
5037 case DW_AT_body_begin
:
5038 return "DW_AT_body_begin";
5039 case DW_AT_body_end
:
5040 return "DW_AT_body_end";
5042 return "DW_AT_<unknown>";
5046 /* Convert a DWARF value form code into its string name. */
5049 dwarf_form_name (register unsigned form
)
5054 return "DW_FORM_addr";
5055 case DW_FORM_block2
:
5056 return "DW_FORM_block2";
5057 case DW_FORM_block4
:
5058 return "DW_FORM_block4";
5060 return "DW_FORM_data2";
5062 return "DW_FORM_data4";
5064 return "DW_FORM_data8";
5065 case DW_FORM_string
:
5066 return "DW_FORM_string";
5068 return "DW_FORM_block";
5069 case DW_FORM_block1
:
5070 return "DW_FORM_block1";
5072 return "DW_FORM_data1";
5074 return "DW_FORM_flag";
5076 return "DW_FORM_sdata";
5078 return "DW_FORM_strp";
5080 return "DW_FORM_udata";
5081 case DW_FORM_ref_addr
:
5082 return "DW_FORM_ref_addr";
5084 return "DW_FORM_ref1";
5086 return "DW_FORM_ref2";
5088 return "DW_FORM_ref4";
5090 return "DW_FORM_ref8";
5091 case DW_FORM_ref_udata
:
5092 return "DW_FORM_ref_udata";
5093 case DW_FORM_indirect
:
5094 return "DW_FORM_indirect";
5096 return "DW_FORM_<unknown>";
5100 /* Convert a DWARF stack opcode into its string name. */
5103 dwarf_stack_op_name (register unsigned op
)
5108 return "DW_OP_addr";
5110 return "DW_OP_deref";
5112 return "DW_OP_const1u";
5114 return "DW_OP_const1s";
5116 return "DW_OP_const2u";
5118 return "DW_OP_const2s";
5120 return "DW_OP_const4u";
5122 return "DW_OP_const4s";
5124 return "DW_OP_const8u";
5126 return "DW_OP_const8s";
5128 return "DW_OP_constu";
5130 return "DW_OP_consts";
5134 return "DW_OP_drop";
5136 return "DW_OP_over";
5138 return "DW_OP_pick";
5140 return "DW_OP_swap";
5144 return "DW_OP_xderef";
5152 return "DW_OP_minus";
5164 return "DW_OP_plus";
5165 case DW_OP_plus_uconst
:
5166 return "DW_OP_plus_uconst";
5172 return "DW_OP_shra";
5190 return "DW_OP_skip";
5192 return "DW_OP_lit0";
5194 return "DW_OP_lit1";
5196 return "DW_OP_lit2";
5198 return "DW_OP_lit3";
5200 return "DW_OP_lit4";
5202 return "DW_OP_lit5";
5204 return "DW_OP_lit6";
5206 return "DW_OP_lit7";
5208 return "DW_OP_lit8";
5210 return "DW_OP_lit9";
5212 return "DW_OP_lit10";
5214 return "DW_OP_lit11";
5216 return "DW_OP_lit12";
5218 return "DW_OP_lit13";
5220 return "DW_OP_lit14";
5222 return "DW_OP_lit15";
5224 return "DW_OP_lit16";
5226 return "DW_OP_lit17";
5228 return "DW_OP_lit18";
5230 return "DW_OP_lit19";
5232 return "DW_OP_lit20";
5234 return "DW_OP_lit21";
5236 return "DW_OP_lit22";
5238 return "DW_OP_lit23";
5240 return "DW_OP_lit24";
5242 return "DW_OP_lit25";
5244 return "DW_OP_lit26";
5246 return "DW_OP_lit27";
5248 return "DW_OP_lit28";
5250 return "DW_OP_lit29";
5252 return "DW_OP_lit30";
5254 return "DW_OP_lit31";
5256 return "DW_OP_reg0";
5258 return "DW_OP_reg1";
5260 return "DW_OP_reg2";
5262 return "DW_OP_reg3";
5264 return "DW_OP_reg4";
5266 return "DW_OP_reg5";
5268 return "DW_OP_reg6";
5270 return "DW_OP_reg7";
5272 return "DW_OP_reg8";
5274 return "DW_OP_reg9";
5276 return "DW_OP_reg10";
5278 return "DW_OP_reg11";
5280 return "DW_OP_reg12";
5282 return "DW_OP_reg13";
5284 return "DW_OP_reg14";
5286 return "DW_OP_reg15";
5288 return "DW_OP_reg16";
5290 return "DW_OP_reg17";
5292 return "DW_OP_reg18";
5294 return "DW_OP_reg19";
5296 return "DW_OP_reg20";
5298 return "DW_OP_reg21";
5300 return "DW_OP_reg22";
5302 return "DW_OP_reg23";
5304 return "DW_OP_reg24";
5306 return "DW_OP_reg25";
5308 return "DW_OP_reg26";
5310 return "DW_OP_reg27";
5312 return "DW_OP_reg28";
5314 return "DW_OP_reg29";
5316 return "DW_OP_reg30";
5318 return "DW_OP_reg31";
5320 return "DW_OP_breg0";
5322 return "DW_OP_breg1";
5324 return "DW_OP_breg2";
5326 return "DW_OP_breg3";
5328 return "DW_OP_breg4";
5330 return "DW_OP_breg5";
5332 return "DW_OP_breg6";
5334 return "DW_OP_breg7";
5336 return "DW_OP_breg8";
5338 return "DW_OP_breg9";
5340 return "DW_OP_breg10";
5342 return "DW_OP_breg11";
5344 return "DW_OP_breg12";
5346 return "DW_OP_breg13";
5348 return "DW_OP_breg14";
5350 return "DW_OP_breg15";
5352 return "DW_OP_breg16";
5354 return "DW_OP_breg17";
5356 return "DW_OP_breg18";
5358 return "DW_OP_breg19";
5360 return "DW_OP_breg20";
5362 return "DW_OP_breg21";
5364 return "DW_OP_breg22";
5366 return "DW_OP_breg23";
5368 return "DW_OP_breg24";
5370 return "DW_OP_breg25";
5372 return "DW_OP_breg26";
5374 return "DW_OP_breg27";
5376 return "DW_OP_breg28";
5378 return "DW_OP_breg29";
5380 return "DW_OP_breg30";
5382 return "DW_OP_breg31";
5384 return "DW_OP_regx";
5386 return "DW_OP_fbreg";
5388 return "DW_OP_bregx";
5390 return "DW_OP_piece";
5391 case DW_OP_deref_size
:
5392 return "DW_OP_deref_size";
5393 case DW_OP_xderef_size
:
5394 return "DW_OP_xderef_size";
5398 return "OP_<unknown>";
5403 dwarf_bool_name (unsigned mybool
)
5411 /* Convert a DWARF type code into its string name. */
5414 dwarf_type_encoding_name (register unsigned enc
)
5418 case DW_ATE_address
:
5419 return "DW_ATE_address";
5420 case DW_ATE_boolean
:
5421 return "DW_ATE_boolean";
5422 case DW_ATE_complex_float
:
5423 return "DW_ATE_complex_float";
5425 return "DW_ATE_float";
5427 return "DW_ATE_signed";
5428 case DW_ATE_signed_char
:
5429 return "DW_ATE_signed_char";
5430 case DW_ATE_unsigned
:
5431 return "DW_ATE_unsigned";
5432 case DW_ATE_unsigned_char
:
5433 return "DW_ATE_unsigned_char";
5435 return "DW_ATE_<unknown>";
5439 /* Convert a DWARF call frame info operation to its string name. */
5443 dwarf_cfi_name (register unsigned cfi_opc
)
5447 case DW_CFA_advance_loc
:
5448 return "DW_CFA_advance_loc";
5450 return "DW_CFA_offset";
5451 case DW_CFA_restore
:
5452 return "DW_CFA_restore";
5454 return "DW_CFA_nop";
5455 case DW_CFA_set_loc
:
5456 return "DW_CFA_set_loc";
5457 case DW_CFA_advance_loc1
:
5458 return "DW_CFA_advance_loc1";
5459 case DW_CFA_advance_loc2
:
5460 return "DW_CFA_advance_loc2";
5461 case DW_CFA_advance_loc4
:
5462 return "DW_CFA_advance_loc4";
5463 case DW_CFA_offset_extended
:
5464 return "DW_CFA_offset_extended";
5465 case DW_CFA_restore_extended
:
5466 return "DW_CFA_restore_extended";
5467 case DW_CFA_undefined
:
5468 return "DW_CFA_undefined";
5469 case DW_CFA_same_value
:
5470 return "DW_CFA_same_value";
5471 case DW_CFA_register
:
5472 return "DW_CFA_register";
5473 case DW_CFA_remember_state
:
5474 return "DW_CFA_remember_state";
5475 case DW_CFA_restore_state
:
5476 return "DW_CFA_restore_state";
5477 case DW_CFA_def_cfa
:
5478 return "DW_CFA_def_cfa";
5479 case DW_CFA_def_cfa_register
:
5480 return "DW_CFA_def_cfa_register";
5481 case DW_CFA_def_cfa_offset
:
5482 return "DW_CFA_def_cfa_offset";
5483 /* SGI/MIPS specific */
5484 case DW_CFA_MIPS_advance_loc8
:
5485 return "DW_CFA_MIPS_advance_loc8";
5487 return "DW_CFA_<unknown>";
5493 dump_die (struct die_info
*die
)
5497 fprintf (stderr
, "Die: %s (abbrev = %d, offset = %d)\n",
5498 dwarf_tag_name (die
->tag
), die
->abbrev
, die
->offset
);
5499 fprintf (stderr
, "\thas children: %s\n",
5500 dwarf_bool_name (die
->has_children
));
5502 fprintf (stderr
, "\tattributes:\n");
5503 for (i
= 0; i
< die
->num_attrs
; ++i
)
5505 fprintf (stderr
, "\t\t%s (%s) ",
5506 dwarf_attr_name (die
->attrs
[i
].name
),
5507 dwarf_form_name (die
->attrs
[i
].form
));
5508 switch (die
->attrs
[i
].form
)
5510 case DW_FORM_ref_addr
:
5512 fprintf (stderr
, "address: ");
5513 print_address_numeric (DW_ADDR (&die
->attrs
[i
]), 1, gdb_stderr
);
5515 case DW_FORM_block2
:
5516 case DW_FORM_block4
:
5518 case DW_FORM_block1
:
5519 fprintf (stderr
, "block: size %d", DW_BLOCK (&die
->attrs
[i
])->size
);
5530 fprintf (stderr
, "constant: %ld", DW_UNSND (&die
->attrs
[i
]));
5532 case DW_FORM_string
:
5533 fprintf (stderr
, "string: \"%s\"",
5534 DW_STRING (&die
->attrs
[i
])
5535 ? DW_STRING (&die
->attrs
[i
]) : "");
5538 if (DW_UNSND (&die
->attrs
[i
]))
5539 fprintf (stderr
, "flag: TRUE");
5541 fprintf (stderr
, "flag: FALSE");
5543 case DW_FORM_strp
: /* we do not support separate string
5545 case DW_FORM_indirect
: /* we do not handle indirect yet */
5547 fprintf (stderr
, "unsupported attribute form: %d.",
5548 die
->attrs
[i
].form
);
5550 fprintf (stderr
, "\n");
5555 dump_die_list (struct die_info
*die
)
5565 store_in_ref_table (unsigned int offset
, struct die_info
*die
)
5568 struct die_info
*old
;
5570 h
= (offset
% REF_HASH_SIZE
);
5571 old
= die_ref_table
[h
];
5572 die
->next_ref
= old
;
5573 die_ref_table
[h
] = die
;
5578 dwarf2_empty_hash_tables (void)
5580 memset (die_ref_table
, 0, sizeof (die_ref_table
));
5584 dwarf2_get_ref_die_offset (struct attribute
*attr
)
5586 unsigned int result
= 0;
5590 case DW_FORM_ref_addr
:
5591 result
= DW_ADDR (attr
);
5597 case DW_FORM_ref_udata
:
5598 result
= cu_header_offset
+ DW_UNSND (attr
);
5601 complain (&dwarf2_unsupported_die_ref_attr
, dwarf_form_name (attr
->form
));
5607 follow_die_ref (unsigned int offset
)
5609 struct die_info
*die
;
5612 h
= (offset
% REF_HASH_SIZE
);
5613 die
= die_ref_table
[h
];
5616 if (die
->offset
== offset
)
5620 die
= die
->next_ref
;
5625 static struct type
*
5626 dwarf2_fundamental_type (struct objfile
*objfile
, int typeid)
5628 if (typeid < 0 || typeid >= FT_NUM_MEMBERS
)
5630 error ("Dwarf Error: internal error - invalid fundamental type id %d.",
5634 /* Look for this particular type in the fundamental type vector. If
5635 one is not found, create and install one appropriate for the
5636 current language and the current target machine. */
5638 if (ftypes
[typeid] == NULL
)
5640 ftypes
[typeid] = cu_language_defn
->la_fund_type (objfile
, typeid);
5643 return (ftypes
[typeid]);
5646 /* Decode simple location descriptions.
5647 Given a pointer to a dwarf block that defines a location, compute
5648 the location and return the value.
5650 FIXME: This is a kludge until we figure out a better
5651 way to handle the location descriptions.
5652 Gdb's design does not mesh well with the DWARF2 notion of a location
5653 computing interpreter, which is a shame because the flexibility goes unused.
5654 FIXME: Implement more operations as necessary.
5656 A location description containing no operations indicates that the
5657 object is optimized out. The global optimized_out flag is set for
5658 those, the return value is meaningless.
5660 When the result is a register number, the global isreg flag is set,
5661 otherwise it is cleared.
5663 When the result is a base register offset, the global offreg flag is set
5664 and the register number is returned in basereg, otherwise it is cleared.
5666 When the DW_OP_fbreg operation is encountered without a corresponding
5667 DW_AT_frame_base attribute, the global islocal flag is set.
5668 Hopefully the machine dependent code knows how to set up a virtual
5669 frame pointer for the local references.
5671 Note that stack[0] is unused except as a default error return.
5672 Note that stack overflow is not yet handled. */
5675 decode_locdesc (struct dwarf_block
*blk
, struct objfile
*objfile
,
5676 const struct comp_unit_head
*cu_header
)
5679 int size
= blk
->size
;
5680 char *data
= blk
->data
;
5681 CORE_ADDR stack
[64];
5683 unsigned int bytes_read
, unsnd
;
5734 stack
[++stacki
] = op
- DW_OP_reg0
;
5739 unsnd
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5741 #if defined(HARRIS_TARGET) && defined(_M88K)
5742 /* The Harris 88110 gdb ports have long kept their special reg
5743 numbers between their gp-regs and their x-regs. This is
5744 not how our dwarf is generated. Punt. */
5747 stack
[++stacki
] = unsnd
;
5783 basereg
= op
- DW_OP_breg0
;
5784 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5790 basereg
= read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5792 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5797 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5799 if (frame_base_reg
>= 0)
5802 basereg
= frame_base_reg
;
5803 stack
[stacki
] += frame_base_offset
;
5807 complain (&dwarf2_missing_at_frame_base
);
5813 stack
[++stacki
] = read_address (objfile
->obfd
, &data
[i
],
5814 cu_header
, &bytes_read
);
5819 stack
[++stacki
] = read_1_byte (objfile
->obfd
, &data
[i
]);
5824 stack
[++stacki
] = read_1_signed_byte (objfile
->obfd
, &data
[i
]);
5829 stack
[++stacki
] = read_2_bytes (objfile
->obfd
, &data
[i
]);
5834 stack
[++stacki
] = read_2_signed_bytes (objfile
->obfd
, &data
[i
]);
5839 stack
[++stacki
] = read_4_bytes (objfile
->obfd
, &data
[i
]);
5844 stack
[++stacki
] = read_4_signed_bytes (objfile
->obfd
, &data
[i
]);
5849 stack
[++stacki
] = read_unsigned_leb128 (NULL
, (data
+ i
),
5855 stack
[++stacki
] = read_signed_leb128 (NULL
, (data
+ i
), &bytes_read
);
5860 stack
[stacki
- 1] += stack
[stacki
];
5864 case DW_OP_plus_uconst
:
5865 stack
[stacki
] += read_unsigned_leb128 (NULL
, (data
+ i
), &bytes_read
);
5870 stack
[stacki
- 1] = stack
[stacki
] - stack
[stacki
- 1];
5876 /* If we're not the last op, then we definitely can't encode
5877 this using GDB's address_class enum. */
5879 complain (&dwarf2_complex_location_expr
);
5883 complain (&dwarf2_unsupported_stack_op
, dwarf_stack_op_name (op
));
5884 return (stack
[stacki
]);
5887 return (stack
[stacki
]);
5890 /* memory allocation interface */
5894 dwarf2_free_tmp_obstack (PTR ignore
)
5896 obstack_free (&dwarf2_tmp_obstack
, NULL
);
5899 static struct dwarf_block
*
5900 dwarf_alloc_block (void)
5902 struct dwarf_block
*blk
;
5904 blk
= (struct dwarf_block
*)
5905 obstack_alloc (&dwarf2_tmp_obstack
, sizeof (struct dwarf_block
));
5909 static struct abbrev_info
*
5910 dwarf_alloc_abbrev (void)
5912 struct abbrev_info
*abbrev
;
5914 abbrev
= (struct abbrev_info
*) xmalloc (sizeof (struct abbrev_info
));
5915 memset (abbrev
, 0, sizeof (struct abbrev_info
));
5919 static struct die_info
*
5920 dwarf_alloc_die (void)
5922 struct die_info
*die
;
5924 die
= (struct die_info
*) xmalloc (sizeof (struct die_info
));
5925 memset (die
, 0, sizeof (struct die_info
));